From dd269fdb847a38339688935db9ecd3ffef256ba2 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 10 May 2018 21:09:34 +0200 Subject: [PATCH] added test-data storage --- source/CMakeLists.txt | 1 + source/LogoTest.cpp | 16 ++++++++++++++++ source/testdata.cpp | 24 ++++++++++++++++++++++++ source/testdata.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 source/testdata.cpp create mode 100644 source/testdata.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index a28384f..7f74deb 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -12,6 +12,7 @@ qt5_wrap_ui(UI_HEADERS add_executable(${PROJECT_NAME} LogoTest.cpp + testdata.cpp mainwindow.cpp ${UI_HEADERS} ) diff --git a/source/LogoTest.cpp b/source/LogoTest.cpp index 30539a1..8b322ad 100644 --- a/source/LogoTest.cpp +++ b/source/LogoTest.cpp @@ -1,8 +1,24 @@ #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/testdata.cpp b/source/testdata.cpp new file mode 100644 index 0000000..61b7a11 --- /dev/null +++ b/source/testdata.cpp @@ -0,0 +1,24 @@ +#include "testdata.h" + +void TestData::Meta::write(QJsonObject &json) +{ + json["participant"] = m_participant; + json["instructor"] = m_instructor; +} + +void TestData::SubTest1::write(QJsonObject &json) +{ + json["type"] = "SubTest1"; +} + +void TestData::write(QJsonObject &json) +{ + QJsonObject metaData; + m_metaData.write(metaData); + json["Meta"] = metaData; + + QJsonObject subTest1Data; + m_subTest1Data.write(subTest1Data); + json["SubTest1"] = subTest1Data; +} + diff --git a/source/testdata.h b/source/testdata.h new file mode 100644 index 0000000..b44f569 --- /dev/null +++ b/source/testdata.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +class TestData +{ +private: + class Meta + { + private: + QString m_participant; + QString m_instructor; + + public: + void write(QJsonObject &json); + }; + + class SubTest1 + { + public: + void write(QJsonObject &json); + }; + +private: + Meta m_metaData; + SubTest1 m_subTest1Data; + +public: + void write(QJsonObject &json); +};