From 619289074ba33f00bb19c5fe62c2c72782d5b997 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 22 Sep 2018 18:01:16 -0700 Subject: [PATCH] qPref: don't compare doubles for equality This is a much safer way to do this. Signed-off-by: Dirk Hohndel --- core/settings/qPrefPrivate.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/settings/qPrefPrivate.cpp b/core/settings/qPrefPrivate.cpp index 8cbbe932e..14fb1be1e 100644 --- a/core/settings/qPrefPrivate.cpp +++ b/core/settings/qPrefPrivate.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "qPrefPrivate.h" +#include "core/subsurface-string.h" #include @@ -22,7 +23,13 @@ void qPrefPrivate::propSetValue(const QString &key, const QVariant &value, const // Having it as a local variable is light weight, because it is an // interface class. QSettings s; - if (value != defaultValue) + bool isDefault = false; + if (value.isValid() && value.type() == QVariant::Double) + isDefault = IS_FP_SAME(value.toDouble(), defaultValue.toDouble()); + else + isDefault = (value == defaultValue); + + if (!isDefault) s.setValue(key, value); else s.remove(key);