87 void QgsHighlight::init()
106 setColor( QColor( Qt::lightGray ) );
119 mPen.setColor( color );
120 QColor fillColor( color.red(), color.green(), color.blue(), 63 );
121 mBrush.setColor( fillColor );
122 mBrush.setStyle( Qt::SolidPattern );
127 mBrush.setColor( fillColor );
128 mBrush.setStyle( Qt::SolidPattern );
143 if ( !symbol )
continue;
144 setSymbol( symbol, context, color, fillColor );
150 void QgsHighlight::setSymbol(
QgsSymbolV2* symbol,
const QgsRenderContext & context,
const QColor & color,
const QColor & fillColor )
152 if ( !symbol )
return;
158 if ( !symbolLayer )
continue;
162 setSymbol( symbolLayer->
subSymbol(), context, color, fillColor );
200 width = qMax( width + 2 * mBuffer * scale, mMinWidth * scale );
209 mPen.setWidth( width );
212 void QgsHighlight::paintPoint( QPainter *p,
QgsPoint point )
226 void QgsHighlight::paintLine( QPainter *p,
QgsPolyline line )
228 QPolygonF polygon( line.size() );
230 for (
int i = 0; i < line.size(); i++ )
235 p->drawPolyline( polygon );
238 void QgsHighlight::paintPolygon( QPainter *p,
QgsPolygon polygon )
244 p->setBrush( mBrush );
246 for (
int i = 0; i < polygon.size(); i++ )
248 if ( polygon[i].empty() )
continue;
251 ring.reserve( polygon[i].size() + 1 );
253 for (
int j = 0; j < polygon[i].size(); j++ )
257 if ( 0 == j || std::abs( ring.back().x() - cur.x() ) > 1 || std::abs( ring.back().y() - cur.y() ) > 1 )
259 ring.push_back( cur );
263 ring.push_back( ring[ 0 ] );
265 path.addPolygon( ring );
284 p->setBrush( mBrush );
286 switch ( mGeometry->
wkbType() )
291 paintPoint( p, mGeometry->
asPoint() );
299 for (
int i = 0; i < m.size(); i++ )
301 paintPoint( p, m[i] );
318 for (
int i = 0; i < m.size(); i++ )
320 paintLine( p, m[i] );
328 paintPolygon( p, mGeometry->
asPolygon() );
336 for (
int i = 0; i < m.size(); i++ )
338 paintPolygon( p, m[i] );
359 QColor tmpColor( 255, 0, 0, 255 );
360 QColor tmpFillColor( 0, 255, 0, 255 );
363 if ( layer && renderer )
367 QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
369 QPainter *imagePainter =
new QPainter( &image );
370 imagePainter->setRenderHint( QPainter::Antialiasing,
true );
380 QColor color( mPen.color() );
382 double k = ( 255. - mBrush.color().alpha() ) / 255.;
383 for (
int r = 0; r < image.height(); r++ )
385 for (
int c = 0; c < image.width(); c++ )
387 QRgb rgba = image.pixel( c, r );
388 int alpha = qAlpha( rgba );
391 int green = qGreen( rgba );
392 color.setAlpha( qBound<int>( 0, alpha - ( green * k ), 255 ) );
394 image.setPixel( c, r, color.rgba() );
399 p->drawImage( 0, 0, image );
423 setVisible( mGeometry );
438 QgsRectangle rect( topLeft.
x(), topLeft.
y(), topLeft.
x() + imageSize.width()*res, topLeft.
y() - imageSize.height()*res );
double borderWidth() const
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
A rectangle specified with double values.
Base class for all map layer types.
bool isEmpty() const
test if rectangle is empty.
virtual void updatePosition() override
called on changed extent or resize event to update position of the item
virtual double width() const
virtual void setOutlineColor(const QColor &color)
Set outline color.
void setXMaximum(double x)
Set the maximum x value.
QPointF toCanvasCoordinates(const QgsPoint &point) const
transformation from map coordinates to screen coordinates
const QgsCoordinateTransform * layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
double yMaximum() const
Get the y maximum value (top side of rectangle)
QgsMultiPolyline asMultiPolyline() const
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
QgsPolygon asPolygon() const
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list ...
void setFillColor(const QColor &fillColor)
Set polygons fill color.
An abstract class for items that can be placed on the map canvas.
void setOutlineWidth(double w)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
const QgsMapToPixel & mapToPixel() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsRectangle rect() const
returns canvas item rectangle in map units
virtual void removeDataDefinedProperty(const QString &property)
Map canvas is a class for displaying all GIS data types on a canvas.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
QgsMultiPolygon asMultiPolygon() const
return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
The QgsMapSettings class contains configuration for rendering of the map.
virtual void stopRender(QgsRenderContext &context)=0
virtual QgsSymbolV2List symbols()=0
for symbol levels
Perform transforms between map coordinates and device coordinates.
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
virtual QgsFeatureRendererV2 * clone() const =0
QgsHighlight(QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsMapLayer *layer)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
QSize outputSize() const
Return the size of the resulting map image.
double xMaximum() const
Get the x maximum value (right side of rectangle)
QgsSymbolV2::OutputUnit outputUnit() const override
void setYMinimum(double y)
Set the minimum y value.
virtual void setWidth(double width)
void updateRect()
recalculates needed rectangle
double outlineWidth() const
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
QVector< QgsPolygon > QgsMultiPolygon
a collection of QgsPolygons that share a common collection of attributes
QVector< QgsPoint > QgsMultiPoint
a collection of QgsPoints that share a common collection of attributes
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
void setPainter(QPainter *p)
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
double mapUnitsPerPixel() const
Return current map units per pixel.
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
const QgsMapLayer * layer() const
A class to represent a point.
virtual void setFillColor(const QColor &color)
Set fill color.
A class to represent a vector.
QVector< QgsPolyline > QgsMultiPolyline
a collection of QgsPolylines that share a common collection of attributes
virtual QgsSymbolV2 * subSymbol()
QgsPolyline asPolyline() const
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list ...
QgsSymbolV2::OutputUnit outlineWidthUnit() const
QgsRectangle boundingBox()
Returns the bounding box of this feature.
Contains information about the context of a rendering operation.
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
void setColor(const QColor &color)
Set line/outline 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
QgsMultiPoint asMultiPoint() const
return contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty list...
QgsMapCanvas * mMapCanvas
pointer to map canvas
virtual void paint(QPainter *p) override
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
virtual void setColor(const QColor &color)
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
double width() const
Width of the rectangle.
QgsPoint asPoint() const
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
Represents a vector layer which manages a vector based data sets.
void setBorderWidth(double borderWidth)
double xMinimum() const
Get the x minimum value (left side of rectangle)
QgsPoint toMapPoint(qreal x, qreal y) const
QgsSymbolV2::OutputUnit widthUnit() const
void setXMinimum(double x)
Set the minimum x value.
void setWidth(int width)
Set width.