Skip to content

Commit

Permalink
Add QgsScopedQPainterState class for scoped save/restore calls
Browse files Browse the repository at this point in the history
to a QPainter object
  • Loading branch information
nyalldawson committed Jul 2, 2020
1 parent 3f7320d commit 7af9090
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/core/qgsrendercontext.h
Expand Up @@ -1040,6 +1040,47 @@ class QgsScopedRenderContextScaleToPixels

QgsRenderContext &mContext;
};


/**
* \ingroup core
*
* Scoped object for saving and restoring a QPainter object's state.
*
* Temporarily saves the QPainter state for the lifetime of the object, before restoring it
* on destruction.
*
* \note Not available in Python bindings
* \since QGIS 3.16
*/
class QgsScopedQPainterState
{
public:

/**
* Constructor for QgsScopedQPainterState.
*
* Saves the specified \a painter state.
*/
QgsScopedQPainterState( QPainter *painter )
: mPainter( painter )
{
mPainter->save();
}

/**
* Restores the painter back to its original state.
*/
~QgsScopedQPainterState()
{
mPainter->restore();
}

private:

QPainter *mPainter = nullptr;
};

#endif

#endif

0 comments on commit 7af9090

Please sign in to comment.