forked from askubis/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transWidget.cpp
210 lines (188 loc) · 7.47 KB
/
transWidget.cpp
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
#include "transWidget.h"
#include <QtGui>
using namespace boost;
TransWidget::TransWidget(QWidget *parent,Model * newmod )
: QWidget(parent)
{
mod = newmod;
QVBoxLayout *TransitionLayout = new QVBoxLayout;
QLabel *transCondLabel = new QLabel(tr("Transition condition:"));
conditionLineEdit = new QLineEdit;
conditionLineEdit->setValidator(new QRegExpValidator(QRegExp("^(stateOperationResult|true|TRUE|iniFile\\.\\w*)$"), conditionLineEdit));
connect(conditionLineEdit, SIGNAL(textChanged(QString)), this, SLOT(lengthChanged(QString)));
QHBoxLayout *bottomLayout = new QHBoxLayout;
TransitionLayout->addWidget(transCondLabel);
TransitionLayout->addWidget(conditionLineEdit);
QLabel * taskLabel = new QLabel(tr("Subtask:"));
subtaskCombo = new QComboBox(this);
subtaskCombo->addItem("None");
subtaskCombo->addItems(mod->getTasksNameListsWithoutMain());
TransitionLayout->addWidget(taskLabel);
TransitionLayout->addWidget(subtaskCombo);
connect(subtaskCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(subtaskChanged(QString)));
QLabel *stateLabel = new QLabel(tr("State:"));
stateCombo = new QComboBox(this);
TransitionLayout->addWidget(stateLabel);
TransitionLayout->addWidget(stateCombo);
OKButton = new QPushButton(tr("&Apply"));
OKButton->setChecked(false);
connect(OKButton, SIGNAL(clicked()), this, SLOT(AcceptTrans()));
OKButton->setDisabled(true);
bottomLayout->addWidget(OKButton);
/*InsertButton = new QPushButton(tr("&Insert"));
InsertButton->setChecked(false);
connect(InsertButton, SIGNAL(clicked()), this, SLOT(InsertTrans()));
InsertButton->setDisabled(true);
bottomLayout->addWidget(InsertButton);*/
QLabel * sourceLabel =new QLabel(tr("Source state:"));
sourceNameCombo = new QComboBox();
QLabel * destLabel =new QLabel(tr("Destination state:"));
destNameCombo = new QComboBox();
TransitionLayout->addWidget(sourceLabel);
TransitionLayout->addWidget(sourceNameCombo);
TransitionLayout->addWidget(destLabel);
TransitionLayout->addWidget(destNameCombo);
TransitionLayout->addStretch();
TransitionLayout->addLayout(bottomLayout);
edited = NULL;
OKButton->setDisabled(true);
setLayout(TransitionLayout);
}
void TransWidget::AcceptTrans()
{
if(edited==NULL)
{
emit reportError(QString("Please, select a transition to edit, edit it and then press OK."));
OKButton->setDisabled(true);
sourceNameCombo->clear();
destNameCombo->clear();
return;
}
if(!mod->checkTransitonExists(edited))
{
emit reportError(QString("The Transition You have been editing has been deleted"));
edited=NULL;
OKButton->setDisabled(true);
sourceNameCombo->clear();
destNameCombo->clear();
return;
}
if (edited->startItem()->getName()==sourceNameCombo->currentText() && edited->endItem()->getName()==destNameCombo->currentText())
{
if(mod->checkTransCondAvailabe(edited, conditionLineEdit->text()))
{
edited->setCondition(conditionLineEdit->text());
edited->setSubtask(mod->getState(stateCombo->currentText()));
OKButton->setDisabled(false);
edited->setToolTip(QString().fromStdString(edited->Print()));
}
else //that condition is already used for the source state
{
emit reportError(QString("The condition you specified is already in use for the source state."));
}
}
else if( ( edited->startItem()->getName() == sourceNameCombo->currentText() && mod->checkTransCondAvailabe(edited, conditionLineEdit->text()) )
||mod->checkTransCondAvailabe(mod->getState(sourceNameCombo->currentText()), conditionLineEdit->text()))
{
QString subtaskName = mod->getSubNameOfTrans(edited);
QGraphicsScene * scene = edited->getScene();
/*if(edited->startItem()->getName()!=sourceNameCombo->currentText())
{
mod->changeSourceStateofTrans(edited, sourceNameCombo->currentText());
}else{}
if(edited->endItem()->getName()!=destNameCombo->currentText())
{
mod->changeDestStateofTrans(edited, destNameCombo->currentText());
}else{}
edited->setCondition(conditionLineEdit->text());
edited->setSubtask(mod->getState(stateCombo->currentText()));
OKButton->setDisabled(false);
edited->setToolTip(QString().fromStdString(edited->Print()));*/
Transition * todelete = edited;
mod->deleteTransition(edited);
scene->removeItem(todelete);
delete todelete;//?
Transition * tr = new Transition(mod->getState(sourceNameCombo->currentText(), subtaskName), mod->getState(destNameCombo->currentText(), subtaskName));
tr->setScene(scene);
tr->setCondition(conditionLineEdit->text());
tr->setSubtask(mod->getState(stateCombo->currentText()));
tr->startItem()->addTransition(tr);
if(tr->startItem()!=tr->endItem())tr->endItem()->addTransition(tr);
tr->setZValue(-1000.0);
tr->updatePosition();
tr->setToolTip(QString().fromStdString(tr->Print()));
scene->addItem(tr);
bool test = mod->tryInsertTransition(tr);
this->TransSelected(tr);
}
else
{
emit reportError(QString("The condition you specified is already in use for the source state."));
}
}
void TransWidget::lengthChanged(QString newString)
{
if(newString.size()>0)
{
//InsertButton->setDisabled(false);
}
else
{
//InsertButton->setDisabled(true);
}
}
/*void TransWidget::InsertTrans()
{
edited = NULL;
OKButton->setDisabled(true);
//sourceNameLabel->setText(QString());
//destNameLabel->setText(QString());
std::pair<QString, QString> thePair = std::make_pair(conditionLineEdit->text(), stateCombo->currentText());
emit insertTransition(thePair);
}*/
void TransWidget::subtaskChanged(QString name)
{
if(subtaskCombo->currentIndex()!=-1)
{
stateCombo->clear();
if(name.toStdString()!="None")
{
stateCombo->addItems(mod->getAllStartStateNames(name));
}
}
}
void TransWidget::refreshData()
{
subtaskCombo->clear();
subtaskCombo->addItem("None");
subtaskCombo->addItems(mod->getTasksNameListsWithoutMain());
subtaskChanged(subtaskCombo->currentText());
sourceNameCombo->clear();
destNameCombo->clear();
}
void TransWidget::TransSelected(Transition * trans)
{
edited = trans;
OKButton->setDisabled(false);
QString subtaskName=mod->getSubtaskName(trans->startItem());
QStringList startList = mod->getAllStartStateNames(subtaskName);
sourceNameCombo->clear();
sourceNameCombo->addItems(startList);
sourceNameCombo->setCurrentIndex(sourceNameCombo->findText(trans->startItem()->getName()));
QStringList endList = mod->getAllEndStateNames(subtaskName);
destNameCombo->clear();
destNameCombo->addItems(endList);
destNameCombo->setCurrentIndex(destNameCombo->findText(trans->endItem()->getName()));
//sourceNameLabel->setText(trans->startItem()->getName());
//destNameLabel->setText(trans->endItem()->getName());
conditionLineEdit->setText(trans->getCondition());
if(mod->getSubtaskName(trans->getSubtask())==QString(""))
{
trans->setSubtask(NULL);
}
else
{
subtaskCombo->setCurrentIndex(subtaskCombo->findText(mod->getSubtaskName(trans->getSubtask())));
stateCombo->setCurrentIndex(stateCombo->findText(trans->getSubtask()->getName()));
}
}