27bool QgsSettingsEntryString::checkValue(
const QString &value )
const
29 if (
value.length() < mMinLength )
31 QgsDebugMsg( QStringLiteral(
"Can't set value for settings. String length '%1' is shorter than minimum length '%2'." )
32 .arg(
value.length() )
38 &&
value.length() > mMaxLength )
40 QgsDebugMsg( QStringLiteral(
"Can't set value for settings. String length '%1' is longer than maximum length '%2'." )
41 .arg(
value.length() )
49QString QgsSettingsEntryString::convertFromVariant(
const QVariant &value )
const
51 return value.toString();
69QStringList QgsSettingsEntryStringList::convertFromVariant(
const QVariant &value )
const
71 return value.toStringList();
80bool QgsSettingsEntryBool::convertFromVariant(
const QVariant &value )
const
82 return value.toBool();
92bool QgsSettingsEntryInteger::checkValue(
int value )
const
94 if (
value < mMinValue )
96 QgsDebugMsg( QObject::tr(
"Can't set value for setting. Value '%1' is less than minimum value '%2'." )
97 .arg( QString::number(
value ) )
98 .arg( QString::number( mMinValue ) ) );
102 if (
value > mMaxValue )
104 QgsDebugMsg( QObject::tr(
"Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
105 .arg( QString::number(
value ) )
106 .arg( QString::number( mMaxValue ) ) );
113int QgsSettingsEntryInteger::convertFromVariant(
const QVariant &value )
const
115 return value.toLongLong();
133bool QgsSettingsEntryInteger64::checkValue( qlonglong value )
const
135 if (
value < mMinValue )
137 QgsDebugMsg( QObject::tr(
"Can't set value for setting. Value '%1' is less than minimum value '%2'." )
138 .arg( QString::number(
value ) )
139 .arg( QString::number( mMinValue ) ) );
143 if (
value > mMaxValue )
145 QgsDebugMsg( QObject::tr(
"Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
146 .arg( QString::number(
value ) )
147 .arg( QString::number( mMaxValue ) ) );
154qlonglong QgsSettingsEntryInteger64::convertFromVariant(
const QVariant &value )
const
156 return value.toLongLong();
176bool QgsSettingsEntryDouble::checkValue(
double value )
const
178 if (
value < mMinValue )
180 QgsDebugMsg( QObject::tr(
"Can't set value for setting. Value '%1' is less than minimum value '%2'." )
181 .arg( QString::number(
value ), QString::number( mMinValue ) ) );
185 if (
value > mMaxValue )
187 QgsDebugMsg( QObject::tr(
"Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
188 .arg( QString::number(
value ), QString::number( mMaxValue ) ) );
195double QgsSettingsEntryDouble::convertFromVariant(
const QVariant &value )
const
197 return value.toDouble();
222 return mDisplayHintDecimals;
226QColor QgsSettingsEntryColor::convertFromVariant(
const QVariant &value )
const
228 return value.value<QColor>();
236bool QgsSettingsEntryColor::checkValue(
const QColor &value )
const
238 if ( !mAllowAlpha &&
value.alpha() != 255 )
240 QgsDebugMsg( QStringLiteral(
"Setting %1 doesn't allow transparency and the given color has transparency." ).arg(
definitionKey() ) );
250 if ( settings.
contains( redKey ) && settings.
contains( greenKey ) && settings.
contains( blueKey ) && ( alphaKey.isNull() || settings.
contains( alphaKey ) ) )
253 if ( alphaKey.isNull() )
254 oldValue = QColor( settings.
value( redKey ).toInt(), settings.
value( greenKey ).toInt(), settings.
value( blueKey ).toInt() );
256 oldValue = QColor( settings.
value( redKey ).toInt(), settings.
value( greenKey ).toInt(), settings.
value( blueKey ).toInt(), settings.
value( alphaKey ).toInt() );
258 if ( removeSettingAtKey )
260 settings.
remove( redKey );
261 settings.
remove( greenKey );
262 settings.
remove( blueKey );
263 settings.
remove( alphaKey );
275 const QColor color =
value();
276 settings.
setValue( redKey, color.red() );
277 settings.
setValue( greenKey, color.green() );
278 settings.
setValue( blueKey, color.blue() );
279 if ( !alphaKey.isNull() )
280 settings.
setValue( alphaKey, color.alpha() );
283QVariantMap QgsSettingsEntryVariantMap::convertFromVariant(
const QVariant &value )
const
285 return value.value<QVariantMap>();
SettingsType
Types of settings entries.
@ Variant
Generic variant.
@ StringList
List of strings.
@ VariantMap
Map of strings.
@ Double
Double precision number.
QString definitionKey() const
Returns settings entry defining key.
bool setVariantValuePrivate(const QVariant &value, const QStringList &dynamicKeyPartList=QStringList()) const
Sets the settings value with a variant value.
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.
bool copyValueFromKeys(const QString &redKey, const QString &greenKey, const QString &blueKey, const QString &alphaKey=QString(), bool removeSettingAtKey=false) const
Copies the value from the given keys if they exist.
void copyValueToKeys(const QString &redKey, const QString &greenKey, const QString &blueKey, const QString &alphaKey=QString()) const
Copies the settings to the given keys.
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.
double maxValue() const
Returns 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.
int minValue() const
Returns the minimum value.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
int maxValue() const
Returns the maximum 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.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
This class is a composition of two QSettings instances:
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.
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.