QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
QgsRubberBand Class Reference

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]

Public Types

enum  IconType {
  ICON_NONE, ICON_CROSS, ICON_X, ICON_BOX,
  ICON_CIRCLE, ICON_FULL_BOX
}
 Icons Added in 1.9. More...
 

Public Member Functions

 QgsRubberBand (QgsMapCanvas *mapCanvas, QGis::GeometryType geometryType=QGis::Line)
 Creates a new RubberBand. More...
 
 QgsRubberBand (QgsMapCanvas *mapCanvas, bool isPolygon)
 Creates a new RubberBand. More...
 
 ~QgsRubberBand ()
 
void setColor (const QColor &color)
 Set the color for the rubberband. More...
 
void setFillColor (const QColor &color)
 Set the file color for the rubberband. More...
 
void setBorderColor (const QColor &color)
 Set the border color for the rubberband. More...
 
void setWidth (int width)
 Set the width of the line. More...
 
void setIcon (IconType icon)
 Set the icon type to highlight point geometries. More...
 
void setIconSize (int iconSize)
 Set the size of the point icons. More...
 
void setLineStyle (Qt::PenStyle penStyle)
 Set the style of the line. More...
 
void setBrushStyle (Qt::BrushStyle brushStyle)
 Set the style of the brush. More...
 
void reset (QGis::GeometryType geometryType=QGis::Line)
 Clears all the geometries in this rubberband. More...
 
void reset (bool isPolygon)
 
void addPoint (const QgsPoint &p, bool doUpdate=true, int geometryIndex=0)
 Add a vertex to the rubberband and update canvas. More...
 
void removePoint (int index=0, bool doUpdate=true, int geometryIndex=0)
 Remove a vertex from the rubberband and (optionally) update canvas. More...
 
void removeLastPoint (int geometryIndex=0, bool doUpdate=true)
 Removes the last point. More...
 
void movePoint (const QgsPoint &p, int geometryIndex=0)
 Moves the rubber band point specified by index. More...
 
void movePoint (int index, const QgsPoint &p, int geometryIndex=0)
 Moves the rubber band point specified by index. More...
 
int partSize (int geometryIndex) const
 Returns number of vertices in feature part. More...
 
void setToGeometry (QgsGeometry *geom, QgsVectorLayer *layer)
 Sets this rubber band to the geometry of an existing feature. More...
 
void setToCanvasRectangle (const QRect &rect)
 Sets this rubber band to a map canvas rectangle. More...
 
void addGeometry (QgsGeometry *geom, QgsVectorLayer *layer)
 Add the geometry of an existing feature to a rubberband This is useful for multi feature highlighting. More...
 
void setTranslationOffset (double dx, double dy)
 Adds translation to original coordinates (all in map coordinates) More...
 
int size () const
 Returns number of geometries. More...
 
int numberOfVertices () const
 Returns count of vertices in all lists of mPoint. More...
 
const QgsPointgetPoint (int i, int j=0) const
 Return vertex. More...
 
QgsGeometryasGeometry ()
 Returns the rubberband as a Geometry. More...
 
- Public Member Functions inherited from QgsMapCanvasItem
virtual void updatePosition ()
 called on changed extent or resize event to update position of the item More...
 
virtual QRectF boundingRect () const
 default implementation for canvas items More...
 
Q_DECL_DEPRECATED void setPanningOffset (const QPoint &point)
 sets current offset, to be called from QgsMapCanvas More...
 
QgsRectangle rect () const
 returns canvas item rectangle More...
 
void setRect (const QgsRectangle &r)
 sets canvas item rectangle More...
 
QgsPoint toMapCoordinates (const QPoint &point)
 transformation from screen coordinates to map coordinates More...
 
QPointF toCanvasCoordinates (const QgsPoint &point)
 transformation from map coordinates to screen coordinates More...
 

Protected Member Functions

virtual void paint (QPainter *p)
 
void updateRect ()
 recalculates needed rectangle More...
 
- Protected Member Functions inherited from QgsMapCanvasItem
 QgsMapCanvasItem (QgsMapCanvas *mapCanvas)
 protected constructor: cannot be constructed directly More...
 
virtual ~QgsMapCanvasItem ()
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
 paint function called by map canvas More...
 
