QGIS API Documentation  2.99.0-Master (11bb234)
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 
35 class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
36 {
37  public:
38 
40  enum IconType
41  {
42 
47 
52 
57 
62 
67 
72 
78 
84  };
85 
92 
97  void setColor( const QColor &color );
98 
104  void setFillColor( const QColor &color );
105 
109  QColor fillColor() const { return mBrush.color(); }
110 
116  void setStrokeColor( const QColor &color );
117 
121  QColor strokeColor() const { return mPen.color(); }
122 
129  void setSecondaryStrokeColor( const QColor &color );
130 
134  QColor secondaryStrokeColor() const { return mSecondaryPen.color(); }
135 
140  void setWidth( int width );
141 
145  int width() const { return mPen.width(); }
146 
151  void setIcon( IconType icon );
152 
153 
157  IconType icon() const { return mIconType; }
158 
162  void setIconSize( int iconSize );
163 
167  int iconSize() const { return mIconSize; }
168 
172  void setLineStyle( Qt::PenStyle penStyle );
173 
177  void setBrushStyle( Qt::BrushStyle brushStyle );
178 
184  void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
185 
194  void addPoint( const QgsPoint &p, bool doUpdate = true, int geometryIndex = 0 );
195 
202  void closePoints( bool doUpdate = true, int geometryIndex = 0 );
203 
210  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
211 
215  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
216 
221  void movePoint( const QgsPoint &p, int geometryIndex = 0 );
222 
227  void movePoint( int index, const QgsPoint &p, int geometryIndex = 0 );
228 
234  int partSize( int geometryIndex ) const;
235 
244  void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
245 
250  void setToCanvasRectangle( QRect rect );
251 
263  void addGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
264 
270  void setTranslationOffset( double dx, double dy );
271 
276  int size() const;
277 
282  int numberOfVertices() const;
283 
289  const QgsPoint *getPoint( int i, int j = 0 ) const;
290 
295  QgsGeometry asGeometry() const;
296 
297  virtual void updatePosition() override;
298 
299  protected:
300 
305  virtual void paint( QPainter *p ) override;
306 
312  void drawShape( QPainter *p, QVector<QPointF> &pts );
313 
315  void updateRect();
316 
317  private:
318  QBrush mBrush;
319  QPen mPen;
320  QPen mSecondaryPen;
321 
323  int mIconSize;
324 
326  IconType mIconType;
327 
331  QList< QList <QgsPoint> > mPoints;
332  QgsWkbTypes::GeometryType mGeometryType;
333  double mTranslationOffsetX;
334  double mTranslationOffsetY;
335 
336  QgsRubberBand();
337 
338  static QgsPolyline getPolyline( const QList<QgsPoint> &points );
339 
340 };
341 
342 #endif
A cross is used to highlight points (x)
Definition: qgsrubberband.h:56
static unsigned index
IconType icon() const
Returns the current icon type to highlight point geometries.
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 diamond is used to highlight points (◇)
Definition: qgsrubberband.h:77
A cross is used to highlight points (+)
Definition: qgsrubberband.h:51
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
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:66
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:35
QColor fillColor() const
Returns the current fill color.
A class to represent a point.
Definition: qgspoint.h:37
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:135
QColor secondaryStrokeColor() const
Returns the current secondary stroke color.
A box is used to highlight points (□)
Definition: qgsrubberband.h:61
int iconSize() const
Returns the current icon size of the point icons.
A diamond is used to highlight points (◆)
Definition: qgsrubberband.h:83
No icon is used.
Definition: qgsrubberband.h:46
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:71