I am moving different entities like point, line, circle and ellipse in my scene. I am implementing undo-redo using the Undo-Redo Framework provided in Qt. I get correct coordinates for point when it is moved from one position to another i.e. I get its scene coordinates.
When I move onto other entities, I get coordinates in the stack in the terms of their local coordinates, not the scene coordinates. How do I get the scene coordinates of other entities?
My move command is defined as:
{
public:
qreal toX, qreal toY)
{
m_item = item;
setText
(QString("Point move (%1,%2) -> (%3,%4)").
arg(fromX
).
arg(fromY
) .arg(toX).arg(toY));
}
virtual void undo()
{
m_item->setPos(mFrom);
}
virtual void redo()
{
m_item->setPos(mTo);
}
private:
};
class CommandMove : public QUndoCommand
{
public:
CommandMove(QGraphicsItem *item, qreal fromX, qreal fromY,
qreal toX, qreal toY)
{
m_item = item;
mFrom = QPointF(fromX, fromY);
mTo = QPointF(toX, toY);
setText(QString("Point move (%1,%2) -> (%3,%4)").arg(fromX).arg(fromY)
.arg(toX).arg(toY));
}
virtual void undo()
{
m_item->setPos(mFrom);
}
virtual void redo()
{
m_item->setPos(mTo);
}
private:
QGraphicsItem *m_item;
QPointF mFrom;
QPointF mTo;
};
To copy to clipboard, switch view to plain text mode
What should be added/edited in this piece of code so that I get the scene coordinates for all entities?
Also I have set the position of point in mousePressEvent using:
setPos(mouseEvent->scenePos);
setPos(mouseEvent->scenePos);
To copy to clipboard, switch view to plain text mode
For line, I do using setLine() function but it doesn't give the scene coordinates of the end points of the line. Help me solve this issue.
Thanks in advance!
Bookmarks