-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.h
executable file
·76 lines (56 loc) · 1.44 KB
/
options.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
65
66
67
68
69
70
71
72
73
74
75
76
/*
* options.h
*
* Created on: 13.08.2008
*/
#ifndef OPTIONS_H_
#define OPTIONS_H_
#include <QtCore>
class Option
{
public:
Option()
{
widget = 0;
}
inline void setup(const QString &_id, const QVariant &_def, int _numId = 0)
{
id = _id;
val = def = _def;
numId = _numId;
}
inline void connectWidget(QWidget *w)
{
widget = w;
}
void readFromWidget();
void storeToWidget(bool _def = false);
inline operator bool() { return val.toBool(); }
inline operator int() { return val.toInt(); }
inline operator QString() { return val.toString(); }
// inline QVariant& operator[](int i) { return data[i]; }
template <typename T> inline Option& operator=(const T& v) { val = v; return *this; }
QString id;
int numId;
QVariant def;
QVariant val;
QWidget *widget;
QMap<int, QVariant> data;
};
class Options
{
public:
Options();
virtual ~Options();
void setup(Option &op, const QString &_id, const QVariant &_def, int _numId = 0);
void store(QSettings &set);
void restore(QSettings &set);
void readFromWidgets();
void storeToWidgets();
void storeDefaultsToWidgets();
inline QList<Option*> options() const { return myOptions; }
QList<Option*> options(int id);
protected:
QList<Option*> myOptions;
};
#endif /* OPTIONS_H_ */