Skip to content

Commit

Permalink
add 64 bits integer settings (not available in Python)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 18, 2023
1 parent 04ff6e7 commit e059f3d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 6 deletions.
Expand Up @@ -508,7 +508,7 @@ Constructor for QgsSettingsEntryDouble.
:param options: specifies the options for the settings entry.
:param minValue: specifies the minimal value.
:param maxValue: specifies the maximal value.
:param displayDecimals: specifies an hint for the gui about how much decimals to show
:param displayDecimals: specifies a hint for the gui about how much decimals to show
for example for a QDoubleSpinBox.
%End

Expand All @@ -531,7 +531,7 @@ Constructor for QgsSettingsEntryDouble.
:param options: specifies the options for the settings entry.
:param minValue: specifies the minimal value.
:param maxValue: specifies the maximal value.
:param displayDecimals: specifies an hint for the gui about how much decimals to show
:param displayDecimals: specifies a hint for the gui about how much decimals to show
for example for a QDoubleSpinBox.
%End
public:
Expand All @@ -555,7 +555,7 @@ This constructor is intended to be used from plugins.
:param description: specifies a description for the settings entry.
:param minValue: specifies the minimal value.
:param maxValue: specifies the maximal value.
:param displayDecimals: specifies an hint for the gui about how much decimals to show
:param displayDecimals: specifies a hint for the gui about how much decimals to show
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryDouble( QgsSettingsEntryDouble( *a0, QgsSettings::createPluginTreeElement( *a1 ), a2, *a3, *a4, a5, a6, a7 ) );
Expand Down
41 changes: 41 additions & 0 deletions src/core/settings/qgssettingsentryimpl.cpp
Expand Up @@ -129,6 +129,47 @@ int QgsSettingsEntryInteger::minValue() const
return mMaxValue;
}

bool QgsSettingsEntryInteger64::checkValue( qlonglong value ) const
{
if ( value < mMinValue )
{
QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is less than minimum value '%2'." )
.arg( QString::number( value ) )
.arg( QString::number( mMinValue ) ) );
return false;
}

if ( value > mMaxValue )
{
QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
.arg( QString::number( value ) )
.arg( QString::number( mMaxValue ) ) );
return false;
}

return true;
}

qlonglong QgsSettingsEntryInteger64::convertFromVariant( const QVariant &value ) const
{
return value.toLongLong();
}

Qgis::SettingsType QgsSettingsEntryInteger64::settingsType() const
{
return Qgis::SettingsType::Integer;
}

qlonglong QgsSettingsEntryInteger64::maxValue() const
{
return mMaxValue;
}

qlonglong QgsSettingsEntryInteger64::minValue() const
{
return mMaxValue;
}



bool QgsSettingsEntryDouble::checkValue( double value ) const
Expand Down
85 changes: 82 additions & 3 deletions src/core/settings/qgssettingsentryimpl.h
Expand Up @@ -474,6 +474,85 @@ class CORE_EXPORT QgsSettingsEntryInteger : public QgsSettingsEntryByValue<int>
int mMaxValue;
};

#ifndef SIP_RUN
// not available in Python for now (no direct suport of 64 bits integers in Python)

/**
* \class QgsSettingsEntryInteger64
* \ingroup core
*
* \brief A 64 bits integer (long long) settings entry.
* \since QGIS 3.30
*/
class CORE_EXPORT QgsSettingsEntryInteger64 : public QgsSettingsEntryByValue<qlonglong>
{
public:

/**
* Constructor for QgsSettingsEntryInteger64.
*
* \param key specifies the final part of the settings key.
* \param parent specifies the parent in the tree of settings.
* \param defaultValue specifies the default value for the settings entry.
* \param description specifies a description for the settings entry.
* \param options specifies the options for the settings entry.
* \param minValue specifies the minimal value.
* \param maxValue specifies the maximal value.
*/
QgsSettingsEntryInteger64( const QString &key,
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() ) SIP_THROW( QgsSettingsException )
: QgsSettingsEntryByValue( key, parent, defaultValue, description, options )
, mMinValue( minValue )
, mMaxValue( maxValue )
{ }

/**
* Constructor for QgsSettingsEntryInteger64.
*
* \param key specifies the final part of the settings key.
* \param section specifies the section.
* \param defaultValue specifies the default value for the settings entry.
* \param description specifies a description for the settings entry.
* \param options specifies the options for the settings entry.
* \param minValue specifies the minimal value.
* \param maxValue specifies the maximal value.
*/
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() )
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
, mMinValue( minValue )
, mMaxValue( maxValue )
{ }

virtual Qgis::SettingsType settingsType() const override;

/**
* Returns the minimum value.
*/
qlonglong minValue() const;

/**
* Returns the maximum value.
*/
qlonglong maxValue() const;

private:
bool checkValue( qlonglong value ) const override;
qlonglong convertFromVariant( const QVariant &value ) const override;
qlonglong mMinValue;
qlonglong mMaxValue;
};
#endif

/**
* \class QgsSettingsEntryDouble
Expand All @@ -496,7 +575,7 @@ class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryByValue<double
* \param options specifies the options for the settings entry.
* \param minValue specifies the minimal value.
* \param maxValue specifies the maximal value.
* \param displayDecimals specifies an hint for the gui about how much decimals to show
* \param displayDecimals specifies a hint for the gui about how much decimals to show
* for example for a QDoubleSpinBox.
*/
QgsSettingsEntryDouble( const QString &key,
Expand All @@ -523,7 +602,7 @@ class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryByValue<double
* \param options specifies the options for the settings entry.
* \param minValue specifies the minimal value.
* \param maxValue specifies the maximal value.
* \param displayDecimals specifies an hint for the gui about how much decimals to show
* \param displayDecimals specifies a hint for the gui about how much decimals to show
* for example for a QDoubleSpinBox.
*/
QgsSettingsEntryDouble( const QString &key,
Expand Down Expand Up @@ -553,7 +632,7 @@ class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryByValue<double
* \param description specifies a description for the settings entry.
* \param minValue specifies the minimal value.
* \param maxValue specifies the maximal value.
* \param displayDecimals specifies an hint for the gui about how much decimals to show
* \param displayDecimals specifies a hint for the gui about how much decimals to show
*/
QgsSettingsEntryDouble( const QString &key,
const QString &pluginName,
Expand Down

0 comments on commit e059f3d

Please sign in to comment.