QGIS API Documentation  3.2.0-Bonn (bc43194)
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  try
241  {
242  geom.transform( ct );
243  }
244  catch ( QgsCsException & )
245  {
246  return;
247  }
248  }
249 
250  addGeometry( geom );
251 }
252 
254 {
255  if ( geometry.isEmpty() )
256  {
257  return;
258  }
259 
260  //maprender object of canvas
261  const QgsMapSettings &ms = mMapCanvas->mapSettings();
262 
263  int idx = mPoints.size();
264 
265  QgsGeometry geom = geometry;
266  if ( crs.isValid() )
267  {
269  geom.transform( ct );
270  }
271 
272  QgsWkbTypes::Type geomType = geom.wkbType();
274  {
275  QgsPointXY pt = geom.asPoint();
276  addPoint( pt, false, idx );
277  removeLastPoint( idx, false );
278  }
279  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::PointGeometry && QgsWkbTypes::isMultiType( geomType ) )
280  {
281  const QgsMultiPointXY mpt = geom.asMultiPoint();
282  for ( const QgsPointXY &pt : mpt )
283  {
284  addPoint( pt, false, idx );
285  removeLastPoint( idx, false );
286  idx++;
287  }
288  }
289  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::LineGeometry && !QgsWkbTypes::isMultiType( geomType ) )
290  {
291  const QgsPolylineXY line = geom.asPolyline();
292  for ( const QgsPointXY &pt : line )
293  {
294  addPoint( pt, false, idx );
295  }
296  }
297  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::LineGeometry && QgsWkbTypes::isMultiType( geomType ) )
298  {
299  const QgsMultiPolylineXY mline = geom.asMultiPolyline();
300  for ( const QgsPolylineXY &line : mline )
301  {
302  if ( line.isEmpty() )
303  {
304  continue;
305  }
306  for ( const QgsPointXY &pt : line )
307  {
308  addPoint( pt, false, idx );
309  }
310  idx++;
311  }
312  }
313  else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::PolygonGeometry && !QgsWkbTypes::isMultiType( geomType ) )
314  {
315  const QgsPolygonXY poly = geom.asPolygon();
316  const QgsPolylineXY line = poly.at( 0 );
317  for ( const QgsPointXY &pt : line )
318  {
319  addPoint( pt, false, idx );
320  }
321  }
323  {
324  const QgsMultiPolygonXY multipoly = geom.asMultiPolygon();
325  for ( const QgsPolygonXY &poly : multipoly )
326  {
327  if ( poly.empty() )
328  continue;
329 
330  const QgsPolylineXY line = poly.at( 0 );
331  for ( const QgsPointXY &pt : line )
332  {
333  addPoint( pt, false, idx );
334  }
335  idx++;
336  }
337  }
338  else
339  {
340  return;
341  }
342 
343  setVisible( true );
344  updateRect();
345  update();
346 }
347 
349 {
350  if ( !mMapCanvas )
351  {
352  return;
353  }
354 
355  const QgsMapToPixel *transform = mMapCanvas->getCoordinateTransform();
356  QgsPointXY ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
357  QgsPointXY lr = transform->toMapCoordinates( rect.right(), rect.bottom() );
358  QgsPointXY ul = transform->toMapCoordinates( rect.left(), rect.top() );
359  QgsPointXY ur = transform->toMapCoordinates( rect.right(), rect.top() );
360 
362  addPoint( ll, false );
363  addPoint( lr, false );
364  addPoint( ur, false );
365  addPoint( ul, true );
366 }
367 
368 void QgsRubberBand::paint( QPainter *p )
369 {
370  if ( mPoints.isEmpty() )
371  return;
372 
373  QVector< QVector<QPointF> > shapes;
374  for ( const QList<QgsPointXY> &line : qgis::as_const( mPoints ) )
375  {
376  QVector<QPointF> pts;
377  for ( const QgsPointXY &pt : line )
378  {
379  const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
380  if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
381  pts.append( cur );
382  }
383  shapes << pts;
384  }
385 
386  int iterations = mSecondaryPen.color().isValid() ? 2 : 1;
387  for ( int i = 0; i < iterations; ++i )
388  {
389  if ( i == 0 && iterations > 1 )
390  {
391  // first iteration with multi-pen painting, so use secondary pen
392  mSecondaryPen.setWidth( mPen.width() + 2 );
393  p->setBrush( Qt::NoBrush );
394  p->setPen( mSecondaryPen );
395  }
396  else
397  {
398  // "top" layer, use primary pen/brush
399  p->setBrush( mBrush );
400  p->setPen( mPen );
401  }
402 
403  for ( const QVector<QPointF> &shape : qgis::as_const( shapes ) )
404  {
405  drawShape( p, shape );
406  }
407  }
408 }
409 
410 void QgsRubberBand::drawShape( QPainter *p, const QVector<QPointF> &pts )
411 {
412  switch ( mGeometryType )
413  {
415  {
416  p->drawPolygon( pts );
417  }
418  break;
419 
421  {
422  Q_FOREACH ( QPointF pt, pts )
423  {
424  double x = pt.x();
425  double y = pt.y();
426 
427  qreal s = ( mIconSize - 1 ) / 2.0;
428 
429  switch ( mIconType )
430  {
431  case ICON_NONE:
432  break;
433 
434  case ICON_CROSS:
435  p->drawLine( QLineF( x - s, y, x + s, y ) );
436  p->drawLine( QLineF( x, y - s, x, y + s ) );
437  break;
438 
439  case ICON_X:
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_BOX:
445  p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
446  p->drawLine( QLineF( x + s, y - s, x + s, y + s ) );
447  p->drawLine( QLineF( x + s, y + s, x - s, y + s ) );
448  p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
449  break;
450 
451  case ICON_FULL_BOX:
452  p->drawRect( x - s, y - s, mIconSize, mIconSize );
453  break;
454 
455  case ICON_CIRCLE:
456  p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
457  break;
458 
459  case ICON_DIAMOND:
460  case ICON_FULL_DIAMOND:
461  {
462  QPointF pts[] =
463  {
464  QPointF( x, y - s ),
465  QPointF( x + s, y ),
466  QPointF( x, y + s ),
467  QPointF( x - s, y )
468  };
469  if ( mIconType == ICON_FULL_DIAMOND )
470  p->drawPolygon( pts, 4 );
471  else
472  p->drawPolyline( pts, 4 );
473  }
474  }
475  }
476  }
477  break;
478 
480  default:
481  {
482  p->drawPolyline( pts );
483  }
484  break;
485  }
486 }
487 
489 {
490  if ( mPoints.empty() )
491  {
492  setRect( QgsRectangle() );
493  setVisible( false );
494  return;
495  }
496 
497  const QgsMapToPixel &m2p = *( mMapCanvas->getCoordinateTransform() );
498 
499  qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() ); // in canvas units
500 
501  QgsRectangle r; // in canvas units
502  for ( int i = 0; i < mPoints.size(); ++i )
503  {
504  QList<QgsPointXY>::const_iterator it = mPoints.at( i ).constBegin(),
505  itE = mPoints.at( i ).constEnd();
506  for ( ; it != itE; ++it )
507  {
508  QgsPointXY p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
509  p = m2p.transform( p );
510  QgsRectangle rect( p.x() - w, p.y() - w, p.x() + w, p.y() + w );
511 
512  if ( r.isEmpty() )
513  {
514  // Get rectangle of the first point
515  r = rect;
516  }
517  else
518  {
519  r.combineExtentWith( rect );
520  }
521  }
522  }
523 
524  // This is an hack to pass QgsMapCanvasItem::setRect what it
525  // expects (encoding of position and size of the item)
526  qreal res = m2p.mapUnitsPerPixel();
527  QgsPointXY topLeft = m2p.toMapPoint( r.xMinimum(), r.yMinimum() );
528  QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + r.width()*res, topLeft.y() - r.height()*res );
529 
530  setRect( rect );
531 }
532 
534 {
535  // re-compute rectangle
536  // See https://issues.qgis.org/issues/12392
537  // NOTE: could be optimized by saving map-extent
538  // of rubberband and simply re-projecting
539  // that to device-rectangle on "updatePosition"
540  updateRect();
541 }
542 
543 void QgsRubberBand::setTranslationOffset( double dx, double dy )
544 {
545  mTranslationOffsetX = dx;
546  mTranslationOffsetY = dy;
547  updateRect();
548 }
549 
551 {
552  return mPoints.size();
553 }
554 
555 int QgsRubberBand::partSize( int geometryIndex ) const
556 {
557  if ( geometryIndex < 0 || geometryIndex >= mPoints.size() ) return 0;
558  return mPoints[geometryIndex].size();
559 }
560 
562 {
563  int count = 0;
564  QList<QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
565  for ( ; it != mPoints.constEnd(); ++it )
566  {
567  QList<QgsPointXY>::const_iterator iter = it->constBegin();
568  for ( ; iter != it->constEnd(); ++iter )
569  {
570  ++count;
571  }
572  }
573  return count;
574 }
575 
576 const QgsPointXY *QgsRubberBand::getPoint( int i, int j ) const
577 {
578  if ( i < mPoints.size() && j < mPoints[i].size() )
579  return &mPoints[i][j];
580  else
581  return nullptr;
582 }
583 
585 {
586  QgsGeometry geom;
587 
588  switch ( mGeometryType )
589  {
591  {
592  QgsPolygonXY polygon;
593  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
594  for ( ; it != mPoints.constEnd(); ++it )
595  {
596  polygon.append( getPolyline( *it ) );
597  }
598  geom = QgsGeometry::fromPolygonXY( polygon );
599  break;
600  }
601 
603  {
604  QgsMultiPointXY multiPoint;
605 
606  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
607  for ( ; it != mPoints.constEnd(); ++it )
608  {
609  multiPoint += getPolyline( *it );
610  }
611  geom = QgsGeometry::fromMultiPointXY( multiPoint );
612  break;
613  }
614 
616  default:
617  {
618  if ( !mPoints.isEmpty() )
619  {
620  if ( mPoints.size() > 1 )
621  {
622  QgsMultiPolylineXY multiPolyline;
623  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
624  for ( ; it != mPoints.constEnd(); ++it )
625  {
626  multiPolyline.append( getPolyline( *it ) );
627  }
628  geom = QgsGeometry::fromMultiPolylineXY( multiPolyline );
629  }
630  else
631  {
632  geom = QgsGeometry::fromPolylineXY( getPolyline( mPoints.at( 0 ) ) );
633  }
634  }
635  break;
636  }
637  }
638  return geom;
639 }
640 
641 QgsPolylineXY QgsRubberBand::getPolyline( const QList<QgsPointXY> &points )
642 {
643  QgsPolylineXY polyline;
644  QList<QgsPointXY>::const_iterator iter = points.constBegin();
645  for ( ; iter != points.constEnd(); ++iter )
646  {
647  polyline.append( *iter );
648  }
649  return polyline;
650 }
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:40
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() )...
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
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:66
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:104
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:72
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:83
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:76
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
Returns the 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.
Definition: qgsrectangle.h:419
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:201
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
Returns 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:176
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
Definition: qgsrectangle.h:352
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:42
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:391
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:166
const QgsMapToPixel * getCoordinateTransform()
Gets 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...
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
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:208
A full box is used to highlight points (■)
Definition: qgsrubberband.h:73
bool isValid() const
Returns whether this CRS is correctly initialized and usable.