Use QPointer to detect object existence, less verbose debug messages

pull/593/head
unelsson 3 years ago
parent b84e41bd27
commit d62ddc002e

@ -1,5 +1,7 @@
#include "commands.hpp" #include "commands.hpp"
#include <QPointer>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/loadland.hpp> #include <components/esm/loadland.hpp>
@ -15,26 +17,38 @@ CSVRender::DrawTerrainSelectionCommand::DrawTerrainSelectionCommand(WorldspaceWi
void CSVRender::DrawTerrainSelectionCommand::redo() void CSVRender::DrawTerrainSelectionCommand::redo()
{ {
if (CSVRender::WorldspaceWidget* worldspaceWidget = dynamic_cast<CSVRender::WorldspaceWidget *> (mWorldspaceWidget)) if (mWorldspaceWidget)
{ {
if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast<CSVRender::TerrainShapeMode *> (worldspaceWidget->getEditMode()) ) if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast<CSVRender::TerrainShapeMode *> (mWorldspaceWidget->getEditMode()) )
{ {
terrainMode->getTerrainSelection()->update(); terrainMode->getTerrainSelection()->update();
return; 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() void CSVRender::DrawTerrainSelectionCommand::undo()
{ {
if (CSVRender::WorldspaceWidget* worldspaceWidget = dynamic_cast<CSVRender::WorldspaceWidget *> (mWorldspaceWidget)) if (mWorldspaceWidget)
{ {
if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast<CSVRender::TerrainShapeMode *> (worldspaceWidget->getEditMode()) ) if (CSVRender::TerrainShapeMode* terrainMode = dynamic_cast<CSVRender::TerrainShapeMode *> (mWorldspaceWidget->getEditMode()) )
{ {
terrainMode->getTerrainSelection()->update(); terrainMode->getTerrainSelection()->update();
return; 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!";
} }

@ -1,6 +1,8 @@
#ifndef CSV_RENDER_COMMANDS_HPP #ifndef CSV_RENDER_COMMANDS_HPP
#define CSV_RENDER_COMMANDS_HPP #define CSV_RENDER_COMMANDS_HPP
#include <QPointer>
#include <QUndoCommand> #include <QUndoCommand>
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
@ -23,10 +25,9 @@ namespace CSVRender
*/ */
class DrawTerrainSelectionCommand : public QUndoCommand class DrawTerrainSelectionCommand : public QUndoCommand
{ {
friend class WorldspaceWidget;
private: private:
WorldspaceWidget *mWorldspaceWidget; QPointer<WorldspaceWidget> mWorldspaceWidget;
public: public:
DrawTerrainSelectionCommand(WorldspaceWidget* worldspaceWidget, QUndoCommand* parent = nullptr); DrawTerrainSelectionCommand(WorldspaceWidget* worldspaceWidget, QUndoCommand* parent = nullptr);

Loading…
Cancel
Save