Items can be deleted from the model.

This commit is contained in:
2025-12-08 14:50:13 +01:00
parent d45b1098f9
commit 169d8f9f1e
2 changed files with 22 additions and 0 deletions

View File

@ -88,6 +88,25 @@ 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) {
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()) {
qWarning() << "Trying to remove rows is out of bounds!";
return false;
}
beginRemoveRows(QModelIndex(), position, position + rows - 1);
m_items.remove(position, rows);
endRemoveRows();
return true;
}
void TableModel::appendItems(const QByteArray& jsonDoc) { insertItems(-1, jsonDoc, QModelIndex()); }
void TableModel::insertItems(int startPosition,

View File

@ -29,6 +29,9 @@ class TableModel : public QAbstractTableModel {
// bool setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) override;
public slots:
// bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex())
// override;
bool removeRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex()) override;
void appendItems(const QByteArray& jsonDoc);
void insertItems(int startPosition, const QByteArray& jsonDoc, const QModelIndex& parentIndex);