QGIS API Documentation 3.43.0-Master (c67cf405802)
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
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
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() { 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
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;
165 QgsGroupBoxCollapseButton *mCollapseButton = nullptr;
166 QWidget *mSyncParent = nullptr;
167 QString mSyncGroup;
171
174
175 private:
176 void init();
177};
178
196{
197 Q_OBJECT
198
202 Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
203
204
207 Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
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 bool saveCollapsedState() { return mSaveCollapsedState; }
227 bool saveCheckedState() { return mSaveCheckedState; }
228
230 void setSettingGroup( const QString &group ) { mSettingGroup = group; }
232 QString settingGroup() const { return mSettingGroup; }
233
234 protected slots:
235
244 void loadState();
245
254 void saveState() const;
255
256 protected:
257 void showEvent( QShowEvent *event ) override;
258 QString saveKey() const;
259
260 private:
261 void init();
262
263 // pointer to app or custom, external QgsSettings
264 // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
265 QPointer<QgsSettings> mSettings;
266 bool mDelSettings;
267
268 bool mSaveCollapsedState;
269 bool mSaveCheckedState;
270 QString mSettingGroup;
271};
272
273#endif
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's co...
void setScrollOnExpand(bool scroll)
Sets this to false to not automatically scroll parent QScrollArea to this widget's contents when expa...
QString syncGroup() const
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
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 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.
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:66
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53