Skip to content

Commit bcfe0a8

Browse files
committed
fix browser dock sorting - only files are sorted
1 parent 48ed1cf commit bcfe0a8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/app/qgsbrowserdockwidget.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
229229
return true;
230230
}
231231

232+
bool lessThan( const QModelIndex &left,
233+
const QModelIndex &right ) const
234+
{
235+
// sort file items by name (a file item is not a directory and its parent is a directory)
236+
// this is necessary because more several providers can add items to a directory and
237+
// alphabetical sorting is not preserved
238+
QgsDataItem* leftItem = mModel->dataItem( left );
239+
QgsDataItem* rightItem = mModel->dataItem( right );
240+
if ( leftItem && leftItem->type() != QgsDataItem::Directory &&
241+
leftItem->parent() && leftItem->parent()->type() == QgsDataItem::Directory &&
242+
rightItem && rightItem->type() != QgsDataItem::Directory &&
243+
rightItem->parent() && rightItem->parent()->type() == QgsDataItem::Directory )
244+
{
245+
return QString::localeAwareCompare( leftItem->name(), rightItem->name() ) < 0;
246+
}
247+
248+
// default is to keep original order
249+
return left.row() < right.row();
250+
}
251+
232252
};
233253
QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
234254
QDockWidget( parent ), mModel( NULL ), mProxyModel( NULL )
@@ -308,7 +328,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
308328
mBrowserView->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
309329
mBrowserView->header()->setStretchLastSection( false );
310330

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

0 commit comments

Comments
 (0)