'How do I undo the most recent transformation performed on QGraphicsView?

I have a QGraphicsView, which contains rectangle, polyline, text etc. I also have some features to transform the view like zoom in, zoom out, Fit in view, change the color on mouse right click etc. I want to add few more features like Undo and Redo.

Undo means, user should cancel the effect of last command executed and show previous transformation. So If user did transformation like zoom in -> zoom in -> fit in -> zoom in and now pressed Undo then view's fit in position should get displayed.

How to think about this ? Should I store each transformation of view somewhere, say in stack ? But how to store each transformation in stack ? I am clueless. Can anyone help me to think ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source