From 42ea5901dec867b31a3172cdea2a643d03256b7d Mon Sep 17 00:00:00 2001 From: Xavier ASUS Date: Fri, 23 Nov 2018 13:08:30 +0100 Subject: Some cosmetic changes and improved const-correctness. Created QList so dynamically-allocated objects are safely deleted on the destructor. --- Source/MapEditor/mainwindow.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'Source/MapEditor/mainwindow.cpp') diff --git a/Source/MapEditor/mainwindow.cpp b/Source/MapEditor/mainwindow.cpp index 32a699e..c0c7635 100644 --- a/Source/MapEditor/mainwindow.cpp +++ b/Source/MapEditor/mainwindow.cpp @@ -32,6 +32,11 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { + foreach (QGraphicsTextItem* it, textItems) + { + delete it; + } + delete ui; delete gscene; } @@ -321,26 +326,29 @@ void MainWindow::parseMapData(QDataStream& ds, const QPixmap& tileSet) } } - QGraphicsPixmapItem* it = gscene->addPixmap(QPixmap::fromImage(cropped)); - int x; - int y; + QGraphicsPixmapItem* const it = gscene->addPixmap(QPixmap::fromImage(cropped)); - x = (i * TILE_SIZE) - (i * (TILE_SIZE / 2)); - x -= (j * (TILE_SIZE / 2)); + if (it != nullptr) + { + const int x = ((i * TILE_SIZE) - (i * (TILE_SIZE / 2))) - (j * (TILE_SIZE / 2)); + const int y = (j * (TILE_SIZE / 4)) + (i * (TILE_SIZE / 4)); - y = (j * (TILE_SIZE / 4)); - y += i * (TILE_SIZE / 4); + it->setX(x); + it->setY(y); - it->setX(x); - it->setY(y); + if (ui->showNumbers_Checkbox->isChecked() ) + { + QGraphicsTextItem* const io = new QGraphicsTextItem(); - if (ui->showNumbers_Checkbox->isChecked() ) - { - QGraphicsTextItem* io = new QGraphicsTextItem(); - io->setPos(x + (TILE_SIZE / 4), y); - io->setPlainText(QString::number(i + (j * level_size))); + if (io != nullptr) + { + io->setPos(x + (TILE_SIZE / 4), y); + io->setPlainText(QString::number(i + (j * level_size))); - gscene->addItem(io); + gscene->addItem(io); + textItems.append(io); + } + } } } } -- cgit v1.2.3