QGIS API Documentation  2.99.0-Master (314842d)
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 <QPointer>
23 #include <QToolButton>
24 #include <QMouseEvent>
25 
26 #include "qgssettings.h"
27 #include "qgis_gui.h"
28 
29 class QToolButton;
30 class QScrollArea;
31 
35 class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
36 {
37  Q_OBJECT
38 
39  public:
40  QgsGroupBoxCollapseButton( QWidget *parent = nullptr )
41  : QToolButton( parent )
42  , mAltDown( false )
43  , mShiftDown( false )
44  {}
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 );
100 
104  bool isCollapsed() const { return mCollapsed; }
105 
111  void setCollapsed( bool collapse );
112 
116  QString syncGroup() const { return mSyncGroup; }
117 
121  void setSyncGroup( const QString &grp );
122 
124  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
125 
127  bool scrollOnExpand() {return mScrollOnExpand;}
128 
129  signals:
131  void collapsedStateChanged( bool collapsed );
132 
133  public slots:
134  void checkToggled( bool ckd );
135  void checkClicked( bool ckd );
136  void toggleCollapsed();
137 
138  protected:
139  void init();
140 
142  void collapseExpandFixes();
143 
144  void showEvent( QShowEvent *event ) override;
145  void mousePressEvent( QMouseEvent *event ) override;
146  void mouseReleaseEvent( QMouseEvent *event ) override;
147  void changeEvent( QEvent *event ) override;
148 
149  void updateStyle();
150  QRect titleRect() const;
151  void clearModifiers();
152 
154  bool mInitFlat;
157  bool mShown;
158  QScrollArea *mParentScrollArea = nullptr;
159  QgsGroupBoxCollapseButton *mCollapseButton = nullptr;
160  QWidget *mSyncParent = nullptr;
161  QString mSyncGroup;
162  bool mAltDown;
165 
167  QIcon mExpandIcon;
168 };
169 
182 {
183  Q_OBJECT
184 
188  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
189 
190 
193  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
194 
195  public:
196  QgsCollapsibleGroupBox( QWidget *parent = nullptr, QgsSettings *settings = nullptr );
197  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = nullptr, QgsSettings *settings = nullptr );
199 
200  // set custom QgsSettings pointer if group box was already created from QtDesigner promotion
201  void setSettings( QgsSettings *settings );
202 
204  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
205 
209  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
210  bool saveCollapsedState() { return mSaveCollapsedState; }
211  bool saveCheckedState() { return mSaveCheckedState; }
212 
214  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
216  QString settingGroup() const { return mSettingGroup; }
217 
218  protected slots:
219 
227  void loadState();
228 
236  void saveState() const;
237 
238  protected:
239  void init();
240  void showEvent( QShowEvent *event ) override;
241  QString saveKey() const;
242 
243  // pointer to app or custom, external QgsSettings
244  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
245  QPointer<QgsSettings> mSettings;
247 
250  QString mSettingGroup;
251 };
252 
253 #endif
QgsGroupBoxCollapseButton(QWidget *parent=nullptr)
This class is a composition of two QSettings instances:
Definition: qgssettings.h:51
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)
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< QgsSettings > mSettings
QString settingGroup() const
Returns the name of the setting group in which the collapsed state will be saved. ...