forked from twiniars/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transWidget.cpp
292 lines (264 loc) · 9.92 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#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:"));
condTypeCombo = new QComboBox();
condTypeCombo->addItems(getCondTypeTable());
connect(condTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)));
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(condTypeCombo);
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()
{
QString src = sourceNameCombo->currentText();
QString dst = destNameCombo->currentText();
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, (ConditionType)condTypeCombo->currentIndex(), conditionLineEdit->text()))
{
edited->setCondition(conditionLineEdit->text());
edited->setCondType((ConditionType)condTypeCombo->currentIndex());
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,(ConditionType)condTypeCombo->currentIndex(), conditionLineEdit->text()) )
||mod->checkTransCondAvailabe(mod->getState(sourceNameCombo->currentText()),(ConditionType) condTypeCombo->currentIndex(), 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(src, subtaskName), mod->getState(dst, subtaskName));
tr->setScene(scene);
tr->setCondType((ConditionType)condTypeCombo->currentIndex());
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);
edited=NULL;
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()
{
if(edited)
{
if(edited->startItem()->getName()!=this->sourceNameCombo->currentText() ||
edited->endItem()->getName()!=this->destNameCombo->currentText() ||
edited->getCondition()!=this->conditionLineEdit->text() ||
condTypeCombo->currentIndex()!=edited->getCondType())
{
AcceptTrans();
return;
}
if(edited->getSubtask())
{
if (edited->getSubtask()->getName()!=this->stateCombo->currentText())
{
AcceptTrans();
return;
}
}
else
{
if(this->subtaskCombo->currentText()!="None")
{
AcceptTrans();
return;
}
}
}
edited=0;
subtaskCombo->clear();
subtaskCombo->addItem("None");
subtaskCombo->addItems(mod->getTasksNameListsWithoutMain());
subtaskChanged(subtaskCombo->currentText());
sourceNameCombo->clear();
destNameCombo->clear();
}
void TransWidget::TransSelected(Transition * trans)
{
if(edited)
{
if(edited->startItem()->getName()!=this->sourceNameCombo->currentText() ||
edited->endItem()->getName()!=this->destNameCombo->currentText() ||
edited->getCondition()!=this->conditionLineEdit->text() ||
condTypeCombo->currentIndex()!=edited->getCondType())
AcceptTrans();
if(edited->getSubtask())
{
if (edited->getSubtask()->getName()!=this->stateCombo->currentText())
AcceptTrans();
}
else
{
if(this->subtaskCombo->currentText()!="None")
AcceptTrans();
}
}
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());
condTypeCombo->setCurrentIndex(trans->getCondType());
conditionLineEdit->setText(trans->getCondition());
if(trans->getSubtask())
{
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()));
}
}
else
{
stateCombo->clear();
subtaskCombo->setCurrentIndex(0);
}
}
void TransWidget::indexChanged(int index)
{
if(index==INIFILE)
{
conditionLineEdit->setEnabled(true);
}
else
{
conditionLineEdit->setDisabled(true);
conditionLineEdit->setText("");
}
}