Iterating over USER_FACING_ROLES to get all the item values when parsing and keeping them in edit and remove commands. Instead of using each role explicitly.
This commit is contained in:
@ -46,19 +46,22 @@ bool ModelItem::setItemData(const QMap<int, QVariant>& changedValues) {
|
||||
|
||||
QJsonObject ModelItem::toJsonObject() const {
|
||||
QJsonObject itemObject;
|
||||
// itemObject.insert("uuid", m_uuid.toString());
|
||||
// itemObject.insert("entryDateUTC", m_entryDateUTC.toString(Qt::ISODate));
|
||||
itemObject.insert(ROLE_NAMES.value(NameRole), data(NameRole).toString());
|
||||
itemObject.insert(ROLE_NAMES.value(DescriptionRole), data(DescriptionRole).toString());
|
||||
itemObject.insert(ROLE_NAMES.value(InfoRole), data(InfoRole).toString());
|
||||
itemObject.insert(ROLE_NAMES.value(AmountRole), data(AmountRole).toInt());
|
||||
itemObject.insert(ROLE_NAMES.value(FactorRole), data(FactorRole).toReal());
|
||||
// TODO add UUID and dates (entry, modification, end)
|
||||
|
||||
// if (m_modifiedDateUTC.isValid()) {
|
||||
// itemObject.insert("modifiedDateUTC", m_modifiedDateUTC.toString(Qt::ISODate));
|
||||
// }
|
||||
// if (m_endDateUTC.isValid()) {
|
||||
// itemObject.insert("endDateUTC", m_endDateUTC.toString(Qt::ISODate));
|
||||
// }
|
||||
QListIterator<UserRoles> i(USER_FACING_ROLES);
|
||||
while (i.hasNext()) {
|
||||
const UserRoles role = i.next();
|
||||
const QString roleName = ROLE_NAMES.value(role);
|
||||
const QVariant value = data(role);
|
||||
if (STRING_ROLES.contains(role)) {
|
||||
itemObject.insert(roleName, value.toString());
|
||||
} else if (INT_ROLES.contains(role)) {
|
||||
itemObject.insert(roleName, value.toInt());
|
||||
} else if (DOUBLE_ROLES.contains(role)) {
|
||||
itemObject.insert(roleName, value.toDouble());
|
||||
} else {
|
||||
qCritical() << QString("Cant find data type of role %1!!!").arg(role);
|
||||
}
|
||||
}
|
||||
return itemObject;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user