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:

Qt Code:
  1. class CommandMove : public QUndoCommand
  2. {
  3. public:
  4. CommandMove(QGraphicsItem *item, qreal fromX, qreal fromY,
  5. qreal toX, qreal toY)
  6. {
  7. m_item = item;
  8. mFrom = QPointF(fromX, fromY);
  9. mTo = QPointF(toX, toY);
  10. setText(QString("Point move (%1,%2) -> (%3,%4)").arg(fromX).arg(fromY)
  11. .arg(toX).arg(toY));
  12. }
  13.  
  14. virtual void undo()
  15. {
  16. m_item->setPos(mFrom);
  17. }
  18.  
  19. virtual void redo()
  20. {
  21. m_item->setPos(mTo);
  22. }
  23.  
  24. private:
  25. QGraphicsItem *m_item;
  26. QPointF mFrom;
  27. QPointF mTo;
  28. };
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:

Qt Code:
  1. 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!