qPref: don't compare doubles for equality

This is a much safer way to do this.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-09-22 18:01:16 -07:00 committed by Jan Mulder
parent 617019bc6b
commit 619289074b

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "qPrefPrivate.h"
#include "core/subsurface-string.h"
#include <QSettings>
@ -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);