Skip to content

Commit

Permalink
Update connection when both start and end connectors are rotated
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Sep 16, 2019
1 parent e180ffc commit f3eaba7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 69 deletions.
101 changes: 33 additions & 68 deletions OMEdit/OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -956,22 +956,6 @@ void LineAnnotation::updateEndPoint(QPointF point)
}
}

/*!
* \brief LineAnnotation::moveAllPoints
* Moves all the whole connection.
* \param offsetX
* \param offsetY
*/
void LineAnnotation::moveAllPoints(qreal offsetX, qreal offsetY)
{
prepareGeometryChange();
for(int i = 0 ; i < mPoints.size() ; i++) {
mPoints[i] = QPointF(mPoints[i].x() + offsetX, mPoints[i].y() + offsetY);
/* updated the corresponding CornerItem */
updateCornerItem(i);
}
}

/*!
* \brief LineAnnotation::updateTransitionTextPosition
* Updates the position of the transition text.
Expand Down Expand Up @@ -1161,67 +1145,48 @@ QVariant LineAnnotation::itemChange(GraphicsItemChange change, const QVariant &v

/*!
* \brief LineAnnotation::handleComponentMoved
* If the component associated with the connection is moved then update the connection accordingly.\n
* If the both start and end components associated with the connection are moved then move whole connection.
* If the component associated with the connection is moved then update the connection accordingly.
*/
void LineAnnotation::handleComponentMoved()
{
if (mPoints.size() < 2) {
return;
}
prepareGeometryChange();
if (mpStartComponent && mpStartComponent->getRootParentComponent()->isSelected() &&
mpEndComponent && mpEndComponent->getRootParentComponent()->isSelected()) {
if (mLineType == LineAnnotation::TransitionType) {
QPointF centerPos = mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()));
QRectF sceneRectF = mpStartComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
centerPos.x(), centerPos.y(),
mPoints.at(1).x(), mPoints.at(1).y());
moveAllPoints(mpGraphicsView->roundPoint(newPos.at(1)).x() - mPoints[0].x(),
mpGraphicsView->roundPoint(newPos.at(1)).y() - mPoints[0].y());
updateTransitionTextPosition();
} else {
moveAllPoints(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()).x() - mPoints[0].x(),
mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()).y() - mPoints[0].y());
}
} else {
if (mpStartComponent) {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpStartComponent->getRootParentComponent()) {
updateStartPoint(mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center())));
if (mLineType == LineAnnotation::TransitionType) {
QRectF sceneRectF = mpStartComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
mPoints.at(0).x(), mPoints.at(0).y(),
mPoints.at(1).x(), mPoints.at(1).y());
updateStartPoint(mpGraphicsView->roundPoint(newPos.at(1)));
updateTransitionTextPosition();
} else if (mLineType == LineAnnotation::InitialStateType) {
QRectF sceneRectF = mpStartComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
mPoints.at(0).x(), mPoints.at(0).y(),
mPoints.at(1).x(), mPoints.at(1).y());
updateStartPoint(mpGraphicsView->roundPoint(newPos.at(1)));
}
if (mpStartComponent) {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpStartComponent->getRootParentComponent()) {
updateStartPoint(mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center())));
if (mLineType == LineAnnotation::TransitionType) {
QRectF sceneRectF = mpStartComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
mPoints.at(0).x(), mPoints.at(0).y(),
mPoints.at(1).x(), mPoints.at(1).y());
updateStartPoint(mpGraphicsView->roundPoint(newPos.at(1)));
updateTransitionTextPosition();
} else if (mLineType == LineAnnotation::InitialStateType) {
QRectF sceneRectF = mpStartComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
mPoints.at(0).x(), mPoints.at(0).y(),
mPoints.at(1).x(), mPoints.at(1).y());
updateStartPoint(mpGraphicsView->roundPoint(newPos.at(1)));
}
}
if (mpEndComponent) {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpEndComponent->getRootParentComponent()) {
updateEndPoint(mpGraphicsView->roundPoint(mpEndComponent->mapToScene(mpEndComponent->boundingRect().center())));
if (mLineType == LineAnnotation::TransitionType) {
QRectF sceneRectF = mpEndComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
mPoints.at(mPoints.size() - 2).x(), mPoints.at(mPoints.size() - 2).y(),
mPoints.at(mPoints.size() - 1).x(), mPoints.at(mPoints.size() - 1).y());
updateEndPoint(mpGraphicsView->roundPoint(newPos.at(0)));
updateTransitionTextPosition();
}
}
if (mpEndComponent) {
Component *pComponent = qobject_cast<Component*>(sender());
if (pComponent == mpEndComponent->getRootParentComponent()) {
updateEndPoint(mpGraphicsView->roundPoint(mpEndComponent->mapToScene(mpEndComponent->boundingRect().center())));
if (mLineType == LineAnnotation::TransitionType) {
QRectF sceneRectF = mpEndComponent->sceneBoundingRect();
QList<QPointF> newPos = Utilities::liangBarskyClipper(sceneRectF.topLeft().x(), sceneRectF.topLeft().y(),
sceneRectF.bottomRight().x(), sceneRectF.bottomRight().y(),
mPoints.at(mPoints.size() - 2).x(), mPoints.at(mPoints.size() - 2).y(),
mPoints.at(mPoints.size() - 1).x(), mPoints.at(mPoints.size() - 1).y());
updateEndPoint(mpGraphicsView->roundPoint(newPos.at(0)));
updateTransitionTextPosition();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -95,7 +95,6 @@ class LineAnnotation : public ShapeAnnotation
void clearPoints();
void updateStartPoint(QPointF point);
void updateEndPoint(QPointF point);
void moveAllPoints(qreal offsetX, qreal offsetY);
void updateTransitionTextPosition();
void setLineType(LineType lineType) {mLineType = lineType;}
LineType getLineType() {return mLineType;}
Expand Down

0 comments on commit f3eaba7

Please sign in to comment.