forked from twiniars/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transition.h
164 lines (141 loc) · 4.27 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
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 };
QGraphicsScene * getScene(){return scene;}
void setScene(QGraphicsScene * sc);
Transition(BaseState *startItem, BaseState *endItem,
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
~Transition();
ConditionType getCondType(){return CondType;}
void setCondType(ConditionType newCondType){CondType=newCondType;}
int type() const
{ return Type; }
QRectF boundingRect() const;
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; }
void setZValue(qreal z);
void removeSubtask()
{
subtask=NULL;
}
BaseState *startItem() const
{ return myStartItem; }
BaseState *endItem() const
{ return myEndItem; }
QString getCondition() {return condition;}
void setCondition(QString newCondition) {condition=newCondition;}
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:
ConditionType CondType;
QGraphicsScene * scene;
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;
QGraphicsTextItem * subtaskItem;
};
#endif