PDA

View Full Version : Can you reverse the insertRow/removeRow order when D&D in the same view?



Jeffb
17th April 2012, 15:00
It seems that when dropping and dragging within a QTreeView, the natural order is to insert the moved node under it's new parent node first (using beingInsertRows() and endInsertRows() )
and then Qt automatically calls your model's implementation of removeRows() to remove the node from its previous parent node (using beginRemoveRows() and endRemoveRows() ).
It is also possible to not implement removeRows() in your model but rather create another method that you call manually to remove the row (still using beginRemoveRows() and endRemoveRows() ).

Either of these methods becomes problematic for me because my underlying datastructure can only have one of the same node object in it at one time. Therefore I can't insert the same node in a new position and remove it from the old position in my datastructure..

What would be easier for me is to remove the dragged node first and then reinsert it into the datastructure.

Before I go to the trouble of implementing this, does anyone know if Qt has a problem with removing the dragged row first and then inserting it rather than the other way around.

Thanks
Jeff

wysota
17th April 2012, 16:53
I don't think you can reverse the order easily. Maybe a solution would be to put the new node on some kind of waiting list (so that you don't ruin your main structure) and when removeRows is called, remove the node and put the waiting node into the structure. You can use a timer to reject or accept the new node if removeRows doesn't follow the insertion. Other than that, you can reimplement dropMimeData() in your model.