17
17
#ifndef QGSMAPCANVASITEM_H
18
18
#define QGSMAPCANVASITEM_H
20
#include <Q3CanvasItem>
20
#include <QGraphicsItem>
21
#include "qgsrectangle.h"
23
23
class QgsMapCanvas;
26
class QgsMapCanvasItem : public QObject, public Q3CanvasRectangle
27
* An abstract class for items that can be placed on the
30
class GUI_EXPORT QgsMapCanvasItem : public QGraphicsItem
32
34
//! protected constructor: cannot be constructed directly
33
QgsMapCanvasItem(QgsMapCanvas* mapCanvas);
35
QgsMapCanvasItem( QgsMapCanvas* mapCanvas );
35
37
virtual ~QgsMapCanvasItem();
37
39
//! function to be implemented by derived classes
38
virtual void drawShape(QPainter & p)=0;
40
virtual void paint( QPainter * painter ) = 0;
42
//! paint function called by map canvas
43
virtual void paint( QPainter * painter,
44
const QStyleOptionGraphicsItem * option,
45
QWidget * widget = 0 );
40
47
//! schedules map canvas for repaint
41
48
void updateCanvas();
53
//! called on changed extent or resize event to update position of the item
54
virtual void updatePosition();
56
//! default implementation for canvas items
57
virtual QRectF boundingRect() const;
46
59
//! sets current offset, to be called from QgsMapCanvas
47
void setPanningOffset(const QPoint& point);
60
void setPanningOffset( const QPoint& point );
49
62
//! returns canvas item rectangle
63
QgsRectangle rect() const;
52
65
//! sets canvas item rectangle
53
void setRect(const QgsRect& r);
66
void setRect( const QgsRectangle& r );
55
68
//! transformation from screen coordinates to map coordinates
56
QgsPoint toMapCoords(const QPoint& point);
69
QgsPoint toMapCoordinates( const QPoint& point );
58
71
//! transformation from map coordinates to screen coordinates
59
QPoint toCanvasCoords(const QgsPoint& point);
61
/** called on changed extents or changed item rectangle
62
* Override this in your subclass if you wish to have custom
63
* behaviour for when the canvas area of interest is changed */
64
virtual void updatePosition();
72
QPointF toCanvasCoordinates( const QgsPoint& point );
68
76
//! pointer to map canvas
69
77
QgsMapCanvas* mMapCanvas;
71
79
//! canvas item rectangle (in map coordinates)
74
82
//! offset from normal position due current panning operation,
75
83
//! used when converting map coordinates to move map canvas items
76
84
QPoint mPanningOffset;
86
//! cached size of the item (to return in boundingRect())