00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptcontext.h"
00021
00022 #include <qdom.h>
00023
00024 #include <kdebug.h>
00025
00026 namespace KPlato
00027 {
00028
00029 Context::Context()
00030 : currentEstimateType(0),
00031 currentSchedule(0) {
00032 }
00033
00034 Context::~Context() {
00035 }
00036
00037 bool Context::load(QDomElement &element) {
00038 currentView = element.attribute("current-view");
00039 currentEstimateType = element.attribute("estimate-type").toInt();
00040 currentSchedule = element.attribute("current-schedule").toLong();
00041 actionViewExpected = element.attribute("view-expected").toInt();
00042 actionViewOptimistic = element.attribute("view-optimistic").toInt();
00043 actionViewPessimistic = element.attribute("view-pessimistic").toInt();
00044
00045 QDomNodeList list = element.childNodes();
00046 for (unsigned int i=0; i<list.count(); ++i) {
00047 if (list.item(i).isElement()) {
00048 QDomElement e = list.item(i).toElement();
00049 if (e.tagName() == "gantt-view") {
00050 ganttview.ganttviewsize = e.attribute("ganttview-size").toInt();
00051 ganttview.taskviewsize = e.attribute("taskview-size").toInt();
00052 ganttview.currentNode = e.attribute("current-node");
00053 ganttview.showResources = e.attribute("show-resources").toInt();
00054 ganttview.showTaskName = e.attribute("show-taskname").toInt();
00055 ganttview.showTaskLinks = e.attribute("show-tasklinks").toInt();
00056 ganttview.showProgress = e.attribute("show-progress").toInt();
00057 ganttview.showPositiveFloat = e.attribute("show-positivefloat").toInt();
00058 ganttview.showCriticalTasks = e.attribute("show-criticaltasks").toInt();
00059 ganttview.showCriticalPath = e.attribute("show-criticalpath").toInt();
00060 ganttview.showNoInformation = e.attribute("show-noinformation").toInt();
00061
00062 QDomNodeList list = e.childNodes();
00063 for (unsigned int i=0; i<list.count(); ++i) {
00064 if (list.item(i).isElement()) {
00065 QDomElement g = list.item(i).toElement();
00066 if (g.tagName() == "closed-nodes") {
00067 QDomNodeList list = g.childNodes();
00068 for (unsigned int i=0; i<list.count(); ++i) {
00069 if (list.item(i).isElement()) {
00070 QDomElement ei = list.item(i).toElement();
00071 if (ei.tagName() == "node") {
00072 ganttview.closedNodes.append(ei.attribute("id"));
00073 }
00074 }
00075 }
00076 }
00077 }
00078 }
00079 } else if (e.tagName() == "accounts-view") {
00080 accountsview.accountsviewsize = e.attribute("accountsview-size").toInt();
00081 accountsview.periodviewsize = e.attribute("periodview-size").toInt();
00082 accountsview.date = QDate::fromString(e.attribute("date"), Qt::ISODate);
00083 accountsview.period = e.attribute("period").toInt();
00084 accountsview.cumulative = e.attribute("cumulative").toInt();
00085
00086 QDomNodeList list = e.childNodes();
00087 for (unsigned int i=0; i<list.count(); ++i) {
00088 if (list.item(i).isElement()) {
00089 QDomElement g = list.item(i).toElement();
00090 if (g.tagName() == "closed-items") {
00091 QDomNodeList list = g.childNodes();
00092 for (unsigned int i=0; i<list.count(); ++i) {
00093 if (list.item(i).isElement()) {
00094 QDomElement ei = list.item(i).toElement();
00095 if (ei.tagName() == "account") {
00096 accountsview.closedItems.append(ei.attribute("name"));
00097 }
00098 }
00099 }
00100 }
00101 }
00102 }
00103 } else {
00104 kError()<<k_funcinfo<<"Unknown tag: "<<e.tagName()<<endl;
00105 }
00106 }
00107 }
00108
00109 return true;
00110 }
00111
00112 void Context::save(QDomElement &element) const {
00113 QDomElement me = element.ownerDocument().createElement("context");
00114 element.appendChild(me);
00115 me.setAttribute("current-view", currentView);
00116 me.setAttribute("estimate-type", currentEstimateType);
00117 me.setAttribute("current-schedule", (qlonglong)currentSchedule);
00118 me.setAttribute("view-expected", actionViewExpected);
00119 me.setAttribute("view-optimistic", actionViewOptimistic);
00120 me.setAttribute("view-pessimistic", actionViewPessimistic);
00121
00122 QDomElement g = me.ownerDocument().createElement("gantt-view");
00123 me.appendChild(g);
00124 g.setAttribute("ganttview-size", ganttview.ganttviewsize);
00125 g.setAttribute("taskview-size", ganttview.taskviewsize);
00126 g.setAttribute("current-node", ganttview.currentNode);
00127 g.setAttribute("show-resources", ganttview.showResources);
00128 g.setAttribute("show-taskname", ganttview.showTaskName);
00129 g.setAttribute("show-tasklinks", ganttview.showTaskLinks);
00130 g.setAttribute("show-progress", ganttview.showProgress);
00131 g.setAttribute("show-positivefloat", ganttview.showPositiveFloat);
00132 g.setAttribute("show-criticaltasks", ganttview.showCriticalTasks);
00133 g.setAttribute("show-criticalpath", ganttview.showCriticalPath);
00134 g.setAttribute("show-noinformation", ganttview.showNoInformation);
00135 if (!ganttview.closedNodes.isEmpty()) {
00136 QDomElement e = g.ownerDocument().createElement("closed-nodes");
00137 g.appendChild(e);
00138 for (QStringList::ConstIterator it = ganttview.closedNodes.begin(); it != ganttview.closedNodes.end(); ++it) {
00139 QDomElement c = e.ownerDocument().createElement("node");
00140 e.appendChild(c);
00141 c.setAttribute("id", (*it));
00142 }
00143 }
00144
00145 QDomElement a = me.ownerDocument().createElement("accounts-view");
00146 me.appendChild(a);
00147 a.setAttribute("accountsview-size", accountsview.accountsviewsize);
00148 a.setAttribute("periodview-size", accountsview.periodviewsize);
00149 a.setAttribute("date", accountsview.date.toString(Qt::ISODate));
00150 a.setAttribute("period", accountsview.period);
00151 a.setAttribute("cumulative", accountsview.cumulative);
00152 if (!accountsview.closedItems.isEmpty()) {
00153 QDomElement e = a.ownerDocument().createElement("closed-items");
00154 a.appendChild(e);
00155 for (QStringList::ConstIterator it = accountsview.closedItems.begin(); it != accountsview.closedItems.end(); ++it) {
00156 QDomElement c = e.ownerDocument().createElement("account");
00157 e.appendChild(c);
00158 c.setAttribute("name", (*it));
00159 }
00160 }
00161 }
00162
00163 }