Tidied and documented Track::find_parent

This commit is contained in:
Joel Holdsworth 2009-01-24 12:02:09 +00:00
parent c88aec9c03
commit 53297cccd6
3 changed files with 30 additions and 14 deletions

View file

@ -21,6 +21,7 @@
* *****************************************************/
#include "track.hpp"
#include "parent-track.hpp"
#include <boost/foreach.hpp>
using namespace boost;
@ -72,8 +73,8 @@ Track::print_branch()
return print_branch_recursive(0);
}
shared_ptr<Track>
Track::find_parent(shared_ptr<Track> root, shared_ptr<Track> child)
shared_ptr<ParentTrack>
Track::find_parent(shared_ptr<ParentTrack> root, shared_ptr<Track> child)
{
REQUIRE(root != NULL);
REQUIRE(child != NULL);
@ -83,12 +84,19 @@ Track::find_parent(shared_ptr<Track> root, shared_ptr<Track> child)
if(track == child)
return root;
shared_ptr<Track> result = find_parent(track, child);
if(result)
return result;
shared_ptr<ParentTrack> parent_track =
dynamic_pointer_cast<model::ParentTrack, model::Track>(
track);
if(parent_track)
{
shared_ptr<ParentTrack> result = find_parent(
parent_track, child);
if(result)
return result;
}
}
return shared_ptr<Track>();
return shared_ptr<ParentTrack>();
}
string

View file

@ -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<Track>
find_parent(boost::shared_ptr<Track> 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<ParentTrack>
find_parent(boost::shared_ptr<ParentTrack> root,
boost::shared_ptr<Track> child);
protected:

View file

@ -563,9 +563,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree(
// Detach the track from the old parent
shared_ptr<model::ParentTrack> old_parent =
dynamic_pointer_cast<model::ParentTrack, model::Track>(
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<model::ParentTrack> new_parent =
dynamic_pointer_cast<model::ParentTrack, model::Track>(
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