Added type role and column & refactored the JsonParser in the process.
This commit is contained in:
@ -13,6 +13,7 @@ enum UserRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
DescriptionRole,
|
||||
InfoRole,
|
||||
TypeRole,
|
||||
AmountRole,
|
||||
FactorRole,
|
||||
/// Non user facing
|
||||
@ -24,16 +25,21 @@ enum UserRoles {
|
||||
|
||||
static UserRoles DEFAULT_ROLE = NameRole;
|
||||
// TODO ?rename USER_FACING_ROLES -> MAIN_ROLES ?
|
||||
static QList<UserRoles> USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole, AmountRole,
|
||||
FactorRole};
|
||||
static QList<UserRoles> USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole,
|
||||
TypeRole, AmountRole, FactorRole};
|
||||
static QHash<int, QByteArray> ROLE_NAMES = {
|
||||
{NameRole, "name"}, {DescriptionRole, "description"}, {InfoRole, "info"},
|
||||
{AmountRole, "amount"}, {FactorRole, "factor"}, {ToStringRole, "ToString"},
|
||||
{IdRole, "id"}};
|
||||
{NameRole, "name"}, {DescriptionRole, "description"},
|
||||
{InfoRole, "info"}, {TypeRole, "type"},
|
||||
{AmountRole, "amount"}, {FactorRole, "factor"},
|
||||
{ToStringRole, "ToString"}, {IdRole, "id"}};
|
||||
|
||||
static QList<UserRoles> STRING_ROLES = {NameRole, DescriptionRole, InfoRole, IdRole};
|
||||
static QList<UserRoles> INT_ROLES = {AmountRole};
|
||||
static QList<UserRoles> DOUBLE_ROLES = {FactorRole};
|
||||
|
||||
static const QList<UserRoles> TYPE_ROLES = {TypeRole};
|
||||
static const QList<QString> TYPES = {"A", "B", "C", ""};
|
||||
|
||||
/// JSON keys
|
||||
static const QString ITEMS_KEY_STRING = "items";
|
||||
static const QString ITEM_KEY_STRING = "item";
|
||||
@ -42,7 +48,7 @@ static const QString ITEM_KEY_STRING = "item";
|
||||
static const QString ITEMS_FILE_NAME = ITEMS_KEY_STRING + ".json";
|
||||
|
||||
/// functions
|
||||
static int GET_ROLE_FOR_COLUMN(const int column) {
|
||||
static UserRoles GET_ROLE_FOR_COLUMN(const int column) {
|
||||
switch (column) {
|
||||
case 0:
|
||||
return NameRole;
|
||||
@ -54,9 +60,12 @@ static int GET_ROLE_FOR_COLUMN(const int column) {
|
||||
return InfoRole;
|
||||
break;
|
||||
case 3:
|
||||
return AmountRole;
|
||||
return TypeRole;
|
||||
break;
|
||||
case 4:
|
||||
return AmountRole;
|
||||
break;
|
||||
case 5:
|
||||
return FactorRole;
|
||||
break;
|
||||
default:
|
||||
@ -65,6 +74,9 @@ static int GET_ROLE_FOR_COLUMN(const int column) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int GET_COLUMN_FOR_ROLE(const UserRoles role) { return USER_FACING_ROLES.indexOf(role); }
|
||||
|
||||
static QList<QString> GET_HEADER_NAMES() {
|
||||
QList<QString> result;
|
||||
for (const UserRoles& role : USER_FACING_ROLES) {
|
||||
|
||||
Reference in New Issue
Block a user