F:/KPlato/koffice/kplato/kptrelation.cc

Aller à la documentation de ce fichier.
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 <qdom.h>
00027 
00028 #include <kdebug.h>
00029 
00030 namespace KPlato
00031 {
00032 
00033 Relation::Relation(Node *parent, Node *child, Type type, Duration lag) {
00034     m_parent=parent;
00035     m_child=child;
00036     m_type=type;
00037     m_lag=lag;
00038     //kDebug()<<k_funcinfo<<this<<endl;
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     //kDebug()<<k_funcinfo<<this<<endl;
00047 }
00048 
00049 Relation::Relation(Relation *rel) {
00050     m_parent=rel->parent();
00051     m_child=rel->child();
00052     m_type=rel->type();
00053     m_lag=rel->lag();
00054     //kDebug()<<k_funcinfo<<this<<endl;
00055 }
00056 
00057 Relation::~Relation() {
00058     //kDebug()<<k_funcinfo<<"("<<this<<") parent: "<<(m_parent ? m_parent->name():"none")<<" child: "<<(m_child ? m_child->name():"None")<<endl;
00059     if (m_parent)
00060         m_parent->takeDependChildNode(this);
00061     if (m_child)
00062         m_child->takeDependParentNode(this);
00063 }
00064 
00065 void Relation::setType(Type type) {
00066     m_type=type;
00067 }
00068 
00069 
00070 bool Relation::load(QDomElement &element, Project &project) {
00071     m_parent = project.findNode(element.attribute("parent-id"));
00072     if (m_parent == 0) {
00073         return false;
00074     }
00075     m_child = project.findNode(element.attribute("child-id"));
00076     if (m_child == 0) {
00077         return false;
00078     }
00079     if (m_child == m_parent) {
00080         kDebug()<<k_funcinfo<<"child == parent"<<endl;
00081         return false;
00082     }
00083     if (m_child == m_parent) {
00084         kDebug()<<k_funcinfo<<"child == parent"<<endl;
00085         return false;
00086     }
00087     if (!m_parent->legalToLink(m_child))
00088         return false;
00089         
00090     QString tr = element.attribute("type");
00091     if ( tr == "Finish-Start" )
00092         m_type = FinishStart;
00093     else if ( tr == "Finish-Finish" )
00094         m_type = FinishFinish;
00095     else if ( tr == "Start-Start" )
00096         m_type = StartStart;
00097     else
00098         m_type = FinishStart;
00099 
00100     m_lag = Duration::fromString(element.attribute("lag"));
00101 
00102     if (!m_parent->addDependChildNode(this)) {
00103         kError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00104         return false;
00105     }
00106     if (!m_child->addDependParentNode(this)) {
00107         m_parent->takeDependChildNode(this);
00108         kError()<<k_funcinfo<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00109         return false;
00110     }
00111 
00112     //kDebug()<<k_funcinfo<<"Added relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
00113     return true;
00114 }
00115 
00116 
00117 void Relation::save(QDomElement &element) const {
00118     QDomElement me = element.ownerDocument().createElement("relation");
00119     element.appendChild(me);
00120 
00121     me.setAttribute("parent-id", m_parent->id());
00122     me.setAttribute("child-id", m_child->id());
00123     QString type = "Finish-Start";
00124     switch (m_type) {
00125         case FinishStart:
00126             type = "Finish-Start";
00127             break;
00128         case FinishFinish:
00129             type = "Finish-Finish";
00130             break;
00131         case StartStart:
00132             type = "Start-Start";
00133             break;
00134     }
00135     me.setAttribute("type", type);
00136     me.setAttribute("lag", m_lag.toString());
00137 }
00138 
00139 #ifndef NDEBUG
00140 void Relation::printDebug(QByteArray indent) {
00141     indent += "  ";
00142     kDebug()<<indent<<"  Parent: "<<m_parent->name()<<endl;
00143     kDebug()<<indent<<"  Child: "<<m_child->name()<<endl;
00144     kDebug()<<indent<<"  Type: "<<m_type<<endl;
00145 }
00146 #endif
00147 
00148 }  //KPlato namespace

Généré le Wed Nov 22 23:40:57 2006 pour KPlato par  doxygen 1.5.1-p1