TableModel::setData can now be called for column 0 with different roles to edit. (Doesn't rely on Qt::EditRole and RoleForColumn in all cases)
This commit is contained in:
@ -104,10 +104,9 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation, int ro
|
||||
}
|
||||
|
||||
bool TableModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
||||
if (role == Qt::EditRole && checkIndex(index)) {
|
||||
const int column = index.column();
|
||||
const int roleForColumn = GET_ROLE_FOR_COLUMN(column);
|
||||
return setItemData(index, {{roleForColumn, value}});
|
||||
if (checkIndex(index)) {
|
||||
const int adjustedRole = getAppropriateRoleForIndex(index, role);
|
||||
return setItemData(index, {{adjustedRole, value}});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -329,6 +328,25 @@ bool TableModel::isEmptyValueEqualToZero(const int role) const {
|
||||
}
|
||||
}
|
||||
|
||||
int TableModel::getAppropriateRoleForIndex(const QModelIndex& index, const int role) const {
|
||||
/// cases:
|
||||
/// 1. Qt::DisplayRole, Qt::EditRole
|
||||
/// -> get role for column
|
||||
/// 2. other roles
|
||||
/// -> use role as given
|
||||
const int column = index.column();
|
||||
const int roleForColumn = GET_ROLE_FOR_COLUMN(column);
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
return roleForColumn;
|
||||
break;
|
||||
default:
|
||||
return role;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex TableModel::searchItemIndex(const ModelItemValues givenItemValues) const {
|
||||
// iterate over indexes to search item : see searchItem(...);
|
||||
// for (const shared_ptr<ModelItem>& item : m_items) {
|
||||
|
||||
Reference in New Issue
Block a user