void updateCanvas ()
 schedules map canvas for repaint More...
 
bool setRenderContextVariables (QPainter *p, QgsRenderContext &context) const
 Sets render context parameters. More...
 

Private Member Functions

 QgsRubberBand ()
 

Static Private Member Functions

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

Private Attributes

QBrush mBrush
 
QPen mPen
 
int mIconSize
 The size of the icon for points. More...
 
IconType mIconType
 Icon to be shown. More...
 
QList< QList< QgsPoint > > mPoints
 Nested lists used for multitypes. More...
 
QGis::GeometryType mGeometryType
 
double mTranslationOffsetX
 
double mTranslationOffsetY
 

Additional Inherited Members

- Protected Attributes inherited from QgsMapCanvasItem
QgsMapCanvasmMapCanvas
 pointer to map canvas More...
 
QgsRectangle mRect
 canvas item rectangle (in map coordinates) More...
 
QPoint mPanningOffset
 offset from normal position due current panning operation, used when converting map coordinates to move map canvas items More...
 
QSizeF mItemSize
 cached size of the item (to return in boundingRect()) More...
 

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. It may be used

Definition at line 32 of file qgsrubberband.h.

Member Enumeration Documentation

Icons Added in 1.9.

Enumerator
ICON_NONE 

No icon is used.

ICON_CROSS 

A cross is used to highlight points (+)

ICON_X 

A cross is used to highlight points (x)

ICON_BOX 

A box is used to highlight points (□)

ICON_CIRCLE 

A circle is used to highlight points (○)

ICON_FULL_BOX 

A full box is used to highlight points (■)

Definition at line 38 of file qgsrubberband.h.

Constructor & Destructor Documentation

QgsRubberBand::QgsRubberBand ( QgsMapCanvas mapCanvas,
QGis::GeometryType  geometryType = QGis::Line 
)

Creates a new RubberBand.

Parameters
mapCanvasThe map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
geometryTypeDefines how the data should be drawn onto the screen. (Use QGis::Line, QGis::Polygon or QGis::Point)
Note
Added in 1.9.

Definition at line 30 of file qgsrubberband.cpp.

References reset(), setBrushStyle(), setColor(), setLineStyle(), and setWidth().

QgsRubberBand::QgsRubberBand ( QgsMapCanvas mapCanvas,
bool  isPolygon 
)

Creates a new RubberBand.

Deprecated:
Use the constructor which takes QGis::GeometryType as second argument instead
Parameters
mapCanvasThe map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
isPolygontrue: draw as (multi-)polygon, false draw as (multi-)linestring

Definition at line 47 of file qgsrubberband.cpp.

References QGis::Line, QGis::Polygon, reset(), setBrushStyle(), setColor(), setLineStyle(), and setWidth().

QgsRubberBand::~QgsRubberBand ( )

Definition at line 67 of file qgsrubberband.cpp.

QgsRubberBand::QgsRubberBand ( )
private

Definition at line 63 of file qgsrubberband.cpp.

Member Function Documentation

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

Add the geometry of an existing feature to a rubberband This is useful for multi feature highlighting.

As of 2.0, this method does not change the GeometryType any more. You need to set the GeometryType of the rubberband explicitly by calling reset or setToGeometry with appropriate arguments. setToGeometry is also to be preferred for backwards-compatibility.

Parameters
geomthe geometry object. Will be treated as a collection of vertices.
layerthe layer containing the feature, used for coord transformation to map crs. In case of 0 pointer, the coordinates are not going to be transformed.
Note
added in 1.5

Definition at line 267 of file qgsrubberband.cpp.

References addPoint(), QgsGeometry::asMultiPoint(), QgsGeometry::asMultiPolygon(), QgsGeometry::asMultiPolyline(), QgsGeometry::asPoint(), QgsGeometry::asPolygon(), QgsGeometry::asPolyline(), QgsMapSettings::layerToMapCoordinates(), QgsMapCanvas::mapSettings(), QgsMapCanvasItem::mMapCanvas, mPoints, removeLastPoint(), updateRect(), QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, QgsGeometry::wkbType(), and QGis::WKBUnknown.

Referenced by setToGeometry().

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

Add a vertex to the rubberband and update canvas.

The rendering of the vertex depends on the current GeometryType and icon. If adding more points consider using update=false for better performance

