QGIS API Documentation  2.99.0-Master (8ec3eaf)
qgscollapsiblegroupbox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscollapsiblegroupbox.h
3  -------------------
4  begin : August 2012
5  copyright : (C) 2012 by Etienne Tourigny
6  email : etourigny dot dev at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOLLAPSIBLEGROUPBOX_H
19 #define QGSCOLLAPSIBLEGROUPBOX_H
20 
21 #include <QGroupBox>
22 #include <QSettings>
23 #include <QPointer>
24 #include <QToolButton>
25 #include <QMouseEvent>
26 
27 class QToolButton;
28 class QScrollArea;
29 
33 class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
34 {
35  Q_OBJECT
36 
37  public:
38  QgsGroupBoxCollapseButton( QWidget *parent = nullptr )
39  : QToolButton( parent )
40  , mAltDown( false )
41  , mShiftDown( false )
42  {}
43 
45 
46  bool altDown() const { return mAltDown; }
47  void setAltDown( bool updown ) { mAltDown = updown; }
48 
49  bool shiftDown() const { return mShiftDown; }
50  void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
51 
52  protected:
53  void mouseReleaseEvent( QMouseEvent *event ) override
54  {
55  mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
56  mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
57  QToolButton::mouseReleaseEvent( event );
58  }
59 
60  private:
61  bool mAltDown;
62  bool mShiftDown;
63 };
64 
75 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
76 {
77  Q_OBJECT
78 
83  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
84 
85 
89  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
90 
95  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
96 
97  public:
98  QgsCollapsibleGroupBoxBasic( QWidget *parent = nullptr );
99  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = nullptr );
101 
105  bool isCollapsed() const { return mCollapsed; }
106 
112  void setCollapsed( bool collapse );
113 
117  QString syncGroup() const { return mSyncGroup; }
118 
122  void setSyncGroup( const QString& grp );
123 
125  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
126 
128  bool scrollOnExpand() {return mScrollOnExpand;}
129 
130  signals:
132  void collapsedStateChanged( bool collapsed );
133 
134  public slots:
135  void checkToggled( bool ckd );
136  void checkClicked( bool ckd );
137  void toggleCollapsed();
138 
139  protected:
140  void init();
141 
143  void collapseExpandFixes();
144 
145  void showEvent( QShowEvent *event ) override;
146  void mousePressEvent( QMouseEvent *event ) override;
147  void mouseReleaseEvent( QMouseEvent *event ) override;
148  void changeEvent( QEvent *event ) override;
149 
150  void updateStyle();
151  QRect titleRect() const;
152  void clearModifiers();
153 
155  bool mInitFlat;
158  bool mShown;
159  QScrollArea* mParentScrollArea;
161  QWidget* mSyncParent;
162  QString mSyncGroup;
163  bool mAltDown;
166 
168  QIcon mExpandIcon;
169 };
170 
183 {
184  Q_OBJECT
185 
189  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
190 
191 
194  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
195 
196  public:
197  QgsCollapsibleGroupBox( QWidget *parent = nullptr, QSettings* settings = nullptr );
198  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = nullptr, QSettings* settings = nullptr );
200 
201  // set custom QSettings pointer if group box was already created from QtDesigner promotion
202  void setSettings( QSettings* settings );
203 
205  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
206 
210  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
211  bool saveCollapsedState() { return mSaveCollapsedState; }
212  bool saveCheckedState() { return mSaveCheckedState; }
213 
215  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
217  QString settingGroup() const { return mSettingGroup; }
218 
219  protected slots:
220 
228  void loadState();
229 
237  void saveState() const;
238 
239  protected:
240  void init();
241  void showEvent( QShowEvent *event ) override;
242  QString saveKey() const;
243 
244  // pointer to app or custom, external QSettings
245  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
246  QPointer<QSettings> mSettings;
248 
251  QString mSettingGroup;
252 };
253 
254 #endif
QgsGroupBoxCollapseButton(QWidget *parent=nullptr)
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
void setSaveCheckedState(bool save)
Set this to true to save/restore checked state.
void setScrollOnExpand(bool scroll)
Set this to false to not automatically scroll parent QScrollArea to this widget&#39;s contents when expan...
void showEvent(QShowEvent *event) override
void setShiftDown(bool shiftdown)
QgsGroupBoxCollapseButton * mCollapseButton
QString syncGroup() const
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
A groupbox that collapses/expands when toggled.
bool scrollOnExpand()
If this is set to false the parent QScrollArea will not be automatically scrolled to this widget&#39;s co...
void setSettingGroup(const QString &group)
Set this to a defined string to share save/restore states across different parent dialogs...
void mouseReleaseEvent(QMouseEvent *event) override
QPointer< QSettings > mSettings
QString settingGroup() const
Returns the name of the setting group in which the collapsed state will be saved. ...