QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
26 mIconSize( 5 ), mIconType( ICON_BOX ), mGeometryType( geomType )
28 mPen = QPen( QColor( 255, 0, 0 ) );
29 mBrush = QBrush( QColor( 255, 0, 0 ) );
38 if ( !mGeometry || !painter )
44 painter->translate( -pos() );
48 painter->setBrush( mBrush );
52 painter->setBrush( Qt::NoBrush );
54 painter->setPen( mPen );
57 std::unique_ptr< QgsAbstractGeometry > paintGeom( mGeometry->clone() );
60 paintGeom->draw( *painter );
68 while ( paintGeom->nextVertex( vertexId, vertex ) )
70 drawVertex( painter, vertex.
x(), vertex.
y() );
84 void QgsGeometryRubberBand::drawVertex( QPainter *p,
double x,
double y )
86 const qreal s = ( mIconSize - 1 ) / 2.0;
94 p->drawLine( QLineF( x - s, y, x + s, y ) );
95 p->drawLine( QLineF( x, y - s, x, y + s ) );
99 p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
100 p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
104 p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
105 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 ) );
111 p->drawRect( x - s, y - s, mIconSize, mIconSize );
115 p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
122 mGeometry.reset( geom );
126 setRect( rubberBandRectangle() );
134 mGeometry->moveVertex(
id, newPos );
135 setRect( rubberBandRectangle() );
141 mBrush.setColor(
c );
151 mPen.setWidth( width );
156 mPen.setStyle( penStyle );
161 mBrush.setStyle( brushStyle );
166 mDrawVertices = isVerticesDrawn;
169 QgsRectangle QgsGeometryRubberBand::rubberBandRectangle()
const
171 if ( !mGeometry || mGeometry->isEmpty() )
177 qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() );
181 QList<QgsPointXY> pl;
211 setRect( rubberBandRectangle() );
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void paint(QPainter *painter) override
function to be implemented by derived classes
double mapUnitsPerPixel() const
Returns the current map units per pixel.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Point geometry type, with support for z-dimension and m-values.
QgsMapCanvas * mMapCanvas
pointer to map canvas
@ ICON_CROSS
A cross is used to highlight points (+)
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Map canvas is a class for displaying all GIS data types on a canvas.
@ ICON_CIRCLE
A circle is used to highlight points (○)
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
A rectangle specified with double values.
@ ICON_BOX
A box is used to highlight points (□)
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
QgsWkbTypes::GeometryType geometryType() const
Returns which geometry is handled by the rubber band, polygon or line.
void setFillColor(const QColor &c)
Sets fill color for vertex markers.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
An abstract class for items that can be placed on the map canvas.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
void setLineStyle(Qt::PenStyle penStyle)
Sets pen style.
QgsGeometryRubberBand(QgsMapCanvas *mapCanvas, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::LineGeometry)
void updatePosition() override
called on changed extent or resize event to update position of the item
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Scoped object for saving and restoring a QPainter object's state.
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform.
virtual void setGeometry(QgsAbstractGeometry *geom)
Sets geometry (takes ownership). Geometry is expected to be in map coordinates.
@ ICON_FULL_BOX
A full box is used to highlight points (■)
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Abstract base class for all geometries.
A class to represent a 2D point.
void setBrushStyle(Qt::BrushStyle brushStyle)
Sets brush style.
void setGeometryType(const QgsWkbTypes::GeometryType &geometryType)
Sets which geometry is handled by the rubber band, polygon or line.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QgsRectangle rect() const
returns canvas item rectangle in map units
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
Perform transforms between map coordinates and device coordinates.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Utility class for identifying a unique vertex within a geometry.
void moveVertex(QgsVertexId id, const QgsPoint &newPos)
Moves vertex to new position (in map coordinates)
@ ICON_NONE
No icon is used.
void setVertexDrawingEnabled(bool isVerticesDrawn)
Sets whether the vertices are drawn.
void setStrokeWidth(int width)
Sets stroke width.
void setStrokeColor(const QColor &c)
Sets stroke color for vertex markers.
@ ICON_X
A cross is used to highlight points (x)
~QgsGeometryRubberBand() override