1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef OPTIONUTILS_H
6#define OPTIONUTILS_H
7
8#include <QObject>
9
10class OptionUtils : public QObject
11{
12 Q_OBJECT
13public:
14 static QString getJsonFilePath();
15
16 static bool writeJsonSection(const QString &fileName, const QString &parentNode, const QString &itemNode,
17 const QMap<QString, QVariant> &map);
18 static bool readJsonSection(const QString &fileName, const QString &parentNode, const QString &itemNode,
19 QMap<QString, QVariant> &map);
20
21 static bool readAll(const QString &fileName, QMap<QString, QVariant> &map);
22 static bool writeAll(const QString &fileName, const QMap<QString, QVariant> &map);
23signals:
24
25public slots:
26
27private:
28 explicit OptionUtils(QObject *parent = nullptr);
29 virtual ~OptionUtils();
30
31 static bool readJsonRootObject(const QString &fileName, QJsonObject &rootObject);
32
33 static bool convertMapToJson(const QMap<QString, QVariant> &map, QJsonObject &jsonObject);
34 static bool convertJsonToMap(const QJsonObject &jsonObject, QMap<QString, QVariant> &map);
35
36 static void convert(const QString &key, const QVariant &variant, QJsonObject &jsonObject);
37 static void convert(const QString &key, const QJsonValue &variant, QMap<QString, QVariant> &map);
38};
39
40#endif // OPTIONUTILS_H
41