diff --git a/include/core/events.h b/include/core/events.h index 2e00ef72..c0a5a625 100644 --- a/include/core/events.h +++ b/include/core/events.h @@ -187,6 +187,7 @@ class Event { static QString eventGroupToString(Event::Group group); static QString eventTypeToString(Event::Type type); static Event::Type eventTypeFromString(QString type); + static void clearIcons(); static void setIcons(); // protected attributes diff --git a/include/project.h b/include/project.h index c3fc1677..9b90a450 100644 --- a/include/project.h +++ b/include/project.h @@ -89,6 +89,8 @@ class Project : public QObject void clearMapCache(); void clearTilesetCache(); + void clearMapLayouts(); + void clearEventGraphics(); struct DataQualifiers { diff --git a/include/ui/updatepromoter.h b/include/ui/updatepromoter.h index 8b67c69e..de73bcdd 100644 --- a/include/ui/updatepromoter.h +++ b/include/ui/updatepromoter.h @@ -17,7 +17,7 @@ class UpdatePromoter : public QDialog public: explicit UpdatePromoter(QWidget *parent, NetworkAccessManager *manager); - ~UpdatePromoter() {}; + ~UpdatePromoter(); void checkForUpdates(); void updatePreferences(); diff --git a/src/core/events.cpp b/src/core/events.cpp index 13be4153..89416eae 100644 --- a/src/core/events.cpp +++ b/src/core/events.cpp @@ -146,10 +146,13 @@ void Event::loadPixmap(Project *) { this->pixmap = pixmap ? *pixmap : QPixmap(); } -void Event::setIcons() { +void Event::clearIcons() { qDeleteAll(icons); icons.clear(); +} +void Event::setIcons() { + clearIcons(); const int w = 16; const int h = 16; static const QPixmap defaultIcons = QPixmap(":/images/Entities_16x16.png"); diff --git a/src/editor.cpp b/src/editor.cpp index 69b2ffb9..ad228d77 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1488,7 +1488,7 @@ void Editor::clearMap() { bool Editor::displayMap() { if (!scene) { scene = new QGraphicsScene; - MapSceneEventFilter *filter = new MapSceneEventFilter(); + MapSceneEventFilter *filter = new MapSceneEventFilter(scene); scene->installEventFilter(filter); connect(filter, &MapSceneEventFilter::wheelZoom, this, &Editor::onWheelZoom); scene->installEventFilter(this->map_ruler); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e87592f3..588ce90f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -85,6 +85,9 @@ MainWindow::~MainWindow() { delete label_MapRulerStatus; delete editor; + delete mapListProxyModel; + delete mapGroupItemsList; + delete mapListModel; delete ui; } @@ -1117,6 +1120,8 @@ void MainWindow::clearProjectUI() { mapListModel->clear(); mapListIndexes.clear(); mapGroupItemsList->clear(); + + Event::clearIcons(); } void MainWindow::sortMapList() { diff --git a/src/project.cpp b/src/project.cpp index ea42988c..5ffc3c43 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -44,6 +44,8 @@ Project::~Project() { clearMapCache(); clearTilesetCache(); + clearMapLayouts(); + clearEventGraphics(); } void Project::initSignals() { @@ -362,6 +364,7 @@ bool Project::loadMapData(Map* map) { heal->setRespawnNPC(loc.respawnNPC); } map->events[Event::Group::Heal].append(heal); + map->ownedEvents.append(heal); } } @@ -455,9 +458,14 @@ bool Project::loadMapLayout(Map* map) { } } -bool Project::readMapLayouts() { +void Project::clearMapLayouts() { + qDeleteAll(mapLayouts); mapLayouts.clear(); mapLayoutsTable.clear(); +} + +bool Project::readMapLayouts() { + clearMapLayouts(); QString layoutsFilepath = projectConfig.getFilePath(ProjectFilePath::json_layouts); QString fullFilepath = QString("%1/%2").arg(root).arg(layoutsFilepath); @@ -483,7 +491,7 @@ bool Project::readMapLayouts() { .arg(layoutsLabel)); } - QList requiredFields = QList{ + static const QList requiredFields = QList{ "id", "name", "width", @@ -2554,7 +2562,14 @@ void Project::setEventPixmap(Event *event, bool forceLoad) { event->loadPixmap(this); } +void Project::clearEventGraphics() { + qDeleteAll(eventGraphicsMap); + eventGraphicsMap.clear(); +} + bool Project::readEventGraphics() { + clearEventGraphics(); + fileWatcher.addPaths(QStringList() << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx_pointers) << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx_info) << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_pic_tables) @@ -2564,8 +2579,6 @@ bool Project::readEventGraphics() { const QString pointersName = projectConfig.getIdentifier(ProjectIdentifier::symbol_obj_event_gfx_pointers); QMap pointerHash = parser.readNamedIndexCArray(pointersFilepath, pointersName); - qDeleteAll(eventGraphicsMap); - eventGraphicsMap.clear(); QStringList gfxNames = gfxDefines.keys(); // The positions of each of the required members for the gfx info struct. @@ -2584,14 +2597,13 @@ bool Project::readEventGraphics() { QMap graphicIncbins = parser.readCIncbinMulti(projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx)); for (QString gfxName : gfxNames) { - EventGraphics * eventGraphics = new EventGraphics; - QString info_label = pointerHash[gfxName].replace("&", ""); if (!gfxInfos.contains(info_label)) continue; const auto gfxInfoAttributes = gfxInfos[info_label]; + auto eventGraphics = new EventGraphics; eventGraphics->inanimate = ParseUtil::gameStringToBool(gfxInfoAttributes.value("inanimate")); QString pic_label = gfxInfoAttributes.value("images"); QString dimensions_label = gfxInfoAttributes.value("oam"); diff --git a/src/ui/noscrollcombobox.cpp b/src/ui/noscrollcombobox.cpp index 3db2a956..542bf5fd 100644 --- a/src/ui/noscrollcombobox.cpp +++ b/src/ui/noscrollcombobox.cpp @@ -19,7 +19,7 @@ NoScrollComboBox::NoScrollComboBox(QWidget *parent) this->completer()->setFilterMode(Qt::MatchContains); static const QRegularExpression re("[^\\s]*"); - QValidator *validator = new QRegularExpressionValidator(re); + QValidator *validator = new QRegularExpressionValidator(re, this); this->setValidator(validator); } diff --git a/src/ui/updatepromoter.cpp b/src/ui/updatepromoter.cpp index 7b9d39d6..f9331a16 100644 --- a/src/ui/updatepromoter.cpp +++ b/src/ui/updatepromoter.cpp @@ -33,6 +33,10 @@ UpdatePromoter::UpdatePromoter(QWidget *parent, NetworkAccessManager *manager) this->resetDialog(); } +UpdatePromoter::~UpdatePromoter() { + delete ui; +} + void UpdatePromoter::resetDialog() { this->button_Downloads->setEnabled(false);