Refactored find_branch_parent
This commit is contained in:
parent
e2992c62ef
commit
ed1f4abfea
6 changed files with 46 additions and 42 deletions
|
|
@ -36,6 +36,7 @@
|
|||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include "lib/util.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include "parent-track.hpp"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace gui {
|
||||
namespace model {
|
||||
|
||||
|
|
@ -70,5 +72,24 @@ ParentTrack::remove_descendant_track(const boost::shared_ptr<Track> track)
|
|||
return false;
|
||||
}
|
||||
|
||||
boost::shared_ptr<ParentTrack>
|
||||
ParentTrack::find_descendant_track_parent(
|
||||
boost::shared_ptr<Track> child)
|
||||
{
|
||||
REQUIRE(child != NULL);
|
||||
BOOST_FOREACH(shared_ptr<Track> track, tracks)
|
||||
{
|
||||
if(track == child)
|
||||
return shared_from_this();
|
||||
|
||||
shared_ptr<ParentTrack> result =
|
||||
track->find_descendant_track_parent(child);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
return shared_ptr<ParentTrack>();
|
||||
}
|
||||
|
||||
} // namespace model
|
||||
} // namespace gui
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ namespace model {
|
|||
* ParentTrack is the abstract base class of all tracks that can parent
|
||||
* children.
|
||||
**/
|
||||
class ParentTrack : public Track
|
||||
class ParentTrack :
|
||||
public Track,
|
||||
public boost::enable_shared_from_this<ParentTrack>
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
|
|
@ -74,6 +76,9 @@ public:
|
|||
* @return Returns true if the track was successfully removed.
|
||||
**/
|
||||
bool remove_descendant_track(const boost::shared_ptr<Track> track);
|
||||
|
||||
boost::shared_ptr<ParentTrack>
|
||||
find_descendant_track_parent(boost::shared_ptr<Track> child);
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -73,29 +73,10 @@ Track::print_branch()
|
|||
return print_branch_recursive(0);
|
||||
}
|
||||
|
||||
shared_ptr<ParentTrack>
|
||||
Track::find_parent(shared_ptr<ParentTrack> root, shared_ptr<Track> child)
|
||||
boost::shared_ptr<ParentTrack>
|
||||
Track::find_descendant_track_parent(
|
||||
boost::shared_ptr<Track> /*child*/)
|
||||
{
|
||||
REQUIRE(root != NULL);
|
||||
REQUIRE(child != NULL);
|
||||
const list< shared_ptr<Track> > children = root->get_child_tracks();
|
||||
BOOST_FOREACH(shared_ptr<Track> track, children)
|
||||
{
|
||||
if(track == child)
|
||||
return root;
|
||||
|
||||
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<ParentTrack>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,16 @@ public:
|
|||
**/
|
||||
virtual bool remove_descendant_track(
|
||||
const boost::shared_ptr<Track> track);
|
||||
|
||||
/**
|
||||
* A utility function that attempts to find the parent of a track by
|
||||
* searching through the tree from this track downward.
|
||||
* @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.
|
||||
**/
|
||||
virtual boost::shared_ptr<ParentTrack>
|
||||
find_descendant_track_parent(boost::shared_ptr<Track> child);
|
||||
|
||||
/**
|
||||
* A debugging helper function that prints this track, and all it's
|
||||
|
|
@ -92,21 +102,7 @@ public:
|
|||
* @return Returns the human readable string.
|
||||
**/
|
||||
virtual std::string print_track() = 0;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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:
|
||||
/**
|
||||
* The internal implementation of print_branch.
|
||||
|
|
|
|||
|
|
@ -563,8 +563,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree(
|
|||
|
||||
// Detach the track from the old parent
|
||||
shared_ptr<model::ParentTrack> old_parent =
|
||||
model::Track::find_parent(
|
||||
timelineWidget.sequence, dragging_track);
|
||||
timelineWidget.sequence->find_descendant_track_parent(
|
||||
dragging_track);
|
||||
REQUIRE(old_parent); // The track must have a parent
|
||||
old_parent->get_child_track_list().remove(dragging_track);
|
||||
|
||||
|
|
@ -572,8 +572,8 @@ TimelineLayoutHelper::apply_drop_to_model_tree(
|
|||
{
|
||||
// Find the new parent track
|
||||
shared_ptr<model::ParentTrack> new_parent =
|
||||
model::Track::find_parent(
|
||||
timelineWidget.sequence, target_track);
|
||||
timelineWidget.sequence->find_descendant_track_parent(
|
||||
target_track);
|
||||
REQUIRE(new_parent); // The track must have a parent
|
||||
|
||||
// Find the destination point
|
||||
|
|
|
|||
Loading…
Reference in a new issue