# HG changeset patch # User Sebastien Jodogne # Date 1791461807 -7200 # Node ID fd6db8542d106adb43a51675fd0b6dabbfce4794 # Parent 521fbb596148213a458101b6c2e0e5b69760b83b fix undo stack diff -r 521fbb596148 -r fd6db8542d10 OrthancStone/Sources/Scene2DViewport/UndoStack.cpp --- a/OrthancStone/Sources/Scene2DViewport/UndoStack.cpp Thu Oct 08 11:51:01 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/UndoStack.cpp Thu Oct 08 14:16:47 2026 +0200 @@ -31,7 +31,7 @@ UndoStack::UndoStack() : numAppliedCommands_(0) {} - void UndoStack::PushCommand(boost::shared_ptr command) + void UndoStack::PushCommand(const boost::shared_ptr& command) { commandStack_.erase( commandStack_.begin() + numAppliedCommands_, diff -r 521fbb596148 -r fd6db8542d10 OrthancStone/Sources/Scene2DViewport/UndoStack.h --- a/OrthancStone/Sources/Scene2DViewport/UndoStack.h Thu Oct 08 11:51:01 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/UndoStack.h Thu Oct 08 14:16:47 2026 +0200 @@ -44,7 +44,7 @@ In other words, when a new command is pushed, all the undone (and not redone) commands are removed. */ - void PushCommand(boost::shared_ptr command); + void PushCommand(const boost::shared_ptr& command); /** Undoes the command at the top of the undo stack, or throws if there is no diff -r 521fbb596148 -r fd6db8542d10 OrthancStone/Sources/Scene2DViewport/ViewportController.cpp --- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Thu Oct 08 11:51:01 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Thu Oct 08 14:16:47 2026 +0200 @@ -38,17 +38,11 @@ // The controller must be able to cope with this. } - ViewportController::~ViewportController() + void ViewportController::PushCommand(const boost::shared_ptr& command) { - } - - void ViewportController::PushCommand( - boost::shared_ptr command) - { - boost::shared_ptr undoStack = undoStackW_.lock(); - if (undoStack.get() != NULL) + if (undoStackW_) { - undoStack->PushCommand(command); + undoStackW_->PushCommand(command); } else { @@ -58,10 +52,9 @@ void ViewportController::Undo() { - boost::shared_ptr undoStack = undoStackW_.lock(); - if (undoStack.get() != NULL) + if (undoStackW_) { - undoStack->Undo(); + undoStackW_->Undo(); } else { @@ -71,10 +64,9 @@ void ViewportController::Redo() { - boost::shared_ptr undoStack = undoStackW_.lock(); - if (undoStack.get() != NULL) + if (undoStackW_) { - undoStack->Redo(); + undoStackW_->Redo(); } else { @@ -84,10 +76,9 @@ bool ViewportController::CanUndo() const { - boost::shared_ptr undoStack = undoStackW_.lock(); - if (undoStack.get() != NULL) + if (undoStackW_) { - return undoStack->CanUndo(); + return undoStackW_->CanUndo(); } else { @@ -97,10 +88,9 @@ bool ViewportController::CanRedo() const { - boost::shared_ptr undoStack = undoStackW_.lock(); - if (undoStack.get() != NULL) + if (undoStackW_) { - return undoStack->CanRedo(); + return undoStackW_->CanRedo(); } else { @@ -274,4 +264,17 @@ InvalidateViewport(); } } + + + void ViewportController::SetUndoStack(const boost::shared_ptr& undoStackW) + { + if (undoStackW) + { + undoStackW_ = undoStackW; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + } } diff -r 521fbb596148 -r fd6db8542d10 OrthancStone/Sources/Scene2DViewport/ViewportController.h --- a/OrthancStone/Sources/Scene2DViewport/ViewportController.h Thu Oct 08 11:51:01 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.h Thu Oct 08 14:16:47 2026 +0200 @@ -92,15 +92,12 @@ explicit ViewportController(const boost::shared_ptr& viewport); - ~ViewportController(); - /** This method returns the list of measure tools containing the supplied point (in scene coords). A tracker can then be requested from the chosen measure tool, if needed */ - std::vector > HitTestMeasureTools( - ScenePoint2D p); + std::vector > HitTestMeasureTools(ScenePoint2D p); /** This function will traverse the measuring tools and will clear their @@ -166,7 +163,7 @@ /** forwarded to the UndoStack */ - void PushCommand(boost::shared_ptr command); + void PushCommand(const boost::shared_ptr& command); /** forwarded to the UndoStack */ void Undo(); @@ -226,11 +223,8 @@ /** Sets the undo stack that is used by PushCommand, Undo... */ - void SetUndoStack(boost::weak_ptr undoStackW) - { - undoStackW_ = undoStackW; - } - + void SetUndoStack(const boost::shared_ptr& undoStackW); + bool HasActiveTracker() const { return activeTracker_.get() != NULL; @@ -243,8 +237,7 @@ std::unique_ptr scene_; boost::weak_ptr viewport_; - - boost::weak_ptr undoStackW_; // Global stack, possibly shared by all viewports + boost::shared_ptr undoStackW_; // Global stack, possibly shared by all viewports std::vector > measureTools_; boost::shared_ptr activeTracker_; // TODO - Couldn't this be a "std::unique_ptr"?