Skip to content

Commit e60891c

Browse files
committedFeb 26, 2013
Add shift-click modifier to QgsCollapsibleGroupBox
- Expands current group box on shift-click, then collapses any others in sync group
1 parent 37208df commit e60891c

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed
 

‎python/gui/qgscollapsiblegroupbox.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* A groupbox that collapses/expands when toggled.
55
* Basic class QgsCollapsibleGroupBoxBasic does not auto-save collapsed or checked state
66
* Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value
7+
* Holding Shift modifier key when attempting to toggle collapsed state will expand current group box, then collapse any others with the same syncGroup QString value
78
* @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:
89
* bool collapsed, QString syncGroup
910
*/
@@ -51,6 +52,7 @@ class QgsCollapsibleGroupBoxBasic : QGroupBox
5152
* A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
5253
* By default, it auto-saves only its collapsed state to the global settings based on the widget and it's parent names.
5354
* Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value
55+
* Holding Shift modifier key when attempting to toggle collapsed state will expand current group box, then collapse any others with the same syncGroup QString value
5456
* @see basic class QgsCollapsibleGroupBoxBasic which does not auto-save states
5557
* @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:
5658
* bool collapsed, bool saveCollapsedState, bool saveCheckedState, QString syncGroup

‎src/gui/qgscollapsiblegroupbox.cpp

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void QgsCollapsibleGroupBoxBasic::init()
6161
mSyncParent = 0;
6262
mSyncGroup = "";
6363
mAltDown = false;
64+
mShiftDown = false;
6465
mTitleClicked = false;
6566

6667
// init icons
@@ -138,8 +139,8 @@ void QgsCollapsibleGroupBoxBasic::showEvent( QShowEvent * event )
138139

