QGIS API Documentation  2.99.0-Master (0a63d1f)
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 #include "qgis_gui.h"
27 
28 class QToolButton;
29 class QScrollArea;
30 
34 class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
35 {
36  Q_OBJECT
37 
38  public:
39  QgsGroupBoxCollapseButton( QWidget *parent = nullptr )
40  : QToolButton( parent )
41  , mAltDown( false )
42  , mShiftDown( false )
43  {}
44 
45  bool altDown() const { return mAltDown; }
46  void setAltDown( bool updown ) { mAltDown = updown; }
47 
48  bool shiftDown() const { return mShiftDown; }
49  void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
50 
51  protected:
52  void mouseReleaseEvent( QMouseEvent *event ) override
53  {
54  mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
55  mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
56  QToolButton::mouseReleaseEvent( event );
57  }
58 
59  private:
60  bool mAltDown;
61  bool mShiftDown;
62 };
63 
74 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
75 {
76  Q_OBJECT
77 
82  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
83 
84 
88  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
89 
94  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
95 
96  public:
97  QgsCollapsibleGroupBoxBasic( QWidget *parent = nullptr );
98  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = nullptr );
99 
103  bool isCollapsed() const { return mCollapsed; }
104 
110  void setCollapsed( bool collapse );
111 
115  QString syncGroup() const { return mSyncGroup; }
116 
120  void setSyncGroup( const QString& grp );
121 
123  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
124 
126  bool scrollOnExpand() {return mScrollOnExpand;}
127 
128  signals:
130  void collapsedStateChanged( bool collapsed );
131 
132  public slots:
133  void checkToggled( bool ckd );
134  void checkClicked( bool ckd );
135  void toggleCollapsed();
136 
137  protected:
138  void init();
139 
141  void collapseExpandFixes();
142 
143  void showEvent( QShowEvent *event ) override;
144  void mousePressEvent( QMouseEvent *event ) override;
145  void mouseReleaseEvent( QMouseEvent *event ) override;
146  void changeEvent( QEvent *event ) override;
147 
148  void updateStyle();
149  QRect titleRect() const;
150  void clearModifiers();
151 
153  bool mInitFlat;
156  bool mShown;
157  QScrollArea* mParentScrollArea;
159  QWidget* mSyncParent;
160  QString mSyncGroup;
161  bool mAltDown;
164 
166  QIcon mExpandIcon;
167 };
168 
181 {
182  Q_OBJECT
183 
187  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
188 
189 
192  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
193 
194  public:
195  QgsCollapsibleGroupBox( QWidget *parent = nullptr, QSettings* settings = nullptr );
196  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = nullptr, QSettings* settings = nullptr );
198 
199  // set custom QSettings pointer if group box was already created from QtDesigner promotion
200  void setSettings( QSettings* settings );
201 
203  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
204 
208  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
209  bool saveCollapsedState() { return mSaveCollapsedState; }
210  bool saveCheckedState() { return mSaveCheckedState; }
211 
213  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
215  QString settingGroup() const { return mSettingGroup; }
216 
217  protected slots:
218 
226  void loadState();
227 
235  void saveState() const;
236 
237  protected:
238  void init();
239  void showEvent( QShowEvent *event ) override;
240  QString saveKey() const;
241 
242  // pointer to app or custom, external QSettings
243  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
244  QPointer<QSettings> mSettings;
246 
249  QString mSettingGroup;
250 };
251 
252 #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. ...