add Map class destructor to manage Event memory
This commit is contained in:
parent
1151f9fc26
commit
3c5401551d
3 changed files with 13 additions and 1 deletions
|
@ -29,6 +29,7 @@ class Map : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Map(QObject *parent = nullptr);
|
explicit Map(QObject *parent = nullptr);
|
||||||
|
~Map();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -92,6 +93,9 @@ public:
|
||||||
void cacheBorder();
|
void cacheBorder();
|
||||||
bool hasUnsavedChanges();
|
bool hasUnsavedChanges();
|
||||||
|
|
||||||
|
// for memory management
|
||||||
|
QVector<Event *> ownedEvents;
|
||||||
|
|
||||||
MapPixmapItem *mapItem = nullptr;
|
MapPixmapItem *mapItem = nullptr;
|
||||||
void setMapItem(MapPixmapItem *item) { mapItem = item; }
|
void setMapItem(MapPixmapItem *item) { mapItem = item; }
|
||||||
|
|
||||||
|
|
|
@ -324,7 +324,6 @@ EventShift::~EventShift() {}
|
||||||
|
|
||||||
EventCreate::EventCreate(Editor *editor, Map *map, Event *event,
|
EventCreate::EventCreate(Editor *editor, Map *map, Event *event,
|
||||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||||
//
|
|
||||||
setText("Create Event");
|
setText("Create Event");
|
||||||
|
|
||||||
this->editor = editor;
|
this->editor = editor;
|
||||||
|
|
|
@ -16,6 +16,14 @@ Map::Map(QObject *parent) : QObject(parent)
|
||||||
editHistory.setClean();
|
editHistory.setClean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map::~Map() {
|
||||||
|
// delete all associated events
|
||||||
|
while (!ownedEvents.isEmpty()) {
|
||||||
|
Event *last = ownedEvents.takeLast();
|
||||||
|
if (last) delete last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Map::setName(QString mapName) {
|
void Map::setName(QString mapName) {
|
||||||
name = mapName;
|
name = mapName;
|
||||||
constantName = mapConstantFromName(mapName);
|
constantName = mapConstantFromName(mapName);
|
||||||
|
@ -457,6 +465,7 @@ void Map::removeEvent(Event *event) {
|
||||||
|
|
||||||
void Map::addEvent(Event *event) {
|
void Map::addEvent(Event *event) {
|
||||||
events[event->get("event_group_type")].append(event);
|
events[event->get("event_group_type")].append(event);
|
||||||
|
if (!ownedEvents.contains(event)) ownedEvents.append(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::hasUnsavedChanges() {
|
bool Map::hasUnsavedChanges() {
|
||||||
|
|
Loading…
Reference in a new issue