Log error when addImage API function fails

This commit is contained in:
GriffinR 2021-11-21 23:14:15 -05:00 committed by huderlem
parent bcf5339c32
commit 9cf0575914
3 changed files with 12 additions and 5 deletions

View file

@ -79,7 +79,7 @@ public:
void clearItems(); void clearItems();
void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12); 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 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: private:
QList<OverlayItem*> items; QList<OverlayItem*> items;
}; };

View file

@ -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) { void MainWindow::addImage(int x, int y, QString filepath) {
if (!this->ui || !this->ui->graphicsView_Map) if (!this->ui || !this->ui->graphicsView_Map)
return; return;
this->ui->graphicsView_Map->overlay.addImage(x, y, filepath); if (this->ui->graphicsView_Map->overlay.addImage(x, y, filepath))
this->ui->graphicsView_Map->scene()->update(); this->ui->graphicsView_Map->scene()->update();
} }
void MainWindow::refreshAfterPaletteChange(Tileset *tileset) { void MainWindow::refreshAfterPaletteChange(Tileset *tileset) {

View file

@ -1,4 +1,5 @@
#include "overlay.h" #include "overlay.h"
#include "log.h"
void OverlayText::render(QPainter *painter) { void OverlayText::render(QPainter *painter) {
QFont font = painter->font(); 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)); this->items.append(new OverlayRect(x, y, width, height, QColor(color), filled));
} }
void Overlay::addImage(int x, int y, QString filepath) { bool Overlay::addImage(int x, int y, QString filepath) {
this->items.append(new OverlayImage(x, y, QImage(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;
} }