Mercurial > hg > orthanc-stone
changeset 2362:fd6db8542d10 refactoring
fix undo stack
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Thu, 08 Oct 2026 14:16:47 +0200 |
| parents | 521fbb596148 |
| children | c03e04878b15 |
| files | OrthancStone/Sources/Scene2DViewport/UndoStack.cpp OrthancStone/Sources/Scene2DViewport/UndoStack.h OrthancStone/Sources/Scene2DViewport/ViewportController.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.h |
| diffstat | 4 files changed, 31 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- 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<MeasureCommand> command) + void UndoStack::PushCommand(const boost::shared_ptr<MeasureCommand>& command) { commandStack_.erase( commandStack_.begin() + numAppliedCommands_,
--- 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<MeasureCommand> command); + void PushCommand(const boost::shared_ptr<MeasureCommand>& command); /** Undoes the command at the top of the undo stack, or throws if there is no
--- 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<MeasureCommand>& command) { - } - - void ViewportController::PushCommand( - boost::shared_ptr<MeasureCommand> command) - { - boost::shared_ptr<UndoStack> 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> 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> 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> 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> 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<UndoStack>& undoStackW) + { + if (undoStackW) + { + undoStackW_ = undoStackW; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + } }
--- 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<IViewport>& 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<boost::shared_ptr<MeasureTool> > HitTestMeasureTools( - ScenePoint2D p); + std::vector<boost::shared_ptr<MeasureTool> > 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<MeasureCommand> command); + void PushCommand(const boost::shared_ptr<MeasureCommand>& 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<UndoStack> undoStackW) - { - undoStackW_ = undoStackW; - } - + void SetUndoStack(const boost::shared_ptr<UndoStack>& undoStackW); + bool HasActiveTracker() const { return activeTracker_.get() != NULL; @@ -243,8 +237,7 @@ std::unique_ptr<Scene2D> scene_; boost::weak_ptr<IViewport> viewport_; - - boost::weak_ptr<UndoStack> undoStackW_; // Global stack, possibly shared by all viewports + boost::shared_ptr<UndoStack> undoStackW_; // Global stack, possibly shared by all viewports std::vector<boost::shared_ptr<MeasureTool> > measureTools_; boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; // TODO - Couldn't this be a "std::unique_ptr"?
