Skip to content

Commit

Permalink
fix browser dock sorting - only files are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed May 17, 2014
1 parent 48ed1cf commit bcfe0a8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down

2 comments on commit bcfe0a8

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

@etiennesky
Copy link
Contributor Author

@etiennesky etiennesky commented on bcfe0a8 May 18, 2014 via email

Choose a reason for hiding this comment

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

Please sign in to comment.