2007-01-09 02:39:15 +00:00
class QgsRubberBand: QgsMapCanvasItem
{
%TypeHeaderCode
#include <qgsrubberband.h>
%End
public:
2016-02-14 03:50:23 +01:00
2014-11-21 01:17:21 +01:00
/** Icons */
2012-12-25 14:12:24 +01:00
enum IconType
{
2014-01-27 09:22:24 +01:00
/**
* No icon is used
*/
2012-12-25 14:12:24 +01:00
ICON_NONE,
2014-01-27 09:22:24 +01:00
/**
* A cross is used to highlight points (+)
*/
2012-12-25 14:12:24 +01:00
ICON_CROSS,
2014-01-27 09:22:24 +01:00
/**
* A cross is used to highlight points (x)
*/
2012-12-25 14:12:24 +01:00
ICON_X,
2014-01-27 09:22:24 +01:00
/**
* A box is used to highlight points (□)
*/
2012-12-25 14:12:24 +01:00
ICON_BOX,
2014-01-27 09:22:24 +01:00
/**
* A circle is used to highlight points (○)
*/
2013-10-29 07:17:52 +01:00
ICON_CIRCLE,
2014-01-27 09:22:24 +01:00
/**
* A full box is used to highlight points (■)
*/
2013-10-29 07:17:52 +01:00
ICON_FULL_BOX
2012-12-25 14:12:24 +01:00
};
2014-01-27 09:22:24 +01:00
/**
* Creates a new RubberBand.
* @param mapCanvas The map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
2016-08-04 09:10:08 +02:00
* @param geometryType Defines how the data should be drawn onto the screen. (Use QgsWkbTypes::LineGeometry, QgsWkbTypes::PolygonGeometry or QgsWkbTypes::PointGeometry)
2014-01-27 09:22:24 +01:00
*/
2016-08-04 09:10:08 +02:00
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
2007-01-09 02:39:15 +00:00
~QgsRubberBand();
2014-01-27 09:22:24 +01:00
/**
* Set the color for the rubberband
* @param color The color used to render this rubberband
*/
2012-09-24 02:28:15 +02:00
void setColor( const QColor & color );
2012-12-25 14:12:24 +01:00
2014-10-27 17:11:39 +02:00
/**
* Set the fill color for the rubberband
* @param color The color used to render this rubberband
* @note Added in 2.6
*/
void setFillColor( const QColor & color );
/**
2017-02-22 17:13:57 +10:00
* Set the stroke color for the rubberband
2014-10-27 17:11:39 +02:00
* @param color The color used to render this rubberband
* @note Added in 2.6
*/
2017-02-22 17:13:57 +10:00
void setStrokeColor( const QColor & color );
2014-10-27 17:11:39 +02:00
2014-01-27 09:22:24 +01:00
/**
2017-02-22 17:13:57 +10:00
* Set the width of the line. Stroke width for polygon.
2014-01-27 09:22:24 +01:00
* @param width The width for any lines painted for this rubberband
*/
2012-09-24 02:28:15 +02:00
void setWidth( int width );
2007-01-09 02:39:15 +00:00
2014-01-27 09:22:24 +01:00
/**
* Set the icon type to highlight point geometries.
* @param icon The icon to visualize point geometries
*/
2012-12-25 14:12:24 +01:00
void setIcon( IconType icon );
2014-01-27 09:22:24 +01:00
/**
* Set the size of the point icons
*/
void setIconSize( int iconSize );
2012-12-25 14:12:24 +01:00
2014-01-27 09:22:24 +01:00
/**
2016-02-14 03:50:23 +01:00
* Set the style of the line
*/
2013-09-02 16:34:33 +02:00
void setLineStyle( Qt::PenStyle penStyle );
2014-01-27 09:22:24 +01:00
/**
2016-02-14 03:50:23 +01:00
* Set the style of the brush
*/
2013-09-02 16:34:33 +02:00
void setBrushStyle( Qt::BrushStyle brushStyle );
2014-01-27 09:22:24 +01:00
/**
* Clears all the geometries in this rubberband.
* Sets the representation type according to geometryType.
2016-08-04 09:10:08 +02:00
* @param geometryType Defines how the data should be drawn onto the screen. (Use QgsWkbTypes::LineGeometry, QgsWkbTypes::PolygonGeometry or QgsWkbTypes::PointGeometry)
2014-01-27 09:22:24 +01:00
*/
2016-08-04 09:10:08 +02:00
void reset( QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::LineGeometry );
2008-01-09 16:54:55 +00:00
2014-01-27 09:22:24 +01:00
/**
* 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
* @param p The vertex/point to add
* @param doUpdate Should the map canvas be updated immediately?
* @param geometryIndex The index of the feature part (in case of multipart geometries)
*/
void addPoint( const QgsPoint & p, bool doUpdate = true, int geometryIndex = 0 );
2016-06-15 11:44:23 +10:00
/** Ensures that a polygon geometry is closed and that the last vertex equals the
* first vertex.
* @param doUpdate set to true to update the map canvas immediately
* @param geometryIndex index of the feature part (in case of multipart geometries)
* @note added in QGIS 2.16
*/
void closePoints( bool doUpdate = true, int geometryIndex = 0 );
2014-01-27 09:22:24 +01:00
/**
2016-02-14 03:50:23 +01:00
* Remove a vertex from the rubberband and (optionally) update canvas.
* @param index The index of the vertex/point to remove, negative indexes start at end
* @param doUpdate Should the map canvas be updated immediately?
* @param geometryIndex The index of the feature part (in case of multipart geometries)
*/
2013-04-18 17:50:38 +02:00
void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0 );
2014-01-27 09:22:24 +01:00
/**
* Removes the last point. Most useful in connection with undo operations
*/
2014-11-21 01:17:21 +01:00
void removeLastPoint( int geometryIndex = 0, bool doUpdate = true );
2007-01-09 02:39:15 +00:00
2014-01-27 09:22:24 +01:00
/**
* 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
*/
2012-09-24 02:28:15 +02:00
void movePoint( const QgsPoint & p, int geometryIndex = 0 );
2014-01-27 09:22:24 +01:00
/**
* 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
*/
2012-09-24 02:28:15 +02:00
void movePoint( int index, const QgsPoint& p, int geometryIndex = 0 );
2008-01-24 14:34:05 +00:00
2014-01-27 09:22:24 +01:00
/**
* Returns number of vertices in feature part
* @param geometryIndex The index of the feature part (in case of multipart geometries)
* @return number of vertices
*/
int partSize( int geometryIndex ) const;
/**
* Sets this rubber band to the geometry of an existing feature.
* This is useful for feature highlighting.
* In contrast to {@link addGeometry}, this method does also change the geometry type of the rubberband.
* @param geom the geometry object
* @param 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.
*/
2016-07-31 21:23:07 +10:00
void setToGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
2010-05-16 18:36:20 +00:00
2014-01-27 09:22:24 +01:00
/**
* Sets this rubber band to a map canvas rectangle
* @param rect rectangle in canvas coordinates
*/
2016-02-02 19:46:18 +11:00
void setToCanvasRectangle( QRect rect );
2011-04-28 08:31:01 +00:00
2014-01-27 09:22:24 +01:00
/**
* 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 {@link reset} or {@link setToGeometry} with appropriate arguments.
* {@link setToGeometry} is also to be preferred for backwards-compatibility.
*
* @param geom the geometry object. Will be treated as a collection of vertices.
* @param 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.
*/
2016-07-31 21:23:07 +10:00
void addGeometry( const QgsGeometry& geom, QgsVectorLayer* layer );
2012-09-24 02:28:15 +02:00
2014-01-27 09:22:24 +01:00
/**
* Adds translation to original coordinates (all in map coordinates)
* @param dx x translation
* @param dy y translation
*/
2012-09-24 02:28:15 +02:00
void setTranslationOffset( double dx, double dy );
2008-01-09 16:54:55 +00:00
2014-01-27 09:22:24 +01:00
/**
* Returns number of geometries
* @return number of geometries
*/
2012-09-24 02:28:15 +02:00
int size() const;
2010-05-16 18:36:20 +00:00
2014-01-27 09:22:24 +01:00
/**
* Returns count of vertices in all lists of mPoint
* @return The total number of vertices
*/
2008-01-09 16:54:55 +00:00
int numberOfVertices() const;
2007-09-30 23:45:36 +00:00
2014-01-27 09:22:24 +01:00
/**
* Return vertex
* @param i The geometry index
* @param j The vertex index within geometry i
*/
2012-09-24 02:28:15 +02:00
const QgsPoint *getPoint( int i, int j = 0 ) const;
2014-01-27 09:22:24 +01:00
/**
* Returns the rubberband as a Geometry.
* @return A geometry object which reflects the current state of the rubberband.
*/
2016-08-01 22:39:38 +10:00
QgsGeometry asGeometry() const;
2008-03-13 13:11:53 +00:00
2015-02-03 02:21:52 +01:00
virtual void updatePosition();
2007-01-09 02:39:15 +00:00
protected:
2012-09-24 02:28:15 +02:00
virtual void paint( QPainter* p );
2007-01-09 02:39:15 +00:00
//! recalculates needed rectangle
void updateRect();
};