30 mPen = QPen( QColor( 255, 0, 0 ) );
31 mBrush = QBrush( QColor( 255, 0, 0 ) );
40 if ( !mGeometry || !painter )
46 painter->translate( -pos() );
50 painter->setBrush( mBrush );
54 painter->setBrush( Qt::NoBrush );
56 painter->setPen( mPen );
59 std::unique_ptr<QgsAbstractGeometry> paintGeom( mGeometry->clone() );
61 paintGeom->transform(
mMapCanvas->getCoordinateTransform()->transform() );
62 paintGeom->draw( *painter );
70 while ( paintGeom->nextVertex( vertexId, vertex ) )
72 drawVertex( painter, vertex.
x(), vertex.
y() );
86void QgsGeometryRubberBand::drawVertex( QPainter *p,
double x,
double y )
88 const qreal s = ( mIconSize - 1 ) / 2.0;
96 p->drawLine( QLineF( x - s, y, x + s, y ) );
97 p->drawLine( QLineF( x, y - s, x, y + s ) );
101 p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
102 p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
106 p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
107 p->drawLine( QLineF( x + s, y - s, x + s, y + s ) );
108 p->drawLine( QLineF( x + s, y + s, x - s, y + s ) );
109 p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
113 p->drawRect( x - s, y - s, mIconSize, mIconSize );
117 p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
124 mGeometry.reset( geom );
128 setRect( rubberBandRectangle() );
136 mGeometry->moveVertex(
id, newPos );
137 setRect( rubberBandRectangle() );
143 mBrush.setColor(
c );
153 mPen.setWidth( width );
158 mPen.setStyle( penStyle );
163 mBrush.setStyle( brushStyle );
168 mDrawVertices = isVerticesDrawn;
171QgsRectangle QgsGeometryRubberBand::rubberBandRectangle()
const
173 if ( !mGeometry || mGeometry->isEmpty() )
177 const QgsMapToPixel &m2p = *(
mMapCanvas->getCoordinateTransform() );
179 qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() );
182 QgsRectangle rectMap = mGeometry->boundingBox();
183 QList<QgsPointXY> pl;
189 for ( QgsPointXY &p : pl )
193 QgsRectangle
rect( p.x() - w, p.y() - w, p.x() + w, p.y() + w,
false );
201 QgsRectangle
rect( topLeft.
x(), topLeft.
y(), topLeft.
x() + r.
width() * res, topLeft.
y() - r.
height() * res );
213 setRect( rubberBandRectangle() );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Abstract base class for all geometries.
void setStrokeColor(const QColor &c)
Sets stroke color for vertex markers.
QgsGeometryRubberBand(QgsMapCanvas *mapCanvas, Qgis::GeometryType geomType=Qgis::GeometryType::Line)
Constructor for QgsGeometryRubberBand of the given geomType, shown in the specified mapCanvas.
~QgsGeometryRubberBand() override
@ ICON_X
A cross is used to highlight points (x).
@ ICON_NONE
No icon is used.
@ ICON_FULL_BOX
A full box is used to highlight points (■).
@ ICON_CIRCLE
A circle is used to highlight points (○).
@ ICON_BOX
A box is used to highlight points (□).
@ ICON_CROSS
A cross is used to highlight points (+).
Qgis::GeometryType geometryType() const
Returns which geometry is handled by the rubber band, polygon or line.
void setGeometryType(Qgis::GeometryType geometryType)
Sets which geometry is handled by the rubber band, polygon or line.
void setBrushStyle(Qt::BrushStyle brushStyle)
Sets brush style.
void updatePosition() override
called on changed extent or resize event to update position of the item
void setLineStyle(Qt::PenStyle penStyle)
Sets pen style.
virtual void setGeometry(QgsAbstractGeometry *geom)
Sets geometry (takes ownership). Geometry is expected to be in map coordinates.
void paint(QPainter *painter) override
function to be implemented by derived classes
void moveVertex(QgsVertexId id, const QgsPoint &newPos)
Moves vertex to new position (in map coordinates).
void setStrokeWidth(int width)
Sets stroke width.
void setVertexDrawingEnabled(bool isVerticesDrawn)
Sets whether the vertices are drawn.
void setFillColor(const QColor &c)
Sets fill color for vertex markers.
QgsRectangle rect() const
returns canvas item rectangle in map units
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsMapCanvas * mMapCanvas
pointer to map canvas
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
QgsMapCanvasItem(QgsMapCanvas *mapCanvas)
protected constructor: cannot be constructed directly
Map canvas is a class for displaying all GIS data types on a canvas.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Scoped object for saving and restoring a QPainter object's state.
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
Utility class for identifying a unique vertex within a geometry.