2018-07-17 13:22:51 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "qPrefPrivate.h"
|
2022-08-30 16:13:13 +00:00
|
|
|
#include "core/subsurface-float.h"
|
2018-07-17 13:22:51 +00:00
|
|
|
|
2018-08-15 11:26:09 +00:00
|
|
|
#include <QSettings>
|
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
QString keyFromGroupAndName(QString group, QString name)
|
|
|
|
{
|
|
|
|
QString slash = (group.endsWith('/') || name.startsWith('/')) ? "" : "/";
|
|
|
|
return group + slash + name;
|
|
|
|
}
|
|
|
|
|
2018-09-06 22:15:19 +00:00
|
|
|
void qPrefPrivate::propSetValue(const QString &key, const QVariant &value, const QVariant &defaultValue)
|
2018-07-17 13:22:51 +00:00
|
|
|
{
|
2018-08-15 11:26:09 +00:00
|
|
|
QSettings s;
|
2018-09-23 01:01:16 +00:00
|
|
|
bool isDefault = false;
|
2022-02-15 20:20:49 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
if (value.isValid() && value.typeId() == QMetaType::Double)
|
|
|
|
#else
|
2018-09-23 01:01:16 +00:00
|
|
|
if (value.isValid() && value.type() == QVariant::Double)
|
2022-02-15 20:20:49 +00:00
|
|
|
#endif
|
2022-08-30 15:55:43 +00:00
|
|
|
isDefault = nearly_equal(value.toDouble(), defaultValue.toDouble());
|
2018-09-23 01:01:16 +00:00
|
|
|
else
|
|
|
|
isDefault = (value == defaultValue);
|
|
|
|
|
|
|
|
if (!isDefault)
|
2018-09-06 22:15:19 +00:00
|
|
|
s.setValue(key, value);
|
|
|
|
else
|
|
|
|
s.remove(key);
|
2018-07-17 13:22:51 +00:00
|
|
|
}
|
2018-07-18 18:47:59 +00:00
|
|
|
|
2024-06-13 20:59:32 +00:00
|
|
|
void qPrefPrivate::propSetValue(const QString &key, const std::string &value, const std::string &defaultValue)
|
|
|
|
{
|
|
|
|
propSetValue(key, QString::fromStdString(value), QString::fromStdString(defaultValue));
|
|
|
|
}
|
|
|
|
|
2018-08-15 11:26:09 +00:00
|
|
|
QVariant qPrefPrivate::propValue(const QString &key, const QVariant &defaultValue)
|
2018-07-18 18:47:59 +00:00
|
|
|
{
|
2018-08-15 11:26:09 +00:00
|
|
|
QSettings s;
|
|
|
|
return s.value(key, defaultValue);
|
2018-07-18 18:47:59 +00:00
|
|
|
}
|
2024-06-13 20:59:32 +00:00
|
|
|
|
|
|
|
QVariant qPrefPrivate::propValue(const QString &key, const std::string &defaultValue)
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
return s.value(key, QString::fromStdString(defaultValue));
|
|
|
|
}
|