Skip to content
Permalink
Browse files

added Database menu and related methods add/remove plugins

git-svn-id: http://svn.osgeo.org/qgis/trunk@14638 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler
brushtyler committed Nov 14, 2010
1 parent 7697714 commit 45ba237967fe1c8ed77d79dfb6ccfddfe533f2a0
Showing with 127 additions and 2 deletions.
  1. +8 −1 python/gui/qgisinterface.sip
  2. +92 −0 src/app/qgisapp.cpp
  3. +10 −1 src/app/qgisapp.h
  4. +11 −0 src/app/qgisappinterface.cpp
  5. +6 −0 src/app/qgisappinterface.h
@@ -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. */
@@ -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();
@@ -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 );
@@ -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; }
@@ -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
@@ -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
@@ -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
@@ -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(); }
@@ -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 );

@@ -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();

0 comments on commit 45ba237

Please sign in to comment.
You can’t perform that action at this time.