Iterating over USER_FACING_ROLES to get all the item values when parsing and keeping them in edit and remove commands. Instead of using each role explicitly.
This commit is contained in:
@ -20,24 +20,19 @@ EditItemCommand::EditItemCommand(TableModel* model,
|
||||
const int role = changedValues.firstKey();
|
||||
const QVariant value = changedValues.first();
|
||||
QString roleName = model->roleNames().value(role);
|
||||
switch (role) {
|
||||
case NameRole:
|
||||
case DescriptionRole:
|
||||
case InfoRole:
|
||||
case AmountRole:
|
||||
case FactorRole:
|
||||
commandText = QString("Setting '%1' of item '%2' to '%3'")
|
||||
.arg(roleName)
|
||||
.arg(index.data(NameRole).toString())
|
||||
.arg(value.toString());
|
||||
break;
|
||||
default:
|
||||
commandText = QString("Edit item '%1'").arg(index.data(NameRole).toString());
|
||||
break;
|
||||
|
||||
if (USER_FACING_ROLES.contains(role)) {
|
||||
commandText = QString("Setting '%1' of item '%2' to '%3'")
|
||||
.arg(roleName)
|
||||
.arg(index.data(DEFAULT_ROLE).toString())
|
||||
.arg(value.toString());
|
||||
} else {
|
||||
qWarning() << "Role didn't match! Using a generic command text...";
|
||||
commandText = QString("Edit item '%1'").arg(index.data(DEFAULT_ROLE).toString());
|
||||
}
|
||||
} else {
|
||||
qDebug() << "More than one value to change. Using a generic command text...";
|
||||
commandText = QString("Edit item '%1'").arg(index.data(NameRole).toString());
|
||||
commandText = QString("Edit item '%1'").arg(index.data(DEFAULT_ROLE).toString());
|
||||
}
|
||||
setText(commandText);
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "../metadata.h"
|
||||
#include "../tablemodel.h"
|
||||
|
||||
RemoveRowsCommand::RemoveRowsCommand(TableModel* model,
|
||||
@ -21,13 +20,7 @@ RemoveRowsCommand::RemoveRowsCommand(TableModel* model,
|
||||
const int rowPosition = startRow + row;
|
||||
QModelIndex index = m_tableModel->index(rowPosition, 0);
|
||||
|
||||
// TODO use a (static) function "getRoleValueHash" or something
|
||||
QHash<int, QVariant> values;
|
||||
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);
|
||||
QHash<int, QVariant> values = m_tableModel->getItemValues(index);
|
||||
|
||||
m_valueList.append(values);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user