
Originally Posted by
wysota
There is no standard way to modify items if the model doesn't allow it.
But if you allow (via flag) - there is. You can simply do this:
roleName = newValue
roleName = newValue
To copy to clipboard, switch view to plain text mode
And it will call setData and such.
Also, standard qml ListModel has append and remove methods.
So if removeRows is already virtual and in interface why isn't it "translated" into remove method of the model?
Btw, I have another question related to removing and c++ <-> qml interop.
I've written removeRows like this:
bool MyModel
::removeRows(int row,
int count,
const QModelIndex &parent
) {
if (count == 0 || mItems.isEmpty())
return true;
beginRemoveRows(parent, row, row + count - 1);
for (int i = row; i < row + count; ++i)
{
AbstractItem *item = mItems.takeAt(row);
delete item;
}
endRemoveRows();
return true;
}
bool MyModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (count == 0 || mItems.isEmpty())
return true;
beginRemoveRows(parent, row, row + count - 1);
for (int i = row; i < row + count; ++i)
{
AbstractItem *item = mItems.takeAt(row);
delete item;
}
endRemoveRows();
return true;
}
To copy to clipboard, switch view to plain text mode
But when I delete item it doesn't update view of my model! How to do this? I thought begin/endRemoveRows should be enough.
Bookmarks