QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
22 #include <QBrush>
23 #include <QList>
24 #include <QPen>
25 #include <QPolygon>
26 #include <QObject>
27 
28 #include "qgis_gui.h"
29 
30 class QgsVectorLayer;
31 class QPaintEvent;
32 
33 #ifdef SIP_RUN
34 % ModuleHeaderCode
35 // For ConvertToSubClassCode.
36 #include <qgsrubberband.h>
37 % End
38 #endif
39 
47 class GUI_EXPORT QgsRubberBand : public QObject, public QgsMapCanvasItem
48 {
49  Q_OBJECT
50 
51 #ifdef SIP_RUN
53  if ( dynamic_cast<QgsRubberBand *>( sipCpp ) )
54  sipType = sipType_QgsRubberBand;
55  else
56  sipType = nullptr;
57  SIP_END
58 #endif
59  public:
60 
61  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
62  Q_PROPERTY( QColor strokeColor READ strokeColor WRITE setStrokeColor )
63  Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
64  Q_PROPERTY( QColor secondaryStrokeColor READ secondaryStrokeColor WRITE setSecondaryStrokeColor )
65  Q_PROPERTY( int width READ width WRITE setWidth )
66 
68  enum IconType
69  {
70 
75 
80 
85 
90 
95 
100 
106 
112  };
113 
123 
129  void setColor( const QColor &color );
130 
136  void setFillColor( const QColor &color );
137 
141  QColor fillColor() const { return mBrush.color(); }
142 
148  void setStrokeColor( const QColor &color );
149 
153  QColor strokeColor() const { return mPen.color(); }
154 
161  void setSecondaryStrokeColor( const QColor &color );
162 
166  QColor secondaryStrokeColor() const { return mSecondaryPen.color(); }
167 
172  void setWidth( int width );
173 
177  int width() const { return mPen.width(); }
178 
183  void setIcon( IconType icon );
184 
185 
189  IconType icon() const { return mIconType; }
190 
194  void setIconSize( int iconSize );
195 
199  int iconSize() const { return mIconSize; }
200 
204  void setLineStyle( Qt::PenStyle penStyle );
205 
209  void setBrushStyle( Qt::BrushStyle brushStyle );
210 
216  void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
217 
226  void addPoint( const QgsPointXY &p, bool doUpdate = true, int geometryIndex = 0 );
227 
235  void closePoints( bool doUpdate = true, int geometryIndex = 0 );
236 
243  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
244 
248  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
249 
254  void movePoint( const QgsPointXY &p, int geometryIndex = 0 );
255 
260  void movePoint( int index, const QgsPointXY &p, int geometryIndex = 0 );
261 
267  int partSize( int geometryIndex ) const;
268 
277  void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
278 
288  void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
289 
294  void setToCanvasRectangle( QRect rect );
295 
307  void addGeometry( const QgsGeometry &geometry, QgsVectorLayer *layer );
308 
317  void addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
318 
324  void setTranslationOffset( double dx, double dy );
325 
330  int size() const;
331 
336  int numberOfVertices() const;
337 
343  const QgsPointXY *getPoint( int i, int j = 0 ) const;
344 
349  QgsGeometry asGeometry() const;
350 
351  void updatePosition() override;
352 
353  protected:
354 
359  void paint( QPainter *p ) override;
360 
366  void drawShape( QPainter *p, const QVector<QPointF> &pts );
367 
369  void updateRect();
370 
371  private:
372  QBrush mBrush;
373  QPen mPen;
374  QPen mSecondaryPen;
375 
377  int mIconSize = 5;
378 
380  IconType mIconType = ICON_CIRCLE;
381 
385  QList< QList <QgsPointXY> > mPoints;
387  double mTranslationOffsetX = 0.0;
388  double mTranslationOffsetY = 0.0;
389 
390  QgsRubberBand();
391 
392  static QgsPolylineXY getPolyline( const QList<QgsPointXY> &points );
393 
394 };
395 
396 #endif
A cross is used to highlight points (x)
Definition: qgsrubberband.h:84
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A class to represent a 2D point.
Definition: qgspointxy.h:43
QColor fillColor() const
Returns the current fill color.
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:106
A diamond is used to highlight points (◇)
const QgsCoordinateReferenceSystem & crs
A cross is used to highlight points (+)
Definition: qgsrubberband.h:79
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
QColor secondaryStrokeColor() const
Returns the current secondary stroke color.
IconType icon() const
Returns the current icon type to highlight point geometries.
A circle is used to highlight points (○)
Definition: qgsrubberband.h:94
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:47
#define SIP_END
Definition: qgis_sip.h:182
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:138
A box is used to highlight points (□)
Definition: qgsrubberband.h:89
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:44
This class represents a coordinate reference system (CRS).
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
A diamond is used to highlight points (◆)
int width() const
Returns the current width of the line or stroke width for polygon.
No icon is used.
Definition: qgsrubberband.h:74
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
QColor strokeColor() const
Returns the current stroke color.
A full box is used to highlight points (■)
Definition: qgsrubberband.h:99
int iconSize() const
Returns the current icon size of the point icons.