Items can be saved to JSON file "items.json" (in standard location).

This commit is contained in:
2025-12-23 10:14:13 +01:00
parent 2c3d49db30
commit 0e1a0d4959
9 changed files with 119 additions and 0 deletions

View File

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