QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsrendercontext.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendercontext.h
3  ------------------
4  begin : March 16, 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSRENDERCONTEXT_H
19 #define QGSRENDERCONTEXT_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include <QColor>
24 #include <memory>
25 
26 #include "qgscoordinatetransform.h"
27 #include "qgsexpressioncontext.h"
29 #include "qgsmaptopixel.h"
30 #include "qgsmapunitscale.h"
31 #include "qgsrectangle.h"
33 #include "qgsdistancearea.h"
35 #include "qgspathresolver.h"
36 
37 class QPainter;
39 class QgsLabelingEngine;
40 class QgsMapSettings;
41 
42 
50 class CORE_EXPORT QgsRenderContext
51 {
52  public:
54 
56  QgsRenderContext &operator=( const QgsRenderContext &rh );
57 
62  enum Flag
63  {
64  DrawEditingInfo = 0x01,
65  ForceVectorOutput = 0x02,
66  UseAdvancedEffects = 0x04,
67  UseRenderingOptimization = 0x08,
68  DrawSelection = 0x10,
69  DrawSymbolBounds = 0x20,
70  RenderMapTile = 0x40,
71  Antialiasing = 0x80,
72  RenderPartialOutput = 0x100,
73  RenderPreviewJob = 0x200,
74  };
75  Q_DECLARE_FLAGS( Flags, Flag )
76 
77 
82  {
83  // refs for below dox: https://github.com/qgis/QGIS/pull/1286#issuecomment-39806854
84  // https://github.com/qgis/QGIS/pull/8573#issuecomment-445585826
85 
103 
119  };
120 
125  void setFlags( QgsRenderContext::Flags flags );
126 
131  void setFlag( Flag flag, bool on = true );
132 
137  Flags flags() const;
138 
143  bool testFlag( Flag flag ) const;
144 
149  static QgsRenderContext fromMapSettings( const QgsMapSettings &mapSettings );
150 
157  static QgsRenderContext fromQPainter( QPainter *painter );
158 
159  //getters
160 
165  QPainter *painter() {return mPainter;}
166 
177  QgsCoordinateTransform coordinateTransform() const {return mCoordTransform;}
178 
183  const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
184 
193  QgsCoordinateTransformContext transformContext() const;
194 
203  void setTransformContext( const QgsCoordinateTransformContext &context );
204 
212  const QgsPathResolver &pathResolver() const { return mPathResolver; }
213 
221  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
222 
238  const QgsRectangle &extent() const { return mExtent; }
239 
250  QgsRectangle mapExtent() const { return mOriginalMapExtent; }
251 
257  const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
258 
265  double scaleFactor() const {return mScaleFactor;}
266 
273  bool renderingStopped() const {return mRenderingStopped;}
274 
281  bool forceVectorOutput() const;
282 
286  bool useAdvancedEffects() const;
287 
291  void setUseAdvancedEffects( bool enabled );
292 
298  bool drawEditingInformation() const;
299 
305  double rendererScale() const {return mRendererScale;}
306 
311  QgsLabelingEngine *labelingEngine() const { return mLabelingEngine; } SIP_SKIP
312 
318  QColor selectionColor() const { return mSelectionColor; }
319 
327  bool showSelection() const;
328 
329  //setters
330 
341  void setCoordinateTransform( const QgsCoordinateTransform &t );
342 
348  void setMapToPixel( const QgsMapToPixel &mtp ) {mMapToPixel = mtp;}
349 
362  void setExtent( const QgsRectangle &extent ) {mExtent = extent;}
363 
374  void setMapExtent( const QgsRectangle &extent ) { mOriginalMapExtent = extent; }
375 
381  void setDrawEditingInformation( bool b );
382 
389  void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
390 
396  void setDistanceArea( const QgsDistanceArea &distanceArea ) {mDistanceArea = distanceArea ;}
397 
404  void setScaleFactor( double factor ) {mScaleFactor = factor;}
405 
411  void setRendererScale( double scale ) {mRendererScale = scale;}
412 
419  void setPainter( QPainter *p ) {mPainter = p;}
420 
427  void setForceVectorOutput( bool force );
428 
433  void setLabelingEngine( QgsLabelingEngine *engine2 ) { mLabelingEngine = engine2; } SIP_SKIP
434 
440  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
441 
449  void setShowSelection( bool showSelection );
450 
454  bool useRenderingOptimization() const;
455 
456  void setUseRenderingOptimization( bool enabled );
457 
459  const QgsVectorSimplifyMethod &vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
460  void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }
461 
468  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
469 
476  QgsExpressionContext &expressionContext() { return mExpressionContext; }
477 
485  const QgsExpressionContext &expressionContext() const { return mExpressionContext; } SIP_SKIP
486 
488  const QgsAbstractGeometry *geometry() const { return mGeometry; }
490  void setGeometry( const QgsAbstractGeometry *geometry ) { mGeometry = geometry; }
491 
498  void setFeatureFilterProvider( const QgsFeatureFilterProvider *ffp );
499 
506  const QgsFeatureFilterProvider *featureFilterProvider() const;
507 
511  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
513  double segmentationTolerance() const { return mSegmentationTolerance; }
514 
518  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
520  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
521 
522  // Conversions
523 
530  double convertToPainterUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
531 
538  double convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
539 
545  double convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const;
546 
553  double convertMetersToMapUnits( double meters ) const;
554 
562  {
563  return mTextRenderFormat;
564  }
565 
573  {
574  mTextRenderFormat = format;
575  }
576 
577  private:
578 
579  Flags mFlags;
580 
582  QPainter *mPainter = nullptr;
583 
585  QgsCoordinateTransform mCoordTransform;
586 
592  QgsDistanceArea mDistanceArea;
593 
594  QgsRectangle mExtent;
595  QgsRectangle mOriginalMapExtent;
596 
597  QgsMapToPixel mMapToPixel;
598 
600  bool mRenderingStopped = false;
601 
603  double mScaleFactor = 1.0;
604 
606  double mRendererScale = 1.0;
607 
609  QgsLabelingEngine *mLabelingEngine = nullptr;
610 
612  QColor mSelectionColor;
613 
615  QgsVectorSimplifyMethod mVectorSimplifyMethod;
616 
618  QgsExpressionContext mExpressionContext;
619 
621  const QgsAbstractGeometry *mGeometry = nullptr;
622 
624  std::unique_ptr< QgsFeatureFilterProvider > mFeatureFilterProvider;
625 
626  double mSegmentationTolerance = M_PI_2 / 90;
627 
629 
630  QgsCoordinateTransformContext mTransformContext;
631 
632  QgsPathResolver mPathResolver;
633 
634  TextRenderFormat mTextRenderFormat = TextFormatAlwaysOutlines;
635 
636 #ifdef QGISDEBUG
637  bool mHasTransformContext = false;
638 #endif
639 };
640 
641 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
642 
643 #endif
void setRenderingStopped(bool stopped)
Sets whether the rendering operation has been stopped and any ongoing rendering should be canceled im...
A rectangle specified with double values.
Definition: qgsrectangle.h:41
double rendererScale() const
Returns the renderer map scale.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
void setLabelingEngine(QgsLabelingEngine *engine2)
Assign new labeling engine.
Maximum angle between generating radii (lines from arc center to output vertices) ...
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr)
Always render text as text objects.
void setRendererScale(double scale)
Sets the renderer map scale.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
void setTextRenderFormat(TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setMapExtent(const QgsRectangle &extent)
Sets the original extent of the map being rendered.
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
void setSelectionColor(const QColor &color)
Sets the color to use when rendering selected features.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setGeometry(const QgsAbstractGeometry *geometry)
Sets pointer to original (unsegmentized) geometry.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
#define SIP_SKIP
Definition: qgis_sip.h:119
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
Always render text using path objects (AKA outlines/curves).
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QColor selectionColor() const
Returns the color to use when rendering selected features.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Abstract interface for use by classes that filter the features of a layer.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Abstract base class for all geometries.
Contains information about the context in which a coordinate transform is executed.
TextRenderFormat
Options for rendering text.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
The QgsLabelingEngine class provides map labeling functionality.
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context&#39;s map to pixel transform, which transforms between map coordinates and device coo...
Struct for storing maximum and minimum scales for measurements in map units.
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context&#39;s map to pixel transform, which transforms between map coordinates and device coordi...
Class for doing transforms between two map coordinate systems.
void setDistanceArea(const QgsDistanceArea &distanceArea)
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
Resolves relative paths into absolute paths and vice versa.
Flag
Enumeration of flags that affect rendering operations.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
const QgsExpressionContext & expressionContext() const
Gets the expression context (const version).
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:111
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.