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