Skip to content

Commit de6f642

Browse files
committed
Fix for #5753, for all platforms.
This fix takes a different approach to dynamically building standard plugin category menus, by putting them after or before the Raster menu, which is already in /src/ui/qgisapp.ui. If third-party plugins use firstRightStandardMenu() as a key for placing their plugin menus before it, this fix should now keep the menubar properly ordered, with dynamically added/removed standard plugin category menus, as such: File, Edit, View, Layer, Settings, Plugins, [Vector], Raster, [Database], [Web], [Plugin-added-menus], Window (on Mac), Help
1 parent 65dcce9 commit de6f642

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

src/app/qgisapp.cpp

+37-10
Original file line numberDiff line numberDiff line change
@@ -5814,22 +5814,31 @@ void QgisApp::addPluginToDatabaseMenu( QString name, QAction* action )
58145814
{
58155815
if ( actions.at( i )->menu() == mDatabaseMenu )
58165816
return;
5817+
5818+
// goes before Web menu, if present
58175819
if ( actions.at( i )->menu() == mWebMenu )
58185820
{
58195821
before = actions.at( i );
58205822
break;
58215823
}
5822-
else if ( actions.at( i )->menu() == firstRightStandardMenu() )
5824+
}
5825+
for ( int i = 0; i < actions.count(); i++ )
5826+
{
5827+
// defaults to after Raster menu, which is already in qgisapp.ui
5828+
if ( actions.at( i )->menu() == mRasterMenu )
58235829
{
5824-
before = actions.at( i );
5825-
break;
5830+
if ( !before )
5831+
{
5832+
before = actions.at( i += 1 );
5833+
break;
5834+
}
58265835
}
58275836
}
5828-
58295837
if ( before )
58305838
menuBar()->insertMenu( before, mDatabaseMenu );
58315839
else
5832-
menuBar()->addMenu( mDatabaseMenu );
5840+
// fallback insert
5841+
menuBar()->insertMenu( firstRightStandardMenu()->menuAction(), mDatabaseMenu );
58335842
}
58345843

58355844
void QgisApp::addPluginToRasterMenu( QString name, QAction* action )
@@ -5853,6 +5862,8 @@ void QgisApp::addPluginToVectorMenu( QString name, QAction* action )
58535862
{
58545863
if ( actions.at( i )->menu() == mVectorMenu )
58555864
return;
5865+
5866+
// goes before Raster menu, which is already in qgisapp.ui
58565867
if ( actions.at( i )->menu() == mRasterMenu )
58575868
{
58585869
before = actions.at( i );
@@ -5863,7 +5874,8 @@ void QgisApp::addPluginToVectorMenu( QString name, QAction* action )
58635874
if ( before )
58645875
menuBar()->insertMenu( before, mVectorMenu );
58655876
else
5866-
menuBar()->addMenu( mVectorMenu );
5877+
// fallback insert
5878+
menuBar()->insertMenu( firstRightStandardMenu()->menuAction(), mVectorMenu );
58675879
}
58685880

58695881
void QgisApp::addPluginToWebMenu( QString name, QAction* action )
@@ -5879,19 +5891,34 @@ void QgisApp::addPluginToWebMenu( QString name, QAction* action )
58795891
QList<QAction*> actions = menuBar()->actions();
58805892
for ( int i = 0; i < actions.count(); i++ )
58815893
{
5894+
// goes after Database menu, if present
5895+
if ( actions.at( i )->menu() == mDatabaseMenu )
5896+
{
5897+
before = actions.at( i += 1 );
5898+
// don't break here
5899+
}
5900+
58825901
if ( actions.at( i )->menu() == mWebMenu )
58835902
return;
5884-
if ( actions.at( i )->menu() == firstRightStandardMenu() )
5903+
}
5904+
for ( int i = 0; i < actions.count(); i++ )
5905+
{
5906+
// defaults to after Raster menu, which is already in qgisapp.ui
5907+
if ( actions.at( i )->menu() == mRasterMenu )
58855908
{
5886-
before = actions.at( i );
5887-
break;
5909+
if ( !before )
5910+
{
5911+
before = actions.at( i += 1 );
5912+
break;
5913+
}
58885914
}
58895915
}
58905916

58915917
if ( before )
58925918
menuBar()->insertMenu( before, mWebMenu );
58935919
else
5894-
menuBar()->addMenu( mWebMenu );
5920+
// fallback insert
5921+
menuBar()->insertMenu( firstRightStandardMenu()->menuAction(), mWebMenu );
58955922
}
58965923

58975924
void QgisApp::removePluginDatabaseMenu( QString name, QAction* action )

0 commit comments

Comments
 (0)