Parameters
pThe vertex/point to add
doUpdateShould the map canvas be updated immediately?
geometryIndexThe index of the feature part (in case of multipart geometries)

Add a point to the shape being created.

Definition at line 149 of file qgsrubberband.cpp.

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

Referenced by addGeometry(), and setToCanvasRectangle().

QgsGeometry * QgsRubberBand::asGeometry ( )

Returns the rubberband as a Geometry.

Returns
A geometry object which reflects the current state of the rubberband.
Note
Added in 1.6

Definition at line 597 of file qgsrubberband.cpp.

References QgsGeometry::fromMultiPoint(), QgsGeometry::fromMultiPolyline(), QgsGeometry::fromPolygon(), QgsGeometry::fromPolyline(), getPolyline(), QGis::Line, mGeometryType, mPoints, QGis::Point, and QGis::Polygon.

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

Return vertex.

Parameters
iThe geometry index
jThe vertex index within geometry i

Definition at line 589 of file qgsrubberband.cpp.

References mPoints.

QgsPolyline QgsRubberBand::getPolyline ( const QList< QgsPoint > &  points)
staticprivate

Definition at line 654 of file qgsrubberband.cpp.

Referenced by asGeometry().

void QgsRubberBand::movePoint ( 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

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

Definition at line 219 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 237 of file qgsrubberband.cpp.

References index, mPoints, and updateRect().

int QgsRubberBand::numberOfVertices ( ) const

Returns count of vertices in all lists of mPoint.

Returns
The total number of vertices

Definition at line 574 of file qgsrubberband.cpp.

References mPoints.

void QgsRubberBand::paint ( QPainter *  p)
protectedvirtual
int QgsRubberBand::partSize ( int  geometryIndex) const

Returns number of vertices in feature part.

Parameters
geometryIndexThe index of the feature part (in case of multipart geometries)
Returns
number of vertices

Definition at line 568 of file qgsrubberband.cpp.

References mPoints.

void QgsRubberBand::removeLastPoint ( int  geometryIndex = 0,
bool  doUpdate = true 
)

Removes the last point.

Most useful in connection with undo operations

Definition at line 211 of file qgsrubberband.cpp.

References removePoint().

Referenced by addGeometry().

void QgsRubberBand::removePoint ( int  index = 0,
bool  doUpdate = true,
int  geometryIndex = 0 
)

Remove a vertex from the rubberband and (optionally) update canvas.

Parameters
indexThe index of the vertex/point to remove, negative indexes start at end
doUpdateShould the map canvas be updated immediately?
geometryIndexThe index of the feature part (in case of multipart geometries)

Definition at line 185 of file qgsrubberband.cpp.

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

Referenced by removeLastPoint().

void QgsRubberBand::reset ( QGis::GeometryType  geometryType = QGis::Line)

Clears all the geometries in this rubberband.

Sets the representation type according to geometryType.

Parameters
geometryTypeDefines how the data should be drawn onto the screen. (Use QGis::Line, QGis::Polygon or QGis::Point)
Note
Added in 1.9.

Remove all points from the shape being created.

Definition at line 130 of file qgsrubberband.cpp.

References mGeometryType, mPoints, and updateRect().

Referenced by QgsRubberBand(), setToCanvasRectangle(), and setToGeometry().

void QgsRubberBand::reset ( bool  isPolygon)
Deprecated:
Use the reset method which takes QGis::GeometryType as second argument instead Clears all the geometries in this rubberband. Sets the representation type according to isPolygon.
Parameters
isPolygontrue: draw as (multi-)polygon, false draw as (multi-)linestring

Definition at line 138 of file qgsrubberband.cpp.

References QGis::Line, mGeometryType, mPoints, QGis::Polygon, and updateRect().

void QgsRubberBand::setBorderColor ( const QColor &  color)

Set the border color for the rubberband.

Parameters
colorThe color used to render this rubberband

Set the outline

Definition at line 92 of file qgsrubberband.cpp.

References mPen.

Referenced by setColor().

void QgsRubberBand::setBrushStyle ( Qt::BrushStyle  brushStyle)

Set the style of the brush.

Note
Added in 1.9

Definition at line 122 of file qgsrubberband.cpp.

References mBrush.

Referenced by QgsRubberBand().

void QgsRubberBand::setColor ( const QColor &  color)

Set the color for the rubberband.

Parameters
colorThe color used to render this rubberband

Set the outline and fill color.

Definition at line 74 of file qgsrubberband.cpp.

References setBorderColor(), and setFillColor().

Referenced by QgsMapToolZoom::canvasMoveEvent(), and QgsRubberBand().

void QgsRubberBand::setFillColor ( const QColor &  color)

Set the file color for the rubberband.

Parameters
colorThe color used to render this rubberband

Set the fill color.

Definition at line 83 of file qgsrubberband.cpp.

References mBrush.

Referenced by setColor().

void QgsRubberBand::setIcon ( IconType  icon)

Set the icon type to highlight point geometries.

Parameters
iconThe icon to visualize point geometries
Note
Added in 1.9

Definition at line 107 of file qgsrubberband.cpp.

References icon(), and mIconType.

void QgsRubberBand::setIconSize ( int  iconSize)

Set the size of the point icons.

Note
Added in 1.9

Definition at line 112 of file qgsrubberband.cpp.

References mIconSize.

void QgsRubberBand::setLineStyle ( Qt::PenStyle  penStyle)

Set the style of the line.

Note
Added in 1.9

Definition at line 117 of file qgsrubberband.cpp.

References mPen.

Referenced by QgsRubberBand().

void QgsRubberBand::setToCanvasRectangle ( const QRect &  rect)

Sets this rubber band to a map canvas rectangle.

Parameters
rectrectangle in canvas coordinates
Note
added in version 1.7

Definition at line 419 of file qgsrubberband.cpp.

References addPoint(), QgsMapCanvas::getCoordinateTransform(), QgsMapCanvasItem::mMapCanvas, QGis::Polygon, reset(), QgsMapToPixel::toMapCoordinates(), QgsPoint::x(), and QgsPoint::y().

Referenced by QgsMapToolZoom::canvasMoveEvent().

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

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

This is useful for feature highlighting. In contrast to addGeometry, this method does also change the geometry type of the rubberband.

Parameters
geomthe geometry object
layerthe 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 255 of file qgsrubberband.cpp.

References addGeometry(), mGeometryType, reset(), and QgsGeometry::type().

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

Adds translation to original coordinates (all in map coordinates)

Parameters
dxx translation
dyy translation

Definition at line 556 of file qgsrubberband.cpp.

References mTranslationOffsetX, mTranslationOffsetY, and updateRect().

void QgsRubberBand::setWidth ( int  width)

Set the width of the line.

Outline width for polygon.

Parameters
widthThe width for any lines painted for this rubberband

Set the outline width.

Definition at line 102 of file qgsrubberband.cpp.

References mPen.

Referenced by QgsRubberBand().

int QgsRubberBand::size ( void  ) const

Returns number of geometries.

Returns
number of geometries
Note
added in 1.5

Definition at line 563 of file qgsrubberband.cpp.

References mPoints.

Referenced by addPoint(), and removePoint().

void QgsRubberBand::updateRect ( )
protected

Member Data Documentation

QBrush QgsRubberBand::mBrush
private

Definition at line 261 of file qgsrubberband.h.

Referenced by paint(), setBrushStyle(), and setFillColor().

QGis::GeometryType QgsRubberBand::mGeometryType
private

Definition at line 276 of file qgsrubberband.h.

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

int QgsRubberBand::mIconSize
private

The size of the icon for points.

Note
Added in 1.9

Definition at line 266 of file qgsrubberband.h.

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

IconType QgsRubberBand::mIconType
private

Icon to be shown.

Note
Added in 1.9

Definition at line 270 of file qgsrubberband.h.

Referenced by paint(), and setIcon().

QPen QgsRubberBand::mPen
private

Definition at line 262 of file qgsrubberband.h.

Referenced by paint(), setBorderColor(), setLineStyle(), setWidth(), and updateRect().

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

Nested lists used for multitypes.

Definition at line 275 of file qgsrubberband.h.

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

double QgsRubberBand::mTranslationOffsetX
private

Definition at line 277 of file qgsrubberband.h.

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

double QgsRubberBand::mTranslationOffsetY
private

Definition at line 278 of file qgsrubberband.h.

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


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