-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathfindingVisualizerApplication.cpp
More file actions
98 lines (78 loc) · 3.28 KB
/
PathfindingVisualizerApplication.cpp
File metadata and controls
98 lines (78 loc) · 3.28 KB
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
#include "PathfindingVisualizerApplication.h"
void PathfindingVisualizerApplication::disableButtons() {
checkBox->setEnabled(false);
algorithmSelector->setEnabled(false);
startButton->setEnabled(false);
clearButton->setEnabled(false);
resetButton->setEnabled(false);
undoButton->setEnabled(false);
}
void PathfindingVisualizerApplication::enableButtons() {
checkBox->setEnabled(true);
algorithmSelector->setEnabled(true);
startButton->setEnabled(true);
clearButton->setEnabled(true);
resetButton->setEnabled(true);
undoButton->setEnabled(true);
}
PathfindingVisualizerApplication::PathfindingVisualizerApplication() {
QString algorithms = "BFS,DFS,Random,AStar";
algoList = algorithms.split(",");
algo = algoFactory->switchAlgo(algoList[0]);
}
void PathfindingVisualizerApplication::handleStartClick() {
disableButtons();
cout << "solving" << endl;
Path path = algo->solve(board->getGrid());
board->drawPath(path);
if (checkBox->isChecked()) {
Analytics *analytics = new Analytics(this);
analytics->show(path);
}
enableButtons();
//cout << path.shortest[path.shortest.size() - 1].first << " " << path.shortest[path.shortest.size() - 1].second << endl;
}
void PathfindingVisualizerApplication::handleClearClick() {
board->clear();
}
void PathfindingVisualizerApplication::handleResetClick() {
board->reset();
}
void PathfindingVisualizerApplication::handleUndoClick() {
board->undo();
}
void PathfindingVisualizerApplication::itemChanged(QString str) {
algo = algoFactory->switchAlgo(str);
}
void PathfindingVisualizerApplication::launch() {
QWidget* window = new QWidget();
QGridLayout *layout = new QGridLayout(window);
window->setLayout(layout);
setCentralWidget(window);
window->setFixedSize(WIDTH, HEIGHT);
window->setWindowFlags(Qt::Widget | Qt::MSWindowsFixedSizeDialogHint);
window->setWindowTitle("Pathfinding Visualizer");
algorithmSelector = new QComboBox(window);
algorithmSelector->addItems(algoList);
connect(algorithmSelector, SIGNAL(currentTextChanged(QString)), this, SLOT(itemChanged(QString)));
layout->addWidget(algorithmSelector, 0, 0);
startButton = new QPushButton("start");
clearButton = new QPushButton("clear");
resetButton = new QPushButton("reset");
undoButton = new QPushButton("undo");
QObject::connect(startButton, &QPushButton::clicked, this, &PathfindingVisualizerApplication::handleStartClick);
QObject::connect(clearButton, &QPushButton::clicked, this, &PathfindingVisualizerApplication::handleClearClick);
QObject::connect(resetButton, &QPushButton::clicked, this, &PathfindingVisualizerApplication::handleResetClick);
QObject::connect(undoButton, &QPushButton::clicked, this, &PathfindingVisualizerApplication::handleUndoClick);
layout->addWidget(startButton, 0, 1);
layout->addWidget(clearButton, 0, 2);
layout->addWidget(resetButton, 0, 3);
layout->addWidget(undoButton, 1, 2);
checkBox = new QCheckBox("Show Analytics", this);
checkBox->setChecked(defaultAnalyticsToggleState);
layout->addWidget(checkBox, 1, 3);
board = new Board();
layout->addWidget(board, 2, 0, -1, -1);
show();
board->initialize();
}