From f01c6ad8c820a68e3d3050921b22781e100209d2 Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Sun, 10 Jun 2012 07:16:52 -0600 Subject: [PATCH 1/2] =?UTF-8?q?Simple=20fix=20for=20#5754=20(Mac=20OS-spec?= =?UTF-8?q?ific).=20Better=20fix=20would=20be=20to=20make=20a=20method=20t?= =?UTF-8?q?hat=20set=20all=20QAction=20additions=20to=20base=20menus=20(su?= =?UTF-8?q?bmenus=20ok)=20to=20QAction::NoRole.=20This=20would=20keep=20an?= =?UTF-8?q?y=20new=20action=20from=20hijacking=20the=20Mac=20app's=20About?= =?UTF-8?q?=20or=20Preferences=E2=80=A6=20menus.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See: http://doc.qt.nokia.com/4.7.1/qmenubar.html#qmenubar-on-mac-os-x --- src/app/qgisapp.cpp | 9 +++++++++ src/app/qgisapp.h | 1 + src/ui/qgisapp.ui | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 3d340accf0f7..8518078b10df 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -928,6 +928,12 @@ void QgisApp::createActions() connect( mActionCustomization, SIGNAL( triggered() ), this, SLOT( customize() ) ); #ifdef Q_WS_MAC + // copy of Options action that gets moved to app Preferences... + mActionOptionsMac = new QAction( mActionOptions->text(), this ); + mActionOptionsMac->setMenuRole( QAction::NoRole ); + mActionOptionsMac->setIcon( mActionOptions->icon() ); + connect( mActionOptionsMac, SIGNAL( triggered() ), this, SLOT( options() ) ); + // Window Menu Items mActionWindowMinimize = new QAction( tr( "Minimize" ), this ); @@ -1158,6 +1164,9 @@ void QgisApp::createMenus() } #ifdef Q_WS_MAC + // copy back the Options action after assigned to app Preferences... + mSettingsMenu->addAction( mActionOptionsMac ); + // Window Menu mWindowMenu = menuBar()->addMenu( tr( "&Window" ) ); diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index ba853fb66cd1..241972efe4d1 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -978,6 +978,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow // actions for menus and toolbars ----------------- #ifdef Q_WS_MAC + QAction *mActionOptionsMac; QAction *mActionWindowMinimize; QAction *mActionWindowZoom; QAction *mActionWindowSeparator1; diff --git a/src/ui/qgisapp.ui b/src/ui/qgisapp.ui index 16514b81ceb8..762f32c981ec 100644 --- a/src/ui/qgisapp.ui +++ b/src/ui/qgisapp.ui @@ -1378,6 +1378,9 @@ Configure shortcuts... + + QAction::NoRole + From 7f1a4e28d12e3fc2bd40d596a4f09138ed368f79 Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Sun, 10 Jun 2012 16:12:58 -0600 Subject: [PATCH 2/2] Fix for #5753 Does not address third-party plugins that add their own menus. They should use (here for Python): menu_bar = self.iface.mainWindow().menuBar() menu_bar.insertMenu( self.iface.firstRightStandardMenu().menuAction(), self.my_plugins_menu ) Ideally, a new QgisInterface public slot pair of addMenuToMenuBar(QMenu)/removeMenuFromMenuBar(QMenu) should be added, to help plugin developers put their menus in the correct place. Deletion in GdalTools.py is redundant add-to-menu code. It moved the Raster menu to -1 on the menubar (between Window and Help on Mac). --- python/plugins/GdalTools/GdalTools.py | 5 ----- src/app/qgisapp.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/python/plugins/GdalTools/GdalTools.py b/python/plugins/GdalTools/GdalTools.py index d5d9893abe02..914233c61b2c 100644 --- a/python/plugins/GdalTools/GdalTools.py +++ b/python/plugins/GdalTools/GdalTools.py @@ -264,11 +264,6 @@ def initGui( self ): QObject.connect( self.settings, SIGNAL( "triggered()" ), self.doSettings ) self.menu.addAction( self.settings ) - menu_bar = self.iface.mainWindow().menuBar() - actions = menu_bar.actions() - lastAction = actions[ len( actions ) - 1 ] - menu_bar.insertMenu( lastAction, self.menu ) - def unload( self ): if not valid: return pass diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 8518078b10df..c0cb5d2e5cbe 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1169,7 +1169,7 @@ void QgisApp::createMenus() // Window Menu - mWindowMenu = menuBar()->addMenu( tr( "&Window" ) ); + mWindowMenu = new QMenu( tr( "Window" ), this ); mWindowMenu->addAction( mActionWindowMinimize ); mWindowMenu->addAction( mActionWindowZoom ); @@ -1177,6 +1177,9 @@ void QgisApp::createMenus() mWindowMenu->addAction( mActionWindowAllToFront ); mWindowMenu->addSeparator(); + + // insert before Help menu, as per Mac OS convention + menuBar()->insertMenu( mHelpMenu->menuAction(), mWindowMenu ); #endif // Database Menu @@ -5793,7 +5796,7 @@ void QgisApp::addPluginToDatabaseMenu( QString name, QAction* action ) before = actions.at( i ); break; } - else if ( actions.at( i )->menu() == mHelpMenu ) + else if ( actions.at( i )->menu() == firstRightStandardMenu() ) { before = actions.at( i ); break; @@ -5855,7 +5858,7 @@ void QgisApp::addPluginToWebMenu( QString name, QAction* action ) { if ( actions.at( i )->menu() == mWebMenu ) return; - if ( actions.at( i )->menu() == mHelpMenu ) + if ( actions.at( i )->menu() == firstRightStandardMenu() ) { before = actions.at( i ); break;