QGIS API Documentation  2.6.0-Brighton
 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  protected:
246  virtual void paint( QPainter* p );
247 
249  void updateRect();
250 
251  private:
252  QBrush mBrush;
253  QPen mPen;
254 
256  int mIconSize;
257 
259  IconType mIconType;
260 
264  QList< QList <QgsPoint> > mPoints;
265  QGis::GeometryType mGeometryType;
266  double mTranslationOffsetX;
267  double mTranslationOffsetY;
268 
269  QgsRubberBand();
270 
271  static QgsPolyline getPolyline( const QList<QgsPoint> & points );
272 
273 };
274 
275 #endif