From dd28d94043e75115b68e1c27a3ac1d870521abcb Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 15 May 2018 13:11:40 +0200 Subject: [PATCH] added save as action to menu and toolbar, extended testdata --- source/CMakeLists.txt | 4 ++++ source/LogoTest.cpp | 16 ---------------- source/mainwindow.cpp | 31 +++++++++++++++++++++++++++++-- source/mainwindow.h | 15 +++++++++------ source/mainwindow.ui | 27 +++++++++++++++++++++++++++ source/testdata.cpp | 7 +++++-- source/testdata.h | 4 ++++ 7 files changed, 78 insertions(+), 26 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 7f74deb..beaa147 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -17,6 +17,10 @@ add_executable(${PROJECT_NAME} ${UI_HEADERS} ) +set_target_properties(${PROJECT_NAME} + PROPERTIES CXX_STANDARD 14 +) + target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} diff --git a/source/LogoTest.cpp b/source/LogoTest.cpp index 8b322ad..30539a1 100644 --- a/source/LogoTest.cpp +++ b/source/LogoTest.cpp @@ -1,24 +1,8 @@ #include "mainwindow.h" #include -#include "testdata.h" -#include -#include -#include - int main(int argc, char **argv) { - TestData testData; - QJsonObject saveData; - testData.write(saveData); - - QJsonDocument saveDoc(saveData); - - QFile saveFile("testdata.json"); - saveFile.open(QFile::WriteOnly); - saveFile.write(saveDoc.toJson()); - saveFile.close(); - QApplication app(argc, argv); MainWindow mainWindow; mainWindow.show(); diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index c41b6fd..ba3cf3f 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -1,11 +1,20 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "testdata.h" +#include +#include +#include +#include + + MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) + : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + + ui->actionSave_as->setIcon(QIcon::fromTheme("document-save-as", QIcon("/usr/share/gtk-doc/html/gtk2/document-save-as.png"))); + connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs())); } MainWindow::~MainWindow() @@ -13,4 +22,22 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::saveAs() +{ + QString filename = QFileDialog::getSaveFileName(this); + if (filename.isEmpty()) + { + return; + } + TestData testData; + QJsonObject saveData; + testData.write(saveData); + + QJsonDocument saveDoc(saveData); + + QFile saveFile(filename); + saveFile.open(QFile::WriteOnly); + saveFile.write(saveDoc.toJson()); + saveFile.close(); +} diff --git a/source/mainwindow.h b/source/mainwindow.h index 2847620..a60c782 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -3,17 +3,20 @@ #include namespace Ui { - class MainWindow; +class MainWindow; }; class MainWindow : public QMainWindow { Q_OBJECT - public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); - private: - Ui::MainWindow *ui; +public slots: + void saveAs(); + +private: + Ui::MainWindow *ui; }; diff --git a/source/mainwindow.ui b/source/mainwindow.ui index 8154e13..14a18a9 100644 --- a/source/mainwindow.ui +++ b/source/mainwindow.ui @@ -115,8 +115,35 @@ 19 + + + &File + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + Save as... + + + Save as... + + diff --git a/source/testdata.cpp b/source/testdata.cpp index 61b7a11..8068003 100644 --- a/source/testdata.cpp +++ b/source/testdata.cpp @@ -2,8 +2,11 @@ void TestData::Meta::write(QJsonObject &json) { - json["participant"] = m_participant; - json["instructor"] = m_instructor; + json["participant name"] = m_participant; + json["instructor name"] = m_instructor; + json["date of birth"] = m_dateOfBirth.toString(Qt::TextDate); + json["date of test"] = m_dateOfTest.toString(Qt::TextDate); + json["remarks"] = m_remarks; } void TestData::SubTest1::write(QJsonObject &json) diff --git a/source/testdata.h b/source/testdata.h index b44f569..77eb58f 100644 --- a/source/testdata.h +++ b/source/testdata.h @@ -2,6 +2,7 @@ #include #include +#include class TestData { @@ -11,6 +12,9 @@ private: private: QString m_participant; QString m_instructor; + QDate m_dateOfBirth; + QDate m_dateOfTest; + QString m_remarks; public: void write(QJsonObject &json);