diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index ca9f1b4bb..04a005118 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -82,19 +82,18 @@ Q_LOGGING_CATEGORY(vDialog, "v.dialog") namespace { //--------------------------------------------------------------------------------------------------------------------- -quint32 RowId(QListWidget *listWidget, int i) +VPieceNode RowNode(QListWidget *listWidget, int i) { SCASSERT(listWidget != nullptr); if (i < 0 || i >= listWidget->count()) { - return NULL_ID; + return VPieceNode(); } const QListWidgetItem *rowItem = listWidget->item(i); SCASSERT(rowItem != nullptr); - const VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); - return rowNode.GetId(); + return qvariant_cast(rowItem->data(Qt::UserRole)); } } @@ -506,29 +505,56 @@ int DialogTool::FindNotExcludedNodeUp(QListWidget *listWidget, int candidate) } //--------------------------------------------------------------------------------------------------------------------- -bool DialogTool::FirstPointEqualLast(QListWidget *listWidget) +bool DialogTool::FirstPointEqualLast(QListWidget *listWidget, const VContainer *data) { SCASSERT(listWidget != nullptr); if (listWidget->count() > 1) { - const quint32 topId = RowId(listWidget, FindNotExcludedNodeDown(listWidget, 0)); - const quint32 bottomId = RowId(listWidget, FindNotExcludedNodeUp(listWidget, listWidget->count()-1)); - return topId == bottomId; + const VPieceNode topNode = RowNode(listWidget, FindNotExcludedNodeDown(listWidget, 0)); + const VPieceNode bottomNode = RowNode(listWidget, FindNotExcludedNodeUp(listWidget, listWidget->count()-1)); + + QSharedPointer firstPoint; + if (topNode.GetTypeTool() == Tool::NodePoint) + { + firstPoint = data->GeometricObject(topNode.GetId()); + } + + QSharedPointer secondPoint; + if (bottomNode.GetTypeTool() == Tool::NodePoint) + { + secondPoint = data->GeometricObject(bottomNode.GetId()); + } + + return topNode.GetId() == bottomNode.GetId() || (not firstPoint.isNull() && not secondPoint.isNull() + && firstPoint->toQPointF() == secondPoint->toQPointF()); } return false; } //--------------------------------------------------------------------------------------------------------------------- -bool DialogTool::DoublePoints(QListWidget *listWidget) +bool DialogTool::DoublePoints(QListWidget *listWidget, const VContainer *data) { SCASSERT(listWidget != nullptr); for (int i=0, sz = listWidget->count()-1; i firstPoint; + if (firstNode.GetTypeTool() == Tool::NodePoint) + { + firstPoint = data->GeometricObject(firstNode.GetId()); + } + + QSharedPointer secondPoint; + if (secondNode.GetTypeTool() == Tool::NodePoint) + { + secondPoint = data->GeometricObject(secondNode.GetId()); + } + + if (firstNode.GetId() == secondNode.GetId() || (not firstPoint.isNull() && not secondPoint.isNull() + && firstPoint->toQPointF() == secondPoint->toQPointF())) { return true; } @@ -650,7 +676,7 @@ void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node) } else { - if(RowId(listWidget, listWidget->count()-1) != node.GetId()) + if(RowNode(listWidget, listWidget->count()-1).GetId() != node.GetId()) { canAddNewPoint = true; } diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index e7f7b5879..0a03f694e 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -272,8 +272,8 @@ protected: static int FindNotExcludedNodeDown(QListWidget *listWidget, int candidate); static int FindNotExcludedNodeUp(QListWidget *listWidget, int candidate); - static bool FirstPointEqualLast(QListWidget *listWidget); - static bool DoublePoints(QListWidget *listWidget); + static bool FirstPointEqualLast(QListWidget *listWidget, const VContainer *data); + static bool DoublePoints(QListWidget *listWidget, const VContainer *data); static bool EachPointLabelIsUnique(QListWidget *listWidget); static QString DialogWarningIcon(); static QFont NodeFont(bool nodeExcluded); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp index 8694e63a0..feb521b54 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp @@ -1251,13 +1251,13 @@ bool DialogPiecePath::PathIsValid() const } else { - if (GetType() == PiecePathType::CustomSeamAllowance && FirstPointEqualLast(ui->listWidget)) + if (GetType() == PiecePathType::CustomSeamAllowance && FirstPointEqualLast(ui->listWidget, data)) { url += tr("First point of custom seam allowance cannot be equal to the last point!"); ui->helpLabel->setText(url); return false; } - else if (DoublePoints(ui->listWidget)) + else if (DoublePoints(ui->listWidget, data)) { url += tr("You have double points!"); ui->helpLabel->setText(url); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index af64a6951..f1ee8fe3f 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -2381,13 +2381,13 @@ bool DialogSeamAllowance::MainPathIsValid() const uiTabPaths->helpLabel->setText(url); valid = false; } - if (FirstPointEqualLast(uiTabPaths->listWidgetMainPath)) + if (FirstPointEqualLast(uiTabPaths->listWidgetMainPath, data)) { url += tr("First point cannot be equal to the last point!"); uiTabPaths->helpLabel->setText(url); valid = false; } - else if (DoublePoints(uiTabPaths->listWidgetMainPath)) + else if (DoublePoints(uiTabPaths->listWidgetMainPath, data)) { url += tr("You have double points!"); uiTabPaths->helpLabel->setText(url);