3 This file is part of R²C²
4 Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
9 #include "libr2c2/block.h"
10 #include "selection.h"
16 Track *Selection::get_track() const
21 return *tracks.begin();
24 void Selection::clear()
27 signal_changed.emit();
30 void Selection::add_track(Track *t)
32 if(tracks.insert(t).second)
33 signal_changed.emit();
36 void Selection::remove_track(Track *t)
39 signal_changed.emit();
42 void Selection::toggle_track(Track *t)
47 signal_changed.emit();
50 void Selection::select_more()
52 set<Track *> new_tracks;
53 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
55 const vector<Track *> &links = (*i)->get_links();
56 for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
58 new_tracks.insert(*j);
62 for(set<Track *>::iterator i=new_tracks.begin(); i!=new_tracks.end(); ++i)
63 if(tracks.insert(*i).second)
67 signal_changed.emit();
70 void Selection::select_linked()
73 list<Track *> queue(tracks.begin(), tracks.end());
76 Track *track = queue.front();
77 queue.erase(queue.begin());
79 const vector<Track *> &links = track->get_links();
80 for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
81 if(*j && tracks.insert(*j).second)
87 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
89 const vector<Track *> &links = (*i)->get_links();
90 for(vector<Track *>::const_iterator j=links.begin(); j!=links.end(); ++j)
91 if(*j && tracks.insert(*j).second)
96 signal_changed.emit();
99 void Selection::select_blocks()
101 bool changed = false;
102 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
104 const set<Track *> &btracks = (*i)->get_block().get_tracks();
105 for(set<Track *>::iterator j=btracks.begin(); j!=btracks.end(); ++j)
106 if(!tracks.count(*j))
114 signal_changed.emit();