Added a ToStringRole to summarize the model items (for tool tip and QR code).
This commit is contained in:
@ -7,7 +7,15 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
/// model data
|
/// model data
|
||||||
enum UserRoles { NameRole = Qt::UserRole + 1, DescriptionRole, InfoRole, AmountRole, FactorRole };
|
enum UserRoles {
|
||||||
|
NameRole = Qt::UserRole + 1,
|
||||||
|
DescriptionRole,
|
||||||
|
InfoRole,
|
||||||
|
AmountRole,
|
||||||
|
FactorRole,
|
||||||
|
/// helper roles
|
||||||
|
ToStringRole
|
||||||
|
};
|
||||||
static UserRoles DEFAULT_ROLE = NameRole;
|
static UserRoles DEFAULT_ROLE = NameRole;
|
||||||
static QList<UserRoles> USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole, AmountRole,
|
static QList<UserRoles> USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole, AmountRole,
|
||||||
FactorRole};
|
FactorRole};
|
||||||
|
|||||||
@ -44,6 +44,20 @@ bool ModelItem::setItemData(const QMap<int, QVariant>& changedValues) {
|
|||||||
return valueChanged;
|
return valueChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ModelItem::toString() const {
|
||||||
|
QString result;
|
||||||
|
|
||||||
|
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);
|
||||||
|
// result.append(value.toString());
|
||||||
|
result.append(QString("%1: %2\n").arg(roleName, data(role).toString()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject ModelItem::toJsonObject() const {
|
QJsonObject ModelItem::toJsonObject() const {
|
||||||
QJsonObject itemObject;
|
QJsonObject itemObject;
|
||||||
// TODO add UUID and dates (entry, modification, end)
|
// TODO add UUID and dates (entry, modification, end)
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class ModelItem {
|
|||||||
// TODO change return value to list of changed roles
|
// TODO change return value to list of changed roles
|
||||||
bool setItemData(const QMap<int, QVariant>& changedValues);
|
bool setItemData(const QMap<int, QVariant>& changedValues);
|
||||||
|
|
||||||
// QString toString() const;
|
QString toString() const;
|
||||||
QJsonObject toJsonObject() const;
|
QJsonObject toJsonObject() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -76,6 +76,8 @@ QVariant TableModel::data(const QModelIndex& index, int role) const {
|
|||||||
case AmountRole:
|
case AmountRole:
|
||||||
case FactorRole:
|
case FactorRole:
|
||||||
return m_items.at(row)->data(role);
|
return m_items.at(row)->data(role);
|
||||||
|
case ToStringRole:
|
||||||
|
return m_items.at(row)->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|||||||
Reference in New Issue
Block a user