Skip to content

Commit f99ff68

Browse files
author
brushtyler
committedNov 14, 2010
added Database menu and related methods add/remove plugins
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14638 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

5 files changed

+127
-2
lines changed

5 files changed

+127
-2
lines changed
 

‎python/gui/qgisinterface.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ class QgisInterface : QObject
9494
/** Remove action from the plugins menu */
9595
virtual void removePluginMenu(QString name, QAction* action)=0;
9696

97-
/** Add a dock widget to the main window */
97+
/** Add action to the Database menu
98+
@note added in version 1.7 */
99+
virtual void addPluginToDatabaseMenu(QString name, QAction* action)=0;
100+
/** Remove action from the Database menu */
101+
virtual void removePluginDatabaseMenu(QString name, QAction* action)=0;
102+
103+
/** Add a dock widget to the main window
104+
@note added in version 1.7 */
98105
virtual void addDockWidget ( Qt::DockWidgetArea area, QDockWidget * dockwidget )=0;
99106

100107
/** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */

‎src/app/qgisapp.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
56605752
int QgisApp::addPluginToolBarIcon( QAction * qAction )
56615753
{
56625754
mPluginToolBar->addAction( qAction );

‎src/app/qgisapp.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ class QgisApp : public QMainWindow
333333
QMenu *layerMenu() { return mLayerMenu; }
334334
QMenu *settingsMenu() { return mSettingsMenu; }
335335
QMenu *pluginMenu() { return mPluginMenu; }
336+
QMenu *databaseMenu() { return mDatabaseMenu; }
336337
#ifdef Q_WS_MAC
337338
QMenu *firstRightStandardMenu() { return mWindowMenu; }
338339
QMenu *windowMenu() { return mWindowMenu; }
@@ -498,12 +499,18 @@ class QgisApp : public QMainWindow
498499
void showPluginManager();
499500
//! load python support if possible
500501
void loadPythonSupport();
501-
//! Find the QMenu with the given name (ie the user visible text on the menu item)
502+
//! Find the QMenu with the given name within plugin menu (ie the user visible text on the menu item)
502503
QMenu* getPluginMenu( QString menuName );
503504
//! Add the action to the submenu with the given name under the plugin menu
504505
void addPluginToMenu( QString name, QAction* action );
505506
//! Remove the action to the submenu with the given name under the plugin menu
506507
void removePluginMenu( QString name, QAction* action );
508+
//! Find the QMenu with the given name within the Database menu (ie the user visible text on the menu item)
509+
QMenu* getDatabaseMenu( QString menuName );
510+
//! Add the action to the submenu with the given name under the Database menu
511+
void addPluginToDatabaseMenu( QString name, QAction* action );
512+
//! Remove the action to the submenu with the given name under the Database menu
513+
void removePluginDatabaseMenu( QString name, QAction* action );
507514
//! Add an icon to the plugin toolbar
508515
int addPluginToolBarIcon( QAction * qAction );
509516
//! Remove an icon from the plugin toolbar
@@ -1093,6 +1100,8 @@ class QgisApp : public QMainWindow
10931100
QMenu * mPopupMenu;
10941101
//! Top level plugin menu
10951102
QMenu *mPluginMenu;
1103+
//! Top level database menu
1104+
QMenu *mDatabaseMenu;
10961105
//! Popup menu for the map overview tools
10971106
QMenu *toolPopupOverviews;
10981107
//! Popup menu for the display tools

‎src/app/qgisappinterface.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ void QgisAppInterface::removePluginMenu( QString name, QAction* action )
144144
qgis->removePluginMenu( name, action );
145145
}
146146

147+
void QgisAppInterface::addPluginToDatabaseMenu( QString name, QAction* action )
148+
{
149+
qgis->addPluginToDatabaseMenu( name, action );
150+
}
151+
152+
void QgisAppInterface::removePluginDatabaseMenu( QString name, QAction* action )
153+
{
154+
qgis->removePluginDatabaseMenu( name, action );
155+
}
156+
147157
int QgisAppInterface::addToolBarIcon( QAction * qAction )
148158
{
149159
// add the menu to the master Plugins menu
@@ -242,6 +252,7 @@ QMenu *QgisAppInterface::viewMenu() { return qgis->viewMenu(); }
242252
QMenu *QgisAppInterface::layerMenu() { return qgis->layerMenu(); }
243253
QMenu *QgisAppInterface::settingsMenu() { return qgis->settingsMenu(); }
244254
QMenu *QgisAppInterface::pluginMenu() { return qgis->pluginMenu(); }
255+
QMenu *QgisAppInterface::databaseMenu() { return qgis->databaseMenu(); }
245256
QMenu *QgisAppInterface::firstRightStandardMenu() { return qgis->firstRightStandardMenu(); }
246257
QMenu *QgisAppInterface::windowMenu() { return qgis->windowMenu(); }
247258
QMenu *QgisAppInterface::helpMenu() { return qgis->helpMenu(); }

‎src/app/qgisappinterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class QgisAppInterface : public QgisInterface
107107
/** Remove action from the plugins menu */
108108
void removePluginMenu( QString name, QAction* action );
109109

110+
/** Add action to the Database menu */
111+
void addPluginToDatabaseMenu( QString name, QAction* action );
112+
/** Remove action from the Database menu */
113+
void removePluginDatabaseMenu( QString name, QAction* action );
114+
110115
/** Add a dock widget to the main window */
111116
void addDockWidget( Qt::DockWidgetArea area, QDockWidget * dockwidget );
112117

@@ -143,6 +148,7 @@ class QgisAppInterface : public QgisInterface
143148
virtual QMenu *layerMenu();
144149
virtual QMenu *settingsMenu();
145150
virtual QMenu *pluginMenu();
151+
virtual QMenu *databaseMenu();
146152
virtual QMenu *firstRightStandardMenu();
147153
virtual QMenu *windowMenu();
148154
virtual QMenu *helpMenu();

0 commit comments

Comments
 (0)
Please sign in to comment.