Fix validation of Curved path tool. Closes smart-pattern/valentina#41.

This commit is contained in:
Roman Telezhynskyi 2020-05-30 18:14:50 +03:00
parent 590e0089da
commit 42ed025afa
2 changed files with 49 additions and 38 deletions

View File

@ -121,6 +121,8 @@ void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value)
{ {
ui->listWidget->setCurrentRow(0); ui->listWidget->setCurrentRow(0);
} }
ValidatePath();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -219,7 +221,6 @@ void DialogCubicBezierPath::PointChanged(int row)
void DialogCubicBezierPath::currentPointChanged(int index) void DialogCubicBezierPath::currentPointChanged(int index)
{ {
const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index)); const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index));
QColor color;
try try
{ {
@ -228,50 +229,16 @@ void DialogCubicBezierPath::currentPointChanged(int index)
DataPoint(*point); DataPoint(*point);
item->setData(Qt::UserRole, QVariant::fromValue(*point)); item->setData(Qt::UserRole, QVariant::fromValue(*point));
if (not IsPathValid()) ValidatePath();
{
flagError = false;
color = errorColor;
ui->lineEditSplPathName->setText(tr("Invalid spline path"));
}
else
{
flagError = true;
color = OkColor(this);
auto first = qvariant_cast<VPointF>(ui->listWidget->item(0)->data(Qt::UserRole));
auto last = qvariant_cast<VPointF>(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<qint32>(DNumber(newPath.name()));
newPath.SetDuplicate(static_cast<quint32>(newDuplicate));
}
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name()));
}
}
} }
catch (const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
flagError = false; flagError = false;
color = errorColor; ChangeColor(ui->labelName, errorColor);
ChangeColor(ui->labelPoint, errorColor);
ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id)); ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id));
} }
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelPoint, color);
CheckState(); CheckState();
} }
@ -350,3 +317,46 @@ VCubicBezierPath DialogCubicBezierPath::ExtractPath() const
} }
return VCubicBezierPath(points); 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<VPointF>(ui->listWidget->item(0)->data(Qt::UserRole));
auto last = qvariant_cast<VPointF>(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<qint32>(DNumber(newPath.name()));
newPath.SetDuplicate(static_cast<quint32>(newDuplicate));
}
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name()));
}
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelPoint, color);
}

View File

@ -84,6 +84,7 @@ private:
QSet<quint32> AllPathBackboneIds() const; QSet<quint32> AllPathBackboneIds() const;
bool IsPathValid() const; bool IsPathValid() const;
VCubicBezierPath ExtractPath() const; VCubicBezierPath ExtractPath() const;
void ValidatePath();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------