@@ -203,6 +203,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
203
203
connect ( mActionUnlockAll , &QAction::triggered, this , &QgsLayoutDesignerDialog::unlockAllItems );
204
204
connect ( mActionLockItems , &QAction::triggered, this , &QgsLayoutDesignerDialog::lockSelectedItems );
205
205
206
+ connect ( mActionHidePanels , &QAction::toggled, this , &QgsLayoutDesignerDialog::setPanelVisibility );
207
+
206
208
// create status bar labels
207
209
mStatusCursorXLabel = new QLabel ( mStatusBar );
208
210
mStatusCursorXLabel ->setMinimumWidth ( 100 );
@@ -329,6 +331,12 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
329
331
mItemsTreeView ->setIndentation ( 0 );
330
332
mItemsDock ->setWidget ( mItemsTreeView );
331
333
334
+ const QList<QDockWidget *> docks = findChildren<QDockWidget *>();
335
+ for ( QDockWidget *dock : docks )
336
+ {
337
+ connect ( dock, &QDockWidget::visibilityChanged, this , &QgsLayoutDesignerDialog::dockVisibilityChanged );
338
+ }
339
+
332
340
addDockWidget ( Qt::RightDockWidgetArea, mItemDock );
333
341
addDockWidget ( Qt::RightDockWidgetArea, mGeneralDock );
334
342
addDockWidget ( Qt::RightDockWidgetArea, mGuideDock );
@@ -397,6 +405,8 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
397
405
#endif
398
406
mItemsTreeView ->header ()->setSectionResizeMode ( 0 , QHeaderView::Fixed );
399
407
mItemsTreeView ->header ()->setSectionResizeMode ( 1 , QHeaderView::Fixed );
408
+ mItemsTreeView ->setColumnWidth ( 0 , 30 );
409
+ mItemsTreeView ->setColumnWidth ( 1 , 30 );
400
410
mItemsTreeView ->header ()->setSectionsMovable ( false );
401
411
402
412
connect ( mItemsTreeView ->selectionModel (), &QItemSelectionModel::currentChanged, mLayout ->itemsModel (), &QgsLayoutModel::setSelected );
@@ -530,6 +540,64 @@ void QgsLayoutDesignerDialog::lockSelectedItems()
530
540
}
531
541
}
532
542
543
+ void QgsLayoutDesignerDialog::setPanelVisibility ( bool hidden )
544
+ {
545
+ /*
546
+ workaround the limited Qt dock widget API
547
+ see http://qt-project.org/forums/viewthread/1141/
548
+ and http://qt-project.org/faq/answer/how_can_i_check_which_tab_is_the_current_one_in_a_tabbed_qdockwidget
549
+ */
550
+
551
+ const QList<QDockWidget *> docks = findChildren<QDockWidget *>();
552
+ const QList<QTabBar *> tabBars = findChildren<QTabBar *>();
553
+
554
+ if ( hidden )
555
+ {
556
+ mPanelStatus .clear ();
557
+ // record status of all docks
558
+
559
+ for ( QDockWidget *dock : docks )
560
+ {
561
+ mPanelStatus .insert ( dock->windowTitle (), PanelStatus ( dock->isVisible (), false ) );
562
+ dock->setVisible ( false );
563
+ }
564
+
565
+ // record active dock tabs
566
+ for ( QTabBar *tabBar : tabBars )
567
+ {
568
+ QString currentTabTitle = tabBar->tabText ( tabBar->currentIndex () );
569
+ mPanelStatus [ currentTabTitle ].isActive = true ;
570
+ }
571
+ }
572
+ else
573
+ {
574
+ // restore visibility of all docks
575
+ for ( QDockWidget *dock : docks )
576
+ {
577
+ if ( ! mPanelStatus .contains ( dock->windowTitle () ) )
578
+ {
579
+ dock->setVisible ( true );
580
+ continue ;
581
+ }
582
+ dock->setVisible ( mPanelStatus .value ( dock->windowTitle () ).isVisible );
583
+ }
584
+
585
+ // restore previously active dock tabs
586
+ for ( QTabBar *tabBar : tabBars )
587
+ {
588
+ // loop through all tabs in tab bar
589
+ for ( int i = 0 ; i < tabBar->count (); ++i )
590
+ {
591
+ QString tabTitle = tabBar->tabText ( i );
592
+ if ( mPanelStatus .value ( tabTitle ).isActive )
593
+ {
594
+ tabBar->setCurrentIndex ( i );
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }
600
+
533
601
void QgsLayoutDesignerDialog::closeEvent ( QCloseEvent * )
534
602
{
535
603
emit aboutToClose ();
@@ -742,6 +810,14 @@ void QgsLayoutDesignerDialog::statusMessageReceived( const QString &message )
742
810
mStatusBar ->showMessage ( message );
743
811
}
744
812
813
+ void QgsLayoutDesignerDialog::dockVisibilityChanged ( bool visible )
814
+ {
815
+ if ( visible )
816
+ {
817
+ whileBlocking ( mActionHidePanels )->setChecked ( false );
818
+ }
819
+ }
820
+
745
821
QgsLayoutView *QgsLayoutDesignerDialog::view ()
746
822
{
747
823
return mView ;
0 commit comments