QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
25 #include "qgis_sip.h"
26 #include "qgssettings.h"
27 #include "qgis_gui.h"
28 
29 class QMouseEvent;
30 class QToolButton;
31 class QScrollArea;
32 
37 class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
38 {
39  Q_OBJECT
40 
41  public:
42  QgsGroupBoxCollapseButton( QWidget *parent SIP_TRANSFERTHIS = nullptr )
43  : QToolButton( parent )
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  private:
56  bool mAltDown = false;
57  bool mShiftDown = false;
58 };
59 
71 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
72 {
73  Q_OBJECT
74 
79  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
80 
81 
85  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
86 
91  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
92 
93  public:
94  QgsCollapsibleGroupBoxBasic( QWidget *parent SIP_TRANSFERTHIS = nullptr );
95  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent SIP_TRANSFERTHIS = nullptr );
96 
100  bool isCollapsed() const { return mCollapsed; }
101 
107  void setCollapsed( bool collapse );
108 
112  QString syncGroup() const { return mSyncGroup; }
113 
117  void setSyncGroup( const QString &grp );
118 
120  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
121 
123  bool scrollOnExpand() {return mScrollOnExpand;}
124 
125  signals:
127  void collapsedStateChanged( bool collapsed );
128 
129  public slots:
130  void checkToggled( bool ckd );
131  void checkClicked( bool ckd );
132  void toggleCollapsed();
133 
139  void setStyleSheet( const QString &style );
140 
141  protected:
142  void init();
143 
145  void collapseExpandFixes();
146 
147  void showEvent( QShowEvent *event ) override;
148  void mousePressEvent( QMouseEvent *event ) override;
149  void mouseReleaseEvent( QMouseEvent *event ) override;
150  void changeEvent( QEvent *event ) override;
151 
152  void updateStyle();
153  QRect titleRect() const;
154  void clearModifiers();
155 
157  bool mInitFlat;
160  bool mShown;
161  QScrollArea *mParentScrollArea = nullptr;
162  QgsGroupBoxCollapseButton *mCollapseButton = nullptr;
163  QWidget *mSyncParent = nullptr;
164  QString mSyncGroup;
165  bool mAltDown;
168 
170  QIcon mExpandIcon;
171 };
172 
186 {
187  Q_OBJECT
188 
192  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
193 
194 
197  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
198 
199  public:
200  QgsCollapsibleGroupBox( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsSettings *settings = nullptr );
201  QgsCollapsibleGroupBox( const QString &title, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsSettings *settings = nullptr );
202  ~QgsCollapsibleGroupBox() override;
203 
204  // set custom QgsSettings pointer if group box was already created from QtDesigner promotion
205  void setSettings( QgsSettings *settings );
206 
208  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
209 
215  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
216  bool saveCollapsedState() { return mSaveCollapsedState; }
217  bool saveCheckedState() { return mSaveCheckedState; }
218 
220  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
222  QString settingGroup() const { return mSettingGroup; }
223 
224  protected slots:
225 
234  void loadState();
235 
244  void saveState() const;
245 
246  protected:
247  void init();
248  void showEvent( QShowEvent *event ) override;
249  QString saveKey() const;
250 
251  // pointer to app or custom, external QgsSettings
252  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
253  QPointer<QgsSettings> mSettings;
255 
258  QString mSettingGroup;
259 };
260 
261 #endif
QgsCollapsibleGroupBoxBasic::scrollOnExpand
bool scrollOnExpand()
If this is set to false the parent QScrollArea will not be automatically scrolled to this widget's co...
Definition: qgscollapsiblegroupbox.h:123
QgsCollapsibleGroupBoxBasic::mCollapsed
bool mCollapsed
Definition: qgscollapsiblegroupbox.h:156
QgsCollapsibleGroupBoxBasic::init
void init()
Definition: qgscollapsiblegroupbox.cpp:44
QgsCollapsibleGroupBox::setSettingGroup
void setSettingGroup(const QString &group)
Sets this to a defined string to share save/restore states across different parent dialogs.
Definition: qgscollapsiblegroupbox.h:220
QgsCollapsibleGroupBoxBasic::mExpandIcon
QIcon mExpandIcon
Definition: qgscollapsiblegroupbox.h:170
QgsCollapsibleGroupBoxBasic::setScrollOnExpand
void setScrollOnExpand(bool scroll)
Sets this to false to not automatically scroll parent QScrollArea to this widget's contents when expa...
Definition: qgscollapsiblegroupbox.h:120
QgsGroupBoxCollapseButton::setAltDown
void setAltDown(bool updown)
Definition: qgscollapsiblegroupbox.h:47
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsCollapsibleGroupBoxBasic::mShown
bool mShown
Definition: qgscollapsiblegroupbox.h:160
QgsCollapsibleGroupBox
A groupbox that collapses/expands when toggled and can save its collapsed and checked states....
Definition: qgscollapsiblegroupbox.h:185
QgsCollapsibleGroupBoxBasic::mCollapseIcon
QIcon mCollapseIcon
Definition: qgscollapsiblegroupbox.h:169
QgsCollapsibleGroupBoxBasic::mInitFlat
bool mInitFlat
Definition: qgscollapsiblegroupbox.h:157
QgsCollapsibleGroupBoxBasic::mTitleClicked
bool mTitleClicked
Definition: qgscollapsiblegroupbox.h:167
QgsCollapsibleGroupBox::mSaveCheckedState
bool mSaveCheckedState
Definition: qgscollapsiblegroupbox.h:257
QgsCollapsibleGroupBox::mDelSettings
bool mDelSettings
Definition: qgscollapsiblegroupbox.h:254
QgsCollapsibleGroupBox::mSettings
QPointer< QgsSettings > mSettings
Definition: qgscollapsiblegroupbox.h:253
QgsGroupBoxCollapseButton::shiftDown
bool shiftDown() const
Definition: qgscollapsiblegroupbox.h:49
QgsCollapsibleGroupBoxBasic
A groupbox that collapses/expands when toggled. Basic class QgsCollapsibleGroupBoxBasic does not auto...
Definition: qgscollapsiblegroupbox.h:71
QgsCollapsibleGroupBoxBasic::mInitFlatChecked
bool mInitFlatChecked
Definition: qgscollapsiblegroupbox.h:158
QgsCollapsibleGroupBoxBasic::mSyncGroup
QString mSyncGroup
Definition: qgscollapsiblegroupbox.h:164
QgsCollapsibleGroupBox::saveCheckedState
bool saveCheckedState()
Definition: qgscollapsiblegroupbox.h:217
qgis_sip.h
QgsCollapsibleGroupBoxBasic::syncGroup
QString syncGroup() const
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
Definition: qgscollapsiblegroupbox.h:112
QgsGroupBoxCollapseButton
Definition: qgscollapsiblegroupbox.h:37
QgsCollapsibleGroupBox::saveCollapsedState
bool saveCollapsedState()
Definition: qgscollapsiblegroupbox.h:216
QgsCollapsibleGroupBox::mSaveCollapsedState
bool mSaveCollapsedState
Definition: qgscollapsiblegroupbox.h:256
QgsCollapsibleGroupBox::mSettingGroup
QString mSettingGroup
Definition: qgscollapsiblegroupbox.h:258
QgsCollapsibleGroupBoxBasic::showEvent
void showEvent(QShowEvent *event) override
Definition: qgscollapsiblegroupbox.cpp:79
QgsCollapsibleGroupBox::setSaveCheckedState
void setSaveCheckedState(bool save)
Set this to true to save/restore checked state.
Definition: qgscollapsiblegroupbox.h:215
qgssettings.h
QgsCollapsibleGroupBoxBasic::mScrollOnExpand
bool mScrollOnExpand
Definition: qgscollapsiblegroupbox.h:159
QgsCollapsibleGroupBox::settingGroup
QString settingGroup() const
Returns the name of the setting group in which the collapsed state will be saved.
Definition: qgscollapsiblegroupbox.h:222
QgsGroupBoxCollapseButton::QgsGroupBoxCollapseButton
QgsGroupBoxCollapseButton(QWidget *parent=nullptr)
Definition: qgscollapsiblegroupbox.h:42
QgsGroupBoxCollapseButton::setShiftDown
void setShiftDown(bool shiftdown)
Definition: qgscollapsiblegroupbox.h:50
QgsCollapsibleGroupBoxBasic::mShiftDown
bool mShiftDown
Definition: qgscollapsiblegroupbox.h:166
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsCollapsibleGroupBoxBasic::mAltDown
bool mAltDown
Definition: qgscollapsiblegroupbox.h:165
QgsGroupBoxCollapseButton::altDown
bool altDown() const
Definition: qgscollapsiblegroupbox.h:46