QGIS API Documentation  2.99.0-Master (dcec6bb)
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 
36 class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
37 {
38  public:
39 
41  enum IconType
42  {
43 
48 
53 
58 
63 
68 
73 
79 
85  };
86 
93 
98  void setColor( const QColor &color );
99 
105  void setFillColor( const QColor &color );
106 
110  QColor fillColor() const { return mBrush.color(); }
111 
117  void setStrokeColor( const QColor &color );
118 
122  QColor strokeColor() const { return mPen.color(); }
123 
130  void setSecondaryStrokeColor( const QColor &color );
131 
135  QColor secondaryStrokeColor() const { return mSecondaryPen.color(); }
136 
141  void setWidth( int width );
142 
146  int width() const { return mPen.width(); }
147 
152  void setIcon( IconType icon );
153 
154 
158  IconType icon() const { return mIconType; }
159 
163  void setIconSize( int iconSize );
164 
168  int iconSize() const { return mIconSize; }
169 
173  void setLineStyle( Qt::PenStyle penStyle );
174 
178  void setBrushStyle( Qt::BrushStyle brushStyle );
179 
185  void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
186 
195  void addPoint( const QgsPointXY &p, bool doUpdate = true, int geometryIndex = 0 );
196 
203  void closePoints( bool doUpdate = true, int geometryIndex = 0 );
204 
211  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
212 
216  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
217 
222  void movePoint( const QgsPointXY &p, int geometryIndex = 0 );
223 
228  void movePoint( int index, const QgsPointXY &p, int geometryIndex = 0 );
229 
235  int partSize( int geometryIndex ) const;
236 
245  void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
246 
251  void setToCanvasRectangle( QRect rect );
252 
264  void addGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
265 
271  void setTranslationOffset( double dx, double dy );
272 
277  int size() const;
278 
283  int numberOfVertices() const;
284 
290  const QgsPointXY *getPoint( int i, int j = 0 ) const;
291 
296  QgsGeometry asGeometry() const;
297 
298  virtual void updatePosition() override;
299 
300  protected:
301 
306  virtual void paint( QPainter *p ) override;
307 
313  void drawShape( QPainter *p, QVector<QPointF> &pts );
314 
316  void updateRect();
317 
318  private:
319  QBrush mBrush;
320  QPen mPen;
321  QPen mSecondaryPen;
322 
324  int mIconSize;
325 
327  IconType mIconType;
328 
332  QList< QList <QgsPointXY> > mPoints;
333  QgsWkbTypes::GeometryType mGeometryType;
334  double mTranslationOffsetX;
335  double mTranslationOffsetY;
336 
337  QgsRubberBand();
338 
339  static QgsPolyline getPolyline( const QList<QgsPointXY> &points );
340 
341 };
342 
343 #endif
A cross is used to highlight points (x)
Definition: qgsrubberband.h:57
#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:42
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:96
A diamond is used to highlight points (◇)
Definition: qgsrubberband.h:78
A cross is used to highlight points (+)
Definition: qgsrubberband.h:52
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
QVector< QgsPointXY > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:48
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:67
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:36
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:136
QColor secondaryStrokeColor() const
Returns the current secondary stroke color.
A box is used to highlight points (□)
Definition: qgsrubberband.h:62
int iconSize() const
Returns the current icon size of the point icons.
A diamond is used to highlight points (◆)
Definition: qgsrubberband.h:84
No icon is used.
Definition: qgsrubberband.h:47
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:72