QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgis.h"
27 #include "qgssettings.h"
28 #include "qgis_gui.h"
29 
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  mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
56  mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
57  QToolButton::mouseReleaseEvent( event );
58  }
59 
60  private:
61  bool mAltDown = false;
62  bool mShiftDown = false;
63 };
64 
76 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
77 {
78  Q_OBJECT
79 
84  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
85 
86 
90  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
91 
96  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
97 
98  public:
99  QgsCollapsibleGroupBoxBasic( QWidget *parent SIP_TRANSFERTHIS = nullptr );
100  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent SIP_TRANSFERTHIS = 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 = nullptr;
160  QgsGroupBoxCollapseButton *mCollapseButton = nullptr;
161  QWidget *mSyncParent = nullptr;
162  QString mSyncGroup;
163  bool mAltDown;
166 
168  QIcon mExpandIcon;
169 };
170 
184 {
185  Q_OBJECT
186 
190  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
191 
192 
195  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
196 
197  public:
198  QgsCollapsibleGroupBox( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsSettings *settings = nullptr );
199  QgsCollapsibleGroupBox( const QString &title, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsSettings *settings = nullptr );
200  ~QgsCollapsibleGroupBox() override;
201 
202  // set custom QgsSettings pointer if group box was already created from QtDesigner promotion
203  void setSettings( QgsSettings *settings );
204 
206  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
207 
212  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
213  bool saveCollapsedState() { return mSaveCollapsedState; }
214  bool saveCheckedState() { return mSaveCheckedState; }
215 
217  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
219  QString settingGroup() const { return mSettingGroup; }
220 
221  protected slots:
222 
230  void loadState();
231 
239  void saveState() const;
240 
241  protected:
242  void init();
243  void showEvent( QShowEvent *event ) override;
244  QString saveKey() const;
245 
246  // pointer to app or custom, external QgsSettings
247  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
248  QPointer<QgsSettings> mSettings;
250 
253  QString mSettingGroup;
254 };
255 
256 #endif
QgsGroupBoxCollapseButton(QWidget *parent=nullptr)
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
This class is a composition of two QSettings instances:
Definition: qgssettings.h:57
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. ...