[vlmc-devel] [PATCH 09/12] Add AbstractUndoStack
Yikai Lu
luyikei.qmltu at gmail.com
Sun May 22 08:36:53 CEST 2016
---
src/CMakeLists.txt | 4 +-
src/Commands/AbstractUndoStack.cpp | 79 ++++++++++++++++++++++++++++++++++++++
src/Commands/AbstractUndoStack.h | 68 ++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+), 2 deletions(-)
create mode 100644 src/Commands/AbstractUndoStack.cpp
create mode 100644 src/Commands/AbstractUndoStack.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 238bffa..fd882fe 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -37,6 +37,7 @@ INCLUDE_DIRECTORIES(${FREI0R_INCLUDE_DIR})
SET(CMAKE_AUTOMOC ON)
SET(VLMC_SRCS
+ Commands/Commands.cpp
Backend/IBackend.h
Backend/ISourceRenderer.h
Backend/ISource.h
@@ -113,7 +114,7 @@ INCLUDE_DIRECTORIES(
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
IF (NOT WITH_GUI)
- LIST (APPEND VLMC_SRCS Main/main.cpp Renderer/ConsoleRenderer.cpp )
+ LIST (APPEND VLMC_SRCS Main/main.cpp Renderer/ConsoleRenderer.cpp Commands/AbstractUndoStack.cpp)
qt5_add_resources(VLMC_RCC_SRCS ${VLMC_RCC})
ADD_EXECUTABLE(vlmc ${GUI_TYPE} ${VLMC_SRCS} ${VLMC_MOC_SRCS} ${VLMC_RCC_SRCS})
qt5_use_modules(vlmc Core Network)
@@ -122,7 +123,6 @@ IF (NOT WITH_GUI)
#Add GUI stuff if required
ELSE(NOT WITH_GUI)
LIST( APPEND VLMC_SRCS
- Commands/Commands.cpp
Commands/KeyboardShortcutHelper.cpp
Renderer/ClipRenderer.cpp
Services/YouTube/YouTubeAuthenticator.cpp
diff --git a/src/Commands/AbstractUndoStack.cpp b/src/Commands/AbstractUndoStack.cpp
new file mode 100644
index 0000000..aa6eed0
--- /dev/null
+++ b/src/Commands/AbstractUndoStack.cpp
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * AbstractUndoStack.cpp: An abstract UndoStack implementation for CUI
+ *****************************************************************************
+ * Copyright (C) 2008-2016 VideoLAN
+ *
+ * Authors: Yikei Lu <luyikei.qmltu at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "AbstractUndoStack.h"
+#include "Commands.h"
+
+using namespace Commands;
+
+AbstractUndoStack::AbstractUndoStack( QObject* parent )
+ : QObject( parent )
+ , m_index( -1 )
+{
+
+}
+
+void
+AbstractUndoStack::redo()
+{
+ if ( m_index >= m_stack.size() )
+ return;
+ m_stack[m_index]->redo();
+ m_index++;
+ _setClean( false );
+}
+
+void
+AbstractUndoStack::undo()
+{
+ if ( m_index < 0 )
+ return;
+ m_stack[m_index]->undo();
+ m_index--;
+ _setClean( false );
+}
+
+void
+AbstractUndoStack::push( Generic* command )
+{
+ if ( m_index == -1 )
+ m_index = 0;
+ while ( m_index < m_stack.size() )
+ m_stack.pop();
+ m_stack.push( command );
+ command->redo();
+ _setClean( false );
+}
+
+void
+AbstractUndoStack::setClean()
+{
+ _setClean( true );
+}
+
+void
+AbstractUndoStack::_setClean( bool val )
+{
+ if ( val != m_isClean )
+ emit cleanChanged( val );
+ m_isClean = val;
+}
diff --git a/src/Commands/AbstractUndoStack.h b/src/Commands/AbstractUndoStack.h
new file mode 100644
index 0000000..b7fdf74
--- /dev/null
+++ b/src/Commands/AbstractUndoStack.h
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * AbstractUndoStack.h: An abstract UndoStack for both GUI and CUI
+ *****************************************************************************
+ * Copyright (C) 2008-2016 VideoLAN
+ *
+ * Authors: Yikei Lu <luyikei.qmltu at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef ABSTRACTUNDOSTACK_H
+#define ABSTRACTUNDOSTACK_H
+
+#include <QObject>
+
+#ifdef WITH_GUI
+#include <QUndoStack>
+#include "Commands.h"
+#else
+#include <QStack>
+#endif
+
+namespace Commands
+{
+#ifdef WITH_GUI
+ class AbstractUndoStack : public QUndoStack
+ {
+#else
+ class Generic;
+ class AbstractUndoStack : public QObject
+ {
+ Q_OBJECT
+ public:
+ explicit AbstractUndoStack( QObject* parent = 0 );
+
+ signals:
+ void cleanChanged( bool val );
+
+ public slots:
+ void redo();
+ void undo();
+ void push( Generic* command );
+ void setClean();
+
+ private:
+ // Avoid overloading setClean
+ void _setClean( bool val );
+
+ bool m_isClean;
+ QStack<Generic*> m_stack;
+ int m_index;
+#endif
+ };
+}
+
+#endif // ABSTRACTUNDOSTACK_H
--
1.9.1
More information about the Vlmc-devel
mailing list