From 1ba0bd68483b900a702c7a38f41250b33770503d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 10 Dec 2009 08:03:10 +0000 Subject: [PATCH] Don't leave removed tracks in routes --- source/designer/toolbar.cpp | 3 ++- source/libmarklin/layout.cpp | 2 +- source/libmarklin/route.cpp | 14 +++++++++++--- source/libmarklin/route.h | 4 +++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/source/designer/toolbar.cpp b/source/designer/toolbar.cpp index 09c025a..12c8388 100644 --- a/source/designer/toolbar.cpp +++ b/source/designer/toolbar.cpp @@ -63,7 +63,8 @@ void Toolbar::route_selected(unsigned index, const string &) { if(index==drp_routes->get_n_items()-1) { - Route *route = new Route(format("Route %d", designer.get_layout()->get_routes().size()+1)); + Layout &layout = *designer.get_layout(); + Route *route = new Route(layout, format("Route %d", layout.get_routes().size()+1)); designer.get_layout()->add_route(*route); designer.edit_route(*route); diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index 234b923..9ec0d0a 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -176,7 +176,7 @@ void Layout::Loader::finish() void Layout::Loader::route(const string &n) { - RefPtr rte = new Route(n); + RefPtr rte = new Route(obj, n); load_sub(*rte); obj.add_route(*rte.release()); } diff --git a/source/libmarklin/route.cpp b/source/libmarklin/route.cpp index fa2286c..364509c 100644 --- a/source/libmarklin/route.cpp +++ b/source/libmarklin/route.cpp @@ -5,18 +5,21 @@ Copyright © 2007-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ +#include "layout.h" +#include "route.h" #include "track.h" #include "tracktype.h" -#include "route.h" using namespace std; using namespace Msp; namespace Marklin { -Route::Route(const string &n): +Route::Route(Layout &layout, const string &n): name(n) -{ } +{ + layout.signal_track_removed.connect(sigc::mem_fun(this, &Route::track_removed)); +} int Route::get_turnout(unsigned id) const { @@ -171,6 +174,11 @@ unsigned Route::check_validity(const Track &trk) const return result; } +void Route::track_removed(Track &t) +{ + tracks.erase(&t); +} + Route::Loader::Loader(Route &r): DataFile::BasicLoader(r) diff --git a/source/libmarklin/route.h b/source/libmarklin/route.h index 6e69bba..bcb76e1 100644 --- a/source/libmarklin/route.h +++ b/source/libmarklin/route.h @@ -15,6 +15,7 @@ Distributed under the GPL namespace Marklin { +class Layout; class Track; class Turnout; @@ -35,7 +36,7 @@ private: std::map turnouts; public: - Route(const std::string &); + Route(Layout &, const std::string &); const std::string &get_name() const { return name; } int get_turnout(unsigned) const; @@ -47,6 +48,7 @@ public: private: void update_turnouts(); unsigned check_validity(const Track &) const; + void track_removed(Track &); }; } // namespace Marklin -- 2.45.2