'Can we use multiple stack in Qt's Undo Framework (Command Pattern )
I am having a QgraphicsView
which contains multiple QGraphicsItem
. I have some features like zoom-in
, zoom-out
, Hide - Unhide selected item
, Undo-Redo
.
To implement Undo-Redo
feature, I am using Qt's Undo framework
( Command Pattern).
I want to separate out Undo-Redo feature of zoom-in/out
with Undo-Redo feature of Hide/Unhide
.
In a nutshell, I do not want to use same stack for all Undo-Redo feature. Separate stack for zoom-in/out
and separate stack for Hide-Unhide
.
Is separate stack possible ? If yes, then how to do that ?
Below Undo-Redo code is of Zoom-in/out
and it just for reference purpose.
myCommand.h
class myCommand: public QUndoCommand
{
public:
myCommand();
myCommand(double scale, QGraphicsScene* scene,QGraphicsView* view);
private:
QGraphicsItem* mItem;
QGraphicsScene* mScene;
QGraphicsView* mView;
double scaleFactor;
void undo();
void redo();
}
myCommand.cpp
myCommand::myCommand(double scale, QGraphicsScene *scene,QGraphicsView* view): mScene(scene),
mView(view),scaleFactor(scale)
{}
void guiCommand::undo()
{
mView->scale(1/scaleFactor,1/scaleFactor);
}
void myCommand::redo()
{
mView->scale(scaleFactor,scaleFactor);
}
myView.cpp
void myView::ZoomIn()
{
double scaleFactor = 1.1;
myCommand* command1 = new myCommand(scaleFactor,scene,view);
undoStack->push(command1);
view->scale(scaleFactor,scaleFactor);
}
void myView::ZoomOut()
{
double scaleFactor = 1.1;
myCommand* command2 = new myCommand(1/scaleFactor,_scene,_view);
undoStack->push(command2 );
view->scale(1/scaleFactor,1/scaleFactor);
}
myView.h
public:
QUndoStack* undoStack;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|