QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
qgssettingseditorwidgetwrapperimpl.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssettingseditorwidgetwrapperimpl.h
3 --------------------------------------
4 Date : February 2023
5 Copyright : (C) 2023 by Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSSETTINGSEDITORWIDGETWRAPPERIMPL_H
17#define QGSSETTINGSEDITORWIDGETWRAPPERIMPL_H
18
19#include <QColor>
20
21#include "qgis_gui.h"
23#include "qgslogger.h"
24
26#include "qgscolorbutton.h"
27#include <QComboBox>
28#include <QLineEdit>
29#include <QCheckBox>
30#include <QSpinBox>
31#include <QDoubleSpinBox>
32#include <QTableWidget>
33
34
35//TODO variant map
36
37class QgsColorButton;
38
45template<class T, class V, class U>
47{
48 public:
50 QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = nullptr )
52
53 virtual QString id() const override = 0;
54
55 virtual bool setWidgetFromSetting() const override
56 {
57 if ( mSetting )
59
60 QgsDebugError( "editor is not configured" );
61 return false;
62 }
63
64 virtual bool setSettingFromWidget() const override = 0;
65
66 void setWidgetFromVariant( const QVariant &value ) const override
67 {
68 setWidgetValue( mSetting->convertFromVariant( value ) );
69 }
70
72 virtual bool setWidgetValue( const U &value ) const = 0;
73
74 QVariant variantValueFromWidget() const override
75 {
76 return QVariant::fromValue( valueFromWidget() );
77 };
78
80 virtual U valueFromWidget() const = 0;
81
83 V *editor() const {return mEditor;}
84
86 const T *setting() const {return mSetting;}
87
88 virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override = 0;
89
90 protected:
91 virtual QWidget *createEditorPrivate( QWidget *parent = nullptr ) const override
92 {
93 V *editor = new V( parent );
94 editor->setAutoFillBackground( true );
95 return editor;
96 }
97
99 {
100 mSetting = static_cast<const T *>( setting );
101 Q_ASSERT( mSetting );
102 mEditor = qobject_cast<V *>( editor );
103 if ( mEditor )
104 {
106 return true;
107 }
108 return false;
109 }
110
113
114 const T *mSetting = nullptr;
115 V *mEditor = nullptr;
116};
117
118
125class GUI_EXPORT QgsSettingsStringEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>
126{
127 Q_OBJECT
128 public:
130 QgsSettingsStringEditorWidgetWrapper( QObject *parent = nullptr )
131 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {}
132
133 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsStringEditorWidgetWrapper( parent );}
134
135 QString id() const override;
136
137 bool setSettingFromWidget() const override;
138
139 QString valueFromWidget() const override;
140
141 bool setWidgetValue( const QString &value ) const override;
142
143 void enableAutomaticUpdatePrivate() override;
144};
145
152class GUI_EXPORT QgsSettingsBoolEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>
153{
154 Q_OBJECT
155 public:
157 QgsSettingsBoolEditorWidgetWrapper( QObject *parent = nullptr )
158 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
159
160 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsBoolEditorWidgetWrapper( parent );}
161
162 QString id() const override;
163
164 bool setSettingFromWidget() const override;
165
166 bool valueFromWidget() const override;
167
168 bool setWidgetValue( const bool &value ) const override;
169
170 void enableAutomaticUpdatePrivate() override;
171};
172
179class GUI_EXPORT QgsSettingsIntegerEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>
180{
181 Q_OBJECT
182 public:
184 QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = nullptr )
186
187 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsIntegerEditorWidgetWrapper( parent );}
188
189 QString id() const override;
190
191 bool setSettingFromWidget() const override;
192
193 int valueFromWidget() const override;
194
195 bool setWidgetValue( const int &value ) const override;
196
197 void enableAutomaticUpdatePrivate() override;
198};
199
200
207class GUI_EXPORT QgsSettingsDoubleEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>
208{
209 Q_OBJECT
210 public:
212 QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = nullptr )
213 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
214
215 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsDoubleEditorWidgetWrapper( parent );}
216
217 QString id() const override;
218
219 bool setSettingFromWidget() const override;
220
221 double valueFromWidget() const override;
222
223 bool setWidgetValue( const double &value ) const override;
224
225 void enableAutomaticUpdatePrivate() override;
226};
227
228
235class GUI_EXPORT QgsSettingsColorEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>
236{
237 Q_OBJECT
238 public:
242
243 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsColorEditorWidgetWrapper( parent );}
244
245 QString id() const override;
246
247 bool setSettingFromWidget() const override;
248
249 QColor valueFromWidget() const override;
250
251 bool setWidgetValue( const QColor &value ) const override;
252
254
255 void enableAutomaticUpdatePrivate() override;
256};
257
258
260// * \ingroup gui
261// * \brief This class is a factory of editor for boolean settings
262// *
263// * \since QGIS 3.32
264// */
265//class GUI_EXPORT QgsSettingsStringListEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>
266//{
267// public:
268// QgsSettingsStringListEditorWidgetWrapper()
269// : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>() {}
270
271// QString id() const override;
272
273// bool setWidgetFromSetting() const override;
274
275// bool setSettingFromWidget() const override;
276
277// QStringList valueFromWidget() const override;
278//};
279
280#if defined(_MSC_VER)
281#ifndef SIP_RUN
287#endif
288#endif
289
290
291
292#endif // QGSSETTINGSEDITORWIDGETWRAPPERIMPL_H
A cross platform button subclass for selecting colors.
This class is a factory of editor for boolean settings.
QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const override
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
QgsSettingsBoolEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
This class is a factory of editor for color settings.
QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const override
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
QgsSettingsColorEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
This class is a factory of editor for double settings.
QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const override
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
QgsSettingsDoubleEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
This class is a base factory of editor for settings.
virtual QString id() const override=0
This id of the type of settings it handles.
virtual void configureEditorPrivateImplementation()
To be re-implemented to implemeent type specific configuration (e.g. opacity for colors)
virtual bool setWidgetValue(const U &value) const =0
Sets the widget value.
bool configureEditorPrivate(QWidget *editor, const QgsSettingsEntryBase *setting) override
Configures an existing editor widget.
QVariant variantValueFromWidget() const override
Returns the value from the widget as a variant The wrapper must be configured before calling this med...
virtual bool setWidgetFromSetting() const override
Sets the widget value from the setting value The wrapper must be configured before calling this medth...
virtual bool setSettingFromWidget() const override=0
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
virtual U valueFromWidget() const =0
Returns the widget value.
QgsSettingsEditorWidgetWrapperTemplate(QObject *parent=nullptr)
Constructor.
virtual QWidget * createEditorPrivate(QWidget *parent=nullptr) const override
Creates the widgets.
void setWidgetFromVariant(const QVariant &value) const override
Sets the value of the widget The wrapper must be configured before calling this medthod.
virtual QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const override=0
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
Base class for settings editor wrappers.
virtual void enableAutomaticUpdatePrivate()=0
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
Represent settings entry and provides methods for reading and writing settings values.
A boolean settings entry.
A color settings entry.
A double settings entry.
An integer settings entry.
A string settings entry.
This class is a factory of editor for integer settings.
QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const override
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
QgsSettingsIntegerEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
This class is a factory of editor for string settings.
QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const override
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
QgsSettingsStringEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
#define QgsDebugError(str)
Definition qgslogger.h:38