Commit b0ef2e6a authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Commands: Rework Remove command

It now stores less individual info and handles grouping
parent 4ef621b9
......@@ -200,45 +200,55 @@ Commands::Clip::Move::internalUndo()
}
Commands::Clip::Remove::Remove( std::shared_ptr<SequenceWorkflow> const& workflow,
const QUuid& uuid ) :
m_workflow( workflow ),
m_clip( workflow->clip( uuid ) ),
m_trackId( workflow->trackId( uuid ) ),
m_pos( workflow->position( uuid ) )
const QUuid& uuid )
: m_workflow( workflow )
{
auto clip = workflow->clip( uuid );
m_clips.append( clip );
retranslate();
}
void
Commands::Clip::Remove::retranslate()
{
setText( tr( "Removing clip " ) );
setText( tr( "Removing clip " ) );
}
int
Commands::Clip::Remove::id() const
{
return static_cast<int>( Commands::Id::Remove );
}
bool
Commands::Clip::Remove::mergeWith(const QUndoCommand* command)
{
auto cmd = static_cast<const Remove*>( command );
if ( cmd->m_clips.count() > 1 )
return false;
const auto& linkedClips = m_clips[0]->linkedClips;
if ( linkedClips.contains( cmd->m_clips[0]->uuid ) == false )
return false;
m_clips += cmd->m_clips[0];
return true;
}
void
Commands::Clip::Remove::internalRedo()
{
if ( m_clip == nullptr )
{
invalidate();
return;
}
m_clip = m_workflow->removeClip( m_clip->uuid );
if ( m_clip == nullptr )
invalidate();
for ( const auto& clip : m_clips )
m_workflow->removeClip( clip->uuid );
}
void
Commands::Clip::Remove::internalUndo()
{
if ( m_clip == nullptr )
for ( const auto& clip : m_clips )
{
invalidate();
return;
auto uuid = m_workflow->addClip( clip->clip, clip->trackId, clip->pos, clip->uuid, clip->isAudio );
if ( uuid.isNull() == true )
invalidate();
}
auto ret = m_workflow->addClip( m_clip->clip, m_trackId, m_pos, m_clip->uuid, m_clip->isAudio );
if ( ret.isNull() == true )
invalidate();
}
Commands::Clip::Resize::Resize( std::shared_ptr<SequenceWorkflow> const& workflow,
......
......@@ -51,6 +51,7 @@ namespace Commands
{
Move,
Resize,
Remove,
};
#ifdef HAVE_GUI
......@@ -131,12 +132,12 @@ namespace Commands
virtual void internalRedo();
virtual void internalUndo();
virtual void retranslate();
virtual int id() const;
virtual bool mergeWith( const QUndoCommand* command );
private:
std::shared_ptr<SequenceWorkflow> m_workflow;
QSharedPointer<SequenceWorkflow::ClipInstance> m_clip;
quint32 m_trackId;
qint64 m_pos;
QVector<QSharedPointer<SequenceWorkflow::ClipInstance>> m_clips;
};
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment