QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
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
19#include "qgscolorbutton.h"
20#include "qgslogger.h"
22
23#include <QCheckBox>
24#include <QLineEdit>
25#include <QString>
26
27#include "moc_qgssettingseditorwidgetwrapperimpl.cpp"
28
29using namespace Qt::StringLiterals;
30
31// *******
32// String with line edit (= default)
33// *******
34
36{
37 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
38}
39
40bool QgsSettingsStringLineEditWrapper::setWidgetValue( const QString &value ) const
41{
42 if ( mEditor )
43 {
44 mEditor->setText( value );
45 return true;
46 }
47 else
48 {
49 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
50 }
51 return false;
52}
53
55{
56 QObject::connect( this->mEditor, &QLineEdit::textChanged, this, [this]( const QString &text ) {
57 this->mSetting->setValue( text, this->mDynamicKeyPartList );
58 } );
59}
60
62{
63 if ( mEditor )
64 {
65 mSetting->setValue( mEditor->text(), mDynamicKeyPartList );
66 return true;
67 }
68 else
69 {
70 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
71 }
72 return false;
73}
74
76{
77 if ( mEditor )
78 {
79 return mEditor->text();
80 }
81 else
82 {
83 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
84 }
85 return QString();
86}
87
88// *******
89// String with combo box
90// *******
91
93{
94 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
95}
96
97bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) const
98{
99 if ( mEditor )
100 {
101 int idx = mMode == Mode::Data ? mEditor->findData( value, mDataRole ) : mEditor->findText( value );
102 if ( idx >= 0 )
103 {
104 mEditor->setCurrentIndex( idx );
105 return true;
106 }
107 else
108 {
109 return false;
110 }
111 }
112 else
113 {
114 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
115 }
116 return false;
117}
118
120{
121 QObject::connect( mEditor, &QComboBox::currentTextChanged, this, [this]( const QString &currentText ) {
122 QString textValue = currentText;
123 if ( mMode == Mode::Data )
124 textValue = mEditor->currentData().toString();
125 mSetting->setValue( textValue, mDynamicKeyPartList );
126 } );
127}
128
130{
131 if ( mEditor )
132 {
134 return true;
135 }
136 else
137 {
138 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
139 }
140 return false;
141}
142
144{
145 if ( mEditor )
146 {
147 return mMode == Mode::Data ? mEditor->currentData( mDataRole ).toString() : mEditor->currentText();
148 }
149 else
150 {
151 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
152 }
153 return QString();
154}
155
156// *******
157// Boolean
158// *******
159
161{
162 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
163}
164
166{
167 if ( mEditor )
168 {
169 mEditor->setChecked( value );
170 return true;
171 }
172 else
173 {
174 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
175 }
176 return false;
177}
178
180{
181 QObject::connect( this->mEditor, &QCheckBox::clicked, this, [this]( bool checked ) {
182 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
183 } );
184}
185
187{
188 if ( mEditor )
189 {
190 mSetting->setValue( mEditor->isChecked(), mDynamicKeyPartList );
191 return true;
192 }
193 else
194 {
195 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
196 }
197 return false;
198}
199
201{
202 if ( mEditor )
203 {
204 return mEditor->isChecked();
205 }
206 else
207 {
208 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
209 }
210 return false;
211}
212
213
214// ******************
215// Boolean (GroupBox)
216// ******************
217
219{
220 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
221}
222
224{
225 if ( mEditor )
226 {
227 mEditor->setChecked( value );
228 return true;
229 }
230 else
231 {
232 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
233 }
234 return false;
235}
236
238{
239 QObject::connect( this->mEditor, &QGroupBox::clicked, this, [this]( bool checked ) {
240 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
241 } );
242}
243
245{
246 if ( mEditor )
247 {
248 mSetting->setValue( mEditor->isChecked(), mDynamicKeyPartList );
249 return true;
250 }
251 else
252 {
253 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
254 }
255 return false;
256}
257
259{
260 if ( mEditor )
261 {
262 return mEditor->isChecked();
263 }
264 else
265 {
266 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
267 }
268 return false;
269}
270
275
276
277// *******
278// Integer
279// *******
280
282{
283 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
284}
285
287{
288 if ( mEditor )
289 {
290 mEditor->setValue( value );
291 return true;
292 }
293 else
294 {
295 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
296 }
297 return false;
298}
299
301{
302 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [this]( int value ) {
303 this->mSetting->setValue( value, this->mDynamicKeyPartList );
304 } );
305}
306
308{
309 if ( mEditor )
310 {
311 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
312 return true;
313 }
314 else
315 {
316 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
317 }
318 return false;
319}
320
322{
323 if ( mEditor )
324 {
325 return mEditor->value();
326 }
327 else
328 {
329 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
330 }
331 return std::numeric_limits<int>::quiet_NaN();
332}
333
334
335// *******
336// Double
337// *******
338
340{
341 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
342}
343
344bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
345{
346 if ( mEditor )
347 {
348 mEditor->setValue( value );
349 return true;
350 }
351 else
352 {
353 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
354 }
355 return false;
356}
357
359{
360 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double value ) {
361 this->mSetting->setValue( value, this->mDynamicKeyPartList );
362 } );
363}
364
366{
367 if ( mEditor )
368 {
369 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
370 return true;
371 }
372 else
373 {
374 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
375 }
376 return false;
377}
378
380{
381 if ( mEditor )
382 {
383 return mEditor->value();
384 }
385 else
386 {
387 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
388 }
389 return std::numeric_limits<double>::quiet_NaN();
390}
391
392// *******
393// Color
394// *******
395
397{
398 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
399}
400
401bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
402{
403 if ( mEditor )
404 {
405 mEditor->setColor( value );
406 return true;
407 }
408 else
409 {
410 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
411 }
412 return false;
413}
414
416{
417 if ( mEditor )
418 {
419 mEditor->setAllowOpacity( mSetting->allowAlpha() );
420 }
421 else
422 {
423 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
424 }
425}
426
428{
429 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [this]( const QColor &color ) {
430 this->mSetting->setValue( color, this->mDynamicKeyPartList );
431 } );
432}
433
435{
436 if ( mEditor )
437 {
438 mSetting->setValue( mEditor->color(), mDynamicKeyPartList );
439 return true;
440 }
441 else
442 {
443 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
444 }
445 return false;
446}
447
449{
450 if ( mEditor )
451 {
452 return mEditor->color();
453 }
454 else
455 {
456 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
457 }
458 return QColor();
459}
460
461// *******
462// StringList
463// *******
464
465//QString QgsSettingsStringListEditorWidgetWrapper::id() const
466//{
467// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
468//}
469
470//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
471//{
472// if ( mEditor )
473// {
474// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
475// return true;
476// }
477// else
478// {
479// QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
480// }
481// return false;
482//}
483
484//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
485//{
486// if ( mEditor )
487// {
488// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
489// return true;
490// }
491// else
492// {
493// QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
494// }
495// return false;
496//}
497
498//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
499//{
500// if ( mEditor )
501// {
502// return mEditor->value();
503// }
504// else
505// {
506// QgsDebugError(QString("editor is not set, returning a non-existing value"));
507// }
508// return QStringList();
509//}
@ String
String.
Definition qgis.h:659
@ Integer
Integer.
Definition qgis.h:663
@ Bool
Boolean.
Definition qgis.h:662
@ Color
Color.
Definition qgis.h:666
@ Double
Double precision number.
Definition qgis.h:664
void colorChanged(const QColor &color)
Emitted whenever a new color is set 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.
void configureEditorPrivateImplementation() override
To be re-implemented to implemeent type specific configuration (e.g. opacity for colors).
bool valueFromWidget() const override
Returns the widget value.
QString id() const override
This id of the type of settings it handles.
bool setWidgetValue(const bool &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...
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 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:59