KDirModel with Node for top level URL

David Faure faure at kde.org
Wed Mar 5 00:28:46 GMT 2008


On Monday 03 March 2008, Christian Loose wrote:
> < Please cc me on replies because I'm not subscribed to this list. Thanks! >
> 
> Hello everybody,
> 
> I'm trying to use KDirModel for the file view in Cervisia. It worked 
> pretty well so far but there is one thing I need
> and I can't get it to work. I need a tree node for the top level URL 
> like "/home/cloose/cvs-src/kde-head/kdepim/kmail"
> in the following screenshot: 
> http://cervisia.kde.org/images/screenshots/HEAD/mainview.png.

> I tried several approaches like subclass or a proxy model but no 
> success. Has somebody done this before or does somebody
> have an idea how to achieve this?

A proxy can certainly do it, but this might be tricky to do right.

I see three solutions:
* a "show root node" mode in KDirModel itself, but I'm afraid of the code complexity
   if it has to follow one of two logics... Sounds like ugly mixed code in the end.
* a proxy that "adds" the toplevel node.
  Note that it still needs to do the usual proxy stuff (converting indexes), on top of which
  it needs to present a model with one additional node at the toplevel.
  Has to be done with QAbstractProxyModel, but note that you need to implement many
methods from the base class, not just those that appear in the QAbstractProxyModel docu.
* I also thought of a filter proxy model that would remove "all but the wanted root node"
but this requires listing the parent url of the one we wanted to list in the first place (can
lead to strange code in the application) and this would prevent having "/" as the root node.

I wonder who else has the same needs; would be worth asking on kde-core-devel I guess,
to see if other apps need this (and which approach they would prefer).

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kfm-devel mailing list