Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
16 #ifndef QGSRUBBERBAND_H
17 #define QGSRUBBERBAND_H
18 
19 #include "qgsmapcanvasitem.h"
20 #include "qgsgeometry.h"
21 #include <QBrush>
22 #include <QList>
23 #include <QPen>
24 #include <QPolygon>
25 
26 class QgsVectorLayer;
27 class QPaintEvent;
28 
32 class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
33 {
34  public:
35  QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon = false );
36  ~QgsRubberBand();
37 
38  void setColor( const QColor & color );
39  void setWidth( int width );
40 
41  void reset( bool isPolygon = false );
42 
46  void addPoint( const QgsPoint & p, bool update = true, int geometryIndex = 0 );
47 
49  void removeLastPoint( int geometryIndex = 0 );
50 
51  void movePoint( const QgsPoint & p, int geometryIndex = 0 );
54  void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
55 
62  void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
63 
67  void setToCanvasRectangle( const QRect& rect );
68 
76  void addGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
77 
79  void setTranslationOffset( double dx, double dy );
80 
83  int size() const;
84 
86  int numberOfVertices() const;
87 
89  const QgsPoint *getPoint( int i, int j = 0 ) const;
90 
93  QgsGeometry* asGeometry();
94 
95  protected:
96  virtual void paint( QPainter* p );
97 
99  void updateRect();
100 
101  private:
102  QBrush mBrush;
103  QPen mPen;
104 
106  QList< QList <QgsPoint> > mPoints;
110 
111  QgsRubberBand();
112 
113  static QgsPolyline getPolyline( const QList<QgsPoint> & points );
114 
115 };
116 
117 #endif