-
Notifications
You must be signed in to change notification settings - Fork 1
/
startwindow.cpp
79 lines (63 loc) · 2.08 KB
/
startwindow.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
#include "startwindow.h"
#include "ui_startwindow.h"
#include "dictionarywindow.h"
#include "settings.h"
#include "setupstudywindow.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QMessageBox>
#include <memory>
StartWindow::StartWindow(DataBase *_db, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::StartWindow)
, db(_db)
{
ui->setupUi(this);
}
StartWindow::~StartWindow() {
delete ui;
}
void StartWindow::on_studyButton_clicked() {
std::unique_ptr<SetupStudyWindow> setup_window_ptr(new SetupStudyWindow(db));
setup_window_ptr->exec();
}
void StartWindow::on_action_Options_triggered() {
Settings options_form;
options_form.Exec();
}
void StartWindow::on_actionEdit_dictionary_triggered() {
DictionaryWindow dictionary_form(db);
dictionary_form.setGeometry(QApplication::desktop()->screenGeometry());
dictionary_form.Exec();
}
void StartWindow::on_actionImport_triggered() {
QString csvFilePath = QFileDialog::getOpenFileName(this, tr("Load CSV"), ".", tr("Dictionary file (*.csv)"));
if (csvFilePath.size() == 0) {
return;
}
db->ImportDictionaryFromCSV(csvFilePath);
QMessageBox msgBox;
msgBox.setText(QString("CSV was imported to Dictionary"));
msgBox.exec();
}
void StartWindow::on_actionExport_triggered() {
QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH:mm");
QString defaultName = "./dictionary_" + currentTime + ".csv";
QString csvFilePath = QFileDialog::getSaveFileName(this, tr("Export Dictionary"), defaultName, tr("Dictionary (*.csv)"));
if (csvFilePath.size() == 0) {
return;
}
if (!csvFilePath.endsWith(".csv", Qt::CaseInsensitive)) {
csvFilePath += ".csv";
}
if (db->ExportDictionaryToCSV(csvFilePath)) {
QMessageBox msgBox;
msgBox.setText(QString("Dictionary export to file %1 failed!").arg(csvFilePath));
msgBox.exec();
return;
}
QMessageBox msgBox;
msgBox.setText(QString("Dictionary was exported to file:\n%1").arg(csvFilePath));
msgBox.exec();
}