From 9cf0575914a038ac8ee835a764ae2d84cedd92f0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 21 Nov 2021 23:14:15 -0500 Subject: [PATCH] Log error when addImage API function fails --- include/ui/overlay.h | 2 +- src/mainwindow_scriptapi.cpp | 4 ++-- src/ui/overlay.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/ui/overlay.h b/include/ui/overlay.h index 87be19bd..b6aa3ef1 100644 --- a/include/ui/overlay.h +++ b/include/ui/overlay.h @@ -79,7 +79,7 @@ public: void clearItems(); void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12); void addRect(int x, int y, int width, int height, QString color = "#000000", bool filled = false); - void addImage(int x, int y, QString filepath); + bool addImage(int x, int y, QString filepath); private: QList items; }; diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 20543c64..2ed0be62 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -241,8 +241,8 @@ void MainWindow::addFilledRect(int x, int y, int width, int height, QString colo void MainWindow::addImage(int x, int y, QString filepath) { if (!this->ui || !this->ui->graphicsView_Map) return; - this->ui->graphicsView_Map->overlay.addImage(x, y, filepath); - this->ui->graphicsView_Map->scene()->update(); + if (this->ui->graphicsView_Map->overlay.addImage(x, y, filepath)) + this->ui->graphicsView_Map->scene()->update(); } void MainWindow::refreshAfterPaletteChange(Tileset *tileset) { diff --git a/src/ui/overlay.cpp b/src/ui/overlay.cpp index 004a1fed..c195d714 100644 --- a/src/ui/overlay.cpp +++ b/src/ui/overlay.cpp @@ -1,4 +1,5 @@ #include "overlay.h" +#include "log.h" void OverlayText::render(QPainter *painter) { QFont font = painter->font(); @@ -40,6 +41,12 @@ void Overlay::addRect(int x, int y, int width, int height, QString color, bool f this->items.append(new OverlayRect(x, y, width, height, QColor(color), filled)); } -void Overlay::addImage(int x, int y, QString filepath) { - this->items.append(new OverlayImage(x, y, QImage(filepath))); +bool Overlay::addImage(int x, int y, QString filepath) { + QImage image = QImage(filepath); + if (image.isNull()) { + logError(QString("Failed to load image '%1'").arg(filepath)); + return false; + } + this->items.append(new OverlayImage(x, y, image)); + return true; }