From e310732169b471eafd10c963d36e5392915482b2 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Fri, 16 Apr 2021 09:04:38 -0400 Subject: [PATCH] Make eventScriptLabelModel and eventScriptLabelCompleter into values rather than pointers --- include/project.h | 8 ++++---- src/core/parseutil.cpp | 12 ++++++++---- src/project.cpp | 25 ++++++++++++++----------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/project.h b/include/project.h index 470a0d12..b33dcee9 100644 --- a/include/project.h +++ b/include/project.h @@ -62,7 +62,7 @@ public: QStringList secretBaseIds; QStringList bgEventFacingDirections; QStringList trainerTypes; - QStringList eventScriptLabels; + QStringList globalScriptLabels; QMap metatileBehaviorMap; QMap metatileBehaviorMapInverse; QMap facingDirections; @@ -180,7 +180,7 @@ public: QString getScriptDefaultString(bool usePoryScript, QString mapName) const; QString getMapScriptsFilePath(const QString &mapName) const; QStringList getEventScriptsFilePaths() const; - QCompleter *getEventScriptLabelCompleter(QStringList additionalCompletions) const; + QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels); bool loadMapBorder(Map *map); @@ -223,8 +223,8 @@ private: static int default_map_size; static int max_object_events; - QStringListModel *eventScriptLabelModel = nullptr; - QCompleter *eventScriptLabelCompleter = nullptr; + QStringListModel eventScriptLabelModel; + QCompleter eventScriptLabelCompleter; signals: void reloadProject(); diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index ea1807e2..e45e8b10 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -467,15 +467,15 @@ QStringList ParseUtil::getGlobalScriptLabels(const QString &filePath) { return getGlobalRawScriptLabels(readTextFile(filePath)); else if (filePath.endsWith(".pory")) return getGlobalPoryScriptLabels(readTextFile(filePath)); - - return { }; + else + return { }; } QStringList ParseUtil::getGlobalRawScriptLabels(QString text) { removeStringLiterals(text); removeLineComments(text, "@"); - auto rawScriptLabels = QStringList(); + QStringList rawScriptLabels; QRegularExpressionMatchIterator it = re_globalIncScriptLabel.globalMatch(text); while (it.hasNext()) { @@ -490,7 +490,7 @@ QStringList ParseUtil::getGlobalPoryScriptLabels(QString text) { removeStringLiterals(text); removeLineComments(text, {"//", "#"}); - auto poryScriptLabels = QStringList(); + QStringList poryScriptLabels; QRegularExpressionMatchIterator it = re_globalPoryScriptLabel.globalMatch(text); while (it.hasNext()) @@ -520,12 +520,15 @@ QString ParseUtil::removeLineComments(QString text, const QStringList &commentSy } #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + #include QStringList ParseUtil::splitShellCommand(QStringView command) { return QProcess::splitCommand(command); } + #else + // The source for QProcess::splitCommand() as of Qt 5.15.2 QStringList ParseUtil::splitShellCommand(QStringView command) { QStringList args; @@ -565,4 +568,5 @@ QStringList ParseUtil::splitShellCommand(QStringView command) { return args; } + #endif diff --git a/src/project.cpp b/src/project.cpp index 6cdb7008..e754d5ac 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -36,7 +36,10 @@ int Project::max_map_data_size = 10240; // 0x2800 int Project::default_map_size = 20; int Project::max_object_events = 64; -Project::Project(QWidget *parent) : QObject(parent) +Project::Project(QWidget *parent) : + QObject(parent), + eventScriptLabelModel(this), + eventScriptLabelCompleter(this) { initSignals(); } @@ -2313,12 +2316,12 @@ bool Project::readMiscellaneousConstants() { bool Project::readEventScriptLabels() { for (const auto &filePath : getEventScriptsFilePaths()) - eventScriptLabels << ParseUtil::getGlobalScriptLabels(filePath); + globalScriptLabels << ParseUtil::getGlobalScriptLabels(filePath); - eventScriptLabelModel = new QStringListModel(eventScriptLabels, this); - eventScriptLabelCompleter = new QCompleter(eventScriptLabelModel, this); - eventScriptLabelCompleter->setCaseSensitivity(Qt::CaseInsensitive); - eventScriptLabelCompleter->setFilterMode(Qt::MatchContains); + eventScriptLabelModel.setStringList(globalScriptLabels); + eventScriptLabelCompleter.setModel(&eventScriptLabelModel); + eventScriptLabelCompleter.setCaseSensitivity(Qt::CaseInsensitive); + eventScriptLabelCompleter.setFilterMode(Qt::MatchContains); return true; } @@ -2386,11 +2389,11 @@ QStringList Project::getEventScriptsFilePaths() const { return filePaths; } -QCompleter *Project::getEventScriptLabelCompleter(QStringList additionalCompletions) const { - additionalCompletions += eventScriptLabels; - additionalCompletions.removeDuplicates(); - eventScriptLabelModel->setStringList(additionalCompletions); - return eventScriptLabelCompleter; +QCompleter *Project::getEventScriptLabelCompleter(QStringList additionalScriptLabels) { + additionalScriptLabels << globalScriptLabels; + additionalScriptLabels.removeDuplicates(); + eventScriptLabelModel.setStringList(additionalScriptLabels); + return &eventScriptLabelCompleter; } void Project::loadEventPixmaps(QList objects) {