Hi all,
I'm using QML treeview with model sub-classed from QAbstractItemModel.
I'm facing this issue that model indexes aren't updated when user removes a row.
Here's the code
bool TreeModel
::removeRows(int row,
int count,
const QModelIndex &parent
) {
TreeItem *parentItem = getItem(parent);
if(parentItem == null) return false;
bool success = false;
if (count > 0)
{
beginRemoveRows(parent, row, row + count - 1);
success = parentItem->removeChildren(row, count);
endRemoveRows();
}
return success;
}
bool TreeItem::removeChildren(int position, int count)
{
if (position < 0 || position + count > children_.size())
return false;
for (int row = 0; row < count; ++row)
delete children_.takeAt(position);
return true;
}
bool TreeModel::removeRows(int row, int count, const QModelIndex &parent)
{
TreeItem *parentItem = getItem(parent);
if(parentItem == null) return false;
bool success = false;
if (count > 0)
{
beginRemoveRows(parent, row, row + count - 1);
success = parentItem->removeChildren(row, count);
endRemoveRows();
}
return success;
}
bool TreeItem::removeChildren(int position, int count)
{
if (position < 0 || position + count > children_.size())
return false;
for (int row = 0; row < count; ++row)
delete children_.takeAt(position);
return true;
}
To copy to clipboard, switch view to plain text mode
Could you point what am I missing?
Bookmarks