QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
150class GUI_EXPORT QgsSettingsBoolEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>
151{
152 Q_OBJECT
153 public:
155 QgsSettingsBoolEditorWidgetWrapper( QObject *parent = nullptr )
156 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
157
158 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsBoolEditorWidgetWrapper( parent );}
159
160 QString id() const override;
161
162 bool setSettingFromWidget() const override;
163
164 bool valueFromWidget() const override;
165
166 bool setWidgetValue( const bool &value ) const override;
167};
168
175class GUI_EXPORT QgsSettingsIntegerEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>
176{
177 Q_OBJECT
178 public:
180 QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = nullptr )
182
183 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsIntegerEditorWidgetWrapper( parent );}
184
185 QString id() const override;
186
187 bool setSettingFromWidget() const override;
188
189 int valueFromWidget() const override;
190
191 bool setWidgetValue( const int &value ) const override;
192};
193
194
201class GUI_EXPORT QgsSettingsDoubleEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>
202{
203 Q_OBJECT
204 public:
206 QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = nullptr )
207 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
208
209 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsDoubleEditorWidgetWrapper( parent );}
210
211 QString id() const override;
212
213 bool setSettingFromWidget() const override;
214
215 double valueFromWidget() const override;
216
217 bool setWidgetValue( const double &value ) const override;
218};
219
220
227class GUI_EXPORT QgsSettingsColorEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>
228{
229 Q_OBJECT
230 public:
234
235 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsColorEditorWidgetWrapper( parent );}
236
237 QString id() const override;
238
239 bool setSettingFromWidget() const override;
240
241 QColor valueFromWidget() const override;
242
243 bool setWidgetValue( const QColor &value ) const override;
244
246};
247
248
250// * \ingroup gui
251// * \brief This class is a factory of editor for boolean settings
252// *
253// * \since QGIS 3.32
254// */
255//class GUI_EXPORT QgsSettingsStringListEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>
256//{
257// public:
258// QgsSettingsStringListEditorWidgetWrapper()
259// : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>() {}
260
261// QString id() const override;
262
263// bool setWidgetFromSetting() const override;
264
265// bool setSettingFromWidget() const override;
266
267// QStringList valueFromWidget() const override;
268//};
269
270#if defined(_MSC_VER)
271#ifndef SIP_RUN
277#endif
278#endif
279
280
281
282#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.
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