Results 1 to 4 of 4

Thread: Drop Actions

  1. #1
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Drop Actions

    Could someone help explain "Drop Actions"?

    I don't want data to be automatically copied into items or for items to be added, I just want to the model to be notified that someone dragged something onto an item, and for the model to take acton.

  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: Drop Actions

    Quote Originally Posted by MTK358 View Post
    Could someone help explain "Drop Actions"?
    Drop action determines what should happen to the original data once the drop occurs. A copy action means a new instance of data is created in the target with no reference to the original data. Move action says the original data is transferred to the target and removed from the source. Link action says the data appears in the target and refers to the same entity as the original. For example, say you have some data model with each item having an identifier. Say you drag item with id=7. If you do a copy action, you will have to generate a new id for the target. If you do a move, the data in the target will retain the original id and a piece of data with this id will be removed from the source. If you do a link action, the data in the target gets the same id as the data in the source.

    It is the source that suggests the drop action but it is ultimately the target that determines what the drop action is performed (it can override the hint from the source of the drag).


    I don't want data to be automatically copied into items or for items to be added, I just want to the model to be notified that someone dragged something onto an item, and for the model to take acton.
    That's most likely a copy action or a link action. What you actually do with the data is decided by how you implement dropMimeData() in the model (or the drop event in case of other objects).
    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. The following 2 users say thank you to wysota for this useful post:

    cai (19th October 2010), MTK358 (9th September 2010)

  4. #3
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drop Actions

    I'm still a bit confused. Is it the model that was dragged from that implements the actions? What if the references are only valid in the context of the model dragged from? What if there are no "references" but just data, like text?

  5. #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: Drop Actions

    Quote Originally Posted by MTK358 View Post
    Is it the model that was dragged from that implements the actions?
    The source of the drag is notified what the final drop action was. Then it can modify its own data accordingly. Unfortunately Qt's QAbstractItemModel doesn't have API for this so if you really need it, you'd have to reimplement the whole dragging routine in the view. By default the view will remove the original rows from the model in case of MoveAction and do nothing for other actions.

    What if the references are only valid in the context of the model dragged from?
    Then obviously you ignore that in the target. Imagine you have a model containing some data and you perform a drag that is encoded in different mime formats. One of the formats is text/plain that contains the xml representation of the data. If you drop it onto a text editor, obviously it won't understand the structure of the xml and will ignore the id and treat everything as text (according to the mime-type) regardless of the drop action. But if the drop action was MoveAction then the original model should discard the original data.

    In general once you do a drag and expect other applications to accept it, you lose control over it (as the drop is handled by the target and not by the source) so the data should be self-contained (i.e. not contain any pointers to the original data) - it should be a copy of all that is required to recreate the original data (technically speaking it is a serialized representation of the data). It is because even if you are certain that only your application will accept the data (i.e. by providing some custom mime-data), if you make a drop on another instance of the application it will accept the drop and will crash when trying to dereference a pointer in memory-space of a different process. Sorry if I overcomplicated things too much
    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.


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

    MTK358 (9th September 2010)

Similar Threads

  1. Menu Actions
    By GrahamLabdon in forum Newbie
    Replies: 9
    Last Post: 16th June 2010, 00:41
  2. Replies: 0
    Last Post: 4th May 2010, 10:24
  3. Menubar actions
    By srohit24 in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2009, 11:35
  4. What's wrong with my actions???
    By fullmetalcoder in forum Qt Programming
    Replies: 6
    Last Post: 4th March 2007, 18:49
  5. Actions and what to do with them?
    By krsmichael in forum Qt Tools
    Replies: 2
    Last Post: 20th January 2006, 22:08

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.