Skip to content

Commit

Permalink
browser sorting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 28, 2014
1 parent 302480d commit 59c88cc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
22 changes: 0 additions & 22 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -228,27 +228,6 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
// accept anything else
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 @@ -321,7 +300,6 @@ 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
2 changes: 1 addition & 1 deletion src/core/qgsdataitem.cpp
Expand Up @@ -223,7 +223,7 @@ void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
{
// sort items by type, so directories are before data items
if ( mChildren[i]->mType == child->mType &&
mChildren[i]->mName.localeAwareCompare( child->mName ) >= 0 )
mChildren[i]->mName.localeAwareCompare( child->mName ) > 0 )
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Expand Up @@ -28,6 +28,8 @@ QgsGrassLocationItem::QgsGrassLocationItem( QgsDataItem* parent, QString path )
QFileInfo fi( path );
mName = fi.baseName();
mIcon = QIcon( QgsApplication::getThemePixmap( "grass_location.png" ) );
// set Directory type so that when sorted it gets into dirs (after the dir it represents)
mType = QgsDataItem::Directory;
}
QgsGrassLocationItem::~QgsGrassLocationItem() {}

Expand Down

0 comments on commit 59c88cc

Please sign in to comment.