27bool QgsSettingsEntryString::checkValuePrivate(
const QString &value )
const
29 if (
value.length() < mMinLength )
31 QgsDebugError( 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 QgsDebugError( QStringLiteral(
"Can't set value for settings. String length '%1' is longer than maximum length '%2'." )
41 .arg(
value.length() )
51 return value.toString();
71 return value.toStringList();
82 return value.toBool();
92bool QgsSettingsEntryInteger::checkValuePrivate(
const int &value )
const
94 if (
value < mMinValue )
96 QgsDebugError( 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 QgsDebugError( 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 ) ) );
115 return value.toLongLong();
133bool QgsSettingsEntryInteger64::checkValuePrivate(
const qlonglong &value )
const
135 if (
value < mMinValue )
137 QgsDebugError( 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 QgsDebugError( 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 ) ) );
156 return value.toLongLong();
176bool QgsSettingsEntryDouble::checkValuePrivate(
const double &value )
const
178 if (
value < mMinValue )
180 QgsDebugError( 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 QgsDebugError( QObject::tr(
"Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
188 .arg( QString::number(
value ), QString::number( mMaxValue ) ) );
197 return value.toDouble();
222 return mDisplayHintDecimals;
228 return value.value<QColor>();
236bool QgsSettingsEntryColor::checkValuePrivate(
const QColor &value )
const
238 if ( !mAllowAlpha &&
value.alpha() != 255 )
240 QgsDebugError( 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() );
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 value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setVariantValue(const QVariant &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QString definitionKey() const
Returns settings entry defining key.
bool convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
QColor convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
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 convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
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.
qlonglong convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
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.
int convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
QStringList convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
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.
QString convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
virtual Qgis::SettingsType settingsType() const override
Returns the settings entry type.
QVariantMap convertFromVariant(const QVariant &value) const override
Converts the variant value to the value type of the setting.
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.
#define QgsDebugError(str)