Moved the model meta data for roles and columns into "model/metadata.h" to gather meta data like this in one central place.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "../model/tablemodel.h"
|
||||
#include "../model/metadata.h"
|
||||
|
||||
QList<QHash<int, QVariant>> JsonParser::toItemValuesList(const QByteArray& jsonData,
|
||||
const QString& objectName) {
|
||||
@ -27,16 +27,11 @@ QHash<int, QVariant> JsonParser::jsonObjectToItemValues(const QJsonObject& itemJ
|
||||
QHash<int, QVariant> values;
|
||||
|
||||
// TODO make this more generic (by reading from model meta data)
|
||||
values[TableModel::NameRole] =
|
||||
itemJsonObject[TableModel::ROLE_NAMES.value(TableModel::NameRole)].toString();
|
||||
values[TableModel::DescriptionRole] =
|
||||
itemJsonObject[TableModel::ROLE_NAMES.value(TableModel::DescriptionRole)].toString();
|
||||
values[TableModel::InfoRole] =
|
||||
itemJsonObject[TableModel::ROLE_NAMES.value(TableModel::InfoRole)].toString();
|
||||
values[TableModel::AmountRole] =
|
||||
itemJsonObject[TableModel::ROLE_NAMES.value(TableModel::AmountRole)].toInt();
|
||||
values[TableModel::FactorRole] =
|
||||
itemJsonObject[TableModel::ROLE_NAMES.value(TableModel::FactorRole)].toDouble();
|
||||
values[NameRole] = itemJsonObject[ROLE_NAMES.value(NameRole)].toString();
|
||||
values[DescriptionRole] = itemJsonObject[ROLE_NAMES.value(DescriptionRole)].toString();
|
||||
values[InfoRole] = itemJsonObject[ROLE_NAMES.value(InfoRole)].toString();
|
||||
values[AmountRole] = itemJsonObject[ROLE_NAMES.value(AmountRole)].toInt();
|
||||
values[FactorRole] = itemJsonObject[ROLE_NAMES.value(FactorRole)].toDouble();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user