QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
26#include "moc_qgssettingseditorwidgetwrapperimpl.cpp"
27
28// *******
29// String with line edit (= default)
30// *******
31
33{
34 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
35}
36
37bool QgsSettingsStringLineEditWrapper::setWidgetValue( const QString &value ) const
38{
39 if ( mEditor )
40 {
41 mEditor->setText( value );
42 return true;
43 }
44 else
45 {
46 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
47 }
48 return false;
49}
50
52{
53 QObject::connect( this->mEditor, &QLineEdit::textChanged, this, [this]( const QString &text ) {
54 this->mSetting->setValue( text, this->mDynamicKeyPartList );
55 } );
56}
57
59{
60 if ( mEditor )
61 {
62 mSetting->setValue( mEditor->text(), mDynamicKeyPartList );
63 return true;
64 }
65 else
66 {
67 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
68 }
69 return false;
70}
71
73{
74 if ( mEditor )
75 {
76 return mEditor->text();
77 }
78 else
79 {
80 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
81 }
82 return QString();
83}
84
85// *******
86// String with combo box
87// *******
88
90{
91 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
92}
93
94bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) const
95{
96 if ( mEditor )
97 {
98 int idx = mMode == Mode::Data ? mEditor->findData( value, mDataRole ) : mEditor->findText( value );
99 if ( idx >= 0 )
100 {
101 mEditor->setCurrentIndex( idx );
102 return true;
103 }
104 else
105 {
106 return false;
107 }
108 }
109 else
110 {
111 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
112 }
113 return false;
114}
115
117{
118 QObject::connect( mEditor, &QComboBox::currentTextChanged, this, [this]( const QString &currentText ) {
119 QString textValue = currentText;
120 if ( mMode == Mode::Data )
121 textValue = mEditor->currentData().toString();
122 mSetting->setValue( textValue, mDynamicKeyPartList );
123 } );
124}
125
127{
128 if ( mEditor )
129 {
131 return true;
132 }
133 else
134 {
135 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
136 }
137 return false;
138}
139
141{
142 if ( mEditor )
143 {
144 return mMode == Mode::Data ? mEditor->currentData( mDataRole ).toString() : mEditor->currentText();
145 }
146 else
147 {
148 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
149 }
150 return QString();
151}
152
153// *******
154// Boolean
155// *******
156
158{
159 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
160}
161
163{
164 if ( mEditor )
165 {
166 mEditor->setChecked( value );
167 return true;
168 }
169 else
170 {
171 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
172 }
173 return false;
174}
175
177{
178 QObject::connect( this->mEditor, &QCheckBox::clicked, this, [this]( bool checked ) {
179 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
180 } );
181}
182
184{
185 if ( mEditor )
186 {
187 mSetting->setValue( mEditor->isChecked(), mDynamicKeyPartList );
188 return true;
189 }
190 else
191 {
192 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
193 }
194 return false;
195}
196
198{
199 if ( mEditor )
200 {
201 return mEditor->isChecked();
202 }
203 else
204 {
205 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
206 }
207 return false;
208}
209
210
211// *******
212// Integer
213// *******
214
216{
217 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
218}
219
221{
222 if ( mEditor )
223 {
224 mEditor->setValue( value );
225 return true;
226 }
227 else
228 {
229 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
230 }
231 return false;
232}
233
235{
236 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [this]( int value ) {
237 this->mSetting->setValue( value, this->mDynamicKeyPartList );
238 } );
239}
240
242{
243 if ( mEditor )
244 {
245 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
246 return true;
247 }
248 else
249 {
250 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
251 }
252 return false;
253}
254
256{
257 if ( mEditor )
258 {
259 return mEditor->value();
260 }
261 else
262 {
263 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
264 }
265 return std::numeric_limits<int>::quiet_NaN();
266}
267
268
269// *******
270// Double
271// *******
272
274{
275 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
276}
277
278bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
279{
280 if ( mEditor )
281 {
282 mEditor->setValue( value );
283 return true;
284 }
285 else
286 {
287 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
288 }
289 return false;
290}
291
293{
294 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double value ) {
295 this->mSetting->setValue( value, this->mDynamicKeyPartList );
296 } );
297}
298
300{
301 if ( mEditor )
302 {
303 mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
304 return true;
305 }
306 else
307 {
308 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
309 }
310 return false;
311}
312
314{
315 if ( mEditor )
316 {
317 return mEditor->value();
318 }
319 else
320 {
321 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
322 }
323 return std::numeric_limits<double>::quiet_NaN();
324}
325
326// *******
327// Color
328// *******
329
331{
332 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
333}
334
335bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
336{
337 if ( mEditor )
338 {
339 mEditor->setColor( value );
340 return true;
341 }
342 else
343 {
344 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
345 }
346 return false;
347}
348
350{
351 if ( mEditor )
352 {
353 mEditor->setAllowOpacity( mSetting->allowAlpha() );
354 }
355 else
356 {
357 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
358 }
359}
360
362{
363 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [this]( const QColor &color ) {
364 this->mSetting->setValue( color, this->mDynamicKeyPartList );
365 } );
366}
367
369{
370 if ( mEditor )
371 {
372 mSetting->setValue( mEditor->color(), mDynamicKeyPartList );
373 return true;
374 }
375 else
376 {
377 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
378 }
379 return false;
380}
381
383{
384 if ( mEditor )
385 {
386 return mEditor->color();
387 }
388 else
389 {
390 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
391 }
392 return QColor();
393}
394
395// *******
396// StringList
397// *******
398
399//QString QgsSettingsStringListEditorWidgetWrapper::id() const
400//{
401// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
402//}
403
404//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
405//{
406// if ( mEditor )
407// {
408// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
409// return true;
410// }
411// else
412// {
413// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
414// }
415// return false;
416//}
417
418//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
419//{
420// if ( mEditor )
421// {
422// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
423// return true;
424// }
425// else
426// {
427// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
428// }
429// return false;
430//}
431
432//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
433//{
434// if ( mEditor )
435// {
436// return mEditor->value();
437// }
438// else
439// {
440// QgsDebugError(QString("editor is not set, returning a non-existing value"));
441// }
442// return QStringList();
443//}
@ String
String.
Definition qgis.h:638
@ Integer
Integer.
Definition qgis.h:642
@ Bool
Boolean.
Definition qgis.h:641
@ Color
Color.
Definition qgis.h:645
@ Double
Double precision number.
Definition qgis.h:643
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:57