QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgsabstractgeometry.h"
27 #include "qgscoordinatetransform.h"
28 #include "qgsexpressioncontext.h"
30 #include "qgsmaptopixel.h"
31 #include "qgsmapunitscale.h"
32 #include "qgsrectangle.h"
34 #include "qgsdistancearea.h"
36 #include "qgspathresolver.h"
37 
38 class QPainter;
40 class QgsLabelingEngine;
41 class QgsMapSettings;
42 
43 
51 class CORE_EXPORT QgsRenderContext
52 {
53  public:
55 
57  QgsRenderContext &operator=( const QgsRenderContext &rh );
58 
63  enum Flag
64  {
65  DrawEditingInfo = 0x01,
66  ForceVectorOutput = 0x02,
67  UseAdvancedEffects = 0x04,
68  UseRenderingOptimization = 0x08,
69  DrawSelection = 0x10,
70  DrawSymbolBounds = 0x20,
71  RenderMapTile = 0x40,
72  Antialiasing = 0x80,
73  RenderPartialOutput = 0x100,
74  RenderPreviewJob = 0x200,
75  };
76  Q_DECLARE_FLAGS( Flags, Flag )
77 
78 
83  {
84  // refs for below dox: https://github.com/qgis/QGIS/pull/1286#issuecomment-39806854
85  // https://github.com/qgis/QGIS/pull/8573#issuecomment-445585826
86 
104 
120  };
121 
126  void setFlags( QgsRenderContext::Flags flags );
127 
132  void setFlag( Flag flag, bool on = true );
133 
138  Flags flags() const;
139 
144  bool testFlag( Flag flag ) const;
145 
150  static QgsRenderContext fromMapSettings( const QgsMapSettings &mapSettings );
151 
158  static QgsRenderContext fromQPainter( QPainter *painter );
159 
160  //getters
161 
166  QPainter *painter() {return mPainter;}
167 
178  QgsCoordinateTransform coordinateTransform() const {return mCoordTransform;}
179 
184  const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
185 
194  QgsCoordinateTransformContext transformContext() const;
195 
204  void setTransformContext( const QgsCoordinateTransformContext &context );
205 
213  const QgsPathResolver &pathResolver() const { return mPathResolver; }
214 
222  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
223 
239  const QgsRectangle &extent() const { return mExtent; }
240 
251  QgsRectangle mapExtent() const { return mOriginalMapExtent; }
252 
258  const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
259 
266  double scaleFactor() const {return mScaleFactor;}
267 
274  bool renderingStopped() const {return mRenderingStopped;}
275 
282  bool forceVectorOutput() const;
283 
287  bool useAdvancedEffects() const;
288 
292  void setUseAdvancedEffects( bool enabled );
293 
299  bool drawEditingInformation() const;
300 
306  double rendererScale() const {return mRendererScale;}
307 
312  QgsLabelingEngine *labelingEngine() const { return mLabelingEngine; } SIP_SKIP
313 
319  QColor selectionColor() const { return mSelectionColor; }
320 
328  bool showSelection() const;
329 
330  //setters
331 
342  void setCoordinateTransform( const QgsCoordinateTransform &t );
343 
349  void setMapToPixel( const QgsMapToPixel &mtp ) {mMapToPixel = mtp;}
350 
363  void setExtent( const QgsRectangle &extent ) {mExtent = extent;}
364 
375  void setMapExtent( const QgsRectangle &extent ) { mOriginalMapExtent = extent; }
376 
382  void setDrawEditingInformation( bool b );
383 
390  void setRenderingStopped( bool stopped ) {mRenderingStopped = stopped;}
391 
397  void setDistanceArea( const QgsDistanceArea &distanceArea ) {mDistanceArea = distanceArea ;}
398 
405  void setScaleFactor( double factor ) {mScaleFactor = factor;}
406 
412  void setRendererScale( double scale ) {mRendererScale = scale;}
413 
420  void setPainter( QPainter *p ) {mPainter = p;}
421 
428  void setForceVectorOutput( bool force );
429 
434  void setLabelingEngine( QgsLabelingEngine *engine2 ) { mLabelingEngine = engine2; } SIP_SKIP
435 
441  void setSelectionColor( const QColor &color ) { mSelectionColor = color; }
442 
450  void setShowSelection( bool showSelection );
451 
455  bool useRenderingOptimization() const;
456 
457  void setUseRenderingOptimization( bool enabled );
458 
460  const QgsVectorSimplifyMethod &vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
461  void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }
462 
469  void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
470 
477  QgsExpressionContext &expressionContext() { return mExpressionContext; }
478 
486  const QgsExpressionContext &expressionContext() const { return mExpressionContext; } SIP_SKIP
487 
489  const QgsAbstractGeometry *geometry() const { return mGeometry; }
491  void setGeometry( const QgsAbstractGeometry *geometry ) { mGeometry = geometry; }
492 
499  void setFeatureFilterProvider( const QgsFeatureFilterProvider *ffp );
500 
507  const QgsFeatureFilterProvider *featureFilterProvider() const;
508 
512  void setSegmentationTolerance( double tolerance ) { mSegmentationTolerance = tolerance; }
514  double segmentationTolerance() const { return mSegmentationTolerance; }
515 
519  void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type ) { mSegmentationToleranceType = type; }
521  QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; }
522 
523  // Conversions
524 
531  double convertToPainterUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
532 
539  double convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale = QgsMapUnitScale() ) const;
540 
546  double convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const;
547 
554  double convertMetersToMapUnits( double meters ) const;
555 
563  {
564  return mTextRenderFormat;
565  }
566 
574  {
575  mTextRenderFormat = format;
576  }
577 
578  private:
579 
580  Flags mFlags;
581 
583  QPainter *mPainter = nullptr;
584 
586  QgsCoordinateTransform mCoordTransform;
587 
593  QgsDistanceArea mDistanceArea;
594 
595  QgsRectangle mExtent;
596  QgsRectangle mOriginalMapExtent;
597 
598  QgsMapToPixel mMapToPixel;
599 
601  bool mRenderingStopped = false;
602 
604  double mScaleFactor = 1.0;
605 
607  double mRendererScale = 1.0;
608 
610  QgsLabelingEngine *mLabelingEngine = nullptr;
611 
613  QColor mSelectionColor;
614 
616  QgsVectorSimplifyMethod mVectorSimplifyMethod;
617 
619  QgsExpressionContext mExpressionContext;
620 
622  const QgsAbstractGeometry *mGeometry = nullptr;
623 
625  std::unique_ptr< QgsFeatureFilterProvider > mFeatureFilterProvider;
626 
627  double mSegmentationTolerance = M_PI_2 / 90;
628 
630 
631  QgsCoordinateTransformContext mTransformContext;
632 
633  QgsPathResolver mPathResolver;
634 
635  TextRenderFormat mTextRenderFormat = TextFormatAlwaysOutlines;
636 
637 #ifdef QGISDEBUG
638  bool mHasTransformContext = false;
639 #endif
640 };
641 
642 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
643 
644 #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:40
void setLabelingEngine(QgsLabelingEngine *engine2)
Assign new labeling engine.
Maximum angle between generating radii (lines from arc center to output vertices) ...
QColor selectionColor() const
Returns the color to use when rendering selected features.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
Always render text as text objects.
double rendererScale() const
Returns the renderer map scale.
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...
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr)
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
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.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
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.
#define SIP_SKIP
Definition: qgis_sip.h:119
bool renderingStopped() const
Returns TRUE if the rendering operation has been stopped and any ongoing rendering should be canceled...
Always render text using path objects (AKA outlines/curves).
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
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.
QPainter * painter()
Returns the destination QPainter for the render operation.
Struct for storing maximum and minimum scales for measurements in map units.
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
const QgsExpressionContext & expressionContext() const
Gets the expression context (const version).
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...
const QgsMapToPixel & mapToPixel() const
Returns the context&#39;s map to pixel transform, which transforms between map coordinates and device coo...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
const QgsDistanceArea & distanceArea() const
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.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:110
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.