QGIS API Documentation 3.43.0-Master (8fc5848dca1)
qgshighlight.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgshighlight.cpp - widget to highlight features on the map
3 --------------------------------------
4 Date : 02-03-2011
5 Copyright : (C) 2011 by Juergen E. Fischer, norBIT GmbH
6 Email : jef at norbit dot de
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include <QImage>
17
19#include "qgslinesymbollayer.h"
20
22#include "qgsfillsymbollayer.h"
23#include "qgsgeometry.h"
24#include "qgshighlight.h"
25#include "moc_qgshighlight.cpp"
26#include "qgsmapcanvas.h"
27#include "qgsmaplayer.h"
28#include "qgsrendercontext.h"
29#include "qgssymbollayer.h"
30#include "qgssymbol.h"
31#include "qgsvectorlayer.h"
32#include "qgsrenderer.h"
34#include "qgspointcloudlayer.h"
36
37/* Few notes about highlighting (RB):
38 - The highlight fill must always be partially transparent because above highlighted layer
39 may be another layer which must remain partially visible.
40 - Because single highlight color does not work well with layers using similar layer color
41 there were considered various possibilities but no optimal solution was found.
42 What does not work:
43 - lighter/darker color: it would work more or less for fully opaque highlight, but
44 overlaying transparent lighter color over original has small visual effect.
45 - complemetary color: mixing transparent (128) complement color with original color
46 results in grey for all colors
47 - contrast line style/ fill pattern: impression is not highligh but just different style
48 - line buffer with contrast (or 2 contrast) color: the same as with patterns, no highlight impression
49 - fill with highlight or contrast color but opaque and using pattern
50 (e.g. Qt::Dense7Pattern): again no highlight impression
51*/
52
54 : QgsMapCanvasItem( mapCanvas )
55 , mGeometry( geom )
56 , mLayer( layer )
57
58{
59 init();
60}
61
63 : QgsMapCanvasItem( mapCanvas )
64 , mLayer( layer )
65 , mFeature( feature )
66{
67 init();
68}
69
70void QgsHighlight::init()
71{
72 mOriginalGeometry = mGeometry.isNull() ? mFeature.geometry() : mGeometry;
73 setColor( QColor( Qt::lightGray ) );
74
75 connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsHighlight::updateTransformedGeometry );
76 updateTransformedGeometry();
77
78 if ( mGeometry.type() == Qgis::GeometryType::Point )
79 {
80 mRenderContext = createRenderContext();
81 }
82}
83
84void QgsHighlight::updateTransformedGeometry()
85{
87
88 // we don't auto-transform if we are highlighting a feature -- the renderer will take care
89 // of that for us
90 if ( ct.isValid() && !mGeometry.isNull() )
91 {
92 // reset to original geometry and transform
93 mGeometry = mOriginalGeometry;
94 try
95 {
96 mGeometry.transform( ct );
97 }
98 catch ( QgsCsException & )
99 {
100 QgsDebugError( QStringLiteral( "Could not transform highlight geometry to canvas CRS" ) );
101 }
102 }
103 updateRect();
104 update();
105}
106
108
109void QgsHighlight::setColor( const QColor &color )
110{
111 mColor = color;
112 mPen.setColor( color );
113 QColor fillColor( color.red(), color.green(), color.blue(), 63 );
114 mBrush.setColor( fillColor );
115 mBrush.setStyle( Qt::SolidPattern );
116}
117
118void QgsHighlight::setFillColor( const QColor &fillColor )
119{
120 mFillColor = fillColor;
121 mBrush.setColor( fillColor );
122 mBrush.setStyle( Qt::SolidPattern );
123}
124
125std::unique_ptr<QgsFeatureRenderer> QgsHighlight::createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor )
126{
127 std::unique_ptr<QgsFeatureRenderer> renderer;
128 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mLayer );
129 if ( layer && layer->renderer() )
130 {
131 renderer.reset( layer->renderer()->clone() );
132 }
133 if ( renderer )
134 {
135 const QgsSymbolList symbols = renderer->symbols( context );
136 for ( QgsSymbol *symbol : symbols )
137 {
138 if ( !symbol )
139 continue;
140 setSymbol( symbol, context, color, fillColor );
141 }
142 }
143 return renderer;
144}
145
146void QgsHighlight::setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor )
147{
148 if ( !symbol )
149 return;
150
151 for ( int i = symbol->symbolLayerCount() - 1; i >= 0; i-- )
152 {
153 QgsSymbolLayer *symbolLayer = symbol->symbolLayer( i );
154 if ( !symbolLayer )
155 continue;
156
157 if ( symbolLayer->subSymbol() )
158 {
159 setSymbol( symbolLayer->subSymbol(), context, color, fillColor );
160 }
161 else
162 {
163 symbolLayer->setColor( color ); // line symbology layers
164 symbolLayer->setStrokeColor( color ); // marker and fill symbology layers
165 symbolLayer->setFillColor( fillColor ); // marker and fill symbology layers
166
167 // Data defined widths overwrite what we set here (widths do not work with data defined)
168 QgsSimpleMarkerSymbolLayer *simpleMarker = dynamic_cast<QgsSimpleMarkerSymbolLayer *>( symbolLayer );
169 if ( simpleMarker )
170 {
171 simpleMarker->setStrokeWidth( getSymbolWidth( context, simpleMarker->strokeWidth(), simpleMarker->strokeWidthUnit() ) );
172 }
173 QgsSimpleLineSymbolLayer *simpleLine = dynamic_cast<QgsSimpleLineSymbolLayer *>( symbolLayer );
174 if ( simpleLine )
175 {
176 simpleLine->setWidth( getSymbolWidth( context, simpleLine->width(), simpleLine->widthUnit() ) );
177 }
178 QgsSimpleFillSymbolLayer *simpleFill = dynamic_cast<QgsSimpleFillSymbolLayer *>( symbolLayer );
179 if ( simpleFill )
180 {
181 simpleFill->setStrokeWidth( getSymbolWidth( context, simpleFill->strokeWidth(), simpleFill->outputUnit() ) );
182 }
185 }
186 }
187}
188
189double QgsHighlight::getSymbolWidth( const QgsRenderContext &context, double width, Qgis::RenderUnit unit )
190{
191 const double widthInPainterUnits = context.convertToPainterUnits( width, unit );
192 const double bufferInPainterUnits = context.convertToPainterUnits( mBuffer, Qgis::RenderUnit::Millimeters );
193 const double minWidthInPainterUnits = context.convertToPainterUnits( mMinWidth, Qgis::RenderUnit::Millimeters );
194
195 const double adjustedWidthInPainterUnits = std::max( widthInPainterUnits + 2 * bufferInPainterUnits, minWidthInPainterUnits );
196 return context.convertFromPainterUnits( adjustedWidthInPainterUnits, unit ) / mMapCanvas->magnificationFactor();
197}
198
199void QgsHighlight::setWidth( int width )
200{
201 mWidth = width;
202 mPen.setWidth( width );
203}
204
205void QgsHighlight::paintPoint( QgsRenderContext &context, const QgsPoint *point, double size, Qgis::RenderUnit sizeUnit, PointSymbol symbol )
206{
207 if ( !point )
208 return;
209
210 const double radius = context.convertToPainterUnits( size, sizeUnit );
211 const double xMin = toCanvasCoordinates( *point ).x() - radius - pos().x();
212 const double yMin = toCanvasCoordinates( *point ).y() - radius - pos().y();
213
214 switch ( symbol )
215 {
216 case QgsHighlight::Square:
217 {
218 const double xMax = xMin + 2 * radius;
219 const double yMax = yMin + 2 * radius;
220 QPolygonF r( QVector<QPointF> { QPointF( xMin, yMin ), QPointF( xMax, yMin ), QPointF( xMax, yMax ), QPointF( xMin, yMax ), QPointF( xMin, yMin ) } );
221 context.painter()->drawPolygon( r );
222 break;
223 }
224
225 case QgsHighlight::Circle:
226 {
227 context.painter()->drawEllipse( QRectF( xMin, yMin, radius * 2, radius * 2 ) );
228 break;
229 }
230 }
231}
232
233void QgsHighlight::paintLine( QPainter *p, QgsPolylineXY line )
234{
235 QPolygonF polygon( line.size() );
236
237 for ( int i = 0; i < line.size(); i++ )
238 {
239 polygon[i] = toCanvasCoordinates( line[i] ) - pos();
240 }
241
242 p->drawPolyline( polygon );
243}
244
245void QgsHighlight::paintPolygon( QPainter *p, const QgsPolygonXY &polygon )
246{
247 // OddEven fill rule by default
248 QPainterPath path;
249
250 p->setPen( mPen );
251 p->setBrush( mBrush );
252
253 for ( const auto &sourceRing : polygon )
254 {
255 if ( sourceRing.empty() )
256 continue;
257
258 QPolygonF ring;
259 ring.reserve( sourceRing.size() + 1 );
260
261 QPointF lastVertex;
262 for ( const auto &sourceVertex : sourceRing )
263 {
264 //adding point only if it is more than a pixel apart from the previous one
265 const QPointF curVertex = toCanvasCoordinates( sourceVertex ) - pos();
266 if ( ring.isEmpty() || std::abs( ring.back().x() - curVertex.x() ) > 1 || std::abs( ring.back().y() - curVertex.y() ) > 1 )
267 {
268 ring.push_back( curVertex );
269 }
270 lastVertex = curVertex;
271 }
272
273 ring.push_back( ring.at( 0 ) );
274
275 path.addPolygon( ring );
276 }
277
278 p->drawPath( path );
279}
280
281QgsRenderContext QgsHighlight::createRenderContext()
282{
283 QgsMapSettings mapSettings = mMapCanvas->mapSettings();
286 return context;
287}
288
290{
291 if ( !isVisible() )
292 return;
293
294 if ( mGeometry.type() == Qgis::GeometryType::Point )
295 {
296 mRenderContext = createRenderContext();
297 }
298
299 updateRect();
300}
301
303{
304 const QgsSettings settings;
305 QColor color = QColor( settings.value( QStringLiteral( "Map/highlight/color" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
306 const int alpha = settings.value( QStringLiteral( "Map/highlight/colorAlpha" ), Qgis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
307 const double buffer = settings.value( QStringLiteral( "Map/highlight/buffer" ), Qgis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
308 const double minWidth = settings.value( QStringLiteral( "Map/highlight/minWidth" ), Qgis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();
309
310 setColor( color ); // sets also fill with default alpha
311 color.setAlpha( alpha );
312 setFillColor( color ); // sets fill with alpha
313 setBuffer( buffer );
314 setMinWidth( minWidth );
315}
316
317void QgsHighlight::paint( QPainter *p )
318{
319 if ( mFeature.hasGeometry() )
320 {
321 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
322 if ( !vlayer )
323 return;
324
325 QgsRenderContext context = createRenderContext();
326 const QgsCoordinateTransform layerToCanvasTransform = mMapCanvas->mapSettings().layerTransform( mLayer );
327 context.setCoordinateTransform( layerToCanvasTransform );
328 QgsRectangle mapExtentInLayerCrs = mMapCanvas->mapSettings().visibleExtent();
329 if ( layerToCanvasTransform.isValid() )
330 {
331 QgsCoordinateTransform approxTransform = layerToCanvasTransform;
332 approxTransform.setBallparkTransformsAreAppropriate( true );
333 try
334 {
335 mapExtentInLayerCrs = approxTransform.transformBoundingBox( mapExtentInLayerCrs, Qgis::TransformDirection::Reverse );
336 }
337 catch ( QgsCsException & )
338 {
339 QgsDebugError( QStringLiteral( "Error transforming canvas extent to layer CRS" ) );
340 }
341 }
342 if ( !mapExtentInLayerCrs.isFinite() )
343 {
344 return;
345 }
346 context.setExtent( mapExtentInLayerCrs );
347
348 // Because lower level outlines must be covered by upper level fill color
349 // we render first with temporary opaque color, which is then replaced
350 // by final transparent fill color.
351 QColor tmpColor( 255, 0, 0, 255 );
352 QColor tmpFillColor( 0, 255, 0, 255 );
353
354 std::unique_ptr<QgsFeatureRenderer> renderer = createRenderer( context, tmpColor, tmpFillColor );
355 if ( renderer )
356 {
357 QSize imageSize( mMapCanvas->mapSettings().outputSize() );
358 QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
359 image.fill( 0 );
360 QPainter imagePainter( &image );
361 imagePainter.setRenderHint( QPainter::Antialiasing, true );
362
363 context.setPainter( &imagePainter );
364 renderer->startRender( context, mFeature.fields() );
365 context.expressionContext().setFeature( mFeature );
366 renderer->renderFeature( mFeature, context );
367 renderer->stopRender( context );
368
369 imagePainter.end();
370
371 // true output color
372 int penRed = mPen.color().red();
373 int penGreen = mPen.color().green();
374 int penBlue = mPen.color().blue();
375 // coefficient to subtract alpha using green (temporary fill)
376 double k = ( 255. - mBrush.color().alpha() ) / 255.;
377 QRgb *line = nullptr;
378 const int height = image.height();
379 const int width = image.width();
380 for ( int r = 0; r < height; r++ )
381 {
382 line = reinterpret_cast<QRgb *>( image.scanLine( r ) );
383 for ( int c = 0; c < width; c++ )
384 {
385 int alpha = qAlpha( line[c] );
386 if ( alpha > 0 )
387 {
388 int green = qGreen( line[c] );
389 line[c] = qRgba( penRed, penGreen, penBlue, std::clamp( static_cast<int>( alpha - ( green * k ) ), 30, 255 ) );
390 }
391 }
392 }
393
394 p->drawImage( 0, 0, image );
395 }
396 }
397 else if ( !mGeometry.isNull() )
398 {
399 p->setPen( mPen );
400 p->setBrush( mBrush );
401
402 switch ( mGeometry.type() )
403 {
405 {
406 setRenderContextVariables( p, mRenderContext );
407
408 // default to 1.5 mm radius square points
409 double pointSizeRadius = mPointSizeRadiusMM;
411 PointSymbol symbol = mPointSymbol;
412
413 // but for point clouds, use actual sizes (+a little margin!)
414 if ( QgsPointCloudLayer *pcLayer = qobject_cast<QgsPointCloudLayer *>( mLayer ) )
415 {
416 if ( QgsPointCloudRenderer *pcRenderer = pcLayer->renderer() )
417 {
418 pointSizeRadius = 1.2 * 0.5 * mRenderContext.convertToPainterUnits( pcRenderer->pointSize(), pcRenderer->pointSizeUnit(), pcRenderer->pointSizeMapUnitScale() );
419 sizeUnit = Qgis::RenderUnit::Pixels;
420 switch ( pcRenderer->pointSymbol() )
421 {
423 symbol = Circle;
424 break;
426 symbol = Square;
427 break;
428 }
429 }
430 }
431
432 for ( auto it = mGeometry.const_parts_begin(); it != mGeometry.const_parts_end(); ++it )
433 {
434 paintPoint( mRenderContext, qgsgeometry_cast<const QgsPoint *>( *it ), pointSizeRadius, sizeUnit, symbol );
435 }
436 }
437 break;
438
440 {
441 if ( !mGeometry.isMultipart() )
442 {
443 paintLine( p, mGeometry.asPolyline() );
444 }
445 else
446 {
447 QgsMultiPolylineXY m = mGeometry.asMultiPolyline();
448
449 for ( int i = 0; i < m.size(); i++ )
450 {
451 paintLine( p, m[i] );
452 }
453 }
454 break;
455 }
456
458 {
459 if ( !mGeometry.isMultipart() )
460 {
461 paintPolygon( p, mGeometry.asPolygon() );
462 }
463 else
464 {
465 QgsMultiPolygonXY m = mGeometry.asMultiPolygon();
466 for ( int i = 0; i < m.size(); i++ )
467 {
468 paintPolygon( p, m[i] );
469 }
470 }
471 break;
472 }
473
476 return;
477 }
478 }
479}
480
482{
483 if ( qobject_cast<QgsPointCloudLayer *>( mLayer ) || mFeature.hasGeometry() )
484 {
485 // We are currently using full map canvas extent for two reasons:
486 // 1) currently there is no method in QgsFeatureRenderer to get rendered feature
487 // bounding box
488 // 2) using different extent would result in shifted fill patterns
489
490 // This is an hack to pass QgsMapCanvasItem::setRect what it
491 // expects (encoding of position and size of the item)
493 QgsPointXY topLeft = m2p.toMapCoordinates( 0, 0 );
494 double res = m2p.mapUnitsPerPixel();
495 QSizeF imageSize = mMapCanvas->mapSettings().outputSize();
496 QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + imageSize.width() * res, topLeft.y() - imageSize.height() * res );
497 setRect( rect );
498
499 setVisible( true );
500 }
501 else if ( !mGeometry.isNull() )
502 {
503 QgsRectangle r = mGeometry.boundingBox();
504
505 if ( r.isEmpty() )
506 {
507 double d = mMapCanvas->extent().width() * 0.005;
508 r.setXMinimum( r.xMinimum() - d );
509 r.setYMinimum( r.yMinimum() - d );
510 r.setXMaximum( r.xMaximum() + d );
511 r.setYMaximum( r.yMaximum() + d );
512 }
513
514 setRect( r );
515 setVisible( true );
516 }
517 else
518 {
520 }
521}
@ Circle
Renders points as circles.
@ Square
Renders points as squares.
static const double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/stroke minimum width in mm.
Definition qgis.h:5983
static const double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition qgis.h:5978
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition qgis.h:5973
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
RenderUnit
Rendering size units.
Definition qgis.h:5045
@ Millimeters
Millimeters.
@ Reverse
Reverse/inverse transform (from destination to source)
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
Custom exception class for Coordinate Reference System related exceptions.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsFields fields
Definition qgsfeature.h:68
QgsGeometry geometry
Definition qgsfeature.h:69
bool hasGeometry() const
Returns true if the feature has an associated geometry.
A geometry is the spatial representation of a feature.
QgsMultiPolygonXY asMultiPolygon() const
Returns the contents of the geometry as a multi-polygon.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
Qgis::GeometryType type
QgsMultiPolylineXY asMultiPolyline() const
Returns the contents of the geometry as a multi-linestring.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
void updatePosition() override
called on changed extent or resize event to update position of the item
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
QgsHighlight(QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer)
Constructor for QgsHighlight.
void setBuffer(double buffer)
Sets the line/stroke buffer size (in millimeters).
QColor fillColor
~QgsHighlight() override
void setMinWidth(double width)
Sets the minimum line/stroke width (in millimeters).
void setFillColor(const QColor &fillColor)
Fill color for the highlight.
void applyDefaultStyle()
Applies the default style from the user settings to the highlight.
void setWidth(int width)
Set stroke width.
void paint(QPainter *p) override
function to be implemented by derived classes
void updateRect()
recalculates needed rectangle
void setColor(const QColor &color)
Set line/stroke to color, polygon fill to color with alpha = 63.
virtual void setWidth(double width)
Sets the width of the line symbol layer.
virtual double width() const
Returns the estimated width for the line symbol layer.
Qgis::RenderUnit widthUnit() const
Returns the units for the line's width.
An abstract class for items that can be placed on the map canvas.
QgsRectangle rect() const
returns canvas item rectangle in map units
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsMapCanvas * mMapCanvas
pointer to map canvas
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
bool setRenderContextVariables(QPainter *p, QgsRenderContext &context) const
Sets render context parameters.
Map canvas is a class for displaying all GIS data types on a canvas.
double magnificationFactor() const
Returns the magnification factor.
void destinationCrsChanged()
Emitted when map CRS has changed.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:77
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
Contains configuration for rendering maps.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
const QgsMapToPixel & mapToPixel() const
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
Represents a map layer supporting display of point clouds.
Abstract base class for 2d point cloud renderers.
Represents a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A store for object properties.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
double yMaximum
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Contains information about the context of a rendering operation.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
double convertFromPainterUnits(double size, Qgis::RenderUnit unit) const
Converts a size from painter units (pixels) to the specified render unit.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Renders polygons using a single fill and stroke color.
void setStrokeWidth(double strokeWidth)
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
Simple marker symbol layer, consisting of a rendered shape with solid fill color and a stroke.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
Qgis::RenderUnit strokeWidthUnit() const
Returns the unit for the width of the marker's stroke.
double strokeWidth() const
Returns the width of the marker's stroke.
Abstract base class for symbol layers.
virtual void setStrokeColor(const QColor &color)
Sets the stroke color for the symbol layer.
@ StrokeColor
Stroke color.
virtual void setFillColor(const QColor &color)
Sets the fill color for the symbol layer.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition qgssymbol.h:353
Represents a vector layer which manages a vector based dataset.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition qgsgeometry.h:74
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
Definition qgsgeometry.h:84
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:62
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
Definition qgsgeometry.h:91
#define QgsDebugError(str)
Definition qgslogger.h:40
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:48