This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttonhandler.cpp
45 lines (38 loc) · 1.51 KB
/
buttonhandler.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
#include "buttonhandler.h"
ButtonHandler::ButtonHandler() {
}
void ButtonHandler::draw(QTextEdit* textEdit, GraphWidget* graphWidget) {
graphWidget->clear();
QString text = textEdit->toPlainText();
QVector<int> a(3);
int cnt = 0;
QStringList l1 = text.split("\n", QString::SkipEmptyParts);
QStringList::const_iterator constIterator, constIterator2;
for (constIterator = l1.constBegin(); constIterator != l1.constEnd(); ++constIterator) {
QStringList l2 = constIterator->split(" ", QString::SkipEmptyParts);
for (constIterator2 = l2.constBegin(); constIterator2 != l2.constEnd(); ++constIterator2) {
a[cnt++] = constIterator2->toInt();
}
qDebug() << a[0] << a[1] << a[2];
if (cnt == 4) {
cnt = 0;
}
graphWidget->addEdge(a[0], a[1], a[2], a[3]);
}
/* graphWidget->addEdge(1, 2, 3); */
graphWidget->draw();
}
void ButtonHandler::calculatePath(QTextEdit* textEdit, GraphWidget* graphWidget) {
QString text = textEdit->toPlainText();
QVector<int> a(3);
int cnt = 0;
graphWidget->resetColor();
QStringList l1 = text.split(" ", QString::SkipEmptyParts);
QStringList::const_iterator constIterator;
for (constIterator = l1.constBegin(); constIterator != l1.constEnd(); ++constIterator) {
a[cnt++] = constIterator->toInt();
}
ShortestPath sp(graphWidget->getGraph(), graphWidget);
qDebug() << "Calculator: " << a[1] << a[2] << a[0];
sp.execute(a[1], a[2], a[0], true);
}