save genus date
This commit is contained in:
parent
bf449dd53f
commit
a9718389e8
@ -3,6 +3,7 @@
|
||||
DataModel::DataModel(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_metaData(this)
|
||||
, m_genus(this)
|
||||
{
|
||||
}
|
||||
|
||||
@ -11,6 +12,10 @@ void DataModel::write(QJsonObject &target) const
|
||||
QJsonObject metaData;
|
||||
m_metaData.write(metaData);
|
||||
target["MetaData"] = metaData;
|
||||
|
||||
QJsonObject genus;
|
||||
m_genus.write(genus);
|
||||
target["Genus"] = genus;
|
||||
}
|
||||
|
||||
void DataModel::read(const QJsonObject &source)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "MetaData/MetaDataModel.h"
|
||||
#include "Genus/GenusModel.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
@ -10,6 +11,7 @@ class DataModel : public QObject
|
||||
|
||||
public:
|
||||
MetaDataModel m_metaData;
|
||||
GenusModel m_genus;
|
||||
|
||||
public:
|
||||
DataModel(QObject *parent);
|
||||
|
@ -2,6 +2,15 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
void CheckableItems::write(QJsonObject &json) const
|
||||
{
|
||||
for (const auto &pair : *this)
|
||||
{
|
||||
json[pair.second.getText().c_str()] =
|
||||
pair.second.isChecked();
|
||||
}
|
||||
}
|
||||
|
||||
GenusModel::GenusModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
@ -104,6 +113,17 @@ QVariant GenusModel::headerData(
|
||||
|
||||
void GenusModel::write(QJsonObject &json) const
|
||||
{
|
||||
QJsonObject tiere;
|
||||
m_tiere.write(tiere);
|
||||
json["Tiere"] = tiere;
|
||||
|
||||
QJsonObject futter;
|
||||
m_futter.write(futter);
|
||||
json["Futter"] = futter;
|
||||
|
||||
QJsonObject zirkus;
|
||||
m_zirkus.write(zirkus);
|
||||
json["Zirkus"] = zirkus;
|
||||
}
|
||||
|
||||
void GenusModel::read(const QJsonObject &json)
|
||||
@ -125,7 +145,7 @@ bool GenusModel::isValidIndex(const QModelIndex &index) const
|
||||
}
|
||||
}
|
||||
|
||||
GenusModel::CheckableItems &GenusModel::getItems(const QModelIndex &index)
|
||||
CheckableItems &GenusModel::getItems(const QModelIndex &index)
|
||||
{
|
||||
switch (index.row())
|
||||
{
|
||||
@ -142,8 +162,7 @@ GenusModel::CheckableItems &GenusModel::getItems(const QModelIndex &index)
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
const GenusModel::CheckableItems &GenusModel::getItems(
|
||||
const QModelIndex &index) const
|
||||
const CheckableItems &GenusModel::getItems(const QModelIndex &index) const
|
||||
{
|
||||
switch (index.row())
|
||||
{
|
||||
|
@ -30,16 +30,25 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <map>
|
||||
|
||||
class CheckableItems : public std::map<size_t, CheckableItem>
|
||||
{
|
||||
public:
|
||||
using std::map<size_t, CheckableItem>::map;
|
||||
|
||||
void write(QJsonObject &json) const;
|
||||
};
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class GenusModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using CheckableItems = std::map<size_t, CheckableItem>;
|
||||
|
||||
CheckableItems m_tiere = {{0, {"Tiger"}}, {1, {"Bär"}}, {2, {"Katze"}},
|
||||
{3, {"Pferd"}}, {4, {"Gans"}}, {5, {"Elefant"}}, {6, {"Katze"}},
|
||||
{7, {"Hund"}}};
|
||||
|
Reference in New Issue
Block a user