Skip to content
Permalink
Browse files

Add QgsScopedQPainterState class for scoped save/restore calls

to a QPainter object
  • Loading branch information
nyalldawson committed Jul 2, 2020
1 parent 3f7320d commit 7af90907435d2e2db544661f07c4fc9f93fd1c07
Showing with 41 additions and 0 deletions.
  1. +41 −0 src/core/qgsrendercontext.h
@@ -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.
You can’t perform that action at this time.