QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsrubberband.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrubberband.h - Rubberband widget for drawing multilines and polygons
3 --------------------------------------
4 Date : 07-Jan-2006
5 Copyright : (C) 2006 by Tom Elwertowski
6 Email : telwertowski at users dot sourceforge dot net
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSRUBBERBAND_H
16#define QGSRUBBERBAND_H
17
18#include "qgsmapcanvasitem.h"
19#include "qgis_sip.h"
20#include "qgsgeometry.h"
22
23#include <QBrush>
24#include <QVector>
25#include <QPen>
26#include <QPolygon>
27#include <QObject>
28#include <QSvgRenderer>
29
30#include "qgis_gui.h"
31
32class QgsMapLayer;
33class QgsVectorLayer;
34class QgsMapLayer;
35class QPaintEvent;
36class QgsSymbol;
37
38#ifdef SIP_RUN
39% ModuleHeaderCode
40// For ConvertToSubClassCode.
41#include <qgsrubberband.h>
42% End
43#endif
44
52#ifndef SIP_RUN
53class GUI_EXPORT QgsRubberBand : public QObject, public QgsMapCanvasItem
54{
55#else
56class GUI_EXPORT QgsRubberBand : public QgsMapCanvasItem
57{
58#endif
59 Q_OBJECT
60
61#ifdef SIP_RUN
63 if ( dynamic_cast<QgsRubberBand *>( sipCpp ) )
64 {
65 sipType = sipType_QgsRubberBand;
66 // We need to tweak the pointer as sip believes it is single inheritance
67 // from QgsMapCanvasItem, but the raw address of QgsRubberBand (sipCpp)
68 // is actually a QObject
69 *sipCppRet = dynamic_cast<QgsRubberBand *>( sipCpp );
70 }
71 else
72 sipType = nullptr;
74#endif
75 public:
76
77 Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
78 Q_PROPERTY( QColor strokeColor READ strokeColor WRITE setStrokeColor )
79 Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
80 Q_PROPERTY( QColor secondaryStrokeColor READ secondaryStrokeColor WRITE setSecondaryStrokeColor )
81 Q_PROPERTY( int width READ width WRITE setWidth )
82
135
145 ~QgsRubberBand() override;
146
152 void setColor( const QColor &color );
153
159 void setFillColor( const QColor &color );
160
164 QColor fillColor() const { return mBrush.color(); }
165
171 void setStrokeColor( const QColor &color );
172
176 QColor strokeColor() const { return mPen.color(); }
177
184 void setSecondaryStrokeColor( const QColor &color );
185
189 QColor secondaryStrokeColor() const { return mSecondaryPen.color(); }
190
195 void setWidth( int width );
196
200 int width() const { return mPen.width(); }
201
206 void setIcon( IconType icon );
207
215 void setSvgIcon( const QString &path, QPoint drawOffset );
216
217
221 IconType icon() const { return mIconType; }
222
226 void setIconSize( int iconSize );
227
231 int iconSize() const { return mIconSize; }
232
236 void setLineStyle( Qt::PenStyle penStyle );
237
241 void setBrushStyle( Qt::BrushStyle brushStyle );
242
248 void reset( Qgis::GeometryType geometryType = Qgis::GeometryType::Line );
249
259 void addPoint( const QgsPointXY &p, bool doUpdate = true, int geometryIndex = 0, int ringIndex = 0 );
260
269 void closePoints( bool doUpdate = true, int geometryIndex = 0, int ringIndex = 0 );
270
278 void removePoint( int index = 0, bool doUpdate = true, int geometryIndex = 0, int ringIndex = 0 );
279
283 void removeLastPoint( int geometryIndex = 0, bool doUpdate = true, int ringIndex = 0 );
284
289 void movePoint( const QgsPointXY &p, int geometryIndex = 0, int ringIndex = 0 );
290
295 void movePoint( int index, const QgsPointXY &p, int geometryIndex = 0, int ringIndex = 0 );
296
302 int partSize( int geometryIndex ) const;
303
312 void setToGeometry( const QgsGeometry &geom, QgsVectorLayer *layer );
313
323 void setToGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
324
329 void setToCanvasRectangle( QRect rect );
330
336 void copyPointsFrom( const QgsRubberBand *other );
337
352 void addGeometry( const QgsGeometry &geometry, QgsMapLayer *layer, bool doUpdate = true );
353
365 void addGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem(), bool doUpdate = true );
366
372 void setTranslationOffset( double dx, double dy );
373
378 int size() const;
379
384 int numberOfVertices() const;
385
386 // TODO QGIS 4: rename i to geometryIndex, j to vertexIndex
387 // TODO QGIS 4: reorder parameters to geom, ring, ring
388
395 const QgsPointXY *getPoint( int i, int j = 0, int ringIndex = 0 ) const;
396
401 QgsGeometry asGeometry() const;
402
403 void updatePosition() override;
404
411 QgsSymbol *symbol() const;
412
426 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
427
428 protected:
429
434 void paint( QPainter *p ) override;
435
441 void drawShape( QPainter *p, const QVector<QPointF> &pts );
442
448 void drawShape( QPainter *p, const QVector<QPolygonF> &rings );
449
451 void updateRect();
452
453 private:
454 QBrush mBrush;
455 QPen mPen;
456 QPen mSecondaryPen;
457
459 int mIconSize = 5;
460
462 IconType mIconType = ICON_CIRCLE;
463 std::unique_ptr<QSvgRenderer> mSvgRenderer;
464 QPoint mSvgOffset;
465
466 std::unique_ptr< QgsSymbol > mSymbol;
467
471 QVector< QVector< QVector <QgsPointXY> > > mPoints;
473 double mTranslationOffsetX = 0.0;
474 double mTranslationOffsetY = 0.0;
475
477
478};
479
480#endif
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
@ Polygon
Polygons.
This class represents a coordinate reference system (CRS).
A geometry is the spatial representation of a feature.
An abstract class for items that can be placed on the map canvas.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:74
A class to represent a 2D point.
Definition qgspointxy.h:59
A class for drawing transient features (e.g.
~QgsRubberBand() override
QColor fillColor() const
Returns the current fill color.
IconType icon() const
Returns the current icon type to highlight point geometries.
@ ICON_X
A cross is used to highlight points (x)
@ ICON_FULL_DIAMOND
A diamond is used to highlight points (◆)
@ ICON_FULL_BOX
A full box is used to highlight points (■)
@ ICON_NONE
No icon is used.
@ ICON_CROSS
A cross is used to highlight points (+)
@ ICON_CIRCLE
A circle is used to highlight points (○)
@ ICON_DIAMOND
A diamond is used to highlight points (◇)
@ ICON_BOX
A box is used to highlight points (□)
QColor secondaryStrokeColor() const
Returns the current secondary stroke color.
int iconSize() const
Returns the current icon size of the point icons.
int width() const
Returns the current width of the line or stroke width for polygon.
QColor strokeColor() const
Returns the current stroke color.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:94
Represents a vector layer which manages a vector based data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:186
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_END
Definition qgis_sip.h:203
const QgsCoordinateReferenceSystem & crs