forked from OlivierDelbeke/MapGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapGraphicsObject.cpp
More file actions
293 lines (243 loc) · 5.84 KB
/
Copy pathMapGraphicsObject.cpp
File metadata and controls
293 lines (243 loc) · 5.84 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include "MapGraphicsObject.h"
#include <QtDebug>
#include <QKeyEvent>
#include <QTimer>
MapGraphicsObject::MapGraphicsObject(bool sizeIsZoomInvariant, MapGraphicsObject *parent) :
_sizeIsZoomInvariant(sizeIsZoomInvariant), _constructed(false)
{
//Set default properties and the parent that was passed as argument
_enabled = true;
_opacity = 1.0;
this->setParent(parent);
_pos = QPointF(0.0,0.0);
_rotation = 0.0;
_visible = true;
_zValue = 0.0;
_selected = false;
/*
* When we get back to the event loop, mark us as constructed.
* This is a hack so that we can set properties of child objects in their constructors
*/
QTimer::singleShot(1, this, SLOT(setConstructed()));
}
MapGraphicsObject::~MapGraphicsObject()
{
}
bool MapGraphicsObject::sizeIsZoomInvariant() const
{
return _sizeIsZoomInvariant;
}
bool MapGraphicsObject::contains(const QPointF &geoPos) const
{
QRectF geoRect = this->boundingRect();
return geoRect.contains(geoPos);
}
bool MapGraphicsObject::enabled() const
{
return _enabled;
}
void MapGraphicsObject::setEnabled(bool nEnabled)
{
_enabled = nEnabled;
if (_constructed)
this->enabledChanged();
else
QTimer::singleShot(1, this, SIGNAL(enabledChanged()));
}
qreal MapGraphicsObject::opacity() const
{
return _opacity;
}
void MapGraphicsObject::setOpacity(qreal nOpacity)
{
_opacity = nOpacity;
if (_constructed)
this->opacityChanged();
else
QTimer::singleShot(1, this, SIGNAL(opacityChanged()));
}
MapGraphicsObject *MapGraphicsObject::parent() const
{
return _parent;
}
void MapGraphicsObject::setParent(MapGraphicsObject * nParent)
{
_parent = nParent;
if (_constructed)
this->parentChanged();
else
QTimer::singleShot(1, this, SIGNAL(parentChanged()));
}
const QPointF &MapGraphicsObject::pos() const
{
return _pos;
}
void MapGraphicsObject::setPos(const QPointF & nPos)
{
if (nPos == _pos)
return;
_pos = nPos;
if (_constructed)
this->posChanged();
else
QTimer::singleShot(1, this, SIGNAL(posChanged()));
}
qreal MapGraphicsObject::rotation() const
{
return _rotation;
}
void MapGraphicsObject::setRotation(qreal nRotation)
{
if (nRotation == _rotation)
return;
_rotation = nRotation;
if (_constructed)
this->rotationChanged();
else
QTimer::singleShot(1, this, SIGNAL(rotationChanged()));
}
bool MapGraphicsObject::visible() const
{
return _visible;
}
void MapGraphicsObject::setVisible(bool nVisible)
{
if (nVisible == _visible)
return;
_visible = nVisible;
if (_constructed)
this->visibleChanged();
else
QTimer::singleShot(1, this, SIGNAL(visibleChanged()));
}
qreal MapGraphicsObject::longitude() const
{
return _pos.x();
}
void MapGraphicsObject::setLongitude(qreal nLongitude)
{
this->setPos(QPointF(nLongitude,this->pos().y()));
}
qreal MapGraphicsObject::latitude() const
{
return _pos.y();
}
void MapGraphicsObject::setLatitude(qreal nLatitude)
{
this->setPos(QPointF(this->pos().x(),nLatitude));
}
qreal MapGraphicsObject::zValue() const
{
return _zValue;
}
void MapGraphicsObject::setZValue(qreal nZValue)
{
_zValue = nZValue;
if (_constructed)
this->zValueChanged();
else
QTimer::singleShot(1, this, SIGNAL(zValueChanged()));
}
bool MapGraphicsObject::isSelected() const
{
return _selected;
}
void MapGraphicsObject::setSelected(bool sel)
{
if (_selected == sel)
return;
_selected = sel;
if (_constructed)
this->selectedChanged();
else
QTimer::singleShot(1, this, SIGNAL(selectedChanged()));
}
QString MapGraphicsObject::toolTip() const
{
return _toolTip;
}
void MapGraphicsObject::setToolTip(const QString &toolTip)
{
_toolTip = toolTip;
this->toolTipChanged(toolTip);
}
void MapGraphicsObject::setFlag(MapGraphicsObject::MapGraphicsObjectFlag flag, bool enabled)
{
if (enabled)
_flags = _flags | flag;
else
_flags = _flags & (~flag);
this->flagsChanged();
}
void MapGraphicsObject::setFlags(MapGraphicsObject::MapGraphicsObjectFlags flags)
{
_flags = flags;
if (_constructed)
this->flagsChanged();
else
QTimer::singleShot(1, this, SIGNAL(flagsChanged()));
}
MapGraphicsObject::MapGraphicsObjectFlags MapGraphicsObject::flags() const
{
return _flags;
}
//protected
void MapGraphicsObject::contextMenuEvent(QGraphicsSceneContextMenuEvent * event)
{
event->ignore();
}
//protected
QVariant MapGraphicsObject::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
Q_UNUSED(change)
return value;
}
//protected
void MapGraphicsObject::keyPressEvent(QKeyEvent *event)
{
event->ignore();
}
//protected
void MapGraphicsObject::keyReleaseEvent(QKeyEvent *event)
{
event->ignore();
}
//protected
void MapGraphicsObject::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
event->ignore();
}
//protected
void MapGraphicsObject::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->ignore();
}
//protected
void MapGraphicsObject::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//The default is to accept this if we are selectable and/or movable. Otherwise, ignore!
if (this->flags() & MapGraphicsObject::ObjectIsMovable
||this->flags() & MapGraphicsObject::ObjectIsSelectable)
{
event->accept();
if (this->flags() & MapGraphicsObject::ObjectIsFocusable)
this->keyFocusRequested();
}
else
event->ignore();
}
//protected
void MapGraphicsObject::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
event->ignore();
}
//protected
void MapGraphicsObject::wheelEvent(QGraphicsSceneWheelEvent *event)
{
event->ignore();
}
//private slot
void MapGraphicsObject::setConstructed()
{
_constructed = true;
}