added serialization to/from json
This commit is contained in:
parent
45923ef8a3
commit
b8fdf26628
2 changed files with 46 additions and 0 deletions
|
@ -39,3 +39,45 @@ QVariant MetaDataModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void MetaDataModel::write(QJsonObject &json)
|
||||
{
|
||||
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 MetaDataModel::read(const QJsonObject &json)
|
||||
{
|
||||
const auto &participant = json["participant name"];
|
||||
if (participant.isString())
|
||||
{
|
||||
m_participant = participant.toString();
|
||||
}
|
||||
|
||||
const auto &instructor = json["instructor name"];
|
||||
if (instructor.isString())
|
||||
{
|
||||
m_instructor = instructor.toString();
|
||||
}
|
||||
|
||||
const auto &dateOfBirth = json["date of birth"];
|
||||
if (dateOfBirth.isString())
|
||||
{
|
||||
m_dateOfBirth.fromString(dateOfBirth.toString());
|
||||
}
|
||||
|
||||
const auto &dateOfTest = json["date of test"];
|
||||
if (dateOfTest.isString())
|
||||
{
|
||||
m_dateOfTest.fromString(dateOfTest.toString());
|
||||
}
|
||||
|
||||
const auto &remarks = json["remarks"];
|
||||
if (remarks.isString())
|
||||
{
|
||||
m_remarks = remarks.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <QAbstractTableModel>
|
||||
#include <QString>
|
||||
#include <QDate>
|
||||
#include <QJsonObject>
|
||||
|
||||
class MetaDataModel : public QAbstractTableModel
|
||||
{
|
||||
|
@ -21,4 +22,7 @@ public:
|
|||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(
|
||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
void write(QJsonObject &json);
|
||||
void read(const QJsonObject &json);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue