Skip to content
Permalink
Browse files

Small cleanups and documentation improvements for QgsRenderContext

  • Loading branch information
nyalldawson committed Jan 16, 2017
1 parent 430af90 commit cc56c80b5bbee2a3d8c423138305cd3e7354e97b
Showing with 57 additions and 34 deletions.
  1. +11 −20 src/core/qgsrendercontext.cpp
  2. +46 −14 src/core/qgsrendercontext.h
@@ -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 );
}
@@ -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;
@@ -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();
}
@@ -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
@@ -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
*/
@@ -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; }

@@ -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;}
@@ -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)
@@ -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 );
@@ -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*/
@@ -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;
@@ -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;
@@ -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 )

0 comments on commit cc56c80

Please sign in to comment.
You can’t perform that action at this time.