From 82dcecf8f2ce90b8a5ac6d8007baf51113db16df Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 13 Oct 2022 18:24:32 -0400 Subject: [PATCH] Add addPath overload --- include/ui/mapview.h | 4 +++- src/scriptapi/apioverlay.cpp | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/ui/mapview.h b/include/ui/mapview.h index 62d5e461..d7034e6f 100644 --- a/include/ui/mapview.h +++ b/include/ui/mapview.h @@ -57,7 +57,9 @@ public: Q_INVOKABLE void rotate(int degrees); Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0); Q_INVOKABLE void addRect(int x, int y, int width, int height, QString borderColor = "#000000", QString fillColor = "transparent", int rounding = 0, int layer = 0); - Q_INVOKABLE void addPath(QList x, QList y, QString borderColor = "#000000", QString fillColor = "transparent", int layer = 0); + Q_INVOKABLE void addPath(QList xCoords, QList yCoords, QString borderColor = "#000000", QString fillColor = "transparent", int layer = 0); + // TODO: Not invokable, haven't successfully tested 2D js array --> QList>. + void addPath(QList> coords, QString borderColor = "#000000", QString fillColor = "transparent", int layer = 0); Q_INVOKABLE void addImage(int x, int y, QString filepath, int layer = 0, bool useCache = true); Q_INVOKABLE void createImage(int x, int y, QString filepath, int width = -1, int height = -1, int xOffset = 0, int yOffset = 0, diff --git a/src/scriptapi/apioverlay.cpp b/src/scriptapi/apioverlay.cpp index 61178c33..3cef69f9 100644 --- a/src/scriptapi/apioverlay.cpp +++ b/src/scriptapi/apioverlay.cpp @@ -217,11 +217,25 @@ void MapView::addRect(int x, int y, int width, int height, QString borderColor, this->scene()->update(); } -void MapView::addPath(QList x, QList y, QString borderColor, QString fillColor, int layer) { - if (this->getOverlay(layer)->addPath(x, y, borderColor, fillColor)) +void MapView::addPath(QList xCoords, QList yCoords, QString borderColor, QString fillColor, int layer) { + if (this->getOverlay(layer)->addPath(xCoords, yCoords, borderColor, fillColor)) this->scene()->update(); } +void MapView::addPath(QList> coords, QString borderColor, QString fillColor, int layer) { + QList xCoords; + QList yCoords; + for (int i = 0; i < coords.length(); i++) { + if (coords[i].length() < 2){ + logWarn(QString("Element %1 of overlay path does not have an x and y value.").arg(i)); + continue; + } + xCoords.append(coords[i][0]); + yCoords.append(coords[i][1]); + } + this->addPath(xCoords, yCoords, borderColor, fillColor, layer); +} + void MapView::addImage(int x, int y, QString filepath, int layer, bool useCache) { if (this->getOverlay(layer)->addImage(x, y, filepath, useCache)) this->scene()->update();