QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
6  Email : [email protected]
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 
17 #include "qgssettingsentryimpl.h"
18 
19 
21 {
23 }
24 
25 
26 bool 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 
48 QString 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 
80 QStringList QgsSettingsEntryStringList::convertFromVariant( const QVariant &value ) const
81 {
82  return value.toStringList();
83 }
84 
86 {
88 }
89 
90 
91 bool QgsSettingsEntryBool::convertFromVariant( const QVariant &value ) const
92 {
93  return value.toBool();
94 }
95 
96 
98 {
100 }
101 
102 
103 bool 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 
124 qlonglong QgsSettingsEntryInteger::convertFromVariant( const QVariant &value ) const
125 {
126  return value.toLongLong();
127 }
128 
130 {
132 }
133 
134 void QgsSettingsEntryInteger::setMinValue( qlonglong minValue )
135 {
136  mMinValue = minValue;
137 }
138 
140 {
141  return mMinValue;
142 }
143 
144 void QgsSettingsEntryInteger::setMaxValue( qlonglong maxValue )
145 {
146  mMaxValue = maxValue;
147 }
148 
150 {
151  return mMaxValue;
152 }
153 
154 
155 
156 
157 bool 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 
178 double QgsSettingsEntryDouble::convertFromVariant( const QVariant &value ) const
179 {
180  return value.toDouble();
181 }
182 
184 {
186 }
187 
188 void QgsSettingsEntryDouble::setMinValue( double minValue )
189 {
190  mMinValue = minValue;
191 }
192 
194 {
195  return mMinValue;
196 }
197 
198 void QgsSettingsEntryDouble::setMaxValue( double maxValue )
199 {
200  mMaxValue = maxValue;
201 }
202 
204 {
205  return mMaxValue;
206 }
207 
208 void QgsSettingsEntryDouble::setDisplayHintDecimals( int displayHintDecimals )
209 {
210  mDisplayHintDecimals = displayHintDecimals;
211 }
212 
214 {
215  return mDisplayHintDecimals;
216 }
217 
218 
219 QColor QgsSettingsEntryColor::convertFromVariant( const QVariant &value ) const
220 {
221  return value.value<QColor>();
222 }
223 
225 {
227 }
228 
QgsSettingsEntryStringList::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:85
QgsSettingsEntryInteger::setMaxValue
void setMaxValue(qlonglong maxValue)
Set the maximum value.
Definition: qgssettingsentryimpl.cpp:144
QgsSettingsEntryDouble::setDisplayHintDecimals
void setDisplayHintDecimals(int displayHintDecimals)
Set the display hint decimals.
Definition: qgssettingsentryimpl.cpp:208
QgsSettingsEntryDouble::maxValue
double maxValue() const
Returns the maximum value.
Definition: qgssettingsentryimpl.cpp:203
QgsSettingsEntryDouble::setMinValue
void setMinValue(double minValue)
Set the minimum value.
Definition: qgssettingsentryimpl.cpp:188
Qgis::SettingsType::Double
@ Double
Double precision number.
QgsSettingsEntryString::maxLength
int maxLength() const
Returns the string maximum length.
Definition: qgssettingsentryimpl.cpp:73
QgsSettingsEntryBool::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:97
QgsSettingsEntryInteger::minValue
qlonglong minValue() const
Returns the minimum value.
Definition: qgssettingsentryimpl.cpp:139
QgsSettingsEntryString::minLength
int minLength() const
Returns the string minimum length.
Definition: qgssettingsentryimpl.cpp:63
QgsSettingsEntryDouble::displayHintDecimals
int displayHintDecimals() const
Returns how much decimals should be shown in the Gui.
Definition: qgssettingsentryimpl.cpp:213
QgsSettingsEntryInteger::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:129
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
Qgis::SettingsType
SettingsType
Types of settings entries.
Definition: qgis.h:230
Qgis::SettingsType::Bool
@ Bool
Boolean.
Qgis::SettingsType::String
@ String
String.
QgsSettingsEntryColor::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:224
Qgis::SettingsType::Variant
@ Variant
Generic variant.
Qgis::SettingsType::StringList
@ StringList
List of strings.
Qgis::SettingsType::Integer
@ Integer
Integer.
QgsSettingsEntryVariant::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:20
QgsSettingsEntryDouble::minValue
double minValue() const
Returns the minimum value.
Definition: qgssettingsentryimpl.cpp:193
qgssettingsentryimpl.h
QgsSettingsEntryString::setMaxLength
void setMaxLength(int maxLength)
Set the string maximum length.
Definition: qgssettingsentryimpl.cpp:68
QgsSettingsEntryByReference< QString >::value
QString value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:379
QgsSettingsEntryDouble::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:183
QgsSettingsEntryDouble::setMaxValue
void setMaxValue(double maxValue)
Set the maximum value.
Definition: qgssettingsentryimpl.cpp:198
QgsSettingsEntryString::setMinLength
void setMinLength(int minLength)
Set the string minimum length.
Definition: qgssettingsentryimpl.cpp:58
QgsSettingsEntryInteger::maxValue
qlonglong maxValue() const
Returns the maximum value.
Definition: qgssettingsentryimpl.cpp:149
QgsSettingsEntryInteger::setMinValue
void setMinValue(qlonglong minValue)
Set the minimum value.
Definition: qgssettingsentryimpl.cpp:134
QgsSettingsEntryString::settingsType
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
Definition: qgssettingsentryimpl.cpp:53
Qgis::SettingsType::Color
@ Color
Color.
QgsSettingsEntryByValue< bool >::value
bool value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:520