QGIS API Documentation  2.99.0-Master (19b062c)
qgsrubberband.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrubberband.cpp - 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 
16 #include "qgsrubberband.h"
17 #include "qgsfeature.h"
18 #include "qgsgeometry.h"
19 #include "qgslogger.h"
20 #include "qgsmapcanvas.h"
21 #include "qgsvectorlayer.h"
22 #include <QPainter>
23 
25  : QgsMapCanvasItem( mapCanvas )
26  , mGeometryType( geometryType )
27 {
28  reset( geometryType );
29  QColor color( Qt::lightGray );
30  color.setAlpha( 63 );
31  setColor( color );
32  setWidth( 1 );
33  setLineStyle( Qt::SolidLine );
34  setBrushStyle( Qt::SolidPattern );
35  setSecondaryStrokeColor( QColor() );
36 }
37 
39  : QgsMapCanvasItem( nullptr )
40 {
41 }
42 
43 void QgsRubberBand::setColor( const QColor &color )
44 {
45  setStrokeColor( color );
46  setFillColor( color );
47 }
48 
49 void QgsRubberBand::setFillColor( const QColor &color )
50 {
51  mBrush.setColor( color );
52 }
53 
54 void QgsRubberBand::setStrokeColor( const QColor &color )
55 {
56  mPen.setColor( color );
57 }
58 
59 void QgsRubberBand::setSecondaryStrokeColor( const QColor &color )
60 {
61  mSecondaryPen.setColor( color );
62 }
63 
65 {
66  mPen.setWidth( width );
67 }
68 
70 {
71  mIconType = icon;
72 }
73 
75 {
76  mIconSize = iconSize;
77 }
78 
79 void QgsRubberBand::setLineStyle( Qt::PenStyle penStyle )
80 {
81  mPen.setStyle( penStyle );
82 }
83 
84 void QgsRubberBand::setBrushStyle( Qt::BrushStyle brushStyle )
85 {
86  mBrush.setStyle( brushStyle );
87 }
88 
90 {
91  mPoints.clear();
92  mGeometryType = geometryType;
93  updateRect();
94  update();
95 }
96 
97 void QgsRubberBand::addPoint( const QgsPointXY &p, bool doUpdate /* = true */, int geometryIndex )
98 {
99  if ( geometryIndex < 0 )
100  {
101  geometryIndex = mPoints.size() - 1;
102  }
103 
104  if ( geometryIndex < 0 || geometryIndex > mPoints.size() )
105  {
106  return;
107  }
108 
109  if ( geometryIndex == mPoints.size() )
110  {
111  mPoints.push_back( QList<QgsPointXY>() << p );
112  }
113 
114  if ( mPoints.at( geometryIndex ).size() == 2 &&
115  mPoints.at( geometryIndex ).at( 0 ) == mPoints.at( geometryIndex ).at( 1 ) )
116  {
117  mPoints[geometryIndex].last() = p;
118  }
119  else
120  {
121  mPoints[geometryIndex] << p;
122  }
123 
124 
125  if ( doUpdate )
126  {
127  setVisible( true );
128  updateRect();
129  update();
130  }
131 }
132 
133 void QgsRubberBand::closePoints( bool doUpdate, int geometryIndex )
134 {
135  if ( geometryIndex < 0 || geometryIndex >= mPoints.size() )
136  {
137  return;
138  }
139 
140  if ( mPoints.at( geometryIndex ).at( 0 ) != mPoints.at( geometryIndex ).at( mPoints.at( geometryIndex ).size() - 1 ) )
141  {
142  mPoints[geometryIndex] << mPoints.at( geometryIndex ).at( 0 );
143  }
144 
145  if ( doUpdate )
146  {
147  setVisible( true );
148  updateRect();
149  update();
150  }
151 }
152 
153 
154 void QgsRubberBand::removePoint( int index, bool doUpdate/* = true*/, int geometryIndex/* = 0*/ )
155 {
156 
157  if ( mPoints.size() < geometryIndex + 1 )
158  {
159  return;
160  }
161 
162 
163  if ( !mPoints[geometryIndex].isEmpty() )
164  {
165  // negative index removes from end, e.g., -1 removes last one
166  if ( index < 0 )
167  {
168  index = mPoints.at( geometryIndex ).size() + index;
169  }
170  mPoints[geometryIndex].removeAt( index );
171  }
172 
173  if ( doUpdate )
174  {
175  updateRect();
176  update();
177  }
178 }
179 
180 void QgsRubberBand::removeLastPoint( int geometryIndex, bool doUpdate/* = true*/ )
181 {
182  removePoint( -1, doUpdate, geometryIndex );
183 }
184 
185 void QgsRubberBand::movePoint( const QgsPointXY &p, int geometryIndex )
186 {
187  if ( mPoints.size() < geometryIndex + 1 )
188  {
189  return;
190  }
191 
192  if ( mPoints.at( geometryIndex ).empty() )
193  {
194  return;
195  }
196 
197  mPoints[geometryIndex].last() = p;
198 
199  updateRect();
200  update();
201 }
202 
203 void QgsRubberBand::movePoint( int index, const QgsPointXY &p, int geometryIndex )
204 {
205  if ( mPoints.size() < geometryIndex + 1 )
206  {
207  return;
208  }
209 
210  if ( mPoints.at( geometryIndex ).size() < index )
211  {
212  return;
213  }
214 
215  mPoints[geometryIndex][index] = p;
216 
217  updateRect();
218  update();
219 }
220 
222 {
223  if ( geom.isNull() )
224  {
225  reset( mGeometryType );
226  return;
227  }
228 
229  reset( geom.type() );
230  addGeometry( geom, layer );
231 }
232 
234 {
235  QgsGeometry geom = geometry;
236  if ( layer )
237  {
239  geom.transform( ct );
240  }
241 
242  addGeometry( geom );
243 }
244 
246 {
247  if ( geometry.isEmpty() )
248  {
249  return;
250  }
251 
252  //maprender object of canvas
253  const QgsMapSettings &ms = mMapCanvas->mapSettings();
254 
255  int idx = mPoints.size();
256 
257  QgsGeometry geom = geometry;
258  if ( crs.isValid() )
259  {
260  QgsCoordinateTransform ct( crs, ms.destinationCrs() );
261  geom.transform( ct );
262  }
263 
264  switch ( QgsWkbTypes::flatType( geom.wkbType() ) )
265  {
266 
267  case QgsWkbTypes::Point:
269  {
270  QgsPointXY pt = geom.asPoint();
271  addPoint( pt, false, idx );
272  removeLastPoint( idx, false );
273  }
274  break;
275 
278  {
279  const QgsMultiPointXY mpt = geom.asMultiPoint();
280  for ( QgsPointXY pt : mpt )
281  {
282  addPoint( pt, false, idx );
283  removeLastPoint( idx, false );
284  idx++;
285  }
286  }
287  break;
288 
291  {
292  const QgsPolylineXY line = geom.asPolyline();
293  for ( QgsPointXY pt : line )
294  {
295  addPoint( pt, false, idx );
296  }
297  }
298  break;
299 
302  {
303 
304  const QgsMultiPolylineXY mline = geom.asMultiPolyline();
305  for ( const QgsPolylineXY &line : mline )
306  {
307  if ( line.isEmpty() )
308  {
309  continue;
310  }
311 
312  for ( QgsPointXY pt : line )
313  {
314  addPoint( pt, false, idx );
315  }
316  idx++;
317  }
318  }
319  break;
320 
323  {
324  const QgsPolygonXY poly = geom.asPolygon();
325  const QgsPolylineXY line = poly.at( 0 );
326  for ( QgsPointXY pt : line )
327  {
328  addPoint( pt, false, idx );
329  }
330  }
331  break;
332 
335  {
336  const QgsMultiPolygonXY multipoly = geom.asMultiPolygon();
337  for ( const QgsPolygonXY &poly : multipoly )
338  {
339  if ( poly.empty() )
340  continue;
341 
342  const QgsPolylineXY line = poly.at( 0 );
343  for ( QgsPointXY pt : line )
344  {
345  addPoint( pt, false, idx );
346  }
347  idx++;
348  }
349  }
350  break;
351 
353  default:
354  return;
355  }
356 
357  setVisible( true );
358  updateRect();
359  update();
360 }
361 
363 {
364  if ( !mMapCanvas )
365  {
366  return;
367  }
368 
369  const QgsMapToPixel *transform = mMapCanvas->getCoordinateTransform();
370  QgsPointXY ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
371  QgsPointXY lr = transform->toMapCoordinates( rect.right(), rect.bottom() );
372  QgsPointXY ul = transform->toMapCoordinates( rect.left(), rect.top() );
373  QgsPointXY ur = transform->toMapCoordinates( rect.right(), rect.top() );
374 
376  addPoint( ll, false );
377  addPoint( lr, false );
378  addPoint( ur, false );
379  addPoint( ul, true );
380 }
381 
382 void QgsRubberBand::paint( QPainter *p )
383 {
384  if ( mPoints.isEmpty() )
385  return;
386 
387  QVector< QVector<QPointF> > shapes;
388  for ( const QList<QgsPointXY> &line : qgis::as_const( mPoints ) )
389  {
390  QVector<QPointF> pts;
391  for ( const QgsPointXY &pt : line )
392  {
393  const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
394  if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
395  pts.append( cur );
396  }
397  shapes << pts;
398  }
399 
400  int iterations = mSecondaryPen.color().isValid() ? 2 : 1;
401  for ( int i = 0; i < iterations; ++i )
402  {
403  if ( i == 0 && iterations > 1 )
404  {
405  // first iteration with multi-pen painting, so use secondary pen
406  mSecondaryPen.setWidth( mPen.width() + 2 );
407  p->setBrush( Qt::NoBrush );
408  p->setPen( mSecondaryPen );
409  }
410  else
411  {
412  // "top" layer, use primary pen/brush
413  p->setBrush( mBrush );
414  p->setPen( mPen );
415  }
416 
417  for ( const QVector<QPointF> &shape : qgis::as_const( shapes ) )
418  {
419  drawShape( p, shape );
420  }
421  }
422 }
423 
424 void QgsRubberBand::drawShape( QPainter *p, const QVector<QPointF> &pts )
425 {
426  switch ( mGeometryType )
427  {
429  {
430  p->drawPolygon( pts );
431  }
432  break;
433 
435  {
436  Q_FOREACH ( QPointF pt, pts )
437  {
438  double x = pt.x();
439  double y = pt.y();
440 
441  qreal s = ( mIconSize - 1 ) / 2.0;
442 
443  switch ( mIconType )
444  {
445  case ICON_NONE:
446  break;
447 
448  case ICON_CROSS:
449  p->drawLine( QLineF( x - s, y, x + s, y ) );
450  p->drawLine( QLineF( x, y - s, x, y + s ) );
451  break;
452 
453  case ICON_X:
454  p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
455  p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
456  break;
457 
458  case ICON_BOX:
459  p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
460  p->drawLine( QLineF( x + s, y - s, x + s, y + s ) );
461  p->drawLine( QLineF( x + s, y + s, x - s, y + s ) );
462  p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
463  break;
464 
465  case ICON_FULL_BOX:
466  p->drawRect( x - s, y - s, mIconSize, mIconSize );
467  break;
468 
469  case ICON_CIRCLE:
470  p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
471  break;
472 
473  case ICON_DIAMOND:
474  case ICON_FULL_DIAMOND:
475  {
476  QPointF pts[] =
477  {
478  QPointF( x, y - s ),
479  QPointF( x + s, y ),
480  QPointF( x, y + s ),
481  QPointF( x - s, y )
482  };
483  if ( mIconType == ICON_FULL_DIAMOND )
484  p->drawPolygon( pts, 4 );
485  else
486  p->drawPolyline( pts, 4 );
487  }
488  }
489  }
490  }
491  break;
492 
494  default:
495  {
496  p->drawPolyline( pts );
497  }
498  break;
499  }
500 }
501 
503 {
504  if ( mPoints.empty() )
505  {
506  setRect( QgsRectangle() );
507  setVisible( false );
508  return;
509  }
510 
511  const QgsMapToPixel &m2p = *( mMapCanvas->getCoordinateTransform() );
512 
513  qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() ); // in canvas units
514 
515  QgsRectangle r; // in canvas units
516  for ( int i = 0; i < mPoints.size(); ++i )
517  {
518  QList<QgsPointXY>::const_iterator it = mPoints.at( i ).constBegin(),
519  itE = mPoints.at( i ).constEnd();
520  for ( ; it != itE; ++it )
521  {
522  QgsPointXY p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
523  p = m2p.transform( p );
524  QgsRectangle rect( p.x() - w, p.y() - w, p.x() + w, p.y() + w );
525 
526  if ( r.isEmpty() )
527  {
528  // Get rectangle of the first point
529  r = rect;
530  }
531  else
532  {
533  r.combineExtentWith( rect );
534  }
535  }
536  }
537 
538  // This is an hack to pass QgsMapCanvasItem::setRect what it
539  // expects (encoding of position and size of the item)
540  qreal res = m2p.mapUnitsPerPixel();
541  QgsPointXY topLeft = m2p.toMapPoint( r.xMinimum(), r.yMinimum() );
542  QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + r.width()*res, topLeft.y() - r.height()*res );
543 
544  setRect( rect );
545 }
546 
548 {
549  // re-compute rectangle
550  // See https://issues.qgis.org/issues/12392
551  // NOTE: could be optimized by saving map-extent
552  // of rubberband and simply re-projecting
553  // that to device-rectangle on "updatePosition"
554  updateRect();
555 }
556 
557 void QgsRubberBand::setTranslationOffset( double dx, double dy )
558 {
559  mTranslationOffsetX = dx;
560  mTranslationOffsetY = dy;
561  updateRect();
562 }
563 
565 {
566  return mPoints.size();
567 }
568 
569 int QgsRubberBand::partSize( int geometryIndex ) const
570 {
571  if ( geometryIndex < 0 || geometryIndex >= mPoints.size() ) return 0;
572  return mPoints[geometryIndex].size();
573 }
574 
576 {
577  int count = 0;
578  QList<QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
579  for ( ; it != mPoints.constEnd(); ++it )
580  {
581  QList<QgsPointXY>::const_iterator iter = it->constBegin();
582  for ( ; iter != it->constEnd(); ++iter )
583  {
584  ++count;
585  }
586  }
587  return count;
588 }
589 
590 const QgsPointXY *QgsRubberBand::getPoint( int i, int j ) const
591 {
592  if ( i < mPoints.size() && j < mPoints[i].size() )
593  return &mPoints[i][j];
594  else
595  return nullptr;
596 }
597 
599 {
600  QgsGeometry geom;
601 
602  switch ( mGeometryType )
603  {
605  {
606  QgsPolygonXY polygon;
607  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
608  for ( ; it != mPoints.constEnd(); ++it )
609  {
610  polygon.append( getPolyline( *it ) );
611  }
612  geom = QgsGeometry::fromPolygonXY( polygon );
613  break;
614  }
615 
617  {
618  QgsMultiPointXY multiPoint;
619 
620  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
621  for ( ; it != mPoints.constEnd(); ++it )
622  {
623  multiPoint += getPolyline( *it );
624  }
625  geom = QgsGeometry::fromMultiPointXY( multiPoint );
626  break;
627  }
628 
630  default:
631  {
632  if ( !mPoints.isEmpty() )
633  {
634  if ( mPoints.size() > 1 )
635  {
636  QgsMultiPolylineXY multiPolyline;
637  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
638  for ( ; it != mPoints.constEnd(); ++it )
639  {
640  multiPolyline.append( getPolyline( *it ) );
641  }
642  geom = QgsGeometry::fromMultiPolylineXY( multiPolyline );
643  }
644  else
645  {
646  geom = QgsGeometry::fromPolylineXY( getPolyline( mPoints.at( 0 ) ) );
647  }
648  }
649  break;
650  }
651  }
652  return geom;
653 }
654 
655 QgsPolylineXY QgsRubberBand::getPolyline( const QList<QgsPointXY> &points )
656 {
657  QgsPolylineXY polyline;
658  QList<QgsPointXY>::const_iterator iter = points.constBegin();
659  for ( ; iter != points.constEnd(); ++iter )
660  {
661  polyline.append( *iter );
662  }
663  return polyline;
664 }
A cross is used to highlight points (x)
Definition: qgsrubberband.h:58
void setIconSize(int iconSize)
Sets the size of the point icons.
void setWidth(int width)
Sets the width of the line.
A rectangle specified with double values.
Definition: qgsrectangle.h:39
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
static QgsGeometry fromPolylineXY(const QgsPolylineXY &polyline)
Creates a new LineString geometry from a list of QgsPointXY points.
QgsRectangle rect() const
returns canvas item rectangle in map units
void setToCanvasRectangle(QRect rect)
Sets this rubber band to a map canvas rectangle.
void setStrokeColor(const QColor &color)
Sets the stroke color for the rubberband.
IconType icon() const
Returns the current icon type to highlight point geometries.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
void setTranslationOffset(double dx, double dy)
Adds translation to original coordinates (all in map coordinates)
void setLineStyle(Qt::PenStyle penStyle)
Sets the style of the line.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
double y
Definition: qgspointxy.h:48
A class to represent a 2D point.
Definition: qgspointxy.h:43
static QgsGeometry fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Creates a new geometry from a QgsMultiPolylineXY object.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:73
An abstract class for items that can be placed on the map canvas.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
void setSecondaryStrokeColor(const QColor &color)
Sets a secondary stroke color for the rubberband which will be drawn under the main stroke color...
A diamond is used to highlight points (◇)
Definition: qgsrubberband.h:79
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition: qgsgeometry.h:79
virtual void updatePosition() override
called on changed extent or resize event to update position of the item
void addGeometry(const QgsGeometry &geometry, QgsVectorLayer *layer)
Adds the geometry of an existing feature to a rubberband This is useful for multi feature highlightin...
A cross is used to highlight points (+)
Definition: qgsrubberband.h:53
const QgsPointXY * getPoint(int i, int j=0) const
Returns a vertex.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
Definition: qgsgeometry.h:90
virtual void paint(QPainter *p) override
Paints the rubber band in response to an update event.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
int width() const
Returns the current width of the line or stroke width for polygon.
The QgsMapSettings class contains configuration for rendering of the map.
void setToGeometry(const QgsGeometry &geom, QgsVectorLayer *layer)
Sets this rubber band to the geometry of an existing feature.
QgsRubberBand(QgsMapCanvas *mapCanvas, QgsWkbTypes::GeometryType geometryType=QgsWkbTypes::LineGeometry)
Creates a new RubberBand.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
Definition: qgsgeometry.h:83
QgsMultiPolylineXY asMultiPolyline() const
Returns contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Return coordinate transform from layer&#39;s CRS to destination CRS.
void closePoints(bool doUpdate=true, int geometryIndex=0)
Ensures that a polygon geometry is closed and that the last vertex equals the first vertex...
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
QgsGeometry asGeometry() const
Returns the rubberband as a Geometry.
bool isEmpty() const
Returns true if the rectangle is empty.
A circle is used to highlight points (○)
Definition: qgsrubberband.h:68
QgsPolygonXY asPolygon() const
Returns contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
void removePoint(int index=0, bool doUpdate=true, int geometryIndex=0)
Removes a vertex from the rubberband and (optionally) updates canvas.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:138
void addPoint(const QgsPointXY &p, bool doUpdate=true, int geometryIndex=0)
Adds a vertex to the rubberband and update canvas.
static QgsGeometry fromMultiPointXY(const QgsMultiPointXY &multipoint)
Creates a new geometry from a QgsMultiPointXY object.
void movePoint(const QgsPointXY &p, int geometryIndex=0)
Moves the rubber band point specified by index.
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
void setFillColor(const QColor &color)
Sets the fill color for the rubberband.
double mapUnitsPerPixel() const
Return current map units per pixel.
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
double x
Definition: qgspointxy.h:47
QgsMapCanvasItem(QgsMapCanvas *mapCanvas)
protected constructor: cannot be constructed directly
void setBrushStyle(Qt::BrushStyle brushStyle)
Sets the style of the brush.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:126
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void combineExtentWith(const QgsRectangle &rect)
Expand the rectangle so that covers both the original rectangle and the given rectangle.
void setIcon(IconType icon)
Sets the icon type to highlight point geometries.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:137
A box is used to highlight points (□)
Definition: qgsrubberband.h:63
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:49
QgsPointXY toMapPoint(double x, double y) const
OperationResult transform(const QgsCoordinateTransform &ct)
Transforms this geometry as described by CoordinateTransform ct.
QgsPointXY asPoint() const
Returns contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
int iconSize() const
Returns the current icon size of the point icons.
void drawShape(QPainter *p, const QVector< QPointF > &pts)
Draws shape of the rubber band.
int partSize(int geometryIndex) const
Returns number of vertices in feature part.
QgsMapCanvas * mMapCanvas
pointer to map canvas
This class represents a coordinate reference system (CRS).
A diamond is used to highlight points (◆)
Definition: qgsrubberband.h:85
Class for doing transforms between two map coordinate systems.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:116
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
void reset(QgsWkbTypes::GeometryType geometryType=QgsWkbTypes::LineGeometry)
Clears all the geometries in this rubberband.
void setColor(const QColor &color)
Sets the color for the rubberband.
QgsPolylineXY asPolyline() const
Returns contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
No icon is used.
Definition: qgsrubberband.h:48
QgsMultiPointXY asMultiPoint() const
Returns contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty lis...
int size() const
Returns number of geometries.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
Represents a vector layer which manages a vector based data sets.
void removeLastPoint(int geometryIndex=0, bool doUpdate=true)
Removes the last point.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:427
QgsMultiPolygonXY asMultiPolygon() const
Returns contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list.
QgsPointXY toMapCoordinates(int x, int y) const
void updateRect()
Recalculates needed rectangle.
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:145
A full box is used to highlight points (■)
Definition: qgsrubberband.h:73
bool isValid() const
Returns whether this CRS is correctly initialized and usable.