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::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()) {
|
if (parentIndex != QModelIndex()) {
|
||||||
qWarning() << "Removing of child rows is not supported yet!";
|
qWarning() << "Removing of child rows is not supported yet!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int endPosition = position + rows;
|
const int lastRow = firstRow + nRows - 1;
|
||||||
if (position < 0 || endPosition >= m_items.size()) {
|
if (firstRow < 0 || lastRow >= m_items.size()) {
|
||||||
qWarning() << "Trying to remove rows is out of bounds!";
|
qWarning() << "Trying to remove rows is out of bounds!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), position, position + rows - 1);
|
beginRemoveRows(QModelIndex(), firstRow, lastRow);
|
||||||
m_items.remove(position, rows);
|
m_items.remove(firstRow, nRows);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class TableModel : public QAbstractTableModel {
|
|||||||
public slots:
|
public slots:
|
||||||
// bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex())
|
// bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex())
|
||||||
// override;
|
// override;
|
||||||
bool removeRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex()) override;
|
bool removeRows(int firstRow, int nRows, const QModelIndex& parentIndex = QModelIndex()) override;
|
||||||
void appendItems(const QByteArray& jsonDoc);
|
void appendItems(const QByteArray& jsonDoc);
|
||||||
void insertItems(int startPosition, const QByteArray& jsonDoc, const QModelIndex& parentIndex);
|
void insertItems(int startPosition, const QByteArray& jsonDoc, const QModelIndex& parentIndex);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user