From 7f846d20c79f0c10daa0689bbcc83757c8ebaf3e Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 23 Jan 2011 00:45:06 +0100 Subject: [PATCH] Make route editing sane. Drag&drop, insert and remove now update the current waypoint as expected. --- src/Autopilot/route_mgr.cxx | 16 ++++++++++------ src/GUI/WaypointList.cxx | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 57f7d5d5c..562c0ec68 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -354,11 +354,6 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) SG_LOG(SG_AUTOPILOT, SG_WARN, "removeWayptAtIndex with invalid index:" << aIndex); return NULL; } - - if (_currentIndex > index) { - --_currentIndex; // shift current index down if necessary - } - WayptVec::iterator it = _route.begin(); it += index; @@ -366,6 +361,15 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) _route.erase(it); update_mirror(); + + if (_currentIndex == index) { + currentWaypointChanged(); // current waypoint was removed + } + else + if (_currentIndex > index) { + --_currentIndex; // shift current index down if necessary + } + _edited->fireValueChanged(); checkFinished(); @@ -682,7 +686,7 @@ void FGRouteMgr::insertWayptAtIndex(Waypt* aWpt, int aIndex) WayptVec::iterator it = _route.begin(); it += index; - if (_currentIndex > index) { + if (_currentIndex >= index) { ++_currentIndex; } diff --git a/src/GUI/WaypointList.cxx b/src/GUI/WaypointList.cxx index b014d1cd3..ded3d46ec 100644 --- a/src/GUI/WaypointList.cxx +++ b/src/GUI/WaypointList.cxx @@ -83,9 +83,15 @@ public: --destIndex; } + int currentWpIndex = currentWaypoint(); WayptRef w(_rm->removeWayptAtIndex(srcIndex)); SG_LOG(SG_GENERAL, SG_INFO, "wpt:" << w->ident()); _rm->insertWayptAtIndex(w, destIndex); + + if (srcIndex == currentWpIndex) { + // current waypoint was moved + _rm->jumpToIndex(destIndex); + } } virtual void setUpdateCallback(SGCallback* cb) -- 2.39.5