[QGIS Commit] r9257 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Sep 5 01:43:33 EDT 2008


Author: telwertowski
Date: 2008-09-05 01:43:33 -0400 (Fri, 05 Sep 2008)
New Revision: 9257

Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
Log:
Improve insertion of plugins into plugin menu. Allow any number of items at top and start inserting below them but above the Python separator if it exists at the bottom.


Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2008-09-05 05:32:11 UTC (rev 9256)
+++ trunk/qgis/src/app/qgisapp.cpp	2008-09-05 05:43:33 UTC (rev 9257)
@@ -1162,16 +1162,9 @@
   mPluginMenu = menuBar()->addMenu( tr( "&Plugins" ) );
 
   mPluginMenu->addAction( mActionManagePlugins );
-  mActionPluginSeparator1 = mPluginMenu->addSeparator();
+  mActionPluginSeparator1 = NULL;  // plugin list separator will be created when the first plugin is loaded
+  mActionPluginSeparator2 = NULL;  // python separator will be created only if python is found
 
-  // Add the plugin manager action to it
-  //actionPluginManager->addTo(mPluginMenu);
-  // Add separator. Plugins will add their menus to this
-  // menu when they are loaded by the plugin manager
-  //mPluginMenu->insertSeparator();
-  // Add to the menubar
-  //menuBar()->insertItem(tr("&Plugins"), mPluginMenu, -1, menuBar()->count() - 1);
-
 #ifdef Q_WS_MAC
   // Window Menu
 
@@ -3568,21 +3561,23 @@
 #endif
 }
 
-#ifdef Q_WS_MAC
 void QgisApp::addWindow( QAction *action )
 {
+#ifdef Q_WS_MAC
   mWindowActions->addAction( action );
   mWindowMenu->addAction( action );
   action->setCheckable( true );
   action->setChecked( true );
+#endif
 }
 
 void QgisApp::removeWindow( QAction *action )
 {
+#ifdef Q_WS_MAC
   mWindowActions->removeAction( action );
   mWindowMenu->removeAction( action );
+#endif
 }
