-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
88 lines (78 loc) · 3.41 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow) {
ui->setupUi(this);
database = new Database("data.bin");
addDialog = new AddDialog(this, database);
tableOutput = new TableOutput(this);
connect(addDialog, &AddDialog::updateCallback, this, &MainWindow::onUpdateCallback);
ui->tableWidget->setColumnCount(5);
ui->tableWidget->setRowCount(1);
ui->tableWidget->setItem(0, 0, new QTableWidgetItem("Name"));
ui->tableWidget->setItem(0, 1, new QTableWidgetItem("Year"));
ui->tableWidget->setItem(0, 2, new QTableWidgetItem("Genre"));
ui->tableWidget->setItem(0, 3, new QTableWidgetItem("Main Actor"));
ui->tableWidget->setItem(0, 4, new QTableWidgetItem("Rating"));
ui->lineEdit->setValidator(new QIntValidator(this));
plotter = new Plotter;
redrawTable();
}
MainWindow::~MainWindow() {
delete ui;
delete database;
delete addDialog;
}
void MainWindow::on_pushButton_clicked() {
addDialog->open();
}
void MainWindow::on_pushButton_2_clicked() {
database->remove(ui->tableWidget->selectedItems().back()->row() - 1);
redrawTable();
}
void MainWindow::onUpdateCallback() {
redrawTable();
}
void MainWindow::redrawTable() {
for(size_t i = 0; i < ui->tableWidget->rowCount(); i++) {
delete ui->tableWidget->item(i + 1, 0);
delete ui->tableWidget->item(i + 1, 1);
delete ui->tableWidget->item(i + 1, 2);
delete ui->tableWidget->item(i + 1, 3);
delete ui->tableWidget->item(i + 1, 4);
}
DatabaseNode *nodes = nullptr;
DatabaseNode leastRated(const_cast<char *>(""), 0, const_cast<char *>("Unavailable"), const_cast<char *>(""), 127);
size_t quantity = database->update(nodes);
ui->tableWidget->setRowCount(quantity + 1);
for(size_t i = 0; i < quantity; i++) {
ui->tableWidget->setItem(i + 1, 0,
new QTableWidgetItem(QString::fromLocal8Bit(nodes[i].name, strlen(nodes[i].name))));
ui->tableWidget->setItem(i + 1, 1,
new QTableWidgetItem(QString::number(nodes[i].year)));
ui->tableWidget->setItem(i + 1, 2,
new QTableWidgetItem(QString::fromLocal8Bit(nodes[i].genre, strlen(nodes[i].genre))));
ui->tableWidget->setItem(i + 1, 3,
new QTableWidgetItem(QString::fromLocal8Bit(nodes[i].mainActor, strlen(nodes[i].mainActor))));
ui->tableWidget->setItem(i + 1, 4,
new QTableWidgetItem(QString::number(nodes[i].rating)));
if(leastRated.rating > nodes[i].rating)
leastRated = nodes[i];
}
ui->lineEdit_5->setText(QString::fromLocal8Bit(leastRated.genre, strlen(leastRated.genre)));
}
void MainWindow::on_pushButton_3_clicked() {
DatabaseNode *nodes = nullptr;
size_t quantity = database->filter(nodes, ui->lineEdit_2->text().toLocal8Bit().data(), ui->lineEdit->text().toInt(), FilterOption::genreFilter);
tableOutput->showTable(nodes, quantity);
}
void MainWindow::on_pushButton_10_clicked() {
DatabaseNode *nodes = nullptr;
size_t quantity = database->filter(nodes, ui->lineEdit_4->text().toLocal8Bit().data());
tableOutput->showTable(nodes, quantity);
}
void MainWindow::on_pushButton_4_clicked() {
DatabaseNode *nodes = nullptr;
plotter->showGraph(nodes, database->update(nodes));
}