Repository navigation
Expand file tree
/
Copy pathsection.cpp
More file actions
58 lines (52 loc) · 1.52 KB
/
Copy pathsection.cpp
File metadata and controls
58 lines (52 loc) · 1.52 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
#include "section.h"
#include <QJsonObject>
#include <QJsonArray>
#include <QList>
#include <QObject>
#include <QVariant>
#include <QDebug>
#include "setting.h"
Section::Section(QObject* parent) : QObject(parent)
{
if(parent) {
m_controller = parent->property("controller").value<QObject*>();
}
}
Section* Section::fromJson(const QJsonObject& object, QObject* parent)
{
Section *section = new Section(parent);
section->setProperty("name", object.value("name").toString());
QList<QObject*> settings;
QJsonArray array = object.value("settings").toArray();
for(QJsonArray::const_iterator element = array.begin(); element != array.end(); element++) {
if(!element->isObject()) {
qDebug() << "Unable to load configuration section from schema";
} else {
QObject* setting = Setting::fromJson(element->toObject(), section);
settings.append(setting);
}
}
section->setProperty("settings", QVariant::fromValue(settings));
return section;
}
QString Section::toString() const
{
QString header = QString("[%1]\n").arg(m_name);
QString settings;
foreach(QObject* setting, m_settings) {
settings += reinterpret_cast<Setting*>(setting)->toString();
}
if(settings.isEmpty()) {
return "";
} else {
return header + settings + "\n";
}
}
QDebug operator<<(QDebug debug, const Section §ion)
{
debug.nospace().noquote() << "[" << section.m_name << "]";
foreach(QObject* setting, section.m_settings) {
debug.maybeSpace() << *static_cast<Setting*>(setting);
}
return debug.space();
}