QGIS API Documentation  3.2.0-Bonn (bc43194)
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.h"
20 #include "qgsgeometry.h"
21 #include <QBrush>
22 #include <QList>
23 #include <QPen>
24 #include <QPolygon>
25 #include "qgis_gui.h"
26 
27 class QgsVectorLayer;
28 class QPaintEvent;
29 
37 class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
38 {
39  public:
40 
42  enum IconType
43  {
44 
49 
54 
59 
64 
69 
74 
80 
86  };
87 
94 
99  void setColor( const QColor &color );
100 
106  void setFillColor( const QColor &color );
107 
111  QColor fillColor() const { return mBrush.color(); }
112 
118  void setStrokeColor( const QColor &color );
119 
123  QColor strokeColor() const { return mPen.color(); }
124 
131  void setSecondaryStrokeColor( const QColor &color );
132 
136  QColor secondaryStrokeColor() const { return mSecondaryPen.color(); }
137 
142  void setWidth( int width );
143 
147  int width() const { return mPen.width(); }
148 
153  void setIcon( IconType icon );
154 
155 
159  IconType icon() const { return mIconType; }
160 
164  void setIconSize( int iconSize );
165 
169  int iconSize() const { return mIconSize; }
170 
174  void setLineStyle( Qt::PenStyle penStyle );
175 
179  void setBrushStyle( Qt::BrushStyle brushStyle );
180 
186  void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
187 
196  void addPoint( const QgsPointXY &p, bool doUpdate = true, int geometryIndex = 0 );
197 
205  void closePoints( bool doUpdate = true, int geometryIndex = 0 );
206 
213  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
214 
218  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
219 
224  void movePoint( const QgsPointXY &p, int geometryIndex = 0 );
225 
230  void movePoint( int index, const QgsPointXY &p, int geometryIndex = 0 );
231 
237  int partSize( int geometryIndex ) const;
238 
247  void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
248 
253  void setToCanvasRectangle( QRect rect );
254 
266  void addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer );
267 
276  void addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
277 
283  void setTranslationOffset( double dx, double dy );
284 
289  int size() const;
290 
295  int numberOfVertices() const;
296 
302  const QgsPointXY *getPoint( int i, int j = 0 ) const;
303 
308  QgsGeometry asGeometry() const;
309 
310  void updatePosition() override;
311 
312  protected:
313 
318  void paint( QPainter *p ) override;
319 
325  void drawShape( QPainter *p, const QVector<QPointF> &pts );
326 
328  void updateRect();
329 
330  private:
331  QBrush mBrush;
332  QPen mPen;
333  QPen mSecondaryPen;
334 
336  int mIconSize = 5;
337 
339  IconType mIconType = ICON_CIRCLE;
340 
344  QList< QList <QgsPointXY> > mPoints;
346  double mTranslationOffsetX = 0.0;
347  double mTranslationOffsetY = 0.0;
348 
349  QgsRubberBand();
350 
351  static QgsPolylineXY getPolyline( const QList<QgsPointXY> &points );
352 
353 };
354 
355 #endif
A cross is used to highlight points (x)
Definition: qgsrubberband.h:58
#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:104
A diamond is used to highlight points (◇)
Definition: qgsrubberband.h:79
A cross is used to highlight points (+)
Definition: qgsrubberband.h:53
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
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:68
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:37
QColor fillColor() const
Returns the current fill color.
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:137
QColor secondaryStrokeColor() const
Returns the current secondary stroke color.
A box is used to highlight points (□)
Definition: qgsrubberband.h:63
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:42
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:85
No icon is used.
Definition: qgsrubberband.h:48
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:73