QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgsrectangle.h"
22
23#include <QGraphicsItem>
24
25class QgsMapCanvas;
27class QPainter;
28
34class GUI_EXPORT QgsMapCanvasItem : public QGraphicsItem
35{
36 protected:
39
40 ~QgsMapCanvasItem() override;
41
43 virtual void paint( QPainter *painter ) = 0;
44
45 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
46
48 void updateCanvas();
49
56 bool setRenderContextVariables( QPainter *p, QgsRenderContext &context ) const;
57
58 public:
60 virtual void updatePosition();
61
62 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:
79
91
92 double mRectRotation = 0.0;
93
95 QSizeF mItemSize;
96};
97
98
99#endif
QRectF boundingRect() const override
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
QSizeF mItemSize
cached size of the item (to return in boundingRect())
QgsRectangle rect() const
returns canvas item rectangle in map units
QgsRectangle mRect
cached canvas item rectangle in map coordinates encodes position (xmin,ymax) and size (width/height) ...
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsMapCanvas * mMapCanvas
pointer to map canvas
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
QgsMapCanvasItem(QgsMapCanvas *mapCanvas)
protected constructor: cannot be constructed directly
void updateCanvas()
schedules map canvas for repaint
bool setRenderContextVariables(QPainter *p, QgsRenderContext &context) const
Sets render context parameters.
virtual void updatePosition()
called on changed extent or resize event to update position of the item
QgsPointXY toMapCoordinates(QPoint point) const
transformation from screen coordinates to map coordinates
Map canvas is a class for displaying all GIS data types on a canvas.
Represents a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
Contains information about the context of a rendering operation.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53