QGIS API Documentation 3.99.0-Master (d270888f95f)
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// Integer
216// *******
217
219{
220 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
221}
222
224{
225 if ( mEditor )
226 {
227 mEditor->setValue( 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, qOverload<int>( &QSpinBox::valueChanged ), this, [this]( int value ) {
240 this->mSetting->setValue( value, this->mDynamicKeyPartList );
241 } );
242}
243
245{
246 if ( mEditor )
247 {
248 mSetting->setValue( mEditor->value(), 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->value();
263 }
264 else
265 {
266 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
267 }
268 return std::numeric_limits<int>::quiet_NaN();
269}
270
271
272// *******
273// Double
274// *******
275
277{
278 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
279}
280
281bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
282{
283 if ( mEditor )
284 {
285 mEditor->setValue( value );
286 return true;
287 }
288 else
289 {
290 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
291 }
292 return false;
293}
294
296{
297 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double value ) {
298 this->mSetting->setValue( value, this->mDynamicKeyPartList );
299 } );
300}
301
303{
304 if ( mEditor )
305 {
306 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
307 return true;
308 }
309 else
310 {
311 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
312 }
313 return false;
314}
315
317{
318 if ( mEditor )
319 {
320 return mEditor->value();
321 }
322 else
323 {
324 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
325 }
326 return std::numeric_limits<double>::quiet_NaN();
327}
328
329// *******
330// Color
331// *******
332
334{
335 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
336}
337
338bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
339{
340 if ( mEditor )
341 {
342 mEditor->setColor( value );
343 return true;
344 }
345 else
346 {
347 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
348 }
349 return false;
350}
351
353{
354 if ( mEditor )
355 {
356 mEditor->setAllowOpacity( mSetting->allowAlpha() );
357 }
358 else
359 {
360 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
361 }
362}
363
365{
366 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [this]( const QColor &color ) {
367 this->mSetting->setValue( color, this->mDynamicKeyPartList );
368 } );
369}
370
372{
373 if ( mEditor )
374 {
375 mSetting->setValue( mEditor->color(), mDynamicKeyPartList );
376 return true;
377 }
378 else
379 {
380 QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
381 }
382 return false;
383}
384
386{
387 if ( mEditor )
388 {
389 return mEditor->color();
390 }
391 else
392 {
393 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
394 }
395 return QColor();
396}
397
398// *******
399// StringList
400// *******
401
402//QString QgsSettingsStringListEditorWidgetWrapper::id() const
403//{
404// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
405//}
406
407//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
408//{
409// if ( mEditor )
410// {
411// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
412// return true;
413// }
414// else
415// {
416// QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
417// }
418// return false;
419//}
420
421//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
422//{
423// if ( mEditor )
424// {
425// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
426// return true;
427// }
428// else
429// {
430// QgsDebugError( u"Settings editor not set for %1"_s.arg( mSetting->definitionKey() ) );
431// }
432// return false;
433//}
434
435//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
436//{
437// if ( mEditor )
438// {
439// return mEditor->value();
440// }
441// else
442// {
443// QgsDebugError(QString("editor is not set, returning a non-existing value"));
444// }
445// return QStringList();
446//}
@ String
String.
Definition qgis.h:657
@ Integer
Integer.
Definition qgis.h:661
@ Bool
Boolean.
Definition qgis.h:660
@ Color
Color.
Definition qgis.h:664
@ Double
Double precision number.
Definition qgis.h:662
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.
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