-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cc
90 lines (68 loc) · 1.97 KB
/
mainwindow.cc
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <vector>
#include <functional>
#include <thread>
#include <QString>
#include <QRegExp>
#include <QPainter>
#include <QAbstractItemModel>
#include <QItemSelectionModel>
#include "datamodel.h"
#include "sortdrawdelegate.h"
#include "sortingalgorithms.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
std::vector<int> test = {1,2,3,4,5,6,7,8,9};
model = nullptr;
sorting_thread = nullptr;
ui->sortingView->setItemDelegate(new Drawing::SortDrawDelegate(this));
ui->sortingView->setUpdatesEnabled(true);
}
MainWindow::~MainWindow()
{
if(sorting_thread != nullptr) {
if(sorting_thread->joinable()) {
sorting_thread->join();
}
delete sorting_thread;
}
delete ui;
delete model;
}
void MainWindow::on_sortButton_clicked() {
QString input_data = ui->unsortedData->text();
unsigned num;
bool ok;
parsed_data.clear();
for(QString i : input_data.split(' ', QString::SplitBehavior::SkipEmptyParts)) {
num = i.toUInt(&ok);
if(ok) {
parsed_data.push_back(num);
} else {
ui->statusBar->showMessage("Invalid input. Input must be non negative integer numbers separeted with spaces.", 10000);
parsed_data.clear();
return;
}
}
if(model != nullptr) {
delete model;
}
model = new Model::DataModel(&parsed_data, this);
ui->sortingView->setModel(model);
if(sorting_thread != nullptr) {
if(sorting_thread->joinable()) {
sorting_thread->join();
}
delete sorting_thread;
}
sorting_thread = new std::thread(&MainWindow::sort_data, this);
// ui->sortingView->selectionModel()->select(model->index(2,0, QModelIndex()), QItemSelectionModel::SelectionFlag::Select);
}
void MainWindow::sort_data()
{
model->BubbleSort(std::less<int>());
}