QGIS API Documentation  2.0.1-Dufour
 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 
38  enum IconType
39  {
59  ICON_CIRCLE
60  };
61 
68  QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType = QGis::Line );
75  QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon );
76  ~QgsRubberBand();
77 
82  void setColor( const QColor & color );
83 
88  void setWidth( int width );
89 
95  void setIcon( IconType icon );
96 
101  void setIconSize( int iconSize );
102 
107  void setLineStyle( Qt::PenStyle penStyle );
108 
113  void setBrushStyle( Qt::BrushStyle brushStyle );
114 
121  void reset( QGis::GeometryType geometryType = QGis::Line );
122 
129  void reset( bool isPolygon );
130 
139  void addPoint( const QgsPoint & p, bool doUpdate = true, int geometryIndex = 0 );
140 
147  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
148 
152  void removeLastPoint( int geometryIndex = 0 , bool doUpdate = true );
153 
158  void movePoint( const QgsPoint & p, int geometryIndex = 0 );
159 
164  void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
165 
171  int partSize( int geometryIndex ) const;
172 
181  void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
182 
188  void setToCanvasRectangle( const QRect& rect );
189 
202  void addGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
203 
209  void setTranslationOffset( double dx, double dy );
210 
216  int size() const;
217 
222  int numberOfVertices() const;
223 
229  const QgsPoint *getPoint( int i, int j = 0 ) const;
230 
236  QgsGeometry* asGeometry();
237 
238  protected:
239  virtual void paint( QPainter* p );
240 
242  void updateRect();
243 
244  private:
245  QBrush mBrush;
246  QPen mPen;
247 
251 
255 
259  QList< QList <QgsPoint> > mPoints;
263 
264  QgsRubberBand();
265 
266  static QgsPolyline getPolyline( const QList<QgsPoint> & points );
267 
268 };
269 
270 #endif