QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
66 void QgsHighlight::init()
97 mPen.setColor(
color );
100 mBrush.setStyle( Qt::SolidPattern );
107 mBrush.setStyle( Qt::SolidPattern );
110 std::unique_ptr<QgsFeatureRenderer> QgsHighlight::createRenderer(
QgsRenderContext &context,
const QColor &color,
const QColor &fillColor )
112 std::unique_ptr<QgsFeatureRenderer> renderer;
120 const auto constSymbols = renderer->symbols( context );
123 if ( !symbol )
continue;
130 void QgsHighlight::setSymbol(
QgsSymbol *symbol,
const QgsRenderContext &context,
const QColor &color,
const QColor &fillColor )
132 if ( !symbol )
return;
138 if ( !symbolLayer )
continue;
180 width = std::max(
width + 2 * mBuffer * scale, mMinWidth * scale );
187 mPen.setWidth(
width );
190 void QgsHighlight::paintPoint( QPainter *p,
const QgsPointXY &point )
204 void QgsHighlight::paintLine( QPainter *p,
QgsPolylineXY line )
206 QPolygonF polygon( line.size() );
208 for (
int i = 0; i < line.size(); i++ )
213 p->drawPolyline( polygon );
216 void QgsHighlight::paintPolygon( QPainter *p,
const QgsPolygonXY &polygon )
222 p->setBrush( mBrush );
224 for (
const auto &sourceRing : polygon )
226 if ( sourceRing.empty() )
230 ring.reserve( sourceRing.size() + 1 );
233 for (
const auto &sourceVertex : sourceRing )
237 if ( ring.isEmpty() || std::abs( ring.back().x() - curVertex.x() ) > 1 || std::abs( ring.back().y() - curVertex.y() ) > 1 )
239 ring.push_back( curVertex );
241 lastVertex = curVertex;
244 ring.push_back( ring.at( 0 ) );
246 path.addPolygon( ring );
262 p->setBrush( mBrush );
264 switch ( mGeometry->
type() )
270 paintPoint( p, mGeometry->
asPoint() );
275 for (
int i = 0; i < m.size(); i++ )
277 paintPoint( p, m[i] );
293 for (
int i = 0; i < m.size(); i++ )
295 paintLine( p, m[i] );
305 paintPolygon( p, mGeometry->
asPolygon() );
310 for (
int i = 0; i < m.size(); i++ )
312 paintPolygon( p, m[i] );
336 QColor tmpColor( 255, 0, 0, 255 );
337 QColor tmpFillColor( 0, 255, 0, 255 );
339 std::unique_ptr< QgsFeatureRenderer > renderer = createRenderer( context, tmpColor, tmpFillColor );
340 if (
layer && renderer )
344 QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
346 QPainter imagePainter( &image );
347 imagePainter.setRenderHint( QPainter::Antialiasing,
true );
351 renderer->startRender( context,
layer->fields() );
353 renderer->renderFeature( mFeature, context );
354 renderer->stopRender( context );
359 int penRed = mPen.color().red();
360 int penGreen = mPen.color().green();
361 int penBlue = mPen.color().blue();
363 double k = ( 255. - mBrush.color().alpha() ) / 255.;
364 QRgb *line =
nullptr;
365 const int height = image.height();
366 const int width = image.width();
367 for (
int r = 0; r < height; r++ )
369 line =
reinterpret_cast<QRgb *
>( image.scanLine( r ) );
372 int alpha = qAlpha( line[
c] );
375 int green = qGreen( line[
c] );
376 line[
c] = qRgba( penRed, penGreen, penBlue, qBound<int>( 0, alpha - ( green * k ), 255 ) );
381 p->drawImage( 0, 0, image );
402 setVisible( mGeometry );
417 QgsRectangle rect( topLeft.
x(), topLeft.
y(), topLeft.
x() + imageSize.width()*res, topLeft.
y() - imageSize.height()*res );
void setColor(const QColor &color)
Set line/stroke to color, polygon fill to color with alpha = 63.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
A store for object properties.
RenderUnit
Rendering size units.
QgsExpressionContext & expressionContext()
Gets the expression context.
double mapUnitsPerPixel() const
Returns current map units per pixel.
virtual double width() const
Returns the estimated width for the line symbol layer.
QSize outputSize() const
Returns the size of the resulting map image.
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
QgsMapCanvas * mMapCanvas
pointer to map canvas
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
virtual void setColor(const QColor &color)
The fill color.
@ 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.
Abstract base class for all rendered symbols.
QgsPointXY toMapCoordinates(int x, int y) const
Transform 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.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
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.
virtual void setFillColor(const QColor &color)
Set fill color.
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.
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
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
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.
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.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
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.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
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.
virtual void setStrokeColor(const QColor &color)
Set stroke color.
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.
A class to represent a vector.
QgsHighlight(QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer)
Constructor for QgsHighlight.
void setWidth(int width)
Set stroke width.
QgsPolylineXY asPolyline() const
Returns the contents of the geometry as a polyline.
QgsMultiPointXY asMultiPoint() const
Returns the contents of the geometry as a multi-point.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsUnitTypes::RenderUnit widthUnit() const
Returns the units for the line's width.
The QgsMapSettings class contains configuration for rendering of the map.
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