QGIS API Documentation  2.99.0-Master (b681b7b)
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 #include "qgis_gui.h"
25 
26 class QgsVectorLayer;
27 class QPaintEvent;
28 
33 class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
34 {
35  public:
36 
38  enum IconType
39  {
40 
45 
50 
55 
60 
65 
69  ICON_FULL_BOX
70  };
71 
78 
83  void setColor( const QColor & color );
84 
90  void setFillColor( const QColor & color );
91 
97  void setStrokeColor( 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:54
static unsigned index
QVector< QgsPoint > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:47
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:79
A cross is used to highlight points (+)
Definition: qgsrubberband.h:49
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
A circle is used to highlight points (○)
Definition: qgsrubberband.h:64
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:33
A class to represent a point.
Definition: qgspoint.h:36
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:131
A box is used to highlight points (□)
Definition: qgsrubberband.h:59
No icon is used.
Definition: qgsrubberband.h:44
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