nodes/timeline: correctly detect when tracks are removed from the graph

Fixes several segfaults that could result from this occurring.
This commit is contained in:
itsmattkc
2020-04-27 01:01:12 +10:00
parent 981860b60b
commit f61321d68b
11 changed files with 92 additions and 63 deletions
+20 -5
View File
@@ -241,7 +241,7 @@ void TimelineWidget::ConnectNodeInternal(ViewerOutput *n)
view->ConnectTrackList(track_list);
// Defer to the track to make all the block UI items necessary
foreach (TrackOutput* track, n->track_list(track_type)->Tracks()) {
foreach (TrackOutput* track, n->track_list(track_type)->GetTracks()) {
AddTrack(track, track_type);
}
}
@@ -881,7 +881,7 @@ void TimelineWidget::InsertGapsAt(const rational &earliest_point, const rational
TrackOutput *TimelineWidget::GetTrackFromReference(const TrackReference &ref)
{
return GetConnectedNode()->track_list(ref.type())->TrackAt(ref.index());
return GetConnectedNode()->track_list(ref.type())->GetTrackAt(ref.index());
}
int TimelineWidget::GetTrackY(const TrackReference &ref)
@@ -1017,9 +1017,7 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
void TimelineWidget::RemoveBlock(Block *block)
{
delete block_items_[block];
block_items_.remove(block);
delete block_items_.take(block);
}
void TimelineWidget::AddTrack(TrackOutput *track, Timeline::TrackType type)
@@ -1027,15 +1025,32 @@ void TimelineWidget::AddTrack(TrackOutput *track, Timeline::TrackType type)
foreach (Block* b, track->Blocks()) {
AddBlock(b, TrackReference(type, track->Index()));
}
connect(track, &TrackOutput::IndexChanged, this, &TimelineWidget::TrackIndexChanged);
}
void TimelineWidget::RemoveTrack(TrackOutput *track)
{
disconnect(track, &TrackOutput::IndexChanged, this, &TimelineWidget::TrackIndexChanged);
foreach (Block* b, track->Blocks()) {
RemoveBlock(b);
}
}
void TimelineWidget::TrackIndexChanged()
{
TrackOutput* track = static_cast<TrackOutput*>(sender());
TrackReference ref(track->track_type(), track->Index());
foreach (Block* b, track->Blocks()) {
TimelineViewBlockItem* item = block_items_.value(b);
item->SetYCoords(GetTrackY(ref), GetTrackHeight(ref));
item->SetTrack(ref);
}
}
void TimelineWidget::ViewSelectionChanged()
{
if (rubberband_.isVisible()) {
@@ -486,6 +486,7 @@ private slots:
void AddTrack(TrackOutput* track, Timeline::TrackType type);
void RemoveTrack(TrackOutput* track);
void TrackIndexChanged();
void ViewSelectionChanged();
@@ -81,7 +81,7 @@ void TrackView::ConnectTrackList(TrackList *list)
list_ = list;
if (list_ != nullptr) {
foreach (TrackOutput* track, list_->Tracks()) {
foreach (TrackOutput* track, list_->GetTracks()) {
TrackViewItem* item = new TrackViewItem(track);
items_.append(item);
splitter_->Insert(track->Index(), track->GetTrackHeight(), item);
@@ -120,7 +120,7 @@ void TrackView::ScrollbarRangeChanged(int, int max)
void TrackView::TrackHeightChanged(int index, int height)
{
list_->TrackAt(index)->SetTrackHeight(height);
list_->GetTrackAt(index)->SetTrackHeight(height);
}
void TrackView::InsertTrack(TrackOutput *track)
@@ -141,7 +141,7 @@ void TrackViewSplitter::Remove(int index)
QList<int> sz = sizes();
if (alignment_ == Qt::AlignBottom) {
index = count() - index;
index = count() - 1 - index;
}
sz.removeAt(index);
+4 -4
View File
@@ -347,13 +347,13 @@ void TrackPlaceBlockCommand::redo_internal()
added_track_count_ = 0;
// Get track (or make it if necessary)
while (track_index_ >= timeline_->Tracks().size()) {
while (track_index_ >= timeline_->GetTracks().size()) {
timeline_->AddTrack();
added_track_count_++;
}
track_ = timeline_->TrackAt(track_index_);
track_ = timeline_->GetTrackAt(track_index_);
append_ = (in_ >= track_->track_length());
@@ -610,7 +610,7 @@ void TrackCleanGapsCommand::redo_internal()
GapBlock* on_gap = nullptr;
QList<GapBlock*> consecutive_gaps;
TrackOutput* track = track_list_->TrackAt(track_index_);
TrackOutput* track = track_list_->GetTrackAt(track_index_);
foreach (Block* b, track->Blocks()) {
if (b) {
@@ -657,7 +657,7 @@ void TrackCleanGapsCommand::redo_internal()
void TrackCleanGapsCommand::undo_internal()
{
TrackOutput* track = track_list_->TrackAt(track_index_);
TrackOutput* track = track_list_->GetTrackAt(track_index_);
// Restored removed end gaps
foreach (GapBlock* gap, removed_end_gaps_) {
@@ -189,11 +189,7 @@ void TimelineView::drawBackground(QPainter *painter, const QRectF &rect)
int line_y = 0;
foreach (TrackOutput* track, connected_track_list_->Tracks()) {
if (!track) {
continue;
}
foreach (TrackOutput* track, connected_track_list_->GetTracks()) {
line_y += track->GetTrackHeight();
// One px gap between tracks
@@ -294,9 +290,9 @@ int TimelineView::GetHeightOfAllTracks() const
{
if (connected_track_list_) {
if (alignment() & Qt::AlignTop) {
return GetTrackY(connected_track_list_->TrackCount());
return GetTrackY(connected_track_list_->GetTrackCount());
} else {
return GetTrackY(connected_track_list_->TrackCount() - 1);
return GetTrackY(connected_track_list_->GetTrackCount() - 1);
}
} else {
return 0;
@@ -305,6 +301,10 @@ int TimelineView::GetHeightOfAllTracks() const
int TimelineView::GetTrackY(int track_index) const
{
if (!connected_track_list_ || !connected_track_list_->GetTrackCount()) {
return 0;
}
int y = 0;
if (alignment() & Qt::AlignBottom) {
@@ -327,11 +327,11 @@ int TimelineView::GetTrackY(int track_index) const
int TimelineView::GetTrackHeight(int track_index) const
{
if (!connected_track_list_ || track_index >= connected_track_list_->TrackCount()) {
if (!connected_track_list_ || track_index >= connected_track_list_->GetTrackCount()) {
return TrackOutput::GetDefaultTrackHeight();
}
return connected_track_list_->TrackAt(track_index)->GetTrackHeight();
return connected_track_list_->GetTrackAt(track_index)->GetTrackHeight();
}
QPoint TimelineView::GetScrollCoordinates() const