Items can be deleted from the model.
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user