QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 {
54 this->mSetting->setValue( text, this->mDynamicKeyPartList );
55 } );
56}
57
59{
60 if ( mEditor )
61 {
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 ) : 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, [ = ]( const QString & currentText )
119 {
120 QString textValue = currentText;
121 if ( mMode == Mode::Data )
122 textValue = mEditor->currentData().toString();
124 } );
125}
126
128{
129 if ( mEditor )
130 {
132 return true;
133 }
134 else
135 {
136 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
137 }
138 return false;
139}
140
142{
143 if ( mEditor )
144 {
145 return mMode == Mode::Data ? mEditor->currentData().toString() : mEditor->currentText();
146 }
147 else
148 {
149 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
150 }
151 return QString();
152}
153
154// *******
155// Boolean
156// *******
157
159{
160 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Bool ) ) );
161}
162
164{
165 if ( mEditor )
166 {
167 mEditor->setChecked( value );
168 return true;
169 }
170 else
171 {
172 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
173 }
174 return false;
175}
176
178{
179 QObject::connect( this->mEditor, &QCheckBox::clicked, this, [ = ]( bool checked )
180 {
181 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
182 } );
183}
184
186{
187 if ( mEditor )
188 {
190 return true;
191 }
192 else
193 {
194 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
195 }
196 return false;
197}
198
200{
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( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
233 }
234 return false;
235}
236
238{
239 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [ = ]( int value )
240 {
241 this->mSetting->setValue( value, this->mDynamicKeyPartList );
242 } );
243}
244
246{
247 if ( mEditor )
248 {
250 return true;
251 }
252 else
253 {
254 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
255 }
256 return false;
257}
258
260{
261 if ( mEditor )
262 {
263 return mEditor->value();
264 }
265 else
266 {
267 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
268 }
269 return std::numeric_limits<int>::quiet_NaN();
270}
271
272
273
274// *******
275// Double
276// *******
277
279{
280 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
281}
282
283bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
284{
285 if ( mEditor )
286 {
287 mEditor->setValue( value );
288 return true;
289 }
290 else
291 {
292 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
293 }
294 return false;
295}
296
298{
299 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [ = ]( double value )
300 {
301 this->mSetting->setValue( value, this->mDynamicKeyPartList );
302 } );
303}
304
306{
307 if ( mEditor )
308 {
310 return true;
311 }
312 else
313 {
314 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
315 }
316 return false;
317}
318
320{
321 if ( mEditor )
322 {
323 return mEditor->value();
324 }
325 else
326 {
327 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
328 }
329 return std::numeric_limits<double>::quiet_NaN();
330}
331
332// *******
333// Color
334// *******
335
337{
338 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
339}
340
341bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
342{
343 if ( mEditor )
344 {
345 mEditor->setColor( value );
346 return true;
347 }
348 else
349 {
350 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
351 }
352 return false;
353}
354
356{
357 if ( mEditor )
358 {
360 }
361 else
362 {
363 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
364 }
365}
366
368{
369 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [ = ]( const QColor & color )
370 {
371 this->mSetting->setValue( color, this->mDynamicKeyPartList );
372 } );
373}
374
376{
377 if ( mEditor )
378 {
380 return true;
381 }
382 else
383 {
384 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
385 }
386 return false;
387}
388
390{
391 if ( mEditor )
392 {
393 return mEditor->color();
394 }
395 else
396 {
397 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
398 }
399 return QColor();
400}
401
402// *******
403// StringList
404// *******
405
406//QString QgsSettingsStringListEditorWidgetWrapper::id() const
407//{
408// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
409//}
410
411//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
412//{
413// if ( mEditor )
414// {
415// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
416// return true;
417// }
418// else
419// {
420// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
421// }
422// return false;
423//}
424
425//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
426//{
427// if ( mEditor )
428// {
429// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
430// return true;
431// }
432// else
433// {
434// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
435// }
436// return false;
437//}
438
439//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
440//{
441// if ( mEditor )
442// {
443// return mEditor->value();
444// }
445// else
446// {
447// QgsDebugError(QString("editor is not set, returning a non-existing value"));
448// }
449// return QStringList();
450//}
@ 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