nodes: allow stalling graph signals until an operation is over

This commit is contained in:
itsmattkc
2020-10-02 13:25:49 +10:00
parent b9359ce50d
commit 2fb7066155
14 changed files with 277 additions and 43 deletions
+58
View File
@@ -149,6 +149,64 @@ private:
};
class NodeGraphBeginOperationCommand : public UndoCommand {
public:
NodeGraphBeginOperationCommand(NodeGraph* graph, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
graph_(graph)
{
}
virtual Project* GetRelevantProject() const override
{
return static_cast<Sequence*>(graph_)->project();
}
protected:
virtual void redo_internal() override
{
graph_->BeginOperation();
}
virtual void undo_internal() override
{
graph_->EndOperation();
}
private:
NodeGraph* graph_;
};
class NodeGraphEndOperationCommand : public UndoCommand {
public:
NodeGraphEndOperationCommand(NodeGraph* graph, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
graph_(graph)
{
}
virtual Project* GetRelevantProject() const override
{
return static_cast<Sequence*>(graph_)->project();
}
protected:
virtual void redo_internal() override
{
graph_->EndOperation();
}
virtual void undo_internal() override
{
graph_->BeginOperation();
}
private:
NodeGraph* graph_;
};
OLIVE_NAMESPACE_EXIT
#endif // NODEVIEWUNDO_H
+46 -26
View File
@@ -918,40 +918,62 @@ void TimelineWidget::ViewDragDropped(TimelineViewMouseEvent *event)
void TimelineWidget::AddBlock(Block *block, TrackReference track)
{
// Set up clip with view parameters (clip item will automatically size its rect accordingly)
TimelineViewBlockItem* item = new TimelineViewBlockItem(block);
TimelineViewBlockItem* item = block_items_.value(block);
item->SetYCoords(GetTrackY(track), GetTrackHeight(track));
item->SetScale(GetScale());
item->SetTrack(track);
item->SetTimebase(timebase());
if (!item) {
// Add to list of clip items that can be iterated through
block_items_.insert(block, item);
// Add to list of clip items that can be iterated through
item = new TimelineViewBlockItem(block);
block_items_.insert(block, item);
// Add item to graphics scene
views_.at(track.type())->view()->scene()->addItem(item);
// Set scale parameters
item->SetScale(GetScale());
item->SetTimebase(timebase());
item->SetYCoords(GetTrackY(track), GetTrackHeight(track));
item->SetTrack(track);
connect(block, &Block::Refreshed, this, &TimelineWidget::BlockRefreshed);
connect(block, &Block::LinksChanged, this, &TimelineWidget::BlockUpdated);
connect(block, &Block::LabelChanged, this, &TimelineWidget::BlockUpdated);
connect(block, &Block::EnabledChanged, this, &TimelineWidget::BlockUpdated);
// Add item to graphics scene
views_.at(track.type())->view()->scene()->addItem(item);
connect(block, &Block::Refreshed, this, &TimelineWidget::BlockRefreshed);
connect(block, &Block::LinksChanged, this, &TimelineWidget::BlockUpdated);
connect(block, &Block::LabelChanged, this, &TimelineWidget::BlockUpdated);
connect(block, &Block::EnabledChanged, this, &TimelineWidget::BlockUpdated);
} else if (item->Track() != track) {
item->SetYCoords(GetTrackY(track), GetTrackHeight(track));
item->SetTrack(track);
}
}
void TimelineWidget::RemoveBlock(Block *block)
void TimelineWidget::RemoveBlock(const QList<Block *> &blocks)
{
disconnect(block, &Block::Refreshed, this, &TimelineWidget::BlockRefreshed);
disconnect(block, &Block::LinksChanged, this, &TimelineWidget::BlockUpdated);
disconnect(block, &Block::LabelChanged, this, &TimelineWidget::BlockUpdated);
disconnect(block, &Block::EnabledChanged, this, &TimelineWidget::BlockUpdated);
QList<TimelineViewBlockItem*> delete_items;
delete_items.reserve(blocks.size());
TimelineViewBlockItem* item = block_items_.take(block);
QList<Block*> deselect_blocks;
if (item->isSelected()) {
// Sending a list of one item all the time is not very efficient
emit BlocksDeselected({block});
foreach (Block* b, blocks) {
disconnect(b, &Block::Refreshed, this, &TimelineWidget::BlockRefreshed);
disconnect(b, &Block::LinksChanged, this, &TimelineWidget::BlockUpdated);
disconnect(b, &Block::LabelChanged, this, &TimelineWidget::BlockUpdated);
disconnect(b, &Block::EnabledChanged, this, &TimelineWidget::BlockUpdated);
TimelineViewBlockItem* item = block_items_.take(b);
delete_items.append(item);
if (item->isSelected()) {
deselect_blocks.append(b);
}
}
delete item;
if (!deselect_blocks.isEmpty()) {
emit BlocksDeselected(deselect_blocks);
}
qDeleteAll(delete_items);
}
void TimelineWidget::AddTrack(TrackOutput *track, Timeline::TrackType type)
@@ -969,9 +991,7 @@ void TimelineWidget::RemoveTrack(TrackOutput *track)
disconnect(track, &TrackOutput::IndexChanged, this, &TimelineWidget::TrackIndexChanged);
disconnect(track, &TrackOutput::PreviewChanged, this, &TimelineWidget::TrackPreviewUpdated);
foreach (Block* b, track->Blocks()) {
RemoveBlock(b);
}
RemoveBlock(track->Blocks());
}
void TimelineWidget::TrackIndexChanged()
+1 -1
View File
@@ -532,7 +532,7 @@ private slots:
void ViewDragDropped(TimelineViewMouseEvent* event);
void AddBlock(Block* block, TrackReference track);
void RemoveBlock(Block* block);
void RemoveBlock(const QList<Block*>& blocks);
void AddTrack(TrackOutput* track, Timeline::TrackType type);
void RemoveTrack(TrackOutput* track);
@@ -555,6 +555,8 @@ void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event)
QUndoCommand* command = new QUndoCommand();
new NodeGraphBeginOperationCommand(static_cast<NodeGraph*>(parent()->GetConnectedNode()->parent()), command);
foreach (const GhostBlockPair& p, blocks_trimming) {
TimelineViewGhostItem* ghost = p.ghost;
@@ -676,6 +678,8 @@ void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event)
}
}
new NodeGraphEndOperationCommand(static_cast<NodeGraph*>(parent()->GetConnectedNode()->parent()), command);
Core::instance()->undo_stack()->pushIfHasChildren(command);
}
+8 -8
View File
@@ -295,7 +295,7 @@ void TrackRippleRemoveAreaCommand::undo_internal()
track_->RippleRemoveBlock(trim_in_);
trim_out_->set_length_and_media_out(trim_out_old_length_);
delete TakeNodeFromParentGraph(trim_in_);
TakeNodeFromParentGraph(trim_in_, &memory_manager_);
} else {
@@ -390,7 +390,7 @@ void TrackPlaceBlockCommand::undo_internal()
if (gap_ != nullptr) {
track_->RippleRemoveBlock(gap_);
delete TakeNodeFromParentGraph(gap_);
TakeNodeFromParentGraph(gap_, &memory_manager_);
}
} else {
TrackRippleRemoveAreaCommand::undo_internal();
@@ -926,7 +926,7 @@ void BlockTrimCommand::undo_internal()
if (we_created_adjacent_) {
// If we created a gap, just remove it straight up
track_->RippleRemoveBlock(adjacent_);
delete TakeNodeFromParentGraph(adjacent_);
TakeNodeFromParentGraph(adjacent_, &memory_manager_);
adjacent_ = nullptr;
we_created_adjacent_ = false;
} else if (adjacent_) {
@@ -1066,7 +1066,7 @@ void TrackReplaceBlockWithGapCommand::undo_internal()
// We made this gap, simply swap our gap back
track_->ReplaceBlock(our_gap_, block_);
delete TakeNodeFromParentGraph(our_gap_);
TakeNodeFromParentGraph(our_gap_, &memory_manager_);
our_gap_ = nullptr;
} else if (existing_gap_) {
@@ -1157,7 +1157,7 @@ void TrackSlideCommand::slide_internal(bool undo)
if (we_created_in_adjacent_) {
// This is a gap we made, we can just delete it entirely
track_->RippleRemoveBlock(in_adjacent_);
delete TakeNodeFromParentGraph(in_adjacent_);
TakeNodeFromParentGraph(in_adjacent_, &memory_manager_);
we_created_in_adjacent_ = false;
in_adjacent_ = nullptr;
} else if (in_adjacent_->parent() == &memory_manager_) {
@@ -1172,7 +1172,7 @@ void TrackSlideCommand::slide_internal(bool undo)
if (we_created_out_adjacent_) {
// This is a gap we made, we can just delete it entirely
track_->RippleRemoveBlock(out_adjacent_);
delete TakeNodeFromParentGraph(out_adjacent_);
TakeNodeFromParentGraph(out_adjacent_, &memory_manager_);
we_created_out_adjacent_ = false;
out_adjacent_ = nullptr;
} else if (out_adjacent_) {
@@ -1490,7 +1490,7 @@ void TrackListRippleToolCommand::undo_internal()
GapBlock* gap = working_data_.at(i).created_gap;
info.track->RippleRemoveBlock(gap);
delete TakeNodeFromParentGraph(gap);
TakeNodeFromParentGraph(gap, &memory_manager_);
}
}
}
@@ -1593,7 +1593,7 @@ void TrackListInsertGaps::undo_internal()
// Remove added gaps
foreach (GapBlock* gap, gaps_added_) {
TrackOutput::TrackFromBlock(gap)->RippleRemoveBlock(gap);
delete TakeNodeFromParentGraph(gap);
TakeNodeFromParentGraph(gap, &memory_manager_);
}
gaps_added_.clear();
+2
View File
@@ -589,6 +589,8 @@ private:
BlockSplitPreservingLinksCommand* split_command_;
QObject memory_manager_;
};
class TransitionRemoveCommand : public UndoCommand {