-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSettings.cpp
More file actions
92 lines (77 loc) · 2.24 KB
/
Copy pathSettings.cpp
File metadata and controls
92 lines (77 loc) · 2.24 KB
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
#include "src/util/Settings.h"
#include "src/util/SettingsCategory.h"
#include "src/util/SettingsEntry.h"
#include "qstringlist.h"
Settings::Settings(QSettings* qsettings)
: _qsettings(qsettings) //???here or in app as back-end? access from entries through a singleton?
{
}
Settings::~Settings()
{
}
SettingsCategory* Settings::createCategory(const QString& name, const QString& label)
{
SettingsCategory* category = new SettingsCategory(*this, name, label);
categories.push_back(SettingsCategoryPtr(category));
return category;
}
SettingsCategory* Settings::getCategory(const QString& name) const
{
auto it = std::find_if(categories.begin(), categories.end(), [&name](const SettingsCategoryPtr& cat)
{
return cat->getName() == name;
});
//assert(it != categories.end());
return (it != categories.end()) ? it->get() : nullptr;
}
SettingsEntry* Settings::getEntry(const QString& path) const
{
return getEntry(path.split("/"));
}
SettingsEntry* Settings::getEntry(QStringList pathSplitted) const
{
if (pathSplitted.size() < 2) return nullptr;
auto category = getCategory(pathSplitted[0]);
pathSplitted.pop_front();
return category ? category->getEntry(pathSplitted) : nullptr;
}
// Robust setting value obtaining method
QVariant Settings::getEntryValue(const QString& path, const QVariant& defaultValue) const
{
SettingsEntry* entry = getEntry(path);
return entry ? entry->value() : defaultValue;
}
void Settings::applyChanges()
{
for (auto&& category : categories)
category->applyChanges();
}
void Settings::discardChanges()
{
for (auto&& category : categories)
category->discardChanges();
}
void Settings::load()
{
for (auto&& category : categories)
category->load();
_changesRequireRestart = false;
}
void Settings::store()
{
for (auto&& category : categories)
category->store();
}
void Settings::sort(bool deep)
{
std::sort(categories.begin(), categories.end(), [](const SettingsCategoryPtr& a, const SettingsCategoryPtr& b)
{
//return a->getName() < b->getName();
return a->getSortingWeight() < b->getSortingWeight();
});
if (deep)
{
for (auto&& category : categories)
category->sort();
}
}