QGIS API Documentation
2.6.0-Brighton
|
A class for drawing transient features (e.g. More...
#include <qgsrubberband.h>
Public Types | |
enum | IconType { ICON_NONE, ICON_CROSS, ICON_X, ICON_BOX, ICON_CIRCLE, ICON_FULL_BOX } |
Icons. 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 | setColor (const QColor &color) |
Set the color for the rubberband. | |
void | setFillColor (const QColor &color) |
Set the fill color for the rubberband. | |
void | setBorderColor (const QColor &color) |
Set the border color for the rubberband. | |
void | setWidth (int width) |
Set the width of the line. | |
void | setIcon (IconType icon) |
Set the icon type to highlight point geometries. | |
void | setIconSize (int iconSize) |
Set the size of the point icons. | |
void | setLineStyle (Qt::PenStyle penStyle) |
Set the style of the line. | |
void | setBrushStyle (Qt::BrushStyle brushStyle) |
Set the style of the brush. | |
void | reset (QGis::GeometryType geometryType=QGis::Line) |
Clears all the geometries in this rubberband. | |
void | reset (bool isPolygon) |
void | addPoint (const QgsPoint &p, bool doUpdate=true, int geometryIndex=0) |
Add a vertex to the rubberband and update canvas. | |
void | removePoint (int index=0, bool doUpdate=true, int geometryIndex=0) |
Remove a vertex from the rubberband and (optionally) update canvas. | |
void | removeLastPoint (int geometryIndex=0, bool doUpdate=true) |
Removes the last point. | |
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 | partSize (int geometryIndex) const |
Returns number of vertices in feature part. | |
void | setToGeometry (QgsGeometry *geom, QgsVectorLayer *layer) |
Sets this rubber band to the geometry of an existing feature. | |
void | setToCanvasRectangle (const QRect &rect) |
Sets this rubber band to a map canvas rectangle. | |
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. | |
int | numberOfVertices () const |
Returns count of vertices in all lists of mPoint. | |
const QgsPoint * | getPoint (int i, int j=0) const |
Return vertex. | |
QgsGeometry * | asGeometry () |
Returns the rubberband as a Geometry. | |
Public Member Functions inherited from QgsMapCanvasItem | |
virtual void | updatePosition () |
called on changed extent or resize event to update position of the item | |
virtual QRectF | boundingRect () const |
default implementation for canvas items | |
Q_DECL_DEPRECATED void | setPanningOffset (const QPoint &point) |
sets current offset, to be called from QgsMapCanvas | |
QgsRectangle | rect () const |
returns canvas item rectangle | |
void | setRect (const QgsRectangle &r) |
sets canvas item rectangle | |
QgsPoint | toMapCoordinates (const QPoint &point) |
transformation from screen coordinates to map coordinates | |
QPointF | toCanvasCoordinates (const QgsPoint &point) |
transformation from map coordinates to screen coordinates |
Protected Member Functions | |
virtual void | paint (QPainter *p) |
void | updateRect () |
recalculates needed rectangle | |
Protected Member Functions inherited from QgsMapCanvasItem | |
QgsMapCanvasItem (QgsMapCanvas *mapCanvas) | |
protected constructor: cannot be constructed directly | |
virtual | ~QgsMapCanvasItem () |
virtual void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) |
paint function called by map canvas | |
void | updateCanvas () |
schedules map canvas for repaint | |
bool | setRenderContextVariables (QPainter *p, QgsRenderContext &context) const |
Sets render context parameters. |
Additional Inherited Members | |
Protected Attributes inherited from QgsMapCanvasItem | |
QgsMapCanvas * | mMapCanvas |
pointer to map canvas | |
QgsRectangle | mRect |
canvas item rectangle (in map coordinates) | |
QPoint | mPanningOffset |
offset from normal position due current panning operation, used when converting map coordinates to move map canvas items | |
QSizeF | mItemSize |
cached size of the item (to return in boundingRect()) |
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
Icons.
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) |
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 |
QgsRubberBand::~QgsRubberBand | ( | ) |
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. |
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.
QgsGeometry * QgsRubberBand::asGeometry | ( | ) |
Returns the rubberband as a Geometry.
const QgsPoint * QgsRubberBand::getPoint | ( | int | i, |
int | j = 0 |
||
) | const |
Return vertex.
i | The geometry index |
j | The vertex index within geometry i |
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.
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
int QgsRubberBand::numberOfVertices | ( | ) | const |
Returns count of vertices in all lists of mPoint.
|
protectedvirtual |
Draw the shape in response to an update event.
Implements QgsMapCanvasItem.
int QgsRubberBand::partSize | ( | int | geometryIndex | ) | const |
Returns number of vertices in feature part.
geometryIndex | The index of the feature part (in case of multipart geometries) |
void QgsRubberBand::removeLastPoint | ( | int | geometryIndex = 0 , |
bool | doUpdate = true |
||
) |
Removes the last point.
Most useful in connection with undo operations
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) |
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.
void QgsRubberBand::reset | ( | bool | isPolygon | ) |
isPolygon | true: draw as (multi-)polygon, false draw as (multi-)linestring |
void QgsRubberBand::setBorderColor | ( | const QColor & | color | ) |
Set the border color for the rubberband.
color | The color used to render this rubberband |
Set the outline
void QgsRubberBand::setBrushStyle | ( | Qt::BrushStyle | brushStyle | ) |
Set the style of the brush.
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.
void QgsRubberBand::setFillColor | ( | const QColor & | color | ) |
Set the fill color for the rubberband.
color | The color used to render this rubberband |
Set the fill color.
void QgsRubberBand::setIcon | ( | IconType | icon | ) |
Set the icon type to highlight point geometries.
icon | The icon to visualize point geometries |
void QgsRubberBand::setIconSize | ( | int | iconSize | ) |
Set the size of the point icons.
void QgsRubberBand::setLineStyle | ( | Qt::PenStyle | penStyle | ) |
Set the style of the line.
void QgsRubberBand::setToCanvasRectangle | ( | const QRect & | rect | ) |
Sets this rubber band to a map canvas rectangle.
rect | rectangle in canvas coordinates |
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. |
void QgsRubberBand::setTranslationOffset | ( | double | dx, |
double | dy | ||
) |
Adds translation to original coordinates (all in map coordinates)
dx | x translation |
dy | y translation |
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.
int QgsRubberBand::size | ( | void | ) | const |
Returns number of geometries.
|
protected |
recalculates needed rectangle