QGIS API Documentation  2.99.0-Master (08ee180)
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 "qgsgeometry.h"
20 #include <QBrush>
21 #include <QList>
22 #include <QPen>
23 #include <QPolygon>
24 
25 class QgsVectorLayer;
26 class QPaintEvent;
27 
32 class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
33 {
34  public:
35 
37  enum IconType
38  {
39 
44 
49 
54 
59 
64 
68  ICON_FULL_BOX
69  };
70 
77  ~QgsRubberBand();
78 
83  void setColor( const QColor & color );
84 
90  void setFillColor( const QColor & color );
91 
97  void setBorderColor( const QColor & color );
98 
103  void setWidth( int width );
104 
109  void setIcon( IconType icon );
110 
114  void setIconSize( int iconSize );
115 
119  void setLineStyle( Qt::PenStyle penStyle );
120 
124  void setBrushStyle( Qt::BrushStyle brushStyle );
125 
131  void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
132 
141  void addPoint( const QgsPoint & p, bool doUpdate = true, int geometryIndex = 0 );
142 
149  void closePoints( bool doUpdate = true, int geometryIndex = 0 );
150 
157  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
158 
162  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
163 
168  void movePoint( const QgsPoint & p, int geometryIndex = 0 );
169 
174  void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
175 
181  int partSize( int geometryIndex ) const;
182 
191  void setToGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
192 
197  void setToCanvasRectangle( QRect rect );
198 
210  void addGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
211 
217  void setTranslationOffset( double dx, double dy );
218 
223  int size() const;
224 
229  int numberOfVertices() const;
230 
236  const QgsPoint *getPoint( int i, int j = 0 ) const;
237 
242  QgsGeometry asGeometry() const;
243 
244  virtual void updatePosition() override;
245 
246  protected:
247  virtual void paint( QPainter* p ) override;
248 
250  void updateRect();
251 
252  private:
253  QBrush mBrush;
254  QPen mPen;
255 
257  int mIconSize;
258 
260  IconType mIconType;
261 
265  QList< QList <QgsPoint> > mPoints;
266  QgsWkbTypes::GeometryType mGeometryType;
267  double mTranslationOffsetX;
268  double mTranslationOffsetY;
269 
270  QgsRubberBand();
271 
272  static QgsPolyline getPolyline( const QList<QgsPoint> & points );
273 
274 };
275 
276 #endif
A cross is used to highlight points (x)
Definition: qgsrubberband.h:53
static unsigned index
QVector< QgsPoint > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:46
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:78
A cross is used to highlight points (+)
Definition: qgsrubberband.h:48
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:106
A circle is used to highlight points (○)
Definition: qgsrubberband.h:63
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:32
A class to represent a point.
Definition: qgspoint.h:111
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
A box is used to highlight points (□)
Definition: qgsrubberband.h:58
No icon is used.
Definition: qgsrubberband.h:43
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