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. QUndoStack Usage.
Forum Updated to NodeBB v4.3 + New Features

QUndoStack Usage.

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.3k Views 1 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.
  • D Offline
    D Offline
    deepakkakkeel
    wrote on last edited by
    #1

    Hi,

    I have a gridLayout with widgets like QCombox and QLineEdit in the cells of the grid.
    I need to do undo redo feature on it. I came to know we to use QUndoStack for that.
    May i know how to use it. Can any one please help.

    Thanks
    Deepak

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      you will need to subclass "QUndoRedoCommand":http://qt-project.org/doc/qt-5.0/qtwidgets/qundocommand.html and implement it's undo() and redo() methods. You must save all values you need to perform undo/redo accordingly to your command.

      This means initialize your instance of your undoredocommand object and set the old and new text of an line edit? Then push the instance on the QUndoRedoStack (note redo() will get called automatically on push to the undoredo-stack).

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deepakkakkeel
        wrote on last edited by
        #3

        Hi,

        May i know how to get the old value of QLineEdit. I am using the signal textChanged() whenever there is a textchange. I can get new text but how to get the old text?

        Deepak

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          since you create a undo command for every text change you know the text from the last time you saved it for that widget. Best would be to subclass QLineEdit widget, listen to it's own textChanged signal and emit an "custom-signal" with the new and old text from the last emission of the custom-signal.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deepakkakkeel
            wrote on last edited by
            #5

            Hi,

            May i know is it possible to delete a particular row from a QUndoStack?

            Deepak

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              i don't think so... but i also can't think of a use case where you would need to?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • D Offline
                D Offline
                deepakkakkeel
                wrote on last edited by
                #7

                Hi,

                I have a row with 2 combobox and a linedit and a minus Button.The minus button click is supposed to delete that row ( deletes the comboBoxes and the lineEdit ).
                1)Suppose i change the value in lineEdit, during this time the UndoStack gets populated. In my undo Command i am passing the pointer of lineEdit for undo , redo operations
                2) Suppose i delete the row , and press undo. It will result in segmentation fault because the lineEdit pointer has been deleted. So before deletion of row if i could delete the entry from UndoStack that contains the QUndoCommand for change in lineEdit it could save me.

                Deepak

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  you should add an undo/redo command also for the deletion.
                  And don't delete the widgets but just remove them from the layout.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deepakkakkeel
                    wrote on last edited by
                    #9

                    Hi,

                    So is it sure that there is no way by which i can delete an entry from the QUndoStack if the index is specified?

                    1 Reply Last reply
                    0
                    • raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #10

                      i don't see a method to do so on QUndoRedoStack class...

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      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