-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
executable file
·163 lines (146 loc) · 4.37 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
place_button_checked = edge_button_checked = false;
}
MainWindow::~MainWindow()
{
delete ui;
}
// Place
void MainWindow::on_pushButton_clicked()
{
if (place_button_checked)
{
ui->graphicsView->setDrawType(NO_TYPE);
ui->pushButton->setChecked(false);
place_button_checked = false;
}
else
{
ui->graphicsView->setDrawType(PLACE);
ui->pushButton_2->setChecked(false);
edge_button_checked = false;
ui->pushButton->setChecked(true);
place_button_checked = true;
}
}
// Edge
void MainWindow::on_pushButton_2_clicked()
{
if (edge_button_checked)
{
ui->graphicsView->setDrawType(NO_TYPE);
ui->pushButton_2->setChecked(false);
edge_button_checked = false;
}
else
{
ui->graphicsView->setDrawType(EDGE);
ui->pushButton->setChecked(false);
place_button_checked = false;
ui->pushButton_2->setChecked(true);
edge_button_checked = true;
}
}
// Clear
void MainWindow::on_pushButton_3_clicked()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Editor", "Really clear all?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes)
ui->graphicsView->clearAll();
}
// Save
void MainWindow::on_actionSave_triggered()
{
fio.saveToFile();
}
// Load
void MainWindow::on_actionLoad_triggered()
{
fio.LoadFromFile();
if (fio.graphChanged())
{
ui->graphicsView->clearView();
ui->graphicsView->redrawView();
}
}
// Simulate
void MainWindow::on_pushButton_4_clicked()
{
if (glob_places.empty() || glob_edges.empty())
{
QMessageBox::information(0, "Simulator", "No graph to simulate on.");
return;
}
QInputDialog qDialog;
QStringList items;
foreach (gEdge *e, glob_edges)
{
if (!items.contains(QString::number(e->getFrom()->id())))
items << QString::number(e->getFrom()->id());
if (!items.contains(QString::number(e->getTo()->id())))
items << QString::number(e->getTo()->id());
}
foreach (gPlace *p, glob_places)
{
if (!items.contains(QString::number(p->id())))
{
QMessageBox::information(0, "Simulator", "Graph must be connected.");
return;
}
}
items.sort();
qDialog.setOptions(QInputDialog::UseListViewForComboBoxItems);
qDialog.setComboBoxItems(items);
qDialog.setWindowTitle("Choose root node");
QObject::connect(&qDialog, SIGNAL(textValueSelected(const QString &)),
this, SLOT(setRoot(const QString &)));
if (qDialog.exec() == QDialog::Rejected)
{
QMessageBox::information(0, "Simulator", "You need to select root "
"ID before simulation.");
return;
}
simdlg = new SimulationDialog(root_id, this);
simdlg->setWindowFlags(Qt::Window | Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint);
simdlg->exec();
delete simdlg;
// reset graph colors
foreach (gEdge *e, glob_edges)
{
e->getFrom()->setBrushYellow();
e->getTo()->setBrushYellow();
e->setPenBlack();
}
ui->graphicsView->clearView();
ui->graphicsView->redrawView();
}
void MainWindow::setRoot(const QString &root)
{
root_id = root.toUInt();
}
// About
void MainWindow::on_actionAbout_triggered()
{
//QMessageBox a()
QMessageBox msgBox(QMessageBox::Information, "About",
"Prim algorithm simulator using Fibonacci heaps.<br>"
"<br>Authors:<br>"
"Erik Skultety<br>"
"Matus Marhefka<br><br>"
"Git repository:<br>"
"<a href=\"https://github.com/eskultety/FibonacciHeaps_demo/"
"\">https://github.com/eskultety/FibonacciHeaps_demo/</a>"
);
msgBox.setTextFormat(Qt::RichText);
msgBox.exec();
}