subsurface/core/settings/qPrefPrivate.cpp
Berthold Stoeger ccdd92aeb7 preferences: use std::string in struct preferences
This is a messy commit, because the "qPref" system relies
heavily on QString, which means lots of conversions between
the two worlds. Ultimately, I plan to base the preferences
system on std::string and only convert to QString when
pushing through Qt's property system or when writing into
Qt's settings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00

47 lines
1.3 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#include "qPrefPrivate.h"
#include "core/subsurface-float.h"
#include <QSettings>
QString keyFromGroupAndName(QString group, QString name)
{
QString slash = (group.endsWith('/') || name.startsWith('/')) ? "" : "/";
return group + slash + name;
}
void qPrefPrivate::propSetValue(const QString &key, const QVariant &value, const QVariant &defaultValue)
{
QSettings s;
bool isDefault = false;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (value.isValid() && value.typeId() == QMetaType::Double)
#else
if (value.isValid() && value.type() == QVariant::Double)
#endif
isDefault = nearly_equal(value.toDouble(), defaultValue.toDouble());
else
isDefault = (value == defaultValue);
if (!isDefault)
s.setValue(key, value);
else
s.remove(key);
}
void qPrefPrivate::propSetValue(const QString &key, const std::string &value, const std::string &defaultValue)
{
propSetValue(key, QString::fromStdString(value), QString::fromStdString(defaultValue));
}
QVariant qPrefPrivate::propValue(const QString &key, const QVariant &defaultValue)
{
QSettings s;
return s.value(key, defaultValue);
}
QVariant qPrefPrivate::propValue(const QString &key, const std::string &defaultValue)
{
QSettings s;
return s.value(key, QString::fromStdString(defaultValue));
}