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_child == m_parent) {
00078 kdDebug()<<k_funcinfo<<"child == parent"<<endl;
00079 return false;
00080 }
00081 if (!m_parent->legalToLink(m_child))
00082 return false;
00083
00084 QString tr = element.attribute("type");
00085 if ( tr == "Finish-Start" )
00086 m_type = FinishStart;
00087 else if ( tr == "Finish-Finish" )
00088 m_type = FinishFinish;
00089 else if ( tr == "Start-Start" )
00090 m_type = StartStart;
00091 else
00092 m_type = FinishStart;
00093
00094 m_lag = Duration::fromString(element.attribute("lag"));
00095
00096 if (!m_parent->addDependChildNode(this)) {
00097 kdError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00098 return false;
00099 }
00100 if (!m_child->addDependParentNode(this)) {
00101 m_parent->delDependChildNode(this, false);
00102 kdError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00103 return false;
00104 }
00105
00106
00107 return true;
00108 }
00109
00110
00111 void Relation::save(QDomElement &element) const {
00112 QDomElement me = element.ownerDocument().createElement("relation");
00113 element.appendChild(me);
00114
00115 me.setAttribute("parent-id", m_parent->id());
00116 me.setAttribute("child-id", m_child->id());
00117 QString type = "Finish-Start";
00118 switch (m_type) {
00119 case FinishStart:
00120 type = "Finish-Start";
00121 break;
00122 case FinishFinish:
00123 type = "Finish-Finish";
00124 break;
00125 case StartStart:
00126 type = "Start-Start";
00127 break;
00128 }
00129 me.setAttribute("type", type);
00130 me.setAttribute("lag", m_lag.toString());
00131 }
00132
00133 #ifndef NDEBUG
00134 void Relation::printDebug(QCString indent) {
00135 indent += " ";
00136 kdDebug()<<indent<<" Parent: "<<m_parent->name()<<endl;
00137 kdDebug()<<indent<<" Child: "<<m_child->name()<<endl;
00138 kdDebug()<<indent<<" Type: "<<m_type<<endl;
00139 }
00140 #endif
00141
00142 }
|