Results 1 to 7 of 7

Thread: programmatic way to determine if in a macro

  1. #1
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4

    Default programmatic way to determine if in a macro

    Howdy,

    I have a custom model with undo/redo implemented via QUndoStack. Some of
    my operations require macros with some complicated logic. Is there any way to
    programmatically determine if you are currently inside an uncompleted macro?

    thanks,
    Danny

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

    Default Re: programmatic way to determine if in a macro

    If you only create macros by creating commands with parents then your commands can check their contructor's "parent" argument to see if they are part of a macro. You can even access the parent's list of children to see if there are more commands to follow.
    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
    Oct 2010
    Posts
    6
    Qt products
    Qt4

    Default Re: programmatic way to determine if in a macro

    Thanks for the response. This doesn't work so well for me though. Currently, my macros are defined in the view, since that is where the composite actions happen (like copy/delete for DnD "move"). The atomic commands happen in the model.
    They don't know anything about the view and the macros living there, so it is hard to set command parents.

    There is another problem, too. I need to check whether there is macro underway at some point in the view code. I need to decide whether to end the macro or not. I have no handle to a command to see whether it is part of a macro.
    Parents would let me if a command is part of a macro, but not whether a macro is underway or completed.

    thanks again,
    Danny

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

    Default Re: programmatic way to determine if in a macro

    It's hard for me to imagine what is going on in your program. By the way, did you follow the QQ article on using undo/redo with the model-view architecture?
    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
    Oct 2010
    Posts
    6
    Qt products
    Qt4

    Default Re: programmatic way to determine if in a macro

    I have read the undo/redo article on model-view controller.

    Here is what the app is trying to do. I am constructing a tree (QTreeView) via Drag and Drop off a toolbar. Items are symbolically dropped onto their desired location in the tree. As the drop happens, I open the editor
    to allow the user to enter text into the new node. The dropping of the node and the editing of the text are the contents of the macro. The problem is that all the DnD machinery is over by the time the editor opens.
    The macro opens with the node drop. The text is edited at human timescales, so at some programmatically infinite time in the future, the macro needs to stop (at the end of the text editing). The right time to end the macro is at the commitData
    member function. The problem is that you can open the node editor anytime you want by double clicking and editing the text. So sometimes in the commit, you end the macro (after a drop), and sometimes
    you don't (when choosing to edit). Hence my problem of trying to determine programmatically whether a macro (the drop/edit one) is underway or not.

    I appreciate you help,
    Danny


    Added after 16 minutes:


    BTW, I am currently solving the problem, but leaving a "cookie", a hidden data member in the tree, to show I am currently in a macro, but this strikes me as extremely inelegant, and dynamic inspection of the macro state would be a much better solution.

    D
    Last edited by shevitz; 2nd December 2010 at 17:59.

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

    Default Re: programmatic way to determine if in a macro

    I would do it differently. Make your two atomic commands (add and edit) mergable - if an edit of the same node comes after a drop simply merge the two commands by reimplementing QUndoCommand::mergeWith(). Then you won't need any macros.
    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. #7
    Join Date
    Oct 2010
    Posts
    6
    Qt products
    Qt4

    Default Re: programmatic way to determine if in a macro

    thanks for the suggestion. I am trying to figure out whether or not it will work for me.

    D

Similar Threads

  1. QSqlTableModel programmatic changes
    By jtdavidson in forum Newbie
    Replies: 3
    Last Post: 13th July 2010, 03:29
  2. QT_MODULE() macro error?
    By batileon in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 04:43
  3. Q_OBJECT macro - what exactly does it do?
    By magland in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 10:30
  4. Macro
    By comlink21 in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 11:28
  5. Macro used for debugging
    By sunil.thaha in forum General Programming
    Replies: 11
    Last Post: 30th March 2007, 17:32

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
  •  
Qt is a trademark of The Qt Company.