diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index 24c5987f..73ec81db 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -118,7 +118,6 @@ struct ModuleWidget : widget::OpaqueWidget { PRIVATE math::Vec& dragOffset(); PRIVATE bool& dragEnabled(); - PRIVATE math::Vec& oldPos(); PRIVATE engine::Module* releaseModule(); }; diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 495c9bb6..4c9735f4 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -36,12 +36,6 @@ struct ModuleWidget::Internal { math::Vec dragRackPos; bool dragEnabled = true; - /** The position in the RackWidget when dragging began. - Used for history::ModuleMove. - Set by RackWidget::updateModuleOldPositions() when *any* module begins dragging, since force-dragging can move other modules around. - */ - math::Vec oldPos; - widget::Widget* panel = NULL; }; @@ -1044,10 +1038,6 @@ bool& ModuleWidget::dragEnabled() { return internal->dragEnabled; } -math::Vec& ModuleWidget::oldPos() { - return internal->oldPos; -} - engine::Module* ModuleWidget::releaseModule() { engine::Module* module = this->module; this->module = NULL; diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 281411f8..1668fa3d 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -36,6 +36,7 @@ struct RackWidget::Internal { math::Vec selectionStart; math::Vec selectionEnd; std::set selectedModules; + std::map moduleOldPositions; }; @@ -800,9 +801,9 @@ bool RackWidget::hasModules() { } void RackWidget::updateModuleOldPositions() { - // Set all modules' oldPos field from their current position. + internal->moduleOldPositions.clear(); for (ModuleWidget* mw : getModules()) { - mw->oldPos() = mw->box.pos; + internal->moduleOldPositions[mw] = mw->getPosition(); } } @@ -812,7 +813,10 @@ history::ComplexAction* RackWidget::getModuleDragAction() { for (ModuleWidget* mw : getModules()) { // Create ModuleMove action if the module was moved. - math::Vec oldPos = mw->oldPos(); + auto it = internal->moduleOldPositions.find(mw); + if (it == internal->moduleOldPositions.end()) + continue; + math::Vec oldPos = it->second; if (!oldPos.equals(mw->box.pos)) { history::ModuleMove* mmh = new history::ModuleMove; mmh->moduleId = mw->module->id;