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
|
||||
public:
|
||||
explicit Map(QObject *parent = nullptr);
|
||||
~Map();
|
||||
|
||||
public:
|
||||
QString name;
|
||||
|
@ -92,6 +93,9 @@ public:
|
|||
void cacheBorder();
|
||||
bool hasUnsavedChanges();
|
||||
|
||||
// for memory management
|
||||
QVector<Event *> ownedEvents;
|
||||
|
||||
MapPixmapItem *mapItem = nullptr;
|
||||
void setMapItem(MapPixmapItem *item) { mapItem = item; }
|
||||
|
||||
|
|
|
@ -324,7 +324,6 @@ EventShift::~EventShift() {}
|
|||
|
||||
EventCreate::EventCreate(Editor *editor, Map *map, Event *event,
|
||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
//
|
||||
setText("Create Event");
|
||||
|
||||
this->editor = editor;
|
||||
|
|
|
@ -16,6 +16,14 @@ Map::Map(QObject *parent) : QObject(parent)
|
|||
editHistory.setClean();
|
||||
}
|
||||
|
||||
Map::~Map() {
|
||||
// delete all associated events
|
||||
while (!ownedEvents.isEmpty()) {
|
||||
Event *last = ownedEvents.takeLast();
|
||||
if (last) delete last;
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setName(QString mapName) {
|
||||
name = mapName;
|
||||
constantName = mapConstantFromName(mapName);
|
||||
|
@ -457,6 +465,7 @@ void Map::removeEvent(Event *event) {
|
|||
|
||||
void Map::addEvent(Event *event) {
|
||||
events[event->get("event_group_type")].append(event);
|
||||
if (!ownedEvents.contains(event)) ownedEvents.append(event);
|
||||
}
|
||||
|
||||
bool Map::hasUnsavedChanges() {
|
||||
|
|
Loading…
Reference in a new issue