From ad23a75d7a7e7c4a67612a2ce5e6e89ae440bcd0 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 23 Mar 2017 19:36:50 +0200 Subject: [PATCH] Check if all points in a path are unique. Because in some valid cases the same geometric point can be included in a path several times we must force user to create unique point for each case. This happens because we determine each point by point id. --HG-- branch : feature --- .../vtools/dialogs/tools/dialogpiecepath.cpp | 6 ++++++ src/libs/vtools/dialogs/tools/dialogtool.cpp | 21 +++++++++++++++++++ src/libs/vtools/dialogs/tools/dialogtool.h | 1 + .../tools/piece/dialogseamallowance.cpp | 6 ++++++ 4 files changed, 34 insertions(+) diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index 4ba8ed87f..3aade7598 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -889,6 +889,12 @@ bool DialogPiecePath::PathIsValid() const ui->helpLabel->setText(url); return false; } + else if (not EachPointLabelIsUnique(ui->listWidget)) + { + url += tr("Each point in the path must be unique!"); + ui->helpLabel->setText(url); + return false; + } } if (not m_showMode && ui->comboBoxPiece->count() <= 0) diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 25d4b5348..6783fb793 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -522,6 +522,27 @@ bool DialogTool::DoublePoints(QListWidget *listWidget) return false; } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogTool::EachPointLabelIsUnique(QListWidget *listWidget) +{ + SCASSERT(listWidget != nullptr); + QSet pointLabels; + int countPoints = 0; + for (int i=0; i < listWidget->count(); ++i) + { + const QListWidgetItem *rowItem = listWidget->item(i); + SCASSERT(rowItem != nullptr); + const VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + if (rowNode.GetTypeTool() == Tool::NodePoint) + { + ++countPoints; + pointLabels.insert(rowNode.GetId()); + } + } + + return countPoints == pointLabels.size(); +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogTool::DialogWarningIcon() { diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index a60ca0fff..4dd5f124b 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -270,6 +270,7 @@ protected: static int FindNotExcludedNodeUp(QListWidget *listWidget, int candidate); static bool FirstPointEqualLast(QListWidget *listWidget); static bool DoublePoints(QListWidget *listWidget); + static bool EachPointLabelIsUnique(QListWidget *listWidget); static QString DialogWarningIcon(); static QFont NodeFont(bool nodeExcluded); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index b1060eb01..1a14450f3 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -2029,6 +2029,12 @@ bool DialogSeamAllowance::MainPathIsValid() const uiTabPaths->helpLabel->setText(url); valid = false; } + else if (not EachPointLabelIsUnique(uiTabPaths->listWidgetMainPath)) + { + url += tr("Each point in the path must be unique!"); + uiTabPaths->helpLabel->setText(url); + valid = false; + } } if (valid)