From 2dbade1a79cdbdb738beb612c18e66fb961e11b0 Mon Sep 17 00:00:00 2001 From: Didier Clerc Date: Mon, 5 Aug 2013 16:17:31 +0900 Subject: [PATCH] Fixed z level undo issue --- .../UBGraphicsItemZLevelUndoCommand.cpp | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/domain/UBGraphicsItemZLevelUndoCommand.cpp b/src/domain/UBGraphicsItemZLevelUndoCommand.cpp index d1683929..e15f59b5 100644 --- a/src/domain/UBGraphicsItemZLevelUndoCommand.cpp +++ b/src/domain/UBGraphicsItemZLevelUndoCommand.cpp @@ -25,17 +25,28 @@ UBGraphicsItemZLevelUndoCommand::~UBGraphicsItemZLevelUndoCommand(){ } void UBGraphicsItemZLevelUndoCommand::undo(){ - if(!mpScene) + if(!mpScene || mItems.empty()) return; - foreach(QGraphicsItem* item, mItems){ - if(mDest == UBZLayerController::down){ - mpScene->changeZLevelTo(item, UBZLayerController::up); - }else if(mDest == UBZLayerController::up){ - mpScene->changeZLevelTo(item, UBZLayerController::down); + // Getting the difference between the initial z-value and the actual one + qreal zDiff = qAbs(mItems.at(mItems.size()-1)->data(UBGraphicsItemData::ItemOwnZValue).toReal() - mPreviousZLevel); + + if(mDest == UBZLayerController::down || mDest == UBZLayerController::bottom){ + // Move up + QList::iterator downIt = mItems.end(); + for(downIt; downIt >= mItems.begin(); downIt--){ + for(int i=0; ichangeZLevelTo(*downIt, UBZLayerController::up); + } + + }else if(mDest == UBZLayerController::up || mDest == UBZLayerController::top){ + // Move down + foreach(QGraphicsItem* item, mItems){ + for(int i=0; ichangeZLevelTo(item, UBZLayerController::down); } - updateLazyScene(); } + } void UBGraphicsItemZLevelUndoCommand::redo(){