QGIS API Documentation  2.99.0-Master (01468d0)
qgsmapcanvasitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapcanvasitem.h - base class for map canvas items
3  ----------------------
4  begin : February 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
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 #ifndef QGSMAPCANVASITEM_H
17 #define QGSMAPCANVASITEM_H
18 
19 #include <QGraphicsItem>
20 #include "qgis.h"
21 #include "qgsrectangle.h"
22 #include "qgis_gui.h"
23 
24 class QgsMapCanvas;
25 class QgsRenderContext;
26 class QPainter;
27 
32 class GUI_EXPORT QgsMapCanvasItem : public QGraphicsItem
33 {
34  protected:
35 
38 
39  virtual ~QgsMapCanvasItem();
40 
42  virtual void paint( QPainter *painter ) = 0;
43 
44  virtual void paint( QPainter *painter,
45  const QStyleOptionGraphicsItem *option,
46  QWidget *widget = nullptr ) override;
47 
49  void updateCanvas();
50 
55  bool setRenderContextVariables( QPainter *p, QgsRenderContext &context ) const;
56 
57  public:
58 
60  virtual void updatePosition();
61 
62  virtual QRectF boundingRect() const override;
63 
65  QgsRectangle rect() const;
66 
68  void setRect( const QgsRectangle &r, bool resetRotation = true );
69 
71  QgsPointXY toMapCoordinates( QPoint point ) const;
72 
74  QPointF toCanvasCoordinates( const QgsPointXY &point ) const;
75 
76  protected:
77 
79  QgsMapCanvas *mMapCanvas = nullptr;
80 
90 
91  double mRectRotation;
92 
94  QSizeF mItemSize;
95 
96 };
97 
98 
99 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:38
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A class to represent a 2D point.
Definition: qgspointxy.h:42
An abstract class for items that can be placed on the map canvas.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
QSizeF mItemSize
cached size of the item (to return in boundingRect())
QgsRectangle mRect
cached canvas item rectangle in map coordinates encodes position (xmin,ymax) and size (width/height) ...
Contains information about the context of a rendering operation.