diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index ee9bfe9e..d18b53ac 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -66,6 +66,7 @@ #include "UBBoardPaletteManager.h" #include "core/memcheck.h" +//#include UBBoardController::UBBoardController(UBMainWindow* mainWindow) : QObject(mainWindow->centralWidget()) @@ -1176,11 +1177,16 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, void UBBoardController::ClearUndoStack() { QSet uniqueItems; - QUndoStack *stack = UBApplication::undoStack; // go through all stack command - for(int i = 0; i < stack->count(); i++) + int count = UBApplication::undoStack->count(); + for(int i = 0; i < UBApplication::undoStack->count(); i++) { - UBGraphicsItemUndoCommand *cmd = (UBGraphicsItemUndoCommand*)stack->command(i); + + UBAbstractUndoCommand *abstractCmd = (UBAbstractUndoCommand*)UBApplication::undoStack->command(i); + if(abstractCmd->getType() != UBAbstractUndoCommand::undotype_GRAPHICITEM) + continue; + + UBGraphicsItemUndoCommand *cmd = (UBGraphicsItemUndoCommand*)UBApplication::undoStack->command(i); // go through all added and removed objects, for create list of unique objects QSetIterator itAdded(cmd->GetAddedList()); @@ -1201,7 +1207,8 @@ void UBBoardController::ClearUndoStack() } // clear stack, and command list - stack->clear(); + UBApplication::undoStack->clear(); + count = UBApplication::undoStack->count(); // go through all unique items, and check, ot on scene, or not. // if not on scene, than item can be deleted diff --git a/src/domain/UBAbstractUndoCommand.cpp b/src/domain/UBAbstractUndoCommand.cpp new file mode 100644 index 00000000..fe623acc --- /dev/null +++ b/src/domain/UBAbstractUndoCommand.cpp @@ -0,0 +1,40 @@ +/* + * 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 3 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, see . + */ + +#include "UBAbstractUndoCommand.h" + +UBAbstractUndoCommand::UBAbstractUndoCommand() +{ + // NOOP +} + +UBAbstractUndoCommand::~UBAbstractUndoCommand() +{ + // NOOP +} + + +void UBAbstractUndoCommand::undo() +{ + // NOOP +} + +void UBAbstractUndoCommand::redo() +{ + // NOOP +} + +//void UBAbstractUndoCommand::UndoType getType(UndoType type); + diff --git a/src/domain/UBAbstractUndoCommand.h b/src/domain/UBAbstractUndoCommand.h new file mode 100644 index 00000000..85dfcc11 --- /dev/null +++ b/src/domain/UBAbstractUndoCommand.h @@ -0,0 +1,46 @@ +/* + * 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 3 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, see . + */ + +#ifndef UBABSTRACTUNDOCOMMAND_H_ +#define UBABSTRACTUNDOCOMMAND_H_ + +#include + +class UBAbstractUndoCommand : public QUndoCommand +{ + public: + + UBAbstractUndoCommand(); + ~UBAbstractUndoCommand(); + + enum UndoType : int + { + undotype_UNKNOWN = 0, + undotype_DOCUMENT = 1, + undotype_GRAPHICITEMTRANSFORM = 2, + undotype_GRAPHICITEM = 3, + undotype_GRAPHICTEXTITEM = 4, + undotype_PAGESIZE = 5, + }; + + virtual UndoType getType() { return undotype_UNKNOWN; }; + + protected: + virtual void undo(); + virtual void redo(); + +}; + +#endif /* UBABSTRACTUNDOCOMMAND_H_ */ diff --git a/src/domain/UBDocumentUndoCommand.h b/src/domain/UBDocumentUndoCommand.h index a5f61d9a..b6b1785a 100644 --- a/src/domain/UBDocumentUndoCommand.h +++ b/src/domain/UBDocumentUndoCommand.h @@ -17,18 +17,20 @@ #define UBDOCUMENTUNDOCOMMAND_H_ #include +#include "UBAbstractUndoCommand.h" class UBDocumentProxy; class UBGraphicsScene; - -class UBDocumentUndoCommand: public QUndoCommand +class UBDocumentUndoCommand: public UBAbstractUndoCommand { public: UBDocumentUndoCommand(UBDocumentProxy* pDocument, const QList& pOldScenes, const QList& pNewScenes, const int& pActiveSceneIndex); virtual ~UBDocumentUndoCommand(); + virtual UndoType getType() { return undotype_DOCUMENT; }; + protected: virtual void undo(); diff --git a/src/domain/UBGraphicsItemTransformUndoCommand.h b/src/domain/UBGraphicsItemTransformUndoCommand.h index 67b57dd1..2f4538d7 100644 --- a/src/domain/UBGraphicsItemTransformUndoCommand.h +++ b/src/domain/UBGraphicsItemTransformUndoCommand.h @@ -19,9 +19,10 @@ #include #include "UBResizableGraphicsItem.h" +#include "UBAbstractUndoCommand.h" -class UBGraphicsItemTransformUndoCommand : public QUndoCommand +class UBGraphicsItemTransformUndoCommand : public UBAbstractUndoCommand { public: UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem, @@ -31,6 +32,8 @@ class UBGraphicsItemTransformUndoCommand : public QUndoCommand const QSizeF& prevSize = QSizeF()); virtual ~UBGraphicsItemTransformUndoCommand(); + virtual UndoType getType() { return undotype_GRAPHICITEMTRANSFORM; }; + protected: virtual void undo(); virtual void redo(); diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index 84711bd4..d3230893 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -17,11 +17,13 @@ #define UBGRAPHICSITEMUNDOCOMMAND_H_ #include +#include "UBAbstractUndoCommand.h" + class UBGraphicsScene; -class UBGraphicsItemUndoCommand : public QUndoCommand +class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand { public: UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, @@ -35,6 +37,8 @@ class UBGraphicsItemUndoCommand : public QUndoCommand QSet GetAddedList() { return mAddedItems; }; QSet GetRemovedList() { return mRemovedItems; }; + virtual UndoType getType() { return undotype_GRAPHICITEM; }; + protected: virtual void undo(); virtual void redo(); diff --git a/src/domain/UBGraphicsTextItemUndoCommand.h b/src/domain/UBGraphicsTextItemUndoCommand.h index 0198d8b5..9f9a610a 100644 --- a/src/domain/UBGraphicsTextItemUndoCommand.h +++ b/src/domain/UBGraphicsTextItemUndoCommand.h @@ -17,16 +17,19 @@ #define UBGRAPHICSTEXTITEMUNDOCOMMAND_H_ #include +#include "UBAbstractUndoCommand.h" #include "UBGraphicsTextItem.h" -class UBGraphicsTextItemUndoCommand: public QUndoCommand +class UBGraphicsTextItemUndoCommand : public UBAbstractUndoCommand { public: UBGraphicsTextItemUndoCommand(UBGraphicsTextItem *textItem); virtual ~UBGraphicsTextItemUndoCommand(); + virtual UndoType getType() { return undotype_GRAPHICTEXTITEM; }; + protected: virtual void undo(); virtual void redo(); diff --git a/src/domain/UBPageSizeUndoCommand.h b/src/domain/UBPageSizeUndoCommand.h index 78cf98b8..ad295d49 100644 --- a/src/domain/UBPageSizeUndoCommand.h +++ b/src/domain/UBPageSizeUndoCommand.h @@ -17,16 +17,19 @@ #define UBPageSizeUndoCommand_H_ #include +#include "UBAbstractUndoCommand.h" class UBGraphicsScene; -class UBPageSizeUndoCommand : public QUndoCommand +class UBPageSizeUndoCommand : public UBAbstractUndoCommand { public: UBPageSizeUndoCommand(UBGraphicsScene* pScene, const QSize& previousSize, const QSize& newSize); virtual ~UBPageSizeUndoCommand(); + virtual UndoType getType() { return undotype_PAGESIZE; }; + protected: virtual void undo(); virtual void redo();