KDirModel with Node for top level URL

Christian Loose christian.loose at hamburg.de
Sun Mar 9 10:41:58 GMT 2008

Sebastian TrĂ¼g schrieb:
> If I understand correctly I have the IMHO perfect solution for you: For K3b I 
> write the K3bMetaItemModel which wraps an arbitrary number of models in one 
> tree. I use it to have multiple root nodes like "home dir", "/", or the 
> mounted drives.
> Have a look here:
> http://websvn.kde.org/trunk/extragear/multimedia/k3b/src/k3bmetaitemmodel.h?revision=766850&view=markup
> and here:
> http://websvn.kde.org/trunk/extragear/multimedia/k3b/src/k3bplacesmodel.h?revision=766850&view=markup
> I hope this helps. I also think that the MetaModel would fit well into 
> kdelibs.
> Cheers,
> Sebastian

Lets see if I understand this:

I would have a MyDirModel class derived from your K3bMetaItemModel 
similar to your K3bPlacesModel. Then I would add a single KDirModel with
the addSubModel() method. The parameter "name" would be the name of the 
root node, right? So passing url.path() would give me the desired result.

If this is correct, than you're right that it's the perfect solution for 
me. What do others say?

> On Saturday 08 March 2008 15:55:26 Christian Loose wrote:
>> 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.
>> David suggested a few solutions on kfm-devel:
>>> * 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.
>> We wonder now who else could have similar needs? What approach would you
>> prefer?
>> From Bug #153878 it seems that at least Dolphin could use a similar feature
>> for its folder panel.
>> Bye,
>> Christian

More information about the kde-core-devel mailing list