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. Code for an Undo option
Forum Updated to NodeBB v4.3 + New Features

Code for an Undo option

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.4k 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.
  • V Offline
    V Offline
    vIJI
    wrote on last edited by
    #1

    How to code for an undo option ....Any help is appreciated.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      hi and welcome
      there is support via

      http://doc.qt.io/qt-5.5/qundo.html

      But that said, it really depends on what you want to undo and how many levels back.
      So it comes down to what kinda of data your application handles and what you do it and
      what undo will do.

      Simple undo from say Delete is easy, as you can keep lasted
      deleted object around until next delete.

      you can have a look at this example
      http://www.walletfox.com/course/qundocommandexample.php

      V 1 Reply Last reply
      0
      • mrjjM mrjj

        hi and welcome
        there is support via

        http://doc.qt.io/qt-5.5/qundo.html

        But that said, it really depends on what you want to undo and how many levels back.
        So it comes down to what kinda of data your application handles and what you do it and
        what undo will do.

        Simple undo from say Delete is easy, as you can keep lasted
        deleted object around until next delete.

        you can have a look at this example
        http://www.walletfox.com/course/qundocommandexample.php

        V Offline
        V Offline
        vIJI
        wrote on last edited by
        #3

        @mrjj i am developing Linux calculator for that the undo is everything that we entered will be going in reverse format....i hope you understood..

        mrjjM 1 Reply Last reply
        0
        • V vIJI

          @mrjj i am developing Linux calculator for that the undo is everything that we entered will be going in reverse format....i hope you understood..

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @vIJI
          Well you want to be able to undo actual sub calculations
          or just the entered text ?
          So
          5+6-4
          undo
          5+6
          or what will it undo ?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vIJI
            wrote on last edited by
            #5

            yup exactly like.....
            5 + 4 + 3
            equal
            result = 12
            if again added
            12 + 2
            equal
            result = 14

            and now when you hit undo it should show the previous expression
            i.e...
            12 + 2
            again undo
            ull get 12
            undo
            5 + 4 + 3
            undo
            "no undo history"

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Ok so the easy way is just to store a QUndoCommand each time
              the state changes. Like add or remove digit.
              Enter should be a bit special as you will have to keep the
              buffer before doing the calc.

              I think the undo system will fully support your case.

              Alternative, you could just store the current Input (1+2)
              in a QStringList each time its changed
              and then just take last string from there on undo.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vIJI
                wrote on last edited by
                #7

                Ok thank you very much You were helpfull...

                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