Skip to content

Commit

Permalink
Fixed: Selecting a shape adds a move action to the undo stack (closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
sofian committed Apr 14, 2020
1 parent 49e90ca commit b2bcfa5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/gui/MapperGLCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow,
_vertexMoved(false),
_activeVertex(NO_VERTEX),
_shapeGrabbed(false), // comment out?
_shapeMoved(false),
_shapeFirstGrab(false), // comment out?
_zoomLevel(0),
_shapeIsAdapted(false)
Expand Down Expand Up @@ -336,6 +337,7 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event)
if (event->buttons() & Qt::LeftButton) {
// Shape can be grabbed only if it is not locked
_shapeGrabbed = !selectedShape->isLocked();
// _shapeMoved = false;
_shapeFirstGrab = true;

_grabbedObjectStartScenePosition = pos;
Expand Down Expand Up @@ -416,13 +418,15 @@ void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event)
}
else if (_shapeGrabbed)
{
undoStack->push(new TranslateShapeCommand(this,
TransformShapeCommand::RELEASE, QPointF()));
if (_shapeMoved)
undoStack->push(new TranslateShapeCommand(this,
TransformShapeCommand::RELEASE, QPointF()));
}

_vertexGrabbed = false;
_vertexMoved = false;
_shapeGrabbed = false;
_shapeMoved = false;
}

void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
Expand Down Expand Up @@ -483,6 +487,8 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
// Reset the mode after moved shape
getCurrentShape()->setShapeMode(MShape::DefaultMode);
}

_shapeMoved = true; // The active vertex is actually moved
}
QPointF diff = scenePos - mapToScene(lastMousePos);
undoStack->push(new TranslateShapeCommand(this, TransformShapeCommand::FREE, diff));
Expand Down Expand Up @@ -695,6 +701,7 @@ void MapperGLCanvas::deselectAll()
{
deselectVertices();
_shapeGrabbed = false;
_shapeMoved = false;
_shapeFirstGrab = false;
}

Expand Down
5 changes: 4 additions & 1 deletion src/gui/MapperGLCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,17 @@ class MapperGLCanvas: public QGraphicsView

// Mouse currently pressed inside a vertex.
bool _vertexGrabbed;
// If current vertex is moved

// If current vertex has been moved.
bool _vertexMoved;

// Index of currently active vertex.
int _activeVertex;

// True iff current shape is grabbed.
bool _shapeGrabbed;
// If current shape has been moved.
bool _shapeMoved;

// True iff current shape is grabbed (first step).
bool _shapeFirstGrab;
Expand Down

0 comments on commit b2bcfa5

Please sign in to comment.