forked from askubis/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransDialog.cpp
98 lines (88 loc) · 3.07 KB
/
TransDialog.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
#include "TransDialog.h"
TransDialog::TransDialog(QWidget * parent, Model * newmod):QDialog(parent)
{
mod = newmod;
setWindowTitle(tr("Pose"));
QGridLayout * mainLayout = new QGridLayout;
QLabel * label1 = new QLabel("Condition:");
QLabel * label2 = new QLabel("Target:");
QLabel * label3 = new QLabel("Subtask:");
mainLayout->addWidget(label1, 0,0);
mainLayout->addWidget(label2, 0,1);
mainLayout->addWidget(label3, 0,2);
transCondList = new QListWidget();
mainLayout->addWidget(transCondList, 1,0,7,1);
connect(transCondList, SIGNAL(currentRowChanged(int)), this, SLOT(RowChanged(int)));
transTargList = new QListWidget();
mainLayout->addWidget(transTargList, 1,1,7,1);
connect(transTargList, SIGNAL(currentRowChanged(int)), this, SLOT(RowChanged(int)));
transSubList = new QListWidget();
mainLayout->addWidget(transSubList, 1,2,7,1);
connect(transSubList, SIGNAL(currentRowChanged(int)), this, SLOT(RowChanged(int)));
QPushButton * UpButton = new QPushButton("Up");
connect(UpButton, SIGNAL(clicked()), this, SLOT(UpPressed()));
QPushButton * DownButton = new QPushButton("Down");
connect(DownButton, SIGNAL(clicked()), this, SLOT(DownPressed()));
QPushButton * OKButton = new QPushButton("OK");
connect(OKButton, SIGNAL(clicked()), this, SLOT(OKPressed()));
mainLayout->addWidget(UpButton,0,4);
mainLayout->addWidget(DownButton,1,4);
mainLayout->addWidget(OKButton,2,4);
this->setGeometry(0,0,500,400);
this->setLayout(mainLayout);
}
void TransDialog::openForAState(BaseState * tmp)
{
state = tmp;
setWindowTitle(tr(("Editing transitions for state "+tmp->getName().toStdString()).c_str()));
transCondList->clear();
transTargList->clear();
transSubList->clear();
std::vector<Transition *> tranList=mod->getTransitions(tmp);
foreach(Transition * tr, tranList)
{
transCondList->addItem(tr->getCondition());
transTargList->addItem(tr->endItem()->getName());
if(tr->getSubtask())transSubList->addItem(tr->getSubtask()->getName());
else transSubList->addItem(QString());
}
RowChanged(0);
}
void TransDialog::RowChanged(int index)
{
transCondList->setCurrentRow(index);
transTargList->setCurrentRow(index);
transSubList->setCurrentRow(index);
}
void TransDialog::OKPressed()
{
this->setVisible(false);
}
void TransDialog::DownPressed()
{
int index = transCondList->currentIndex().row();
if(index==state->getTransitions().size()-1)
{
emit reportError(QString("Cannot move the last transition down"));
return;
}
mod->MoveTransitionDown(state,index);
openForAState(state);
RowChanged(index+1);
}
void TransDialog::UpPressed()
{
int index = transCondList->currentIndex().row();
if(index<0)
{
emit reportError(QString("A transition has to be selected"));
}
if(index==0)
{
emit reportError(QString("Cannot move the first transition up"));
return;
}
mod->MoveTransitionUp(state,index);
openForAState(state);
RowChanged(index-1);
}