From d62ddc002efd3304a134a9cfefebb4d125da5431 Mon Sep 17 00:00:00 2001 From: unelsson Date: Sun, 22 Aug 2021 19:04:16 +0300 Subject: [PATCH] Use QPointer to detect object existence, less verbose debug messages --- apps/opencs/view/render/commands.cpp | 42 ++++++++++++++++++---------- apps/opencs/view/render/commands.hpp | 5 ++-- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/apps/opencs/view/render/commands.cpp b/apps/opencs/view/render/commands.cpp index 7afbd024a..b9b7b12f7 100644 --- a/apps/opencs/view/render/commands.cpp +++ b/apps/opencs/view/render/commands.cpp @@ -1,5 +1,7 @@ #include "commands.hpp" +#include + #include #include @@ -15,26 +17,38 @@ CSVRender::DrawTerrainSelectionCommand::DrawTerrainSelectionCommand(WorldspaceWi void CSVRender::DrawTerrainSelectionCommand::redo() { - if (CSVRender::WorldspaceWidget* worldspaceWidget = dynamic_cast (mWorldspaceWidget)) + if (mWorldspaceWidget) { - if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast (worldspaceWidget->getEditMode()) ) - { - terrainMode->getTerrainSelection()->update(); - return; - } + if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast (mWorldspaceWidget->getEditMode()) ) + { + terrainMode->getTerrainSelection()->update(); + return; + } + else + { + Log(Debug::Verbose) << "Can't update terrain selection in current EditMode"; + return; + } } - Log(Debug::Warning) << "Error in redoing terrain selection"; + else + Log(Debug::Verbose) << "Can't update terrain selection, no WorldspaceWidget found!"; } void CSVRender::DrawTerrainSelectionCommand::undo() { - if (CSVRender::WorldspaceWidget* worldspaceWidget = dynamic_cast (mWorldspaceWidget)) + if (mWorldspaceWidget) { - if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast (worldspaceWidget->getEditMode()) ) - { - terrainMode->getTerrainSelection()->update(); - return; - } + if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast (mWorldspaceWidget->getEditMode()) ) + { + terrainMode->getTerrainSelection()->update(); + return; + } + else + { + Log(Debug::Verbose) << "Can't undo terrain selection in current EditMode"; + return; + } } - Log(Debug::Warning) << "Error in undoing terrain selection"; + else + Log(Debug::Verbose) << "Can't undo terrain selection, no WorldspaceWidget found!"; } diff --git a/apps/opencs/view/render/commands.hpp b/apps/opencs/view/render/commands.hpp index 6845785ec..9698010a9 100644 --- a/apps/opencs/view/render/commands.hpp +++ b/apps/opencs/view/render/commands.hpp @@ -1,6 +1,8 @@ #ifndef CSV_RENDER_COMMANDS_HPP #define CSV_RENDER_COMMANDS_HPP +#include + #include #include "worldspacewidget.hpp" @@ -23,10 +25,9 @@ namespace CSVRender */ class DrawTerrainSelectionCommand : public QUndoCommand { - friend class WorldspaceWidget; private: - WorldspaceWidget *mWorldspaceWidget; + QPointer mWorldspaceWidget; public: DrawTerrainSelectionCommand(WorldspaceWidget* worldspaceWidget, QUndoCommand* parent = nullptr);