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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/* This file is part of the KDE project
Copyright (C) 2005 Dag Andersen <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kptcontext.h"
#include <qdom.h>
#include <kdebug.h>
namespace KPlato
{
Context::Context()
: currentEstimateType(0),
currentSchedule(0) {
}
Context::~Context() {
}
bool Context::load(QDomElement &element) {
currentView = element.attribute("current-view");
currentEstimateType = element.attribute("estimate-type").toInt();
currentSchedule = element.attribute("current-schedule").toLong();
actionViewExpected = element.attribute("view-expected").toInt();
actionViewOptimistic = element.attribute("view-optimistic").toInt();
actionViewPessimistic = element.attribute("view-pessimistic").toInt();
QDomNodeList list = element.childNodes();
for (unsigned int i=0; i<list.count(); ++i) {
if (list.item(i).isElement()) {
QDomElement e = list.item(i).toElement();
if (e.tagName() == "gantt-view") {
ganttview.ganttviewsize = e.attribute("ganttview-size").toInt();
ganttview.taskviewsize = e.attribute("taskview-size").toInt();
ganttview.currentNode = e.attribute("current-node");
ganttview.showResources = e.attribute("show-resources").toInt();
ganttview.showTaskName = e.attribute("show-taskname").toInt();
ganttview.showTaskLinks = e.attribute("show-tasklinks").toInt();
ganttview.showProgress = e.attribute("show-progress").toInt();
ganttview.showPositiveFloat = e.attribute("show-positivefloat").toInt();
ganttview.showCriticalTasks = e.attribute("show-criticaltasks").toInt();
ganttview.showCriticalPath = e.attribute("show-criticalpath").toInt();
ganttview.showNoInformation = e.attribute("show-noinformation").toInt();
QDomNodeList list = e.childNodes();
for (unsigned int i=0; i<list.count(); ++i) {
if (list.item(i).isElement()) {
QDomElement g = list.item(i).toElement();
if (g.tagName() == "closed-nodes") {
QDomNodeList list = g.childNodes();
for (unsigned int i=0; i<list.count(); ++i) {
if (list.item(i).isElement()) {
QDomElement ei = list.item(i).toElement();
if (ei.tagName() == "node") {
ganttview.closedNodes.append(ei.attribute("id"));
}
}
}
}
}
}
} else if (e.tagName() == "accounts-view") {
accountsview.accountsviewsize = e.attribute("accountsview-size").toInt();
accountsview.periodviewsize = e.attribute("periodview-size").toInt();
accountsview.date = QDate::fromString(e.attribute("date"), Qt::ISODate);
accountsview.period = e.attribute("period").toInt();
accountsview.cumulative = e.attribute("cumulative").toInt();
QDomNodeList list = e.childNodes();
for (unsigned int i=0; i<list.count(); ++i) {
if (list.item(i).isElement()) {
QDomElement g = list.item(i).toElement();
if (g.tagName() == "closed-items") {
QDomNodeList list = g.childNodes();
for (unsigned int i=0; i<list.count(); ++i) {
if (list.item(i).isElement()) {
QDomElement ei = list.item(i).toElement();
if (ei.tagName() == "account") {
accountsview.closedItems.append(ei.attribute("name"));
}
}
}
}
}
}
} else {
kdError()<<k_funcinfo<<"Unknown tag: "<<e.tagName()<<endl;
}
}
}
return true;
}
void Context::save(QDomElement &element) const {
QDomElement me = element.ownerDocument().createElement("context");
element.appendChild(me);
me.setAttribute("current-view", currentView);
me.setAttribute("estimate-type", currentEstimateType);
me.setAttribute("current-schedule", currentSchedule);
me.setAttribute("view-expected", actionViewExpected);
me.setAttribute("view-optimistic", actionViewOptimistic);
me.setAttribute("view-pessimistic", actionViewPessimistic);
// Ganttview
QDomElement g = me.ownerDocument().createElement("gantt-view");
me.appendChild(g);
g.setAttribute("ganttview-size", ganttview.ganttviewsize);
g.setAttribute("taskview-size", ganttview.taskviewsize);
g.setAttribute("current-node", ganttview.currentNode);
g.setAttribute("show-resources", ganttview.showResources);
g.setAttribute("show-taskname", ganttview.showTaskName);
g.setAttribute("show-tasklinks", ganttview.showTaskLinks);
g.setAttribute("show-progress", ganttview.showProgress);
g.setAttribute("show-positivefloat", ganttview.showPositiveFloat);
g.setAttribute("show-criticaltasks", ganttview.showCriticalTasks);
g.setAttribute("show-criticalpath", ganttview.showCriticalPath);
g.setAttribute("show-noinformation", ganttview.showNoInformation);
if (!ganttview.closedNodes.isEmpty()) {
QDomElement e = g.ownerDocument().createElement("closed-nodes");
g.appendChild(e);
for (QStringList::ConstIterator it = ganttview.closedNodes.begin(); it != ganttview.closedNodes.end(); ++it) {
QDomElement c = e.ownerDocument().createElement("node");
e.appendChild(c);
c.setAttribute("id", (*it));
}
}
// Accountsview
QDomElement a = me.ownerDocument().createElement("accounts-view");
me.appendChild(a);
a.setAttribute("accountsview-size", accountsview.accountsviewsize);
a.setAttribute("periodview-size", accountsview.periodviewsize);
a.setAttribute("date", accountsview.date.toString(Qt::ISODate));
a.setAttribute("period", accountsview.period);
a.setAttribute("cumulative", accountsview.cumulative);
if (!accountsview.closedItems.isEmpty()) {
QDomElement e = a.ownerDocument().createElement("closed-items");
a.appendChild(e);
for (QStringList::ConstIterator it = accountsview.closedItems.begin(); it != accountsview.closedItems.end(); ++it) {
QDomElement c = e.ownerDocument().createElement("account");
e.appendChild(c);
c.setAttribute("name", (*it));
}
}
}
} //KPlato namespace
|