SANKORE-300 / SANKORE-332 : fix clear item when we add new page, and this item not in scene

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent d15e23d629
commit c4cefa677e
  1. 45
      src/board/UBBoardController.cpp
  2. 3
      src/board/UBBoardController.h
  3. 3
      src/domain/UBGraphicsItemUndoCommand.h

@ -1132,7 +1132,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
if(sceneChange)
emit activeSceneWillChange();
UBApplication::undoStack->clear();
ClearUndoStack();
mActiveScene = targetScene;
mActiveDocument = pDocumentProxy;
@ -1173,6 +1173,49 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
}
}
void UBBoardController::ClearUndoStack()
{
QSet<QGraphicsItem*> uniqueItems;
QUndoStack *stack = UBApplication::undoStack;
// go through all stack command
for(int i = 0; i < stack->count(); i++)
{
UBGraphicsItemUndoCommand *cmd = (UBGraphicsItemUndoCommand*)stack->command(i);
// go through all added and removed objects, for create list of unique objects
QSetIterator<QGraphicsItem*> itAdded(cmd->GetAddedList());
while (itAdded.hasNext())
{
QGraphicsItem* item = itAdded.next();
if( !uniqueItems.contains(item) )
uniqueItems.insert(item);
}
QSetIterator<QGraphicsItem*> itRemoved(cmd->GetRemovedList());
while (itRemoved.hasNext())
{
QGraphicsItem* item = itRemoved.next();
if( !uniqueItems.contains(item) )
uniqueItems.insert(item);
}
}
// clear stack, and command list
stack->clear();
// go through all unique items, and check, ot on scene, or not.
// if not on scene, than item can be deleted
QSetIterator<QGraphicsItem*> itUniq(uniqueItems);
while (itUniq.hasNext())
{
QGraphicsItem* item = itUniq.next();
UBGraphicsScene *scene = (UBGraphicsScene*)item->scene();
if(!scene)
delete item;
}
}
void UBBoardController::adjustDisplayViews()
{

@ -150,6 +150,9 @@ class UBBoardController : public QObject
void notifyPageChanged();
void displayMetaData(QMap<QString, QString> metadatas);
void ClearUndoStack();
public slots:
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0);
void showDocumentsDialog();

@ -32,6 +32,9 @@ class UBGraphicsItemUndoCommand : public QUndoCommand
virtual ~UBGraphicsItemUndoCommand();
QSet<QGraphicsItem*> GetAddedList() { return mAddedItems; };
QSet<QGraphicsItem*> GetRemovedList() { return mRemovedItems; };
protected:
virtual void undo();
virtual void redo();

Loading…
Cancel
Save