QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 "qgis_gui.h"
22#include "qgis_sip.h"
23#include "qgssettings.h"
24
25#include <QGroupBox>
26#include <QPointer>
27#include <QToolButton>
28
29class QMouseEvent;
30class QToolButton;
31class QScrollArea;
32
38class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
39{
40 Q_OBJECT
41
42 public:
43 QgsGroupBoxCollapseButton( QWidget *parent SIP_TRANSFERTHIS = nullptr )
44 : QToolButton( parent )
45 {}
46
47 bool altDown() const { return mAltDown; }
48 void setAltDown( bool updown ) { mAltDown = updown; }
49
50 bool shiftDown() const { return mShiftDown; }
51 void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
52
53 protected:
54 void mouseReleaseEvent( QMouseEvent *event ) override;
55
56 private:
57 bool mAltDown = false;
58 bool mShiftDown = false;
59};
60
75
76class 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() const { return mScrollOnExpand; }
129
130 signals:
133
134 public slots:
135 void checkToggled( bool ckd );
136 void checkClicked( bool ckd );
137 void toggleCollapsed();
138
144 void setStyleSheet( const QString &style );
145
146 protected:
148 void collapseExpandFixes();
149
150 void showEvent( QShowEvent *event ) override;
151 void mousePressEvent( QMouseEvent *event ) override;
152 void mouseReleaseEvent( QMouseEvent *event ) override;
153 void changeEvent( QEvent *event ) override;
154
155 void updateStyle();
156 QRect titleRect() const;
157 void clearModifiers();
158
163 bool mShown;
164 QScrollArea *mParentScrollArea = nullptr;
166 QWidget *mSyncParent = nullptr;
167 QString mSyncGroup;
171
174
175 private:
176 void init();
177};
178
194
196{
197 Q_OBJECT
198
203
204
208
209 public:
210 QgsCollapsibleGroupBox( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsSettings *settings = nullptr );
211 QgsCollapsibleGroupBox( const QString &title, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsSettings *settings = nullptr );
212 ~QgsCollapsibleGroupBox() override;
213
214 // set custom QgsSettings pointer if group box was already created from QtDesigner promotion
215 void setSettings( QgsSettings *settings );
216
218 void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
219
225 void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
226
230 bool saveCollapsedState() const { return mSaveCollapsedState; }
231
235 bool saveCheckedState() const { return mSaveCheckedState; }
236
238 void setSettingGroup( const QString &group ) { mSettingGroup = group; }
240 QString settingGroup() const { return mSettingGroup; }
241
242 protected slots:
243
252 void loadState();
253
262 void saveState() const;
263
264 protected:
265 void showEvent( QShowEvent *event ) override;
266 QString saveKey() const;
267
268 private:
269 void init();
270
271 // pointer to app or custom, external QgsSettings
272 // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
273 QPointer<QgsSettings> mSettings;
274 bool mDelSettings;
275
276 bool mSaveCollapsedState;
277 bool mSaveCheckedState;
278 QString mSettingGroup;
279};
280
281#endif
QString syncGroup
An optional group to be collapsed and uncollapsed in sync with this group box if the Alt-modifier is ...
void changeEvent(QEvent *event) override
void collapseExpandFixes()
Visual fixes for when group box is collapsed/expanded.
void setScrollOnExpand(bool scroll)
Sets this to false to not automatically scroll parent QScrollArea to this widget's contents when expa...
bool collapsed
The collapsed state of this group box.
QgsCollapsibleGroupBoxBasic(QWidget *parent=nullptr)
QString syncGroup() const
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
void setSyncGroup(const QString &grp)
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
bool isCollapsed() const
Returns the current collapsed state of this group box.
void showEvent(QShowEvent *event) override
bool scrollOnExpand
If this property is set to true, a parent scroll area will try to make sure that the whole group box ...
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
QgsGroupBoxCollapseButton * mCollapseButton
void setStyleSheet(const QString &style)
Overridden to prepare base call and avoid crash due to specific QT versions.
void setCollapsed(bool collapse)
Collapse or uncollapse this groupbox.
void mousePressEvent(QMouseEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
bool scrollOnExpand() const
If this is set to false the parent QScrollArea will not be automatically scrolled to this widget's co...
bool saveCollapsedState() const
Returns whether the collapsed state of this group box is saved and loaded persistently in QgsSettings...
void setSaveCheckedState(bool save)
Set this to true to save/restore checked state.
void setSaveCollapsedState(bool save)
Sets this to false to not save/restore collapsed state.
QgsCollapsibleGroupBox(QWidget *parent=nullptr, QgsSettings *settings=nullptr)
void setSettingGroup(const QString &group)
Sets this to a defined string to share save/restore states across different parent dialogs.
QString settingGroup() const
Returns the name of the setting group in which the collapsed state will be saved.
bool saveCollapsedState
Shall the collapsed state of this group box be saved and loaded persistently in QgsSettings.
bool saveCheckedState() const
Returns whether the checked state of this group box is saved and loaded persistently in QgsSettings.
bool saveCheckedState
Shall the checked state of this group box be saved and loaded persistently in QgsSettings.
void setSettings(QgsSettings *settings)
A collapse button widget for collapsible group boxes.
void setShiftDown(bool shiftdown)
QgsGroupBoxCollapseButton(QWidget *parent=nullptr)
Stores settings for use within QGIS.
Definition qgssettings.h:65
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53