-
Notifications
You must be signed in to change notification settings - Fork 22
/
aogsettings.h
65 lines (51 loc) · 1.56 KB
/
aogsettings.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef AOGSETTINGS_H
#define AOGSETTINGS_H
#include <QSettings>
#include <QVariant>
#include <QList>
#include <QVector3D>
#include <QColor>
//Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QVector<int>)
extern QVariant unset;
class QJsonObject;
class AOGSettings : public QSettings
{
Q_OBJECT
public:
AOGSettings(QObject *parent = 0);
QVariant value(const QString &key, const QVariant &defaultvalue = unset);
QVector<int> value(const QString &key, const QVector<int> &defaultvalue = QVector<int> {});
void setValue(const QString &key, const QVector<int> &value_list);
void setValue(const QString &key, const QVariant &value);
//special method for QMLSettings to call, which won't call back to
//QMLSettings which would be a loop
void setValue_noqml(const QString &key, const QVariant &value);
QJsonObject toJson();
bool saveJson(QString filename);
bool loadJson(QString filename);
signals:
void updateFromSettings();
};
template <class T> static QVariant toVariant(const QVector<T> &list)
{
QVariantList variantList;
variantList.reserve(list.size());
for (const auto& v : list)
{
variantList.append(v);
}
return variantList;
}
template <class T> static QVector<T> toVector(const QVariant &qv)
{
QVector <T> dataList;
foreach(QVariant v, qv.value<QVariantList>()) {
dataList << v.value<T>();
}
return dataList;
}
QColor parseColor(QString setcolor);
QVector3D parseColorVector(QString setcolor);
int colorSettingStringToInt(QString colorSettingString);
#endif // AOGSETTINGS_H