-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTransition.h
225 lines (201 loc) · 5.62 KB
/
Transition.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
class Transition;
#ifndef Transition_H
#define Transition_H
#include <QGraphicsLineItem>
#include "baseState.h"
#include "Graph.h"
QT_BEGIN_NAMESPACE
class QGraphicsPolygonItem;
class QGraphicsLineItem;
class QGraphicsScene;
class QRectF;
class QGraphicsSceneMouseEvent;
class QPainterPath;
QT_END_NAMESPACE
/**
* Class representing a transition between the tasks, and it's graphic representation.
*/
class Transition : public QGraphicsLineItem
{
public:
enum { Type = UserType + 4 };
/**
* Getter function for scene.
*/
QGraphicsScene * getScene(){return scene;}
/**
* Setter function for scene adding this item, all elements of lines vector and subtaskItem.
*/
void setScene(QGraphicsScene * sc);
/**
* Constructor creating Transition between startItem and EndItem.
*/
Transition(BaseState *startItem, BaseState *endItem,
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
/**
* Destructor removing this item from subtask list of the state pointed as subtask and removes this item from scene.
*/
~Transition();
/**
* Getter function for CondType.
*/
ConditionType getCondType(){return CondType;}
/**
* Setter function for CondType.
*/
void setCondType(ConditionType newCondType){CondType=newCondType;}
/**
* Getter function for type.
*/
int type() const
{ return Type; }
/**
* Returns QRectf bounding the transition.
*/
QRectF boundingRect() const;
/**
* Returns the path of the shape of transition.
*/
QPainterPath shape() const;
/**
* Sets state, which is a start state for this transition.
*/
void setStartItem( BaseState *newStartItem) { myStartItem=newStartItem; }
/**
* Sets state, which is an end state for this transition
*/
void setEndItem( BaseState *newEndItem) { myEndItem=newEndItem; }
/**
* Changes the z value (position of overlapping towards other elements).
*/
void setZValue(qreal z);
/**
* Sets subtask to NULL pointer.
*/
void removeSubtask()
{
subtask=NULL;
}
/**
* Getter function for myStartItem.
*/
BaseState *startItem() const
{ return myStartItem; }
/**
* Getter function for myEndItem.
*/
BaseState *endItem() const
{ return myEndItem; }
/**
* Getter function for condition.
*/
QString getCondition() {return condition;}
/**
* Setter function for subtask.
*/
void setCondition(QString newCondition) {condition=newCondition;}
/**
* Getter function for subtask.
*/
BaseState * getSubtask() {return subtask;}
/**
* Sets new subtask value (state pointer) and removes this transition from the list of pointers of the old state, and adds it to the new state.
*/
void setSubtask(BaseState * newSubtask)
{
if(subtask)subtask->removeSubtaskTrans(this);
if(subtask)subtaskItem->setPlainText("");
subtask=newSubtask;
if(subtask)subtask->addSubtaskTrans(this);
if(subtask)subtaskItem->setPlainText(QString("Subtask: ").append(subtask->getName()));
}
/**
* Creates a string describing the coordinates attributes.
* @returns String with the description of the Coordinates
*/
std::string Print()
{
std::string toRet;
toRet+="Condition: ";
toRet+=CONDITION_TABLE[CondType];
toRet+=condition.toStdString();
if(subtask!=NULL)
{
toRet+="\nSubtask: ";
toRet+=subtask->getName().toStdString();
}
return toRet;
}
/**
* Writes the data of the state to the XML stream.
* @param writer Stream to which the data is written
*/
void Print(QXmlStreamWriter * writer)
{
writer->writeStartElement("transition");
writer->writeAttribute("condition", QString().fromStdString(CONDITION_TABLE[CondType]).append(condition));
BaseState *tmpState;
tmpState = endItem();
QString tmpString;
if(subtask!=NULL)
{
tmpString = subtask->getName();
tmpString.append(QString(">>")).append(QString(tmpState->getName()));
}
else
{
tmpString= QString(tmpState->getName());
}
writer->writeAttribute("target", tmpString);
writer->writeEndElement();
}
protected:
/**
* Paints line, and head of the transition with colour dependent on isSelected().
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
public slots:
/**
* Creates new, actual line of the transition.
*/
void updatePosition();
protected:
/**
* Type of the condition.
*/
ConditionType CondType;
/**
* Scene on which this item is.
*/
QGraphicsScene * scene;
/**
* Additional lines usedfor transition whose start and end element are the same.
*/
std::vector<QGraphicsLineItem *> lines;
/**
* Start item of the transition.
*/
BaseState *myStartItem;
/**
* End item of the transition.
*/
BaseState *myEndItem;
/**
* Polygon representing the arrowhead of the transition.
*/
QPolygonF TransitionHead;
/**
* String representing the condition of this transition.
*/
QString condition;
/**
* Pointer to the subtask starting point of the transition.
*/
BaseState * subtask;
/**
* GraphicsItem representing name of the State, which is a subtask to this transition.
*/
QGraphicsTextItem * subtaskItem;
};
#endif