Skip to content

Commit c80a1f4

Browse files
committedJul 12, 2013
Group and sort providers in browser listing by type then name
1 parent 20e969e commit c80a1f4

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed
 

‎src/core/qgsbrowsermodel.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828

2929
#include <QSettings>
3030

31+
// sort function for QList<QgsDataItem*>, e.g. sorted/grouped provider listings
32+
static bool cmpByDataItemName_( QgsDataItem* a, QgsDataItem* b )
33+
{
34+
return QString::localeAwareCompare( a->name(), b->name() ) < 0;
35+
}
36+
3137
QgsBrowserModel::QgsBrowserModel( QObject *parent )
3238
: QAbstractItemModel( parent )
3339
, mFavourites( 0 )
@@ -109,7 +115,10 @@ void QgsBrowserModel::addRootItems()
109115

110116
// Add non file top level items
111117
QStringList providersList = QgsProviderRegistry::instance()->providerList();
112-
providersList.sort();
118+
119+
// container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
120+
QMap<int, QgsDataItem *> providerMap;
121+
113122
foreach ( QString key, providersList )
114123
{
115124
QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( key );
@@ -142,7 +151,22 @@ void QgsBrowserModel::addRootItems()
142151
{
143152
QgsDebugMsg( "Add new top level item : " + item->name() );
144153
connectItem( item );
145-
mRootItems << item;
154+
providerMap.insertMulti( capabilities, item );
155+
}
156+
}
157+
158+
// add as sorted groups by QgsDataProvider::DataCapability enum
159+
foreach ( int key, providerMap.uniqueKeys() )
160+
{
161+
QList<QgsDataItem *> providerGroup = providerMap.values( key );
162+
if ( providerGroup.size() > 1 )
163+
{
164+
qSort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ );
165+
}
166+
167+
foreach ( QgsDataItem * ditem, providerGroup )
168+
{
169+
mRootItems << ditem;
146170
}
147171
}
148172
}

0 commit comments

Comments
 (0)
Please sign in to comment.