Skip to content

Commit 6ca8c1c

Browse files
committed
Fixes #3766.
Added more sanity checks. Move whole connection when both start and end components are selected.
1 parent 1ec6313 commit 6ca8c1c

File tree

3 files changed

+67
-51
lines changed

3 files changed

+67
-51
lines changed

OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,17 @@ void LineAnnotation::updateEndPoint(QPointF point)
632632
}
633633
}
634634

635+
/*!
636+
* \brief LineAnnotation::moveAllPoints
637+
* Moves all the whole connection.
638+
* \param offsetX
639+
* \param offsetY
640+
*/
635641
void LineAnnotation::moveAllPoints(qreal offsetX, qreal offsetY)
636642
{
637643
prepareGeometryChange();
638644
for(int i = 0 ; i < mPoints.size() ; i++) {
639-
mPoints[i] = QPointF(mPoints[i].x()+offsetX, mPoints[i].y()+offsetY);
645+
mPoints[i] = QPointF(mPoints[i].x() + offsetX, mPoints[i].y() + offsetY);
640646
/* updated the corresponding CornerItem */
641647
updateCornerItem(i);
642648
}
@@ -682,24 +688,31 @@ void LineAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
682688

683689
/*!
684690
* \brief LineAnnotation::handleComponentMoved
685-
* If the component associated with the connection is moved then update the connection accordingly.
691+
* If the component associated with the connection is moved then update the connection accordingly.\n
692+
* If the both start and end components associated with the connection are moved then move whole connection.
686693
*/
687694
void LineAnnotation::handleComponentMoved()
688695
{
689696
if (mPoints.size() < 2) {
690697
return;
691698
}
692699
prepareGeometryChange();
693-
if (mpStartComponent) {
694-
Component *pComponent = qobject_cast<Component*>(sender());
695-
if (pComponent == mpStartComponent->getRootParentComponent()) {
696-
updateStartPoint(mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center())));
700+
if (mpStartComponent && mpStartComponent->getRootParentComponent()->isSelected() &&
701+
mpEndComponent && mpEndComponent->getRootParentComponent()->isSelected()) {
702+
moveAllPoints(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()).x() - mPoints[0].x(),
703+
mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()).y() - mPoints[0].y());
704+
} else {
705+
if (mpStartComponent) {
706+
Component *pComponent = qobject_cast<Component*>(sender());
707+
if (pComponent == mpStartComponent->getRootParentComponent()) {
708+
updateStartPoint(mpGraphicsView->roundPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center())));
709+
}
697710
}
698-
}
699-
if (mpEndComponent) {
700-
Component *pComponent = qobject_cast<Component*>(sender());
701-
if (pComponent == mpEndComponent->getRootParentComponent()) {
702-
updateEndPoint(mpGraphicsView->roundPoint(mpEndComponent->mapToScene(mpEndComponent->boundingRect().center())));
711+
if (mpEndComponent) {
712+
Component *pComponent = qobject_cast<Component*>(sender());
713+
if (pComponent == mpEndComponent->getRootParentComponent()) {
714+
updateEndPoint(mpGraphicsView->roundPoint(mpEndComponent->mapToScene(mpEndComponent->boundingRect().center())));
715+
}
703716
}
704717
}
705718
}

OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,42 +1378,44 @@ void ShapeAnnotation::updateCornerItemPoint(int index, QPointF point)
13781378
if (dynamic_cast<LineAnnotation*>(this)) {
13791379
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
13801380
if (pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
1381-
// if moving the 2nd last point then we need to add more points after it to keep the last point manhattanized with connector
1382-
int secondLastIndex = mPoints.size() - 2;
1383-
if (index == secondLastIndex) {
1384-
// just check if additional points are really needed or not.
1385-
if ((mGeometries[secondLastIndex] == ShapeAnnotation::HorizontalLine && mPoints[index].y() != point.y()) ||
1386-
(mGeometries[secondLastIndex] == ShapeAnnotation::VerticalLine && mPoints[index].x() != point.x())) {
1387-
insertPointsGeometriesAndCornerItems(mPoints.size() - 1);
1381+
if (mPoints.size() > index) {
1382+
// if moving the 2nd last point then we need to add more points after it to keep the last point manhattanized with connector
1383+
int secondLastIndex = mPoints.size() - 2;
1384+
if (index == secondLastIndex) {
1385+
// just check if additional points are really needed or not.
1386+
if ((mGeometries[secondLastIndex] == ShapeAnnotation::HorizontalLine && mPoints[index].y() != point.y()) ||
1387+
(mGeometries[secondLastIndex] == ShapeAnnotation::VerticalLine && mPoints[index].x() != point.x())) {
1388+
insertPointsGeometriesAndCornerItems(mPoints.size() - 1);
1389+
}
13881390
}
1389-
}
1390-
// if moving the 2nd point then we need to add more points behind it to keep the first point manhattanized with connector
1391-
if (index == 1) {
1392-
// just check if additional points are really needed or not.
1393-
if ((mGeometries[0] == ShapeAnnotation::HorizontalLine && mPoints[index].y() != point.y()) ||
1394-
(mGeometries[0] == ShapeAnnotation::VerticalLine && mPoints[index].x() != point.x())) {
1395-
insertPointsGeometriesAndCornerItems(1);
1396-
index = index + 2;
1391+
// if moving the 2nd point then we need to add more points behind it to keep the first point manhattanized with connector
1392+
if (index == 1) {
1393+
// just check if additional points are really needed or not.
1394+
if ((mGeometries[0] == ShapeAnnotation::HorizontalLine && mPoints[index].y() != point.y()) ||
1395+
(mGeometries[0] == ShapeAnnotation::VerticalLine && mPoints[index].x() != point.x())) {
1396+
insertPointsGeometriesAndCornerItems(1);
1397+
index = index + 2;
1398+
}
1399+
}
1400+
qreal dx = point.x() - mPoints[index].x();
1401+
qreal dy = point.y() - mPoints[index].y();
1402+
mPoints.replace(index, point);
1403+
// update previous point
1404+
if (mGeometries.size() > index - 1 && mGeometries[index - 1] == ShapeAnnotation::HorizontalLine && mPoints.size() > index - 1) {
1405+
mPoints[index - 1] = QPointF(mPoints[index - 1].x(), mPoints[index - 1].y() + dy);
1406+
updateCornerItem(index - 1);
1407+
} else if (mGeometries.size() > index - 1 && mGeometries[index - 1] == ShapeAnnotation::VerticalLine && mPoints.size() > index - 1) {
1408+
mPoints[index - 1] = QPointF(mPoints[index - 1].x() + dx, mPoints[index - 1].y());
1409+
updateCornerItem(index - 1);
1410+
}
1411+
// update next point
1412+
if (mGeometries.size() > index && mGeometries[index] == ShapeAnnotation::HorizontalLine && mPoints.size() > index + 1) {
1413+
mPoints[index + 1] = QPointF(mPoints[index + 1].x(), mPoints[index + 1].y() + dy);
1414+
updateCornerItem(index + 1);
1415+
} else if (mGeometries.size() > index && mGeometries[index] == ShapeAnnotation::VerticalLine && mPoints.size() > index + 1) {
1416+
mPoints[index + 1] = QPointF(mPoints[index + 1].x() + dx, mPoints[index + 1].y());
1417+
updateCornerItem(index + 1);
13971418
}
1398-
}
1399-
qreal dx = point.x() - mPoints[index].x();
1400-
qreal dy = point.y() - mPoints[index].y();
1401-
mPoints.replace(index, point);
1402-
// update previous point
1403-
if (mGeometries[index - 1] == ShapeAnnotation::HorizontalLine) {
1404-
mPoints[index - 1] = QPointF(mPoints[index - 1].x(), mPoints[index - 1].y() + dy);
1405-
updateCornerItem(index - 1);
1406-
} else if (mGeometries[index - 1] == ShapeAnnotation::VerticalLine) {
1407-
mPoints[index - 1] = QPointF(mPoints[index - 1].x() + dx, mPoints[index - 1].y());
1408-
updateCornerItem(index - 1);
1409-
}
1410-
// update next point
1411-
if (mGeometries[index] == ShapeAnnotation::HorizontalLine) {
1412-
mPoints[index + 1] = QPointF(mPoints[index + 1].x(), mPoints[index + 1].y() + dy);
1413-
updateCornerItem(index + 1);
1414-
} else if (mGeometries[index] == ShapeAnnotation::VerticalLine) {
1415-
mPoints[index + 1] = QPointF(mPoints[index + 1].x() + dx, mPoints[index + 1].y());
1416-
updateCornerItem(index + 1);
14171419
}
14181420
} else {
14191421
mPoints.replace(index, point);

OMEdit/OMEditGUI/MainWindow.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,14 +2016,15 @@ void MainWindow::updateModelSwitcherMenu(QMdiSubWindow *pActivatedWindow)
20162016
}
20172017
}
20182018

2019+
/*!
2020+
* \brief MainWindow::toggleAutoSave
2021+
* Start/Stop the auto save timer based on the settings.
2022+
*/
20192023
void MainWindow::toggleAutoSave()
20202024
{
2021-
if (mpOptionsDialog->getGeneralSettingsPage()->getEnableAutoSaveGroupBox()->isChecked())
2022-
{
2023-
mpAutoSaveTimer->start(mpOptionsDialog->getGeneralSettingsPage()->getAutoSaveIntervalSpinBox()->value() * 1000);
2024-
}
2025-
else
2026-
{
2025+
if (mpOptionsDialog->getGeneralSettingsPage()->getEnableAutoSaveGroupBox()->isChecked()) {
2026+
mpAutoSaveTimer->start();
2027+
} else {
20272028
mpAutoSaveTimer->stop();
20282029
}
20292030
}

0 commit comments

Comments
 (0)