forked from madtreat/qt-dynamic-layout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layoutprofile.cpp
63 lines (56 loc) · 1.76 KB
/
layoutprofile.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
/*
* File: layoutprofile.cpp
* Author: madtreat
*
* Created on July 13, 2015, 1:39 PM
*/
#include "layoutprofile.h"
#include <QSettings>
#include <QDebug>
LayoutProfile::LayoutProfile(QString _filepath, QObject* _parent)
: QObject(_parent),
filepath(_filepath),
width(0),
height(0)
{
qDebug() << "Loading LayoutProfile from file:";
qDebug() << " " << filepath;
settings = new QSettings(filepath, QSettings::IniFormat);
loadLayoutProfile();
qDebug() << " with" << QString::number(itemList.size()) << "layout items";
}
//LayoutProfile::LayoutProfile(const LayoutProfile& orig) {
//}
LayoutProfile::~LayoutProfile() {
}
LayoutItem* LayoutProfile::getItemByName(QString name) const
{
for (int i = 0; i < itemList.size(); i++) {
LayoutItem* item = itemList.at(i);
if (item->name == name) {
return item;
}
}
return NULL;
}
void LayoutProfile::loadLayoutProfile() {
settings->beginGroup("layout");
width = settings->value("width").toInt();
height = settings->value("height").toInt();
settings->endGroup(); // "layout"
qDebug() << " Grid size:" << width << "x" << height;
qDebug() << " Child groups:" << settings->childGroups();
int size = settings->beginReadArray("layout-items");
for (int i = 0; i < size; i++) {
settings->setArrayIndex(i);
LayoutItem* item = new LayoutItem();
item->name = settings->value("name").toString();
item->row = settings->value("row").toInt();
item->col = settings->value("col").toInt();
item->rowSpan = settings->value("rowSpan").toInt();
item->colSpan = settings->value("colSpan").toInt();
item->visible = settings->value("visible").toBool();
itemList.append(item);
}
settings->endArray(); // "layout-items"
}