-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSettingsSection.cpp
More file actions
88 lines (74 loc) · 2.12 KB
/
Copy pathSettingsSection.cpp
File metadata and controls
88 lines (74 loc) · 2.12 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
#include "src/util/SettingsSection.h"
#include "src/util/SettingsCategory.h"
#include "src/util/SettingsEntry.h"
// also there was "sortingWeight = 0"
SettingsSection::SettingsSection(SettingsCategory& category, const QString& name, const QString& label, int sortingWeight)
: _category(category)
, _name(name)
, _label(label.isEmpty() ? name : label)
, _sortingWeight(sortingWeight)
{
}
SettingsSection::~SettingsSection()
{
}
// It was createEntry(), and probably that was better from the OOP point,
// but SettingsEntry has so many constructor args that I don't want to
// copy them here and keep them in sync. Let it be compact and readable.
SettingsEntry* SettingsSection::addEntry(SettingsEntryPtr&& entry)
{
if (!entry || &entry->getSection() != this)
{
assert(false && "SettingsSection::addEntry() > invalid entry");
return nullptr;
}
entries.push_back(std::move(entry));
return entries.back().get();
}
SettingsEntry* SettingsSection::getEntry(const QString& name) const
{
auto it = std::find_if(entries.begin(), entries.end(), [&name](const SettingsEntryPtr& ent)
{
return ent->getName() == name;
});
assert(it != entries.end());
return (it != entries.end()) ? it->get() : nullptr;
}
QString SettingsSection::getPath() const
{
return _category.getPath() + "/" + _name;
}
void SettingsSection::applyChanges()
{
for (auto&& entry : entries)
entry->applyChanges();
}
void SettingsSection::discardChanges()
{
for (auto&& entry : entries)
entry->discardChanges();
}
void SettingsSection::load()
{
for (auto&& entry : entries)
entry->load();
}
void SettingsSection::store()
{
for (auto&& entry : entries)
entry->store();
}
void SettingsSection::sort()
{
std::sort(entries.begin(), entries.end(), [](const SettingsEntryPtr& a, const SettingsEntryPtr& b)
{
//return a->getName() < b->getName();
return a->getSortingWeight() < b->getSortingWeight();
});
}
bool SettingsSection::isModified() const
{
for (auto&& entry : entries)
if (entry->isModified()) return true;
return false;
}