QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsrubberband.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrubberband.h - Rubberband widget for drawing multilines and polygons
3  --------------------------------------
4  Date : 07-Jan-2006
5  Copyright : (C) 2006 by Tom Elwertowski
6  Email : telwertowski at users dot sourceforge dot net
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSRUBBERBAND_H
16 #define QGSRUBBERBAND_H
17 
18 #include "qgsmapcanvasitem.h"
19 #include "qgis_sip.h"
20 #include "qgsgeometry.h"
21 
22 #include <QBrush>
23 #include <QList>
24 #include <QPen>
25 #include <QPolygon>
26 #include <QObject>
27 
28 #include "qgis_gui.h"
29 
30 class QgsVectorLayer;
31 class QPaintEvent;
32 
40 class GUI_EXPORT QgsRubberBand : public QObject, public QgsMapCanvasItem
41 {
42  Q_OBJECT
43  public:
44 
45  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
46  Q_PROPERTY( QColor strokeColor READ strokeColor WRITE setStrokeColor )
47  Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
48  Q_PROPERTY( QColor secondaryStrokeColor READ secondaryStrokeColor WRITE setSecondaryStrokeColor )
49  Q_PROPERTY( int width READ width WRITE setWidth )
50 
52  enum IconType
53  {
54 
59 
64 
69 
74 
79 
84 
90 
96  };
97 
107 
113  void setColor( const QColor &color );
114 
120  void setFillColor( const QColor &color );
121 
125  QColor fillColor() const { return mBrush.color(); }
126 
132  void setStrokeColor( const QColor &color );
133 
137  QColor strokeColor() const { return mPen.color(); }
138 
145  void setSecondaryStrokeColor( const QColor &color );
146 
150  QColor secondaryStrokeColor() const { return mSecondaryPen.color(); }
151 
156  void setWidth( int width );
157 
161  int width() const { return mPen.width(); }
162 
167  void setIcon( IconType icon );
168 
169 
173  IconType icon() const { return mIconType; }
174 
178  void setIconSize( int iconSize );
179 
183  int iconSize() const { return mIconSize; }
184 
188  void setLineStyle( Qt::PenStyle penStyle );
189 
193  void setBrushStyle( Qt::BrushStyle brushStyle );
194 
200  void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
201 
210  void addPoint( const QgsPointXY &p, bool doUpdate = true, int geometryIndex = 0 );
211 
219  void closePoints( bool doUpdate = true, int geometryIndex = 0 );
220 
227  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
228 
232  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
233 
238  void movePoint( const QgsPointXY &p, int geometryIndex = 0 );
239 
244  void movePoint( int index, const QgsPointXY &p, int geometryIndex = 0 );
245 
251  int partSize( int geometryIndex ) const;
252 
261  void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
262 
272  void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
273 
278  void setToCanvasRectangle( QRect rect );
279 
291  void addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer );
292 
301  void addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
302 
308  void setTranslationOffset( double dx, double dy );
309 
314  int size() const;
315 
320  int numberOfVertices() const;
321 
327  const QgsPointXY *getPoint( int i, int j = 0 ) const;
328 
333  QgsGeometry asGeometry() const;
334 
335  void updatePosition() override;
336 
337  protected:
338 
343  void paint( QPainter *p ) override;
344 
350  void drawShape( QPainter *p, const QVector<QPointF> &pts );
351 
353  void updateRect();
354 
355  private:
356  QBrush mBrush;
357  QPen mPen;
358  QPen mSecondaryPen;
359 
361  int mIconSize = 5;
362 
364  IconType mIconType = ICON_CIRCLE;
365 
369  QList< QList <QgsPointXY> > mPoints;
371  double mTranslationOffsetX = 0.0;
372  double mTranslationOffsetY = 0.0;
373 
374  QgsRubberBand();
375 
376  static QgsPolylineXY getPolyline( const QList<QgsPointXY> &points );
377 
378 };
379 
380 #endif
A cross is used to highlight points (x)
Definition: qgsrubberband.h:68
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
IconType icon() const
Returns the current icon type to highlight point geometries.
A class to represent a 2D point.
Definition: qgspointxy.h:43
An abstract class for items that can be placed on the map canvas.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
A diamond is used to highlight points (◇)
Definition: qgsrubberband.h:89
const QgsCoordinateReferenceSystem & crs
A cross is used to highlight points (+)
Definition: qgsrubberband.h:63
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
int width() const
Returns the current width of the line or stroke width for polygon.
A circle is used to highlight points (○)
Definition: qgsrubberband.h:78
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:40
QColor fillColor() const
Returns the current fill color.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window&#39;s toolbar icons.
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
QColor secondaryStrokeColor() const
Returns the current secondary stroke color.
A box is used to highlight points (□)
Definition: qgsrubberband.h:73
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:49
int iconSize() const
Returns the current icon size of the point icons.
This class represents a coordinate reference system (CRS).
A diamond is used to highlight points (◆)
Definition: qgsrubberband.h:95
No icon is used.
Definition: qgsrubberband.h:58
QColor strokeColor() const
Returns the current stroke color.
Represents a vector layer which manages a vector based data sets.
virtual void updatePosition()
called on changed extent or resize event to update position of the item
A full box is used to highlight points (■)
Definition: qgsrubberband.h:83