timeline: auto-unlink blocks when they're deleted

This commit is contained in:
itsmattkc
2020-03-15 13:15:36 +11:00
parent 78baf7661f
commit b57b091ca4
5 changed files with 100 additions and 4 deletions
+17 -3
View File
@@ -204,11 +204,12 @@ void Block::LengthInputChanged()
void Block::Link(Block *a, Block *b)
{
if (a == b || a == nullptr || b == nullptr) {
if (a == b || !a || !b) {
return;
}
// Assume both clips are already linked since Link() and Unlink() should be the only entry points to this array
// Prevent duplicate link entries (assume that we only need to check one clip since this should be the only function
// that adds to the linked array)
if (a->linked_clips_.contains(b)) {
return;
}
@@ -217,7 +218,7 @@ void Block::Link(Block *a, Block *b)
b->linked_clips_.append(a);
}
void Block::Link(QList<Block *> blocks)
void Block::Link(const QList<Block*>& blocks)
{
foreach (Block* a, blocks) {
foreach (Block* b, blocks) {
@@ -228,10 +229,23 @@ void Block::Link(QList<Block *> blocks)
void Block::Unlink(Block *a, Block *b)
{
if (a == b || !a || !b) {
return;
}
a->linked_clips_.removeOne(b);
b->linked_clips_.removeOne(a);
}
void Block::Unlink(const QList<Block *> &blocks)
{
foreach (Block* a, blocks) {
foreach (Block* b, blocks) {
Unlink(a, b);
}
}
}
bool Block::AreLinked(Block *a, Block *b)
{
return a->linked_clips_.contains(b);
+2 -1
View File
@@ -77,8 +77,9 @@ public:
void set_block_name(const QString& name);
static void Link(Block* a, Block* b);
static void Link(QList<Block*> blocks);
static void Link(const QList<Block*>& blocks);
static void Unlink(Block* a, Block* b);
static void Unlink(const QList<Block*>& blocks);
static bool AreLinked(Block* a, Block* b);
const QVector<Block*>& linked_clips();
bool HasLinks();
@@ -380,6 +380,8 @@ void TimelineWidget::DeleteSelectedInternal(const QList<Block *> &blocks,
}
if (remove_from_graph) {
new BlockUnlinkAllCommand(b, command);
new NodeRemoveWithExclusiveDeps(static_cast<NodeGraph*>(b->parent()), b, command);
}
}
+49
View File
@@ -715,3 +715,52 @@ void WorkareaSetRangeCommand::undo_internal()
{
points_->workarea()->set_range(old_range_);
}
BlockLinkCommand::BlockLinkCommand(const QList<Block *> &blocks, bool link, QUndoCommand *parent) :
UndoCommand(parent),
blocks_(blocks),
link_(link)
{
}
void BlockLinkCommand::redo_internal()
{
if (link_) {
Block::Link(blocks_);
} else {
Block::Unlink(blocks_);
}
}
void BlockLinkCommand::undo_internal()
{
if (link_) {
Block::Unlink(blocks_);
} else {
Block::Link(blocks_);
}
}
BlockUnlinkAllCommand::BlockUnlinkAllCommand(Block *block, QUndoCommand *parent) :
UndoCommand(parent),
block_(block)
{
}
void BlockUnlinkAllCommand::redo_internal()
{
unlinked_ = block_->linked_clips();
foreach (Block* link, unlinked_) {
Block::Unlink(block_, link);
}
}
void BlockUnlinkAllCommand::undo_internal()
{
foreach (Block* link, unlinked_) {
Block::Link(block_, link);
}
unlinked_.clear();
}
+30
View File
@@ -331,4 +331,34 @@ private:
};
class BlockLinkCommand : public UndoCommand {
public:
BlockLinkCommand(const QList<Block*>& blocks, bool link, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
QList<Block*> blocks_;
bool link_;
};
class BlockUnlinkAllCommand : public UndoCommand {
public:
BlockUnlinkAllCommand(Block* block, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
Block* block_;
QVector<Block*> unlinked_;
};
#endif // TIMELINEUNDOABLE_H