QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
qgssettingseditorwidgetwrapperimpl.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssettingseditorwidgetwrapperimpl.cpp
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
18#include "qgslogger.h"
20#include "qgscolorbutton.h"
21
22#include <QLineEdit>
23#include <QCheckBox>
24
25
26// *******
27// String
28// *******
29
31{
32 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
33}
34
36{
37 if ( mEditor )
38 {
39 mEditor->setText( value );
40 return true;
41 }
42 else
43 {
44 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
45 }
46 return false;
47}
48
50{
51 QObject::connect( this->mEditor, &QLineEdit::textChanged, this, [ = ]( const QString & text )
52 {
53 this->mSetting->setValue( text, this->mDynamicKeyPartList );
54 } );
55}
56
58{
59 if ( mEditor )
60 {
62 return true;
63 }
64 else
65 {
66 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
67 }
68 return false;
69}
70
72{
73 if ( mEditor )
74 {
75 return mEditor->text();
76 }
77 else
78 {
79 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
80 }
81 return QString();
82}
83
84// *******
85// Boolean
86// *******
87
89{
90 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
91}
92
94{
95 if ( mEditor )
96 {
97 mEditor->setChecked( value );
98 return true;
99 }
100 else
101 {
102 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
103 }
104 return false;
105}
106
108{
109 QObject::connect( this->mEditor, &QCheckBox::clicked, this, [ = ]( bool checked )
110 {
111 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
112 } );
113}
114
116{
117 if ( mEditor )
118 {
120 return true;
121 }
122 else
123 {
124 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
125 }
126 return false;
127}
128
130{
131
132 if ( mEditor )
133 {
134 return mEditor->isChecked();
135 }
136 else
137 {
138 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
139 }
140 return false;
141}
142
143
144// *******
145// Integer
146// *******
147
149{
150 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
151}
152
154{
155 if ( mEditor )
156 {
157 mEditor->setValue( value );
158 return true;
159 }
160 else
161 {
162 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
163 }
164 return false;
165}
166
168{
169 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [ = ]( int value )
170 {
171 this->mSetting->setValue( value, this->mDynamicKeyPartList );
172 } );
173}
174
176{
177 if ( mEditor )
178 {
180 return true;
181 }
182 else
183 {
184 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
185 }
186 return false;
187}
188
190{
191 if ( mEditor )
192 {
193 return mEditor->value();
194 }
195 else
196 {
197 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
198 }
199 return std::numeric_limits<int>::quiet_NaN();
200}
201
202
203
204// *******
205// Double
206// *******
207
209{
210 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
211}
212
214{
215 if ( mEditor )
216 {
217 mEditor->setValue( value );
218 return true;
219 }
220 else
221 {
222 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
223 }
224 return false;
225}
226
228{
229 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [ = ]( double value )
230 {
231 this->mSetting->setValue( value, this->mDynamicKeyPartList );
232 } );
233}
234
236{
237 if ( mEditor )
238 {
240 return true;
241 }
242 else
243 {
244 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
245 }
246 return false;
247}
248
250{
251 if ( mEditor )
252 {
253 return mEditor->value();
254 }
255 else
256 {
257 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
258 }
259 return std::numeric_limits<double>::quiet_NaN();
260}
261
262// *******
263// Color
264// *******
265
267{
268 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
269}
270
272{
273 if ( mEditor )
274 {
275 mEditor->setColor( value );
276 return true;
277 }
278 else
279 {
280 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
281 }
282 return false;
283}
284
286{
287 if ( mEditor )
288 {
290 }
291 else
292 {
293 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
294 }
295}
296
298{
299 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [ = ]( const QColor & color )
300 {
301 this->mSetting->setValue( color, this->mDynamicKeyPartList );
302 } );
303}
304
306{
307 if ( mEditor )
308 {
310 return true;
311 }
312 else
313 {
314 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
315 }
316 return false;
317}
318
320{
321 if ( mEditor )
322 {
323 return mEditor->color();
324 }
325 else
326 {
327 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
328 }
329 return QColor();
330}
331
332// *******
333// StringList
334// *******
335
336//QString QgsSettingsStringListEditorWidgetWrapper::id() const
337//{
338// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
339//}
340
341//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
342//{
343// if ( mEditor )
344// {
345// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
346// return true;
347// }
348// else
349// {
350// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
351// }
352// return false;
353//}
354
355//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
356//{
357// if ( mEditor )
358// {
359// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
360// return true;
361// }
362// else
363// {
364// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
365// }
366// return false;
367//}
368
369//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
370//{
371// if ( mEditor )
372// {
373// return mEditor->value();
374// }
375// else
376// {
377// QgsDebugError(QString("editor is not set, returning a non-existing value"));
378// }
379// return QStringList();
380//}
@ Double
Double precision number.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
void setColor(const QColor &color)
Sets the current color for the button.
bool valueFromWidget() const override
Returns the widget value.
bool setWidgetValue(const bool &value) const override
Sets the widget value.
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
QString id() const override
This id of the type of settings it handles.
QString id() const override
This id of the type of settings it handles.
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
QColor valueFromWidget() const override
Returns the widget value.
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
bool setWidgetValue(const QColor &value) const override
Sets the widget value.
void configureEditorPrivateImplementation() override
To be re-implemented to implemeent type specific configuration (e.g. opacity for colors)
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
bool setWidgetValue(const double &value) const override
Sets the widget value.
double valueFromWidget() const override
Returns the widget value.
QString id() const override
This id of the type of settings it handles.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QString definitionKey() const
Returns settings entry defining key.
bool allowAlpha() const
Returns true if transparency is allowed for the color.
QString id() const override
This id of the type of settings it handles.
bool setWidgetValue(const int &value) const override
Sets the widget value.
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
int valueFromWidget() const override
Returns the widget value.
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
bool setWidgetValue(const QString &value) const override
Sets the widget value.
QString valueFromWidget() const override
Returns the widget value.
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
QString id() const override
This id of the type of settings it handles.
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
#define QgsDebugError(str)
Definition qgslogger.h:38