SANKORE-300 / SANKORE-332 fix crash while processing undo commands with types not equal GraphicsItem

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 34646dab0b
commit 26e1f11a61
  1. 15
      src/board/UBBoardController.cpp
  2. 40
      src/domain/UBAbstractUndoCommand.cpp
  3. 46
      src/domain/UBAbstractUndoCommand.h
  4. 6
      src/domain/UBDocumentUndoCommand.h
  5. 5
      src/domain/UBGraphicsItemTransformUndoCommand.h
  6. 6
      src/domain/UBGraphicsItemUndoCommand.h
  7. 5
      src/domain/UBGraphicsTextItemUndoCommand.h
  8. 5
      src/domain/UBPageSizeUndoCommand.h

@ -66,6 +66,7 @@
#include "UBBoardPaletteManager.h" #include "UBBoardPaletteManager.h"
#include "core/memcheck.h" #include "core/memcheck.h"
//#include <typeinfo>
UBBoardController::UBBoardController(UBMainWindow* mainWindow) UBBoardController::UBBoardController(UBMainWindow* mainWindow)
: QObject(mainWindow->centralWidget()) : QObject(mainWindow->centralWidget())
@ -1176,11 +1177,16 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
void UBBoardController::ClearUndoStack() void UBBoardController::ClearUndoStack()
{ {
QSet<QGraphicsItem*> uniqueItems; QSet<QGraphicsItem*> uniqueItems;
QUndoStack *stack = UBApplication::undoStack;
// go through all stack command // 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 // go through all added and removed objects, for create list of unique objects
QSetIterator<QGraphicsItem*> itAdded(cmd->GetAddedList()); QSetIterator<QGraphicsItem*> itAdded(cmd->GetAddedList());
@ -1201,7 +1207,8 @@ void UBBoardController::ClearUndoStack()
} }
// clear stack, and command list // 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. // go through all unique items, and check, ot on scene, or not.
// if not on scene, than item can be deleted // if not on scene, than item can be deleted

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "UBAbstractUndoCommand.h"
UBAbstractUndoCommand::UBAbstractUndoCommand()
{
// NOOP
}
UBAbstractUndoCommand::~UBAbstractUndoCommand()
{
// NOOP
}
void UBAbstractUndoCommand::undo()
{
// NOOP
}
void UBAbstractUndoCommand::redo()
{
// NOOP
}
//void UBAbstractUndoCommand::UndoType getType(UndoType type);

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef UBABSTRACTUNDOCOMMAND_H_
#define UBABSTRACTUNDOCOMMAND_H_
#include <QtGui>
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_ */

@ -17,18 +17,20 @@
#define UBDOCUMENTUNDOCOMMAND_H_ #define UBDOCUMENTUNDOCOMMAND_H_
#include <QtGui> #include <QtGui>
#include "UBAbstractUndoCommand.h"
class UBDocumentProxy; class UBDocumentProxy;
class UBGraphicsScene; class UBGraphicsScene;
class UBDocumentUndoCommand: public UBAbstractUndoCommand
class UBDocumentUndoCommand: public QUndoCommand
{ {
public: public:
UBDocumentUndoCommand(UBDocumentProxy* pDocument, const QList<UBGraphicsScene*>& pOldScenes, UBDocumentUndoCommand(UBDocumentProxy* pDocument, const QList<UBGraphicsScene*>& pOldScenes,
const QList<UBGraphicsScene*>& pNewScenes, const int& pActiveSceneIndex); const QList<UBGraphicsScene*>& pNewScenes, const int& pActiveSceneIndex);
virtual ~UBDocumentUndoCommand(); virtual ~UBDocumentUndoCommand();
virtual UndoType getType() { return undotype_DOCUMENT; };
protected: protected:
virtual void undo(); virtual void undo();

@ -19,9 +19,10 @@
#include <QtGui> #include <QtGui>
#include "UBResizableGraphicsItem.h" #include "UBResizableGraphicsItem.h"
#include "UBAbstractUndoCommand.h"
class UBGraphicsItemTransformUndoCommand : public QUndoCommand class UBGraphicsItemTransformUndoCommand : public UBAbstractUndoCommand
{ {
public: public:
UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem, UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem,
@ -31,6 +32,8 @@ class UBGraphicsItemTransformUndoCommand : public QUndoCommand
const QSizeF& prevSize = QSizeF()); const QSizeF& prevSize = QSizeF());
virtual ~UBGraphicsItemTransformUndoCommand(); virtual ~UBGraphicsItemTransformUndoCommand();
virtual UndoType getType() { return undotype_GRAPHICITEMTRANSFORM; };
protected: protected:
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();

@ -17,11 +17,13 @@
#define UBGRAPHICSITEMUNDOCOMMAND_H_ #define UBGRAPHICSITEMUNDOCOMMAND_H_
#include <QtGui> #include <QtGui>
#include "UBAbstractUndoCommand.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBGraphicsItemUndoCommand : public QUndoCommand class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand
{ {
public: public:
UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet<QGraphicsItem*>& pRemovedItems, UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet<QGraphicsItem*>& pRemovedItems,
@ -35,6 +37,8 @@ class UBGraphicsItemUndoCommand : public QUndoCommand
QSet<QGraphicsItem*> GetAddedList() { return mAddedItems; }; QSet<QGraphicsItem*> GetAddedList() { return mAddedItems; };
QSet<QGraphicsItem*> GetRemovedList() { return mRemovedItems; }; QSet<QGraphicsItem*> GetRemovedList() { return mRemovedItems; };
virtual UndoType getType() { return undotype_GRAPHICITEM; };
protected: protected:
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();

@ -17,16 +17,19 @@
#define UBGRAPHICSTEXTITEMUNDOCOMMAND_H_ #define UBGRAPHICSTEXTITEMUNDOCOMMAND_H_
#include <QtGui> #include <QtGui>
#include "UBAbstractUndoCommand.h"
#include "UBGraphicsTextItem.h" #include "UBGraphicsTextItem.h"
class UBGraphicsTextItemUndoCommand: public QUndoCommand class UBGraphicsTextItemUndoCommand : public UBAbstractUndoCommand
{ {
public: public:
UBGraphicsTextItemUndoCommand(UBGraphicsTextItem *textItem); UBGraphicsTextItemUndoCommand(UBGraphicsTextItem *textItem);
virtual ~UBGraphicsTextItemUndoCommand(); virtual ~UBGraphicsTextItemUndoCommand();
virtual UndoType getType() { return undotype_GRAPHICTEXTITEM; };
protected: protected:
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();

@ -17,16 +17,19 @@
#define UBPageSizeUndoCommand_H_ #define UBPageSizeUndoCommand_H_
#include <QtGui> #include <QtGui>
#include "UBAbstractUndoCommand.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBPageSizeUndoCommand : public QUndoCommand class UBPageSizeUndoCommand : public UBAbstractUndoCommand
{ {
public: public:
UBPageSizeUndoCommand(UBGraphicsScene* pScene, const QSize& previousSize, const QSize& newSize); UBPageSizeUndoCommand(UBGraphicsScene* pScene, const QSize& previousSize, const QSize& newSize);
virtual ~UBPageSizeUndoCommand(); virtual ~UBPageSizeUndoCommand();
virtual UndoType getType() { return undotype_PAGESIZE; };
protected: protected:
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();

Loading…
Cancel
Save