|
Quantum GIS API Documentation
master-ce49b66
|
A class for drawing transient features (e.g. More...
#include <qgsrubberband.h>
Inheritance diagram for QgsRubberBand:
Collaboration diagram for QgsRubberBand:Public Types | |
| enum | IconType { ICON_NONE, ICON_CROSS, ICON_X, ICON_BOX, ICON_CIRCLE } |
| Icons Added in 1.9. More... | |
Public Member Functions | |
| QgsRubberBand (QgsMapCanvas *mapCanvas, QGis::GeometryType geometryType=QGis::Line) | |
| Creates a new RubberBand. | |
| QgsRubberBand (QgsMapCanvas *mapCanvas, bool isPolygon) | |
| Creates a new RubberBand. | |
| ~QgsRubberBand () | |
| void | addGeometry (QgsGeometry *geom, QgsVectorLayer *layer) |
| Add the geometry of an existing feature to a rubberband This is useful for multi feature highlighting. | |
| void | addPoint (const QgsPoint &p, bool doUpdate=true, int geometryIndex=0) |
| Add a vertex to the rubberband and update canvas. | |
| QgsGeometry * | asGeometry () |
| Returns the rubberband as a Geometry. | |
| const QgsPoint * | getPoint (int i, int j=0) const |
| Return vertex. | |
| void | movePoint (const QgsPoint &p, int geometryIndex=0) |
| Moves the rubber band point specified by index. | |
| void | movePoint (int index, const QgsPoint &p, int geometryIndex=0) |
| Moves the rubber band point specified by index. | |
| int | numberOfVertices () const |
| Returns count of vertices in all lists of mPoint. | |
| void | removeLastPoint (int geometryIndex=0) |
| Removes the last point. | |
| void | removePoint (int index=0, bool doUpdate=true, int geometryIndex=0) |
| Remove a vertex from the rubberband and (optionally) update canvas. | |
| void | reset (QGis::GeometryType geometryType=QGis::Line) |
| Clears all the geometries in this rubberband. | |
| void | reset (bool isPolygon) |
| void | setColor (const QColor &color) |
| Set the color for the rubberband. | |
| void | setIcon (IconType icon) |
| Set the icon type to highlight point geometries. | |
| void | setIconSize (int iconSize) |
| Set the size of the point icons. | |
| void | setToCanvasRectangle (const QRect &rect) |
| Sets this rubber band to a map canvas rectangle. | |
| void | setToGeometry (QgsGeometry *geom, QgsVectorLayer *layer) |
| Sets this rubber band to the geometry of an existing feature. | |
| void | setTranslationOffset (double dx, double dy) |
| Adds translation to original coordinates (all in map coordinates) | |
| void | setWidth (int width) |
| Set the width of the line. | |
| int | size () const |
| Returns number of geometries. | |
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 |
| QGis::GeometryType | mGeometryType |
| int | mIconSize |
| The size of the icon for points. | |
| IconType | mIconType |
| Icon to be shown. | |
| QPen | mPen |
| QList< QList< QgsPoint > > | mPoints |
| Nested lists used for multitypes. | |
| double | mTranslationOffsetX |
| double | mTranslationOffsetY |
| int | mWidth |
| The width of any line within the rubberband. | |
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.
Icons Added in 1.9.
Definition at line 38 of file qgsrubberband.h.
| QgsRubberBand::QgsRubberBand | ( | QgsMapCanvas * | mapCanvas, |
| QGis::GeometryType | geometryType = QGis::Line |
||
| ) |
Creates a new RubberBand.
| mapCanvas | The map canvas to draw onto. It's CRS will be used map points onto screen coordinates. |
| geometryType | Defines how the data should be drawn onto the screen. (Use QGis::Line, QGis::Polygon or QGis::Point) |
Definition at line 30 of file qgsrubberband.cpp.
References reset(), and setColor().
| QgsRubberBand::QgsRubberBand | ( | QgsMapCanvas * | mapCanvas, |
| bool | isPolygon | ||
| ) |
Creates a new RubberBand.
| mapCanvas | The map canvas to draw onto. It's CRS will be used map points onto screen coordinates. |
| isPolygon | true: draw as (multi-)polygon, false draw as (multi-)linestring |
Definition at line 43 of file qgsrubberband.cpp.
References QGis::Line, QGis::Polygon, reset(), and setColor().
Definition at line 59 of file qgsrubberband.cpp.
| QgsRubberBand::QgsRubberBand | ( | ) | [private] |
Definition at line 55 of file qgsrubberband.cpp.
| 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.
| geom | the geometry object. Will be treated as a collection of vertices. |
| 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 226 of file qgsrubberband.cpp.
References addPoint(), QgsGeometry::asMultiPoint(), QgsGeometry::asMultiPolygon(), QgsGeometry::asMultiPolyline(), QgsGeometry::asPoint(), QgsGeometry::asPolygon(), QgsGeometry::asPolyline(), QgsMapRenderer::layerToMapCoordinates(), QgsMapCanvas::mapRenderer(), QgsMapCanvasItem::mMapCanvas, mPoints, 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
| p | The vertex/point to add |
| doUpdate | Should the map canvas be updated immediately? |
| geometryIndex | The index of the feature part (in case of multipart geometries) |
Add a point to the shape being created.
Definition at line 114 of file qgsrubberband.cpp.
References mPoints, size(), and updateRect().
Referenced by addGeometry(), and setToCanvasRectangle().
Returns the rubberband as a Geometry.
Definition at line 547 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.
| i | The geometry index |
| j | The vertex index within geometry i |
Definition at line 539 of file qgsrubberband.cpp.
References mPoints.
| QgsPolyline QgsRubberBand::getPolyline | ( | const QList< QgsPoint > & | points | ) | [static, private] |
Definition at line 604 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 184 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 202 of file qgsrubberband.cpp.
References mPoints, and updateRect().
| int QgsRubberBand::numberOfVertices | ( | ) | const |
Returns count of vertices in all lists of mPoint.
Definition at line 524 of file qgsrubberband.cpp.
References mPoints.
| void QgsRubberBand::paint | ( | QPainter * | p | ) | [protected, virtual] |
Draw the shape in response to an update event.
Implements QgsMapCanvasItem.
Definition at line 400 of file qgsrubberband.cpp.
References ICON_BOX, ICON_CIRCLE, ICON_CROSS, ICON_NONE, ICON_X, QGis::Line, mBrush, mGeometryType, mIconSize, mIconType, mPen, mPoints, mTranslationOffsetX, mTranslationOffsetY, mWidth, QGis::Point, QGis::Polygon, and QgsMapCanvasItem::toCanvasCoordinates().
| void QgsRubberBand::removeLastPoint | ( | int | geometryIndex = 0 | ) |
Removes the last point.
Most useful in connection with undo operations
Definition at line 176 of file qgsrubberband.cpp.
References removePoint().
| void QgsRubberBand::removePoint | ( | int | index = 0, |
| bool | doUpdate = true, |
||
| int | geometryIndex = 0 |
||
| ) |
Remove a vertex from the rubberband and (optionally) update canvas.
| index | The index of the vertex/point to remove, negative indexes start at end |
| doUpdate | Should the map canvas be updated immediately? |
| geometryIndex | The index of the feature part (in case of multipart geometries) |
Definition at line 150 of file qgsrubberband.cpp.
References 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.
| geometryType | Defines how the data should be drawn onto the screen. (Use QGis::Line, QGis::Polygon or QGis::Point) |
Remove all points from the shape being created.
Definition at line 95 of file qgsrubberband.cpp.
References mGeometryType, mPoints, and updateRect().
Referenced by QgsRubberBand(), setToCanvasRectangle(), and setToGeometry().
| void QgsRubberBand::reset | ( | bool | isPolygon | ) |
Sets the representation type according to isPolygon.
| isPolygon | true: draw as (multi-)polygon, false draw as (multi-)linestring |
Definition at line 103 of file qgsrubberband.cpp.
References QGis::Line, mGeometryType, mPoints, QGis::Polygon, and updateRect().
| void QgsRubberBand::setColor | ( | const QColor & | color | ) |
Set the color for the rubberband.
| color | The color used to render this rubberband |
Set the outline and fill color.
Definition at line 66 of file qgsrubberband.cpp.
Referenced by QgsRubberBand().
| void QgsRubberBand::setIcon | ( | IconType | icon | ) |
Set the icon type to highlight point geometries.
| icon | The icon to visualize point geometries |
Definition at line 82 of file qgsrubberband.cpp.
| void QgsRubberBand::setIconSize | ( | int | iconSize | ) |
Set the size of the point icons.
Definition at line 87 of file qgsrubberband.cpp.
References mIconSize.
| void QgsRubberBand::setToCanvasRectangle | ( | const QRect & | rect | ) |
Sets this rubber band to a map canvas rectangle.
| rect | rectangle in canvas coordinates |
Definition at line 379 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.
| 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 220 of file qgsrubberband.cpp.
References addGeometry(), reset(), and QgsGeometry::type().
| void QgsRubberBand::setTranslationOffset | ( | double | dx, |
| double | dy | ||
| ) |
Adds translation to original coordinates (all in map coordinates)
| dx | x translation |
| dy | y translation |
Definition at line 512 of file qgsrubberband.cpp.
References mTranslationOffsetX, mTranslationOffsetY, and updateRect().
| void QgsRubberBand::setWidth | ( | int | width | ) |
Set the width of the line.
Outline width for polygon.
| width | The width for any lines painted for this rubberband |
Set the outline width.
Definition at line 77 of file qgsrubberband.cpp.
References mWidth.
| int QgsRubberBand::size | ( | void | ) | const |
Returns number of geometries.
Definition at line 519 of file qgsrubberband.cpp.
References mPoints.
Referenced by addPoint(), and removePoint().
| void QgsRubberBand::updateRect | ( | ) | [protected] |
recalculates needed rectangle
Definition at line 477 of file qgsrubberband.cpp.
References QgsRectangle::combineExtentWith(), mIconSize, mPoints, mTranslationOffsetX, mTranslationOffsetY, mWidth, QgsMapCanvasItem::rect(), and QgsMapCanvasItem::setRect().
Referenced by addGeometry(), addPoint(), movePoint(), removePoint(), reset(), and setTranslationOffset().
QBrush QgsRubberBand::mBrush [private] |
Definition at line 226 of file qgsrubberband.h.
Referenced by paint(), and setColor().
Definition at line 244 of file qgsrubberband.h.
Referenced by asGeometry(), paint(), and reset().
int QgsRubberBand::mIconSize [private] |
The size of the icon for points.
Definition at line 234 of file qgsrubberband.h.
Referenced by paint(), setIconSize(), and updateRect().
IconType QgsRubberBand::mIconType [private] |
QPen QgsRubberBand::mPen [private] |
Definition at line 227 of file qgsrubberband.h.
Referenced by paint(), and setColor().
QList< QList <QgsPoint> > QgsRubberBand::mPoints [private] |
Nested lists used for multitypes.
Definition at line 243 of file qgsrubberband.h.
Referenced by addGeometry(), addPoint(), asGeometry(), getPoint(), movePoint(), numberOfVertices(), paint(), removePoint(), reset(), size(), and updateRect().
double QgsRubberBand::mTranslationOffsetX [private] |
Definition at line 245 of file qgsrubberband.h.
Referenced by paint(), setTranslationOffset(), and updateRect().
double QgsRubberBand::mTranslationOffsetY [private] |
Definition at line 246 of file qgsrubberband.h.
Referenced by paint(), setTranslationOffset(), and updateRect().
int QgsRubberBand::mWidth [private] |
The width of any line within the rubberband.
Definition at line 230 of file qgsrubberband.h.
Referenced by paint(), setWidth(), and updateRect().