QGIS API Documentation  2.2.0-Valmiera
 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  {
63  ICON_FULL_BOX
64  };
65 
72  QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType = QGis::Line );
79  QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon );
80  ~QgsRubberBand();
81 
86  void setColor( const QColor & color );
87 
92  void setWidth( int width );
93 
99  void setIcon( IconType icon );
100 
105  void setIconSize( int iconSize );
106 
111  void setLineStyle( Qt::PenStyle penStyle );
112 
117  void setBrushStyle( Qt::BrushStyle brushStyle );
118 
125  void reset( QGis::GeometryType geometryType = QGis::Line );
126 
133  void reset( bool isPolygon );
134 
143  void addPoint( const QgsPoint & p, bool doUpdate = true, int geometryIndex = 0 );
144 
151  void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
152 
156  void removeLastPoint( int geometryIndex = 0 , bool doUpdate = true );
157 
162  void movePoint( const QgsPoint & p, int geometryIndex = 0 );
163 
168  void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
169 
175  int partSize( int geometryIndex ) const;
176 
185  void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
186 
192  void setToCanvasRectangle( const QRect& rect );
193 
206  void addGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
207 
213  void setTranslationOffset( double dx, double dy );
214 
220  int size() const;
221 
226  int numberOfVertices() const;
227 
233  const QgsPoint *getPoint( int i, int j = 0 ) const;
234 
240  QgsGeometry* asGeometry();
241 
242  protected:
243  virtual void paint( QPainter* p );
244 
246  void updateRect();
247 
248  private:
249  QBrush mBrush;
250  QPen mPen;
251 
255 
259 
263  QList< QList <QgsPoint> > mPoints;
267 
268  QgsRubberBand();
269 
270  static QgsPolyline getPolyline( const QList<QgsPoint> & points );
271 
272 };
273 
274 #endif