Skip to content

Commit 833cb60

Browse files
committedOct 6, 2017
Port toggle panel action to layouts
1 parent 0283102 commit 833cb60

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
 

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
203203
connect( mActionUnlockAll, &QAction::triggered, this, &QgsLayoutDesignerDialog::unlockAllItems );
204204
connect( mActionLockItems, &QAction::triggered, this, &QgsLayoutDesignerDialog::lockSelectedItems );
205205

206+
connect( mActionHidePanels, &QAction::toggled, this, &QgsLayoutDesignerDialog::setPanelVisibility );
207+
206208
//create status bar labels
207209
mStatusCursorXLabel = new QLabel( mStatusBar );
208210
mStatusCursorXLabel->setMinimumWidth( 100 );
@@ -329,6 +331,12 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
329331
mItemsTreeView->setIndentation( 0 );
330332
mItemsDock->setWidget( mItemsTreeView );
331333

334+
const QList<QDockWidget *> docks = findChildren<QDockWidget *>();
335+
for ( QDockWidget *dock : docks )
336+
{
337+
connect( dock, &QDockWidget::visibilityChanged, this, &QgsLayoutDesignerDialog::dockVisibilityChanged );
338+
}
339+
332340
addDockWidget( Qt::RightDockWidgetArea, mItemDock );
333341
addDockWidget( Qt::RightDockWidgetArea, mGeneralDock );
334342
addDockWidget( Qt::RightDockWidgetArea, mGuideDock );
@@ -397,6 +405,8 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
397405
#endif
398406
mItemsTreeView->header()->setSectionResizeMode( 0, QHeaderView::Fixed );
399407
mItemsTreeView->header()->setSectionResizeMode( 1, QHeaderView::Fixed );
408+
mItemsTreeView->setColumnWidth( 0, 30 );
409+
mItemsTreeView->setColumnWidth( 1, 30 );
400410
mItemsTreeView->header()->setSectionsMovable( false );
401411

402412
connect( mItemsTreeView->selectionModel(), &QItemSelectionModel::currentChanged, mLayout->itemsModel(), &QgsLayoutModel::setSelected );
@@ -530,6 +540,64 @@ void QgsLayoutDesignerDialog::lockSelectedItems()
530540
}
531541
}
532542

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+
533601
void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
534602
{
535603
emit aboutToClose();
@@ -742,6 +810,14 @@ void QgsLayoutDesignerDialog::statusMessageReceived( const QString &message )
742810
mStatusBar->showMessage( message );
743811
}
744812

813+
void QgsLayoutDesignerDialog::dockVisibilityChanged( bool visible )
814+
{
815+
if ( visible )
816+
{
817+
whileBlocking( mActionHidePanels )->setChecked( false );
818+
}
819+
}
820+
745821
QgsLayoutView *QgsLayoutDesignerDialog::view()
746822
{
747823
return mView;

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
162162
*/
163163
void lockSelectedItems();
164164

165+
/**
166+
* Sets whether the dock panels are \a hidden.
167+
*/
168+
void setPanelVisibility( bool hidden );
169+
165170
signals:
166171

167172
/**
@@ -190,6 +195,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
190195

191196
void addPages();
192197
void statusMessageReceived( const QString &message );
198+
void dockVisibilityChanged( bool visible );
193199

194200
private:
195201

@@ -240,6 +246,17 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
240246
QgsDockWidget *mItemsDock = nullptr;
241247
QTreeView *mItemsTreeView = nullptr;
242248

249+
struct PanelStatus
250+
{
251+
PanelStatus( bool visible = true, bool active = false )
252+
: isVisible( visible )
253+
, isActive( active )
254+
{}
255+
bool isVisible;
256+
bool isActive;
257+
};
258+
QMap< QString, PanelStatus > mPanelStatus;
259+
243260
//! Save window state
244261
void saveWindowState();
245262

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<addaction name="mToolbarMenu"/>
138138
<addaction name="mPanelsMenu"/>
139139
<addaction name="mActionToggleFullScreen"/>
140+
<addaction name="mActionHidePanels"/>
140141
</widget>
141142
<widget class="QMenu" name="menuEdit">
142143
<property name="title">
@@ -584,6 +585,20 @@
584585
<string>Ctrl+Shift+L</string>
585586
</property>
586587
</action>
588+
<action name="mActionHidePanels">
589+
<property name="checkable">
590+
<bool>true</bool>
591+
</property>
592+
<property name="text">
593+
<string>Toggle Panel &amp;Visibility</string>
594+
</property>
595+
<property name="toolTip">
596+
<string>Hide panels</string>
597+
</property>
598+
<property name="shortcut">
599+
<string>Ctrl+Tab</string>
600+
</property>
601+
</action>
587602
</widget>
588603
<resources>
589604
<include location="../../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.