QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
38
44
46{
47 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
48}
49
50bool QgsSettingsStringLineEditWrapper::setWidgetValue( const QString &value ) const
51{
52 if ( mEditor )
53 {
54 mEditor->setText( value );
55 return true;
56 }
57 else
58 {
59 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
60 }
61 return false;
62}
63
65{
66 QObject::connect( this->mEditor, &QLineEdit::textChanged, this, [this]( const QString &text ) { this->mSetting->setValue( text, this->mDynamicKeyPartList ); } );
67}
68
70{
71 if ( mEditor )
72 {
73 mSetting->setValue( mEditor->text(), mDynamicKeyPartList );
74 return true;
75 }
76 else
77 {
78 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
79 }
80 return false;
81}
82
84{
85 if ( mEditor )
86 {
87 return mEditor->text();
88 }
89 else
90 {
91 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
92 }
93 return QString();
94}
95
96// *******
97// String with combo box
98// *******
99
103
109
116
119 , mMode( mode )
120 , mDataRole( role )
121{
123}
124
126{
127 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
128}
129
130bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) const
131{
132 if ( mEditor )
133 {
134 int idx = mMode == Mode::Data ? mEditor->findData( value, mDataRole ) : mEditor->findText( value );
135 if ( idx >= 0 )
136 {
137 mEditor->setCurrentIndex( idx );
138 return true;
139 }
140 else
141 {
142 return false;
143 }
144 }
145 else
146 {
147 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
148 }
149 return false;
150}
151
153{
154 QObject::connect( mEditor, &QComboBox::currentTextChanged, this, [this]( const QString &currentText ) {
155 QString textValue = currentText;
156 if ( mMode == Mode::Data )
157 textValue = mEditor->currentData().toString();
158 mSetting->setValue( textValue, mDynamicKeyPartList );
159 } );
160}
161
163{
164 if ( mEditor )
165 {
167 return true;
168 }
169 else
170 {
171 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
172 }
173 return false;
174}
175
177{
178 if ( mEditor )
179 {
180 return mMode == Mode::Data ? mEditor->currentData( mDataRole ).toString() : mEditor->currentText();
181 }
182 else
183 {
184 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
185 }
186 return QString();
187}
188
189// *******
190// Boolean
191// *******
192
196
202
204{
205 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
206}
207
209{
210 if ( mEditor )
211 {
212 mEditor->setChecked( value );
213 return true;
214 }
215 else
216 {
217 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
218 }
219 return false;
220}
221
223{
224 QObject::connect( this->mEditor, &QCheckBox::clicked, this, [this]( bool checked ) { this->mSetting->setValue( checked, this->mDynamicKeyPartList ); } );
225}
226
228{
229 if ( mEditor )
230 {
231 mSetting->setValue( mEditor->isChecked(), mDynamicKeyPartList );
232 return true;
233 }
234 else
235 {
236 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
237 }
238 return false;
239}
240
242{
243 if ( mEditor )
244 {
245 return mEditor->isChecked();
246 }
247 else
248 {
249 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
250 }
251 return false;
252}
253
254
255// ******************
256// Boolean (GroupBox)
257// ******************
258
262
268
270{
271 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
272}
273
275{
276 if ( mEditor )
277 {
278 mEditor->setChecked( value );
279 return true;
280 }
281 else
282 {
283 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
284 }
285 return false;
286}
287
289{
290 QObject::connect( this->mEditor, &QGroupBox::clicked, this, [this]( bool checked ) { this->mSetting->setValue( checked, this->mDynamicKeyPartList ); } );
291}
292
294{
295 if ( mEditor )
296 {
297 mSetting->setValue( mEditor->isChecked(), mDynamicKeyPartList );
298 return true;
299 }
300 else
301 {
302 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
303 }
304 return false;
305}
306
308{
309 if ( mEditor )
310 {
311 return mEditor->isChecked();
312 }
313 else
314 {
315 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
316 }
317 return false;
318}
319
324
325
326// *******
327// Integer
328// *******
329
333
339
341{
342 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
343}
344
346{
347 if ( mEditor )
348 {
349 mEditor->setValue( value );
350 return true;
351 }
352 else
353 {
354 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
355 }
356 return false;
357}
358
360{
361 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [this]( int value ) { this->mSetting->setValue( value, this->mDynamicKeyPartList ); } );
362}
363
365{
366 if ( mEditor )
367 {
368 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
369 return true;
370 }
371 else
372 {
373 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
374 }
375 return false;
376}
377
379{
380 if ( mEditor )
381 {
382 return mEditor->value();
383 }
384 else
385 {
386 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
387 }
388 return std::numeric_limits<int>::quiet_NaN();
389}
390
391
392// *******
393// Double
394// *******
395
399
405
407{
408 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
409}
410
411bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
412{
413 if ( mEditor )
414 {
415 mEditor->setValue( value );
416 return true;
417 }
418 else
419 {
420 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
421 }
422 return false;
423}
424
426{
427 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double value ) { this->mSetting->setValue( value, this->mDynamicKeyPartList ); } );
428}
429
431{
432 if ( mEditor )
433 {
434 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
435 return true;
436 }
437 else
438 {
439 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
440 }
441 return false;
442}
443
445{
446 if ( mEditor )
447 {
448 return mEditor->value();
449 }
450 else
451 {
452 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
453 }
454 return std::numeric_limits<double>::quiet_NaN();
455}
456
457// *******
458// Color
459// *******
460
464
470
472{
473 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
474}
475
476bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
477{
478 if ( mEditor )
479 {
480 mEditor->setColor( value );
481 return true;
482 }
483 else
484 {
485 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
486 }
487 return false;
488}
489
491{
492 if ( mEditor )
493 {
494 mEditor->setAllowOpacity( mSetting->allowAlpha() );
495 }
496 else
497 {
498 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
499 }
500}
501
503{
504 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [this]( const QColor &color ) { this->mSetting->setValue( color, this->mDynamicKeyPartList ); } );
505}
506
508{
509 if ( mEditor )
510 {
511 mSetting->setValue( mEditor->color(), mDynamicKeyPartList );
512 return true;
513 }
514 else
515 {
516 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
517 }
518 return false;
519}
520
522{
523 if ( mEditor )
524 {
525 return mEditor->color();
526 }
527 else
528 {
529 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
530 }
531 return QColor();
532}
533
534// *******
535// StringList
536// *******
537
538//QString QgsSettingsStringListEditorWidgetWrapper::id() const
539//{
540// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
541//}
542
543//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
544//{
545// if ( mEditor )
546// {
547// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
548// return true;
549// }
550// else
551// {
552// QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
553// }
554// return false;
555//}
556
557//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
558//{
559// if ( mEditor )
560// {
561// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
562// return true;
563// }
564// else
565// {
566// QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
567// }
568// return false;
569//}
570
571//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
572//{
573// if ( mEditor )
574// {
575// return mEditor->value();
576// }
577// else
578// {
579// QgsDebugError(QString("editor is not set, returning a non-existing value"));
580// }
581// return QStringList();
582//}
@ String
String.
Definition qgis.h:664
@ Integer
Integer.
Definition qgis.h:668
@ Bool
Boolean.
Definition qgis.h:667
@ Color
Color.
Definition qgis.h:671
@ Double
Double precision number.
Definition qgis.h:669
A cross platform button subclass for selecting colors.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
QgsSettingsBoolCheckBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
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...
QgsSettingsBoolGroupBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
QgsSettingsColorButtonWrapper(QObject *parent=nullptr)
Constructor of the factory.
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...
QgsSettingsDoubleSpinBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
bool setWidgetValue(const double &value) const override
Sets the widget value.
QString id() const override
This id of the type of settings it handles.
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.
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.
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...
QgsSettingsIntegerSpinBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
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.
QgsSettingsStringComboBoxWrapper(QObject *parent=nullptr)
Constructor of the factory.
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.
Mode
Mode to determine if the value is hold in the combo box text or data.
@ 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.
QgsSettingsStringLineEditWrapper(QObject *parent=nullptr)
Constructor of the factory.
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