forked from OlivierDelbeke/MapGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapGraphicsObject.h
More file actions
191 lines (145 loc) · 5.19 KB
/
Copy pathMapGraphicsObject.h
File metadata and controls
191 lines (145 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#ifndef MAPGRAPHICSOBJECT_H
#define MAPGRAPHICSOBJECT_H
#include <QObject>
#include <QPointF>
#include <QRectF>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsItem>
#include <QString>
#include "MapGraphics_global.h"
#include "MapTileSource.h"
class MAPGRAPHICSSHARED_EXPORT MapGraphicsObject : public QObject
{
Q_OBJECT
public:
enum class CoordinateMode
{
LocalMeters,
ScreenPixels,
MapPixels
};
enum MapGraphicsObjectFlag
{
ObjectIsMovable = 0x01,
ObjectIsSelectable = 0x02,
ObjectIsFocusable = 0x04
};
Q_DECLARE_FLAGS(MapGraphicsObjectFlags,MapGraphicsObjectFlag)
//PrivateQGraphicsObject will call some of our protected event handlers that nobody else needs to touch
friend class PrivateQGraphicsObject;
friend class MapGraphicsScene;
public:
explicit MapGraphicsObject(CoordinateMode coordinateMode=CoordinateMode::LocalMeters,
MapGraphicsObject *parent = 0);
virtual ~MapGraphicsObject();
CoordinateMode coordinateMode() const;
/*!
\brief You need to implement this. LocalMeters objects return ENU meters and their rectangle
should be centered at (0,0). ScreenPixels objects return screen pixels. MapPixels objects return
offsets in the tile source's projected map-pixel coordinates relative to pos().
\return QRectF
*/
virtual QRectF boundingRect() const=0;
/*!\
\brief Extra padding around boundingRect(), in screen pixels.
This is useful for non-zoom-invariant objects that paint cosmetic pens.
*/
virtual qreal boundingRectPadding() const;
/*!
\brief You can reimplement this if you want. Given a point in geographic coordinates (lat/lon),
return true if the object contains that point. Return false otherwise. The default implementation just uses
boundingRect() to decide.
\param geoPos
\return bool
*/
virtual bool contains(const QPointF& geoPos) const;
/**
* @brief Paints the object in the coordinate system selected by coordinateMode(). The painter
* operates in the same units as boundingRect(): ENU meters, screen pixels, or projected map-pixel
* offsets.
* You must implement this.
*
* @param painter
* @param option
* @param widget
*/
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget=0)=0;
bool enabled() const;
void setEnabled(bool);
qreal opacity() const;
void setOpacity(qreal);
MapGraphicsObject * parent() const;
void setParent(MapGraphicsObject *);
const QPointF& pos() const;
virtual void setPos(const QPointF&);
qreal rotation() const;
void setRotation(qreal);
bool visible() const;
void setVisible(bool);
qreal longitude() const;
void setLongitude(qreal);
qreal latitude() const;
void setLatitude(qreal);
qreal zValue() const;
void setZValue(qreal);
bool isSelected() const;
void setSelected(bool);
QString toolTip() const;
void setToolTip(const QString& toolTip);
void setFlag(MapGraphicsObjectFlag, bool enabled=true);
void setFlags(MapGraphicsObject::MapGraphicsObjectFlags);
MapGraphicsObject::MapGraphicsObjectFlags flags() const;
protected:
virtual void updateMapProjection(const MapTileSource& tileSource, quint8 zoomLevel);
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent * event);
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value);
virtual void keyPressEvent(QKeyEvent * event);
virtual void keyReleaseEvent(QKeyEvent * event);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
signals:
void enabledChanged();
void opacityChanged();
void parentChanged();
void posChanged();
void rotationChanged();
void visibleChanged();
void zValueChanged();
void toolTipChanged(const QString& toolTip);
void flagsChanged();
//Please do not use this for now. It should only be used internally for now. Ugly, I know.
void selectedChanged();
void newObjectGenerated(MapGraphicsObject *);
/*!
\brief Emitted when we'd like to be redrawn
*/
void redrawRequested();
void geometryChanged();
/*!
\brief Emitted when this MapGraphicsObject wants keyboard focus. (to receive keyboard events)
*/
void keyFocusRequested();
public slots:
private slots:
void setConstructed();
private:
CoordinateMode _coordinateMode;
bool _enabled;
qreal _opacity;
MapGraphicsObject * _parent;
QPointF _pos;
qreal _rotation;
bool _visible;
qreal _zValue;
bool _selected;
QString _toolTip;
MapGraphicsObject::MapGraphicsObjectFlags _flags;
bool _constructed;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MapGraphicsObject::MapGraphicsObjectFlags)
#endif // MAPGRAPHICSOBJECT_H