parent
034800538d
commit
be14bdc657
@ -0,0 +1,59 @@ |
|||||||
|
#include "UBGraphicsItemZLevelUndoCommand.h" |
||||||
|
|
||||||
|
UBGraphicsItemZLevelUndoCommand::UBGraphicsItemZLevelUndoCommand(UBGraphicsScene *_scene, const QList<QGraphicsItem*>& _items, qreal _previousZLevel, UBZLayerController::moveDestination dest):UBUndoCommand(){ |
||||||
|
Q_ASSERT(_scene != NULL); |
||||||
|
mpScene = _scene; |
||||||
|
mItems = _items; |
||||||
|
mPreviousZLevel = _previousZLevel; |
||||||
|
mDest = dest; |
||||||
|
mHack = false; |
||||||
|
} |
||||||
|
|
||||||
|
UBGraphicsItemZLevelUndoCommand::UBGraphicsItemZLevelUndoCommand(UBGraphicsScene *_scene, QGraphicsItem* _item, qreal _previousZLevel, UBZLayerController::moveDestination dest):UBUndoCommand(){ |
||||||
|
Q_ASSERT(_scene != NULL); |
||||||
|
mpScene = _scene; |
||||||
|
if(NULL != _item) |
||||||
|
mItems.append(_item); |
||||||
|
|
||||||
|
mPreviousZLevel = _previousZLevel; |
||||||
|
mDest = dest; |
||||||
|
mHack = false; |
||||||
|
} |
||||||
|
|
||||||
|
UBGraphicsItemZLevelUndoCommand::~UBGraphicsItemZLevelUndoCommand(){ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsItemZLevelUndoCommand::undo(){ |
||||||
|
if(!mpScene) |
||||||
|
return; |
||||||
|
|
||||||
|
foreach(QGraphicsItem* item, mItems){ |
||||||
|
if(mDest == UBZLayerController::down){ |
||||||
|
mpScene->changeZLevelTo(item, UBZLayerController::up); |
||||||
|
}else if(mDest == UBZLayerController::up){ |
||||||
|
mpScene->changeZLevelTo(item, UBZLayerController::down); |
||||||
|
} |
||||||
|
updateLazyScene(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsItemZLevelUndoCommand::redo(){ |
||||||
|
if(!mHack){ |
||||||
|
// Ugly! But pushing a new command to QUndoStack calls redo by itself.
|
||||||
|
mHack = true; |
||||||
|
}else{ |
||||||
|
if(!mpScene) |
||||||
|
return; |
||||||
|
|
||||||
|
foreach(QGraphicsItem* item, mItems){ |
||||||
|
mpScene->changeZLevelTo(item, mDest); |
||||||
|
updateLazyScene(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsItemZLevelUndoCommand::updateLazyScene(){ |
||||||
|
mpScene->update(mpScene->sceneRect()); |
||||||
|
mpScene->updateSelectionFrame(); |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
#ifndef UBGRAPHICSITEMZLEVELUNDOCOMMAND_H |
||||||
|
#define UBGRAPHICSITEMZLEVELUNDOCOMMAND_H |
||||||
|
|
||||||
|
#include <QGraphicsItem> |
||||||
|
|
||||||
|
#include "UBUndoCommand.h" |
||||||
|
#include "UBGraphicsScene.h" |
||||||
|
|
||||||
|
class UBGraphicsItemZLevelUndoCommand : public UBUndoCommand{ |
||||||
|
public: |
||||||
|
UBGraphicsItemZLevelUndoCommand(UBGraphicsScene* _scene, const QList<QGraphicsItem*>& _items, qreal _previousZLevel, UBZLayerController::moveDestination dest); |
||||||
|
UBGraphicsItemZLevelUndoCommand(UBGraphicsScene* _scene, QGraphicsItem* _item, qreal _previousZLevel, UBZLayerController::moveDestination dest); |
||||||
|
~UBGraphicsItemZLevelUndoCommand(); |
||||||
|
|
||||||
|
virtual int getType() const { return UBUndoType::undotype_GRAPHICITEMZVALUE; } |
||||||
|
|
||||||
|
protected: |
||||||
|
virtual void undo(); |
||||||
|
virtual void redo(); |
||||||
|
|
||||||
|
private: |
||||||
|
void updateLazyScene(); |
||||||
|
|
||||||
|
qreal mPreviousZLevel; |
||||||
|
QList<QGraphicsItem*> mItems; |
||||||
|
UBGraphicsScene* mpScene; |
||||||
|
UBZLayerController::moveDestination mDest; |
||||||
|
bool mHack; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
#endif // UBGRAPHICSITEMZLEVELUNDOCOMMAND_H
|
Loading…
Reference in new issue