Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best app object hierarchy pattern for QUndoStack/QUndoCommand
Forum Updated to NodeBB v4.3 + New Features

Best app object hierarchy pattern for QUndoStack/QUndoCommand

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 449 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patrickkidd
    wrote on 20 Dec 2024, 08:24 last edited by patrickkidd
    #1

    I will admit, despite writing apps for 20 years and using Qt since v1.44 in 1998, I have never been pushed to perfect the object model for QUndoStack. I am not clear on where to house the stack, e.g. in the mainwindow, in the document view, or in the data model. My pyqt5 app (of 5 years, plenty of costly tech debt) incorrectly punts and stores the stack globally for easy access. But it's not unit testable, doesn't allow for a meaningful python wheel, isn't unit testable, and on and on. Plus, there is the problem of calling setters on the data model from all over the app but needing easy access. So, two major questions:

    • How do you organize the object hierarchy, i.e. where do you store a reference to the QUndoStack and provide access everywhere?
    • How do you optimize code footprint for QUndoCommand, i.e. do you end up implementing a ton of subclasses that all look the same>

    Here is an answer from ChatGPT, at least so far as my ability to prompt would generate: https://chatgpt.com/share/67651fd4-f538-8003-90e1-4c316c51e9fd

    Cheers,
    -Patrick

    https://alaskafamilysystems.com/

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Jan 2025, 08:40 last edited by
      #2

      Hi,

      The answer depends partly on what your application does.
      For example, a text editor will have an undo stack per document. Same for a painting application.
      Taking the painting application example, would you need one global stack for the document or one per tool you are using ? Both.
      There's no single universal answer to your question as it depends highly about the operations you are doing, how far does undoing go, etc.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved