kplato
kptrelation.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptrelation.h"
00021
00022 #include "kptnode.h"
00023 #include "kptproject.h"
00024 #include "kptcanvasitem.h"
00025
00026 #include <qcanvas.h>
00027 #include <qdom.h>
00028
00029 #include <kdebug.h>
00030
00031 namespace KPlato
00032 {
00033
00034 Relation::Relation(Node *parent, Node *child, Type type, Duration lag) {
00035 m_parent=parent;
00036 m_child=child;
00037 m_type=type;
00038 m_lag=lag;
00039 }
00040
00041 Relation::Relation(Node *parent, Node *child, Type type) {
00042 m_parent=parent;
00043 m_child=child;
00044 m_type=type;
00045 m_lag=Duration();
00046 }
00047
00048 Relation::Relation(Relation *rel) {
00049 m_parent=rel->parent();
00050 m_child=rel->child();
00051 m_type=rel->type();
00052 m_lag=rel->lag();
00053 }
00054
00055 Relation::~Relation() {
00056
00057 if (m_parent)
00058 m_parent->takeDependChildNode(this);
00059 if (m_child)
00060 m_child->takeDependParentNode(this);
00061 }
00062
00063 void Relation::setType(Type type) {
00064 m_type=type;
00065 }
00066
00067
00068 bool Relation::load(QDomElement &element, Project &project) {
00069 m_parent = project.findNode(element.attribute("parent-id"));
00070 if (m_parent == 0) {
00071 return false;
00072 }
00073 m_child = project.findNode(element.attribute("child-id"));
00074 if (m_child == 0) {
00075 return false;
00076 }
00077 if (!m_parent->legalToLink(m_child))
00078 return false;
00079
00080 QString tr = element.attribute("type");
00081 if ( tr == "Finish-Start" )
00082 m_type = FinishStart;
00083 else if ( tr == "Finish-Finish" )
00084 m_type = FinishFinish;
00085 else if ( tr == "Start-Start" )
00086 m_type = StartStart;
00087 else
00088 m_type = FinishStart;
00089
00090 m_lag = Duration::fromString(element.attribute("lag"));
00091
00092 if (!m_parent->addDependChildNode(this)) {
00093 kdError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00094 return false;
00095 }
00096 if (!m_child->addDependParentNode(this)) {
00097 m_parent->delDependChildNode(this, false);
00098 kdError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00099 return false;
00100 }
00101
00102
00103 return true;
00104 }
00105
00106
00107 void Relation::save(QDomElement &element) const {
00108 QDomElement me = element.ownerDocument().createElement("relation");
00109 element.appendChild(me);
00110
00111 me.setAttribute("parent-id", m_parent->id());
00112 me.setAttribute("child-id", m_child->id());
00113 QString type = "Finish-Start";
00114 switch (m_type) {
00115 case FinishStart:
00116 type = "Finish-Start";
00117 break;
00118 case FinishFinish:
00119 type = "Finish-Finish";
00120 break;
00121 case StartStart:
00122 type = "Start-Start";
00123 break;
00124 }
00125 me.setAttribute("type", type);
00126 me.setAttribute("lag", m_lag.toString());
00127 }
00128
00129 #ifndef NDEBUG
00130 void Relation::printDebug(QCString indent) {
00131 indent += " ";
00132 kdDebug()<<indent<<" Parent: "<<m_parent->name()<<endl;
00133 kdDebug()<<indent<<" Child: "<<m_child->name()<<endl;
00134 kdDebug()<<indent<<" Type: "<<m_type<<endl;
00135 }
00136 #endif
00137
00138 }
|