QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgslogger.h"
20#include "qgscolorbutton.h"
21
22#include <QLineEdit>
23#include <QCheckBox>
24
25
26// *******
27// String with line edit (= default)
28// *******
29
31{
32 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
33}
34
35bool QgsSettingsStringLineEditWrapper::setWidgetValue( const QString &value ) const
36{
37 if ( mEditor )
38 {
39 mEditor->setText( value );
40 return true;
41 }
42 else
43 {
44 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
45 }
46 return false;
47}
48
50{
51 QObject::connect( this->mEditor, &QLineEdit::textChanged, this, [ = ]( const QString & text )
52 {
53 this->mSetting->setValue( text, this->mDynamicKeyPartList );
54 } );
55}
56
58{
59 if ( mEditor )
60 {
62 return true;
63 }
64 else
65 {
66 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
67 }
68 return false;
69}
70
72{
73 if ( mEditor )
74 {
75 return mEditor->text();
76 }
77 else
78 {
79 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
80 }
81 return QString();
82}
83
84// *******
85// String with combo box
86// *******
87
89{
90 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
91}
92
93bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) const
94{
95 if ( mEditor )
96 {
97 int idx = mMode == Mode::Data ? mEditor->findData( value ) : mEditor->findText( value );
98 if ( idx >= 0 )
99 {
100 mEditor->setCurrentIndex( idx );
101 return true;
102 }
103 else
104 {
105 return false;
106 }
107 }
108 else
109 {
110 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
111 }
112 return false;
113}
114
116{
117 QObject::connect( mEditor, &QComboBox::currentTextChanged, this, [ = ]( const QString & currentText )
118 {
119 QString textValue = currentText;
120 if ( mMode == Mode::Data )
121 textValue = mEditor->currentData().toString();
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().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, [ = ]( bool checked )
179 {
180 this->mSetting->setValue( checked, this->mDynamicKeyPartList );
181 } );
182}
183
185{
186 if ( mEditor )
187 {
189 return true;
190 }
191 else
192 {
193 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
194 }
195 return false;
196}
197
199{
200
201 if ( mEditor )
202 {
203 return mEditor->isChecked();
204 }
205 else
206 {
207 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
208 }
209 return false;
210}
211
212
213// *******
214// Integer
215// *******
216
218{
219 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Integer ) ) );
220}
221
223{
224 if ( mEditor )
225 {
226 mEditor->setValue( value );
227 return true;
228 }
229 else
230 {
231 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
232 }
233 return false;
234}
235
237{
238 QObject::connect( this->mEditor, qOverload<int>( &QSpinBox::valueChanged ), this, [ = ]( int value )
239 {
240 this->mSetting->setValue( value, this->mDynamicKeyPartList );
241 } );
242}
243
245{
246 if ( mEditor )
247 {
249 return true;
250 }
251 else
252 {
253 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).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// *******
274// Double
275// *******
276
278{
279 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Double ) ) );
280}
281
282bool QgsSettingsDoubleSpinBoxWrapper::setWidgetValue( const double &value ) const
283{
284 if ( mEditor )
285 {
286 mEditor->setValue( value );
287 return true;
288 }
289 else
290 {
291 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
292 }
293 return false;
294}
295
297{
298 QObject::connect( this->mEditor, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [ = ]( double value )
299 {
300 this->mSetting->setValue( value, this->mDynamicKeyPartList );
301 } );
302}
303
305{
306 if ( mEditor )
307 {
309 return true;
310 }
311 else
312 {
313 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
314 }
315 return false;
316}
317
319{
320 if ( mEditor )
321 {
322 return mEditor->value();
323 }
324 else
325 {
326 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
327 }
328 return std::numeric_limits<double>::quiet_NaN();
329}
330
331// *******
332// Color
333// *******
334
336{
337 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::Color ) ) );
338}
339
340bool QgsSettingsColorButtonWrapper::setWidgetValue( const QColor &value ) const
341{
342 if ( mEditor )
343 {
344 mEditor->setColor( value );
345 return true;
346 }
347 else
348 {
349 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
350 }
351 return false;
352}
353
355{
356 if ( mEditor )
357 {
359 }
360 else
361 {
362 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
363 }
364}
365
367{
368 QObject::connect( this->mEditor, &QgsColorButton::colorChanged, this, [ = ]( const QColor & color )
369 {
370 this->mSetting->setValue( color, this->mDynamicKeyPartList );
371 } );
372}
373
375{
376 if ( mEditor )
377 {
379 return true;
380 }
381 else
382 {
383 QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
384 }
385 return false;
386}
387
389{
390 if ( mEditor )
391 {
392 return mEditor->color();
393 }
394 else
395 {
396 QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
397 }
398 return QColor();
399}
400
401// *******
402// StringList
403// *******
404
405//QString QgsSettingsStringListEditorWidgetWrapper::id() const
406//{
407// return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::StringList ) ) );
408//}
409
410//bool QgsSettingsStringListEditorWidgetWrapper::setWidgetFromSetting() const
411//{
412// if ( mEditor )
413// {
414// mEditor->setValue( mSetting->value( mDynamicKeyPartList ) );
415// return true;
416// }
417// else
418// {
419// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
420// }
421// return false;
422//}
423
424//bool QgsSettingsStringListEditorWidgetWrapper::setSettingFromWidget() const
425//{
426// if ( mEditor )
427// {
428// mSetting->setValue( mEditor->value(), mDynamicKeyPartList );
429// return true;
430// }
431// else
432// {
433// QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
434// }
435// return false;
436//}
437
438//QVariant QgsSettingsStringListEditorWidgetWrapper::valueFromWidget() const
439//{
440// if ( mEditor )
441// {
442// return mEditor->value();
443// }
444// else
445// {
446// QgsDebugError(QString("editor is not set, returning a non-existing value"));
447// }
448// return QStringList();
449//}
@ 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