Bugfix: Last row could not be removed due to miscalculations of the bounds.

This commit is contained in:
2025-12-09 09:33:46 +01:00
parent 169d8f9f1e
commit e21c899aac
2 changed files with 6 additions and 6 deletions

View File

@ -88,20 +88,20 @@ bool TableModel::setData(const QModelIndex& index, const QVariant& value, int ro
// bool TableModel::setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) {}
bool TableModel::removeRows(int position, int rows, const QModelIndex& parentIndex) {
bool TableModel::removeRows(int firstRow, int nRows, const QModelIndex& parentIndex) {
if (parentIndex != QModelIndex()) {
qWarning() << "Removing of child rows is not supported yet!";
return false;
}
const int endPosition = position + rows;
if (position < 0 || endPosition >= m_items.size()) {
const int lastRow = firstRow + nRows - 1;
if (firstRow < 0 || lastRow >= m_items.size()) {
qWarning() << "Trying to remove rows is out of bounds!";
return false;
}
beginRemoveRows(QModelIndex(), position, position + rows - 1);
m_items.remove(position, rows);
beginRemoveRows(QModelIndex(), firstRow, lastRow);
m_items.remove(firstRow, nRows);
endRemoveRows();
return true;