QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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 "moc_qgssettingseditorwidgetwrapperimpl.cpp"
19#include "qgslogger.h"
21#include "qgscolorbutton.h"
22
23#include <QLineEdit>
24#include <QCheckBox>
25
26
27// *******
28// String with line edit (= default)
29// *******
30
32{
33 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
34}
35
36bool QgsSettingsStringLineEditWrapper::setWidgetValue( const QString &value ) const
37{
38 if ( mEditor )
39 {
40 mEditor->setText( value );
41 return true;
42 }
43 else
44 {
45 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
46 }
47 return false;
48}
49
51{
52 QObject::connect( this->mEditor, &QLineEdit::textChanged, this, [=]( const QString &text ) {
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// String with combo box
86// *******
87
89{
90 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
91}
92
93bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) const
94{
95 if ( mEditor )
96 {
97 int idx = mMode == Mode::Data ? mEditor->findData( value ) : mEditor->findText( value );
98 if ( idx >= 0 )
99 {
100 mEditor->setCurrentIndex( idx );
101 return true;
102 }
103 else
104 {
105 return false;
106 }
107 }
108 else
109 {
110 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
111 }
112 return false;
113}
114
116{
117 QObject::connect( mEditor, &QComboBox::currentTextChanged, this, [=]( const QString &currentText ) {
118 QString textValue = currentText;
119 if ( mMode == Mode::Data )
120 textValue = mEditor->currentData().toString();
122 } );
123}
124
126{
127 if ( mEditor )
128 {
130 return true;
131 }
132 else
133 {
134 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
135 }
136 return false;
137}
138
140{
141 if ( mEditor )
142 {
143 return mMode == Mode::Data ? mEditor->currentData().toString() : mEditor->currentText();
144 }
145 else
146 {
147 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
148 }
149 return QString();
150}
151
152// *******
153// Boolean
154// *******
155
157{
158 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
159}
160
162{
163 if ( mEditor )
164 {
165 mEditor->setChecked( value );
166 return true;
167 }
168 else
169 {
170 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
171 }
172 return false;
173}
174
176{
177 QObject::connect( this->mEditor, &QCheckBox::clicked, this, [=]( bool checked ) {
178 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
179 } );
180}
181
183{
184 if ( mEditor )
185 {
187 return true;
188 }
189 else
190 {
191 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
192 }
193 return false;
194}
195
197{
198 if ( mEditor )
199 {
200 return mEditor->isChecked();
201 }
202 else
203 {
204 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
205 }
206 return false;
207}
208
209
210// *******
211// Integer
212// *******
213
215{
216 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
217}
218
220{
221 if ( mEditor )
222 {
223 mEditor->setValue( value );
224 return true;
225 }
226 else
227 {
228 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
229 }
230 return false;
231}
232
234{
235 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [=]( int value ) {
236 this->mSetting->setValue( value, this->mDynamicKeyPartList );
237 } );
238}
239
241{
242 if ( mEditor )
243 {
245 return true;
246 }
247 else
248 {
249 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
250 }
251 return false;
252}
253
255{
256 if ( mEditor )
257 {
258 return mEditor->value();
259 }
260 else
261 {
262 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
263 }
264 return std::numeric_limits<int>::quiet_NaN();
265}
266
267
268// *******
269// Double
270// *******
271
273{
274 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
275}
276
277bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
278{
279 if ( mEditor )
280 {
281 mEditor->setValue( value );
282 return true;
283 }
284 else
285 {
286 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
287 }
288 return false;
289}
290
292{
293 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [=]( double value ) {
294 this->mSetting->setValue( value, this->mDynamicKeyPartList );
295 } );
296}
297
299{
300 if ( mEditor )
301 {
303 return true;
304 }
305 else
306 {
307 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
308 }
309 return false;
310}
311
313{
314 if ( mEditor )
315 {
316 return mEditor->value();
317 }
318 else
319 {
320 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
321 }
322 return std::numeric_limits<double>::quiet_NaN();
323}
324
325// *******
326// Color
327// *******
328
330{
331 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
332}
333
334bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
335{
336 if ( mEditor )
337 {
338 mEditor->setColor( value );
339 return true;
340 }
341 else
342 {
343 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
344 }
345 return false;
346}
347
349{
350 if ( mEditor )
351 {
353 }
354 else
355 {
356 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
357 }
358}
359
361{
362 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [=]( const QColor &color ) {
363 this->mSetting->setValue( color, this->mDynamicKeyPartList );
364 } );
365}
366
368{
369 if ( mEditor )
370 {
372 return true;
373 }
374 else
375 {
376 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
377 }
378 return false;
379}
380
382{
383 if ( mEditor )
384 {
385 return mEditor->color();
386 }
387 else
388 {
389 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
390 }
391 return QColor();
392}
393
394// *******
395// StringList
396// *******
397
398//QString QgsSettingsStringListEditorWidgetWrapper::id() const
399//{
400// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
401//}
402
403//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
404//{
405// if ( mEditor )
406// {
407// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
408// return true;
409// }
410// else
411// {
412// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
413// }
414// return false;
415//}
416
417//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
418//{
419// if ( mEditor )
420// {
421// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
422// return true;
423// }
424// else
425// {
426// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
427// }
428// return false;
429//}
430
431//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
432//{
433// if ( mEditor )
434// {
435// return mEditor->value();
436// }
437// else
438// {
439// QgsDebugError(QString("editor is not set, returning a non-existing value"));
440// }
441// return QStringList();
442//}
@ 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.
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...
bool valueFromWidget() const override
Returns the widget value.
bool setWidgetValue(const bool &value) const override
Sets the widget value.
QColor valueFromWidget() const override
Returns the widget value.
void configureEditorPrivateImplementation() override
To be re-implemented to implemeent type specific configuration (e.g. opacity for colors)
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...
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.
double 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 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.
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.
bool setWidgetValue(const int &value) const override
Sets the widget value.
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
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.
int valueFromWidget() const override
Returns the widget value.
bool setWidgetValue(const QString &value) const override
Sets the widget value.
QString id() const override
This id of the type of settings it handles.
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
QString valueFromWidget() const override
Returns the widget value.
@ Data
Value is defined as data entry with Qt::UserRole.
bool setSettingFromWidget() const override
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
QString valueFromWidget() const override
Returns the widget value.
bool setWidgetValue(const QString &value) const override
Sets the widget value.
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...
void enableAutomaticUpdatePrivate() override
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
#define QgsDebugError(str)
Definition qgslogger.h:38