-
Notifications
You must be signed in to change notification settings - Fork 1
/
Settings.h
51 lines (36 loc) · 1.37 KB
/
Settings.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef MAGICASSISTANT_SETTINGS_H
#define MAGICASSISTANT_SETTINGS_H
#include <QObject>
#include <QVariant>
#include <QMap>
class Settings : public QObject
{
Q_OBJECT
public:
Settings(QObject *parent = Q_NULLPTR);
Settings(const QString &filePath, QObject *parent = Q_NULLPTR);
~Settings();
bool setContent(const QString &content);
void setValue(const QString &key, const QVariant &value);
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
void insert(const QString &key, const QVariant &value);
QList<QVariant> values(const QString &key) const;
/// @brief parser functions.
static QString variantToString(const QVariant &v);
static QVariant stringToVariant(const QString &s);
private:
/// @brief
bool readXmlFile(const QString &fileName);
bool writeXmlFile(const QString &fileName);
static QStringList splitArgs(const QString &s, int idx);
/// @brief make sure dir exist. make sure this file is the type of xml.
QString processFile(const QString &filePath);
/// @brief 检查文件类型,若以非suffix后缀结尾,则添加此后缀至file.
void checkFileFormat(QString &file, const QString &suffix);
private:
QMap<QString, QVariant> m_map;
QString m_fileName;
// write file after setValue call.
bool m_isWrite;
};
#endif // MAGICASSISTANT_SETTINGS_H