Skip to content

Commit

Permalink
sort panels alphabeticaly in context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 26, 2011
1 parent 5712369 commit bafa99c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -374,6 +374,11 @@ static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )
}
}

static bool cmpByText_( QAction* a, QAction* b )
{
return QString::localeAwareCompare( a->text(), b->text() ) < 0;
}


QgisApp *QgisApp::smInstance = 0;

Expand Down Expand Up @@ -1138,6 +1143,9 @@ void QgisApp::createToolBars()
toolbarMenuActions << toolBar->toggleViewAction();
}

// sort actions in toolbar menu
qSort( toolbarMenuActions.begin(), toolbarMenuActions.end(), cmpByText_ );

mToolbarMenu->addActions( toolbarMenuActions );

// select tool button
Expand Down Expand Up @@ -7131,3 +7139,46 @@ void QgisApp::toolButtonActionTriggered( QAction *action )

bt->setDefaultAction( action );
}

QMenu* QgisApp::createPopupMenu()
{
QMenu* menu = QMainWindow::createPopupMenu();
QList< QAction* > al = menu->actions();
QList< QAction* > panels, toolbars;

if( !al.isEmpty() )
{
bool found = false;
for ( int i = 0; i < al.size(); ++i )
{
if ( al[ i ]->isSeparator() )
{
found = true;
continue;
}

if ( !found )
{
panels.append( al[ i ] );
}
else
{
toolbars.append( al[ i ] );
}
}

qSort( panels.begin(), panels.end(), cmpByText_ );
foreach( QAction* a, panels )
{
menu->addAction( a );
}
menu->addSeparator();
qSort( toolbars.begin(), toolbars.end(), cmpByText_ );
foreach( QAction* a, toolbars )
{
menu->addAction( a );
}
}

return menu;
}
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -207,6 +207,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
/**Deletes a composer and removes entry from Set*/
void deleteComposer( QgsComposer* c );

/** overloaded function used to sort menu entries alphabetically */
QMenu* createPopupMenu();


//! Actions to be inserted in menus and toolbars
QAction *actionNewProject() { return mActionNewProject; }
Expand Down Expand Up @@ -1132,6 +1135,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

//! project changed
void projectChanged( const QDomDocument & );

bool cmpByText( QAction* a, QAction* b );
};

#endif

0 comments on commit bafa99c

Please sign in to comment.