From c8ca3761ff1c5902e567fcdcc7d360bc70666f97 Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Tue, 12 Feb 2013 14:43:05 -0700 Subject: [PATCH] Add collapse toggling synchronization to QgsCollapsibleGroupBoxBasic - Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other boxes with the same syncGroup QString value - Synchronizes boxes of same syncGroup via recursive search in parent or grandparent widget (if grandparent is not QgisApp) --- python/gui/qgscollapsiblegroupbox.sip | 10 +- src/gui/qgscollapsiblegroupbox.cpp | 53 ++++++++- src/gui/qgscollapsiblegroupbox.h | 46 +++++++- src/ui/qgslabelingguibase.ui | 162 +++++++++++++++++++++++--- 4 files changed, 248 insertions(+), 23 deletions(-) diff --git a/python/gui/qgscollapsiblegroupbox.sip b/python/gui/qgscollapsiblegroupbox.sip index ab23a40da79..bb617f8bae8 100644 --- a/python/gui/qgscollapsiblegroupbox.sip +++ b/python/gui/qgscollapsiblegroupbox.sip @@ -3,8 +3,9 @@ * \class QgsCollapsibleGroupBoxBasic * A groupbox that collapses/expands when toggled. * Basic class QgsCollapsibleGroupBoxBasic does not auto-save collapsed or checked state + * Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette: - * bool collapsed + * bool collapsed, QString syncGroup */ class QgsCollapsibleGroupBoxBasic : QGroupBox @@ -20,6 +21,10 @@ class QgsCollapsibleGroupBoxBasic : QGroupBox bool isCollapsed() const; void setCollapsed( bool collapse ); + /** Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier key */ + QString syncGroup() const; + void setSyncGroup( QString grp ); + //! set this to false to not automatically scroll parent QScrollArea to this widget's contents when expanded void setScrollOnExpand( bool scroll ); @@ -45,9 +50,10 @@ class QgsCollapsibleGroupBoxBasic : QGroupBox * \class QgsCollapsibleGroupBox * A groupbox that collapses/expands when toggled and can save its collapsed and checked states. * By default, it auto-saves only its collapsed state to the global settings based on the widget and it's parent names. + * Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value * @see basic class QgsCollapsibleGroupBoxBasic which does not auto-save states * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette: - * bool collapsed, bool saveCollapsedState, bool saveCheckedState + * bool collapsed, bool saveCollapsedState, bool saveCheckedState, QString syncGroup */ class QgsCollapsibleGroupBox : QgsCollapsibleGroupBoxBasic diff --git a/src/gui/qgscollapsiblegroupbox.cpp b/src/gui/qgscollapsiblegroupbox.cpp index 1a85c05af93..09f8bf38b5f 100644 --- a/src/gui/qgscollapsiblegroupbox.cpp +++ b/src/gui/qgscollapsiblegroupbox.cpp @@ -58,6 +58,8 @@ void QgsCollapsibleGroupBoxBasic::init() mScrollOnExpand = true; mShown = false; mParentScrollArea = 0; + mSyncParent = 0; + mSyncGroup = ""; // init icons if ( mCollapseIcon.isNull() ) @@ -67,7 +69,7 @@ void QgsCollapsibleGroupBoxBasic::init() } // collapse button - mCollapseButton = new QToolButton( this ); + mCollapseButton = new QgsGroupBoxCollapseButton( this ); mCollapseButton->setObjectName( "collapseButton" ); mCollapseButton->setAutoRaise( true ); mCollapseButton->setFixedSize( 16, 16 ); @@ -175,6 +177,55 @@ void QgsCollapsibleGroupBoxBasic::checkToggled( bool chkd ) void QgsCollapsibleGroupBoxBasic::toggleCollapsed() { + // verify if sender is this group box's collapse button + bool senderCollBtn = false; + QgsGroupBoxCollapseButton* collBtn = qobject_cast( QObject::sender() ); + senderCollBtn = ( collBtn && collBtn == mCollapseButton ); + + // find any sync group siblings and toggle them + if ( senderCollBtn && mCollapseButton->altDown() && !mSyncGroup.isEmpty() ) + { + mCollapseButton->setAltDown( false ); + QgsDebugMsg( "Alt key down, syncing group" ); + // get pointer to parent or grandparent widget + if ( parentWidget() ) + { + mSyncParent = parentWidget(); + if ( mSyncParent->parentWidget() ) + { + // don't use whole app for grandparent (common for dialogs that use main window for parent) + if ( mSyncParent->parentWidget()->objectName() != QString( "QgisApp" ) ) + { + mSyncParent = mSyncParent->parentWidget(); + } + } + } + else + { + mSyncParent = 0; + } + + if ( mSyncParent ) + { + QgsDebugMsg( "found sync parent: " + mSyncParent->objectName() ); + + bool thisCollapsed = mCollapsed; // get state of current box before its changed + foreach ( QgsCollapsibleGroupBoxBasic *grpbox, mSyncParent->findChildren() ) + { + if ( grpbox->syncGroup() == syncGroup() && grpbox->isEnabled() ) + { + grpbox->setCollapsed( !thisCollapsed ); + } + } + + return; + } + else + { + QgsDebugMsg( "did not find a sync parent" ); + } + } + setCollapsed( !mCollapsed ); } diff --git a/src/gui/qgscollapsiblegroupbox.h b/src/gui/qgscollapsiblegroupbox.h index d5b5ec99667..d0abbd5180a 100644 --- a/src/gui/qgscollapsiblegroupbox.h +++ b/src/gui/qgscollapsiblegroupbox.h @@ -23,16 +23,43 @@ #include #include #include +#include +#include class QToolButton; class QScrollArea; +class QgsGroupBoxCollapseButton: public QToolButton +{ + Q_OBJECT + + public: + QgsGroupBoxCollapseButton( QWidget *parent = 0 ) + : QToolButton( parent ), mAltDown( false ) {} + + ~QgsGroupBoxCollapseButton() {} + + bool altDown() const { return mAltDown; } + void setAltDown( bool updown ) { mAltDown = updown; } + + protected: + void mouseReleaseEvent( QMouseEvent *event ) + { + mAltDown = ( event->modifiers() & Qt::AltModifier ); + QToolButton::mouseReleaseEvent( event ); + } + + private: + bool mAltDown; +}; + /** \ingroup gui * \class QgsCollapsibleGroupBoxBasic * A groupbox that collapses/expands when toggled. * Basic class QgsCollapsibleGroupBoxBasic does not auto-save collapsed or checked state + * Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette: - * bool collapsed + * bool collapsed, QString syncGroup */ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox @@ -40,6 +67,7 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox Q_OBJECT Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true ) + Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup ) public: QgsCollapsibleGroupBoxBasic( QWidget *parent = 0 ); @@ -49,6 +77,10 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox bool isCollapsed() const { return mCollapsed; } void setCollapsed( bool collapse ); + /** Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier key */ + QString syncGroup() const { return mSyncGroup; } + void setSyncGroup( QString grp ) { mSyncGroup = grp; } + //! set this to false to not automatically scroll parent QScrollArea to this widget's contents when expanded void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; } @@ -75,7 +107,9 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox bool mScrollOnExpand; bool mShown; QScrollArea* mParentScrollArea; - QToolButton* mCollapseButton; + QgsGroupBoxCollapseButton* mCollapseButton; + QWidget* mSyncParent; + QString mSyncGroup; static QIcon mCollapseIcon; static QIcon mExpandIcon; @@ -85,9 +119,10 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox * \class QgsCollapsibleGroupBox * A groupbox that collapses/expands when toggled and can save its collapsed and checked states. * By default, it auto-saves only its collapsed state to the global settings based on the widget and it's parent names. + * Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value * @see basic class QgsCollapsibleGroupBoxBasic which does not auto-save states * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette: - * bool collapsed, bool saveCollapsedState, bool saveCheckedState + * bool collapsed, bool saveCollapsedState, bool saveCheckedState, QString syncGroup */ class GUI_EXPORT QgsCollapsibleGroupBox : public QgsCollapsibleGroupBoxBasic @@ -95,8 +130,9 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QgsCollapsibleGroupBoxBasic Q_OBJECT Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true ) - Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState USER true ) - Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState USER true ) + Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState ) + Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState ) + Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup ) public: QgsCollapsibleGroupBox( QWidget *parent = 0, QSettings* settings = 0 ); diff --git a/src/ui/qgslabelingguibase.ui b/src/ui/qgslabelingguibase.ui index 215cbf814ca..fbd8335b2ce 100644 --- a/src/ui/qgslabelingguibase.ui +++ b/src/ui/qgslabelingguibase.ui @@ -169,7 +169,7 @@ false - falsetrue + 0 @@ -188,6 +188,12 @@ true + + false + + + true + 0 @@ -462,7 +468,7 @@ 20 - falsetrue + 0 @@ -481,6 +487,15 @@ true + + false + + + true + + + labelsettings + @@ -529,7 +544,7 @@ - falsetrue + 0 @@ -542,6 +557,15 @@ false + + false + + + true + + + labelsettings + @@ -677,7 +701,7 @@ - falsetrue + 0 @@ -693,6 +717,15 @@ Text style + + false + + + true + + + labelsettings + @@ -1161,7 +1194,7 @@ - falsetrue + 0 @@ -1180,6 +1213,15 @@ true + + false + + + true + + + labelsettings + @@ -1412,13 +1454,22 @@ - falsetrue + Pixel size-based visibility true + + false + + + true + + + labelsettings + @@ -1550,7 +1601,7 @@ - falsetrue + 0 @@ -1575,6 +1626,15 @@ true + + false + + + true + + + labelsettings + @@ -1691,7 +1751,7 @@ - falsetrue + Line direction symbols @@ -1701,6 +1761,15 @@ true + + false + + + true + + + labelsettings + @@ -1929,7 +1998,7 @@ 6 - falsetrue + 16777215 @@ -1939,6 +2008,15 @@ Priority + + false + + + true + + + advanced + @@ -1977,7 +2055,7 @@ - falsetrue + 0 @@ -1993,6 +2071,15 @@ Placement + + false + + + true + + + advanced + 0 @@ -2731,7 +2818,7 @@ - falsetrue + 16777215 @@ -2741,6 +2828,15 @@ Options + + false + + + true + + + advanced + @@ -3003,10 +3099,19 @@ 6 - falsetrue + Buffer properties + + false + + + true + + + datadefined + @@ -3049,10 +3154,19 @@ - falsetrue + Position + + false + + + true + + + datadefined + @@ -3147,10 +3261,19 @@ - falsetrue + Display properties + + false + + + true + + + datadefined + @@ -3211,7 +3334,7 @@ - falsetrue + 0 @@ -3221,6 +3344,15 @@ Font properties + + false + + + true + + + datadefined +