[vlmc-devel] commit: Undo/Redo: Allow commands to be invalidated. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Oct 11 00:07:23 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sat Oct  9 17:10:26 2010 +0200| [52718ac06bea951f8b6af3e42ccd4ab065effa05] | committer: Hugo Beauzée-Luyssen 

Undo/Redo: Allow commands to be invalidated.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=52718ac06bea951f8b6af3e42ccd4ab065effa05
---

 src/CMakeLists.txt        |    1 +
 src/Commands/Commands.cpp |   26 ++++++++++++++++++++++----
 src/Commands/Commands.h   |   14 ++++++++++++--
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e462a96..df6cdd3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -222,6 +222,7 @@ ELSE(NOT WITH_GUI)
         )
 
     LIST( APPEND VLMC_MOC_HDRS
+        Commands/Commands.h
         Commands/KeyboardShortcutHelper.h
         Gui/About.h
         Gui/ClipProperty.h
diff --git a/src/Commands/Commands.cpp b/src/Commands/Commands.cpp
index 06792d6..2738336 100644
--- a/src/Commands/Commands.cpp
+++ b/src/Commands/Commands.cpp
@@ -46,13 +46,29 @@ void Commands::trigger( Commands::Generic* command )
 }
 #endif
 
+Commands::Generic::Generic() :
+        m_valid( true )
+{
+}
+
+void
+Commands::Generic::invalidate()
+{
+    m_valid = false;
+}
 
+bool
+Commands::Generic::isValid() const
+{
+    return m_valid;
+}
 
 Commands::Clip::Add::Add( ClipHelper* ch, TrackWorkflow* tw, qint64 pos ) :
         m_clipHelper( ch ),
         m_trackWorkflow( tw ),
         m_pos( pos )
 {
+    connect( ch->clip(), SIGNAL( destroyed() ), this, SLOT( invalidate() ) );
     setText( QObject::tr( "Adding clip to track %1" ).arg( tw->trackId() ) );
 }
 
@@ -78,6 +94,7 @@ Commands::Clip::Move::Move( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
     m_newPos( newPos )
 
 {
+    connect( clipHelper->clip(), SIGNAL( destroyed() ), this, SLOT( invalidate() ) );
     Q_ASSERT( oldTrack->type() == newTrack->type() );
 
     if ( oldTrack != newTrack )
@@ -113,6 +130,7 @@ void Commands::Clip::Move::undo()
 Commands::Clip::Remove::Remove( ClipHelper* ch, TrackWorkflow* tw ) :
         m_clipHelper( ch ), m_trackWorkflow( tw )
 {
+    connect( ch->clip(), SIGNAL( destroyed() ), this, SLOT( invalidate() ) );
     setText( QObject::tr( "Remove clip" ) );
     m_pos = tw->getClipPosition( ch->uuid() );
 }
@@ -127,16 +145,15 @@ void Commands::Clip::Remove::undo()
     m_trackWorkflow->addClip( m_clipHelper, m_pos );
 }
 
-Commands::Clip::Resize::Resize( TrackWorkflow* tw,
-                                                ClipHelper* ch,
-                                                qint64 newBegin, qint64 newEnd,
-                                                qint64 newPos ) :
+Commands::Clip::Resize::Resize( TrackWorkflow* tw, ClipHelper* ch, qint64 newBegin,
+                                qint64 newEnd, qint64 newPos ) :
     m_trackWorkflow( tw ),
     m_clipHelper( ch ),
     m_newBegin( newBegin ),
     m_newEnd( newEnd ),
     m_newPos( newPos )
 {
+    connect( ch->clip(), SIGNAL( destroyed() ), this, SLOT( invalidate() ) );
     m_oldBegin = ch->begin();
     m_oldEnd = ch->end();
     m_oldPos = tw->getClipPosition( ch->uuid() );
@@ -169,6 +186,7 @@ Commands::Clip::Split::Split( TrackWorkflow *tw, ClipHelper *toSplit,
     m_newClipPos( newClipPos ),
     m_newClipBegin( newClipBegin )
 {
+    connect( toSplit->clip(), SIGNAL( destroyed() ), this, SLOT( invalidate() ) );
     m_newClip = new ClipHelper( toSplit->clip(), newClipBegin, toSplit->end() );
     m_oldEnd = toSplit->end();
     setText( QObject::tr("Splitting clip") );
diff --git a/src/Commands/Commands.h b/src/Commands/Commands.h
index fb4609e..983383a 100644
--- a/src/Commands/Commands.h
+++ b/src/Commands/Commands.h
@@ -42,14 +42,24 @@ class   EffectUser;
 namespace Commands
 {
 #ifdef WITH_GUI
-    class       Generic : public QUndoCommand
+    class       Generic : public QObject, public QUndoCommand
 #else
-    class       Generic
+    class       Generic : public QObject
 #endif
     {
+        Q_OBJECT
+
         public:
+            Generic();
             virtual void    redo() = 0;
             virtual void    undo() = 0;
+            bool            isValid() const;
+        private:
+            bool            m_valid;
+        protected slots:
+            void            invalidate();
+        signals:
+            void            invalidated();
 #ifndef WITH_GUI
             virtual void    setText( const QString& ) {}
 #endif



More information about the Vlmc-devel mailing list