Skip to content
Permalink
Browse files
fix browser dock sorting - only files are sorted
  • Loading branch information
etiennesky committed May 17, 2014
1 parent 48ed1cf commit bcfe0a8e10e87c17ee41e9282c8a8c54c279d47b
Showing with 21 additions and 1 deletion.
  1. +21 −1 src/app/qgsbrowserdockwidget.cpp
@@ -229,6 +229,26 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
return true;
}

bool lessThan( const QModelIndex &left,
const QModelIndex &right ) const
{
// sort file items by name (a file item is not a directory and its parent is a directory)
// this is necessary because more several providers can add items to a directory and
// alphabetical sorting is not preserved
QgsDataItem* leftItem = mModel->dataItem( left );
QgsDataItem* rightItem = mModel->dataItem( right );
if ( leftItem && leftItem->type() != QgsDataItem::Directory &&
leftItem->parent() && leftItem->parent()->type() == QgsDataItem::Directory &&
rightItem && rightItem->type() != QgsDataItem::Directory &&
rightItem->parent() && rightItem->parent()->type() == QgsDataItem::Directory )
{
return QString::localeAwareCompare( leftItem->name(), rightItem->name() ) < 0;
}

// default is to keep original order
return left.row() < right.row();
}

};
QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
QDockWidget( parent ), mModel( NULL ), mProxyModel( NULL )
@@ -308,7 +328,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
mBrowserView->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
mBrowserView->header()->setStretchLastSection( false );

// find root favourites item
// expand root favourites item
for ( int i = 0; i < mModel->rowCount(); i++ )
{
QModelIndex index = mModel->index( i, 0 );

2 comments on commit bcfe0a8

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied May 18, 2014

This is much better - my only suggestion is that "Favourites" should always be listed first in the tree for quick access

@etiennesky

This comment has been minimized.

Copy link
Contributor Author

@etiennesky etiennesky replied May 18, 2014

Please sign in to comment.