65 void QgsHighlight::init()
94 mPen.setColor( color );
95 QColor fillColor( color.red(), color.green(), color.blue(), 63 );
96 mBrush.setColor( fillColor );
97 mBrush.setStyle( Qt::SolidPattern );
102 mBrush.setColor( fillColor );
103 mBrush.setStyle( Qt::SolidPattern );
106 std::unique_ptr<QgsFeatureRenderer> QgsHighlight::createRenderer(
QgsRenderContext &context,
const QColor &color,
const QColor &fillColor )
108 std::unique_ptr<QgsFeatureRenderer> renderer;
116 Q_FOREACH (
QgsSymbol *symbol, renderer->symbols( context ) )
118 if ( !symbol )
continue;
119 setSymbol( symbol, context, color, fillColor );
125 void QgsHighlight::setSymbol(
QgsSymbol *symbol,
const QgsRenderContext &context,
const QColor &color,
const QColor &fillColor )
127 if ( !symbol )
return;
133 if ( !symbolLayer )
continue;
137 setSymbol( symbolLayer->
subSymbol(), context, color, fillColor );
175 width = std::max( width + 2 * mBuffer * scale, mMinWidth * scale );
181 mPen.setWidth( width );
184 void QgsHighlight::paintPoint( QPainter *p,
const QgsPointXY &point )
198 void QgsHighlight::paintLine( QPainter *p,
QgsPolylineXY line )
200 QPolygonF polygon( line.size() );
202 for (
int i = 0; i < line.size(); i++ )
207 p->drawPolyline( polygon );
210 void QgsHighlight::paintPolygon( QPainter *p,
const QgsPolygonXY &polygon )
216 p->setBrush( mBrush );
218 for (
const auto &sourceRing : polygon )
220 if ( sourceRing.empty() )
224 ring.reserve( sourceRing.size() + 1 );
227 for (
const auto &sourceVertex : sourceRing )
231 if ( ring.isEmpty() || std::abs( ring.back().x() - curVertex.x() ) > 1 || std::abs( ring.back().y() - curVertex.y() ) > 1 )
233 ring.push_back( curVertex );
235 lastVertex = curVertex;
238 ring.push_back( ring.at( 0 ) );
240 path.addPolygon( ring );
256 p->setBrush( mBrush );
258 switch ( mGeometry->
type() )
264 paintPoint( p, mGeometry->
asPoint() );
269 for (
int i = 0; i < m.size(); i++ )
271 paintPoint( p, m[i] );
287 for (
int i = 0; i < m.size(); i++ )
289 paintLine( p, m[i] );
299 paintPolygon( p, mGeometry->
asPolygon() );
304 for (
int i = 0; i < m.size(); i++ )
306 paintPolygon( p, m[i] );
330 QColor tmpColor( 255, 0, 0, 255 );
331 QColor tmpFillColor( 0, 255, 0, 255 );
333 std::unique_ptr< QgsFeatureRenderer > renderer = createRenderer( context, tmpColor, tmpFillColor );
334 if ( layer && renderer )
338 QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
340 QPainter imagePainter( &image );
341 imagePainter.setRenderHint( QPainter::Antialiasing,
true );
345 renderer->startRender( context, layer->
fields() );
347 renderer->renderFeature( mFeature, context );
348 renderer->stopRender( context );
353 int penRed = mPen.color().red();
354 int penGreen = mPen.color().green();
355 int penBlue = mPen.color().blue();
357 double k = ( 255. - mBrush.color().alpha() ) / 255.;
358 QRgb *line =
nullptr;
359 for (
int r = 0; r < image.height(); r++ )
361 line = ( QRgb * )image.scanLine( r );
362 for (
int c = 0; c < image.width(); c++ )
364 int alpha = qAlpha( line[c] );
367 int green = qGreen( line[c] );
368 line[c] = qRgba( penRed, penGreen, penBlue, qBound<int>( 0, alpha - ( green * k ), 255 ) );
373 p->drawImage( 0, 0, image );
394 setVisible( mGeometry );
409 QgsRectangle rect( topLeft.
x(), topLeft.
y(), topLeft.
x() + imageSize.width()*res, topLeft.
y() - imageSize.height()*res );
A rectangle specified with double values.
Base class for all map layer types.
QgsMapLayer * layer() const
Return the layer for which this highlight has been created.
QgsHighlight(QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer)
Constructor for QgsHighlight.
void updatePosition() override
called on changed extent or resize event to update position of the item
QgsRectangle rect() const
returns canvas item rectangle in map units
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
void setXMaximum(double x)
Set the maximum x value.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke...
virtual void setWidth(double width)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
A class to represent a 2D point.
void setFillColor(const QColor &fillColor)
Fill color for the highlight.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
An abstract class for items that can be placed on the map canvas.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
A geometry is the spatial representation of a feature.
int symbolLayerCount() const
Returns total number of symbol layers contained in the symbol.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Map canvas is a class for displaying all GIS data types on a canvas.
virtual double width() const
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
void setStrokeWidth(double strokeWidth)
double strokeWidth() const
Returns the width of the marker's stroke.
The QgsMapSettings class contains configuration for rendering of the map.
virtual void setColor(const QColor &color)
The fill color.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
QgsMultiPolylineXY asMultiPolyline() const
Returns contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
Perform transforms between map coordinates and device coordinates.
double strokeWidth() const
QgsFields fields() const override
Returns the list of fields of this layer.
QgsUnitTypes::RenderUnit widthUnit() const
Returns the units for the line's width.
bool isEmpty() const
Returns true if the rectangle is empty.
QgsPolygonXY asPolygon() const
Returns contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
double width() const
Returns the width of the rectangle.
void setYMinimum(double y)
Set the minimum y value.
void updateRect()
recalculates needed rectangle
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsFeatureRenderer * renderer()
Return renderer.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
double mapUnitsPerPixel() const
Return current map units per pixel.
A store for object properties.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
const QgsMapToPixel & mapToPixel() const
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
virtual void setStrokeColor(const QColor &color)
Set stroke color.
A class to represent a vector.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsExpressionContext & expressionContext()
Gets the expression context.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the unit for the width of the marker's stroke.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Contains information about the context of a rendering operation.
QgsPointXY toMapPoint(double x, double y) const
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
virtual void setFillColor(const QColor &color)
Set fill color.
QgsPointXY asPoint() const
Returns contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
void setColor(const QColor &color)
Set line/stroke to color, polygon fill to color with alpha = 63.
void setYMaximum(double y)
Set the maximum y value.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
QgsMapCanvas * mMapCanvas
pointer to map canvas
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
void paint(QPainter *p) override
function to be implemented by derived classes
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsPolylineXY asPolyline() const
Returns contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
QgsMultiPointXY asMultiPoint() const
Returns contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty lis...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
Represents a vector layer which manages a vector based data sets.
QgsMultiPolygonXY asMultiPolygon() const
Returns contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list.
QSize outputSize() const
Return the size of the resulting map image.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
void setXMinimum(double x)
Set the minimum x value.
RenderUnit
Rendering size units.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
void setWidth(int width)
Set stroke width.