diff --git a/src/gui/model/track.cpp b/src/gui/model/track.cpp index c8d1c3356..aa099848f 100644 --- a/src/gui/model/track.cpp +++ b/src/gui/model/track.cpp @@ -21,6 +21,7 @@ * *****************************************************/ #include "track.hpp" +#include "parent-track.hpp" #include using namespace boost; @@ -72,8 +73,8 @@ Track::print_branch() return print_branch_recursive(0); } -shared_ptr -Track::find_parent(shared_ptr root, shared_ptr child) +shared_ptr +Track::find_parent(shared_ptr root, shared_ptr child) { REQUIRE(root != NULL); REQUIRE(child != NULL); @@ -83,12 +84,19 @@ Track::find_parent(shared_ptr root, shared_ptr child) if(track == child) return root; - shared_ptr result = find_parent(track, child); - if(result) - return result; + shared_ptr parent_track = + dynamic_pointer_cast( + track); + if(parent_track) + { + shared_ptr result = find_parent( + parent_track, child); + if(result) + return result; + } } - return shared_ptr(); + return shared_ptr(); } string diff --git a/src/gui/model/track.hpp b/src/gui/model/track.hpp index 039d61969..9e116e743 100644 --- a/src/gui/model/track.hpp +++ b/src/gui/model/track.hpp @@ -31,6 +31,8 @@ namespace gui { namespace model { + +class ParentTrack; /** * The model representation of a track. This is the base class for all @@ -89,10 +91,18 @@ public: **/ virtual std::string print_track() = 0; -protected: +public: - static boost::shared_ptr - find_parent(boost::shared_ptr root, + /** + * A utility function that attempts to find the parent of a track by + * searching through the tree from a root downward. + * @param root The root track to begin searching down from. + * @param child The child track to find the parent of. + * @return Returns the parent track if one was found, or an empty + * shared_ptr if none was found. + **/ + static boost::shared_ptr + find_parent(boost::shared_ptr root, boost::shared_ptr child); protected: diff --git a/src/gui/widgets/timeline/timeline-layout-helper.cpp b/src/gui/widgets/timeline/timeline-layout-helper.cpp index 105e6fcd1..f05b63155 100644 --- a/src/gui/widgets/timeline/timeline-layout-helper.cpp +++ b/src/gui/widgets/timeline/timeline-layout-helper.cpp @@ -563,9 +563,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree( // Detach the track from the old parent shared_ptr old_parent = - dynamic_pointer_cast( model::Track::find_parent( - timelineWidget.sequence, dragging_track)); + timelineWidget.sequence, dragging_track); REQUIRE(old_parent); // The track must have a parent old_parent->get_child_track_list().remove(dragging_track); @@ -573,9 +572,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree( { // Find the new parent track shared_ptr new_parent = - dynamic_pointer_cast( - model::Track::find_parent( - timelineWidget.sequence, target_track)); + model::Track::find_parent( + timelineWidget.sequence, target_track); REQUIRE(new_parent); // The track must have a parent // Find the destination point