forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNekoGui_ConfigItem.hpp
70 lines (51 loc) · 1.53 KB
/
NekoGui_ConfigItem.hpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// DO NOT INCLUDE THIS
namespace NekoGui_ConfigItem {
// config 工具
enum itemType {
string,
integer,
integer64,
boolean,
stringList,
integerList,
jsonStore,
};
class configItem {
public:
QString name;
void *ptr;
itemType type;
configItem(QString n, void *p, itemType t) {
name = std::move(n);
ptr = p;
type = t;
}
};
// 可格式化对象
class JsonStore {
public:
QMap<QString, std::shared_ptr<configItem>> _map;
std::function<void()> callback_after_load = nullptr;
std::function<void()> callback_before_save = nullptr;
QString fn;
bool load_control_must = false; // must load from file
bool save_control_compact = false;
bool save_control_no_save = false;
QByteArray last_save_content;
JsonStore() = default;
explicit JsonStore(QString fileName) {
fn = std::move(fileName);
}
void _add(configItem *item);
QString _name(void *p);
std::shared_ptr<configItem> _get(const QString &name);
void _setValue(const QString &name, void *p);
QJsonObject ToJson(const QStringList &without = {});
QByteArray ToJsonBytes();
void FromJson(QJsonObject object);
void FromJsonBytes(const QByteArray &data);
bool Save();
bool Load();
};
} // namespace NekoGui_ConfigItem
using namespace NekoGui_ConfigItem;