Items can be saved to JSON file "items.json" (in standard location).
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
#include "modelitem.h"
|
||||
|
||||
#include "tablemodel.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
ModelItem::ModelItem(const QHash<int, QVariant> values)
|
||||
: m_values(values) {}
|
||||
|
||||
@ -38,3 +43,27 @@ bool ModelItem::setItemData(const QMap<int, QVariant>& changedValues) {
|
||||
|
||||
return valueChanged;
|
||||
}
|
||||
|
||||
QJsonObject ModelItem::toJsonObject() const {
|
||||
QJsonObject itemObject;
|
||||
// itemObject.insert("uuid", m_uuid.toString());
|
||||
// itemObject.insert("entryDateUTC", m_entryDateUTC.toString(Qt::ISODate));
|
||||
itemObject.insert(TableModel::ROLE_NAMES.value(TableModel::NameRole),
|
||||
data(TableModel::NameRole).toString());
|
||||
itemObject.insert(TableModel::ROLE_NAMES.value(TableModel::DescriptionRole),
|
||||
data(TableModel::DescriptionRole).toString());
|
||||
itemObject.insert(TableModel::ROLE_NAMES.value(TableModel::InfoRole),
|
||||
data(TableModel::InfoRole).toString());
|
||||
itemObject.insert(TableModel::ROLE_NAMES.value(TableModel::AmountRole),
|
||||
data(TableModel::AmountRole).toInt());
|
||||
itemObject.insert(TableModel::ROLE_NAMES.value(TableModel::FactorRole),
|
||||
data(TableModel::FactorRole).toReal());
|
||||
|
||||
// if (m_modifiedDateUTC.isValid()) {
|
||||
// itemObject.insert("modifiedDateUTC", m_modifiedDateUTC.toString(Qt::ISODate));
|
||||
// }
|
||||
// if (m_endDateUTC.isValid()) {
|
||||
// itemObject.insert("endDateUTC", m_endDateUTC.toString(Qt::ISODate));
|
||||
// }
|
||||
return itemObject;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user