-#endif
 
 void QgisApp::stopRendering()
 {
@@ -4193,9 +4188,10 @@
 
   if ( mPythonUtils && mPythonUtils->isEnabled() )
   {
-    mActionShowPythonDialog = new QAction( tr( "Python console" ), this );
+    mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
     connect( mActionShowPythonDialog, SIGNAL( triggered() ), this, SLOT( showPythonDialog() ) );
 
+    mActionPluginSeparator2 = mPluginMenu->addSeparator();
     mPluginMenu->addAction( mActionShowPythonDialog );
     std::cout << "Python support ENABLED :-) " << std::endl; // OK
 
@@ -4729,32 +4725,38 @@
 
 QMenu* QgisApp::getPluginMenu( QString menuName )
 {
-  // This is going to record the menu item that the potentially new
-  // menu item is going to be inserted before. A value of 0 will a new
-  // menu item to be appended.
-  QAction* before = 0;
-
-  QList<QAction*> actions = mPluginMenu->actions();
-  // Avoid 1 because the first item (number 0) is 'Plugin Manager',
-  // which we  want to stay first. Search in reverse order as that
-  // makes it easier to find out where which item a new menu item
-  // should go before (since the insertMenu() function requires a
-  // 'before' argument).
-  for ( unsigned int i = actions.count() - 1; i > 0; --i )
+  /* Plugin menu items are below the plugin separator (which may not exist yet
+   * if no plugins are loaded) and above the python separator. If python is not
+   * present, there is no python separator and the plugin list is at the bottom
+   * of the menu.
+   */
+  QAction *before = mActionPluginSeparator2;  // python separator or end of list
+  if ( !mActionPluginSeparator1 )
   {
-    if ( actions.at( i )->text() == menuName )
+    // First plugin - create plugin list separator
+    mActionPluginSeparator1 = mPluginMenu->insertSeparator( before );
+  }
+  else
+  {
+    // Plugins exist - search between plugin separator and python separator or end of list
+    QList<QAction*> actions = mPluginMenu->actions();
+    int end = mActionPluginSeparator2 ? actions.indexOf( mActionPluginSeparator2 ) : actions.count();
+    for ( int i = actions.indexOf( mActionPluginSeparator1 ) + 1; i < end; i++ )
     {
-      return actions.at( i )->menu();
+      int comp = menuName.localeAwareCompare( actions.at( i )->text() );
+      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();
+      }
     }
-    // Find out where to put the menu item, assuming that it is a new one
-    //
-    // This bit of code assumes that the menu items are already in
-    // alphabetical order, which they will be if the menus are all
-    // created using this function.
-    if ( menuName.localeAwareCompare( actions.at( i )->text() ) <= 0 )
-      before = actions.at( i );
   }
-
   // It doesn't exist, so create
   QMenu* menu = new QMenu( menuName, this );
   // Where to put it? - we worked that out above...
@@ -4777,6 +4779,14 @@
   {
     mPluginMenu->removeAction( menu->menuAction() );
   }
+  // Remove separator above plugins in Plugin menu if no plugins remain
+  QList<QAction*> actions = mPluginMenu->actions();
+  int end = mActionPluginSeparator2 ? actions.indexOf( mActionPluginSeparator2 ) : actions.count();
+  if ( actions.indexOf( mActionPluginSeparator1 ) + 1 == end )
+  {
+    mPluginMenu->removeAction( mActionPluginSeparator1 );
+    mActionPluginSeparator1 = NULL;
+  }
 }
 
 int QgisApp::addPluginToolBarIcon( QAction * qAction )

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2008-09-05 05:32:11 UTC (rev 9256)
+++ trunk/qgis/src/app/qgisapp.h	2008-09-05 05:43:33 UTC (rev 9257)
@@ -180,12 +180,12 @@
      * parent class, it will also add it to the View menu list of toolbars.*/
     QToolBar *addToolBar( QString name );
 
-#ifdef Q_WS_MAC
-    //! Add window item to Window menu
+    /** Add window to Window menu. The action title is the window title
+     * and the action should raise, unminimize and activate the window. */
     void addWindow( QAction *action );
-    //! Remove window item from Window menu
+    /** Remove window from Window menu. Calling this is necessary only for
+     * windows which are hidden rather than deleted when closed. */
     void removeWindow( QAction *action );
-#endif
 
     //! Actions to be inserted in menus and toolbars
     QAction *actionNewProject() { return mActionNewProject; }
@@ -260,6 +260,9 @@
 
     QAction *actionManagePlugins() { return mActionManagePlugins; }
     QAction *actionPluginSeparator1() { return mActionPluginSeparator1; }
+    QAction *actionPluginListSeparator() { return mActionPluginSeparator1; }
+    QAction *actionPluginSeparator2() { return mActionPluginSeparator2; }
+    QAction *actionPluginPythonSeparator() { return mActionPluginSeparator2; }
     QAction *actionShowPythonDialog() { return mActionShowPythonDialog; }
 
     QAction *actionToggleFullScreen() { return mActionToggleFullScreen; }
@@ -290,7 +293,11 @@
     QMenu *settingsMenu() { return mSettingsMenu; }
     QMenu *pluginMenu() { return mPluginMenu; }
 #ifdef Q_WS_MAC
+    QMenu *firstRightStandardMenu() { return mWindowMenu; }
     QMenu *windowMenu() { return mWindowMenu; }
+#else
+    QMenu *firstRightStandardMenu() { return mHelpMenu; }
+    QMenu *windowMenu() { return NULL; }
 #endif
     QMenu *helpMenu() { return mHelpMenu; }
 
@@ -718,6 +725,7 @@
 
     QAction *mActionManagePlugins;
     QAction *mActionPluginSeparator1;
+    QAction *mActionPluginSeparator2;
     QAction *mActionShowPythonDialog;
 
     QAction *mActionToggleFullScreen;



More information about the QGIS-commit mailing list