From bd5446a40be7acea956a789c1011079b2f88391d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 5 Sep 2022 11:53:30 -0400 Subject: [PATCH] Move script utility functions to own object --- include/api_util.h | 54 ++++++++++++ include/mainwindow.h | 47 ++-------- include/scripting.h | 3 +- porymap.pro | 1 + src/mainwindow.cpp | 13 +-- src/script_api/api_util.cpp | 161 +++++++++++++++++++---------------- src/script_api/scripting.cpp | 22 ++--- src/ui/graphicsview.cpp | 6 +- 8 files changed, 164 insertions(+), 143 deletions(-) create mode 100644 include/api_util.h diff --git a/include/api_util.h b/include/api_util.h new file mode 100644 index 00000000..85ad3f1b --- /dev/null +++ b/include/api_util.h @@ -0,0 +1,54 @@ +#pragma once +#ifndef APIUTIL_H +#define APIUTIL_H + +#include "mainwindow.h" + +class ScriptUtility : public QObject +{ + Q_OBJECT + +public: + ScriptUtility(MainWindow *mainWindow); + void clearActions(); + QString getActionFunctionName(QString actionName); + Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = ""); + Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds); + Q_INVOKABLE void log(QString message); + Q_INVOKABLE void warn(QString message); + Q_INVOKABLE void error(QString message); + Q_INVOKABLE void showMessage(QString text, QString informativeText = "", QString detailedText = ""); + Q_INVOKABLE void showWarning(QString text, QString informativeText = "", QString detailedText = ""); + Q_INVOKABLE void showError(QString text, QString informativeText = "", QString detailedText = ""); + Q_INVOKABLE bool showQuestion(QString text, QString informativeText = "", QString detailedText = ""); + Q_INVOKABLE QJSValue getInputText(QString title, QString label, QString defaultValue = ""); + Q_INVOKABLE QJSValue getInputNumber(QString title, QString label, double defaultValue = 0, double min = INT_MIN, double max = INT_MAX, int decimals = 0, double step = 1); + Q_INVOKABLE QJSValue getInputItem(QString title, QString label, QStringList items, int defaultValue = 0, bool editable = false); + Q_INVOKABLE int getMainTab(); + Q_INVOKABLE void setMainTab(int index); + Q_INVOKABLE int getMapViewTab(); + Q_INVOKABLE void setMapViewTab(int index); + Q_INVOKABLE void setGridVisibility(bool visible); + Q_INVOKABLE bool getGridVisibility(); + Q_INVOKABLE void setBorderVisibility(bool visible); + Q_INVOKABLE bool getBorderVisibility(); + Q_INVOKABLE void setSmartPathsEnabled(bool visible); + Q_INVOKABLE bool getSmartPathsEnabled(); + Q_INVOKABLE QList getCustomScripts(); + Q_INVOKABLE QList getMetatileLayerOrder(); + Q_INVOKABLE void setMetatileLayerOrder(QList order); + Q_INVOKABLE QList getMetatileLayerOpacity(); + Q_INVOKABLE void setMetatileLayerOpacity(QList order); + Q_INVOKABLE bool isPrimaryTileset(QString tilesetName); + Q_INVOKABLE bool isSecondaryTileset(QString tilesetName); + +private: + void callTimeoutFunction(QJSValue callback); + void runMessageBox(QString text, QString informativeText, QString detailedText, QMessageBox::Icon icon); + + MainWindow *window; + QList registeredActions; + QMap actionMap; +}; + +#endif // APIUTIL_H diff --git a/include/mainwindow.h b/include/mainwindow.h index 131250e4..d317764e 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -42,8 +42,6 @@ public: MainWindow(const MainWindow &) = delete; MainWindow & operator = (const MainWindow &) = delete; - MapView *getMapView(); - // Scripting API Q_INVOKABLE QJSValue getBlock(int x, int y); void tryRedrawMapArea(bool forceRedraw); @@ -104,36 +102,10 @@ public: Q_INVOKABLE int getNumSecondaryTilesetMetatiles(); Q_INVOKABLE int getNumPrimaryTilesetTiles(); Q_INVOKABLE int getNumSecondaryTilesetTiles(); - Q_INVOKABLE bool isPrimaryTileset(QString tilesetName); - Q_INVOKABLE bool isSecondaryTileset(QString tilesetName); Q_INVOKABLE QString getPrimaryTileset(); Q_INVOKABLE QString getSecondaryTileset(); Q_INVOKABLE void setPrimaryTileset(QString tileset); Q_INVOKABLE void setSecondaryTileset(QString tileset); - Q_INVOKABLE void setGridVisibility(bool visible); - Q_INVOKABLE bool getGridVisibility(); - Q_INVOKABLE void setBorderVisibility(bool visible); - Q_INVOKABLE bool getBorderVisibility(); - Q_INVOKABLE void setSmartPathsEnabled(bool visible); - Q_INVOKABLE bool getSmartPathsEnabled(); - Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = ""); - Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds); - void invokeCallback(QJSValue callback); - Q_INVOKABLE void log(QString message); - Q_INVOKABLE void warn(QString message); - Q_INVOKABLE void error(QString message); - void runMessageBox(QString text, QString informativeText, QString detailedText, QMessageBox::Icon icon); - Q_INVOKABLE void showMessage(QString text, QString informativeText = "", QString detailedText = ""); - Q_INVOKABLE void showWarning(QString text, QString informativeText = "", QString detailedText = ""); - Q_INVOKABLE void showError(QString text, QString informativeText = "", QString detailedText = ""); - Q_INVOKABLE bool showQuestion(QString text, QString informativeText = "", QString detailedText = ""); - Q_INVOKABLE QJSValue getInputText(QString title, QString label, QString defaultValue = ""); - Q_INVOKABLE QJSValue getInputNumber(QString title, QString label, double defaultValue = 0, double min = INT_MIN, double max = INT_MAX, int decimals = 0, double step = 1); - Q_INVOKABLE QJSValue getInputItem(QString title, QString label, QStringList items, int defaultValue = 0, bool editable = false); - Q_INVOKABLE QList getMetatileLayerOrder(); - Q_INVOKABLE void setMetatileLayerOrder(QList order); - Q_INVOKABLE QList getMetatileLayerOpacity(); - Q_INVOKABLE void setMetatileLayerOpacity(QList order); void saveMetatilesByMetatileId(int metatileId); void saveMetatileAttributesByMetatileId(int metatileId); Metatile * getMetatile(int metatileId); @@ -157,11 +129,6 @@ public: Q_INVOKABLE void setMetatileTiles(int metatileId, QJSValue tilesObj, int tileStart = 0, int tileEnd = -1, bool forceRedraw = true); Q_INVOKABLE void setMetatileTiles(int metatileId, int tileId, bool xflip, bool yflip, int palette, int tileStart = 0, int tileEnd = -1, bool forceRedraw = true); Q_INVOKABLE QJSValue getTilePixels(int tileId); - Q_INVOKABLE QList getCustomScripts(); - Q_INVOKABLE int getMainTab(); - Q_INVOKABLE void setMainTab(int index); - Q_INVOKABLE int getMapViewTab(); - Q_INVOKABLE void setMapViewTab(int index); bool gameStringToBool(QString s); Q_INVOKABLE QString getSong(); Q_INVOKABLE void setSong(QString song); @@ -186,6 +153,10 @@ public: Q_INVOKABLE int getFloorNumber(); Q_INVOKABLE void setFloorNumber(int floorNumber); +public slots: + void on_mainTabBar_tabBarClicked(int index); + void on_mapViewTab_tabBarClicked(int index); + private slots: void on_action_Open_Project_triggered(); void on_action_Reload_Project_triggered(); @@ -232,9 +203,6 @@ private slots: void on_actionOpen_Recent_Project_On_Launch_triggered(bool checked); void on_actionEdit_Shortcuts_triggered(); - void on_mainTabBar_tabBarClicked(int index); - void on_mapViewTab_tabBarClicked(int index); - void on_actionZoom_In_triggered(); void on_actionZoom_Out_triggered(); void on_actionBetter_Cursors_triggered(); @@ -318,8 +286,11 @@ private slots: void on_actionEdit_Preferences_triggered(); void togglePreferenceSpecificUi(); -private: +public: Ui::MainWindow *ui; + Editor *editor = nullptr; + +private: QLabel *label_MapRulerStatus = nullptr; QPointer tilesetEditor = nullptr; QPointer regionMapEditor = nullptr; @@ -331,7 +302,6 @@ private: QStandardItemModel *mapListModel; QList *mapGroupItemsList; QMap mapListIndexes; - Editor *editor = nullptr; QIcon* mapIcon; QIcon* mapEditedIcon; QIcon* mapOpenedIcon; @@ -355,7 +325,6 @@ private: DraggablePixmapItem *selectedBG; DraggablePixmapItem *selectedHealspot; - QList registeredActions; QVector openScriptButtons; bool isProgrammaticEventTabChange; diff --git a/include/scripting.h b/include/scripting.h index 4558f0e0..98982e44 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -4,6 +4,7 @@ #include "mainwindow.h" #include "block.h" +#include "api_util.h" #include #include @@ -63,8 +64,8 @@ private: QJSEngine *engine; QStringList filepaths; QList modules; - QMap registeredActions; QMap imageCache; + ScriptUtility *scriptUtility; void loadModules(QStringList moduleFiles); void invokeCallback(CallbackType type, QJSValueList args); diff --git a/porymap.pro b/porymap.pro index c0ab808c..e1edf4e0 100644 --- a/porymap.pro +++ b/porymap.pro @@ -169,6 +169,7 @@ HEADERS += include/core/block.h \ include/ui/preferenceeditor.h \ include/ui/regionmappropertiesdialog.h \ include/ui/colorpicker.h \ + include/api_util.h \ include/config.h \ include/editor.h \ include/mainwindow.h \ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 16a51e9b..11ba6e3a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -540,6 +540,7 @@ bool MainWindow::openProject(QString dir) { if (success) { showWindowTitle(); this->statusBar()->showMessage(QString("Opened project %1").arg(nativeDir)); + Scripting::cb_ProjectOpened(dir); } else { this->statusBar()->showMessage(QString("Failed to open project %1").arg(nativeDir)); QMessageBox msgBox(this); @@ -550,14 +551,6 @@ bool MainWindow::openProject(QString dir) { msgBox.critical(nullptr, "Error Opening Project", errorMsg); } - - if (success) { - for (auto action : this->registeredActions) { - this->ui->menuTools->removeAction(action); - } - Scripting::cb_ProjectOpened(dir); - } - projectOpenFailure = !success; return success; } @@ -3238,7 +3231,3 @@ void MainWindow::closeEvent(QCloseEvent *event) { QMainWindow::closeEvent(event); } - -MapView *MainWindow::getMapView() { - return this->ui->graphicsView_Map; -} diff --git a/src/script_api/api_util.cpp b/src/script_api/api_util.cpp index 6f52434f..8bf25a17 100644 --- a/src/script_api/api_util.cpp +++ b/src/script_api/api_util.cpp @@ -3,16 +3,20 @@ #include "scripting.h" #include "config.h" -void MainWindow::registerAction(QString functionName, QString actionName, QString shortcut) { - if (!this->ui || !this->ui->menuTools) +ScriptUtility::ScriptUtility(MainWindow *mainWindow) { + this->window = mainWindow; +} + +void ScriptUtility::registerAction(QString functionName, QString actionName, QString shortcut) { + if (!window || !window->ui || !window->ui->menuTools) return; - Scripting::registerAction(functionName, actionName); - if (Scripting::numRegisteredActions() == 1) { - QAction *section = this->ui->menuTools->addSection("Custom Actions"); + this->actionMap.insert(actionName, functionName); + if (this->actionMap.size() == 1) { + QAction *section = window->ui->menuTools->addSection("Custom Actions"); this->registeredActions.append(section); } - QAction *action = this->ui->menuTools->addAction(actionName, [actionName](){ + QAction *action = window->ui->menuTools->addAction(actionName, [actionName](){ Scripting::invokeAction(actionName); }); if (!shortcut.isEmpty()) { @@ -21,37 +25,47 @@ void MainWindow::registerAction(QString functionName, QString actionName, QStrin this->registeredActions.append(action); } -void MainWindow::setTimeout(QJSValue callback, int milliseconds) { +void ScriptUtility::clearActions() { + for (auto action : this->registeredActions) { + window->ui->menuTools->removeAction(action); + } +} + +QString ScriptUtility::getActionFunctionName(QString actionName) { + return this->actionMap.value(actionName); +} + +void ScriptUtility::setTimeout(QJSValue callback, int milliseconds) { if (!callback.isCallable() || milliseconds < 0) return; QTimer *timer = new QTimer(0); connect(timer, &QTimer::timeout, [=](){ - this->invokeCallback(callback); + this->callTimeoutFunction(callback); }); connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater); timer->setSingleShot(true); timer->start(milliseconds); } -void MainWindow::invokeCallback(QJSValue callback) { +void ScriptUtility::callTimeoutFunction(QJSValue callback) { Scripting::tryErrorJS(callback.call()); } -void MainWindow::log(QString message) { +void ScriptUtility::log(QString message) { logInfo(message); } -void MainWindow::warn(QString message) { +void ScriptUtility::warn(QString message) { logWarn(message); } -void MainWindow::error(QString message) { +void ScriptUtility::error(QString message) { logError(message); } -void MainWindow::runMessageBox(QString text, QString informativeText, QString detailedText, QMessageBox::Icon icon) { - QMessageBox messageBox(this); +void ScriptUtility::runMessageBox(QString text, QString informativeText, QString detailedText, QMessageBox::Icon icon) { + QMessageBox messageBox(window); messageBox.setText(text); messageBox.setInformativeText(informativeText); messageBox.setDetailedText(detailedText); @@ -59,20 +73,20 @@ void MainWindow::runMessageBox(QString text, QString informativeText, QString de messageBox.exec(); } -void MainWindow::showMessage(QString text, QString informativeText, QString detailedText) { +void ScriptUtility::showMessage(QString text, QString informativeText, QString detailedText) { this->runMessageBox(text, informativeText, detailedText, QMessageBox::Information); } -void MainWindow::showWarning(QString text, QString informativeText, QString detailedText) { +void ScriptUtility::showWarning(QString text, QString informativeText, QString detailedText) { this->runMessageBox(text, informativeText, detailedText, QMessageBox::Warning); } -void MainWindow::showError(QString text, QString informativeText, QString detailedText) { +void ScriptUtility::showError(QString text, QString informativeText, QString detailedText) { this->runMessageBox(text, informativeText, detailedText, QMessageBox::Critical); } -bool MainWindow::showQuestion(QString text, QString informativeText, QString detailedText) { - QMessageBox messageBox(this); +bool ScriptUtility::showQuestion(QString text, QString informativeText, QString detailedText) { + QMessageBox messageBox(window); messageBox.setText(text); messageBox.setInformativeText(informativeText); messageBox.setDetailedText(detailedText); @@ -81,83 +95,87 @@ bool MainWindow::showQuestion(QString text, QString informativeText, QString det return messageBox.exec() == QMessageBox::Yes; } -QJSValue MainWindow::getInputText(QString title, QString label, QString defaultValue) { +QJSValue ScriptUtility::getInputText(QString title, QString label, QString defaultValue) { bool ok; - QString input = QInputDialog::getText(this, title, label, QLineEdit::Normal, defaultValue, &ok); + QString input = QInputDialog::getText(window, title, label, QLineEdit::Normal, defaultValue, &ok); return Scripting::dialogInput(input, ok); } -QJSValue MainWindow::getInputNumber(QString title, QString label, double defaultValue, double min, double max, int decimals, double step) { +QJSValue ScriptUtility::getInputNumber(QString title, QString label, double defaultValue, double min, double max, int decimals, double step) { bool ok; - double input = QInputDialog::getDouble(this, title, label, defaultValue, min, max, decimals, &ok, Qt::WindowFlags(), step); + double input = QInputDialog::getDouble(window, title, label, defaultValue, min, max, decimals, &ok, Qt::WindowFlags(), step); return Scripting::dialogInput(input, ok); } -QJSValue MainWindow::getInputItem(QString title, QString label, QStringList items, int defaultValue, bool editable) { +QJSValue ScriptUtility::getInputItem(QString title, QString label, QStringList items, int defaultValue, bool editable) { bool ok; - QString input = QInputDialog::getItem(this, title, label, items, defaultValue, editable, &ok); + QString input = QInputDialog::getItem(window, title, label, items, defaultValue, editable, &ok); return Scripting::dialogInput(input, ok); } -int MainWindow::getMainTab() { - if (!this->ui || !this->ui->mainTabBar) +int ScriptUtility::getMainTab() { + if (!window || !window->ui || !window->ui->mainTabBar) return -1; - return this->ui->mainTabBar->currentIndex(); + return window->ui->mainTabBar->currentIndex(); } -void MainWindow::setMainTab(int index) { - if (!this->ui || !this->ui->mainTabBar || index < 0 || index >= this->ui->mainTabBar->count()) +void ScriptUtility::setMainTab(int index) { + if (!window || !window->ui || !window->ui->mainTabBar || index < 0 || index >= window->ui->mainTabBar->count()) return; // Can't select Wild Encounters tab if it's disabled if (index == 4 && !projectConfig.getEncounterJsonActive()) return; - this->on_mainTabBar_tabBarClicked(index); + window->on_mainTabBar_tabBarClicked(index); } -int MainWindow::getMapViewTab() { - if (!this->ui || !this->ui->mapViewTab) +int ScriptUtility::getMapViewTab() { + if (!window || !window->ui || !window->ui->mapViewTab) return -1; - return this->ui->mapViewTab->currentIndex(); + return window->ui->mapViewTab->currentIndex(); } -void MainWindow::setMapViewTab(int index) { - if (this->getMainTab() != 0 || !this->ui->mapViewTab || index < 0 || index >= this->ui->mapViewTab->count()) +void ScriptUtility::setMapViewTab(int index) { + if (this->getMainTab() != 0 || !window->ui->mapViewTab || index < 0 || index >= window->ui->mapViewTab->count()) return; - this->on_mapViewTab_tabBarClicked(index); + window->on_mapViewTab_tabBarClicked(index); } -void MainWindow::setGridVisibility(bool visible) { - this->ui->checkBox_ToggleGrid->setChecked(visible); +void ScriptUtility::setGridVisibility(bool visible) { + window->ui->checkBox_ToggleGrid->setChecked(visible); } -bool MainWindow::getGridVisibility() { - return this->ui->checkBox_ToggleGrid->isChecked(); +bool ScriptUtility::getGridVisibility() { + return window->ui->checkBox_ToggleGrid->isChecked(); } -void MainWindow::setBorderVisibility(bool visible) { - this->editor->toggleBorderVisibility(visible, false); +void ScriptUtility::setBorderVisibility(bool visible) { + window->editor->toggleBorderVisibility(visible, false); } -bool MainWindow::getBorderVisibility() { - return this->ui->checkBox_ToggleBorder->isChecked(); +bool ScriptUtility::getBorderVisibility() { + return window->ui->checkBox_ToggleBorder->isChecked(); } -void MainWindow::setSmartPathsEnabled(bool visible) { - this->ui->checkBox_smartPaths->setChecked(visible); +void ScriptUtility::setSmartPathsEnabled(bool visible) { + window->ui->checkBox_smartPaths->setChecked(visible); } -bool MainWindow::getSmartPathsEnabled() { - return this->ui->checkBox_smartPaths->isChecked(); +bool ScriptUtility::getSmartPathsEnabled() { + return window->ui->checkBox_smartPaths->isChecked(); } -QList MainWindow::getMetatileLayerOrder() { - if (!this->editor || !this->editor->map) +QList ScriptUtility::getCustomScripts() { + return projectConfig.getCustomScripts(); +} + +QList ScriptUtility::getMetatileLayerOrder() { + if (!window || !window->editor || !window->editor->map) return QList(); - return this->editor->map->metatileLayerOrder; + return window->editor->map->metatileLayerOrder; } -void MainWindow::setMetatileLayerOrder(QList order) { - if (!this->editor || !this->editor->map) +void ScriptUtility::setMetatileLayerOrder(QList order) { + if (!window || !window->editor || !window->editor->map) return; const int numLayers = 3; @@ -176,36 +194,31 @@ void MainWindow::setMetatileLayerOrder(QList order) { } if (invalid) return; - this->editor->map->metatileLayerOrder = order; - this->refreshAfterPalettePreviewChange(); + window->editor->map->metatileLayerOrder = order; + window->refreshAfterPalettePreviewChange(); } -QList MainWindow::getMetatileLayerOpacity() { - if (!this->editor || !this->editor->map) +QList ScriptUtility::getMetatileLayerOpacity() { + if (!window || !window->editor || !window->editor->map) return QList(); - return this->editor->map->metatileLayerOpacity; + return window->editor->map->metatileLayerOpacity; } -void MainWindow::setMetatileLayerOpacity(QList order) { - if (!this->editor || !this->editor->map) +void ScriptUtility::setMetatileLayerOpacity(QList order) { + if (!window || !window->editor || !window->editor->map) return; - this->editor->map->metatileLayerOpacity = order; - this->refreshAfterPalettePreviewChange(); + window->editor->map->metatileLayerOpacity = order; + window->refreshAfterPalettePreviewChange(); } -bool MainWindow::isPrimaryTileset(QString tilesetName) { - if (!this->editor || !this->editor->project) +bool ScriptUtility::isPrimaryTileset(QString tilesetName) { + if (!window || !window->editor || !window->editor->project) return false; - return this->editor->project->tilesetLabels["primary"].contains(tilesetName); + return window->editor->project->tilesetLabels["primary"].contains(tilesetName); } -bool MainWindow::isSecondaryTileset(QString tilesetName) { - if (!this->editor || !this->editor->project) +bool ScriptUtility::isSecondaryTileset(QString tilesetName) { + if (!window || !window->editor || !window->editor->project) return false; - return this->editor->project->tilesetLabels["secondary"].contains(tilesetName); + return window->editor->project->tilesetLabels["secondary"].contains(tilesetName); } - -QList MainWindow::getCustomScripts() { - return projectConfig.getCustomScripts(); -} - diff --git a/src/script_api/scripting.cpp b/src/script_api/scripting.cpp index 5a3fd097..6541acb2 100644 --- a/src/script_api/scripting.cpp +++ b/src/script_api/scripting.cpp @@ -25,6 +25,7 @@ Scripting *instance = nullptr; void Scripting::init(MainWindow *mainWindow) { if (instance) { instance->engine->setInterrupted(true); + instance->scriptUtility->clearActions(); qDeleteAll(instance->imageCache); delete instance; } @@ -38,6 +39,7 @@ Scripting::Scripting(MainWindow *mainWindow) { this->filepaths.append(script); } this->loadModules(this->filepaths); + this->scriptUtility = new ScriptUtility(mainWindow); } void Scripting::loadModules(QStringList moduleFiles) { @@ -58,7 +60,8 @@ void Scripting::populateGlobalObject(MainWindow *mainWindow) { if (!instance || !instance->engine) return; instance->engine->globalObject().setProperty("map", instance->engine->newQObject(mainWindow)); - instance->engine->globalObject().setProperty("overlay", instance->engine->newQObject(mainWindow->getMapView())); + instance->engine->globalObject().setProperty("overlay", instance->engine->newQObject(mainWindow->ui->graphicsView_Map)); + instance->engine->globalObject().setProperty("utility", instance->engine->newQObject(instance->scriptUtility)); QJSValue constants = instance->engine->newObject(); @@ -91,6 +94,7 @@ void Scripting::populateGlobalObject(MainWindow *mainWindow) { // Prevent changes to the object properties of the global object instance->engine->evaluate("Object.freeze(map);"); instance->engine->evaluate("Object.freeze(overlay);"); + instance->engine->evaluate("Object.freeze(utility);"); instance->engine->evaluate("Object.freeze(constants.version);"); instance->engine->evaluate("Object.freeze(constants);"); } @@ -125,22 +129,12 @@ void Scripting::invokeCallback(CallbackType type, QJSValueList args) { } } -void Scripting::registerAction(QString functionName, QString actionName) { - if (!instance) return; - instance->registeredActions.insert(actionName, functionName); -} - -int Scripting::numRegisteredActions() { - if (!instance) return 0; - return instance->registeredActions.size(); -} - void Scripting::invokeAction(QString actionName) { - if (!instance) return; - if (!instance->registeredActions.contains(actionName)) return; + if (!instance || !instance->scriptUtility) return; + QString functionName = instance->scriptUtility->getActionFunctionName(actionName); + if (functionName.isEmpty()) return; bool foundFunction = false; - QString functionName = instance->registeredActions.value(actionName); for (QJSValue module : instance->modules) { QJSValue callbackFunction = module.property(functionName); if (callbackFunction.isUndefined() || !callbackFunction.isCallable()) diff --git a/src/ui/graphicsview.cpp b/src/ui/graphicsview.cpp index cc270849..1c86e004 100644 --- a/src/ui/graphicsview.cpp +++ b/src/ui/graphicsview.cpp @@ -42,9 +42,9 @@ void MapView::drawForeground(QPainter *painter, const QRectF&) { } void MapView::clearOverlayMap() { - foreach (Overlay * layer, this->overlayMap) { - layer->clearItems(); - delete layer; + foreach (Overlay * overlay, this->overlayMap) { + overlay->clearItems(); + delete overlay; } this->overlayMap.clear(); }