forked from AlexK168/CourseProject2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
90 lines (73 loc) · 1.96 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->tabWidget->clear();
}
MainWindow::~MainWindow()
{
delete ui;
delete this->myableWidget;
}
void MainWindow::clearTable(){
for (auto c : constructors)
delete c;
constructors.clear();
ui->tabWidget->clear();
}
bool MainWindow::getJsonDoc(){
QString inputPath = QFileDialog::getOpenFileName(this, "Открыть файл", "", "*.json");
if (inputPath.isEmpty())
return false;
QFile json_file(inputPath);
if (!json_file.exists()) {
QMessageBox::warning(
this,
tr(APP_NAME),
tr("File doesn't exist!") );
return false;
}
json_file.open(QIODevice::ReadOnly | QIODevice::Text);
QString json_string = json_file.readAll();
json_file.close();
document = QJsonDocument::fromJson(json_string.toUtf8());
if (document.isNull()){
QMessageBox::warning(
this,
tr(APP_NAME),
tr("Wrong format!") );
return false;
}
return true;
}
void MainWindow::on_upload_log_triggered() {
if (!getJsonDoc())
return;
clearTable();
QJsonArray tests = document.array();
int i = 1;
for (const auto t : tests) {
QJsonArray test;
test = t.toArray();
QWidget* tab = new QWidget();
TableConstructor *constructor = new TableConstructor(test, tab);
constructors.push_back(constructor);
ui->tabWidget->addTab(tab, "test " + QString::number(i));
++i;
}
}
void MainWindow::on_exit_triggered()
{
clearTable();
QApplication::quit();
}
void MainWindow::on_about_triggered()
{
QMessageBox::information(
this,
tr("Vizualizer"),
tr(MainWindow::about_text) );
}