added test-data storage

pull/12/head
mandlm 2018-05-10 21:09:34 +02:00
parent 0e19343a22
commit dd269fdb84
4 changed files with 72 additions and 0 deletions

View File

@ -12,6 +12,7 @@ qt5_wrap_ui(UI_HEADERS
add_executable(${PROJECT_NAME}
LogoTest.cpp
testdata.cpp
mainwindow.cpp
${UI_HEADERS}
)

View File

@ -1,8 +1,24 @@
#include "mainwindow.h"
#include <QApplication>
#include "testdata.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
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();

24
source/testdata.cpp Normal file
View File

@ -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;
}

31
source/testdata.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include <QJsonObject>
#include <QString>
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);
};