QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgssettingsentry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssettingsentry.cpp
3  --------------------------------------
4  Date : February 2021
5  Copyright : (C) 2021 by Damiano Lombardi
6  Email : damiano at opengis dot ch
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 #include "qgssettingsentry.h"
17 
18 #include "qgslogger.h"
19 
20 #include <QRegularExpression>
21 
22 QgsSettingsEntryBase::QgsSettingsEntryBase( const QString &key, QgsSettings::Section section, const QVariant &defaultValue, const QString &description )
23  : mKey( key )
24  , mDefaultValue( defaultValue )
25  , mSection( section )
26  , mDescription( description )
27  , mPluginName()
28 {
29 }
30 
31 QgsSettingsEntryBase::QgsSettingsEntryBase( const QString &key, const QString &pluginName, const QVariant &defaultValue, const QString &description )
32  : mKey( key )
33  , mDefaultValue( defaultValue )
34  , mSection( QgsSettings::Plugins )
35  , mDescription( description )
36  , mPluginName( pluginName )
37 {
38 }
39 
41 {
42 }
43 
44 QString QgsSettingsEntryBase::key( const QString &dynamicKeyPart ) const
45 {
46  QStringList dynamicKeyPartList;
47  if ( !dynamicKeyPart.isNull() )
48  dynamicKeyPartList.append( dynamicKeyPart );
49 
50  return key( dynamicKeyPartList );
51 }
52 
53 QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const
54 {
55  QString completeKey = mKey;
56  if ( !mPluginName.isEmpty() )
57  {
58  if ( !completeKey.startsWith( '/' ) )
59  completeKey.prepend( '/' );
60  completeKey.prepend( mPluginName );
61  }
62 
63  if ( dynamicKeyPartList.isEmpty() )
64  {
65  if ( hasDynamicKey() )
66  QgsDebugMsg( QStringLiteral( "Settings '%1' have a dynamic key but the dynamic key part was not provided" ).arg( completeKey ) );
67 
68  return completeKey;
69  }
70  else
71  {
72  if ( !hasDynamicKey() )
73  {
74  QgsDebugMsg( QStringLiteral( "Settings '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( completeKey ) );
75  return completeKey;
76  }
77 
78  for ( int i = 0; i < dynamicKeyPartList.size(); i++ )
79  {
80  completeKey.replace( QStringLiteral( "%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
81  }
82  }
83  return completeKey;
84 }
85 
86 bool QgsSettingsEntryBase::keyIsValid( const QString &key ) const
87 {
88  if ( !hasDynamicKey() )
89  {
90  if ( !key.contains( definitionKey() ) )
91  return false;
92  }
93 
94  // Key to check
95  QString completeKeyToCheck = key;
96 
97  QString settingsPrefix = QgsSettings().prefixedKey( QString(), section() );
98  settingsPrefix.chop( 1 );
99  if ( !completeKeyToCheck.startsWith( settingsPrefix ) )
100  {
101  if ( !mPluginName.isEmpty()
102  && !completeKeyToCheck.startsWith( mPluginName ) )
103  {
104  if ( !completeKeyToCheck.startsWith( '/' ) )
105  completeKeyToCheck.prepend( '/' );
106  completeKeyToCheck.prepend( mPluginName );
107  }
108 
109  if ( !completeKeyToCheck.startsWith( '/' ) )
110  completeKeyToCheck.prepend( '/' );
111  completeKeyToCheck.prepend( settingsPrefix );
112  }
113 
114  // Prefixed settings key
115  QString prefixedSettingsKey = definitionKey();
116  if ( !prefixedSettingsKey.startsWith( settingsPrefix ) )
117  {
118  if ( !prefixedSettingsKey.startsWith( '/' ) )
119  prefixedSettingsKey.prepend( '/' );
120  prefixedSettingsKey.prepend( settingsPrefix );
121  }
122 
123  if ( !hasDynamicKey() )
124  return completeKeyToCheck == prefixedSettingsKey;
125 
126  const QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) );
127  const QRegularExpressionMatch regularExpressionMatch = regularExpression.match( completeKeyToCheck );
128  return regularExpressionMatch.hasMatch();
129 }
130 
132 {
133  QString completeKey = mKey;
134  if ( !mPluginName.isEmpty() )
135  {
136  if ( !completeKey.startsWith( '/' ) )
137  completeKey.prepend( '/' );
138  completeKey.prepend( mPluginName );
139  }
140 
141  return completeKey;
142 }
143 
145 {
146  const thread_local QRegularExpression regularExpression( QStringLiteral( "%\\d+" ) );
147  return mKey.contains( regularExpression );
148 }
149 
150 bool QgsSettingsEntryBase::exists( const QString &dynamicKeyPart ) const
151 {
152  return QgsSettings().contains( key( dynamicKeyPart ), section() );
153 }
154 
155 bool QgsSettingsEntryBase::exists( const QStringList &dynamicKeyPartList ) const
156 {
157  return QgsSettings().contains( key( dynamicKeyPartList ), section() );
158 }
159 
160 void QgsSettingsEntryBase::remove( const QString &dynamicKeyPart ) const
161 {
162  QgsSettings().remove( key( dynamicKeyPart ), section() );
163 }
164 
165 void QgsSettingsEntryBase::remove( const QStringList &dynamicKeyPartList ) const
166 {
167  QgsSettings().remove( key( dynamicKeyPartList ), section() );
168 }
169 
171 {
172  return mSection;
173 }
174 
175 bool QgsSettingsEntryBase::setVariantValue( const QVariant &value, const QString &dynamicKeyPart ) const
176 {
177  QStringList dynamicKeyPartList;
178  if ( !dynamicKeyPart.isNull() )
179  dynamicKeyPartList.append( dynamicKeyPart );
180 
181  return setVariantValue( value, dynamicKeyPartList );
182 }
183 
184 bool QgsSettingsEntryBase::setVariantValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const
185 {
186  QgsSettings().setValue( key( dynamicKeyPartList ),
187  value,
188  section() );
189  return true;
190 }
191 
192 QVariant QgsSettingsEntryBase::valueAsVariant( const QString &dynamicKeyPart, bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
193 {
194  QStringList dynamicKeyPartList;
195  if ( !dynamicKeyPart.isNull() )
196  dynamicKeyPartList.append( dynamicKeyPart );
197 
198  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride );
199 }
200 
201 QVariant QgsSettingsEntryBase::valueAsVariant( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
202 {
203  if ( useDefaultValueOverride )
204  return QgsSettings().value( key( dynamicKeyPartList ),
205  defaultValueOverride,
206  mSection );
207  else
208  return QgsSettings().value( key( dynamicKeyPartList ),
209  mDefaultValue,
210  mSection );
211 }
212 
214 {
215  return mDefaultValue;
216 }
217 
219 {
220  return mDescription;
221 }
222 
223 
224 QgsSettingsEntryVariant::QgsSettingsEntryVariant( const QString &key, QgsSettings::Section section, const QVariant &defaultValue, const QString &description )
225  : QgsSettingsEntryBase( key,
226  section,
227  defaultValue,
228  description )
229 {
230 }
231 
232 QgsSettingsEntryVariant::QgsSettingsEntryVariant( const QString &key, const QString &pluginName, const QVariant &defaultValue, const QString &description )
233  : QgsSettingsEntryBase( key,
234  pluginName,
235  defaultValue,
236  description )
237 {
238 }
239 
240 bool QgsSettingsEntryVariant::setValue( const QVariant &value, const QString &dynamicKeyPart ) const
241 {
242  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPart );
243 }
244 
245 bool QgsSettingsEntryVariant::setValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const
246 {
247  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
248 }
249 
250 QVariant QgsSettingsEntryVariant::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
251 {
252  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride );
253 }
254 
255 QVariant QgsSettingsEntryVariant::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
256 {
257  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride );
258 }
259 
261 {
262  return defaultValueAsVariant();
263 }
264 
266 {
268 }
269 
270 QgsSettingsEntryString::QgsSettingsEntryString( const QString &key, QgsSettings::Section section, const QString &defaultValue, const QString &description, int minLength, int maxLength )
271  : QgsSettingsEntryBase( key,
272  section,
273  defaultValue,
274  description )
275  , mMinLength( minLength )
276  , mMaxLength( maxLength )
277 {
278 }
279 
280 QgsSettingsEntryString::QgsSettingsEntryString( const QString &key, const QString &pluginName, const QString &defaultValue, const QString &description )
281  : QgsSettingsEntryBase( key,
282  pluginName,
283  defaultValue,
284  description )
285  , mMinLength( 0 )
286  , mMaxLength( -1 )
287 {
288 }
289 
290 bool QgsSettingsEntryString::setValue( const QString &value, const QString &dynamicKeyPart ) const
291 {
292  QStringList dynamicKeyPartList;
293  if ( !dynamicKeyPart.isNull() )
294  dynamicKeyPartList.append( dynamicKeyPart );
295 
296  return setValue( value, dynamicKeyPartList );
297 }
298 
299 bool QgsSettingsEntryString::setValue( const QString &value, const QStringList &dynamicKeyPartList ) const
300 {
301  if ( value.length() < mMinLength )
302  {
303  QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. String length '%2' is shorter than minimum length '%3'." )
304  .arg( QgsSettingsEntryBase::key( dynamicKeyPartList ) )
305  .arg( value.length() )
306  .arg( mMinLength ) );
307  return false;
308  }
309 
310  if ( mMaxLength >= 0
311  && value.length() > mMaxLength )
312  {
313  QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. String length '%2' is longer than maximum length '%3'." )
314  .arg( QgsSettingsEntryBase::key( dynamicKeyPartList ) )
315  .arg( value.length() )
316  .arg( mMinLength ) );
317  return false;
318  }
319 
320  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
321 }
322 
323 QString QgsSettingsEntryString::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, const QString &defaultValueOverride ) const
324 {
325  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride ).toString();
326 }
327 
328 QString QgsSettingsEntryString::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, const QString &defaultValueOverride ) const
329 {
330  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride ).toString();
331 }
332 
334 {
335  return defaultValueAsVariant().toString();
336 }
337 
339 {
341 }
342 
344 {
345  mMinLength = minLength;
346 }
347 
349 {
350  return mMinLength;
351 }
352 
354 {
355  mMaxLength = maxLength;
356 }
357 
359 {
360  return mMaxLength;
361 }
362 
363 QgsSettingsEntryStringList::QgsSettingsEntryStringList( const QString &key, QgsSettings::Section section, const QStringList &defaultValue, const QString &description )
364  : QgsSettingsEntryBase( key,
365  section,
366  defaultValue,
367  description )
368 {
369 }
370 
371 QgsSettingsEntryStringList::QgsSettingsEntryStringList( const QString &key, const QString &pluginName, const QStringList &defaultValue, const QString &description )
372  : QgsSettingsEntryBase( key,
373  pluginName,
374  defaultValue,
375  description )
376 {
377 }
378 
379 bool QgsSettingsEntryStringList::setValue( const QStringList &value, const QString &dynamicKeyPart ) const
380 {
381  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPart );
382 }
383 
384 bool QgsSettingsEntryStringList::setValue( const QStringList &value, const QStringList &dynamicKeyPartList ) const
385 {
386  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
387 }
388 
389 QStringList QgsSettingsEntryStringList::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, const QStringList &defaultValueOverride ) const
390 {
391  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride ).toStringList();
392 }
393 
394 QStringList QgsSettingsEntryStringList::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, const QStringList &defaultValueOverride ) const
395 {
396  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride ).toStringList();
397 }
398 
400 {
401  return defaultValueAsVariant().toStringList();
402 }
403 
405 {
407 }
408 
409 QgsSettingsEntryBool::QgsSettingsEntryBool( const QString &key, QgsSettings::Section section, bool defaultValue, const QString &description )
410  : QgsSettingsEntryBase( key,
411  section,
412  defaultValue,
413  description )
414 {
415 }
416 
417 QgsSettingsEntryBool::QgsSettingsEntryBool( const QString &key, const QString &pluginName, bool defaultValue, const QString &description )
418  : QgsSettingsEntryBase( key,
419  pluginName,
420  defaultValue,
421  description )
422 {
423 }
424 
425 bool QgsSettingsEntryBool::setValue( bool value, const QString &dynamicKeyPart ) const
426 {
427  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPart );
428 }
429 
430 bool QgsSettingsEntryBool::setValue( bool value, const QStringList &dynamicKeyPartList ) const
431 {
432  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
433 }
434 
435 bool QgsSettingsEntryBool::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, bool defaultValueOverride ) const
436 {
437  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride ).toBool();
438 }
439 
440 bool QgsSettingsEntryBool::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, bool defaultValueOverride ) const
441 {
442  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride ).toBool();
443 }
444 
446 {
447  return defaultValueAsVariant().toBool();
448 }
449 
451 {
453 }
454 
455 QgsSettingsEntryInteger::QgsSettingsEntryInteger( const QString &key, QgsSettings::Section section, qlonglong defaultValue, const QString &description, qlonglong minValue, qlonglong maxValue )
456  : QgsSettingsEntryBase( key,
457  section,
458  defaultValue,
459  description )
460  , mMinValue( minValue )
461  , mMaxValue( maxValue )
462 {
463 }
464 
465 QgsSettingsEntryInteger::QgsSettingsEntryInteger( const QString &key, const QString &pluginName, qlonglong defaultValue, const QString &description )
466  : QgsSettingsEntryBase( key,
467  pluginName,
468  defaultValue,
469  description )
470  , mMinValue( std::numeric_limits<qlonglong>::min() )
471  , mMaxValue( std::numeric_limits<qlonglong>::max() )
472 {
473 }
474 
475 bool QgsSettingsEntryInteger::setValue( qlonglong value, const QString &dynamicKeyPart ) const
476 {
477  QStringList dynamicKeyPartList;
478  if ( !dynamicKeyPart.isNull() )
479  dynamicKeyPartList.append( dynamicKeyPart );
480 
481  return setValue( value, dynamicKeyPartList );
482 }
483 
484 bool QgsSettingsEntryInteger::setValue( qlonglong value, const QStringList &dynamicKeyPartList ) const
485 {
486  if ( value < mMinValue )
487  {
488  QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is less than minimum value '%3'." )
489  .arg( QgsSettingsEntryBase::key( dynamicKeyPartList ),
490  QString::number( value ),
491  QString::number( mMinValue ) ) );
492  return false;
493  }
494 
495  if ( value > mMaxValue )
496  {
497  QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is greather than maximum value '%3'." )
498  .arg( QgsSettingsEntryBase::key( dynamicKeyPartList ),
499  QString::number( value ),
500  QString::number( mMinValue ) ) );
501  return false;
502  }
503 
504  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
505 }
506 
507 qlonglong QgsSettingsEntryInteger::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, qlonglong defaultValueOverride ) const
508 {
509  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride ).toLongLong();
510 }
511 
512 qlonglong QgsSettingsEntryInteger::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, qlonglong defaultValueOverride ) const
513 {
514  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride ).toLongLong();
515 }
516 
518 {
519  return defaultValueAsVariant().toLongLong();
520 }
521 
523 {
525 }
526 
527 void QgsSettingsEntryInteger::setMinValue( qlonglong minValue )
528 {
529  mMinValue = minValue;
530 }
531 
533 {
534  return mMinValue;
535 }
536 
537 void QgsSettingsEntryInteger::setMaxValue( qlonglong maxValue )
538 {
539  mMaxValue = maxValue;
540 }
541 
543 {
544  return mMaxValue;
545 }
546 
547 QgsSettingsEntryDouble::QgsSettingsEntryDouble( const QString &key, QgsSettings::Section section, double defaultValue, const QString &description, double minValue, double maxValue, int displayDecimals )
548  : QgsSettingsEntryBase( key,
549  section,
550  defaultValue,
551  description )
552  , mMinValue( minValue )
553  , mMaxValue( maxValue )
554  , mDisplayHintDecimals( displayDecimals )
555 {
556 }
557 
558 QgsSettingsEntryDouble::QgsSettingsEntryDouble( const QString &key, const QString &pluginName, double defaultValue, const QString &description )
559  : QgsSettingsEntryBase( key,
560  pluginName,
561  defaultValue,
562  description )
563  , mMinValue( std::numeric_limits<double>::lowest() )
564  , mMaxValue( std::numeric_limits<double>::max() )
565  , mDisplayHintDecimals( 1 )
566 {
567 }
568 
569 bool QgsSettingsEntryDouble::setValue( double value, const QString &dynamicKeyPart ) const
570 {
571  QStringList dynamicKeyPartList;
572  if ( !dynamicKeyPart.isNull() )
573  dynamicKeyPartList.append( dynamicKeyPart );
574 
575  return setValue( value, dynamicKeyPartList );
576 }
577 
578 bool QgsSettingsEntryDouble::setValue( double value, const QStringList &dynamicKeyPartList ) const
579 {
580  if ( value < mMinValue )
581  {
582  QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is less than minimum value '%3'." )
583  .arg( QgsSettingsEntryBase::key( dynamicKeyPartList ),
584  QString::number( value ),
585  QString::number( mMinValue ) ) );
586  return false;
587  }
588 
589  if ( value > mMaxValue )
590  {
591  QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is greather than maximum value '%3'." )
592  .arg( QgsSettingsEntryBase::key( dynamicKeyPartList ),
593  QString::number( value ),
594  QString::number( mMinValue ) ) );
595  return false;
596  }
597 
598  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
599 }
600 
601 double QgsSettingsEntryDouble::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, double defaultValueOverride ) const
602 {
603  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride ).toDouble();
604 }
605 
606 double QgsSettingsEntryDouble::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, double defaultValueOverride ) const
607 {
608  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride ).toDouble();
609 }
610 
612 {
613  return defaultValueAsVariant().toDouble();
614 }
615 
617 {
619 }
620 
621 void QgsSettingsEntryDouble::setMinValue( double minValue )
622 {
623  mMinValue = minValue;
624 }
625 
627 {
628  return mMinValue;
629 }
630 
631 void QgsSettingsEntryDouble::setMaxValue( double maxValue )
632 {
633  mMaxValue = maxValue;
634 }
635 
637 {
638  return mMaxValue;
639 }
640 
641 void QgsSettingsEntryDouble::setDisplayHintDecimals( int displayHintDecimals )
642 {
643  mDisplayHintDecimals = displayHintDecimals;
644 }
645 
647 {
648  return mDisplayHintDecimals;
649 }
650 
651 QgsSettingsEntryColor::QgsSettingsEntryColor( const QString &key, QgsSettings::Section section, const QColor &defaultValue, const QString &description )
652  : QgsSettingsEntryBase( key,
653  section,
654  defaultValue,
655  description )
656 {
657 }
658 
659 QgsSettingsEntryColor::QgsSettingsEntryColor( const QString &key, const QString &pluginName, const QColor &defaultValue, const QString &description )
660  : QgsSettingsEntryBase( key,
661  pluginName,
662  defaultValue,
663  description )
664 {
665 }
666 
667 bool QgsSettingsEntryColor::setValue( const QColor &value, const QString &dynamicKeyPart ) const
668 {
669  QStringList dynamicKeyPartList;
670  if ( !dynamicKeyPart.isNull() )
671  dynamicKeyPartList.append( dynamicKeyPart );
672 
673  return setValue( value, dynamicKeyPartList );
674 }
675 
676 bool QgsSettingsEntryColor::setValue( const QColor &value, const QStringList &dynamicKeyPartList ) const
677 {
678  return QgsSettingsEntryBase::setVariantValue( value, dynamicKeyPartList );
679 }
680 
681 QColor QgsSettingsEntryColor::value( const QString &dynamicKeyPart, bool useDefaultValueOverride, const QString &defaultValueOverride ) const
682 {
683  return valueAsVariant( dynamicKeyPart, useDefaultValueOverride, defaultValueOverride ).value<QColor>();
684 }
685 
686 QColor QgsSettingsEntryColor::value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, const QString &defaultValueOverride ) const
687 {
688  return valueAsVariant( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride ).value<QColor>();
689 }
690 
692 {
693  return defaultValueAsVariant().value<QColor>();
694 }
695 
697 {
699 }
700 
Represent settings entry and provides methods for reading and writing settings values.
QgsSettings::Section section() const
Returns settings section.
bool exists(const QString &dynamicKeyPart=QString()) const
Returns true if the settings is contained in the underlying QSettings.
QVariant defaultValueAsVariant() const
Returns settings default value.
bool keyIsValid(const QString &key) const
Returns true if the provided key match the settings entry.
QString description() const
Returns the settings entry description.
virtual ~QgsSettingsEntryBase()
Destructor for QgsSettingsEntryBase.
bool hasDynamicKey() const
Returns true if a part of the settings key is built dynamically.
void remove(const QString &dynamicKeyPart=QString()) const
Removes the settings from the underlying QSettings.
QgsSettingsEntryBase(const QString &key, QgsSettings::Section section, const QVariant &defaultValue=QVariant(), const QString &description=QString())
Constructor for QgsSettingsEntryBase.
virtual bool setVariantValue(const QVariant &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
SettingsType
Types of settings entries.
@ Double
Double precision numer.
QVariant valueAsVariant(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, const QVariant &defaultValueOverride=QVariant()) const
Returns settings value.
QString definitionKey() const
Returns settings entry defining key.
QString key(const QString &dynamicKeyPart=QString()) const
Returns settings entry key.
bool value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, bool defaultValueOverride=false) const
Returns settings value.
QgsSettingsEntryBool(const QString &key, QgsSettings::Section section, bool defaultValue=false, const QString &description=QString())
Constructor for QgsSettingsEntryBool.
virtual SettingsType settingsType() const override
Returns the settings entry type.
bool setValue(bool value, const QString &dynamicKeyPart=QString()) const
Set settings value.
bool defaultValue() const
Returns settings default value.
bool setValue(const QColor &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
virtual SettingsType settingsType() const override
Returns the settings entry type.
QColor defaultValue() const
Returns settings default value.
QColor value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, const QString &defaultValueOverride=QString()) const
Returns settings value.
QgsSettingsEntryColor(const QString &key, QgsSettings::Section section, const QColor &defaultValue=QColor(), const QString &description=QString())
Constructor for QgsSettingsEntryColor.
void setDisplayHintDecimals(int displayHintDecimals)
Set the display hint decimals.
bool setValue(double value, const QString &dynamicKeyPart=QString()) const
Set settings value.
double value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, double defaultValueOverride=0.0) const
Returns settings value.
int displayHintDecimals() const
Returns how much decimals should be shown in the Gui.
QgsSettingsEntryDouble(const QString &key, QgsSettings::Section section, double defaultValue=0.0, const QString &description=QString(), double minValue=std::numeric_limits< double >::lowest(), double maxValue=std::numeric_limits< double >::max(), int displayDecimals=1)
Constructor for QgsSettingsEntryDouble.
double minValue() const
Returns the minimum value.
void setMinValue(double minValue)
Set the minimum value.
double maxValue() const
Returns the maximum value.
void setMaxValue(double maxValue)
Set the maximum value.
double defaultValue() const
Returns settings default value.
virtual SettingsType settingsType() const override
Returns the settings entry type.
qlonglong minValue()
Returns the minimum value.
bool setValue(qlonglong value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QgsSettingsEntryInteger(const QString &key, QgsSettings::Section section, qlonglong defaultValue=0, const QString &description=QString(), qlonglong minValue=std::numeric_limits< qlonglong >::min(), qlonglong maxValue=std::numeric_limits< qlonglong >::max())
Constructor for QgsSettingsEntryInteger.
virtual SettingsType settingsType() const override
Returns the settings entry type.
qlonglong maxValue()
Returns the maximum value.
qlonglong defaultValue() const
Returns settings default value.
void setMaxValue(qlonglong maxValue)
Set the maximum value.
qlonglong value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, qlonglong defaultValueOverride=0) const
Returns settings value.
void setMinValue(qlonglong minValue)
Set the minimum value.
bool setValue(const QStringList &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
virtual SettingsType settingsType() const override
Returns the settings entry type.
QgsSettingsEntryStringList(const QString &key, QgsSettings::Section section, const QStringList &defaultValue=QStringList(), const QString &description=QString())
Constructor for QgsSettingsEntryStringList.
QStringList value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, const QStringList &defaultValueOverride=QStringList()) const
Returns settings value.
QStringList defaultValue() const
Returns settings default value.
QString defaultValue() const
Returns settings default value.
QString value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, const QString &defaultValueOverride=QString()) const
Returns settings value.
virtual SettingsType settingsType() const override
Returns the settings entry type.
void setMinLength(int minLength)
Set the string minimum length.
QgsSettingsEntryString(const QString &key, QgsSettings::Section section, const QString &defaultValue=QString(), const QString &description=QString(), int minLength=0, int maxLength=-1)
Constructor for QgsSettingsEntryString.
int maxLength()
Returns the string maximum length.
void setMaxLength(int maxLength)
Set the string maximum length.
int minLength()
Returns the string minimum length.
bool setValue(const QString &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QVariant defaultValue() const
Returns settings default value.
virtual SettingsType settingsType() const override
Returns the settings entry type.
QgsSettingsEntryVariant(const QString &key, QgsSettings::Section section, const QVariant &defaultValue=QVariant(), const QString &description=QString())
Constructor for QgsSettingsEntryVariant.
QVariant value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, const QVariant &defaultValueOverride=QVariant()) const
Returns settings value.
bool setValue(const QVariant &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
QString prefixedKey(const QString &key, QgsSettings::Section section) const
Returns the sanitized and prefixed key.
Section
Sections for namespaced settings.
Definition: qgssettings.h:68
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38