forked from OlivierDelbeke/MapGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapGraphicsScene.cpp
More file actions
66 lines (52 loc) · 1.47 KB
/
Copy pathMapGraphicsScene.cpp
File metadata and controls
66 lines (52 loc) · 1.47 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
#include "MapGraphicsScene.h"
#include <QtDebug>
MapGraphicsScene::MapGraphicsScene(QObject * parent)
: QObject(parent)
{
}
MapGraphicsScene::~MapGraphicsScene()
{
foreach(MapGraphicsObject * obj, _objects)
this->removeObject(obj);
}
void MapGraphicsScene::addObject(MapGraphicsObject *object)
{
if (object == 0)
return;
object->setConstructed();
connect(object,
SIGNAL(newObjectGenerated(MapGraphicsObject*)),
this,
SLOT(handleNewObjectGenerated(MapGraphicsObject*)));
connect(object,
SIGNAL(destroyed(QObject*)),
this,
SLOT(handleObjectDestroyed(QObject*)));
_objects.insert(object);
this->objectAdded(object);
}
QList<MapGraphicsObject *> MapGraphicsScene::objects() const
{
QList<MapGraphicsObject *> toRet;
return toRet;
}
void MapGraphicsScene::removeObject(MapGraphicsObject *object)
{
_objects.remove(object);
this->objectRemoved(object);
}
//private slot
void MapGraphicsScene::handleNewObjectGenerated(MapGraphicsObject *newObject)
{
this->addObject(newObject);
}
//private slot
void MapGraphicsScene::handleObjectDestroyed(QObject *object)
{
/*
We have to be careful with this casted pointer as technically at this point the MapGraphicsObject
portion of it has been destroyed. This signal comes from the QObject destructor.
*/
MapGraphicsObject *mgObj = (MapGraphicsObject*)object;
this->removeObject(mgObj);
}