Skip to content

Commit

Permalink
sort browser list by name
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 15, 2014
1 parent 408aece commit a7cb486
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -301,6 +301,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )

mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
mProxyModel->setBrowserModel( mModel );
mProxyModel->sort( 0 );
mBrowserView->setModel( mProxyModel );
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
mBrowserView->setTextElideMode( Qt::ElideNone );
Expand Down

23 comments on commit a7cb486

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this done? It messes the display of the browser pretty bad IMO.

image

The way it was displayed before was better for usability.

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing folders with files also makes thing confusing:

image

Folders should be listed first then files.

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous behaviour was much better

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort by name was added because each provider may add an entry for a dir or file and additional entries for the same dir were added far from the dir and thus not noticed by user.

I'll try to implement something more complex, not messing root and dirs with files.

@NathanW2
Copy link
Member

@NathanW2 NathanW2 commented on a7cb486 May 17, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already implemented a custom sorting logic in the proxy filterAcceptsRow(), you can fix things there.

Can you show a specific example illustrating the problem (or explain how to reproduce it)? which providers add dir entries and where?

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try, but not before Monday, I am offline.

GRASS ;-)

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm I thought as much! cheers.

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One approach would be to implement QgsBrowserTreeFilterProxyModel::lessThan().
I guess it would work if the default would be to sort by modelIndex values (to preserve original insert order). For directory and file items, use the items' directory/file names.

Another, simpler approach, would be to call sort() on all root items that are directory items.

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just implemented lessThan() that sorts files by item's name(), others use the item's modeindex so original order is preseved

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see bcfe0a8

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I don't use grass could not test this with grass, but order is fine in gdal/ogr items

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Etienne and sorry for problems I introduced.

Unfortunately it is not yet optimal for GRASS because GRASS location entries (location is directory) are now listed between files but they should always follow directory of the same name. I have no idea how to resolve it. If an entry appears within dirs or within files should depend on whether the item was created based on dir or file (I believe). But we don't have such a flag on QgsDataItem.
browser-sort

@etiennesky
Copy link
Contributor

@etiennesky etiennesky commented on a7cb486 May 20, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But QgsGrassLocationItem is not QgsLayerItem, it doesn't have providerKey(). I cannot invent any simple clean solution without adding more info to QgsDataItem, like source type (dir/file). I dont know about other providers adding virtual item but in general it is possible that multiple providers add items for the same file/dir.

@etiennesky
Copy link
Contributor

@etiennesky etiennesky commented on a7cb486 May 28, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already considered that all, but

  • cast to QgsGrassLocationItem seems really a hack over acceptable limits because grass header is not part of core, even providerKey() would be quite hacky
  • QgsDataItem::Collection type cannot be used because QgsZipItem is also QgsDataCollectionItem

Do you have another idea? I wanted to add enum SrcType { SrcDirectory, SrcFile } but then considered it as overkill and too much mess for nothing but cannot come up with anything else.

@etiennesky
Copy link
Contributor

@etiennesky etiennesky commented on a7cb486 May 28, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the QgsGrassLocationItem type() method to return Directory
instead of Collection? The existing filter would work in this case.

In theory yes, but that is just another hack. The idea of Collection was something with children which is not Directory.

I like the srcType() approach, but there should be more values i.e. db,
network, etc. I think it would be ok to add new methods, even now in
feature freeze as long as it helps fix a bug.

Of course more types are necessary. But what other use apart sorting GRASS it may have? Maybe it could be used also to sort top level items, e.g. keep db providers and W*S in together groups - which seems to happen already anyway.

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually sorting of top-level items is avoided, the initial inserting order is preserved, which I think is better. So I don't any further uses for srcType() than this specific case.

I still think the best option is to change the QgsGrassLocationItem type() to Directory, which it really is when you think about it. It's a directory with some children (files), in the same sense that a "real" directory has gdal or ogr children files, and another Collection type (e.g. spatialite .db) has some children. Or perhaps I'm simplifying it.

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll probably change it to Directory, at least for now.

Last cosmetic detail, to always put GRASS item under the dir, it should be enough to compare row(), right?

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now all comparison is done using QString::localeAwareCompare(). In this case it will return 0, so I'm not sure which other criteria to use. But I think you are right to use row() (when compare==0) if the grass dir item is detected after the normal dir item.

@blazek
Copy link
Member Author

@blazek blazek commented on a7cb486 May 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already sorting implemented in QgsDataItem::addChildItem(). I hope it's fixed in 59c88cc.

Please sign in to comment.