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