1
/* This file is part of the KDE project
2
Copyright (C) 2001 Thomas zander <zander@kde.org>
3
Copyright (C) 2004, 2012 Dag Andersen <danders@get2net.dk>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
20
#include "kptrelation.h"
23
#include "kptproject.h"
26
#include <KoXmlReader.h>
28
#include <KLocalizedString>
30
#include <QStringList>
36
Relation::Relation(Node *parent, Node *child, Type type, Duration lag) {
44
Relation::Relation(Node *parent, Node *child, Type type) {
52
Relation::Relation(Relation *rel) {
53
m_parent=rel->parent();
60
Relation::~Relation() {
61
//debugPlan<<"("<<this<<") parent:"<<(m_parent ? m_parent->name():"none")<<" child:"<<(m_child ? m_child->name():"None");
63
m_parent->takeDependChildNode(this);
65
m_child->takeDependParentNode(this);
68
void Relation::setType(Type type) {
72
void Relation::setType( const QString &type )
74
int t = typeList().indexOf( type );
78
m_type = static_cast<Type>( t );
81
QString Relation::typeToString( bool trans ) const
83
return typeList( trans ).at( m_type );
86
QStringList Relation::typeList( bool trans )
88
//NOTE: must match enum
90
lst << ( trans ? i18n( "Finish-Start" ) : "Finish-Start" );
91
lst << ( trans ? i18n( "Finish-Finish" ) : "Finish-Finish" );
92
lst << ( trans ? i18n( "Start-Start" ) : "Start-Start" );
96
void Relation::setParent( Node* node )
101
void Relation::setChild( Node* node )
107
bool Relation::load(KoXmlElement &element, Project &project) {
108
m_parent = project.findNode(element.attribute("parent-id"));
112
m_child = project.findNode(element.attribute("child-id"));
116
if (m_child == m_parent) {
117
debugPlan<<"child == parent";
120
if (m_child == m_parent) {
121
debugPlan<<"child == parent";
124
if (!m_parent->legalToLink(m_child))
127
setType( element.attribute("type") );
129
m_lag = Duration::fromString(element.attribute("lag"));
131
if (!m_parent->addDependChildNode(this)) {
132
errorPlan<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
135
if (!m_child->addDependParentNode(this)) {
136
m_parent->takeDependChildNode(this);
137
errorPlan<<"Failed to add relation: Child="<<m_child->name()<<" parent="<<m_parent->name()<<endl;
141
//debugPlan<<"Added relation: Child="<<m_child->name()<<" parent="<<m_parent->name();
146
void Relation::save(QDomElement &element) const {
147
QDomElement me = element.ownerDocument().createElement("relation");
148
element.appendChild(me);
150
me.setAttribute("parent-id", m_parent->id());
151
me.setAttribute("child-id", m_child->id());
152
QString type = "Finish-Start";
155
type = "Finish-Start";
158
type = "Finish-Finish";
161
type = "Start-Start";
166
me.setAttribute("type", type);
167
me.setAttribute("lag", m_lag.toString());
171
void Relation::printDebug(const QByteArray& _indent) {
172
QString indent = _indent;
174
debugPlan<<indent<<" Parent:"<<m_parent->name();
175
debugPlan<<indent<<" Child:"<<m_child->name();
176
debugPlan<<indent<<" Type:"<<m_type;
183
QDebug operator<<( QDebug dbg, const KPlato::Relation *r )
188
QDebug operator<<( QDebug dbg, const KPlato::Relation &r )
190
KPlato::Node *parent = r.parent();
191
KPlato::Node *child = r.child();
193
switch ( r.type() ) {
194
case KPlato::Relation::StartStart: type = "SS"; break;
195
case KPlato::Relation::FinishFinish: type = "FF"; break;
199
KPlato::Duration lag = r.lag();
200
dbg<<"Relation["<<parent->name()<<"->"<<child->name()<<type;
202
dbg<<lag.toString( KPlato::Duration::Format_HourFraction );