QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgssettingsentryimpl.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssettingsentryimpl.cpp
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
18
19
21{
23}
24
25
26bool QgsSettingsEntryString::checkValue( const QString &value ) const
27{
28 if ( value.length() < mMinLength )
29 {
30 QgsDebugMsg( QObject::tr( "Can't set value for settings. String length '%1' is shorter than minimum length '%2'." )
31 .arg( value.length() )
32 .arg( mMinLength ) );
33 return false;
34 }
35
36 if ( mMaxLength >= 0
37 && value.length() > mMaxLength )
38 {
39 QgsDebugMsg( QObject::tr( "Can't set value for settings. String length '%1' is longer than maximum length '%2'." )
40 .arg( value.length() )
41 .arg( mMinLength ) );
42 return false;
43 }
44
45 return true;
46}
47
48QString QgsSettingsEntryString::convertFromVariant( const QVariant &value ) const
49{
50 return value.toString();
51}
52
54{
56}
57
59{
60 mMinLength = minLength;
61}
62
64{
65 return mMinLength;
66}
67
69{
70 mMaxLength = maxLength;
71}
72
74{
75 return mMaxLength;
76}
77
78
79
80QStringList QgsSettingsEntryStringList::convertFromVariant( const QVariant &value ) const
81{
82 return value.toStringList();
83}
84
86{
88}
89
90
91bool QgsSettingsEntryBool::convertFromVariant( const QVariant &value ) const
92{
93 return value.toBool();
94}
95
96
98{
100}
101
102
103bool QgsSettingsEntryInteger::checkValue( qlonglong value ) const
104{
105 if ( value < mMinValue )
106 {
107 QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is less than minimum value '%2'." )
108 .arg( QString::number( value ) )
109 .arg( QString::number( mMinValue ) ) );
110 return false;
111 }
112
113 if ( value > mMaxValue )
114 {
115 QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
116 .arg( QString::number( value ) )
117 .arg( QString::number( mMaxValue ) ) );
118 return false;
119 }
120
121 return true;
122}
123
124qlonglong QgsSettingsEntryInteger::convertFromVariant( const QVariant &value ) const
125{
126 return value.toLongLong();
127}
128
130{
132}
133
134void QgsSettingsEntryInteger::setMinValue( qlonglong minValue )
135{
136 mMinValue = minValue;
137}
138
140{
141 return mMinValue;
142}
143
144void QgsSettingsEntryInteger::setMaxValue( qlonglong maxValue )
145{
146 mMaxValue = maxValue;
147}
148
150{
151 return mMaxValue;
152}
153
154
155
156
157bool QgsSettingsEntryDouble::checkValue( double value ) const
158{
159 if ( value < mMinValue )
160 {
161 QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is less than minimum value '%2'." )
162 .arg( QString::number( value ) )
163 .arg( QString::number( mMinValue ) ) );
164 return false;
165 }
166
167 if ( value > mMaxValue )
168 {
169 QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
170 .arg( QString::number( value ) )
171 .arg( QString::number( mMaxValue ) ) );
172 return false;
173 }
174
175 return true;
176}
177
178double QgsSettingsEntryDouble::convertFromVariant( const QVariant &value ) const
179{
180 return value.toDouble();
181}
182
184{
186}
187
189{
190 mMinValue = minValue;
191}
192
194{
195 return mMinValue;
196}
197
199{
200 mMaxValue = maxValue;
201}
202
204{
205 return mMaxValue;
206}
207
209{
210 mDisplayHintDecimals = displayHintDecimals;
211}
212
214{
215 return mDisplayHintDecimals;
216}
217
218
219QColor QgsSettingsEntryColor::convertFromVariant( const QVariant &value ) const
220{
221 return value.value<QColor>();
222}
223
225{
227}
228
SettingsType
Types of settings entries.
Definition: qgis.h:231
@ Variant
Generic variant.
@ StringList
List of strings.
@ Double
Double precision number.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
QString value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
void setDisplayHintDecimals(int displayHintDecimals)
Set the display hint decimals.
int displayHintDecimals() const
Returns how much decimals should be shown in the Gui.
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.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
qlonglong maxValue() const
Returns the maximum value.
qlonglong minValue() const
Returns the minimum value.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
void setMaxValue(qlonglong maxValue)
Set the maximum value.
void setMinValue(qlonglong minValue)
Set the minimum value.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
int maxLength() const
Returns the string maximum length.
int minLength() const
Returns the string minimum length.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
void setMinLength(int minLength)
Set the string minimum length.
void setMaxLength(int maxLength)
Set the string maximum length.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38