QGIS API Documentation 3.99.0-Master (c22de0620c0)
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 "qgis_gui.h"
20#include "qgscolorbutton.h"
21#include "qgslogger.h"
24
25#include <QCheckBox>
26#include <QColor>
27#include <QComboBox>
28#include <QDoubleSpinBox>
29#include <QGroupBox>
30#include <QLineEdit>
31#include <QSpinBox>
32#include <QTableWidget>
33
34//TODO variant map
35
36class QgsColorButton;
37
44template<class T, class V, class U>
46{
47 public:
49 QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = nullptr )
51
52 QString id() const override = 0;
53
54 bool setWidgetFromSetting() const override
55 {
56 if ( mSetting )
58
59 QgsDebugError( "editor is not configured" );
60 return false;
61 }
62
63 bool setSettingFromWidget() const override = 0;
64
65 bool setWidgetFromVariant( const QVariant &value ) const override
66 {
67 return setWidgetValue( mSetting->convertFromVariant( value ) );
68 }
69
71 virtual bool setWidgetValue( const U &value ) const = 0;
72
73 QVariant variantValueFromWidget() const override
74 {
75 return QVariant::fromValue( 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 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override = 0;
88
89 protected:
90 QWidget *createEditorPrivate( QWidget *parent = nullptr ) const override
91 {
92 V *editor = new V( parent );
93 editor->setAutoFillBackground( true );
94 return editor;
95 }
96
98 {
99 mSetting = static_cast<const T *>( setting );
100 Q_ASSERT( mSetting );
101 mEditor = qobject_cast<V *>( editor );
102 if ( mEditor )
103 {
105 return true;
106 }
107 return false;
108 }
109
112
113 const T *mSetting = nullptr;
114 V *mEditor = nullptr;
115};
116
117
124class GUI_EXPORT QgsSettingsStringLineEditWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>
125{
126 Q_OBJECT
127 public:
129 QgsSettingsStringLineEditWrapper( QObject *parent = nullptr )
130 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {}
131
135
136
137 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsStringLineEditWrapper( parent ); }
138
139 QString id() const override;
140
141 bool setSettingFromWidget() const override;
142
143 QString valueFromWidget() const override;
144
145 bool setWidgetValue( const QString &value ) const override;
146
147 void enableAutomaticUpdatePrivate() override;
148};
149
150
157class GUI_EXPORT QgsSettingsStringComboBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>
158{
159 Q_OBJECT
160 public:
162 enum class Mode : int
163 {
164 Text,
165 Data
166 };
167
169 QgsSettingsStringComboBoxWrapper( QObject *parent = nullptr )
170 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( parent ) {}
171
175
179
184 QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, int role, const QStringList &dynamicKeyPartList = QStringList() )
185 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ), mMode( mode ), mDataRole( role ) { configureEditor( editor, setting, dynamicKeyPartList ); }
186
187 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsStringComboBoxWrapper( parent ); }
188
189 QString id() const override;
190
191 bool setSettingFromWidget() const override;
192
193 QString valueFromWidget() const override;
194
195 bool setWidgetValue( const QString &value ) const override;
196
197 void enableAutomaticUpdatePrivate() override;
198
199 private:
200 Mode mMode = Mode::Text;
201 int mDataRole = Qt::UserRole; // Default to UserRole, can be changed in the constructor
202};
203
204
211class GUI_EXPORT QgsSettingsBoolCheckBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>
212{
213 Q_OBJECT
214 public:
216 QgsSettingsBoolCheckBoxWrapper( QObject *parent = nullptr )
217 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
218
222
223 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsBoolCheckBoxWrapper( parent ); }
224
225 QString id() const override;
226
227 bool setSettingFromWidget() const override;
228
229 bool valueFromWidget() const override;
230
231 bool setWidgetValue( const bool &value ) const override;
232
233 void enableAutomaticUpdatePrivate() override;
234};
235
242class GUI_EXPORT QgsSettingsBoolGroupBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QGroupBox, bool>
243{
244 Q_OBJECT
245 public:
247 QgsSettingsBoolGroupBoxWrapper( QObject *parent = nullptr )
248 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QGroupBox, bool>( parent ) {}
249
253
254 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsBoolGroupBoxWrapper( parent ); }
255
256 QString id() const override;
257
258 bool setSettingFromWidget() const override;
259
260 bool valueFromWidget() const override;
261
262 bool setWidgetValue( const bool &value ) const override;
263
264 void enableAutomaticUpdatePrivate() override;
265
266 protected:
268};
269
276class GUI_EXPORT QgsSettingsIntegerSpinBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>
277{
278 Q_OBJECT
279 public:
281 QgsSettingsIntegerSpinBoxWrapper( QObject *parent = nullptr )
283
287
288 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsIntegerSpinBoxWrapper( parent ); }
289
290 QString id() const override;
291
292 bool setSettingFromWidget() const override;
293
294 int valueFromWidget() const override;
295
296 bool setWidgetValue( const int &value ) const override;
297
298 void enableAutomaticUpdatePrivate() override;
299};
300
301
308class GUI_EXPORT QgsSettingsDoubleSpinBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>
309{
310 Q_OBJECT
311 public:
313 QgsSettingsDoubleSpinBoxWrapper( QObject *parent = nullptr )
314 : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
315
319
320 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsDoubleSpinBoxWrapper( parent ); }
321
322 QString id() const override;
323
324 bool setSettingFromWidget() const override;
325
326 double valueFromWidget() const override;
327
328 bool setWidgetValue( const double &value ) const override;
329
330 void enableAutomaticUpdatePrivate() override;
331};
332
333
340class GUI_EXPORT QgsSettingsColorButtonWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>
341{
342 Q_OBJECT
343 public:
347
351
352 QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsColorButtonWrapper( parent ); }
353
354 QString id() const override;
355
356 bool setSettingFromWidget() const override;
357
358 QColor valueFromWidget() const override;
359
360 bool setWidgetValue( const QColor &value ) const override;
361
363
364 void enableAutomaticUpdatePrivate() override;
365};
366
367
369// * \ingroup gui
370// * \brief This class is a factory of editor for boolean settings
371// *
372// * \since QGIS 3.32
373// */
374//class GUI_EXPORT QgsSettingsStringListEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>
375//{
376// public:
377// QgsSettingsStringListEditorWidgetWrapper()
378// : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryStringList, QTableWidget, QStringList>() {}
379
380// QString id() const override;
381
382// bool setWidgetFromSetting() const override;
383
384// bool setSettingFromWidget() const override;
385
386// QStringList valueFromWidget() const override;
387//};
388
389#if defined( _MSC_VER )
390#ifndef SIP_RUN
397#endif
398#endif
399
400
401#endif // QGSSETTINGSEDITORWIDGETWRAPPERIMPL_H
A cross platform button subclass for selecting colors.
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.
QgsSettingsBoolGroupBoxWrapper(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.
QgsSettingsBoolGroupBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
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.
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.
bool setSettingFromWidget() const override=0
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
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...
bool setWidgetFromSetting() const override
Sets the widget value from the setting value The wrapper must be configured before calling this medth...
QString id() const override=0
This id of the type of settings it handles.
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.
QWidget * createEditorPrivate(QWidget *parent=nullptr) const override
Creates the widgets.
virtual U valueFromWidget() const =0
Returns the widget value.
QgsSettingsEditorWidgetWrapperTemplate(QObject *parent=nullptr)
Constructor.
bool setWidgetFromVariant(const QVariant &value) const override
Sets the value of the widget The wrapper must be configured before calling this medthod.
QStringList dynamicKeyPartList() const
Returns the dynamic key parts.
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...
QgsSettingsEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
Represents a 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.
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.
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.
QgsSettingsStringComboBoxWrapper(QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, int role, 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.
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:59