Bugfix: Last row could not be removed due to miscalculations of the bounds.
This commit is contained in:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user