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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#include <limits>
#include "settings.hpp"
SettingsRegistry::SettingsRegistry(QString path)
{
s = new QSettings(path, QSettings::Format::IniFormat);
}
SettingsRegistry::~SettingsRegistry()
{
delete s;
}
int SettingsRegistry::register_tab(QString tab_name)
{
tabs.push_back(tab_name);
return tabs.size() - 1;
}
void SettingsRegistry::register_int_option(int tab, std::string key, QString desc, int min, int max, int defaultval)
{
klist.push_back(key);
smap[key] = {
SettingsItem::ParameterType::_int,
tab,
key,
desc,
QVariant::fromValue<int>(min),
QVariant::fromValue<int>(max),
QVariant::fromValue<int>(defaultval),
nullptr};
}
int SettingsRegistry::get_option_int(std::string key)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_int)
return -1;
return s->value(QString::fromStdString(key), smap[key].defaultv).value<int>();
}
void SettingsRegistry::set_option_int(std::string key, int val)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_int)
return;
s->setValue(QString::fromStdString(key), QVariant::fromValue<int>(val));
}
void SettingsRegistry::register_bool_option(int tab, std::string key, QString desc, bool defaultval)
{
klist.push_back(key);
smap[key] = {
SettingsItem::ParameterType::_bool,
tab,
key,
desc,
QVariant(),
QVariant(),
QVariant::fromValue<bool>(defaultval),
nullptr};
}
bool SettingsRegistry::get_option_bool(std::string key)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_bool)
return false;
return s->value(QString::fromStdString(key), smap[key].defaultv).value<bool>();
}
void SettingsRegistry::set_option_bool(std::string key, bool val)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_bool)
return;
s->setValue(QString::fromStdString(key), QVariant::fromValue<bool>(val));
}
void SettingsRegistry::register_double_option(int tab, std::string key, QString desc, double min, double max, double defaultval)
{
klist.push_back(key);
smap[key] = {
SettingsItem::ParameterType::_double,
tab,
key,
desc,
QVariant::fromValue<double>(min),
QVariant::fromValue<double>(max),
QVariant::fromValue<double>(defaultval),
nullptr};
}
double SettingsRegistry::get_option_double(std::string key)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_double)
return std::numeric_limits<double>::quiet_NaN();
return s->value(QString::fromStdString(key), smap[key].defaultv).value<double>();
}
void SettingsRegistry::set_option_double(std::string key, double val)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_double)
return;
s->setValue(QString::fromStdString(key), QVariant::fromValue<double>(val));
}
void SettingsRegistry::register_keyseq_option(int tab, std::string key, QString desc, QKeySequence defaultval)
{
klist.push_back(key);
smap[key] = {
SettingsItem::ParameterType::_keyseq,
tab,
key,
desc,
QVariant(),
QVariant(),
QVariant::fromValue<QKeySequence>(defaultval),
nullptr};
}
QKeySequence SettingsRegistry::get_option_keyseq(std::string key)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_keyseq)
return QKeySequence();
return s->value(QString::fromStdString(key), smap[key].defaultv).value<QKeySequence>();
}
void SettingsRegistry::set_option_keyseq(std::string key, QKeySequence ks)
{
if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_keyseq)
return;
s->setValue(QString::fromStdString(key), QVariant::fromValue<QKeySequence>(ks));
}
|