Results 1 to 2 of 2

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

  1. #1
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Can you reverse the insertRow/removeRow order when D&D in the same view?

    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

  2. The following user says thank you to Jeffb for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can you reverse the insertRow/removeRow order when D&D in the same view?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following 2 users say thank you to wysota for this useful post:

    Jeffb (18th April 2012)

Similar Threads

  1. Replies: 0
    Last Post: 28th November 2011, 20:03
  2. QTableWidget/RemoveRow
    By navi1084 in forum Qt Programming
    Replies: 0
    Last Post: 28th November 2008, 12:01
  3. RemoveRow problem
    By nategoofs in forum Qt Programming
    Replies: 4
    Last Post: 18th August 2007, 14:11
  4. Reverse Order on QStringList slow...?
    By patrik08 in forum Qt Programming
    Replies: 24
    Last Post: 21st February 2007, 10:32
  5. Drag and drop items in view to sort order
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 20:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.