-
Notifications
You must be signed in to change notification settings - Fork 4
/
state.cpp
69 lines (62 loc) · 1.74 KB
/
state.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
#include "state.h"
#include "ui_state.h"
State::State(): QWidget(0), ui(0), level(0) {
this->parentState = 0;
}
State::State(QList<Element *> &places): State() {
this->tokenCounts.resize(places.count());
for (Element *place: places) {
this->tokenCounts[place->number()] = ((Place *)place)->tokenCount();
}
}
State::State(const State &state): State() {
this->tokenCounts = state.tokenCounts;
}
State::~State() {
if (ui) {
delete ui;
}
}
bool State::operator==(const State &stateToCompareTo) {
return this->tokenCounts == stateToCompareTo.tokenCounts;
}
QString State::description() {
QString description = "(";
if (this->tokenCounts.count() != 0) {
if (this->tokenCounts[0] != -1) {
description += QString::number(this->tokenCounts[0]);
}
else {
description += "inf";
}
for (int i = 1; i < this->tokenCounts.count(); ++i) {
description += ",";
int tokenCount = this->tokenCounts[i];
if (tokenCount != -1) {
description += QString::number(tokenCount);
}
else {
description += "inf";
}
}
}
description += ")";
return description;
}
void State::setupUi(QWidget *parent)
{
this->setParent(parent);
ui = new Ui::State;
ui->setupUi(this);
this->show();
QString text = "(";
for (int tokenCount: this->tokenCounts) {
text += QString::number(tokenCount) + ",";
}
text += ")";
for (State::StateConnection connection: this->outgoingConnections) {
text += "T" + QString::number(connection.transition->number()) + ",";
}
ui->tokenCountsLabel->setText(text);
this->adjustSize();
}