Skip to content

Commit

Permalink
added Database menu and related methods add/remove plugins
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14638 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Nov 14, 2010
1 parent 7697714 commit 45ba237
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 2 deletions.
9 changes: 8 additions & 1 deletion python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ class QgisInterface : QObject
/** Remove action from the plugins menu */
virtual void removePluginMenu(QString name, QAction* action)=0;

/** Add a dock widget to the main window */
/** Add action to the Database menu
@note added in version 1.7 */
virtual void addPluginToDatabaseMenu(QString name, QAction* action)=0;
/** Remove action from the Database menu */
virtual void removePluginDatabaseMenu(QString name, QAction* action)=0;

/** Add a dock widget to the main window
@note added in version 1.7 */
virtual void addDockWidget ( Qt::DockWidgetArea area, QDockWidget * dockwidget )=0;

/** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */
Expand Down
92 changes: 92 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,11 @@ void QgisApp::createMenus()
mActionWindowSeparator2 = mWindowMenu->addSeparator();
#endif

// Database Menu
// don't add it yet, wait for a plugin
mDatabaseMenu = new QMenu( tr( "&Database" ) );


// Help Menu

menuBar()->addSeparator();
Expand Down Expand Up @@ -5657,6 +5662,93 @@ void QgisApp::removePluginMenu( QString name, QAction* action )
}
}

QMenu* QgisApp::getDatabaseMenu( QString menuName )
{
#ifdef Q_WS_MAC
// Mac doesn't have '&' keyboard shortcuts.
menuName.remove( QChar( '&' ) );
#endif
QString dst = menuName;
dst.remove( QChar( '&' ) );

QAction *before = NULL;
QList<QAction*> actions = mDatabaseMenu->actions();
for ( int i = 0; i < actions.count(); i++ )
{
QString src = actions.at( i )->text();
src.remove( QChar( '&' ) );

int comp = dst.localeAwareCompare( src );
if ( comp < 0 )
{
// Add item before this one
before = actions.at( i );
break;
}
else if ( comp == 0 )
{
// Plugin menu item already exists
return actions.at( i )->menu();
}
}
// It doesn't exist, so create
QMenu *menu = new QMenu( menuName, this );
if ( before )
mDatabaseMenu->insertMenu( before, menu );
else
mDatabaseMenu->addMenu( menu );

return menu;
}

void QgisApp::addPluginToDatabaseMenu( QString name, QAction* action )
{
QMenu* menu = getDatabaseMenu( name );
menu->addAction( action );

// add the Database menu to the menuBar if not added yet
if ( mDatabaseMenu->actions().count() != 1 )
return;

QAction* before = NULL;
QList<QAction*> actions = menuBar()->actions();
for ( int i = 0; i < actions.count(); i++ )
{
if ( actions.at( i )->menu() == mDatabaseMenu )
return;
if ( actions.at( i )->menu() == mHelpMenu )
{
before = actions.at( i );
break;
}
}

if ( before )
menuBar()->insertMenu( before, mDatabaseMenu );
else
menuBar()->addMenu( mDatabaseMenu );
}

void QgisApp::removePluginDatabaseMenu( QString name, QAction* action )
{
QMenu* menu = getDatabaseMenu( name );
menu->removeAction( action );

// remove the Database menu from the menuBar if there are no more actions
if ( mDatabaseMenu->actions().count() > 0 )
return;

QList<QAction*> actions = menuBar()->actions();
for ( int i = 0; i < actions.count(); i++ )
{
if ( actions.at( i )->menu() == mDatabaseMenu )
{
menuBar()->removeAction( actions.at( i ) );
return;
}
}
}

