Nominate our 2022 Qt Champions!

Enhancement to QUndoStack::endMacro

  • I apologize if this isn't the right forum. If not, please direct me elsewhere.

    I'm frustrated with the limitation of QUndoStack::endMacro in that it always creates an undo command on the stack even if there weren't any intervening children. In the graphic editor code I work on, I quite often need to start a macro that encapsulates potentially many operations scattered over a number of classes, and there's always the possibility that the user didn't actually do anything during the procedure (beginning a text edit and canceling, for example).

    The beginMacro/endMacro mechanism is great if you're sure that there will be intervening undo operations added to the stack, but if not, then the stack always has an empty undo command with text that appears on the actions and tooltips, and that's very confusing to the user.

    It seems to me that it should be very trivial to change the endMacro signature to:

     void endMacro (bool discard_if_empty = false);

    The default behavior would be unchanged. If the flag is set to true, then, if the internal macro parent has no children, it gets discarded rather than added to the stack. It would clean up a lot of messy code and make this much more useful.

    Is there a technical reason why this change couldn't be done? Or is it just a choice that's been made by the architects of Qt?

  • Hi! Maybe you want to discuss this with the devs on the mailing list. They can help you to write a patch :-)

Log in to reply