33 , mIconType( ICON_CIRCLE )
34 , mGeometryType( geometryType )
35 , mTranslationOffsetX( 0.0 )
36 , mTranslationOffsetY( 0.0 )
38 reset( geometryType );
39 QColor color( Qt::lightGray );
51 , mTranslationOffsetX( 0.0 )
52 , mTranslationOffsetY( 0.0 )
55 QColor color( Qt::lightGray );
68 , mTranslationOffsetX( 0.0 )
69 , mTranslationOffsetY( 0.0 )
91 QColor fillColor( color.red(), color.green(), color.blue(), color.alpha() );
92 mBrush.setColor( fillColor );
100 QColor penColor( color.red(), color.green(), color.blue(), color.alpha() );
101 mPen.setColor( penColor );
110 mPen.setWidth( width );
120 mIconSize = iconSize;
125 mPen.setStyle( penStyle );
130 mBrush.setStyle( brushStyle );
139 mGeometryType = geometryType;
157 if ( geometryIndex < 0 )
159 geometryIndex = mPoints.size() - 1;
162 if ( geometryIndex < 0 || geometryIndex > mPoints.size() )
167 if ( geometryIndex == mPoints.size() )
169 mPoints.push_back( QList<QgsPoint>() << p );
172 if ( mPoints[geometryIndex].
size() == 2 &&
173 mPoints[geometryIndex][0] == mPoints[geometryIndex][1] )
175 mPoints[geometryIndex].last() = p;
179 mPoints[geometryIndex] << p;
195 if ( mPoints.size() < geometryIndex + 1 )
201 if ( mPoints[geometryIndex].
size() > 0 )
206 index = mPoints[geometryIndex].size() +
index;
208 mPoints[geometryIndex].removeAt( index );
228 if ( mPoints.size() < geometryIndex + 1 )
233 if ( mPoints.at( geometryIndex ).size() < 1 )
238 mPoints[geometryIndex].last() = p;
246 if ( mPoints.size() < geometryIndex + 1 )
251 if ( mPoints.at( geometryIndex ).size() <
index )
256 mPoints[geometryIndex][
index] = p;
266 reset( mGeometryType );
284 int idx = mPoints.size();
310 for (
int i = 0; i < mpt.size(); ++i, ++idx )
331 for (
int i = 0; i < line.count(); i++ )
350 for (
int i = 0; i < mline.size(); ++i, ++idx )
354 if ( line.size() == 0 )
359 for (
int j = 0; j < line.size(); ++j )
379 for (
int i = 0; i < line.count(); i++ )
398 for (
int i = 0; i < multipoly.size(); ++i, ++idx )
402 for (
int j = 0; j < line.count(); ++j )
452 if ( mPoints.size() > 0 )
454 p->setBrush( mBrush );
457 Q_FOREACH (
const QList<QgsPoint>& line, mPoints )
459 QVector<QPointF> pts;
460 Q_FOREACH (
const QgsPoint& pt, line )
463 if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
467 switch ( mGeometryType )
471 p->drawPolygon( pts );
477 Q_FOREACH (
const QPointF& pt, pts )
482 qreal s = ( mIconSize - 1 ) / 2.0;
490 p->drawLine( QLineF( x - s, y, x + s, y ) );
491 p->drawLine( QLineF( x, y - s, x, y + s ) );
495 p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
496 p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
500 p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
501 p->drawLine( QLineF( x + s, y - s, x + s, y + s ) );
502 p->drawLine( QLineF( x + s, y + s, x - s, y + s ) );
503 p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
507 p->drawRect( x - s, y - s, mIconSize, mIconSize );
511 p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
521 p->drawPolyline( pts );
531 if ( mPoints.empty() )
541 qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() ) / res;
544 for (
int i = 0; i < mPoints.size(); ++i )
546 QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin(),
547 itE = mPoints.at( i ).constEnd();
548 for ( ; it != itE; ++it )
550 QgsPoint p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
586 mTranslationOffsetX = dx;
587 mTranslationOffsetY = dy;
593 return mPoints.size();
598 if ( geometryIndex < 0 || geometryIndex >= mPoints.size() )
return 0;
599 return mPoints[geometryIndex].size();
605 QList<QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
606 for ( ; it != mPoints.constEnd(); ++it )
608 QList<QgsPoint>::const_iterator iter = it->constBegin();
609 for ( ; iter != it->constEnd(); ++iter )
619 if ( i < mPoints.size() && j < mPoints[i].size() )
620 return &mPoints[i][j];
629 switch ( mGeometryType )
634 QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
635 for ( ; it != mPoints.constEnd(); ++it )
637 polygon.append( getPolyline( *it ) );
647 QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
648 for ( ; it != mPoints.constEnd(); ++it )
650 multiPoint += getPolyline( *it );
659 if ( mPoints.size() > 0 )
661 if ( mPoints.size() > 1 )
664 QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
665 for ( ; it != mPoints.constEnd(); ++it )
667 multiPolyline.append( getPolyline( *it ) );
682 QgsPolyline QgsRubberBand::getPolyline(
const QList<QgsPoint> & points )
685 QList<QgsPoint>::const_iterator iter = points.constBegin();
686 for ( ; iter != points.constEnd(); ++iter )
688 polyline.append( *iter );
A cross is used to highlight points (x)
void setIconSize(int iconSize)
Set the size of the point icons.
void setWidth(int width)
Set the width of the line.
A rectangle specified with double values.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
bool isEmpty() const
test if rectangle is empty.
void setBorderColor(const QColor &color)
Set the border color for the rubberband.
QPointF toCanvasCoordinates(const QgsPoint &point) const
transformation from map coordinates to screen coordinates
void setTranslationOffset(double dx, double dy)
Adds translation to original coordinates (all in map coordinates)
void setLineStyle(Qt::PenStyle penStyle)
Set the style of the line.
QgsMultiPolyline asMultiPolyline() const
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
void movePoint(const QgsPoint &p, int geometryIndex=0)
Moves the rubber band point specified by index.
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
QgsPolygon asPolygon() const
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list ...
QgsPoint transform(const QgsPoint &p) const
const QgsPoint * getPoint(int i, int j=0) const
Return vertex.
An abstract class for items that can be placed on the map canvas.
QGis::GeometryType type() const
Returns type of the vector.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
virtual void updatePosition() override
called on changed extent or resize event to update position of the item
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
A cross is used to highlight points (+)
QgsRectangle rect() const
returns canvas item rectangle in map units
QgsGeometry * asGeometry()
Returns the rubberband as a Geometry.
Map canvas is a class for displaying all GIS data types on a canvas.
virtual void paint(QPainter *p) override
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.
Perform transforms between map coordinates and device coordinates.
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
A circle is used to highlight points (○)
void removePoint(int index=0, bool doUpdate=true, int geometryIndex=0)
Remove a vertex from the rubberband and (optionally) update canvas.
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
void addPoint(const QgsPoint &p, bool doUpdate=true, int geometryIndex=0)
Add a vertex to the rubberband and update canvas.
QVector< QgsPoint > QgsMultiPoint
a collection of QgsPoints that share a common collection of attributes
void reset(QGis::GeometryType geometryType=QGis::Line)
Clears all the geometries in this rubberband.
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
double mapUnitsPerPixel() const
Return current map units per pixel.
void setFillColor(const QColor &color)
Set the fill color for the rubberband.
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
void setToGeometry(QgsGeometry *geom, QgsVectorLayer *layer)
Sets this rubber band to the geometry of an existing feature.
A class to represent a point.
QgsMapCanvasItem(QgsMapCanvas *mapCanvas)
protected constructor: cannot be constructed directly
void setBrushStyle(Qt::BrushStyle brushStyle)
Set the style of the brush.
QVector< QgsPolyline > QgsMultiPolyline
a collection of QgsPolylines that share a common collection of attributes
static QgsGeometry * fromMultiPolyline(const QgsMultiPolyline &multiline)
construct geometry from a multipolyline
QgsPoint toMapCoordinates(int x, int y) const
void setIcon(IconType icon)
Set the icon type to highlight point geometries.
QgsPolyline asPolyline() const
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list ...
A box is used to highlight points (□)
int size() const
Returns number of geometries.
void setToCanvasRectangle(const QRect &rect)
Sets this rubber band to a map canvas rectangle.
QgsRubberBand(QgsMapCanvas *mapCanvas, QGis::GeometryType geometryType=QGis::Line)
Creates a new RubberBand.
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
int partSize(int geometryIndex) const
Returns number of vertices in feature part.
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
static QgsGeometry * fromMultiPoint(const QgsMultiPoint &multipoint)
construct geometry from a multipoint
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
construct geometry from a polyline
void setColor(const QColor &color)
Set the color for the rubberband.
static QgsGeometry * fromPolygon(const QgsPolygon &polygon)
construct geometry from a polygon
void addGeometry(QgsGeometry *geom, QgsVectorLayer *layer)
Add the geometry of an existing feature to a rubberband This is useful for multi feature highlighting...
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 removeLastPoint(int geometryIndex=0, bool doUpdate=true)
Removes the last point.
double xMinimum() const
Get the x minimum value (left side of rectangle)
QgsPoint toMapPoint(qreal x, qreal y) const
void updateRect()
recalculates needed rectangle
double height() const
Height of the rectangle.
A full box is used to highlight points (■)