int QgisApp::addPluginToolBarIcon( QAction * qAction )
{
mPluginToolBar->addAction( qAction );
Expand Down
11 changes: 10 additions & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class QgisApp : public QMainWindow
QMenu *layerMenu() { return mLayerMenu; }
QMenu *settingsMenu() { return mSettingsMenu; }
QMenu *pluginMenu() { return mPluginMenu; }
QMenu *databaseMenu() { return mDatabaseMenu; }
#ifdef Q_WS_MAC
QMenu *firstRightStandardMenu() { return mWindowMenu; }
QMenu *windowMenu() { return mWindowMenu; }
Expand Down Expand Up @@ -498,12 +499,18 @@ class QgisApp : public QMainWindow
void showPluginManager();
//! load python support if possible
void loadPythonSupport();
//! Find the QMenu with the given name (ie the user visible text on the menu item)
//! Find the QMenu with the given name within plugin menu (ie the user visible text on the menu item)
QMenu* getPluginMenu( QString menuName );
//! Add the action to the submenu with the given name under the plugin menu
void addPluginToMenu( QString name, QAction* action );
//! Remove the action to the submenu with the given name under the plugin menu
void removePluginMenu( QString name, QAction* action );
//! Find the QMenu with the given name within the Database menu (ie the user visible text on the menu item)
QMenu* getDatabaseMenu( QString menuName );
//! Add the action to the submenu with the given name under the Database menu
void addPluginToDatabaseMenu( QString name, QAction* action );
//! Remove the action to the submenu with the given name under the Database menu
void removePluginDatabaseMenu( QString name, QAction* action );
//! Add an icon to the plugin toolbar
int addPluginToolBarIcon( QAction * qAction );
//! Remove an icon from the plugin toolbar
Expand Down Expand Up @@ -1093,6 +1100,8 @@ class QgisApp : public QMainWindow
QMenu * mPopupMenu;
//! Top level plugin menu
QMenu *mPluginMenu;
//! Top level database menu
QMenu *mDatabaseMenu;
//! Popup menu for the map overview tools
QMenu *toolPopupOverviews;
//! Popup menu for the display tools
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ void QgisAppInterface::removePluginMenu( QString name, QAction* action )
qgis->removePluginMenu( name, action );
}

void QgisAppInterface::addPluginToDatabaseMenu( QString name, QAction* action )
{
qgis->addPluginToDatabaseMenu( name, action );
}

void QgisAppInterface::removePluginDatabaseMenu( QString name, QAction* action )
{
qgis->removePluginDatabaseMenu( name, action );
}

int QgisAppInterface::addToolBarIcon( QAction * qAction )
{
// add the menu to the master Plugins menu
Expand Down Expand Up @@ -242,6 +252,7 @@ QMenu *QgisAppInterface::viewMenu() { return qgis->viewMenu(); }
QMenu *QgisAppInterface::layerMenu() { return qgis->layerMenu(); }
QMenu *QgisAppInterface::settingsMenu() { return qgis->settingsMenu(); }
QMenu *QgisAppInterface::pluginMenu() { return qgis->pluginMenu(); }
QMenu *QgisAppInterface::databaseMenu() { return qgis->databaseMenu(); }
QMenu *QgisAppInterface::firstRightStandardMenu() { return qgis->firstRightStandardMenu(); }
QMenu *QgisAppInterface::windowMenu() { return qgis->windowMenu(); }
QMenu *QgisAppInterface::helpMenu() { return qgis->helpMenu(); }
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ class QgisAppInterface : public QgisInterface
/** Remove action from the plugins menu */
void removePluginMenu( QString name, QAction* action );

/** Add action to the Database menu */
void addPluginToDatabaseMenu( QString name, QAction* action );
/** Remove action from the Database menu */
void removePluginDatabaseMenu( QString name, QAction* action );

/** Add a dock widget to the main window */
void addDockWidget( Qt::DockWidgetArea area, QDockWidget * dockwidget );

Expand Down Expand Up @@ -143,6 +148,7 @@ class QgisAppInterface : public QgisInterface
virtual QMenu *layerMenu();
virtual QMenu *settingsMenu();
virtual QMenu *pluginMenu();
virtual QMenu *databaseMenu();
virtual QMenu *firstRightStandardMenu();
virtual QMenu *windowMenu();
virtual QMenu *helpMenu();
Expand Down

0 comments on commit 45ba237

Please sign in to comment.