QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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  const auto constPts = pts;
440  for ( QPointF pt : constPts )
441  {
442  double x = pt.x();
443  double y = pt.y();
444 
445  qreal s = ( mIconSize - 1 ) / 2.0;
446 
447  switch ( mIconType )
448  {
449  case ICON_NONE:
450  break;
451 
452  case ICON_CROSS:
453  p->drawLine( QLineF( x - s, y, x + s, y ) );
454  p->drawLine( QLineF( x, y - s, x, y + s ) );
455  break;
456 
457  case ICON_X:
458  p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
459  p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
460  break;
461 
462  case ICON_BOX:
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  p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
467  break;
468 
469  case ICON_FULL_BOX:
470  p->drawRect( x - s, y - s, mIconSize, mIconSize );
471  break;
472 
473  case ICON_CIRCLE:
474  p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
475  break;
476 
477  case ICON_DIAMOND:
478  case ICON_FULL_DIAMOND:
479  {
480  QPointF pts[] =
481  {
482  QPointF( x, y - s ),
483  QPointF( x + s, y ),
484  QPointF( x, y + s ),
485  QPointF( x - s, y )
486  };
487  if ( mIconType == ICON_FULL_DIAMOND )
488  p->drawPolygon( pts, 4 );
489  else
490  p->drawPolyline( pts, 4 );
491  }
492  }
493  }
494  }
495  break;
496 
498  default:
499  {
500  p->drawPolyline( pts );
501  }
502  break;
503  }
504 }
505 
507 {
508  if ( mPoints.empty() )
509  {
510  setRect( QgsRectangle() );
511  setVisible( false );
512  return;
513  }
514 
515  const QgsMapToPixel &m2p = *( mMapCanvas->getCoordinateTransform() );
516 
517  qreal w = ( ( mIconSize - 1 ) / 2 + mPen.width() ); // in canvas units
518 
519  QgsRectangle r; // in canvas units
520  for ( int i = 0; i < mPoints.size(); ++i )
521  {
522  QList<QgsPointXY>::const_iterator it = mPoints.at( i ).constBegin(),
523  itE = mPoints.at( i ).constEnd();
524  for ( ; it != itE; ++it )
525  {
526  QgsPointXY p( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
527  p = m2p.transform( p );
528  QgsRectangle rect( p.x() - w, p.y() - w, p.x() + w, p.y() + w );
529 
530  if ( r.isEmpty() )
531  {
532  // Get rectangle of the first point
533  r = rect;
534  }
535  else
536  {
537  r.combineExtentWith( rect );
538  }
539  }
540  }
541 
542  // This is an hack to pass QgsMapCanvasItem::setRect what it
543  // expects (encoding of position and size of the item)
544  qreal res = m2p.mapUnitsPerPixel();
545  QgsPointXY topLeft = m2p.toMapCoordinates( r.xMinimum(), r.yMinimum() );
546  QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + r.width()*res, topLeft.y() - r.height()*res );
547 
548  setRect( rect );
549 }
550 
552 {
553  // re-compute rectangle
554  // See https://github.com/qgis/QGIS/issues/20566
555  // NOTE: could be optimized by saving map-extent
556  // of rubberband and simply re-projecting
557  // that to device-rectangle on "updatePosition"
558  updateRect();
559 }
560 
561 void QgsRubberBand::setTranslationOffset( double dx, double dy )
562 {
563  mTranslationOffsetX = dx;
564  mTranslationOffsetY = dy;
565  updateRect();
566 }
567 
569 {
570  return mPoints.size();
571 }
572 
573 int QgsRubberBand::partSize( int geometryIndex ) const
574 {
575  if ( geometryIndex < 0 || geometryIndex >= mPoints.size() ) return 0;
576  return mPoints[geometryIndex].size();
577 }
578 
580 {
581  int count = 0;
582  QList<QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
583  for ( ; it != mPoints.constEnd(); ++it )
584  {
585  QList<QgsPointXY>::const_iterator iter = it->constBegin();
586  for ( ; iter != it->constEnd(); ++iter )
587  {
588  ++count;
589  }
590  }
591  return count;
592 }
593 
594 const QgsPointXY *QgsRubberBand::getPoint( int i, int j ) const
595 {
596  if ( i < mPoints.size() && j < mPoints[i].size() )
597  return &mPoints[i][j];
598  else
599  return nullptr;
600 }
601 
603 {
604  QgsGeometry geom;
605 
606  switch ( mGeometryType )
607  {
609  {
610  QgsPolygonXY polygon;
611  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
612  for ( ; it != mPoints.constEnd(); ++it )
613  {
614  polygon.append( getPolyline( *it ) );
615  }
616  geom = QgsGeometry::fromPolygonXY( polygon );
617  break;
618  }
619 
621  {
622  QgsMultiPointXY multiPoint;
623 
624  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
625  for ( ; it != mPoints.constEnd(); ++it )
626  {
627  multiPoint += getPolyline( *it );
628  }
629  geom = QgsGeometry::fromMultiPointXY( multiPoint );
630  break;
631  }
632 
634  default:
635  {
636  if ( !mPoints.isEmpty() )
637  {
638  if ( mPoints.size() > 1 )
639  {
640  QgsMultiPolylineXY multiPolyline;
641  QList< QList<QgsPointXY> >::const_iterator it = mPoints.constBegin();
642  for ( ; it != mPoints.constEnd(); ++it )
643  {
644  multiPolyline.append( getPolyline( *it ) );
645  }
646  geom = QgsGeometry::fromMultiPolylineXY( multiPolyline );
647  }
648  else
649  {
650  geom = QgsGeometry::fromPolylineXY( getPolyline( mPoints.at( 0 ) ) );
651  }
652  }
653  break;
654  }
655  }
656  return geom;
657 }
658 
659 QgsPolylineXY QgsRubberBand::getPolyline( const QList<QgsPointXY> &points )
660 {
661  QgsPolylineXY polyline;
662  QList<QgsPointXY>::const_iterator iter = points.constBegin();
663  for ( ; iter != points.constEnd(); ++iter )
664  {
665  polyline.append( *iter );
666  }
667  return polyline;
668 }
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:560
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:89
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...
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: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 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:83
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:666
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:139
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:49
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:438
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:115
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.