QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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 <QLineEdit>
28#include <QCheckBox>
29#include <QSpinBox>
30#include <QDoubleSpinBox>
31#include <QTableWidget>
32
33
34//TODO variant map, enum
35
36class QgsColorButton;
37
44template<class T, class V, class U>
46{
47 public:
49 QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = nullptr )
51
52 virtual QString id() const override = 0;
53
54 virtual bool setWidgetFromSetting() const override
55 {
56 if ( mSetting )
57 return setWidgetValue( mSetting->value( mDynamicKeyPartList ) );
58
59 QgsDebugError( "editor is not configured" );
60 return false;
61 }
62
63 virtual bool setSettingFromWidget() const override = 0;
64
65 void setWidgetFromVariant( const QVariant &value ) const override
66 {
67 setWidgetValue( mSetting->convertFromVariant( value ) );
68 }
69
71 virtual bool setWidgetValue( const U &value ) const = 0;
72
73 QVariant variantValueFromWidget() const override
74 {
75 return valueFromWidget();
76 };
77
79 virtual U valueFromWidget() const = 0;
80
82 V *editor() const {return mEditor;}
83
85 const T *setting() const {return mSetting;}
86
87 virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override = 0;
88
89 protected:
90 virtual QWidget *createEditorPrivate( QWidget *parent = nullptr ) const override
91 {
92 V *editor = new V( parent );
93 editor->setAutoFillBackground( true );
94 return editor;
95 }
96
97 bool configureEditorPrivate( QWidget *editor, const QgsSettingsEntryBase *setting ) override
98 {
99 mSetting = dynamic_cast<const T *>( setting );
100 mEditor = qobject_cast<V *>( editor );
101 if ( mEditor )
102 {
103 configureEditorPrivateImplementation();
104 return true;
105 }
106 return false;
107 }
108
111
112 const T *mSetting = nullptr;
113 V *mEditor = nullptr;
114};
115
116
123class GUI_EXPORT QgsSettingsStringEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>
124{
125 Q_OBJECT
126 public:
128 QgsSettingsStringEditorWidgetWrapper( QObject *parent = nullptr )
129 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {}
130
131 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsStringEditorWidgetWrapper( parent );}
132
133 QString id() const override;
134
135 bool setSettingFromWidget() const override;
136
137 QString valueFromWidget() const override;
138
139 bool setWidgetValue( const QString &value ) const override;
140};
141
148class GUI_EXPORT QgsSettingsBoolEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>
149{
150 Q_OBJECT
151 public:
153 QgsSettingsBoolEditorWidgetWrapper( QObject *parent = nullptr )
154 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
155
156 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsBoolEditorWidgetWrapper( parent );}
157
158 QString id() const override;
159
160 bool setSettingFromWidget() const override;
161
162 bool valueFromWidget() const override;
163
164 bool setWidgetValue( const bool &value ) const override;
165};
166
173class GUI_EXPORT QgsSettingsIntegerEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>
174{
175 Q_OBJECT
176 public:
178 QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = nullptr )
180
181 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsIntegerEditorWidgetWrapper( parent );}
182
183 QString id() const override;
184
185 bool setSettingFromWidget() const override;
186
187 int valueFromWidget() const override;
188
189 bool setWidgetValue( const int &value ) const override;
190};
191
192
199class GUI_EXPORT QgsSettingsDoubleEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>
200{
201 Q_OBJECT
202 public:
204 QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = nullptr )
205 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
206
207 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsDoubleEditorWidgetWrapper( parent );}
208
209 QString id() const override;
210
211 bool setSettingFromWidget() const override;
212
213 double valueFromWidget() const override;
214
215 bool setWidgetValue( const double &value ) const override;
216};
217
218
225class GUI_EXPORT QgsSettingsColorEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>
226{
227 Q_OBJECT
228 public:
230 QgsSettingsColorEditorWidgetWrapper( QObject *parent = nullptr )
232
233 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsColorEditorWidgetWrapper( parent );}
234
235 QString id() const override;
236
237 bool setSettingFromWidget() const override;
238
239 QColor valueFromWidget() const override;
240
241 bool setWidgetValue( const QColor &value ) const override;
242
243 void configureEditorPrivateImplementation() override;
244};
245
247// * \ingroup gui
248// * \brief This class is a factory of editor for boolean settings
249// *
250// * \since QGIS 3.32
251// */
252//class GUI_EXPORT QgsSettingsStringListEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>
253//{
254// public:
255// QgsSettingsStringListEditorWidgetWrapper()
256// : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>() {}
257
258// QString id() const override;
259
260// bool setWidgetFromSetting() const override;
261
262// bool setSettingFromWidget() const override;
263
264// QStringList valueFromWidget() const override;
265//};
266
267#if defined(_MSC_VER)
268#ifndef SIP_RUN
274#endif
275#endif
276
277
278
279#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 bool setSettingFromWidget() const =0
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
virtual QString id() const =0
This id of the type of settings it handles.
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