Skip to content

Commit 022be6e

Browse files
committed
customize mMenuToolbar according to toolbars customization
1 parent c2457ae commit 022be6e

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/app/qgisapp.cpp

100755100644
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
538538
restoreWindowState();
539539

540540
// do main window customization - after window state has been restored, before the window is shown
541-
QgsCustomization::instance()->updateMainWindow();
541+
QgsCustomization::instance()->updateMainWindow( mToolbarMenu );
542542

543543
mSplash->showMessage( tr( "QGIS Ready!" ), Qt::AlignHCenter | Qt::AlignBottom );
544544

@@ -1065,17 +1065,26 @@ void QgisApp::createToolBars()
10651065
// qmainwindow::saveState and qmainwindow::restoreState
10661066
// work properly
10671067

1068+
QList<QToolBar*> toolbarMenuToolBars;
1069+
toolbarMenuToolBars << mFileToolBar
1070+
<< mLayerToolBar
1071+
<< mDigitizeToolBar
1072+
<< mAdvancedDigitizeToolBar
1073+
<< mMapNavToolBar
1074+
<< mAttributesToolBar
1075+
<< mPluginToolBar
1076+
<< mHelpToolBar
1077+
<< mRasterToolBar
1078+
<< mLabelToolBar;
1079+
10681080
QList<QAction*> toolbarMenuActions;
1069-
toolbarMenuActions << mFileToolBar->toggleViewAction()
1070-
<< mLayerToolBar->toggleViewAction()
1071-
<< mDigitizeToolBar->toggleViewAction()
1072-
<< mAdvancedDigitizeToolBar->toggleViewAction()
1073-
<< mMapNavToolBar->toggleViewAction()
1074-
<< mAttributesToolBar->toggleViewAction()
1075-
<< mPluginToolBar->toggleViewAction()
1076-
<< mHelpToolBar->toggleViewAction()
1077-
<< mRasterToolBar->toggleViewAction()
1078-
<< mLabelToolBar->toggleViewAction();
1081+
// Set action names so that they can be used in customization
1082+
foreach ( QToolBar *toolBar, toolbarMenuToolBars )
1083+
{
1084+
toolBar->toggleViewAction()->setObjectName ( "mActionToggle" + toolBar->objectName().mid(1) );
1085+
toolbarMenuActions << toolBar->toggleViewAction();
1086+
}
1087+
10791088
mToolbarMenu->addActions( toolbarMenuActions );
10801089

10811090
// select tool button

src/app/qgscustomization.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ QgsCustomization::~QgsCustomization()
594594
{
595595
}
596596

597-
void QgsCustomization::updateMainWindow()
597+
void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
598598
{
599599
// collect tree items even if the customization is disabled
600600
createTreeItemMenus();
@@ -643,6 +643,8 @@ void QgsCustomization::updateMainWindow()
643643
if (!visible)
644644
{
645645
mw->removeToolBar(tb);
646+
// remove also from menu, because toolbars removed here, switched on later from menu don't work correctly
647+
theToolBarMenu->removeAction( tb->toggleViewAction() );
646648
}
647649
else
648650
{

src/app/qgscustomization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class QgsCustomization : public QObject
119119
static void customizeWidget( QString path, QWidget * widget );
120120
static void removeFromLayout( QLayout *theLayout, QWidget * widget );
121121

122-
void updateMainWindow();
122+
void updateMainWindow( QMenu * theToolBarMenu );
123123

124124
// make sure to enable/disable before creating QgisApp in order to get it customized (or not)
125125
void setEnabled(bool enabled) { mEnabled = enabled; }

0 commit comments

Comments
 (0)