QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgsproject.h"
23 #include <QPainter>
24 
26  : QgsMapCanvasItem( mapCanvas )
27  , mGeometryType( geometryType )
28 {
29  reset( geometryType );
30  QColor color( Qt::lightGray );
31  color.setAlpha( 63 );
32  setColor( color );
33  setWidth( 1 );
34  setLineStyle( Qt::SolidLine );
35  setBrushStyle( Qt::SolidPattern );
36  setSecondaryStrokeColor( QColor() );
37 }
38 
40  : QgsMapCanvasItem( nullptr )
41 {
42 }
43 
44 void QgsRubberBand::setColor( const QColor &color )
45 {
46  setStrokeColor( color );
47  setFillColor( color );
48 }
49 
50 void QgsRubberBand::setFillColor( const QColor &color )
51 {
52  mBrush.setColor( color );
53 }
54 
55 void QgsRubberBand::setStrokeColor( const QColor &color )
56 {
57  mPen.setColor( color );
58 }
59 
60 void QgsRubberBand::setSecondaryStrokeColor( const QColor &color )
61 {
62  mSecondaryPen.setColor( color );
63 }
64 
66 {
67  mPen.setWidth( width );
68 }
69 
71 {
72  mIconType = icon;
73 }
74 
76 {
77  mIconSize = iconSize;
78 }
79 
80 void QgsRubberBand::setLineStyle( Qt::PenStyle penStyle )
81 {
82  mPen.setStyle( penStyle );
83 }
84 
85 void QgsRubberBand::setBrushStyle( Qt::BrushStyle brushStyle )
86 {
87  mBrush.setStyle( brushStyle );
88 }
89 
91 {
92  mPoints.clear();
93  mGeometryType = geometryType;
94  updateRect();
95  update();
96 }
97 
98 void QgsRubberBand::addPoint( const QgsPointXY &p, bool doUpdate /* = true */, int geometryIndex )
99 {
100  if ( geometryIndex < 0 )
101  {
102  geometryIndex = mPoints.size() - 1;
103  }
104 
105  if ( geometryIndex < 0 || geometryIndex > mPoints.size() )
106  {
107  return;
108  }
109 
110  if ( geometryIndex == mPoints.size() )
111  {
112  mPoints.push_back( QList<QgsPointXY>() << p );
113  }
114 
115  if ( mPoints.at( geometryIndex ).size() == 2 &&
116  mPoints.at( geometryIndex ).at( 0 ) == mPoints.at( geometryIndex ).at( 1 ) )
117  {
118  mPoints[geometryIndex].last() = p;
119  }
120  else
121  {
122  mPoints[geometryIndex] << p;
123  }
124 
125 
126  if ( doUpdate )
127  {
128  setVisible( true );
129  updateRect();
130  update();
131  }
132 }
133 
134 void QgsRubberBand::closePoints( bool doUpdate, int geometryIndex )
135 {
136  if ( geometryIndex < 0 || geometryIndex >= mPoints.size() )
137  {
138  return;
139  }
140 
141  if ( mPoints.at( geometryIndex ).at( 0 ) != mPoints.at( geometryIndex ).at( mPoints.at( geometryIndex ).size() - 1 ) )
142  {
143  mPoints[geometryIndex] << mPoints.at( geometryIndex ).at( 0 );
144  }
145 
146  if ( doUpdate )
147  {
148  setVisible( true );
149  updateRect();
150  update();
151  }
152 }
153 
154 
155 void QgsRubberBand::removePoint( int index, bool doUpdate/* = true*/, int geometryIndex/* = 0*/ )
156 {
157 
158  if ( mPoints.size() < geometryIndex + 1 )
159  {
160  return;
161  }
162 
163 
164  if ( !mPoints[geometryIndex].isEmpty() )
165  {
166  // negative index removes from end, e.g., -1 removes last one
167  if ( index < 0 )
168  {
169  index = mPoints.at( geometryIndex ).size() + index;
170  }
171  mPoints[geometryIndex].removeAt( index );
172  }
173 
174  if ( doUpdate )
175  {
176  updateRect();
177  update();
178  }
179 }
180 
181 void QgsRubberBand::removeLastPoint( int geometryIndex, bool doUpdate/* = true*/ )
182 {
183  removePoint( -1, doUpdate, geometryIndex );
184 }
185 
186 void QgsRubberBand::movePoint( const QgsPointXY &p, int geometryIndex )
187 {
188  if ( mPoints.size() < geometryIndex + 1 )
189  {
190  return;
191  }
192 
193  if ( mPoints.at( geometryIndex ).empty() )
194  {
195  return;
196  }
197 
198  mPoints[geometryIndex].last() = p;
199 
200  updateRect();
201  update();
202 }
203 
204 void QgsRubberBand::movePoint( int index, const QgsPointXY &p, int geometryIndex )
205 {
206  if ( mPoints.size() < geometryIndex + 1 )
207  {
208  return;
209  }
210 
211  if ( mPoints.at( geometryIndex ).size() < index )
212  {
213  return;
214  }
215 
216  mPoints[geometryIndex][index] = p;
217 
218  updateRect();
219  update();
220 }
221 
223 {
224  if ( geom.isNull() )
225  {
226  reset( mGeometryType );
227  return;
228  }
229 
230  reset( geom.type() );
231  addGeometry( geom, layer );
232 }
233 
235 {
236  QgsGeometry geom = geometry;
237  if ( layer )
238  {
240  geom.transform( ct );
241  }
242 
243  addGeometry( geom );
244 }
245 
247 {
248  if ( geometry.isEmpty() )
249  {
250  return;
251  }
252 
253  //maprender object of canvas
254  const QgsMapSettings &ms = mMapCanvas->mapSettings();
255 
256  int idx = mPoints.size();
257 
258  QgsGeometry geom = geometry;
259  if ( crs.isValid() )
260  {
262  geom.transform( ct );
263  }
264 
265  QgsWkbTypes::Type geomType = geom.wkbType();
267  {
268  QgsPointXY pt = geom.asPoint();
269  addPoint( pt, false, idx );
270  removeLastPoint( idx, false );
271  }
272  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::PointGeometry && QgsWkbTypes::isMultiType( geomType ) )
273  {
274  const QgsMultiPointXY mpt = geom.asMultiPoint();
275  for ( const QgsPointXY &pt : mpt )
276  {
277  addPoint( pt, false, idx );
278  removeLastPoint( idx, false );
279  idx++;
280  }
281  }
282  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::LineGeometry && !QgsWkbTypes::isMultiType( geomType ) )
283  {
284  const QgsPolylineXY line = geom.asPolyline();
285  for ( const QgsPointXY &pt : line )
286  {
287  addPoint( pt, false, idx );
288  }
289  }
290  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::LineGeometry && QgsWkbTypes::isMultiType( geomType ) )
291  {
292  const QgsMultiPolylineXY mline = geom.asMultiPolyline();
293  for ( const QgsPolylineXY &line : mline )
294  {
295  if ( line.isEmpty() )
296  {
297  continue;
298  }
299  for ( const QgsPointXY &pt : line )
300  {
301  addPoint( pt, false, idx );
302  }
303  idx++;
304  }
305  }
306  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::PolygonGeometry && !QgsWkbTypes::isMultiType( geomType ) )
307  {
308  const QgsPolygonXY poly = geom.asPolygon();
309  const QgsPolylineXY line = poly.at( 0 );
310  for ( const QgsPointXY &pt : line )
311  {
312  addPoint( pt, false, idx );
313  }
314  }
316  {
317  const QgsMultiPolygonXY multipoly = geom.asMultiPolygon();
318  for ( const QgsPolygonXY &poly : multipoly )
319  {
320  if ( poly.empty() )
321  continue;
322 
323  const QgsPolylineXY line = poly.at( 0 );
324  for ( const QgsPointXY &pt : line )
325  {
326  addPoint( pt, false, idx );
327  }
328  idx++;
329  }
330  }
331  else
332  {
333  return;
334  }
335 
336  setVisible( true );
337  updateRect();
338  update();
339 }
340 
342 {
343  if ( !mMapCanvas )
344  {
345  return;
346  }
347 
348  const QgsMapToPixel *transform = mMapCanvas->getCoordinateTransform();
349  QgsPointXY ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
350  QgsPointXY lr = transform->toMapCoordinates( rect.right(), rect.bottom() );
351  QgsPointXY ul = transform->toMapCoordinates( rect.left(), rect.top() );
352  QgsPointXY ur = transform->toMapCoordinates( rect.right(), rect.top() );
353 
355  addPoint( ll, false );
356  addPoint( lr, false );
357  addPoint( ur, false );
358  addPoint( ul, true );
359 }
360 
361 void QgsRubberBand::paint( QPainter *p )
362 {
363  if ( mPoints.isEmpty() )
364  return;
365 
366  QVector< QVector<QPointF> > shapes;
367  for ( const QList<QgsPointXY> &line : qgis::as_const( mPoints ) )
368  {
369  QVector<QPointF> pts;
370  for ( const QgsPointXY &pt : line )
371  {
372  const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
373  if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
374  pts.append( cur );
375  }
376  shapes << pts;
377  }
378 
379  int iterations = mSecondaryPen.color().isValid() ? 2 : 1;
380  for ( int i = 0; i < iterations; ++i )
381  {
382  if ( i == 0 && iterations > 1 )
383  {
384  // first iteration with multi-pen painting, so use secondary pen
385  mSecondaryPen.setWidth( mPen.width() + 2 );
386  p->setBrush( Qt::NoBrush );
387  p->setPen( mSecondaryPen );
388  }
389  else
390  {
391  // "top" layer, use primary pen/brush
392  p->setBrush( mBrush );
393  p->setPen( mPen );
394  }
395 
396  for ( const QVector<QPointF> &shape : qgis::as_const( shapes ) )
397  {
398  drawShape( p, shape );
399  }
400  }
401 }
402 
403 void QgsRubberBand::drawShape( QPainter *p, const QVector<QPointF> &pts )
404 {
405  switch ( mGeometryType )
406  {
408  {
409  p->drawPolygon( pts );
410  }
411  break;
412 
414  {
415  Q_FOREACH ( QPointF pt, pts )
416  {
417  double x = pt.x();
418  double y = pt.y();
419 
420  qreal s = ( mIconSize - 1 ) / 2.0;
421 
422  switch ( mIconType )
423  {
424  case ICON_NONE:
425  break;
426 
427  case ICON_CROSS:
428  p->drawLine( QLineF( x - s, y, x + s, y ) );
429  p->drawLine( QLineF( x, y - s, x, y + s ) );
430  break;
431 
432  case ICON_X:
433  p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
434  p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
435  break;
436 
437  case ICON_BOX:
438  p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
439  p->drawLine( QLineF( x + s, y - s, x + s, y + s ) );
440  p->drawLine( QLineF( x + s, y + s, x - s, y + s ) );
441  p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
442  break;
443 
444  case ICON_FULL_BOX:
445  p->drawRect( x - s, y - s, mIconSize, mIconSize );
446  break;
447 
448  case ICON_CIRCLE:
449  p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
450  break;
451 
452  case ICON_DIAMOND:
453  case ICON_FULL_DIAMOND:
454  {
455  QPointF pts[] =
456  {
457  QPointF( x, y - s ),
458  QPointF( x + s, y ),
459  QPointF( x, y + s ),
460  QPointF( x - s, y )
461  };
462  if ( mIconType == ICON_FULL_DIAMOND )
463  p->drawPolygon( pts, 4 );
464  else
465  p->drawPolyline( pts, 4 );
466  }
467  }
468  }
469  }
470  break;
471 
473  default:
474  {
475  p->drawPolyline( pts );
476  }
477  break;
478  }
479 }
480 
482 {
483  if ( mPoints.empty() )
484  {
485  setRect( QgsRectangle() );
486  setVisible( false );
487  return;
488  }
489 
490  const QgsMapToPixel &m2p = *( mMapCanvas->getCoordinateTransform() );
491 
492  qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() ); // in canvas units
493 
494  QgsRectangle r; // in canvas units
495  for ( int i = 0; i < mPoints.size(); ++i )
496  {
497  QList<QgsPointXY>::const_iterator it = mPoints.at( i ).constBegin(),
498  itE = mPoints.at( i ).constEnd();
499  for ( ; it != itE; ++it )
500  {
501  QgsPointXY p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
502  p = m2p.transform( p );
503  QgsRectangle rect( p.x() - w, p.y() - w, p.x() + w, p.y() + w );
504 
505  if ( r.isEmpty() )
506  {
507  // Get rectangle of the first point
508  r = rect;
509  }
510  else
511  {
512  r.combineExtentWith( rect );
513  }
514  }
515  }
516 
517  // This is an hack to pass QgsMapCanvasItem::setRect what it
518  // expects (encoding of position and size of the item)
519  qreal res = m2p.mapUnitsPerPixel();
520  QgsPointXY topLeft = m2p.toMapPoint( r.xMinimum(), r.yMinimum() );
521  QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + r.width()*res, topLeft.y() - r.height()*res );
522 
523  setRect( rect );
524 }
525 
527 {
528  // re-compute rectangle
529  // See https://issues.qgis.org/issues/12392
530  // NOTE: could be optimized by saving map-extent
531  // of rubberband and simply re-projecting
532  // that to device-rectangle on "updatePosition"
533  updateRect();
534 }
535 
536 void QgsRubberBand::setTranslationOffset( double dx, double dy )
537 {
538  mTranslationOffsetX = dx;
539  mTranslationOffsetY = dy;
540  updateRect();
541 }
542 
544 {
545  return mPoints.size();
546 }
547 
548 int QgsRubberBand::partSize( int geometryIndex ) const
549 {
550  if ( geometryIndex < 0 || geometryIndex >= mPoints.size() ) return 0;
551  return mPoints[geometryIndex].size();
552 }
553 
555 {
556  int count = 0;
557  QList<QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
558  for ( ; it != mPoints.constEnd(); ++it )
559  {
560  QList<QgsPointXY>::const_iterator iter = it->constBegin();
561  for ( ; iter != it->constEnd(); ++iter )
562  {
563  ++count;
564  }
565  }
566  return count;
567 }
568 
569 const QgsPointXY *QgsRubberBand::getPoint( int i, int j ) const
570 {
571  if ( i < mPoints.size() && j < mPoints[i].size() )
572  return &mPoints[i][j];
573  else
574  return nullptr;
575 }
576 
578 {
579  QgsGeometry geom;
580 
581  switch ( mGeometryType )
582  {
584  {
585  QgsPolygonXY polygon;
586  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
587  for ( ; it != mPoints.constEnd(); ++it )
588  {
589  polygon.append( getPolyline( *it ) );
590  }
591  geom = QgsGeometry::fromPolygonXY( polygon );
592  break;
593  }
594 
596  {
597  QgsMultiPointXY multiPoint;
598 
599  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
600  for ( ; it != mPoints.constEnd(); ++it )
601  {
602  multiPoint += getPolyline( *it );
603  }
604  geom = QgsGeometry::fromMultiPointXY( multiPoint );
605  break;
606  }
607 
609  default:
610  {
611  if ( !mPoints.isEmpty() )
612  {
613  if ( mPoints.size() > 1 )
614  {
615  QgsMultiPolylineXY multiPolyline;
616  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
617  for ( ; it != mPoints.constEnd(); ++it )
618  {
619  multiPolyline.append( getPolyline( *it ) );
620  }
621  geom = QgsGeometry::fromMultiPolylineXY( multiPolyline );
622  }
623  else
624  {
625  geom = QgsGeometry::fromPolylineXY( getPolyline( mPoints.at( 0 ) ) );
626  }
627  }
628  break;
629  }
630  }
631  return geom;
632 }
633 
634 QgsPolylineXY QgsRubberBand::getPolyline( const QList<QgsPointXY> &points )
635 {
636  QgsPolylineXY polyline;
637  QList<QgsPointXY>::const_iterator iter = points.constBegin();
638  for ( ; iter != points.constEnd(); ++iter )
639  {
640  polyline.append( *iter );
641  }
642  return polyline;
643 }
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() )...
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:557
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
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
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.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:67
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:142
void addPoint(const QgsPointXY &p, bool doUpdate=true, int geometryIndex=0)
Adds a vertex to the rubberband and update canvas.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:663
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
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
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:130
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
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
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:383
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:120
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.
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:149
A full box is used to highlight points (■)
Definition: qgsrubberband.h:73
bool isValid() const
Returns whether this CRS is correctly initialized and usable.