QgsRubberBand Class Reference
[QGIS gui library.]

A class for drawing transient features (e.g. More...

#include <qgsrubberband.h>

Inheritance diagram for QgsRubberBand:

Inheritance graph
[legend]
Collaboration diagram for QgsRubberBand:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 QgsRubberBand (QgsMapCanvas *mapCanvas, bool isPolygon=false)
 ~QgsRubberBand ()
void setColor (const QColor &color)
void setWidth (int width)
void reset (bool isPolygon=false)
void addPoint (const QgsPoint &p, bool update=true, int geometryIndex=0)
 Add point to rubberband and update canvas If adding more points consider using update=false for better performance geometryIndex is the index of the feature part (in case of multipart geometries).
void removeLastPoint (int geometryIndex=0)
 Removes the last point. Most useful in connection with undo operations.
void movePoint (const QgsPoint &p, int geometryIndex=0)
void movePoint (int index, const QgsPoint &p, int geometryIndex=0)
 Moves the rubber band point specified by index.
void setToGeometry (QgsGeometry *geom, QgsVectorLayer *layer)
 Sets this rubber band to the geometry of an existing feature.
void addGeometry (QgsGeometry *geom, QgsVectorLayer *layer)
 Add the geometry of an existing feature to a rubberband This is useful for multi feature highlighting.
void setTranslationOffset (double dx, double dy)
 Adds translation to original coordinates (all in map coordinates).
int size () const
 Returns number of geometries added in 1.5.
int numberOfVertices () const
 Returns count of vertices in all lists of mPoint.
const QgsPointgetPoint (int i, int j=0) const
 Return vertex.
QgsGeometryasGeometry ()
 Returns the rubberband as a Geometry.

Protected Member Functions

virtual void paint (QPainter *p)
void updateRect ()
 recalculates needed rectangle

Private Member Functions

 QgsRubberBand ()

Static Private Member Functions

static QgsPolyline getPolyline (const QList< QgsPoint > &points)

Private Attributes

QBrush mBrush
QPen mPen
QList< QList< QgsPoint > > mPoints
 Nested lists used for multitypes.
bool mIsPolygon
double mTranslationOffsetX
double mTranslationOffsetY


Detailed Description

A class for drawing transient features (e.g.

The QgsRubberBand class provides a transparent overlay widget for tracking the mouse while drawing polylines or polygons.

digitising lines) on the map.

Definition at line 32 of file qgsrubberband.h.


Constructor & Destructor Documentation

QgsRubberBand::QgsRubberBand ( QgsMapCanvas mapCanvas,
bool  isPolygon = false 
)

Definition at line 31 of file qgsrubberband.cpp.

References reset(), and setColor().

QgsRubberBand::~QgsRubberBand (  ) 

Definition at line 41 of file qgsrubberband.cpp.

QgsRubberBand::QgsRubberBand (  )  [private]

Definition at line 38 of file qgsrubberband.cpp.


Member Function Documentation

void QgsRubberBand::setColor ( const QColor &  color  ) 

Set the outline and fill color.

Definition at line 47 of file qgsrubberband.cpp.

References mBrush, and mPen.

Referenced by QgsRubberBand().

void QgsRubberBand::setWidth ( int  width  ) 

Set the outline width.

Definition at line 58 of file qgsrubberband.cpp.

References mPen.

void QgsRubberBand::reset ( bool  isPolygon = false  ) 

Remove all points from the shape being created.

Definition at line 66 of file qgsrubberband.cpp.

References mIsPolygon, mPoints, and updateRect().

Referenced by QgsRubberBand(), and setToGeometry().

void QgsRubberBand::addPoint ( const QgsPoint p,
bool  do_update = true,
int  geometryIndex = 0 
)

Add point to rubberband and update canvas If adding more points consider using update=false for better performance geometryIndex is the index of the feature part (in case of multipart geometries).

Add a point to the shape being created.

Definition at line 77 of file qgsrubberband.cpp.

References mPoints, size(), and updateRect().

Referenced by addGeometry().

void QgsRubberBand::removeLastPoint ( int  geometryIndex = 0  ) 

Removes the last point. Most useful in connection with undo operations.

Definition at line 108 of file qgsrubberband.cpp.

References mPoints, size(), and updateRect().

void QgsRubberBand::movePoint ( const QgsPoint p,
int  geometryIndex = 0 
)

Update the line between the last added point and the mouse position.

Definition at line 127 of file qgsrubberband.cpp.

References mPoints, and updateRect().

void QgsRubberBand::movePoint ( int  index,
const QgsPoint p,
int  geometryIndex = 0 
)

Moves the rubber band point specified by index.

Note that if the rubber band is not used to track the last mouse position, the first point of the rubber band has two vertices

Definition at line 145 of file qgsrubberband.cpp.

References mPoints, and updateRect().

void QgsRubberBand::setToGeometry ( QgsGeometry geom,
QgsVectorLayer layer 
)

Sets this rubber band to the geometry of an existing feature.

This is useful for feature highlighting.

Parameters:
geom the geometry object
layer the layer containing the feature, used for coord transformation to map crs. In case of 0 pointer, the coordinates are not going to be transformed.

Definition at line 163 of file qgsrubberband.cpp.

References addGeometry(), mIsPolygon, and reset().

void QgsRubberBand::addGeometry ( QgsGeometry geom,
QgsVectorLayer layer 
)

void QgsRubberBand::setTranslationOffset ( double  dx,
double  dy 
)

Adds translation to original coordinates (all in map coordinates).

Definition at line 400 of file qgsrubberband.cpp.

References mTranslationOffsetX, mTranslationOffsetY, and updateRect().

int QgsRubberBand::size ( void   )  const

Returns number of geometries added in 1.5.

Definition at line 407 of file qgsrubberband.cpp.

References mPoints.

Referenced by addPoint(), and removeLastPoint().

int QgsRubberBand::numberOfVertices (  )  const

Returns count of vertices in all lists of mPoint.

Definition at line 412 of file qgsrubberband.cpp.

References mPoints.

const QgsPoint * QgsRubberBand::getPoint ( int  i,
int  j = 0 
) const

Return vertex.

Definition at line 427 of file qgsrubberband.cpp.

References mPoints.

QgsGeometry * QgsRubberBand::asGeometry (  ) 

Returns the rubberband as a Geometry.

added in 1.6

Definition at line 435 of file qgsrubberband.cpp.

References QgsGeometry::fromMultiPolyline(), QgsGeometry::fromPolygon(), QgsGeometry::fromPolyline(), getPolyline(), mIsPolygon, and mPoints.

void QgsRubberBand::paint ( QPainter *  p  )  [protected, virtual]

Draw the shape in response to an update event.

Implements QgsMapCanvasItem.

Definition at line 338 of file qgsrubberband.cpp.

References mBrush, mIsPolygon, mPen, mPoints, mTranslationOffsetX, mTranslationOffsetY, and QgsMapCanvasItem::toCanvasCoordinates().

void QgsRubberBand::updateRect (  )  [protected]

QgsPolyline QgsRubberBand::getPolyline ( const QList< QgsPoint > &  points  )  [static, private]

Definition at line 471 of file qgsrubberband.cpp.

Referenced by asGeometry().


Member Data Documentation

QBrush QgsRubberBand::mBrush [private]

Definition at line 97 of file qgsrubberband.h.

Referenced by paint(), and setColor().

QPen QgsRubberBand::mPen [private]

Definition at line 98 of file qgsrubberband.h.

Referenced by paint(), setColor(), and setWidth().

QList< QList <QgsPoint> > QgsRubberBand::mPoints [private]

Nested lists used for multitypes.

Definition at line 101 of file qgsrubberband.h.

Referenced by addGeometry(), addPoint(), asGeometry(), getPoint(), movePoint(), numberOfVertices(), paint(), removeLastPoint(), reset(), size(), and updateRect().

bool QgsRubberBand::mIsPolygon [private]

Definition at line 102 of file qgsrubberband.h.

Referenced by addGeometry(), asGeometry(), paint(), reset(), and setToGeometry().

Definition at line 103 of file qgsrubberband.h.

Referenced by paint(), setTranslationOffset(), and updateRect().

Definition at line 104 of file qgsrubberband.h.

Referenced by paint(), setTranslationOffset(), and updateRect().


The documentation for this class was generated from the following files:

Generated on Sat Feb 4 19:17:50 2012 for Quantum GIS API Documentation by  doxygen 1.5.6