From 42ed025afa0a9c6cbd0f509dbddca8e55cc136d6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 30 May 2020 18:14:50 +0300 Subject: [PATCH] Fix validation of Curved path tool. Closes smart-pattern/valentina#41. --- .../dialogs/tools/dialogcubicbezierpath.cpp | 86 +++++++++++-------- .../dialogs/tools/dialogcubicbezierpath.h | 1 + 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index 428317032..47d30cdaa 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -121,6 +121,8 @@ void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value) { ui->listWidget->setCurrentRow(0); } + + ValidatePath(); } //--------------------------------------------------------------------------------------------------------------------- @@ -219,7 +221,6 @@ void DialogCubicBezierPath::PointChanged(int row) void DialogCubicBezierPath::currentPointChanged(int index) { const quint32 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); - QColor color; try { @@ -228,50 +229,16 @@ void DialogCubicBezierPath::currentPointChanged(int index) DataPoint(*point); item->setData(Qt::UserRole, QVariant::fromValue(*point)); - if (not IsPathValid()) - { - flagError = false; - color = errorColor; - - ui->lineEditSplPathName->setText(tr("Invalid spline path")); - } - else - { - flagError = true; - color = OkColor(this); - - auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); - auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); - - if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id()) - { - newDuplicate = -1; - ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); - } - else - { - VCubicBezierPath newPath = ExtractPath(); - - if (not data->IsUnique(newPath.name())) - { - newDuplicate = static_cast(DNumber(newPath.name())); - newPath.SetDuplicate(static_cast(newDuplicate)); - } - - ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); - } - } + ValidatePath(); } catch (const VExceptionBadId &) { flagError = false; - color = errorColor; + ChangeColor(ui->labelName, errorColor); + ChangeColor(ui->labelPoint, errorColor); ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id)); } - - ChangeColor(ui->labelName, color); - ChangeColor(ui->labelPoint, color); CheckState(); } @@ -350,3 +317,46 @@ VCubicBezierPath DialogCubicBezierPath::ExtractPath() const } return VCubicBezierPath(points); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ValidatePath() +{ + QColor color; + + if (not IsPathValid()) + { + flagError = false; + color = errorColor; + + ui->lineEditSplPathName->setText(tr("Invalid spline path")); + } + else + { + flagError = true; + color = OkColor(this); + + auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); + auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); + + if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id()) + { + newDuplicate = -1; + ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); + } + else + { + VCubicBezierPath newPath = ExtractPath(); + + if (not data->IsUnique(newPath.name())) + { + newDuplicate = static_cast(DNumber(newPath.name())); + newPath.SetDuplicate(static_cast(newDuplicate)); + } + + ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); + } + } + + ChangeColor(ui->labelName, color); + ChangeColor(ui->labelPoint, color); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h index f8fb418f9..00c9e946b 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h @@ -84,6 +84,7 @@ private: QSet AllPathBackboneIds() const; bool IsPathValid() const; VCubicBezierPath ExtractPath() const; + void ValidatePath(); }; //---------------------------------------------------------------------------------------------------------------------