Skip to content

Commit 6768e6a

Browse files
etienneskytimlinux
authored andcommitted
sort items in browser dock: sort items by type, so directories are before data items, sort top-level provider items by name
Signed-off-by: Tim Sutton <tim@linfiniti.com>
1 parent efac197 commit 6768e6a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/core/qgsbrowsermodel.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ void QgsBrowserModel::addRootItems()
5454
}
5555

5656
// Add non file top level items
57-
foreach( QString key, QgsProviderRegistry::instance()->providerList() )
57+
QStringList providersList = QgsProviderRegistry::instance()->providerList();
58+
providersList.sort();
59+
foreach( QString key, providersList )
5860
{
5961
QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( key );
6062
if ( !library )

src/core/qgsdataitem.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,23 @@ void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
206206
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( mChildren.size() ).arg( child->mName ) );
207207

208208
int i;
209-
for ( i = 0; i < mChildren.size(); i++ )
209+
if ( type() == Directory )
210210
{
211-
if ( mChildren[i]->mName.localeAwareCompare( child->mName ) >= 0 )
212-
break;
211+
for ( i = 0; i < mChildren.size(); i++ )
212+
{
213+
// sort items by type, so directories are before data items
214+
if ( mChildren[i]->mType == child->mType &&
215+
mChildren[i]->mName.localeAwareCompare( child->mName ) >= 0 )
216+
break;
217+
}
218+
}
219+
else
220+
{
221+
for ( i = 0; i < mChildren.size(); i++ )
222+
{
223+
if ( mChildren[i]->mName.localeAwareCompare( child->mName ) >= 0 )
224+
break;
225+
}
213226
}
214227

215228
if ( refresh )

0 commit comments

Comments
 (0)