save() and restore() are particularly useful for building hierarichal models.
For example a robot:
painter->save();
translate, scale, or rotate the torso;
draw the torso;
painter->save();
translate, scale, or rotate the left hand;
draw the left hand;
painter->restore();
painter->save();
translate, scale, or rotate the right hand;
draw the right hand;
painter->restore();
painter->restore();
painter->save();
translate, scale, or rotate the torso;
draw the torso;
painter->save();
translate, scale, or rotate the left hand;
draw the left hand;
painter->restore();
painter->save();
translate, scale, or rotate the right hand;
draw the right hand;
painter->restore();
painter->restore();
To copy to clipboard, switch view to plain text mode
The right hand has nothing to do with the left hand's transformations. If either hands move, nothing else changes; However if the torso moves, both the hands move as well.

Originally Posted by
wysota
I think it came from OpenGL world where you can save/restore the state of matrices.
As Wysota said, we use such a concept widely in OpenGL programming.
*OpenGL's equivalent is glPushMatrix() and glPopMatrix()
Bookmarks