[vlmc-devel] Move UndoStack to Core

Hugo Beauzée-Luyssen git at videolan.org
Fri Mar 4 17:14:17 CET 2016


vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Mar  4 11:29:34 2016 +0100| [c79bc205515d9c288ca9a40db5daa8a90abc4dd0] | committer: Hugo Beauzée-Luyssen

Move UndoStack to Core

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

 src/Commands/Commands.cpp        |  4 ++--
 src/Gui/MainWindow.cpp           | 14 +++++++-------
 src/Gui/timeline/TracksScene.cpp |  4 ++--
 src/Gui/timeline/TracksView.cpp  |  8 ++++----
 src/Main/Core.cpp                | 14 ++++++++++++++
 src/Main/Core.h                  |  4 ++++
 src/Project/Project.cpp          | 12 ------------
 src/Project/Project.h            |  3 ---
 8 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/src/Commands/Commands.cpp b/src/Commands/Commands.cpp
index 80a4d06..9351107 100644
--- a/src/Commands/Commands.cpp
+++ b/src/Commands/Commands.cpp
@@ -35,7 +35,7 @@
 void
 Commands::trigger( QUndoCommand* command )
 {
-    Core::getInstance()->currentProject()->undoStack()->push( command );
+    Core::getInstance()->undoStack()->push( command );
 }
 
 Commands::Generic::Generic() :
@@ -43,7 +43,7 @@ Commands::Generic::Generic() :
 {
     //This is connected using a direct connection to ensure the view can be refreshed
     //just after the signal has been emited.
-    connect( Core::getInstance()->currentProject()->undoStack(), SIGNAL( retranslateRequired() ),
+    connect( Core::getInstance()->undoStack(), SIGNAL( retranslateRequired() ),
              this, SLOT( retranslate() ), Qt::DirectConnection );
 }
 
diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index 353b3a9..eb61e7d 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -792,13 +792,13 @@ MainWindow::cleanStateChanged( bool isClean )
 void
 MainWindow::on_actionUndo_triggered()
 {
-    Core::getInstance()->currentProject()->undoStack()->undo();
+    Core::getInstance()->undoStack()->undo();
 }
 
 void
 MainWindow::on_actionRedo_triggered()
 {
-    Core::getInstance()->currentProject()->undoStack()->redo();
+    Core::getInstance()->undoStack()->redo();
 }
 
 void
@@ -858,11 +858,11 @@ MainWindow::onProjectLoading(Project* project)
     connect( project, SIGNAL( projectUpdated( const QString&, bool ) ), this, SLOT( projectUpdated( const QString&, bool ) ) );
 
     // Undo/Redo
-    connect( project->undoStack(), SIGNAL( canUndoChanged( bool ) ), this, SLOT( canUndoChanged( bool ) ) );
-    connect( project->undoStack(), SIGNAL( canRedoChanged( bool ) ), this, SLOT( canRedoChanged( bool ) ) );
-    canUndoChanged( project->undoStack()->canUndo() );
-    canRedoChanged( project->undoStack()->canRedo() );
-    m_undoView->setStack( project->undoStack() );
+    connect( Core::getInstance()->undoStack(), SIGNAL( canUndoChanged( bool ) ), this, SLOT( canUndoChanged( bool ) ) );
+    connect( Core::getInstance()->undoStack(), SIGNAL( canRedoChanged( bool ) ), this, SLOT( canRedoChanged( bool ) ) );
+    canUndoChanged( Core::getInstance()->undoStack()->canUndo() );
+    canRedoChanged( Core::getInstance()->undoStack()->canRedo() );
+    m_undoView->setStack( Core::getInstance()->undoStack() );
 
     const ClipRenderer* clipRenderer = qobject_cast<const ClipRenderer*>( m_clipPreview->getGenericRenderer() );
     connect( project->library(), SIGNAL( clipRemoved( const QUuid& ) ), clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
diff --git a/src/Gui/timeline/TracksScene.cpp b/src/Gui/timeline/TracksScene.cpp
index 5b68cd3..2bb5a64 100644
--- a/src/Gui/timeline/TracksScene.cpp
+++ b/src/Gui/timeline/TracksScene.cpp
@@ -105,7 +105,7 @@ TracksScene::askRemoveSelectedItems()
         }
     }
 
-    Core::getInstance()->currentProject()->undoStack()->beginMacro( "Remove clip(s)" );
+    Core::getInstance()->undoStack()->beginMacro( "Remove clip(s)" );
 
     QList<QGraphicsItem*> items = selectedItems();
     for (int i = 0; i < items.size(); ++i )
@@ -132,5 +132,5 @@ TracksScene::askRemoveSelectedItems()
         }
     }
 
-    Core::getInstance()->currentProject()->undoStack()->endMacro();
+    Core::getInstance()->undoStack()->endMacro();
 }
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 30cd527..5f805b5 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -799,7 +799,7 @@ TracksView::dropEvent( QDropEvent *event )
 
     if ( m_dragAudioItem != NULL || m_dragVideoItem != NULL )
     {
-        Core::getInstance()->currentProject()->undoStack()->beginMacro( "Add clip" );
+        Core::getInstance()->undoStack()->beginMacro( "Add clip" );
 
         if ( m_dragAudioItem )
         {
@@ -835,7 +835,7 @@ TracksView::dropEvent( QDropEvent *event )
             m_dragVideoItem = NULL;
         }
 
-        Core::getInstance()->currentProject()->undoStack()->endMacro();
+        Core::getInstance()->undoStack()->endMacro();
 
         m_lastKnownTrack = NULL;
     }
@@ -1183,7 +1183,7 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
             }
         }
         else