139140
void QgsCollapsibleGroupBoxBasic::mousePressEvent( QMouseEvent *event )
140141
{
141-
// avoid leaving checkbox in pressed state if alt-clicking
142-
if ( event->modifiers() & Qt::AltModifier
142+
// avoid leaving checkbox in pressed state if alt- or shift-clicking
143+
if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
143144
&& titleRect().contains( event->pos() )
144145
&& isCheckable() )
145146
{
@@ -154,12 +155,14 @@ void QgsCollapsibleGroupBoxBasic::mousePressEvent( QMouseEvent *event )
154155
void QgsCollapsibleGroupBoxBasic::mouseReleaseEvent( QMouseEvent *event )
155156
{
156157
mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
158+
mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
157159
mTitleClicked = ( titleRect().contains( event->pos() ) );
158160

159161
// sync group when title is alt-clicked
160162
// collapse/expand when title is clicked and non-checkable
163+
// expand current and collapse others on shift-click
161164
if ( event->button() == Qt::LeftButton && mTitleClicked &&
162-
( mAltDown || !isCheckable() ) )
165+
( mAltDown || mShiftDown || !isCheckable() ) )
163166
{
164167
toggleCollapsed();
165168
return;
@@ -184,14 +187,12 @@ void QgsCollapsibleGroupBoxBasic::changeEvent( QEvent *event )
184187
void QgsCollapsibleGroupBoxBasic::setSyncGroup( QString grp )
185188
{
186189
mSyncGroup = grp;
190+
QString tipTxt = QString( "" );
187191
if ( !grp.isEmpty() )
188192
{
189-
mCollapseButton->setToolTip( tr( "Ctrl(or Alt)-click to toggle all" ) );
190-
}
191-
else
192-
{
193-
mCollapseButton->setToolTip( QString( "" ) );
193+
tipTxt = tr( "Ctrl(or Alt)-click to toggle all" ) + "\n" + tr( "Shift-click to expand, then collapse others" );
194194
}
195+
mCollapseButton->setToolTip( tipTxt );
195196
}
196197

197198
QRect QgsCollapsibleGroupBoxBasic::titleRect() const
@@ -202,6 +203,14 @@ QRect QgsCollapsibleGroupBoxBasic::titleRect() const
202203
QStyle::SC_GroupBoxLabel, this );
203204
}
204205

206+
void QgsCollapsibleGroupBoxBasic::clearModifiers()
207+
{
208+
mCollapseButton->setAltDown( false );
209+
mCollapseButton->setShiftDown( false );
210+
mAltDown = false;
211+
mShiftDown = false;
212+
}
213+
205214
void QgsCollapsibleGroupBoxBasic::checkToggled( bool chkd )
206215
{
207216
mCollapseButton->setEnabled( true ); // always keep enabled
@@ -219,13 +228,15 @@ void QgsCollapsibleGroupBoxBasic::toggleCollapsed()
219228
QgsGroupBoxCollapseButton* collBtn = qobject_cast<QgsGroupBoxCollapseButton*>( QObject::sender() );
220229
senderCollBtn = ( collBtn && collBtn == mCollapseButton );
221230

231+
mAltDown = ( mAltDown || mCollapseButton->altDown() );
232+
mShiftDown = ( mShiftDown || mCollapseButton->shiftDown() );
233+
222234
// find any sync group siblings and toggle them
223-
if ((( senderCollBtn && mCollapseButton->altDown() ) || ( mTitleClicked && mAltDown ) )
235+
if (( senderCollBtn || mTitleClicked )
236+
&& ( mAltDown || mShiftDown )
224237
&& !mSyncGroup.isEmpty() )
225238
{
226-
mCollapseButton->setAltDown( false );
227-
mAltDown = false;
228-
QgsDebugMsg( "Alt key down, syncing group" );
239+
QgsDebugMsg( "Alt or Shift key down, syncing group" );
229240
// get pointer to parent or grandparent widget
230241
if ( parentWidget() )
231242
{
@@ -253,10 +264,19 @@ void QgsCollapsibleGroupBoxBasic::toggleCollapsed()
253264
{
254265
if ( grpbox->syncGroup() == syncGroup() && grpbox->isEnabled() )
255266
{
256-
grpbox->setCollapsed( !thisCollapsed );
267+
if ( mShiftDown && grpbox == dynamic_cast<QgsCollapsibleGroupBoxBasic *>( this ) )
268+
{
269+
// expand current group box on shift-click
270+
setCollapsed( false );
271+
}
272+
else
273+
{
274+
grpbox->setCollapsed( mShiftDown ? true : !thisCollapsed );
275+
}
257276
}
258277
}
259278

279+
clearModifiers();
260280
return;
261281
}
262282
else
@@ -265,7 +285,17 @@ void QgsCollapsibleGroupBoxBasic::toggleCollapsed()
265285
}
266286
}
267287

268-
setCollapsed( !mCollapsed );
288+
// expand current group box on shift-click, even if no sync group
289+
if ( mShiftDown )
290+
{
291+
setCollapsed( false );
292+
}
293+
else
294+
{
295+
setCollapsed( !mCollapsed );
296+
}
297+
298+
clearModifiers();
269299
}
270300

271301
void QgsCollapsibleGroupBoxBasic::updateStyle()

‎src/gui/qgscollapsiblegroupbox.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,35 @@ class QgsGroupBoxCollapseButton: public QToolButton
3535

3636
public:
3737
QgsGroupBoxCollapseButton( QWidget *parent = 0 )
38-
: QToolButton( parent ), mAltDown( false ) {}
38+
: QToolButton( parent ), mAltDown( false ), mShiftDown( false ) {}
3939

4040
~QgsGroupBoxCollapseButton() {}
4141

4242
bool altDown() const { return mAltDown; }
4343
void setAltDown( bool updown ) { mAltDown = updown; }
4444

45+
bool shiftDown() const { return mShiftDown; }
46+
void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
47+
4548
protected:
4649
void mouseReleaseEvent( QMouseEvent *event )
4750
{
4851
mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
52+
mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
4953
QToolButton::mouseReleaseEvent( event );
5054
}
5155

5256
private:
5357
bool mAltDown;
58+
bool mShiftDown;
5459
};
5560

5661
/** \ingroup gui
5762
* \class QgsCollapsibleGroupBoxBasic
5863
* A groupbox that collapses/expands when toggled.
5964
* Basic class QgsCollapsibleGroupBoxBasic does not auto-save collapsed or checked state
6065
* Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value
66+
* Holding Shift modifier key when attempting to toggle collapsed state will expand current group box, then collapse any others with the same syncGroup QString value
6167
* @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:
6268
* bool collapsed, QString syncGroup
6369
*/
@@ -101,6 +107,7 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
101107

102108
void updateStyle();
103109
QRect titleRect() const;
110+
void clearModifiers();
104111

105112
bool mCollapsed;
106113
bool mInitFlat;
@@ -112,6 +119,7 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
112119
QWidget* mSyncParent;
113120
QString mSyncGroup;
114121
bool mAltDown;
122+
bool mShiftDown;
115123
bool mTitleClicked;
116124

117125
static QIcon mCollapseIcon;
@@ -123,6 +131,7 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
123131
* A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
124132
* By default, it auto-saves only its collapsed state to the global settings based on the widget and it's parent names.
125133
* Holding Alt modifier key when toggling collapsed state will synchronize the toggling across other collapsible group boxes with the same syncGroup QString value
134+
* Holding Shift modifier key when attempting to toggle collapsed state will expand current group box, then collapse any others with the same syncGroup QString value
126135
* @see basic class QgsCollapsibleGroupBoxBasic which does not auto-save states
127136
* @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:
128137
* bool collapsed, bool saveCollapsedState, bool saveCheckedState, QString syncGroup

0 commit comments

Comments
 (0)
Please sign in to comment.