@@ -1611,6 +1611,11 @@ void QgisApp::createMenus()
16111611 mActionWindowSeparator2 = mWindowMenu ->addSeparator ();
16121612#endif
16131613
1614+ // Database Menu
1615+ // don't add it yet, wait for a plugin
1616+ mDatabaseMenu = new QMenu ( tr ( " &Database" ) );
1617+
1618+
16141619 // Help Menu
16151620
16161621 menuBar ()->addSeparator ();
@@ -5657,6 +5662,93 @@ void QgisApp::removePluginMenu( QString name, QAction* action )
56575662 }
56585663}
56595664
5665+ QMenu* QgisApp::getDatabaseMenu ( QString menuName )
5666+ {
5667+ #ifdef Q_WS_MAC
5668+ // Mac doesn't have '&' keyboard shortcuts.
5669+ menuName.remove ( QChar ( ' &' ) );
5670+ #endif
5671+ QString dst = menuName;
5672+ dst.remove ( QChar ( ' &' ) );
5673+
5674+ QAction *before = NULL ;
5675+ QList<QAction*> actions = mDatabaseMenu ->actions ();
5676+ for ( int i = 0 ; i < actions.count (); i++ )
5677+ {
5678+ QString src = actions.at ( i )->text ();
5679+ src.remove ( QChar ( ' &' ) );
5680+
5681+ int comp = dst.localeAwareCompare ( src );
5682+ if ( comp < 0 )
5683+ {
5684+ // Add item before this one
5685+ before = actions.at ( i );
5686+ break ;
5687+ }
5688+ else if ( comp == 0 )
5689+ {
5690+ // Plugin menu item already exists
5691+ return actions.at ( i )->menu ();
5692+ }
5693+ }
5694+ // It doesn't exist, so create
5695+ QMenu *menu = new QMenu ( menuName, this );
5696+ if ( before )
5697+ mDatabaseMenu ->insertMenu ( before, menu );
5698+ else
5699+ mDatabaseMenu ->addMenu ( menu );
5700+
5701+ return menu;
5702+ }
5703+
5704+ void QgisApp::addPluginToDatabaseMenu ( QString name, QAction* action )
5705+ {
5706+ QMenu* menu = getDatabaseMenu ( name );
5707+ menu->addAction ( action );
5708+
5709+ // add the Database menu to the menuBar if not added yet
5710+ if ( mDatabaseMenu ->actions ().count () != 1 )
5711+ return ;
5712+
5713+ QAction* before = NULL ;
5714+ QList<QAction*> actions = menuBar ()->actions ();
5715+ for ( int i = 0 ; i < actions.count (); i++ )
5716+ {
5717+ if ( actions.at ( i )->menu () == mDatabaseMenu )
5718+ return ;
5719+ if ( actions.at ( i )->menu () == mHelpMenu )
5720+ {
5721+ before = actions.at ( i );
5722+ break ;
5723+ }
5724+ }
5725+
5726+ if ( before )
5727+ menuBar ()->insertMenu ( before, mDatabaseMenu );
5728+ else
5729+ menuBar ()->addMenu ( mDatabaseMenu );
5730+ }
5731+
5732+ void QgisApp::removePluginDatabaseMenu ( QString name, QAction* action )
5733+ {
5734+ QMenu* menu = getDatabaseMenu ( name );
5735+ menu->removeAction ( action );
5736+
5737+ // remove the Database menu from the menuBar if there are no more actions
5738+ if ( mDatabaseMenu ->actions ().count () > 0 )
5739+ return ;
5740+
5741+ QList<QAction*> actions = menuBar ()->actions ();
5742+ for ( int i = 0 ; i < actions.count (); i++ )
5743+ {
5744+ if ( actions.at ( i )->menu () == mDatabaseMenu )
5745+ {
5746+ menuBar ()->removeAction ( actions.at ( i ) );
5747+ return ;
5748+ }
5749+ }
5750+ }
5751+
56605752int QgisApp::addPluginToolBarIcon ( QAction * qAction )
56615753{
56625754 mPluginToolBar ->addAction ( qAction );
0 commit comments