33 , mIconType( ICON_CIRCLE )
34 , mGeometryType( geometryType )
35 , mTranslationOffsetX( 0.0 )
36 , mTranslationOffsetY( 0.0 )
38 reset( geometryType );
39 QColor color( Qt::lightGray );
50 , mIconType( ICON_CIRCLE )
51 , mTranslationOffsetX( 0.0 )
52 , mTranslationOffsetY( 0.0 )
55 QColor color( Qt::lightGray );
63 QgsRubberBand::QgsRubberBand()
66 , mIconType( ICON_CIRCLE )
67 , mGeometryType(
QGis::Polygon )
68 , mTranslationOffsetX( 0.0 )
69 , mTranslationOffsetY( 0.0 )
120 mIconSize = iconSize;
139 mGeometryType = geometryType;
157 if ( geometryIndex < 0 )
159 geometryIndex = mPoints.
size() - 1;
162 if ( geometryIndex < 0 || geometryIndex > mPoints.
size() )
167 if ( geometryIndex == mPoints.
size() )
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 )
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 )
477 Q_FOREACH (
const QPointF& pt, pts )
482 qreal s = ( mIconSize - 1 ) / 2.0;
507 p->
drawRect( x - s, y - s, mIconSize, mIconSize );
511 p->
drawEllipse( x - s, y - s, mIconSize, mIconSize );
531 if ( mPoints.
empty() )
541 qreal w = (( mIconSize - 1 ) / 2 + mPen.
width() ) / res;
544 for (
int i = 0; i < mPoints.
size(); ++i )
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();
606 for ( ; it != mPoints.
constEnd(); ++it )
609 for ( ; iter != it->
constEnd(); ++iter )
619 if ( i < mPoints.
size() && j < mPoints[i].
size() )
620 return &mPoints[i][j];
629 switch ( mGeometryType )
635 for ( ; it != mPoints.
constEnd(); ++it )
637 polygon.
append( getPolyline( *it ) );
648 for ( ; it != mPoints.
constEnd(); ++it )
650 multiPoint += getPolyline( *it );
659 if ( mPoints.
size() > 0 )
661 if ( mPoints.
size() > 1 )
665 for ( ; it != mPoints.
constEnd(); ++it )
667 multiPolyline.
append( getPolyline( *it ) );
686 for ( ; iter != points.
constEnd(); ++iter )
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
void setStyle(Qt::PenStyle style)
bool isEmpty() const
test if rectangle is empty.
void setBorderColor(const QColor &color)
Set the border color for the rubberband.
void append(const T &value)
void push_back(const T &value)
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.
void drawPolyline(const QPointF *points, int pointCount)
A box is used to highlight 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
Transform the point from map (world) coordinates to device coordinates.
const T & at(int i) 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 geometry as a QGis::GeometryType.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
A geometry is the spatial representation of a feature.
virtual void updatePosition() override
called on changed extent or resize event to update position of the item
The QGis class provides global constants for use throughout the application.
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
void drawLine(const QLineF &line)
QgsRectangle rect() const
returns canvas item rectangle in map units
void setStyle(Qt::BrushStyle style)
QgsGeometry * asGeometry()
Returns the rubberband as a Geometry.
Map canvas is a class for displaying all GIS data types on a canvas.
void update(const QRectF &rect)
double x() const
Get the x value of the point.
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.
void drawRect(const QRectF &rectangle)
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 setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
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
void addPoint(const QgsPoint &p, bool doUpdate=true, int geometryIndex=0)
Add a vertex to the rubberband and update canvas.
void setBrush(const QBrush &brush)
void reset(QGis::GeometryType geometryType=QGis::Line)
Clears all the geometries in this rubberband.
void addGeometry(const QgsGeometry *geom, QgsVectorLayer *layer)
Add the geometry of an existing feature to a rubberband This is useful for multi feature highlighting...
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (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.
void setColor(const QColor &color)
A cross is used to highlight points (x)
A class to represent a point.
A full box is used to highlight points (■)
void setBrushStyle(Qt::BrushStyle brushStyle)
Set the style of the brush.
static QgsGeometry * fromMultiPolyline(const QgsMultiPolyline &multiline)
Creates a new geometry from a QgsMultiPolyline object.
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...
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.
int count(const T &value) const
A cross is used to highlight points (+)
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
static QgsGeometry * fromMultiPoint(const QgsMultiPoint &multipoint)
Creates a new geometry from a QgsMultiPoint object.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
void setVisible(bool visible)
double y() const
Get the y value of the point.
void setColor(const QColor &color)
Set the color for the rubberband.
static QgsGeometry * fromPolygon(const QgsPolygon &polygon)
Creates a new geometry from a QgsPolygon.
const_iterator constEnd() const
const_iterator constBegin() const
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.
void setColor(const QColor &color)
double xMinimum() const
Get the x minimum value (left side of rectangle)
void updateRect()
recalculates needed rectangle
void setToGeometry(const QgsGeometry *geom, QgsVectorLayer *layer)
Sets this rubber band to the geometry of an existing feature.
double height() const
Height of the rectangle.
QgsPoint toMapPoint(double x, double y) const