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.
at( geometryIndex ).size() == 2 &&
173 mPoints.
at( geometryIndex ).at( 0 ) == mPoints.
at( geometryIndex ).at( 1 ) )
175 mPoints[geometryIndex].
last() = p;
179 mPoints[geometryIndex] << p;
193 if ( geometryIndex < 0 || geometryIndex >= mPoints.
size() )
198 if ( mPoints.
at( geometryIndex ).at( 0 ) != mPoints.
at( geometryIndex ).at( mPoints.
at( geometryIndex ).size() - 1 ) )
200 mPoints[geometryIndex] << mPoints.
at( geometryIndex ).at( 0 );
215 if ( mPoints.
size() < geometryIndex + 1 )
221 if ( !mPoints[geometryIndex].isEmpty() )
226 index = mPoints.
at( geometryIndex ).size() +
index;
228 mPoints[geometryIndex].
removeAt( index );
248 if ( mPoints.
size() < geometryIndex + 1 )
253 if ( mPoints.
at( geometryIndex ).size() < 1 )
258 mPoints[geometryIndex].
last() = p;
266 if ( mPoints.
size() < geometryIndex + 1 )
271 if ( mPoints.
at( geometryIndex ).size() <
index )
276 mPoints[geometryIndex][
index] = p;
286 reset( mGeometryType );
304 int idx = mPoints.
size();
330 for (
int i = 0; i < mpt.
size(); ++i, ++idx )
351 for (
int i = 0; i < line.
count(); i++ )
370 for (
int i = 0; i < mline.
size(); ++i, ++idx )
379 for (
int j = 0; j < line.
size(); ++j )
399 for (
int i = 0; i < line.
count(); i++ )
418 for (
int i = 0; i < multipoly.
size(); ++i, ++idx )
422 for (
int j = 0; j < line.
count(); ++j )
480 Q_FOREACH (
const QgsPoint& pt, line )
483 if ( pts.
empty() || std::abs( pts.
back().x() - cur.
x() ) > 1 || std::abs( pts.
back().y() - cur.
y() ) > 1 )
487 switch ( mGeometryType )
502 qreal s = ( mIconSize - 1 ) / 2.0;
527 p->
drawRect( x - s, y - s, mIconSize, mIconSize );
531 p->
drawEllipse( x - s, y - s, mIconSize, mIconSize );
551 if ( mPoints.
empty() )
561 qreal w = (( mIconSize - 1 ) / 2 + mPen.
width() ) / res;
564 for (
int i = 0; i < mPoints.
size(); ++i )
567 itE = mPoints.
at( i ).constEnd();
568 for ( ; it != itE; ++it )
570 QgsPoint p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
606 mTranslationOffsetX = dx;
607 mTranslationOffsetY = dy;
613 return mPoints.
size();
618 if ( geometryIndex < 0 || geometryIndex >= mPoints.
size() )
return 0;
619 return mPoints[geometryIndex].
size();
626 for ( ; it != mPoints.
constEnd(); ++it )
629 for ( ; iter != it->
constEnd(); ++iter )
639 if ( i < mPoints.
size() && j < mPoints[i].
size() )
640 return &mPoints[i][j];
649 switch ( mGeometryType )
655 for ( ; it != mPoints.
constEnd(); ++it )
657 polygon.
append( getPolyline( *it ) );
668 for ( ; it != mPoints.
constEnd(); ++it )
670 multiPoint += getPolyline( *it );
681 if ( mPoints.
size() > 1 )
685 for ( ; it != mPoints.
constEnd(); ++it )
687 multiPolyline.
append( getPolyline( *it ) );
706 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 setToCanvasRectangle(QRect rect)
Sets this rubber band to a map canvas rectangle.
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 closePoints(bool doUpdate=true, int geometryIndex=0)
Ensures that a polygon geometry is closed and that the last vertex equals the first vertex...
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.
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