-            Core::getInstance()->currentProject()->undoStack()->beginMacro( "Move clip" );
+            Core::getInstance()->undoStack()->beginMacro( "Move clip" );
         m_actionItem->triggerMove( target, targetPos );
         // Update the linked item too
         if ( m_actionItem->groupItem() )
@@ -1194,7 +1194,7 @@ TracksView::mouseReleaseEvent( QMouseEvent *event )
         }
 
         if ( effectItem == NULL )
-            Core::getInstance()->currentProject()->undoStack()->endMacro();
+            Core::getInstance()->undoStack()->endMacro();
 
         m_actionItem->m_oldTrack = m_actionItem->track()->trackWorkflow();
         m_actionRelativeX = -1;
diff --git a/src/Main/Core.cpp b/src/Main/Core.cpp
index a43e076..ae3757b 100644
--- a/src/Main/Core.cpp
+++ b/src/Main/Core.cpp
@@ -25,6 +25,8 @@
 #include <QCoreApplication>
 #include <QDir>
 #include <QtGlobal>
+#include <QUndoStack>
+
 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 # include <QStandardPaths>
 #else
@@ -54,11 +56,17 @@ Core::Core()
     m_workspace = new Workspace( m_settings );
     m_workflow = new MainWorkflow;
     m_workflowRenderer = new WorkflowRenderer( Backend::getBackend(), m_workflow );
+    m_undoStack = new QUndoStack;
+
+    //FIXME: This requires that we always have a project instance, which is the plan, but is broken for now
+    connect( m_undoStack, SIGNAL( cleanChanged( bool ) ), m_currentProject, SLOT( cleanChanged( bool ) ) );
+    connect( m_currentProject, SIGNAL( projectSaved() ), m_undoStack, SLOT( setClean() ) );
 }
 
 Core::~Core()
 {
     m_settings->save();
+    delete m_undoStack;
     delete m_workflowRenderer;
     delete m_workflow;
     delete m_currentProject;
@@ -193,6 +201,12 @@ Core::workflow()
     return m_workflow;
 }
 
+QUndoStack*
+Core::undoStack()
+{
+    return m_undoStack;
+}
+
 Core*
 Core::getInstance()
 {
diff --git a/src/Main/Core.h b/src/Main/Core.h
index 5a160d1..130b27b 100644
--- a/src/Main/Core.h
+++ b/src/Main/Core.h
@@ -34,6 +34,8 @@ class VlmcLogger;
 class Workspace;
 class WorkflowRenderer;
 
+class QUndoStack;
+
 namespace Backend
 {
     class IBackend;
@@ -56,6 +58,7 @@ class Core : public QObject
         Project*                currentProject();
         WorkflowRenderer*       workflowRenderer();
         MainWorkflow*           workflow();
+        QUndoStack*             undoStack();
 
 
         bool                    loadProject( const QString& fileName );
@@ -93,6 +96,7 @@ class Core : public QObject
         Project*                m_currentProject;
         MainWorkflow*           m_workflow;
         WorkflowRenderer*       m_workflowRenderer;
+        QUndoStack*             m_undoStack;
 };
 
 #endif // CORE_H
diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
index 8386ad8..f7e2762 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -24,7 +24,6 @@
 
 #include <QFile>
 #include <QFileInfo>
-#include <QUndoStack>
 
 #include "AutomaticBackup.h"
 #include "Backend/IBackend.h"
@@ -52,7 +51,6 @@ Project::Project( QFile* projectFile )
     m_isClean = projectFile->fileName().endsWith( Project::backupSuffix ) == false;
 
     m_settings = new Settings( QString() );
-    m_undoStack = new QUndoStack;
     m_library = new Library( Core::getInstance()->workspace() );
     initSettings();
     connectComponents();
@@ -67,7 +65,6 @@ Project::Project( const QString& projectName, const QString& projectPath )
     , m_projectManagerUi( NULL )
 {
     m_settings = new Settings( QString() );
-    m_undoStack = new QUndoStack;
     m_library = new Library( Core::getInstance()->workspace() );
     initSettings();
     connectComponents();
@@ -82,7 +79,6 @@ Project::~Project()
 
     delete m_projectFile;
     delete m_library;
-    delete m_undoStack;
     delete m_settings;
 }
 
@@ -92,12 +88,6 @@ Project::library()
     return m_library;
 }
 
-QUndoStack*
-Project::undoStack()
-{
-    return m_undoStack;
-}
-
 Settings*
 Project::settings()
 {
@@ -147,8 +137,6 @@ Project::connectComponents()
 {
     connect( m_library, SIGNAL( cleanStateChanged( bool ) ),
              this, SLOT( libraryCleanChanged( bool ) ) );
-    connect( m_undoStack, SIGNAL( cleanChanged( bool ) ), this, SLOT( cleanChanged( bool ) ) );
-    connect( this, SIGNAL( projectSaved() ), m_undoStack, SLOT( setClean() ) );
     //We have to wait for the library to be loaded before loading the workflow
     //FIXME
     //connect( Core::getInstance()->currentProject()->library(), SIGNAL( projectLoaded() ), this, SLOT( loadWorkflow() ) );
diff --git a/src/Project/Project.h b/src/Project/Project.h
index d66923e..564d5ff 100644
--- a/src/Project/Project.h
+++ b/src/Project/Project.h
@@ -32,7 +32,6 @@
 class QDomDocument;
 class QFile;
 class QString;
-class QUndoStack;
 class QXmlStreamWriter;
 
 class AutomaticBackup;
@@ -140,12 +139,10 @@ class Project : public QObject
     // Dependent components part below:
     public:
         Library*            library();
-        QUndoStack*         undoStack();
         Settings*           settings();
 
     private:
         Library*            m_library;
-        QUndoStack*         m_undoStack;
         Settings*           m_settings;
 };
 



More information about the Vlmc-devel mailing list