QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
qgssettingsentryimpl.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssettingsentryimpl.h
3 --------------------------------------
4 Date : February 2022
5 Copyright : (C) 2022 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#ifndef QGSSETTINGSENTRYIMPL_H
17#define QGSSETTINGSENTRYIMPL_H
18
19#include "qgssettingsentry.h"
20
28class CORE_EXPORT QgsSettingsEntryVariant : public QgsSettingsEntryBaseTemplate<QVariant>
29{
30 public:
31
32
43 QgsSettingsEntryVariant( const QString &name,
44 QgsSettingsTreeNode *parent,
45 const QVariant &defaultValue = QVariant(),
46 const QString &description = QString(),
48 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
49 {}
50
61 QgsSettingsEntryVariant( const QString &key,
62 const QString &section,
63 const QVariant &defaultValue = QVariant(),
64 const QString &description = QString(),
66 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
67 {}
68
69#ifdef SIP_RUN
70
81 QgsSettingsEntryVariant( const QString &key,
82 const QString &pluginName,
83 const QVariant &defaultValue = QVariant(),
84 const QString &description = QString(),
86 % MethodCode
87 sipCpp = new sipQgsSettingsEntryVariant( QgsSettingsEntryVariant( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), *a2, *a3, *a4 ) );
88 % End
89#endif
90
91#ifdef SIP_RUN
92
99 SIP_PYOBJECT valueAs( SIP_PYOBJECT type ) const;
100 % MethodCode
101 typedef PyObject *( *pyqt_from_qvariant_by_type )( QVariant &value, PyObject *type );
102 QVariant value;
103
104 value = sipCpp->value();
105
106 pyqt_from_qvariant_by_type f = ( pyqt_from_qvariant_by_type ) sipImportSymbol( SIP_PYQT_FROM_QVARIANT_BY_TYPE );
107 sipRes = f( value, a0 );
108
109 sipIsErr = !sipRes;
110 % End
111#endif
112
113
114 virtual Qgis::SettingsType settingsType() const override;
115
116 QVariant convertFromVariant( const QVariant &value ) const override SIP_FORCE {return value;}
117};
118
126class CORE_EXPORT QgsSettingsEntryString : public QgsSettingsEntryBaseTemplate<QString>
127{
128 public:
129
141 QgsSettingsEntryString( const QString &name,
142 QgsSettingsTreeNode *parent,
143 const QString &defaultValue = QString(),
144 const QString &description = QString(),
146 int minLength = 0,
147 int maxLength = -1 ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER
148 : QgsSettingsEntryBaseTemplate<QString>( name, parent, defaultValue, description, options )
149 , mMinLength( minLength )
150 , mMaxLength( maxLength )
151 {}
152
164 QgsSettingsEntryString( const QString &key,
165 const QString &section,
166 const QString &defaultValue = QString(),
167 const QString &description = QString(),
169 int minLength = 0,
171 : QgsSettingsEntryBaseTemplate<QString>( key, section, defaultValue, description, options )
172 , mMinLength( minLength )
173 , mMaxLength( maxLength )
174 {}
175
176#ifdef SIP_RUN
177
188 QgsSettingsEntryString( const QString &key,
189 const QString &pluginName,
190 const QString &defaultValue = QString(),
191 const QString &description = QString(),
193 int minLength = 0,
194 int maxLength = -1 ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER;
195 % MethodCode
196 sipCpp = new sipQgsSettingsEntryString( QgsSettingsEntryString( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), *a2, *a3, *a4 ) );
197 % End
198#endif
199
200 virtual Qgis::SettingsType settingsType() const override;
201
205 int minLength() const;
206
210 int maxLength() const;
211
212 QString convertFromVariant( const QVariant &value ) const override SIP_FORCE;
213
214 private:
215 bool checkValuePrivate( const QString &value ) const override SIP_FORCE;
216
217 int mMinLength;
218 int mMaxLength;
219
220};
221
222
230class CORE_EXPORT QgsSettingsEntryStringList : public QgsSettingsEntryBaseTemplate<QStringList>
231{
232 public:
233
243 QgsSettingsEntryStringList( const QString &name,
244 QgsSettingsTreeNode *parent,
245 const QStringList &defaultValue = QStringList(),
246 const QString &description = QString(),
248 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
249 {}
250
260 QgsSettingsEntryStringList( const QString &key,
261 const QString &section,
262 const QStringList &defaultValue = QStringList(),
263 const QString &description = QString(),
265 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
266 {}
267
268
269#ifdef SIP_RUN
270
281 QgsSettingsEntryStringList( const QString &key,
282 const QString &pluginName,
283 const QStringList &defaultValue = QStringList(),
284 const QString &description = QString(),
286 % MethodCode
287 sipCpp = new sipQgsSettingsEntryStringList( QgsSettingsEntryStringList( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), *a2, *a3, *a4 ) );
288 % End
289#endif
290
291 virtual Qgis::SettingsType settingsType() const override;
292
293 QStringList convertFromVariant( const QVariant &value ) const override SIP_FORCE;
294};
295
296
305{
306 public:
307
317 QgsSettingsEntryBool( const QString &name,
318 QgsSettingsTreeNode *parent,
319 bool defaultValue = false,
320 const QString &description = QString(),
322 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
323 {}
324
334 QgsSettingsEntryBool( const QString &key,
335 const QString &section,
336 bool defaultValue = false,
337 const QString &description = QString(),
339 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
340 {}
341
342#ifdef SIP_RUN
343
354 QgsSettingsEntryBool( const QString &key,
355 const QString &pluginName,
356 bool defaultValue = false,
357 const QString &description = QString(),
359 % MethodCode
360 sipCpp = new sipQgsSettingsEntryBool( QgsSettingsEntryBool( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), a2, *a3, *a4 ) );
361 % End
362#endif
363
364
365 virtual Qgis::SettingsType settingsType() const override;
366
367 bool convertFromVariant( const QVariant &value ) const override SIP_FORCE;
368};
369
370
379{
380 public:
381
393 QgsSettingsEntryInteger( const QString &name,
394 QgsSettingsTreeNode *parent,
395 int defaultValue = 0,
396 const QString &description = QString(),
398 int minValue = std::numeric_limits<int>::min(),
399 int maxValue = std::numeric_limits<int>::max() ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER
400 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
401 , mMinValue( minValue )
402 , mMaxValue( maxValue )
403 { }
404
416 QgsSettingsEntryInteger( const QString &key,
417 const QString &section,
418 int defaultValue = 0,
419 const QString &description = QString(),
421 int minValue = std::numeric_limits<int>::min(),
422 int maxValue = std::numeric_limits<int>::max() ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER SIP_MAKE_PRIVATE
423 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
424 , mMinValue( minValue )
425 , mMaxValue( maxValue )
426 { }
427
428#ifdef SIP_RUN
429
442 QgsSettingsEntryInteger( const QString &key,
443 const QString &pluginName,
444 int defaultValue = 0,
445 const QString &description = QString(),
447 int minValue = std::numeric_limits<int>::min(),
448 int maxValue = std::numeric_limits<int>::max() ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER;
449 % MethodCode
450 sipCpp = new sipQgsSettingsEntryInteger( QgsSettingsEntryInteger( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), a2, *a3, *a4, a5, a6 ) );
451 % End
452#endif
453
454 virtual Qgis::SettingsType settingsType() const override;
455
459 int minValue() const;
460
464 int maxValue() const;
465
466 int convertFromVariant( const QVariant &value ) const override SIP_FORCE;
467
468 private:
469 bool checkValuePrivate( const int &value ) const override SIP_FORCE;
470 int mMinValue;
471 int mMaxValue;
472};
473
474#ifndef SIP_RUN
475// not available in Python for now (no direct support of 64 bits integers in Python)
476
484class CORE_EXPORT QgsSettingsEntryInteger64 : public QgsSettingsEntryBaseTemplate<qlonglong>
485{
486 public:
487
499 QgsSettingsEntryInteger64( const QString &name,
500 QgsSettingsTreeNode *parent,
501 qlonglong defaultValue = 0,
502 const QString &description = QString(),
504 qlonglong minValue = std::numeric_limits<qlonglong>::min(),
505 qlonglong maxValue = std::numeric_limits<qlonglong>::max() ) SIP_THROW( QgsSettingsException )
506 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
507 , mMinValue( minValue )
508 , mMaxValue( maxValue )
509 { }
510
522 QgsSettingsEntryInteger64( const QString &key,
523 const QString &section,
524 qlonglong defaultValue = 0,
525 const QString &description = QString(),
527 qlonglong minValue = std::numeric_limits<qlonglong>::min(),
528 qlonglong maxValue = std::numeric_limits<qlonglong>::max() )
529 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
530 , mMinValue( minValue )
531 , mMaxValue( maxValue )
532 { }
533
534 virtual Qgis::SettingsType settingsType() const override;
535
539 qlonglong minValue() const;
540
544 qlonglong maxValue() const;
545
546 qlonglong convertFromVariant( const QVariant &value ) const override;
547
548 private:
549 bool checkValuePrivate( const qlonglong &value ) const override;
550 qlonglong mMinValue;
551 qlonglong mMaxValue;
552};
553#endif
554
562class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryBaseTemplate<double>
563{
564 public:
565
579 QgsSettingsEntryDouble( const QString &name,
580 QgsSettingsTreeNode *parent,
581 double defaultValue = 0.0,
582 const QString &description = QString(),
584 double minValue = std::numeric_limits<double>::lowest(),
585 double maxValue = std::numeric_limits<double>::max(),
586 int displayDecimals = 1 ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER
587 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
588 , mMinValue( minValue )
589 , mMaxValue( maxValue )
590 , mDisplayHintDecimals( displayDecimals )
591 {}
592
606 QgsSettingsEntryDouble( const QString &key,
607 const QString &section,
608 double defaultValue = 0.0,
609 const QString &description = QString(),
611 double minValue = std::numeric_limits<double>::lowest(),
612 double maxValue = std::numeric_limits<double>::max(),
614 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
615 , mMinValue( minValue )
616 , mMaxValue( maxValue )
617 , mDisplayHintDecimals( displayDecimals )
618 {}
619
620#ifdef SIP_RUN
621
635 QgsSettingsEntryDouble( const QString &key,
636 const QString &pluginName,
637 double defaultValue,
638 const QString &description = QString(),
640 double minValue = std::numeric_limits<double>::lowest(),
641 double maxValue = std::numeric_limits<double>::max(),
642 int displayDecimals = 1 ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER;
643 % MethodCode
644 sipCpp = new sipQgsSettingsEntryDouble( QgsSettingsEntryDouble( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), a2, *a3, *a4, a5, a6, a7 ) );
645 % End
646#endif
647
648
649 virtual Qgis::SettingsType settingsType() const override;
650
654 double minValue() const;
655
659 double maxValue() const;
660
666 void setDisplayHintDecimals( int displayHintDecimals );
667
671 int displayHintDecimals() const;
672
673 double convertFromVariant( const QVariant &value ) const override SIP_FORCE;
674
675 private:
676 bool checkValuePrivate( const double &value ) const override SIP_FORCE;
677 double mMinValue;
678 double mMaxValue;
679
680 int mDisplayHintDecimals;
681
682};
683
684
685
693class CORE_EXPORT QgsSettingsEntryColor : public QgsSettingsEntryBaseTemplate<QColor>
694{
695 public:
696
707 QgsSettingsEntryColor( const QString &name,
708 QgsSettingsTreeNode *parent,
709 const QColor &defaultValue = QColor(),
710 const QString &description = QString(),
712 bool allowAlpha = true ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER
713 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
714 , mAllowAlpha( allowAlpha )
715 {}
716
727 QgsSettingsEntryColor( const QString &key,
728 const QString &section,
729 const QColor &defaultValue = QColor(),
730 const QString &description = QString(),
733 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
734 , mAllowAlpha( allowAlpha )
735 {}
736
737#ifdef SIP_RUN
738
749 QgsSettingsEntryColor( const QString &key,
750 const QString &pluginName,
751 const QColor &defaultValue = QColor(),
752 const QString &description = QString(),
754 bool allowAlpha = true ) SIP_THROW( QgsSettingsException ) SIP_TRANSFER;
755 % MethodCode
756 sipCpp = new sipQgsSettingsEntryColor( QgsSettingsEntryColor( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), *a2, *a3, *a4, a5 ) );
757 % End
758#endif
759
760 virtual Qgis::SettingsType settingsType() const override;
761
766 bool allowAlpha() const {return mAllowAlpha;}
767
773 bool copyValueFromKeys( const QString &redKey, const QString &greenKey, const QString &blueKey, const QString &alphaKey = QString(), bool removeSettingAtKey = false ) const SIP_SKIP;
774
779 void copyValueToKeys( const QString &redKey, const QString &greenKey, const QString &blueKey, const QString &alphaKey = QString() ) const SIP_SKIP;
780
781 QColor convertFromVariant( const QVariant &value ) const override SIP_FORCE;
782
783 private:
784
785 bool checkValuePrivate( const QColor &value ) const override SIP_FORCE;
786 bool mAllowAlpha = true;
787};
788
796class CORE_EXPORT QgsSettingsEntryVariantMap : public QgsSettingsEntryBaseTemplate<QVariantMap>
797{
798 public:
799
800
810 QgsSettingsEntryVariantMap( const QString &name,
811 QgsSettingsTreeNode *parent,
812 const QVariantMap &defaultValue = QVariantMap(),
813 const QString &description = QString(),
815 : QgsSettingsEntryBaseTemplate( name, parent, defaultValue, description, options )
816 {
817 }
818
828 QgsSettingsEntryVariantMap( const QString &key,
829 const QString &section,
830 const QVariantMap &defaultValue = QVariantMap(),
831 const QString &description = QString(),
833 : QgsSettingsEntryBaseTemplate( key, section, defaultValue, description, options )
834 {
835 }
836
837#ifdef SIP_RUN
838
849 QgsSettingsEntryVariantMap( const QString &key,
850 const QString &pluginName,
851 const QVariantMap &defaultValue = QVariantMap(),
852 const QString &description = QString(),
854 % MethodCode
855 sipCpp = new sipQgsSettingsEntryVariantMap( QgsSettingsEntryVariantMap( *a0, QgsSettingsTree::createPluginTreeNode( *a1 ), *a2, *a3, *a4 ) );
856 % End
857#endif
858
859 virtual Qgis::SettingsType settingsType() const override;
860
861 QVariantMap convertFromVariant( const QVariant &value ) const override SIP_FORCE;
862};
863
864
865#endif // QGSSETTINGSENTRYIMPL_H
SettingsType
Types of settings entries.
Definition qgis.h:599
QFlags< SettingsOption > SettingsOptions
Definition qgis.h:693
Base abstract class for settings entries with typed get and set methods.
virtual T convertFromVariant(const QVariant &value) const =0
Converts the variant value to the value type of the setting.
virtual Qgis::SettingsType settingsType() const override=0
Returns the settings entry type.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
virtual bool checkValuePrivate(const T &value) const
Check if the value is valid.
A boolean settings entry.
QgsSettingsEntryBool(const QString &name, QgsSettingsTreeNode *parent, bool defaultValue=false, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryBool.
QgsSettingsEntryBool(const QString &key, const QString &section, bool defaultValue=false, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryBool.
A color settings entry.
QgsSettingsEntryColor(const QString &key, const QString &section, const QColor &defaultValue=QColor(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), bool allowAlpha=true)
Constructor for QgsSettingsEntryColor.
bool allowAlpha() const
Returns true if transparency is allowed for the color.
QgsSettingsEntryColor(const QString &name, QgsSettingsTreeNode *parent, const QColor &defaultValue=QColor(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), bool allowAlpha=true)
Constructor for QgsSettingsEntryColor.
A double settings entry.
QgsSettingsEntryDouble(const QString &name, QgsSettingsTreeNode *parent, double defaultValue=0.0, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), double minValue=std::numeric_limits< double >::lowest(), double maxValue=std::numeric_limits< double >::max(), int displayDecimals=1)
Constructor for QgsSettingsEntryDouble.
QgsSettingsEntryDouble(const QString &key, const QString &section, double defaultValue=0.0, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), double minValue=std::numeric_limits< double >::lowest(), double maxValue=std::numeric_limits< double >::max(), int displayDecimals=1)
Constructor for QgsSettingsEntryDouble.
A 64 bits integer (long long) settings entry.
QgsSettingsEntryInteger64(const QString &name, QgsSettingsTreeNode *parent, qlonglong defaultValue=0, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), qlonglong minValue=std::numeric_limits< qlonglong >::min(), qlonglong maxValue=std::numeric_limits< qlonglong >::max())
Constructor for QgsSettingsEntryInteger64.
QgsSettingsEntryInteger64(const QString &key, const QString &section, qlonglong defaultValue=0, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), qlonglong minValue=std::numeric_limits< qlonglong >::min(), qlonglong maxValue=std::numeric_limits< qlonglong >::max())
Constructor for QgsSettingsEntryInteger64.
An integer settings entry.
QgsSettingsEntryInteger(const QString &name, QgsSettingsTreeNode *parent, int defaultValue=0, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), int minValue=std::numeric_limits< int >::min(), int maxValue=std::numeric_limits< int >::max())
Constructor for QgsSettingsEntryInteger.
QgsSettingsEntryInteger(const QString &key, const QString &section, int defaultValue=0, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), int minValue=std::numeric_limits< int >::min(), int maxValue=std::numeric_limits< int >::max())
Constructor for QgsSettingsEntryInteger.
A string list settings entry.
QgsSettingsEntryStringList(const QString &name, QgsSettingsTreeNode *parent, const QStringList &defaultValue=QStringList(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryStringList.
QgsSettingsEntryStringList(const QString &key, const QString &section, const QStringList &defaultValue=QStringList(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryStringList.
A string settings entry.
QgsSettingsEntryString(const QString &name, QgsSettingsTreeNode *parent, const QString &defaultValue=QString(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), int minLength=0, int maxLength=-1)
Constructor for QgsSettingsEntryString.
QgsSettingsEntryString(const QString &key, const QString &section, const QString &defaultValue=QString(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions(), int minLength=0, int maxLength=-1)
Constructor for QgsSettingsEntryString.
A string list settings entry.
QgsSettingsEntryVariantMap(const QString &key, const QString &section, const QVariantMap &defaultValue=QVariantMap(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryVariantMap.
QgsSettingsEntryVariantMap(const QString &name, QgsSettingsTreeNode *parent, const QVariantMap &defaultValue=QVariantMap(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryVariantMap.
A variant settings entry.
QgsSettingsEntryVariant(const QString &name, QgsSettingsTreeNode *parent, const QVariant &defaultValue=QVariant(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryVariant.
QVariant convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
QgsSettingsEntryVariant(const QString &key, const QString &section, const QVariant &defaultValue=QVariant(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryVariant.
Custom exception class for settings related exceptions.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTree holds the tree structure for the settings in QGIS core.
#define SIP_FORCE
Definition qgis_sip.h:131
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MAKE_PRIVATE
Definition qgis_sip.h:136
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_THROW(name,...)
Definition qgis_sip.h:203