Refactored JsonParser to not use roles (or their names) directly.

This commit is contained in:
2025-12-29 13:03:09 +01:00
parent 3610aa3841
commit acb8be5602
4 changed files with 38 additions and 21 deletions

View File

@ -13,10 +13,9 @@ static QHash<int, QByteArray> ROLE_NAMES = {{NameRole, "Name"},
{InfoRole, "Info"},
{AmountRole, "Amount"},
{FactorRole, "Factor"}};
// TODO ? use a data structure containing the type information of each column
// ([QString, QString, QString, int, double], {{NameRole, QString},...})
// instead of INT_COLUMNS,...
static QList<QString> INT_COLUMNS = {"Amount", "Factor"};
static QList<UserRoles> STRING_ROLES = {NameRole, DescriptionRole, InfoRole};
static QList<UserRoles> INT_ROLES = {AmountRole};
static QList<UserRoles> DOUBLE_ROLES = {FactorRole};
/// JSON keys
static const QString ITEM_KEY_STRING = "items";
@ -24,6 +23,7 @@ static const QString ITEM_KEY_STRING = "items";
/// file naming
static const QString ITEM_FILE_NAME = ITEM_KEY_STRING + ".json";
/// functions
static int GET_ROLE_FOR_COLUMN(const int column) {
switch (column) {
case 0: