-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
122 lines (92 loc) · 3.32 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QThread>
#include <QMessageBox>
#include "xdffile.h"
MainWindow::MainWindow(QWidget *parent, const char* filename) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
if(filename) loadfile(QString::fromLatin1(filename));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::handleSelectionChanged(const QItemSelection& selection) {
if(selection.indexes().isEmpty()) {
} else {
int selectionAsInt = selection.indexes().first().row();
ui->textEdit->setPlainText(xdfFile->getChunkText(selectionAsInt));
}
}
void MainWindow::onTextChanged() {
if(xdfFile)
xdfFile->setChunkText(ui->listView->selectionModel()->currentIndex().row(),ui->textEdit->toPlainText());
}
void MainWindow::on_actionSave_As_triggered()
{
if(!xdfFile) return;
QString xdfFileName = QFileDialog::getSaveFileName(this, tr("Save XDF File As"), "",tr("*.xdf"));
if(!xdfFileName.isNull()) {
SaverThread *workerThread = new SaverThread;
workerThread->xdfFile = xdfFile;
workerThread->xdfFileName = xdfFileName;
workerThread->progressBar = ui->progressBar;
connect(workerThread, SIGNAL(errorMessageSignal(QString)), this, SLOT(errorDialog(QString)));
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
workerThread->start();
this->setWindowTitle(xdfFileName);
}
}
void MainWindow::on_actionSave_triggered()
{
//try invoke method with this function?
//QMessageBox::critical(NULL, tr("Critical"), tr("Critical message text"));
if(!xdfFile) return;
SaverThread *workerThread = new SaverThread;
workerThread->xdfFile = xdfFile;
workerThread->xdfFileName = xdfFile->getFileName();
workerThread->progressBar = ui->progressBar;
connect(workerThread, SIGNAL(errorMessageSignal(QString)), this, SLOT(errorDialog(QString)));
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
workerThread->start();
//xdfFile->saveAs(xdfFile->getFileName()),ui->progressBar);
}
void MainWindow::on_actionOpen_triggered()
{
QString xdfFileName = QFileDialog::getOpenFileName(this, tr("Open XDF File"), tr("*.xdf"));
loadfile(xdfFileName);
}
void MainWindow::loadfile(QString xdfFileName) {
if(!xdfFileName.isNull()) {
chunkNameList.reset(new StringList());
ui->listView->setModel(chunkNameList.get());
connect(ui->listView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(handleSelectionChanged(QItemSelection)));
xdfFile.reset(new XDFfile(xdfFileName));
OpenerThread *workerThread = new OpenerThread;
workerThread->xdfFile = xdfFile;
workerThread->chunkNameList = chunkNameList;
workerThread->progressBar = ui->progressBar;
connect(workerThread, SIGNAL(errorMessageSignal(QString)), this, SLOT(errorDialog(QString)));
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
workerThread->start();
this->setWindowTitle(xdfFileName);
}
}
void MainWindow::on_actionClose_triggered()
{
if(xdfFile) {
chunkNameList.reset();
xdfFile.get()->close();
xdfFile.reset();
ui->textEdit->setPlainText(QString(""));
}
}
void MainWindow::errorDialog(QString errorMessage) {
QMessageBox::critical(this, tr("Error"), errorMessage);
}