2018-07-17 13:22:51 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "qPrefPrivate.h"
|
2018-09-23 01:01:16 +00:00
|
|
|
#include "core/subsurface-string.h"
|
2018-07-17 13:22:51 +00:00
|
|
|
|
2018-08-15 11:26:09 +00:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
void qPrefPrivate::copy_txt(const char **name, const QString &string)
|
2018-07-17 13:22:51 +00:00
|
|
|
{
|
2018-08-15 11:26:09 +00:00
|
|
|
free((void *)*name);
|
|
|
|
*name = copy_qstring(string);
|
2018-07-17 13:22:51 +00:00
|
|
|
}
|
2018-08-15 11:26:09 +00:00
|
|
|
|
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
|
2018-09-23 01:01:16 +00:00
|
|
|
isDefault = IS_FP_SAME(value.toDouble(), defaultValue.toDouble());
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|