QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 bool setWidgetFromVariant( const QVariant &value ) const override
67 {
68 return 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 QgsSettingsStringLineEditWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>
126{
127 Q_OBJECT
128 public:
130 QgsSettingsStringLineEditWrapper( QObject *parent = nullptr )
131 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {}
132
134 QgsSettingsStringLineEditWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
135 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
136
137
138 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsStringLineEditWrapper( parent ); }
139
140 QString id() const override;
141
142 bool setSettingFromWidget() const override;
143
144 QString valueFromWidget() const override;
145
146 bool setWidgetValue( const QString &value ) const override;
147
148 void enableAutomaticUpdatePrivate() override;
149};
150
151
158class GUI_EXPORT QgsSettingsStringComboBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>
159{
160 Q_OBJECT
161 public:
163 enum class Mode : int
164 {
165 Text,
166 Data
167 };
168
170 QgsSettingsStringComboBoxWrapper( QObject *parent = nullptr )
171 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( parent ) {}
172
174 QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
175 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
176
178 QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, const QStringList &dynamicKeyPartList = QStringList() )
179 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ), mMode( mode ) { configureEditor( editor, setting, dynamicKeyPartList ); }
180
181 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsStringComboBoxWrapper( parent ); }
182
183 QString id() const override;
184
185 bool setSettingFromWidget() const override;
186
187 QString valueFromWidget() const override;
188
189 bool setWidgetValue( const QString &value ) const override;
190
191 void enableAutomaticUpdatePrivate() override;
192
193 private:
194 Mode mMode = Mode::Text;
195};
196
197
204class GUI_EXPORT QgsSettingsBoolCheckBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>
205{
206 Q_OBJECT
207 public:
209 QgsSettingsBoolCheckBoxWrapper( QObject *parent = nullptr )
210 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
211
213 QgsSettingsBoolCheckBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
214 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
215
216 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsBoolCheckBoxWrapper( parent ); }
217
218 QString id() const override;
219
220 bool setSettingFromWidget() const override;
221
222 bool valueFromWidget() const override;
223
224 bool setWidgetValue( const bool &value ) const override;
225
226 void enableAutomaticUpdatePrivate() override;
227};
228
235class GUI_EXPORT QgsSettingsIntegerSpinBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>
236{
237 Q_OBJECT
238 public:
240 QgsSettingsIntegerSpinBoxWrapper( QObject *parent = nullptr )
242
244 QgsSettingsIntegerSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
245 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
246
247 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsIntegerSpinBoxWrapper( parent ); }
248
249 QString id() const override;
250
251 bool setSettingFromWidget() const override;
252
253 int valueFromWidget() const override;
254
255 bool setWidgetValue( const int &value ) const override;
256
257 void enableAutomaticUpdatePrivate() override;
258};
259
260
267class GUI_EXPORT QgsSettingsDoubleSpinBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>
268{
269 Q_OBJECT
270 public:
272 QgsSettingsDoubleSpinBoxWrapper( QObject *parent = nullptr )
273 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
274
276 QgsSettingsDoubleSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
277 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
278
279 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsDoubleSpinBoxWrapper( parent ); }
280
281 QString id() const override;
282
283 bool setSettingFromWidget() const override;
284
285 double valueFromWidget() const override;
286
287 bool setWidgetValue( const double &value ) const override;
288
289 void enableAutomaticUpdatePrivate() override;
290};
291
292
299class GUI_EXPORT QgsSettingsColorButtonWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>
300{
301 Q_OBJECT
302 public:
306
308 QgsSettingsColorButtonWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
309 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
310
311 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsColorButtonWrapper( parent ); }
312
313 QString id() const override;
314
315 bool setSettingFromWidget() const override;
316
317 QColor valueFromWidget() const override;
318
319 bool setWidgetValue( const QColor &value ) const override;
320
322
323 void enableAutomaticUpdatePrivate() override;
324};
325
326
328// * \ingroup gui
329// * \brief This class is a factory of editor for boolean settings
330// *
331// * \since QGIS 3.32
332// */
333//class GUI_EXPORT QgsSettingsStringListEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>
334//{
335// public:
336// QgsSettingsStringListEditorWidgetWrapper()
337// : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>() {}
338
339// QString id() const override;
340
341// bool setWidgetFromSetting() const override;
342
343// bool setSettingFromWidget() const override;
344
345// QStringList valueFromWidget() const override;
346//};
347
348#if defined( _MSC_VER )
349#ifndef SIP_RUN
355#endif
356#endif
357
358
359#endif // QGSSETTINGSEDITORWIDGETWRAPPERIMPL_H
A cross platform button subclass for selecting colors.
This class is a factory of editor for boolean settings with a checkbox.
QgsSettingsBoolCheckBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
QgsSettingsBoolCheckBoxWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
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.
This class is a factory of editor for color settings with a color button.
QgsSettingsColorButtonWrapper(QObject *parent=nullptr)
Constructor of the factory.
QgsSettingsColorButtonWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
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.
This class is a factory of editor for double settings with a double spin box.
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.
QgsSettingsDoubleSpinBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
QgsSettingsDoubleSpinBoxWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
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.
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.
bool setWidgetFromVariant(const QVariant &value) const override
Sets the value of the widget The wrapper must be configured before calling this medthod.
Base class for settings editor wrappers.
bool configureEditor(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Configures the editor according the setting.
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 with a spin box.
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.
QgsSettingsIntegerSpinBoxWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
QgsSettingsIntegerSpinBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
This class is a factory of editor for string settings with a combo box.
QgsSettingsStringComboBoxWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
QgsSettingsStringComboBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
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.
QgsSettingsStringComboBoxWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
Mode
Mode to determine if the value is hold in the combo box text or data.
This class is a factory of editor for string settings with a line edit.
QgsSettingsStringLineEditWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Constructor of the wrapper for a given setting and its widget editor.
QgsSettingsStringLineEditWrapper(QObject *parent=nullptr)
Constructor of the factory.
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.
#define QgsDebugError(str)
Definition qgslogger.h:38