kplato

kptrelation.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Thomas zander <zander@kde.org>
00003    Copyright (C) 2004 Dag Andersen <danders@get2net.dk>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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     //kdDebug()<<k_funcinfo<<"parent: "<<(m_parent ? m_parent->name():"none")<<" child: "<<(m_child ? m_child->name():"None")<<endl;
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/*do not delete*/);
00098         kdError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00099         return false;
00100     }
00101 
00102     //kdDebug()<<k_funcinfo<<"Added relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
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 }  //KPlato namespace
KDE Home | KDE Accessibility Home | Description of Access Keys