Skip to content

Commit

Permalink
Use one command class to update component instead of three.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 19, 2015
1 parent c5ef284 commit a818bbd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 190 deletions.
36 changes: 4 additions & 32 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -621,39 +621,11 @@ void LineAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

/*!
* \brief LineAnnotation::handleComponentMoved
* If the component associated with the connection is moved then update the connection accordingly.
*/
void LineAnnotation::handleComponentMoved()
{
if (mPoints.size() < 2) {
return;
}
// if both the components are moved then move the whole connection
if (mpStartComponent && mpEndComponent) {
if (mpStartComponent->getRootParentComponent()->isSelected() && mpEndComponent->getRootParentComponent()->isSelected()) {
moveAllPoints(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()).x() - mPoints[0].x(),
mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()).y() - mPoints[0].y());
} else {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpStartComponent->getRootParentComponent()) {
updateStartPoint(mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center())));
} else if (pComponent == mpEndComponent->getRootParentComponent()) {
updateEndPoint(mpGraphicsView->roundPoint(mpEndComponent->mapToScene(mpEndComponent->boundingRect().center())));
}
}
} else if (mpStartComponent) {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpStartComponent->getRootParentComponent()) {
updateStartPoint(mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center())));
}
} else if (mpEndComponent) {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpEndComponent->getRootParentComponent()) {
updateEndPoint(mpGraphicsView->roundPoint(mpEndComponent->mapToScene(mpEndComponent->boundingRect().center())));
}
}
update();
}

void LineAnnotation::handleComponentRotation()
{
if (mPoints.size() < 2) {
return;
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -102,7 +102,6 @@ class LineAnnotation : public ShapeAnnotation
QString mEndComponentName;
public slots:
void handleComponentMoved();
void handleComponentRotation();
void updateConnectionAnnotation();
void duplicate();
};
Expand Down
75 changes: 46 additions & 29 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -727,21 +727,19 @@ QString Component::getTransformationExtent()

void Component::applyRotation(qreal angle)
{
Transformation oldTransformation = mTransformation;
setOriginAndExtents();
if (angle == 360) {
angle = 0;
}
mTransformation.setRotateAngle(angle);
setTransform(mTransformation.getTransformationMatrix());
emit rotationChange();
emit transformHasChanged();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
{
// handle component position, rotation and scale changes
connect(this, SIGNAL(transformChange()), pConnectorLineAnnotation, SLOT(handleComponentMoved()));
connect(this, SIGNAL(rotationChange()), pConnectorLineAnnotation, SLOT(handleComponentRotation()));
if (!pConnectorLineAnnotation->isInheritedShape()) {
connect(this, SIGNAL(transformHasChanged()), pConnectorLineAnnotation, SLOT(updateConnectionAnnotation()));
}
Expand All @@ -750,7 +748,6 @@ void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
void Component::removeConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
{
disconnect(this, SIGNAL(transformChange()), pConnectorLineAnnotation, SLOT(handleComponentMoved()));
disconnect(this, SIGNAL(rotationChange()), pConnectorLineAnnotation, SLOT(handleComponentRotation()));
if (!pConnectorLineAnnotation->isInheritedShape()) {
disconnect(this, SIGNAL(transformHasChanged()), pConnectorLineAnnotation, SLOT(updateConnectionAnnotation()));
}
Expand Down Expand Up @@ -1231,13 +1228,19 @@ void Component::duplicate()

void Component::rotateClockwise()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new RotateComponentCommand(this, true));
qreal oldRotation = StringHandler::getNormalizedAngle(mTransformation.getRotateAngle());
qreal rotateIncrement = -90;
qreal angle = oldRotation + rotateIncrement;
applyRotation(angle);
showResizerItems();
}

void Component::rotateAntiClockwise()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new RotateComponentCommand(this, false));
qreal oldRotation = StringHandler::getNormalizedAngle(mTransformation.getRotateAngle());
qreal rotateIncrement = 90;
qreal angle = oldRotation + rotateIncrement;
applyRotation(angle);
showResizerItems();
}

Expand All @@ -1260,7 +1263,6 @@ void Component::flipHorizontal()
mTransformation.setExtent2(QPointF(extent2.x(), extent1.y()));
}
setTransform(mTransformation.getTransformationMatrix());
emit rotationChange();
emit transformHasChanged();
showResizerItems();
}
Expand All @@ -1284,7 +1286,6 @@ void Component::flipVertical()
mTransformation.setExtent2(QPointF(extent1.x(), extent2.y()));
}
setTransform(mTransformation.getTransformationMatrix());
emit rotationChange();
emit transformHasChanged();
showResizerItems();
}
Expand All @@ -1297,8 +1298,9 @@ void Component::flipVertical()
*/
void Component::moveUp()
{
qreal y = mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 0, y, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1309,8 +1311,9 @@ void Component::moveUp()
*/
void Component::moveShiftUp()
{
qreal y = mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5;
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 0, y, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1321,7 +1324,9 @@ void Component::moveShiftUp()
*/
void Component::moveCtrlUp()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 0, 1, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, 1);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1332,8 +1337,9 @@ void Component::moveCtrlUp()
*/
void Component::moveDown()
{
qreal y = -mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 0, y, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1344,8 +1350,9 @@ void Component::moveDown()
*/
void Component::moveShiftDown()
{
qreal y = -(mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 0, y, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -(mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1356,7 +1363,9 @@ void Component::moveShiftDown()
*/
void Component::moveCtrlDown()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 0, -1, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -1);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1367,8 +1376,9 @@ void Component::moveCtrlDown()
*/
void Component::moveLeft()
{
qreal x = -mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, x, 0, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1379,8 +1389,9 @@ void Component::moveLeft()
*/
void Component::moveShiftLeft()
{
qreal x = -(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, x, 0, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1391,7 +1402,9 @@ void Component::moveShiftLeft()
*/
void Component::moveCtrlLeft()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, -1, 0, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-1, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1402,8 +1415,9 @@ void Component::moveCtrlLeft()
*/
void Component::moveRight()
{
qreal x = mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, x, 0, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1414,8 +1428,9 @@ void Component::moveRight()
*/
void Component::moveShiftRight()
{
qreal x = mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5;
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, x, 0, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

/*!
Expand All @@ -1426,7 +1441,9 @@ void Component::moveShiftRight()
*/
void Component::moveCtrlRight()
{
mpGraphicsView->getModelWidget()->getUndoStack()->push(new MoveComponentKeyCommand(this, 1, 0, mpGraphicsView));
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(1, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentCommand(this, oldTransformation, mTransformation, mpGraphicsView));
}

//! Slot that opens up the component parameters dialog.
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -235,7 +235,6 @@ class Component : public QObject, public QGraphicsItem
void transformChange();
void transformHasChanged();
void displayTextChanged();
void rotationChange();
void deleted();
public slots:
void updatePlacementAnnotation();
Expand Down

0 comments on commit a818bbd

Please sign in to comment.