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. Undo by saving the whole model-state not actions possible with QUndoStack?

Undo by saving the whole model-state not actions possible with QUndoStack?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 384 Views
  • 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hi,

    i have a project where there is a QAbstractItemModel that can be manipulated by some actions.
    The changes to the model sometimes are a bit complicated, so it is hard to keep track of all the action and the opposite of them.
    Therefore I think the easiest way to implement Undo / Redo would be to just save the model state to a stack each time something is changed and load the old model for undo.

    The problem I see with this approach is, that for loading back the old model I also have to "undo" the beginInsertColumns() beginRemoveRows() begindeleteRows() and so on for the ItemView.

    Is there maybe some example for such a case?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Even if it might be quite inefficient, if you have control over the model, you can call beginResetModel/endResetModel to signal the complete change to the view

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        @VRonin: Thanks for the hint.
        I got that approach working now, however every time I undo the whole treeView collapses.
        Is there some Method to prevent this?

        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