Tidied and documented Track::find_parent
This commit is contained in:
parent
c88aec9c03
commit
53297cccd6
3 changed files with 30 additions and 14 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
* *****************************************************/
|
* *****************************************************/
|
||||||
|
|
||||||
#include "track.hpp"
|
#include "track.hpp"
|
||||||
|
#include "parent-track.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
@ -72,8 +73,8 @@ Track::print_branch()
|
||||||
return print_branch_recursive(0);
|
return print_branch_recursive(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<Track>
|
shared_ptr<ParentTrack>
|
||||||
Track::find_parent(shared_ptr<Track> root, shared_ptr<Track> child)
|
Track::find_parent(shared_ptr<ParentTrack> root, shared_ptr<Track> child)
|
||||||
{
|
{
|
||||||
REQUIRE(root != NULL);
|
REQUIRE(root != NULL);
|
||||||
REQUIRE(child != NULL);
|
REQUIRE(child != NULL);
|
||||||
|
|
@ -83,12 +84,19 @@ Track::find_parent(shared_ptr<Track> root, shared_ptr<Track> child)
|
||||||
if(track == child)
|
if(track == child)
|
||||||
return root;
|
return root;
|
||||||
|
|
||||||
shared_ptr<Track> result = find_parent(track, child);
|
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)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return shared_ptr<Track>();
|
return shared_ptr<ParentTrack>();
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@
|
||||||
namespace gui {
|
namespace gui {
|
||||||
namespace model {
|
namespace model {
|
||||||
|
|
||||||
|
class ParentTrack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The model representation of a track. This is the base class for all
|
* The model representation of a track. This is the base class for all
|
||||||
* types of track that are implemented.
|
* types of track that are implemented.
|
||||||
|
|
@ -89,10 +91,18 @@ public:
|
||||||
**/
|
**/
|
||||||
virtual std::string print_track() = 0;
|
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);
|
boost::shared_ptr<Track> child);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -563,9 +563,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree(
|
||||||
|
|
||||||
// Detach the track from the old parent
|
// Detach the track from the old parent
|
||||||
shared_ptr<model::ParentTrack> old_parent =
|
shared_ptr<model::ParentTrack> old_parent =
|
||||||
dynamic_pointer_cast<model::ParentTrack, model::Track>(
|
|
||||||
model::Track::find_parent(
|
model::Track::find_parent(
|
||||||
timelineWidget.sequence, dragging_track));
|
timelineWidget.sequence, dragging_track);
|
||||||
REQUIRE(old_parent); // The track must have a parent
|
REQUIRE(old_parent); // The track must have a parent
|
||||||
old_parent->get_child_track_list().remove(dragging_track);
|
old_parent->get_child_track_list().remove(dragging_track);
|
||||||
|
|
||||||
|
|
@ -573,9 +572,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree(
|
||||||
{
|
{
|
||||||
// Find the new parent track
|
// Find the new parent track
|
||||||
shared_ptr<model::ParentTrack> new_parent =
|
shared_ptr<model::ParentTrack> new_parent =
|
||||||
dynamic_pointer_cast<model::ParentTrack, model::Track>(
|
|
||||||
model::Track::find_parent(
|
model::Track::find_parent(
|
||||||
timelineWidget.sequence, target_track));
|
timelineWidget.sequence, target_track);
|
||||||
REQUIRE(new_parent); // The track must have a parent
|
REQUIRE(new_parent); // The track must have a parent
|
||||||
|
|
||||||
// Find the destination point
|
// Find the destination point
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue