QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  {
62  ICON_FULL_BOX
63  };
64 
70  QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType = QGis::Line );
77  QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon );
78  ~QgsRubberBand();
79 
84  void setColor( const QColor & color );
85 
91  void setFillColor( const QColor & color );
92 
98  void setBorderColor( const QColor & color );
99 
104  void setWidth( int width );
105 
110  void setIcon( IconType icon );
111 
115  void setIconSize( int iconSize );
116 
120  void setLineStyle( Qt::PenStyle penStyle );
121 
125  void setBrushStyle( Qt::BrushStyle brushStyle );
126 
132  void reset( QGis::GeometryType geometryType = QGis::Line );
133 
140  void reset( bool isPolygon );
141 
150  void addPoint( const QgsPoint & p, bool doUpdate = true, int geometryIndex = 0 );
151 
158  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
159 
163  void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
164 
169  void movePoint( const QgsPoint & p, int geometryIndex = 0 );
170 
175  void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
176 
182  int partSize( int geometryIndex ) const;
183 
192  void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
193 
198  void setToCanvasRectangle( const QRect& rect );
199 
211  void addGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
212 
218  void setTranslationOffset( double dx, double dy );
219 
224  int size() const;
225 
230  int numberOfVertices() const;
231 
237  const QgsPoint *getPoint( int i, int j = 0 ) const;
238 
243  QgsGeometry* asGeometry();
244 
245  virtual void updatePosition() override;
246 
247  protected:
248  virtual void paint( QPainter* p ) override;
249 
251  void updateRect();
252 
253  private:
254  QBrush mBrush;
255  QPen mPen;
256 
258  int mIconSize;
259 
261  IconType mIconType;
262 
266  QList< QList <QgsPoint> > mPoints;
267  QGis::GeometryType mGeometryType;
268  double mTranslationOffsetX;
269  double mTranslationOffsetY;
270 
271  QgsRubberBand();
272 
273  static QgsPolyline getPolyline( const QList<QgsPoint> & points );
274 
275 };
276 
277 #endif