[QGIS Commit] r14638 - in trunk/qgis: python/gui src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Nov 14 09:00:57 EST 2010


Author: brushtyler
Date: 2010-11-14 06:00:57 -0800 (Sun, 14 Nov 2010)
New Revision: 14638

Modified:
   trunk/qgis/python/gui/qgisinterface.sip
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
   trunk/qgis/src/app/qgisappinterface.cpp
   trunk/qgis/src/app/qgisappinterface.h
Log:
added Database menu and related methods add/remove plugins


Modified: trunk/qgis/python/gui/qgisinterface.sip
===================================================================
--- trunk/qgis/python/gui/qgisinterface.sip	2010-11-14 13:27:03 UTC (rev 14637)
+++ trunk/qgis/python/gui/qgisinterface.sip	2010-11-14 14:00:57 UTC (rev 14638)
@@ -94,7 +94,14 @@
     /** 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. */

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2010-11-14 13:27:03 UTC (rev 14637)
+++ trunk/qgis/src/app/qgisapp.cpp	2010-11-14 14:00:57 UTC (rev 14638)
@@ -1611,6 +1611,11 @@
   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 @@
   }
 }
 
+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 );

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2010-11-14 13:27:03 UTC (rev 14637)
+++ trunk/qgis/src/app/qgisapp.h	2010-11-14 14:00:57 UTC (rev 14638)
@@ -333,6 +333,7 @@
     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 @@
     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 @@
     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

Modified: trunk/qgis/src/app/qgisappinterface.cpp
===================================================================
--- trunk/qgis/src/app/qgisappinterface.cpp	2010-11-14 13:27:03 UTC (rev 14637)
+++ trunk/qgis/src/app/qgisappinterface.cpp	2010-11-14 14:00:57 UTC (rev 14638)
@@ -144,6 +144,16 @@
   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::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(); }

Modified: trunk/qgis/src/app/qgisappinterface.h
===================================================================
--- trunk/qgis/src/app/qgisappinterface.h	2010-11-14 13:27:03 UTC (rev 14637)
+++ trunk/qgis/src/app/qgisappinterface.h	2010-11-14 14:00:57 UTC (rev 14638)
@@ -107,6 +107,11 @@
     /** 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 @@
     virtual QMenu *layerMenu();
     virtual QMenu *settingsMenu();
     virtual QMenu *pluginMenu();
+    virtual QMenu *databaseMenu();
     virtual QMenu *firstRightStandardMenu();
     virtual QMenu *windowMenu();
     virtual QMenu *helpMenu();



More information about the QGIS-commit mailing list