106 lines
2.7 KiB
C
106 lines
2.7 KiB
C
#ifndef METADATA_H
|
|
#define METADATA_H
|
|
|
|
#include <QDebug>
|
|
#include <QHash>
|
|
#include <QList>
|
|
#include <QString>
|
|
|
|
// TODO add namespace
|
|
|
|
/// model data
|
|
enum UserRoles {
|
|
NameRole = Qt::UserRole + 1,
|
|
DescriptionRole,
|
|
InfoRole,
|
|
TypeRole,
|
|
AmountRole,
|
|
FactorRole,
|
|
/// Non user facing
|
|
IdRole,
|
|
/// read only roles
|
|
ToStringRole,
|
|
ToJsonRole
|
|
};
|
|
|
|
static UserRoles DEFAULT_ROLE = NameRole;
|
|
// TODO ?rename USER_FACING_ROLES -> MAIN_ROLES ?
|
|
static QList<UserRoles> USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole, TypeRole,
|
|
AmountRole, FactorRole, IdRole};
|
|
|
|
static QList<UserRoles> READ_ONLY_ROLES = {IdRole};
|
|
|
|
static QHash<int, QByteArray> ROLE_NAMES = {
|
|
{NameRole, "name"}, {DescriptionRole, "description"},
|
|
{InfoRole, "info"}, {TypeRole, "type"},
|
|
{AmountRole, "amount"}, {FactorRole, "factor"},
|
|
{ToStringRole, "ToString"}, {IdRole, "id"},
|
|
{Qt::DisplayRole, "display"}, {Qt::EditRole, "edit"}};
|
|
|
|
static QList<UserRoles> STRING_ROLES = {NameRole, DescriptionRole, InfoRole, IdRole};
|
|
static QList<UserRoles> INT_ROLES = {AmountRole};
|
|
static QList<UserRoles> DOUBLE_ROLES = {FactorRole};
|
|
static QList<UserRoles> NUMBER_ROLES = INT_ROLES + DOUBLE_ROLES;
|
|
|
|
static const QList<UserRoles> TYPE_ROLES = {TypeRole};
|
|
static const QList<QString> TYPES = {"A", "B", "C", ""};
|
|
|
|
static const QStringList OPTIONAL_CSV_HEADERS = {"description", "info"};
|
|
|
|
/// JSON keys
|
|
static const QString ITEMS_KEY_STRING = "items";
|
|
static const QString ITEM_KEY_STRING = "item";
|
|
|
|
/// file naming
|
|
static const QString ITEMS_FILE_NAME = ITEMS_KEY_STRING + ".json";
|
|
|
|
/// functions
|
|
static UserRoles GET_ROLE_FOR_COLUMN(const int column) {
|
|
switch (column) {
|
|
case 0:
|
|
return NameRole;
|
|
break;
|
|
case 1:
|
|
return DescriptionRole;
|
|
break;
|
|
case 2:
|
|
return InfoRole;
|
|
break;
|
|
case 3:
|
|
return TypeRole;
|
|
break;
|
|
case 4:
|
|
return AmountRole;
|
|
break;
|
|
case 5:
|
|
return FactorRole;
|
|
break;
|
|
case 6:
|
|
return IdRole;
|
|
break;
|
|
default:
|
|
qWarning() << QString("No role found for column %1! Returning 'NameRole'...").arg(column);
|
|
return NameRole;
|
|
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) {
|
|
const QString headerName = ROLE_NAMES.value(role);
|
|
result.append(headerName);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static QString GET_HEADER_FOR_COLUMN(const int column) {
|
|
const UserRoles role = GET_ROLE_FOR_COLUMN(column);
|
|
const QString headerName = ROLE_NAMES.value(role);
|
|
return headerName;
|
|
}
|
|
|
|
#endif // METADATA_H
|