From 269fa6d9057473780166241fb137fd9fa90c2632 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 21 Apr 2021 17:24:43 +1000 Subject: [PATCH] remove block enum Replaced with dynamic casts. --- app/node/block/block.h | 8 ------- app/node/block/clip/clip.cpp | 5 ----- app/node/block/clip/clip.h | 2 -- app/node/block/gap/gap.cpp | 5 ----- app/node/block/gap/gap.h | 2 -- app/node/block/transition/transition.cpp | 9 ++------ app/node/block/transition/transition.h | 2 -- app/task/project/saveotio/saveotio.cpp | 18 +++++---------- app/widget/timelinewidget/timelineundo.h | 12 +++++----- app/widget/timelinewidget/timelinewidget.cpp | 14 ++++++------ app/widget/timelinewidget/tool/pointer.cpp | 22 ++++++++----------- app/widget/timelinewidget/tool/razor.cpp | 2 +- app/widget/timelinewidget/tool/ripple.cpp | 4 ++-- app/widget/timelinewidget/tool/transition.cpp | 8 +++---- .../timelinewidget/view/timelineview.cpp | 2 +- .../view/timelineviewghostitem.h | 11 ++++------ 16 files changed, 40 insertions(+), 86 deletions(-) diff --git a/app/node/block/block.h b/app/node/block/block.h index e4fb258cc..5901e6768 100644 --- a/app/node/block/block.h +++ b/app/node/block/block.h @@ -39,14 +39,6 @@ public: NODE_DEFAULT_DESTRUCTOR(Block) - enum Type { - kClip, - kGap, - kTransition - }; - - virtual Type type() const = 0; - virtual QVector Category() const override; const rational& in() const diff --git a/app/node/block/clip/clip.cpp b/app/node/block/clip/clip.cpp index aabc5524e..05dad2efd 100644 --- a/app/node/block/clip/clip.cpp +++ b/app/node/block/clip/clip.cpp @@ -34,11 +34,6 @@ Node *ClipBlock::copy() const return new ClipBlock(); } -Block::Type ClipBlock::type() const -{ - return kClip; -} - QString ClipBlock::Name() const { return tr("Clip"); diff --git a/app/node/block/clip/clip.h b/app/node/block/clip/clip.h index ed3e9619e..051f22b37 100644 --- a/app/node/block/clip/clip.h +++ b/app/node/block/clip/clip.h @@ -38,8 +38,6 @@ public: virtual Node* copy() const override; - virtual Type type() const override; - virtual QString Name() const override; virtual QString id() const override; virtual QString Description() const override; diff --git a/app/node/block/gap/gap.cpp b/app/node/block/gap/gap.cpp index 80afbd0ac..d5ea6915c 100644 --- a/app/node/block/gap/gap.cpp +++ b/app/node/block/gap/gap.cpp @@ -31,11 +31,6 @@ Node *GapBlock::copy() const return new GapBlock(); } -Block::Type GapBlock::type() const -{ - return kGap; -} - QString GapBlock::Name() const { return tr("Gap"); diff --git a/app/node/block/gap/gap.h b/app/node/block/gap/gap.h index 42d28f9c5..c048e229e 100644 --- a/app/node/block/gap/gap.h +++ b/app/node/block/gap/gap.h @@ -38,8 +38,6 @@ public: virtual Node * copy() const override; - virtual Type type() const override; - virtual QString Name() const override; virtual QString id() const override; virtual QString Description() const override; diff --git a/app/node/block/transition/transition.cpp b/app/node/block/transition/transition.cpp index 463e7375d..f503d2cb8 100644 --- a/app/node/block/transition/transition.cpp +++ b/app/node/block/transition/transition.cpp @@ -39,11 +39,6 @@ TransitionBlock::TransitionBlock() : AddInput(kCurveInput, NodeValue::kCombo, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable)); } -Block::Type TransitionBlock::type() const -{ - return kTransition; -} - void TransitionBlock::Retranslate() { Block::Retranslate(); @@ -255,7 +250,7 @@ void TransitionBlock::InputConnectedEvent(const QString &input, int element, con // If node is not a block, this will just be null if ((connected_out_block_ = dynamic_cast(output.node()))) { - Q_ASSERT(connected_out_block_->type() != Block::kTransition + Q_ASSERT(!dynamic_cast(connected_out_block_) && !connected_out_block_->out_transition() && connected_out_block_ == this->previous()); @@ -265,7 +260,7 @@ void TransitionBlock::InputConnectedEvent(const QString &input, int element, con // If node is not a block, this will just be null if ((connected_in_block_ = dynamic_cast(output.node()))) { - Q_ASSERT(connected_in_block_->type() != Block::kTransition + Q_ASSERT(!dynamic_cast(connected_in_block_) && !connected_in_block_->in_transition() && connected_in_block_ == this->next()); diff --git a/app/node/block/transition/transition.h b/app/node/block/transition/transition.h index 3d2a32893..6ca621960 100644 --- a/app/node/block/transition/transition.h +++ b/app/node/block/transition/transition.h @@ -33,8 +33,6 @@ public: NODE_DEFAULT_DESTRUCTOR(TransitionBlock) - virtual Type type() const override; - virtual void Retranslate() override; rational in_offset() const; diff --git a/app/task/project/saveotio/saveotio.cpp b/app/task/project/saveotio/saveotio.cpp index a083fb357..92af6753b 100644 --- a/app/task/project/saveotio/saveotio.cpp +++ b/app/task/project/saveotio/saveotio.cpp @@ -29,6 +29,8 @@ #include #include +#include "node/block/clip/clip.h" +#include "node/block/gap/gap.h" #include "node/block/transition/transition.h" #include "node/project/footage/footage.h" @@ -130,9 +132,7 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track) foreach (Block* block, track->Blocks()) { OTIO::Composable* otio_block = nullptr; - switch (block->type()) { - case Block::kClip: - { + if (dynamic_cast(block)) { auto otio_clip = new OTIO::Clip(block->GetLabel().toStdString()); otio_clip->set_source_range(OTIO::TimeRange(block->in().toRationalTime(), @@ -145,18 +145,12 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track) } otio_block = otio_clip; - break; - } - case Block::kGap: - { + } else if (dynamic_cast(block)) { otio_block = new OTIO::Gap(OTIO::TimeRange(block->in().toRationalTime(), block->length().toRationalTime()), block->GetLabel().toStdString() ); - break; - } - case Block::kTransition: - { + } else if (dynamic_cast(block)) { auto otio_transition = new OTIO::Transition(block->GetLabel().toStdString()); TransitionBlock* our_transition = static_cast(block); @@ -165,8 +159,6 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track) otio_transition->set_out_offset(our_transition->out_offset().toRationalTime()); otio_block = new OTIO::Transition(); - break; - } } if (!otio_block) { diff --git a/app/widget/timelinewidget/timelineundo.h b/app/widget/timelinewidget/timelineundo.h index 78f1e90ef..9ba308874 100644 --- a/app/widget/timelinewidget/timelineundo.h +++ b/app/widget/timelinewidget/timelineundo.h @@ -1666,8 +1666,8 @@ public: Block* previous = block_->previous(); Block* next = block_->next(); - bool previous_is_a_gap = (previous && previous->type() == Block::kGap); - bool next_is_a_gap = (next && next->type() == Block::kGap); + bool previous_is_a_gap = dynamic_cast(previous); + bool next_is_a_gap = dynamic_cast(next); if (previous_is_a_gap && next_is_a_gap) { // Clip is preceded and followed by a gap, so we'll merge the two @@ -1717,7 +1717,7 @@ public: // Determine if it's proceeded by a gap, and remove that gap if so Block* preceding = block_->previous(); - if (preceding && preceding->type() == Block::kGap) { + if (dynamic_cast(preceding)) { track_->RippleRemoveBlock(preceding); preceding->setParent(&memory_manager_); @@ -1836,7 +1836,7 @@ public: Block* block_at_time = track->NearestBlockBeforeOrAt(range.in()); if (block_at_time) { - if (block_at_time->type() == Block::kGap) { + if (dynamic_cast(block_at_time)) { max_ripple_length = qMin(block_at_time->length(), max_ripple_length); } else { max_ripple_length = 0; @@ -2287,11 +2287,11 @@ private: foreach (Track* track, working_tracks_) { foreach (Block* b, track->Blocks()) { - if (b->type() == Block::kGap && b->in() <= point_ && b->out() >= point_) { + if (dynamic_cast(b) && b->in() <= point_ && b->out() >= point_) { // Found a gap at the location gaps_to_extend_.append(b); break; - } else if (b->type() == Block::kClip && b->out() >= point_) { + } else if (dynamic_cast(b) && b->out() >= point_) { if (b->out() > point_) { blocks_to_split.append(b); } diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index 6b96b9b12..3529edb44 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -396,7 +396,7 @@ void TimelineWidget::SplitAtPlayhead() foreach (Track* track, sequence()->GetTracks()) { Block* b = track->BlockContainingTime(playhead_time); - if (b && b->type() == Block::kClip) { + if (dynamic_cast(b)) { bool selected = false; // See if this block is selected @@ -434,7 +434,7 @@ void TimelineWidget::ReplaceBlocksWithGaps(const QVector &blocks, MultiUndoCommand *command) { foreach (Block* b, blocks) { - if (b->type() == Block::kGap) { + if (dynamic_cast(b)) { // No point in replacing a gap with a gap, and TrackReplaceBlockWithGapCommand will clear // up any extraneous gaps continue; @@ -470,9 +470,9 @@ void TimelineWidget::DeleteSelected(bool ripple) QVector transitions_to_delete; foreach (Block* b, blocks_to_delete) { - if (b->type() == Block::kClip) { + if (dynamic_cast(b)) { clips_to_delete.append(b); - } else if (b->type() == Block::kTransition) { + } else if (dynamic_cast(b)) { transitions_to_delete.append(static_cast(b)); } } @@ -548,7 +548,7 @@ void TimelineWidget::ToggleLinksOnSelected() foreach (Block* item, GetSelectedBlocks()) { // Only clips can be linked - if (item->type() != Block::kClip) { + if (!dynamic_cast(item)) { continue; } @@ -1279,7 +1279,7 @@ void TimelineWidget::EditTo(Timeline::MovementMode mode) foreach (const Timeline::EditToInfo& info, tracks) { if (info.nearest_block - && info.nearest_block->type() != Block::kGap + && !dynamic_cast(info.nearest_block) && info.nearest_time != playhead_time) { rational new_len; @@ -1410,7 +1410,7 @@ void TimelineWidget::MoveRubberBandSelect(bool enable_selecting, bool select_lin rubberband_now_selected_.clear(); foreach (Block* b, items_in_rubberband) { - if (b->type() == Block::kGap) { + if (dynamic_cast(b)) { continue; } diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index dcea40a4a..af2a3c667 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -75,7 +75,7 @@ void PointerTool::MousePress(TimelineViewMouseEvent *event) // the block is not a gap) if (drag_movement_mode_ == Timeline::kNone && movement_allowed_ - && clicked_item_->type() != Block::kGap) { + && !dynamic_cast(clicked_item_)) { drag_movement_mode_ = Timeline::kMove; } @@ -250,18 +250,14 @@ void PointerTool::InitiateDragInternal(Block *clicked_item, if (trim_mode == Timeline::kMove) { - // Each block type has different behavior, so we determine the type of the block that was - // clicked and filter out any others. - Block::Type clicked_block_type = clicked_item->type(); - // Gaps are not allowed to move, and since we only allow moving one block type at a time, // dragging a gap is a no-op - if (clicked_block_type == Block::kGap) { + if (dynamic_cast(clicked_item)) { return; } // Determine if this move is a slide, which is determined by either - bool clips_are_sliding = (slide_instead_of_moving || clicked_block_type == Block::kTransition); + bool clips_are_sliding = (slide_instead_of_moving || dynamic_cast(clicked_item)); if (clips_are_sliding) { // This is a slide. What we do here is move clips within their own track, between the clips @@ -325,7 +321,7 @@ void PointerTool::InitiateDragInternal(Block *clicked_item, } else { // Prepare for a standard pointer move foreach (Block* block, clips) { - if (block->type() == Block::kGap || block->type() == Block::kTransition) { + if (dynamic_cast(block) || dynamic_cast(block)) { // Gaps cannot move, and we handle transitions further down continue; } @@ -378,7 +374,7 @@ void PointerTool::InitiateDragInternal(Block *clicked_item, // transition than a trim/roll bool treat_trim_as_slide = false; - if (block->type() == Block::kClip) { + if (dynamic_cast(block)) { // See if this clip has a transition attached, and move it with the trim if so TransitionBlock* connected_transition; @@ -416,9 +412,9 @@ void PointerTool::InitiateDragInternal(Block *clicked_item, } // See if we can roll the adjacent or if we'll need to create our own gap - if (block->type() != Block::kGap - && !allow_nongap_rolling && adjacent && adjacent->type() != Block::kGap - && !(block->type() == Block::kTransition + if (!dynamic_cast(block) + && !allow_nongap_rolling && adjacent && !dynamic_cast(adjacent) + && !(dynamic_cast(block) && ((trim_mode == Timeline::kTrimIn && static_cast(block)->connected_out_block() == adjacent) || (trim_mode == Timeline::kTrimOut && static_cast(block)->connected_in_block() == adjacent)))) { adjacent = nullptr; @@ -445,7 +441,7 @@ void PointerTool::InitiateDragInternal(Block *clicked_item, if (treat_trim_as_slide) { // We're sliding a transition rather than a pure trim/roll SetGhostToSlideMode(adjacent_ghost); - } else if (block->type() == Block::kGap) { + } else if (dynamic_cast(block)) { ghost->SetData(TimelineViewGhostItem::kTrimShouldBeIgnored, true); } else { adjacent_ghost->SetData(TimelineViewGhostItem::kTrimShouldBeIgnored, true); diff --git a/app/widget/timelinewidget/tool/razor.cpp b/app/widget/timelinewidget/tool/razor.cpp index 2e7a84e20..fadc7b7c0 100644 --- a/app/widget/timelinewidget/tool/razor.cpp +++ b/app/widget/timelinewidget/tool/razor.cpp @@ -71,7 +71,7 @@ void RazorTool::MouseRelease(TimelineViewMouseEvent *event) // Ensure there's a valid block here if (block_at_time && block_at_time->out() != split_time - && block_at_time->type() == Block::kClip + && dynamic_cast(block_at_time) && !blocks_to_split.contains(block_at_time)) { blocks_to_split.append(block_at_time); diff --git a/app/widget/timelinewidget/tool/ripple.cpp b/app/widget/timelinewidget/tool/ripple.cpp index 3e9557216..ba5e3dce9 100644 --- a/app/widget/timelinewidget/tool/ripple.cpp +++ b/app/widget/timelinewidget/tool/ripple.cpp @@ -82,7 +82,7 @@ void RippleTool::InitiateDrag(Block *clicked_item, if (block_after_ripple) { TimelineViewGhostItem* ghost; - if (block_after_ripple->type() == Block::kGap) { + if (dynamic_cast(block_after_ripple)) { // If this Block is already a Gap, ghost it now ghost = AddGhostFromBlock(block_after_ripple, trim_mode); } else { @@ -90,7 +90,7 @@ void RippleTool::InitiateDrag(Block *clicked_item, // or we'll have to create a new gap ourselves Block* previous = block_after_ripple->previous(); - if (previous && previous->type() == Block::kGap) { + if (dynamic_cast(previous)) { // Previous is a gap, that'll make a fine substitute ghost = AddGhostFromBlock(previous, trim_mode); } else { diff --git a/app/widget/timelinewidget/tool/transition.cpp b/app/widget/timelinewidget/tool/transition.cpp index 4e5ff5e7e..b66ba7394 100644 --- a/app/widget/timelinewidget/tool/transition.cpp +++ b/app/widget/timelinewidget/tool/transition.cpp @@ -45,7 +45,7 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event) } Block* block_at_time = t->BlockAtTime(event->GetFrame()); - if (!block_at_time || block_at_time->type() != Block::kClip) { + if (!dynamic_cast(block_at_time)) { return; } @@ -60,8 +60,7 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event) trim_mode = Timeline::kTrimIn; if (cursor_frame < tenth_point - && block_at_time->previous() - && block_at_time->previous()->type() == Block::kClip) { + && dynamic_cast(block_at_time->previous())) { other_block = block_at_time->previous(); } } else { @@ -70,8 +69,7 @@ void TransitionTool::MousePress(TimelineViewMouseEvent *event) dual_transition_ = (cursor_frame > block_at_time->length() - tenth_point); if (cursor_frame > block_at_time->length() - tenth_point - && block_at_time->next() - && block_at_time->next()->type() == Block::kClip) { + && dynamic_cast(block_at_time->next())) { other_block = block_at_time->next(); } } diff --git a/app/widget/timelinewidget/view/timelineview.cpp b/app/widget/timelinewidget/view/timelineview.cpp index 671ce8418..66d35f005 100644 --- a/app/widget/timelinewidget/view/timelineview.cpp +++ b/app/widget/timelinewidget/view/timelineview.cpp @@ -384,7 +384,7 @@ void TimelineView::DrawBlocks(QPainter *painter, bool foreground) Block* block = track->NearestBlockBeforeOrAt(start_time); while (block) { - if (block->type() == Block::kClip || block->type() == Block::kTransition) { + if (dynamic_cast(block) || dynamic_cast(block)) { qreal block_left = qMax(left_bound, TimeToScene(block->in())); qreal block_right = qMin(right_bound, TimeToScene(block->out())) - 1; diff --git a/app/widget/timelinewidget/view/timelineviewghostitem.h b/app/widget/timelinewidget/view/timelineviewghostitem.h index c7f62c846..3237b6519 100644 --- a/app/widget/timelinewidget/view/timelineviewghostitem.h +++ b/app/widget/timelinewidget/view/timelineviewghostitem.h @@ -23,6 +23,8 @@ #include +#include "node/block/clip/clip.h" +#include "node/block/transition/transition.h" #include "node/output/track/track.h" #include "node/project/footage/footage.h" #include "timeline/timelinecommon.h" @@ -67,16 +69,11 @@ public: ghost->SetTrack(block->track()->ToReference()); ghost->SetData(kAttachedBlock, Node::PtrToValue(block)); - switch (block->type()) { - case Block::kClip: + if (dynamic_cast(block)) { ghost->can_have_zero_length_ = false; - break; - case Block::kTransition: + } else if (dynamic_cast(block)) { ghost->can_have_zero_length_ = false; ghost->SetCanMoveTracks(false); - break; - case Block::kGap: - break; } return ghost;