Skip to content

Commit

Permalink
Small cleanups and documentation improvements for QgsRenderContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 16, 2017
1 parent 430af90 commit cc56c80
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
31 changes: 11 additions & 20 deletions src/core/qgsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@

QgsRenderContext::QgsRenderContext()
: mFlags( DrawEditingInfo | UseAdvancedEffects | DrawSelection | UseRenderingOptimization )
, mPainter( nullptr )
, mRenderingStopped( false )
, mScaleFactor( 1.0 )
, mRendererScale( 1.0 )
, mLabelingEngine( nullptr )
, mGeometry( nullptr )
, mFeatureFilterProvider( nullptr )
, mSegmentationTolerance( M_PI_2 / 90 )
, mSegmentationToleranceType( QgsAbstractGeometry::MaximumAngle )
{
mVectorSimplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
}
Expand Down Expand Up @@ -73,18 +64,12 @@ QgsRenderContext&QgsRenderContext::operator=( const QgsRenderContext & rh )
mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
mExpressionContext = rh.mExpressionContext;
mGeometry = rh.mGeometry;
mFeatureFilterProvider = rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr;
mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
mSegmentationTolerance = rh.mSegmentationTolerance;
mSegmentationToleranceType = rh.mSegmentationToleranceType;
return *this;
}

QgsRenderContext::~QgsRenderContext()
{
delete mFeatureFilterProvider;
mFeatureFilterProvider = nullptr;
}

QgsRenderContext QgsRenderContext::fromQPainter( QPainter* painter )
{
QgsRenderContext context;
Expand Down Expand Up @@ -209,11 +194,17 @@ void QgsRenderContext::setUseRenderingOptimization( bool enabled )

void QgsRenderContext::setFeatureFilterProvider( const QgsFeatureFilterProvider* ffp )
{
delete mFeatureFilterProvider;
mFeatureFilterProvider = nullptr;

if ( ffp )
{
mFeatureFilterProvider = ffp->clone();
mFeatureFilterProvider.reset( ffp->clone() );
}
else
{
mFeatureFilterProvider.reset( nullptr );
}
}

const QgsFeatureFilterProvider* QgsRenderContext::featureFilterProvider() const
{
return mFeatureFilterProvider.data();
}
60 changes: 46 additions & 14 deletions src/core/qgsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
#include "qgsrectangle.h"
#include "qgsvectorsimplifymethod.h"
#include "qgsexpressioncontext.h"
#include "qgsfeaturefilterprovider.h"

class QPainter;

class QgsAbstractGeometry;
class QgsLabelingEngine;
class QgsMapSettings;
class QgsFeatureFilterProvider;


/** \ingroup core
Expand All @@ -50,8 +49,6 @@ class CORE_EXPORT QgsRenderContext
QgsRenderContext( const QgsRenderContext& rh );
QgsRenderContext& operator=( const QgsRenderContext& rh );

~QgsRenderContext();

/** Enumeration of flags that affect rendering operations.
* @note added in QGIS 2.14
*/
Expand Down Expand Up @@ -103,6 +100,10 @@ class CORE_EXPORT QgsRenderContext

//getters

/**
* Returns the destination QPainter for the render operation.
* @see setPainter()
*/
QPainter* painter() {return mPainter;}
const QPainter* constPainter() const { return mPainter; }

Expand All @@ -115,6 +116,12 @@ class CORE_EXPORT QgsRenderContext

const QgsMapToPixel& mapToPixel() const {return mMapToPixel;}

/**
* Returns the scaling factor for the render to convert painter units
* to physical sizes. This is usually equal to the number of pixels
* per millimeter.
* @see setScaleFactor()
*/
double scaleFactor() const {return mScaleFactor;}

bool renderingStopped() const {return mRenderingStopped;}
Expand All @@ -131,6 +138,11 @@ class CORE_EXPORT QgsRenderContext

bool drawEditingInformation() const;

/**
* Returns the renderer map scale. This will match the desired scale denominator
* for the rendered map, eg 1000.0 for a 1:1000 map render.
* @see setRendererScale()
*/
double rendererScale() const {return mRendererScale;}

//! Get access to new labeling engine (may be nullptr)
Expand All @@ -157,8 +169,28 @@ class CORE_EXPORT QgsRenderContext
void setDrawEditingInformation( bool b );

void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}

/**
* Sets the scaling factor for the render to convert painter units
* to physical sizes. This should usually be equal to the number of pixels
* per millimeter.
* @see scaleFactor()
*/
void setScaleFactor( double factor ) {mScaleFactor = factor;}

/**
* Sets the renderer map scale. This should match the desired scale denominator
* for the rendered map, eg 1000.0 for a 1:1000 map render.
* @see rendererScale()
*/
void setRendererScale( double scale ) {mRendererScale = scale;}

/**
* Sets the destination QPainter for the render operation. Ownership of the painter
* is not transferred and the QPainter destination must stay alive for the duration
* of any rendering operations.
* @see painter()
*/
void setPainter( QPainter* p ) {mPainter = p;}

void setForceVectorOutput( bool force );
Expand Down Expand Up @@ -225,7 +257,7 @@ class CORE_EXPORT QgsRenderContext
* @note added in QGIS 2.14
* @see setFeatureFilterProvider()
*/
const QgsFeatureFilterProvider* featureFilterProvider() const { return mFeatureFilterProvider; }
const QgsFeatureFilterProvider* featureFilterProvider() const;

/** Sets the segmentation tolerance applied when rendering curved geometries
@param tolerance the segmentation tolerance*/
Expand All @@ -244,7 +276,7 @@ class CORE_EXPORT QgsRenderContext
Flags mFlags;

//! Painter for rendering operations
QPainter* mPainter;
QPainter* mPainter = nullptr;

//! For transformation between coordinate systems. Can be invalid if on-the-fly reprojection is not used
QgsCoordinateTransform mCoordTransform;
Expand All @@ -254,16 +286,16 @@ class CORE_EXPORT QgsRenderContext
QgsMapToPixel mMapToPixel;

//! True if the rendering has been canceled
bool mRenderingStopped;
bool mRenderingStopped = false;

//! Factor to scale line widths and point marker sizes
double mScaleFactor;
double mScaleFactor = 1.0;

//! Map scale
double mRendererScale;
double mRendererScale = 1.0;

//! Newer labeling engine implementation (can be nullptr)
QgsLabelingEngine* mLabelingEngine;
QgsLabelingEngine* mLabelingEngine = nullptr;

//! Color used for features that are marked as selected
QColor mSelectionColor;
Expand All @@ -275,14 +307,14 @@ class CORE_EXPORT QgsRenderContext
QgsExpressionContext mExpressionContext;

//! Pointer to the (unsegmentized) geometry
const QgsAbstractGeometry* mGeometry;
const QgsAbstractGeometry* mGeometry = nullptr;

//! The feature filter provider
const QgsFeatureFilterProvider* mFeatureFilterProvider;
QScopedPointer< QgsFeatureFilterProvider > mFeatureFilterProvider;

double mSegmentationTolerance;
double mSegmentationTolerance = M_PI_2 / 90;

QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType;
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType = QgsAbstractGeometry::MaximumAngle;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
Expand Down

0 comments on commit cc56c80

Please sign in to comment.