[vlmc-devel] Commands: Rework Remove command

Hugo Beauzée-Luyssen git at videolan.org
Sun Oct 30 22:36:46 CET 2016


vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sun Oct 30 22:10:08 2016 +0100| [b0ef2e6a790172339416ec5a839a6b4bd5932ca6] | committer: Hugo Beauzée-Luyssen

Commands: Rework Remove command

It now stores less individual info and handles grouping

> https://code.videolan.org/videolan/vlmc/commit/b0ef2e6a790172339416ec5a839a6b4bd5932ca6
---

 src/Commands/Commands.cpp | 50 ++++++++++++++++++++++++++++-------------------
 src/Commands/Commands.h   |  7 ++++---
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/src/Commands/Commands.cpp b/src/Commands/Commands.cpp
index e20ee8f..dfe194d 100644
--- a/src/Commands/Commands.cpp
+++ b/src/Commands/Commands.cpp
@@ -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,
diff --git a/src/Commands/Commands.h b/src/Commands/Commands.h
index 656d637..7fbfaf3 100644
--- a/src/Commands/Commands.h
+++ b/src/Commands/Commands.h
@@ -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;
         };
 
         /**



More information about the Vlmc-devel mailing list