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:
2025-12-29 10:30:12 +01:00
parent b2f01a7990
commit 0c3d711513
9 changed files with 78 additions and 77 deletions

View File

@ -2,6 +2,7 @@
#include <QDebug>
#include "../metadata.h"
#include "../tablemodel.h"
EditItemCommand::EditItemCommand(TableModel* model,
@ -20,23 +21,23 @@ EditItemCommand::EditItemCommand(TableModel* model,
const QVariant value = changedValues.first();
QString roleName = model->roleNames().value(role);
switch (role) {
case TableModel::NameRole:
case TableModel::DescriptionRole:
case TableModel::InfoRole:
case TableModel::AmountRole:
case TableModel::FactorRole:
case NameRole:
case DescriptionRole:
case InfoRole:
case AmountRole:
case FactorRole:
commandText = QString("Setting '%1' of item '%2' to '%3'")
.arg(roleName)
.arg(index.data(TableModel::NameRole).toString())
.arg(index.data(NameRole).toString())
.arg(value.toString());
break;
default:
commandText = QString("Edit item '%1'").arg(index.data(TableModel::NameRole).toString());
commandText = QString("Edit item '%1'").arg(index.data(NameRole).toString());
break;
}
} else {
qDebug() << "More than one value to change. Using a generic command text...";
commandText = QString("Edit item '%1'").arg(index.data(TableModel::NameRole).toString());
commandText = QString("Edit item '%1'").arg(index.data(NameRole).toString());
}
setText(commandText);

View File

@ -8,6 +8,9 @@ class TableModel;
class EditItemCommand : public QUndoCommand {
public:
// TODO don't use simple pointer to model
/// Using simple pointer to model because there was a crash when closing the application with an
/// unclean undo stack
EditItemCommand(TableModel* model,
const QModelIndex& index,
QMap<int, QVariant>& changedValues,

View File

@ -2,6 +2,7 @@
#include <QDebug>
#include "../metadata.h"
#include "../tablemodel.h"
RemoveRowsCommand::RemoveRowsCommand(TableModel* model,
@ -22,11 +23,11 @@ RemoveRowsCommand::RemoveRowsCommand(TableModel* model,
// TODO use a (static) function "getRoleValueHash" or something
QHash<int, QVariant> values;
values[TableModel::NameRole] = m_tableModel->data(index, TableModel::NameRole);
values[TableModel::DescriptionRole] = m_tableModel->data(index, TableModel::DescriptionRole);
values[TableModel::InfoRole] = m_tableModel->data(index, TableModel::InfoRole);
values[TableModel::AmountRole] = m_tableModel->data(index, TableModel::AmountRole);
values[TableModel::FactorRole] = m_tableModel->data(index, TableModel::FactorRole);
values[NameRole] = m_tableModel->data(index, NameRole);
values[DescriptionRole] = m_tableModel->data(index, DescriptionRole);
values[InfoRole] = m_tableModel->data(index, InfoRole);
values[AmountRole] = m_tableModel->data(index, AmountRole);
values[FactorRole] = m_tableModel->data(index, FactorRole);
m_valueList.append(values);
}