Skip to content

Commit

Permalink
Port toggle panel action to layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent 0283102 commit 833cb60
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -203,6 +203,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mActionUnlockAll, &QAction::triggered, this, &QgsLayoutDesignerDialog::unlockAllItems );
connect( mActionLockItems, &QAction::triggered, this, &QgsLayoutDesignerDialog::lockSelectedItems );

connect( mActionHidePanels, &QAction::toggled, this, &QgsLayoutDesignerDialog::setPanelVisibility );

//create status bar labels
mStatusCursorXLabel = new QLabel( mStatusBar );
mStatusCursorXLabel->setMinimumWidth( 100 );
Expand Down Expand Up @@ -329,6 +331,12 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mItemsTreeView->setIndentation( 0 );
mItemsDock->setWidget( mItemsTreeView );

const QList<QDockWidget *> docks = findChildren<QDockWidget *>();
for ( QDockWidget *dock : docks )
{
connect( dock, &QDockWidget::visibilityChanged, this, &QgsLayoutDesignerDialog::dockVisibilityChanged );
}

addDockWidget( Qt::RightDockWidgetArea, mItemDock );
addDockWidget( Qt::RightDockWidgetArea, mGeneralDock );
addDockWidget( Qt::RightDockWidgetArea, mGuideDock );
Expand Down Expand Up @@ -397,6 +405,8 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
#endif
mItemsTreeView->header()->setSectionResizeMode( 0, QHeaderView::Fixed );
mItemsTreeView->header()->setSectionResizeMode( 1, QHeaderView::Fixed );
mItemsTreeView->setColumnWidth( 0, 30 );
mItemsTreeView->setColumnWidth( 1, 30 );
mItemsTreeView->header()->setSectionsMovable( false );

connect( mItemsTreeView->selectionModel(), &QItemSelectionModel::currentChanged, mLayout->itemsModel(), &QgsLayoutModel::setSelected );
Expand Down Expand Up @@ -530,6 +540,64 @@ void QgsLayoutDesignerDialog::lockSelectedItems()
}
}

void QgsLayoutDesignerDialog::setPanelVisibility( bool hidden )
{
/*
workaround the limited Qt dock widget API
see http://qt-project.org/forums/viewthread/1141/
and http://qt-project.org/faq/answer/how_can_i_check_which_tab_is_the_current_one_in_a_tabbed_qdockwidget
*/

const QList<QDockWidget *> docks = findChildren<QDockWidget *>();
const QList<QTabBar *> tabBars = findChildren<QTabBar *>();

if ( hidden )
{
mPanelStatus.clear();
//record status of all docks

for ( QDockWidget *dock : docks )
{
mPanelStatus.insert( dock->windowTitle(), PanelStatus( dock->isVisible(), false ) );
dock->setVisible( false );
}

//record active dock tabs
for ( QTabBar *tabBar : tabBars )
{
QString currentTabTitle = tabBar->tabText( tabBar->currentIndex() );
mPanelStatus[ currentTabTitle ].isActive = true;
}
}
else
{
//restore visibility of all docks
for ( QDockWidget *dock : docks )
{
if ( ! mPanelStatus.contains( dock->windowTitle() ) )
{
dock->setVisible( true );
continue;
}
dock->setVisible( mPanelStatus.value( dock->windowTitle() ).isVisible );
}

//restore previously active dock tabs
for ( QTabBar *tabBar : tabBars )
{
//loop through all tabs in tab bar
for ( int i = 0; i < tabBar->count(); ++i )
{
QString tabTitle = tabBar->tabText( i );
if ( mPanelStatus.value( tabTitle ).isActive )
{
tabBar->setCurrentIndex( i );
}
}
}
}
}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
{
emit aboutToClose();
Expand Down Expand Up @@ -742,6 +810,14 @@ void QgsLayoutDesignerDialog::statusMessageReceived( const QString &message )
mStatusBar->showMessage( message );
}

void QgsLayoutDesignerDialog::dockVisibilityChanged( bool visible )
{
if ( visible )
{
whileBlocking( mActionHidePanels )->setChecked( false );
}
}

QgsLayoutView *QgsLayoutDesignerDialog::view()
{
return mView;
Expand Down
17 changes: 17 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -162,6 +162,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void lockSelectedItems();

/**
* Sets whether the dock panels are \a hidden.
*/
void setPanelVisibility( bool hidden );

signals:

/**
Expand Down Expand Up @@ -190,6 +195,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

void addPages();
void statusMessageReceived( const QString &message );
void dockVisibilityChanged( bool visible );

private:

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

struct PanelStatus
{
PanelStatus( bool visible = true, bool active = false )
: isVisible( visible )
, isActive( active )
{}
bool isVisible;
bool isActive;
};
QMap< QString, PanelStatus > mPanelStatus;

//! Save window state
void saveWindowState();

Expand Down
15 changes: 15 additions & 0 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -137,6 +137,7 @@
<addaction name="mToolbarMenu"/>
<addaction name="mPanelsMenu"/>
<addaction name="mActionToggleFullScreen"/>
<addaction name="mActionHidePanels"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
Expand Down Expand Up @@ -584,6 +585,20 @@
<string>Ctrl+Shift+L</string>
</property>
</action>
<action name="mActionHidePanels">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Toggle Panel &amp;Visibility</string>
</property>
<property name="toolTip">
<string>Hide panels</string>
</property>
<property name="shortcut">
<string>Ctrl+Tab</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down

0 comments on commit 833cb60

Please sign in to comment.