2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2009-05-19 19:20:53 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2009-05-19 19:20:53 +02:00
|
|
|
|
|
|
|
|
#include "core_global.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QVariant>
|
2009-05-19 19:20:53 +02:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace Internal { class SettingsDatabasePrivate; }
|
2009-05-19 19:20:53 +02:00
|
|
|
|
|
|
|
|
class CORE_EXPORT SettingsDatabase : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-05-07 17:34:42 +02:00
|
|
|
SettingsDatabase(const QString &path, const QString &application, QObject *parent = nullptr);
|
2018-05-07 15:00:03 +02:00
|
|
|
~SettingsDatabase() override;
|
2009-05-19 19:20:53 +02:00
|
|
|
|
|
|
|
|
void setValue(const QString &key, const QVariant &value);
|
|
|
|
|
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
2021-01-26 16:31:12 +01:00
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
void setValueWithDefault(const QString &key, const T &val, const T &defaultValue);
|
|
|
|
|
template<typename T>
|
|
|
|
|
void setValueWithDefault(const QString &key, const T &val);
|
|
|
|
|
|
2009-05-19 19:20:53 +02:00
|
|
|
bool contains(const QString &key) const;
|
|
|
|
|
void remove(const QString &key);
|
|
|
|
|
|
|
|
|
|
void beginGroup(const QString &prefix);
|
|
|
|
|
void endGroup();
|
|
|
|
|
QString group() const;
|
|
|
|
|
QStringList childKeys() const;
|
|
|
|
|
|
2014-02-21 15:43:49 +01:00
|
|
|
void beginTransaction();
|
|
|
|
|
void endTransaction();
|
|
|
|
|
|
2009-05-19 19:20:53 +02:00
|
|
|
void sync();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Internal::SettingsDatabasePrivate *d;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-26 16:31:12 +01:00
|
|
|
template<typename T>
|
|
|
|
|
void SettingsDatabase::setValueWithDefault(const QString &key, const T &val, const T &defaultValue)
|
|
|
|
|
{
|
|
|
|
|
if (val == defaultValue)
|
|
|
|
|
remove(key);
|
|
|
|
|
else
|
|
|
|
|
setValue(key, QVariant::fromValue(val));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
void SettingsDatabase::setValueWithDefault(const QString &key, const T &val)
|
|
|
|
|
{
|
|
|
|
|
if (val == T())
|
|
|
|
|
remove(key);
|
|
|
|
|
else
|
|
|
|
|
setValue(key, QVariant::fromValue(val));
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-19 19:20:53 +02:00
|
|
|
} // namespace Core
|