Skip to content
Permalink
Browse files
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)
  • Loading branch information
dakcarto committed Feb 12, 2013
1 parent df412ec commit c8ca3761ff1c5902e567fcdcc7d360bc70666f97
Showing with 248 additions and 23 deletions.
  1. +8 −2 python/gui/qgscollapsiblegroupbox.sip
  2. +52 −1 src/gui/qgscollapsiblegroupbox.cpp
  3. +41 −5 src/gui/qgscollapsiblegroupbox.h
  4. +147 −15 src/ui/qgslabelingguibase.ui
@@ -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
@@ -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<QgsGroupBoxCollapseButton*>( 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<QgsCollapsibleGroupBoxBasic*>() )
{
if ( grpbox->syncGroup() == syncGroup() && grpbox->isEnabled() )
{
grpbox->setCollapsed( !thisCollapsed );
}
}

return;
}
else
{
QgsDebugMsg( "did not find a sync parent" );
}
}

setCollapsed( !mCollapsed );
}

@@ -23,23 +23,51 @@
#include <QGroupBox>
#include <QSettings>
#include <QPointer>
#include <QToolButton>
#include <QMouseEvent>

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
{
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,18 +119,20 @@ 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
{
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 );
Loading

0 comments on commit c8ca376

Please sign in to comment.