summaryrefslogtreecommitdiffstats
path: root/core/settings/qPrefPrivate.cpp
blob: e1622c3e7af9087a58e80178c6f8e4434c91fe83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: GPL-2.0
#include "qPrefPrivate.h"
#include "core/subsurface-string.h"

#include <QSettings>

void qPrefPrivate::copy_txt(const char **name, const QString &string)
{
	free((void *)*name);
	*name = copy_qstring(string);
}

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 (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);
}

QVariant qPrefPrivate::propValue(const QString &key, const QVariant &defaultValue)
{
	QSettings s;
	return  s.value(key, defaultValue);
}