Results 1 to 6 of 6

Thread: Drag and Drop for tree model

  1. #1
    Join Date
    Nov 2010
    Posts
    22
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Drag and Drop for tree model

    Hi!

    I have a custom tree view with drag/drop support.

    Every node in the tree can have different types and descendants, hence some drops might be rejected.

    The whole thing is already working because I reject invalid descendants within the setData() function of the model. However I would like to provide immediate visual feedback to the user changing the cursor drop icon.

    The first solution I thought was implementing a custom dragMoveEvent() within the view which could retrieve constantly the cursor position and issue an Qt::IgnoreAction or Qt::CopyAction depending on the validity of the insertion. I do not like this because I would have to implement some model logic within the viewer. Since I have many node types I do not wish to define a new mimetype for everyone.

    I am convinced there must be a more elegant solution based on MVC. Any ideas?

  2. #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: Drag and Drop for tree model

    I didn't quite get that part about multiple mime types. Could you explain? dragMoveEvent() is in general the proper way to go but I'm afraid you misinterpreted something about how it should work.
    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.


  3. #3
    Join Date
    Nov 2010
    Posts
    22
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drag and Drop for tree model

    I would like to come up with a design where the model decides which objects can be dropped.

    I know that the dragMoveEvent() solution will work, but this way I will have to code into the View the logic for valid/invalid node combinations. I believe it would be "more MVC" if such logic could be coded into the Model

  4. #4
    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: Drag and Drop for tree model

    The view can ask the model for a list of mime-types or whatever else data you wish to decide upon that can be dropped on a particular model index through a custom role.
    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.


  5. #5
    Join Date
    Nov 2010
    Posts
    22
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drag and Drop for tree model

    thanks! However my tree has something like 400 node types. In every other case having just one mimetype is OK. I thought it would be too much work definining one mimetype for every case.

    Furthermore, as far as I know the view asks such list of mime-types only once, when drag mode is entered. The dragMoveEvent() can acept/deny drops depending on the node the cursor is floating.

    Could I replicate the same functionality from the model in a more MVC way? I want the model to acept/reject a node drop (before drop happens) depending on the item the cursor is covering. With dragMoveEvent() the view takes that decision. Even if the mimeTypes() of my model supports 400 types, these should be different depending on where within the view the cursor is floating.

    So far I have implemented a static member dropCompatible() in my model which I call from the dragMoveEvent(). In that case the model can decide if the dragged node can be droped into the selected one. But in such case my view can only support my model :-(

    thanks for all!

  6. #6
    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: Drag and Drop for tree model

    Quote Originally Posted by frank100 View Post
    thanks! However my tree has something like 400 node types. In every other case having just one mimetype is OK. I thought it would be too much work definining one mimetype for every case.
    You don't have to use mime-types. And actually you probably shouldn't. A trivial solution to the problem is introduction of TypeRole and AcceptedTypeRole roles. FIrst would say "my type is T" and the second would say "I accept drags of type X, Y and Z". Then it's just a matter of checking whether T in {X, Y, Z} and accepting or rejecting the drop.
    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.


  7. The following user says thank you to wysota for this useful post:

    frank100 (3rd February 2011)

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 20:36
  2. Replies: 1
    Last Post: 2nd August 2010, 20:16
  3. Replies: 1
    Last Post: 18th November 2008, 06:57
  4. Drag and drop between model views
    By larry104 in forum Qt Programming
    Replies: 20
    Last Post: 19th January 2008, 16:09
  5. Model Drag'n'Drop - Default Move
    By Lemming in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2006, 21:46

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.