-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
91 lines (77 loc) · 2.38 KB
/
mainwindow.cpp
File metadata and controls
91 lines (77 loc) · 2.38 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ui_databaseoutput.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
myParser = new Parser(this);
db = new DBHandler(this);
//Creating new DB or connecting to excisting DB here
if (db->connect() == false){
QMessageBox msgBox;
msgBox.setText("Cannot connect or create Database");
msgBox.exec();
}
}
MainWindow::~MainWindow()
{
delete ui;
dialog->close();
delete dialog;
}
// OK button clicked, starting parsing and analysing
void MainWindow::on_pushButton_clicked()
{
//Vars to calculate elapsed time
long long start = QDateTime::currentMSecsSinceEpoch();
QString path = ui->lineEdit->text();
int length = ui->spinBox->value();
//To prevent parsing the same file twice
if(path != lastAddedFile){
myParser->parseFile(path);
myParser->calculateStatistics(length);
ui->statusBar->showMessage("Parsing...", 300);
}
myParser->filterHash(length);
lastAddedFile = path;
ui->textBrowser->setText(myParser->getResult());
QString includedFiles;
for(QString file : *myParser->getFiles()){
includedFiles.append(file + "<br></br>");
}
ui->textBrowser_includedFiles->setText(includedFiles);
long long end = QDateTime::currentMSecsSinceEpoch();
long long elapsed_seconds = end-start;
myParser->setElapsedTime(elapsed_seconds);
ui->statusBar->showMessage("Elapsed time: " + QString::number(elapsed_seconds) + " ms", 10000);
}
// Selecting file
void MainWindow::on_pushButton_choose_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Select file"), "/", tr("Text files(*.txt)"));
ui->lineEdit->setText(fileName);
}
//Recreate Parser object
void MainWindow::on_actionRemove_all_files_triggered()
{
ui->textBrowser->clear();
ui->textBrowser_includedFiles->clear();
lastAddedFile = "null";
delete myParser;
myParser = new Parser(this);
}
//Saving to a DataBase
void MainWindow::on_actionSave_triggered()
{
db->writeData(myParser->output, myParser->getElapsedTime(), myParser->getFiles(), ui->spinBox->value());
}
//TODO Implement DB history output
void MainWindow::on_actionView_History_triggered()
{
dialog = new DbIndexDialog(this);
dialog->createList(*db);
dialog->show();
}