QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
70 void QgsHighlight::init()
72 mOriginalGeometry = mGeometry.
isNull() ? mFeature.
geometry() : mGeometry;
76 updateTransformedGeometry();
80 mRenderContext = createRenderContext();
84 void QgsHighlight::updateTransformedGeometry()
93 mGeometry = mOriginalGeometry;
100 QgsDebugMsg( QStringLiteral(
"Could not transform highlight geometry to canvas CRS" ) );
112 mPen.setColor(
color );
115 mBrush.setStyle( Qt::SolidPattern );
122 mBrush.setStyle( Qt::SolidPattern );
125 std::unique_ptr<QgsFeatureRenderer> QgsHighlight::createRenderer(
QgsRenderContext &context,
const QColor &color,
const QColor &fillColor )
127 std::unique_ptr<QgsFeatureRenderer> renderer;
146 void QgsHighlight::setSymbol(
QgsSymbol *symbol,
const QgsRenderContext &context,
const QColor &color,
const QColor &fillColor )
197 width = std::max(
width + 2 * mBuffer * scale, mMinWidth * scale );
204 mPen.setWidth(
width );
218 case QgsHighlight::Square:
220 const double xMax = xMin + 2 * radius;
221 const double yMax = yMin + 2 * radius;
222 QPolygonF r( QVector<QPointF> { QPointF( xMin, yMin ),
223 QPointF( xMax, yMin ),
224 QPointF( xMax, yMax ),
225 QPointF( xMin, yMax ),
226 QPointF( xMin, yMin )
228 context.
painter()->drawPolygon( r );
232 case QgsHighlight::Circle:
234 context.
painter()->drawEllipse( QRectF( xMin, yMin, radius * 2, radius * 2 ) );
240 void QgsHighlight::paintLine( QPainter *p,
QgsPolylineXY line )
242 QPolygonF polygon( line.size() );
244 for (
int i = 0; i < line.size(); i++ )
249 p->drawPolyline( polygon );
252 void QgsHighlight::paintPolygon( QPainter *p,
const QgsPolygonXY &polygon )
258 p->setBrush( mBrush );
260 for (
const auto &sourceRing : polygon )
262 if ( sourceRing.empty() )
266 ring.reserve( sourceRing.size() + 1 );
269 for (
const auto &sourceVertex : sourceRing )
273 if ( ring.isEmpty() || std::abs( ring.back().x() - curVertex.x() ) > 1 || std::abs( ring.back().y() - curVertex.y() ) > 1 )
275 ring.push_back( curVertex );
277 lastVertex = curVertex;
280 ring.push_back( ring.at( 0 ) );
282 path.addPolygon( ring );
303 mRenderContext = createRenderContext();
313 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
321 if ( layerToCanvasTransform.
isValid() )
327 mapExtentInLayerCrs = approxTransform.
transformBoundingBox( mapExtentInLayerCrs, Qgis::TransformDirection::Reverse );
331 QgsDebugMsg( QStringLiteral(
"Error transforming canvas extent to layer CRS" ) );
334 if ( !mapExtentInLayerCrs.
isFinite() )
338 context.
setExtent( mapExtentInLayerCrs );
343 QColor tmpColor( 255, 0, 0, 255 );
344 QColor tmpFillColor( 0, 255, 0, 255 );
346 std::unique_ptr< QgsFeatureRenderer > renderer = createRenderer( context, tmpColor, tmpFillColor );
351 QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
353 QPainter imagePainter( &image );
354 imagePainter.setRenderHint( QPainter::Antialiasing,
true );
357 renderer->startRender( context, mFeature.
fields() );
359 renderer->renderFeature( mFeature, context );
360 renderer->stopRender( context );
365 int penRed = mPen.color().red();
366 int penGreen = mPen.color().green();
367 int penBlue = mPen.color().blue();
369 double k = ( 255. - mBrush.color().alpha() ) / 255.;
370 QRgb *line =
nullptr;
371 const int height = image.height();
372 const int width = image.width();
373 for (
int r = 0; r < height; r++ )
375 line =
reinterpret_cast<QRgb *
>( image.scanLine( r ) );
378 int alpha = qAlpha( line[
c] );
381 int green = qGreen( line[
c] );
382 line[
c] = qRgba( penRed, penGreen, penBlue, std::clamp(
static_cast< int >( alpha - ( green * k ) ), 0, 255 ) );
387 p->drawImage( 0, 0, image );
390 else if ( !mGeometry.
isNull() )
393 p->setBrush( mBrush );
395 switch ( mGeometry.
type() )
402 double pointSizeRadius = 1.5;
404 PointSymbol symbol = Square;
411 pointSizeRadius = 1.2 * 0.5 * mRenderContext.
convertToPainterUnits( pcRenderer->pointSize(), pcRenderer->pointSizeUnit(), pcRenderer->pointSizeMapUnitScale() );
413 switch ( pcRenderer->pointSymbol() )
427 paintPoint( mRenderContext, qgsgeometry_cast< const QgsPoint *>( *it ), pointSizeRadius, sizeUnit, symbol );
442 for (
int i = 0; i < m.size(); i++ )
444 paintLine( p, m[i] );
454 paintPolygon( p, mGeometry.
asPolygon() );
459 for (
int i = 0; i < m.size(); i++ )
461 paintPolygon( p, m[i] );
476 if ( qobject_cast<QgsPointCloudLayer *>( mLayer ) || mFeature.
hasGeometry() )
489 QgsRectangle rect( topLeft.
x(), topLeft.
y(), topLeft.
x() + imageSize.width()*res, topLeft.
y() - imageSize.height()*res );
494 else if ( !mGeometry.
isNull() )
void setColor(const QColor &color)
Set line/stroke to color, polygon fill to color with alpha = 63.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
A store for object properties.
RenderUnit
Rendering size units.
QgsExpressionContext & expressionContext()
Gets the expression context.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
void destinationCrsChanged()
Emitted when map CRS has changed.
virtual double width() const
Returns the estimated width for the line symbol layer.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Point geometry type, with support for z-dimension and m-values.
QgsMapCanvas * mMapCanvas
pointer to map canvas
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
virtual void setFillColor(const QColor &color)
Sets the fill color for the symbol layer.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
Represents a map layer supporting display of point clouds.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
bool setRenderContextVariables(QPainter *p, QgsRenderContext &context) const
Sets render context parameters.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
@ PropertyFillColor
Fill color.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
virtual void setWidth(double width)
Sets the width of the line symbol layer.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Map canvas is a class for displaying all GIS data types on a canvas.
Contains information about the context of a rendering operation.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
@ RenderMillimeters
Millimeters.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
Abstract base class for all rendered symbols.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
@ PropertyStrokeColor
Stroke color.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
A rectangle specified with double values.
QgsMultiPolylineXY asMultiPolyline() const
Returns the contents of the geometry as a multi-linestring.
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
void setStrokeWidth(double strokeWidth)
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.
Custom exception class for Coordinate Reference System related exceptions.
An abstract class for items that can be placed on the map canvas.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QList< QgsSymbol * > QgsSymbolList
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
double strokeWidth() const
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke.
@ Square
Renders points as squares.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
double strokeWidth() const
Returns the width of the marker's stroke.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the unit for the width of the marker's stroke.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
@ Circle
Renders points as circles.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void updatePosition() override
called on changed extent or resize event to update position of the item
void setFillColor(const QColor &fillColor)
Fill color for the highlight.
A class to represent a 2D point.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
QgsRectangle rect() const
returns canvas item rectangle in map units
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
A geometry is the spatial representation of a feature.
Perform transforms between map coordinates and device coordinates.
Represents a vector layer which manages a vector based data sets.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Base class for all map layer types. This is the base class for all map layer types (vector,...
virtual void setStrokeColor(const QColor &color)
Sets the stroke color for the symbol layer.
QgsHighlight(QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer)
Constructor for QgsHighlight.
Abstract base class for 2d point cloud renderers.
void setWidth(int width)
Set stroke width.
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsUnitTypes::RenderUnit widthUnit() const
Returns the units for the line's width.
QPainter * painter()
Returns the destination QPainter for the render operation.
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
QgsWkbTypes::GeometryType type
bool isEmpty() const
Returns true if the rectangle is empty.
const QgsMapToPixel & mapToPixel() const
void updateRect()
recalculates needed rectangle
@ RenderMapUnits
Map units.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
QgsMultiPolygonXY asMultiPolygon() const
Returns the contents of the geometry as a multi-polygon.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void paint(QPainter *p) override
function to be implemented by derived classes