1 | /* This file is part of the KDE project |
2 | Copyright (C) 2001 Thomas Zander zander@kde.org |
3 | Copyright (C) 2004-2007 Dag Andersen <danders@get2net.dk> |
4 | |
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. |
9 | |
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. |
14 | |
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. |
19 | */ |
20 | |
21 | #ifndef KPTRELATION_H |
22 | #define KPTRELATION_H |
23 | |
24 | #include "kplatokernel_export.h" |
25 | |
26 | #include "kptduration.h" |
27 | |
28 | #include <KoXmlReader.h> |
29 | |
30 | #include <QString> |
31 | |
32 | class QDomElement; |
33 | |
34 | /// The main namespace |
35 | namespace KPlato |
36 | { |
37 | |
38 | class Node; |
39 | class Project; |
40 | |
41 | /** |
42 | * The relation class couples 2 nodes together which are dependent on each other. |
43 | * If for example you have a project to build a house, the node that represents the |
44 | * adding of the roof is dependent on the node that represents the building of the walls; |
45 | * the roof can't be put up if the walls are not there yet. |
46 | * We actually have a number of relationtypes so this relation can be used in different manners. |
47 | */ |
48 | class KPLATOKERNEL_EXPORT Relation { |
49 | public: |
50 | enum Type { FinishStart, FinishFinish, StartStart }; |
51 | |
52 | Relation(Node *parent, Node *child, Type type, Duration lag); |
53 | explicit Relation(Node *parent=0, Node *child=0, Type type=FinishStart); |
54 | explicit Relation(Relation *rel); |
55 | |
56 | /** |
57 | * When deleted the relation will remove itself from |
58 | * the parent- and child nodes lists |
59 | */ |
60 | virtual ~Relation(); |
61 | |
62 | /// Set relation type |
63 | void setType(Type ); |
64 | /// Set relation type |
65 | void setType( const QString &type ); |
66 | /// Return relation type |
67 | Type type() const { return m_type; } |
68 | /// Return relation type as a string. Translated if @p trans = true. |
69 | QString typeToString( bool trans = false ) const; |
70 | /// Convert @p type to a valid relation type |
71 | static Type typeFromString( const QString &type ); |
72 | /// Return a stringlist of relation types. Translated if @p trans = true |
73 | static QStringList typeList( bool trans = false ); |
74 | |
75 | /** |
76 | * Returns the lag. |
77 | * The lag of a relation is the time it takes between the parent starting/stopping |
78 | * and the start of the child. |
79 | */ |
80 | const Duration &lag() const { return m_lag; } |
81 | /// Set relaion time lag |
82 | void setLag(Duration lag) { m_lag = lag; } |
83 | |
84 | /** |
85 | * @return The parent dependent node. |
86 | */ |
87 | Node *parent() const { return m_parent; } |
88 | void setParent( Node *node ); |
89 | /** |
90 | * @return The child dependent node. |
91 | */ |
92 | Node *child() const { return m_child; } |
93 | void setChild( Node *node ); |
94 | |
95 | bool load(KoXmlElement &element, Project &project); |
96 | void save(QDomElement &element) const; |
97 | |
98 | protected: // variables |
99 | Node *m_parent; |
100 | Node *m_child; |
101 | Type m_type; |
102 | Duration m_lag; |
103 | |
104 | private: |
105 | QString m_parentId; |
106 | |
107 | #ifndef NDEBUG |
108 | public: |
109 | void printDebug(const QByteArray& indent); |
110 | #endif |
111 | |
112 | }; |
113 | |
114 | class KPLATOKERNEL_EXPORT ProxyRelation : public Relation |
115 | { |
116 | public: |
117 | ProxyRelation(Node *parent, Node *child, Relation::Type type, Duration lag) |
118 | : Relation(parent, child, type, lag) |
119 | {} |
120 | |
121 | ~ProxyRelation() { m_parent = 0; m_child = 0;} |
122 | }; |
123 | |
124 | } //KPlato namespace |
125 | |
126 | KPLATOKERNEL_EXPORT QDebug operator<<( QDebug dbg, const KPlato::Relation* r ); |
127 | KPLATOKERNEL_EXPORT QDebug operator<<( QDebug dbg, const KPlato::Relation& r ); |
128 | |
129 | #endif |
130 | |