I have a model/view system where I am attempting to implement drag and drop. The actual drag and drop seems to be operating correctly... but the model::removeRows() function doesn't appear to be working as documented.
Here's an example... take the tree describe below
rootnode
|
|----A
|----B
|----C
rootnode
|
|----A
|----B
|----C
To copy to clipboard, switch view to plain text mode
I can drag C to go under B, but QtGui calls removeRows() with C as the parent, rather than rootnode (invalid QModelIndex).
the relevant code:
bool modelPlugins
::removeRows(int row,
int count,
const QModelIndex & parent
) {
int index(0);
modelPluginItem * parentItem;
if(row < 0 || row + count > rowCount(parent))
return false;
if(parent.isValid())
parentItem = static_cast<modelPluginItem *>(parent.internalPointer());
else
parentItem = rootItem;
beginRemoveRows(parent, row, row + count - 1);
for(; index < count; index++)
parentItem->nondestructiveremovechild(row);
endRemoveRows();
return true;
}
bool modelPlugins::removeRows(int row, int count, const QModelIndex & parent)
{
int index(0);
modelPluginItem * parentItem;
if(row < 0 || row + count > rowCount(parent))
return false;
if(parent.isValid())
parentItem = static_cast<modelPluginItem *>(parent.internalPointer());
else
parentItem = rootItem;
beginRemoveRows(parent, row, row + count - 1);
for(; index < count; index++)
parentItem->nondestructiveremovechild(row);
endRemoveRows();
return true;
}
To copy to clipboard, switch view to plain text mode
In my debugger, the modelPluginItems each have a unique id... the root node has ID 0, and C has ID 3... parentItem has ID 3. I can see this if Qt were to attempt to remove all children before removing the item, but it never tries to remove row 2 with an invalid parent index. How can I fix this?
Bookmarks