-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.cpp
executable file
·111 lines (89 loc) · 2.38 KB
/
options.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* options.cpp
*
* Created on: 13.08.2008
*/
#include "options.h"
#include <QtWidgets>
void Option::readFromWidget()
{
if (!widget) return;
if (dynamic_cast<QAbstractButton*>(widget)) {
val = ((QAbstractButton*)widget)->isChecked();
return;
}
if (dynamic_cast<QLineEdit*>(widget)) {
val = ((QLineEdit*)widget)->text();
return;
}
}
void Option::storeToWidget(bool _def)
{
if (!widget) return;
if (dynamic_cast<QAbstractButton*>(widget)) {
((QAbstractButton*)widget)->setChecked(_def ? def.toBool() : val.toBool());
return;
}
if (dynamic_cast<QLineEdit*>(widget)) {
((QLineEdit*)widget)->setText(_def ? def.toString() : val.toString());
return;
}
}
Options::Options()
{
// TODO Auto-generated constructor stub
}
Options::~Options()
{
// TODO Auto-generated destructor stub
}
void Options::setup(Option &op, const QString &_id, const QVariant &_def, int _numId)
{
op.setup(_id,_def,_numId);
myOptions << &op;
}
QList<Option*> Options::options(int id)
{
QList<Option*> list;
QList<Option*>::const_iterator it, it_end = myOptions.end();
for (it = myOptions.begin(); it != it_end; it++) {
if ((*it)->numId == id)
list << *it;
}
return list;
}
void Options::store(QSettings &set)
{
QList<Option*>::const_iterator it, it_end = myOptions.end();
for (it = myOptions.begin(); it != it_end; it++) {
set.setValue((*it)->id, (*it)->val);
}
}
void Options::restore(QSettings &set)
{
QList<Option*>::iterator it, it_end = myOptions.end();
for (it = myOptions.begin(); it != it_end; it++) {
(*it)->val = set.value((*it)->id, (*it)->def);
}
}
void Options::readFromWidgets()
{
QList<Option*>::iterator it, it_end = myOptions.end();
for (it = myOptions.begin(); it != it_end; it++) {
(*it)->readFromWidget();
}
}
void Options::storeToWidgets()
{
QList<Option*>::iterator it, it_end = myOptions.end();
for (it = myOptions.begin(); it != it_end; it++) {
(*it)->storeToWidget();
}
}
void Options::storeDefaultsToWidgets()
{
QList<Option*>::iterator it, it_end = myOptions.end();
for (it = myOptions.begin(); it != it_end; it++) {
(*it)->storeToWidget(true);
}
}