Skip to content
Permalink
Browse files
Fixed min negative value for QgsSettingsEntryDouble
  • Loading branch information
domi4484 committed Apr 8, 2021
1 parent 3c5f9b1 commit be0488887c08e8f3035d1cdb305b0b9a13eaa00e
@@ -425,7 +425,7 @@ QgsSettingsEntryDouble::QgsSettingsEntryDouble( const QString &key, const QStrin
pluginName,
defaultValue,
description )
, mMinValue( std::numeric_limits<double>::min() )
, mMinValue( std::numeric_limits<double>::lowest() )
, mMaxValue( std::numeric_limits<double>::max() )
, mDisplayHintDecimals( 1 )
{
@@ -581,7 +581,7 @@ class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryBase
QgsSettings::Section section,
double defaultValue = 0.0,
const QString &description = QString(),
double minValue = std::numeric_limits<double>::min(),
double minValue = std::numeric_limits<double>::lowest(),
double maxValue = std::numeric_limits<double>::max(),
int displayDecimals = 1 );

@@ -31,10 +31,67 @@ class TestQgsSettingsEntry : public QObject
Q_OBJECT

private slots:
void settingsKey();
void enumValue();
void flagValue();
};

void TestQgsSettingsEntry::settingsKey()
{
QgsSettings settings;

{
QString key( QStringLiteral( "/qgis/testing/settingsKey" ) );

// Be sure that settings does not exist already
settings.remove( key );

// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 42 );

QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::NoSection, 0 );
QCOMPARE( settingsEntryInteger.value(), 42 );
}

{
QString key( QStringLiteral( "qgis/testing/settingsKey" ) );

// Be sure that settings does not exist already
settings.remove( key );

// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 43 );

QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::NoSection, 0 );
QCOMPARE( settingsEntryInteger.value(), 43 );
}

{
QString key( QStringLiteral( "/qgis/testing/settingsKey" ) );

// Be sure that settings does not exist already
settings.remove( key, QgsSettings::Core );

// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 44, QgsSettings::Core );

QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::Core, 0 );
QCOMPARE( settingsEntryInteger.value(), 44 );
}

{
QString key( QStringLiteral( "qgis/testing/settingsKey" ) );

// Be sure that settings does not exist already
settings.remove( key, QgsSettings::Core );

// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 45, QgsSettings::Core );

QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::Core, 0 );
QCOMPARE( settingsEntryInteger.value(), 45 );
}
}

void TestQgsSettingsEntry::enumValue()
{
@@ -214,6 +214,12 @@ def test_settings_entry_integer(self):
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 43)
self.assertEqual(settingsEntryInteger.valueAsVariant(), 43)

# Set/Get negative value
settingsEntryInteger.setValue(-42)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), -42)
self.assertEqual(settingsEntryInteger.valueAsVariant(), -42)

# Settings type
self.assertEqual(settingsEntryInteger.settingsType(), QgsSettingsEntryBase.Integer)

@@ -236,6 +242,12 @@ def test_settings_entry_double(self):
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 1.618)
self.assertEqual(settingsEntryDouble.valueAsVariant(), 1.618)

# Set/Get negative value
settingsEntryDouble.setValue(-273.15)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), -273.15)
self.assertEqual(settingsEntryDouble.valueAsVariant(), -273.15)

# Settings type
self.assertEqual(settingsEntryDouble.settingsType(), QgsSettingsEntryBase.Double)

0 comments on commit be04888

Please sign in to comment.