Fix alias validation bug.

This commit is contained in:
Roman Telezhynskyi 2020-11-07 11:18:13 +02:00
parent 061c9b502a
commit 3feddb9ce9
21 changed files with 307 additions and 110 deletions

View File

@ -244,7 +244,8 @@ QString DialogArc::GetNotes() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArc::SetAliasSuffix(const QString &alias) void DialogArc::SetAliasSuffix(const QString &alias)
{ {
ui->lineEditAlias->setText(alias); originAliasSuffix = alias;
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
} }
@ -361,7 +362,8 @@ void DialogArc::ValidateAlias()
VArc arc; VArc arc;
arc.SetAliasSuffix(GetAliasSuffix()); arc.SetAliasSuffix(GetAliasSuffix());
if (not GetAliasSuffix().isEmpty() && if (not GetAliasSuffix().isEmpty() &&
(not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) (not rx.match(arc.GetAlias()).hasMatch() ||
(originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);

View File

@ -146,6 +146,8 @@ private:
qreal angleF1; qreal angleF1;
qreal angleF2; qreal angleF2;
QString originAliasSuffix{};
void EvalRadius(); void EvalRadius();
void EvalF(); void EvalF();
}; };

View File

@ -270,7 +270,8 @@ QString DialogArcWithLength::GetNotes() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetAliasSuffix(const QString &alias) void DialogArcWithLength::SetAliasSuffix(const QString &alias)
{ {
ui->lineEditAlias->setText(alias); originAliasSuffix = alias;
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
} }
@ -398,7 +399,8 @@ void DialogArcWithLength::ValidateAlias()
VArc arc; VArc arc;
arc.SetAliasSuffix(GetAliasSuffix()); arc.SetAliasSuffix(GetAliasSuffix());
if (not GetAliasSuffix().isEmpty() && if (not GetAliasSuffix().isEmpty() &&
(not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) (not rx.match(arc.GetAlias()).hasMatch() ||
(originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);

View File

@ -137,6 +137,8 @@ private:
int formulaBaseHeightF1; int formulaBaseHeightF1;
int formulaBaseHeightLength; int formulaBaseHeightLength;
QString originAliasSuffix{};
void Radius(); void Radius();
void Length(); void Length();
void EvalF(); void EvalF();

View File

@ -109,7 +109,8 @@ void DialogCubicBezier::SetSpline(const VCubicBezier &spline)
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name())); ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
ui->doubleSpinBoxApproximationScale->setValue(spl.GetApproximationScale()); ui->doubleSpinBoxApproximationScale->setValue(spl.GetApproximationScale());
ui->lineEditAlias->setText(spl.GetAliasSuffix()); originAliasSuffix = spl.GetAliasSuffix();
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
auto path = qobject_cast<VisToolCubicBezier *>(vis); auto path = qobject_cast<VisToolCubicBezier *>(vis);
@ -270,7 +271,8 @@ void DialogCubicBezier::ValidateAlias()
VCubicBezier spline = spl; VCubicBezier spline = spl;
spline.SetAliasSuffix(ui->lineEditAlias->text()); spline.SetAliasSuffix(ui->lineEditAlias->text());
if (not ui->lineEditAlias->text().isEmpty() && if (not ui->lineEditAlias->text().isEmpty() &&
(not rx.match(spline.GetAlias()).hasMatch() || not data->IsUnique(spline.GetAlias()))) (not rx.match(spline.GetAlias()).hasMatch() ||
(originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(spline.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);

View File

@ -83,6 +83,8 @@ private:
bool flagError; bool flagError;
bool flagAlias{true}; bool flagAlias{true};
QString originAliasSuffix{};
const QSharedPointer<VPointF> GetP1() const; const QSharedPointer<VPointF> GetP1() const;
const QSharedPointer<VPointF> GetP2() const; const QSharedPointer<VPointF> GetP2() const;
const QSharedPointer<VPointF> GetP3() const; const QSharedPointer<VPointF> GetP3() const;

View File

@ -115,7 +115,8 @@ void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value)
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name()));
ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale()); ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale());
ui->lineEditAlias->setText(path.GetAliasSuffix()); originAliasSuffix = path.GetAliasSuffix();
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle()); ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle());
@ -259,7 +260,8 @@ void DialogCubicBezierPath::ValidateAlias()
VCubicBezierPath tempPath = path; VCubicBezierPath tempPath = path;
tempPath.SetAliasSuffix(ui->lineEditAlias->text()); tempPath.SetAliasSuffix(ui->lineEditAlias->text());
if (not ui->lineEditAlias->text().isEmpty() && if (not ui->lineEditAlias->text().isEmpty() &&
(not rx.match(tempPath.GetAlias()).hasMatch() || not data->IsUnique(tempPath.GetAlias()))) (not rx.match(tempPath.GetAlias()).hasMatch() ||
(originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(tempPath.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);

View File

@ -83,6 +83,8 @@ private:
bool flagError; bool flagError;
bool flagAlias{true}; bool flagAlias{true};
QString originAliasSuffix{};
void NewItem(const VPointF &point); void NewItem(const VPointF &point);
void DataPoint(const VPointF &p); void DataPoint(const VPointF &p);
void SavePath(); void SavePath();

View File

@ -209,46 +209,37 @@ void DialogCutArc::ArcChanged()
void DialogCutArc::ValidateAlias() void DialogCutArc::ValidateAlias()
{ {
QRegularExpression rx(NameRegExp()); QRegularExpression rx(NameRegExp());
VArc arc1; VArc arc1;
arc1.SetAliasSuffix(GetAliasSuffix1()); arc1.SetAliasSuffix(GetAliasSuffix1());
if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(arc1.GetAlias()).hasMatch() || not data->IsUnique(arc1.GetAlias())))
{
flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor);
}
else
{
flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this));
}
VArc arc2; VArc arc2;
arc2.SetAliasSuffix(GetAliasSuffix2()); arc2.SetAliasSuffix(GetAliasSuffix2());
if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(arc2.GetAlias()))
{
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this));
}
if (arc1.GetAlias() == arc2.GetAlias()) if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(arc1.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(arc1.GetAlias())) ||
arc1.GetAlias() == arc2.GetAlias()))
{ {
flagAlias1 = false; flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor); ChangeColor(ui->labelAlias1, errorColor);
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
} }
else else
{ {
flagAlias1 = true; flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this)); ChangeColor(ui->labelAlias1, OkColor(this));
}
if (not GetAliasSuffix2().isEmpty() &&
(not rx.match(arc2.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(arc2.GetAlias())) ||
arc1.GetAlias() == arc2.GetAlias()))
{
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true; flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this)); ChangeColor(ui->labelAlias2, OkColor(this));
} }
@ -338,7 +329,8 @@ QString DialogCutArc::GetNotes() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::SetAliasSuffix1(const QString &alias) void DialogCutArc::SetAliasSuffix1(const QString &alias)
{ {
ui->lineEditAlias1->setText(alias); originAliasSuffix1 = alias;
ui->lineEditAlias1->setText(originAliasSuffix1);
ValidateAlias(); ValidateAlias();
} }
@ -351,7 +343,8 @@ QString DialogCutArc::GetAliasSuffix1() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::SetAliasSuffix2(const QString &alias) void DialogCutArc::SetAliasSuffix2(const QString &alias)
{ {
ui->lineEditAlias2->setText(alias); originAliasSuffix2 = alias;
ui->lineEditAlias2->setText(originAliasSuffix2);
ValidateAlias(); ValidateAlias();
} }

View File

@ -110,6 +110,9 @@ private:
bool flagName; bool flagName;
bool flagAlias1{true}; bool flagAlias1{true};
bool flagAlias2{true}; bool flagAlias2{true};
QString originAliasSuffix1{};
QString originAliasSuffix2{};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -216,46 +216,37 @@ void DialogCutSpline::SplineChanged()
void DialogCutSpline::ValidateAlias() void DialogCutSpline::ValidateAlias()
{ {
QRegularExpression rx(NameRegExp()); QRegularExpression rx(NameRegExp());
VSpline spl1; VSpline spl1;
spl1.SetAliasSuffix(GetAliasSuffix1()); spl1.SetAliasSuffix(GetAliasSuffix1());
if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(spl1.GetAlias()).hasMatch() || not data->IsUnique(spl1.GetAlias())))
{
flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor);
}
else
{
flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this));
}
VSpline spl2; VSpline spl2;
spl2.SetAliasSuffix(GetAliasSuffix2()); spl2.SetAliasSuffix(GetAliasSuffix2());
if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(spl2.GetAlias()))
{
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this));
}
if (spl1.GetAlias() == spl2.GetAlias()) if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(spl1.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) ||
spl1.GetAlias() == spl2.GetAlias()))
{ {
flagAlias1 = false; flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor); ChangeColor(ui->labelAlias1, errorColor);
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
} }
else else
{ {
flagAlias1 = true; flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this)); ChangeColor(ui->labelAlias1, OkColor(this));
}
if (not GetAliasSuffix2().isEmpty() &&
(not rx.match(spl2.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(spl2.GetAlias())) ||
spl1.GetAlias() == spl2.GetAlias()))
{
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true; flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this)); ChangeColor(ui->labelAlias2, OkColor(this));
} }
@ -338,7 +329,8 @@ QString DialogCutSpline::GetNotes() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SetAliasSuffix1(const QString &alias) void DialogCutSpline::SetAliasSuffix1(const QString &alias)
{ {
ui->lineEditAlias1->setText(alias); originAliasSuffix1 = alias;
ui->lineEditAlias1->setText(originAliasSuffix1);
ValidateAlias(); ValidateAlias();
} }
@ -351,7 +343,8 @@ QString DialogCutSpline::GetAliasSuffix1() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SetAliasSuffix2(const QString &alias) void DialogCutSpline::SetAliasSuffix2(const QString &alias)
{ {
ui->lineEditAlias2->setText(alias); originAliasSuffix2 = alias;
ui->lineEditAlias2->setText(originAliasSuffix2);
ValidateAlias(); ValidateAlias();
} }

View File

@ -109,6 +109,9 @@ private:
bool flagName; bool flagName;
bool flagAlias1{true}; bool flagAlias1{true};
bool flagAlias2{true}; bool flagAlias2{true};
QString originAliasSuffix1{};
QString originAliasSuffix2{};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -216,46 +216,37 @@ void DialogCutSplinePath::SplinePathChanged()
void DialogCutSplinePath::ValidateAlias() void DialogCutSplinePath::ValidateAlias()
{ {
QRegularExpression rx(NameRegExp()); QRegularExpression rx(NameRegExp());
VSplinePath path1; VSplinePath path1;
path1.SetAliasSuffix(GetAliasSuffix1()); path1.SetAliasSuffix(GetAliasSuffix1());
if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(path1.GetAlias()).hasMatch() || not data->IsUnique(path1.GetAlias())))
{
flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor);
}
else
{
flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this));
}
VSplinePath path2; VSplinePath path2;
path2.SetAliasSuffix(GetAliasSuffix2()); path2.SetAliasSuffix(GetAliasSuffix2());
if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(path2.GetAlias()))
{
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this));
}
if (path1.GetAlias() == path2.GetAlias()) if (not GetAliasSuffix1().isEmpty() &&
(not rx.match(path1.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(path1.GetAlias())) ||
path1.GetAlias() == path2.GetAlias()))
{ {
flagAlias1 = false; flagAlias1 = false;
ChangeColor(ui->labelAlias1, errorColor); ChangeColor(ui->labelAlias1, errorColor);
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
} }
else else
{ {
flagAlias1 = true; flagAlias1 = true;
ChangeColor(ui->labelAlias1, OkColor(this)); ChangeColor(ui->labelAlias1, OkColor(this));
}
if (not GetAliasSuffix2().isEmpty() &&
(not rx.match(path2.GetAlias()).hasMatch() ||
(originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(path2.GetAlias())) ||
path1.GetAlias() == path2.GetAlias()))
{
flagAlias2 = false;
ChangeColor(ui->labelAlias2, errorColor);
}
else
{
flagAlias2 = true; flagAlias2 = true;
ChangeColor(ui->labelAlias2, OkColor(this)); ChangeColor(ui->labelAlias2, OkColor(this));
} }
@ -338,7 +329,8 @@ QString DialogCutSplinePath::GetNotes() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::SetAliasSuffix1(const QString &alias) void DialogCutSplinePath::SetAliasSuffix1(const QString &alias)
{ {
ui->lineEditAlias1->setText(alias); originAliasSuffix1 = alias;
ui->lineEditAlias1->setText(originAliasSuffix1);
ValidateAlias(); ValidateAlias();
} }
@ -351,7 +343,8 @@ QString DialogCutSplinePath::GetAliasSuffix1() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::SetAliasSuffix2(const QString &alias) void DialogCutSplinePath::SetAliasSuffix2(const QString &alias)
{ {
ui->lineEditAlias2->setText(alias); originAliasSuffix2 = alias;
ui->lineEditAlias2->setText(originAliasSuffix2);
ValidateAlias(); ValidateAlias();
} }

View File

@ -108,6 +108,9 @@ private:
bool flagName; bool flagName;
bool flagAlias1{true}; bool flagAlias1{true};
bool flagAlias2{true}; bool flagAlias2{true};
QString originAliasSuffix1{};
QString originAliasSuffix2{};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -603,7 +603,8 @@ void DialogEllipticalArc::ValidateAlias()
VEllipticalArc arc; VEllipticalArc arc;
arc.SetAliasSuffix(GetAliasSuffix()); arc.SetAliasSuffix(GetAliasSuffix());
if (not GetAliasSuffix().isEmpty() && if (not GetAliasSuffix().isEmpty() &&
(not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) (not rx.match(arc.GetAlias()).hasMatch() ||
(originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);
@ -632,7 +633,8 @@ QString DialogEllipticalArc::GetNotes() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::SetAliasSuffix(const QString &alias) void DialogEllipticalArc::SetAliasSuffix(const QString &alias)
{ {
ui->lineEditAlias->setText(alias); originAliasSuffix = alias;
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
} }

View File

@ -173,6 +173,8 @@ private:
qreal angleF2; qreal angleF2;
qreal angleRotation; qreal angleRotation;
QString originAliasSuffix{};
void EvalRadiuses(); void EvalRadiuses();
void EvalAngles(); void EvalAngles();
}; };

View File

@ -64,7 +64,6 @@
DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, quint32 toolId, QWidget *parent) DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent), : DialogTool(data, toolId, parent),
ui(new Ui::DialogFlippingByAxis), ui(new Ui::DialogFlippingByAxis),
objects(),
stage1(true), stage1(true),
m_suffix(), m_suffix(),
flagName(true), flagName(true),
@ -87,6 +86,9 @@ DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, quint32 toolI
connect(ui->comboBoxOriginPoint, &QComboBox::currentTextChanged, connect(ui->comboBoxOriginPoint, &QComboBox::currentTextChanged,
this, &DialogFlippingByAxis::PointChanged); this, &DialogFlippingByAxis::PointChanged);
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogFlippingByAxis::ShowSourceDetails);
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogFlippingByAxis::AliasChanged);
vis = new VisToolFlippingByAxis(data); vis = new VisToolFlippingByAxis(data);
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
@ -147,12 +149,6 @@ void DialogFlippingByAxis::SetSuffix(const QString &value)
ui->lineEditSuffix->setText(value); ui->lineEditSuffix->setText(value);
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> DialogFlippingByAxis::GetObjects() const
{
return ConvertToVector(objects);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogFlippingByAxis::GetVisibilityGroupName() const QString DialogFlippingByAxis::GetVisibilityGroupName() const
{ {
@ -201,7 +197,7 @@ void DialogFlippingByAxis::ShowDialog(bool click)
{ {
if (stage1 && not click) if (stage1 && not click)
{ {
if (objects.isEmpty()) if (sourceObjects.isEmpty())
{ {
return; return;
} }
@ -214,7 +210,7 @@ void DialogFlippingByAxis::ShowDialog(bool click)
VisToolFlippingByAxis *operation = qobject_cast<VisToolFlippingByAxis *>(vis); VisToolFlippingByAxis *operation = qobject_cast<VisToolFlippingByAxis *>(vis);
SCASSERT(operation != nullptr) SCASSERT(operation != nullptr)
operation->SetObjects(ConvertToVector(objects)); operation->SetObjects(SourceToObjects(sourceObjects));
operation->VisualMode(); operation->VisualMode();
scene->ToggleArcSelection(false); scene->ToggleArcSelection(false);
@ -229,6 +225,8 @@ void DialogFlippingByAxis::ShowDialog(bool click)
qApp->getSceneView()->AllowRubberBand(false); qApp->getSceneView()->AllowRubberBand(false);
FillSourceList();
emit ToolTip(tr("Select origin point")); emit ToolTip(tr("Select origin point"));
} }
else if (not stage1 && prepare && click) else if (not stage1 && prepare && click)
@ -240,6 +238,19 @@ void DialogFlippingByAxis::ShowDialog(bool click)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<SourceItem> DialogFlippingByAxis::GetSourceObjects() const
{
return sourceObjects;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::SetSourceObjects(const QVector<SourceItem> &value)
{
sourceObjects = value;
FillSourceList();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type) void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type)
{ {
@ -247,7 +258,10 @@ void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (type == SceneObject::Point) if (type == SceneObject::Point)
{ {
if (objects.contains(id)) auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(),
[id](const SourceItem &sItem) { return sItem.id == id; });
if (obj != sourceObjects.end())
{ {
emit ToolTip(tr("Select origin point that is not part of the list of objects")); emit ToolTip(tr("Select origin point that is not part of the list of objects"));
return; return;
@ -272,16 +286,23 @@ void DialogFlippingByAxis::SelectedObject(bool selected, quint32 object, quint32
Q_UNUSED(tool) Q_UNUSED(tool)
if (stage1) if (stage1)
{ {
auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(),
[object](const SourceItem &sItem) { return sItem.id == object; });
if (selected) if (selected)
{ {
if (not objects.contains(object)) if (obj == sourceObjects.cend())
{ {
objects.append(object); SourceItem item;
item.id = object;
sourceObjects.append(item);
} }
} }
else else
{ {
objects.removeOne(object); if (obj != sourceObjects.end())
{
sourceObjects.erase(obj);
}
} }
} }
} }
@ -297,6 +318,7 @@ void DialogFlippingByAxis::SuffixChanged()
{ {
flagName = false; flagName = false;
ChangeColor(ui->labelSuffix, errorColor); ChangeColor(ui->labelSuffix, errorColor);
ui->labelStatus->setText(tr("Invalid suffix"));
CheckState(); CheckState();
return; return;
} }
@ -313,6 +335,7 @@ void DialogFlippingByAxis::SuffixChanged()
{ {
flagName = false; flagName = false;
ChangeColor(ui->labelSuffix, errorColor); ChangeColor(ui->labelSuffix, errorColor);
ui->labelStatus->setText(tr("Invalid suffix"));
CheckState(); CheckState();
return; return;
} }
@ -337,6 +360,7 @@ void DialogFlippingByAxis::GroupNameChanged()
{ {
flagGroupName = false; flagGroupName = false;
ChangeColor(ui->labelGroupName, errorColor); ChangeColor(ui->labelGroupName, errorColor);
ui->labelStatus->setText(tr("Invalid group name"));
CheckState(); CheckState();
return; return;
} }
@ -347,6 +371,63 @@ void DialogFlippingByAxis::GroupNameChanged()
CheckState(); CheckState();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::ShowSourceDetails(int row)
{
ui->lineEditAlias->setDisabled(true);
if (ui->listWidget->count() == 0)
{
return;
}
const auto sourceItem = qvariant_cast<SourceItem>(ui->listWidget->item(row)->data(Qt::UserRole));
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
ui->labelAlias->setText(obj->getType() == GOType::Point ? tr("Label:") : tr("Alias:"));
ui->lineEditAlias->blockSignals(true);
ui->lineEditAlias->setText(sourceItem.alias);
ui->lineEditAlias->setEnabled(true);
ui->lineEditAlias->blockSignals(false);
QRegularExpression rx(NameRegExp());
if (not rx.match(sourceItem.alias).hasMatch() || not data->IsUnique(sourceItem.alias))
{
flagAlias = false;
ChangeColor(ui->labelAlias, errorColor);
ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias"));
CheckState();
return;
}
else
{
flagAlias = true;
ChangeColor(ui->labelAlias, errorColor);
CheckState();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::AliasChanged(const QString &text)
{
if (ui->listWidget->count() == 0)
{
return;
}
if (auto *item = ui->listWidget->currentItem())
{
auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
sourceItem.alias = text;
item->setData(Qt::UserRole, QVariant::fromValue(sourceItem));
ValidateSourceAliases();
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::ShowVisualization() void DialogFlippingByAxis::ShowVisualization()
{ {
@ -358,10 +439,22 @@ void DialogFlippingByAxis::SaveData()
{ {
m_suffix = ui->lineEditSuffix->text(); m_suffix = ui->lineEditSuffix->text();
sourceObjects.clear();
sourceObjects.reserve(ui->listWidget->count());
for (int i=0; i<ui->listWidget->count(); ++i)
{
if (const QListWidgetItem *item = ui->listWidget->item(i))
{
auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
sourceObjects.append(sourceItem);
}
}
VisToolFlippingByAxis *operation = qobject_cast<VisToolFlippingByAxis *>(vis); VisToolFlippingByAxis *operation = qobject_cast<VisToolFlippingByAxis *>(vis);
SCASSERT(operation != nullptr) SCASSERT(operation != nullptr)
operation->SetObjects(ConvertToVector(objects)); operation->SetObjects(SourceToObjects(sourceObjects));
operation->SetOriginPointId(GetOriginPointId()); operation->SetOriginPointId(GetOriginPointId());
operation->SetAxisType(GetAxisType()); operation->SetAxisType(GetAxisType());
operation->RefreshGeometry(); operation->RefreshGeometry();
@ -383,9 +476,13 @@ void DialogFlippingByAxis::SaveData()
void DialogFlippingByAxis::PointChanged() void DialogFlippingByAxis::PointChanged()
{ {
QColor color; QColor color;
if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint))) quint32 id = getCurrentObjectId(ui->comboBoxOriginPoint);
auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(),
[id](const SourceItem &sItem) { return sItem.id == id; });
if (obj != sourceObjects.end())
{ {
flagError = false; flagError = false;
ui->labelStatus->setText(tr("Invalid point"));
color = errorColor; color = errorColor;
} }
else else
@ -406,6 +503,73 @@ void DialogFlippingByAxis::FillComboBoxAxisType(QComboBox *box)
box->addItem(tr("Horizontal axis"), QVariant(static_cast<int>(AxisType::HorizontalAxis))); box->addItem(tr("Horizontal axis"), QVariant(static_cast<int>(AxisType::HorizontalAxis)));
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::FillSourceList()
{
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
int row = -1;
for (auto &sourceItem : sourceObjects)
{
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
auto *item = new QListWidgetItem(obj->ObjectName());
item->setToolTip(obj->ObjectName());
item->setData(Qt::UserRole, QVariant::fromValue(sourceItem));
ui->listWidget->insertItem(++row, item);
}
ui->listWidget->blockSignals(false);
if (ui->listWidget->count() > 0)
{
ui->listWidget->setCurrentRow(0);
}
ValidateSourceAliases();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::ValidateSourceAliases()
{
QRegularExpression rx(NameRegExp());
for (int i=0; i<ui->listWidget->count(); ++i)
{
if (const QListWidgetItem *item = ui->listWidget->item(i))
{
auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
QString name;
if (obj->getType() == GOType::Point)
{
name = sourceItem.alias;
}
else
{
const QString oldAlias = obj->GetAliasSuffix();
obj->SetAliasSuffix(sourceItem.alias);
name = obj->GetAlias();
obj->SetAliasSuffix(oldAlias);
}
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
{
flagAlias = false;
ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias"));
CheckState();
return;
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::SetNotes(const QString &notes) void DialogFlippingByAxis::SetNotes(const QString &notes)
{ {
@ -417,3 +581,16 @@ QString DialogFlippingByAxis::GetNotes() const
{ {
return ui->plainTextEditToolNotes->toPlainText(); return ui->plainTextEditToolNotes->toPlainText();
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogFlippingByAxis::IsValid() const
{
bool ready = flagError && flagName && flagGroupName && flagAlias;
if (ready)
{
ui->labelStatus->setText(tr("Ready"));
}
return ready;
}

View File

@ -439,10 +439,13 @@ void DialogSpline::EvalLength2()
void DialogSpline::ValidateAlias() void DialogSpline::ValidateAlias()
{ {
QRegularExpression rx(NameRegExp()); QRegularExpression rx(NameRegExp());
VSpline spline = spl; VSpline spline = spl;
spline.SetAliasSuffix(ui->lineEditAlias->text()); spline.SetAliasSuffix(ui->lineEditAlias->text());
if (not ui->lineEditAlias->text().isEmpty() && if (not ui->lineEditAlias->text().isEmpty() &&
(not rx.match(spline.GetAlias()).hasMatch() || not data->IsUnique(spline.GetAlias()))) (not rx.match(spline.GetAlias()).hasMatch() ||
(originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(spline.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);
@ -613,7 +616,8 @@ void DialogSpline::SetSpline(const VSpline &spline)
ui->plainTextEditLength2F->setPlainText(length2F); ui->plainTextEditLength2F->setPlainText(length2F);
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name())); ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
ui->lineEditAlias->setText(spl.GetAliasSuffix()); originAliasSuffix = spl.GetAliasSuffix();
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
auto path = qobject_cast<VisToolSpline *>(vis); auto path = qobject_cast<VisToolSpline *>(vis);

View File

@ -121,6 +121,8 @@ private:
bool flagError; bool flagError;
bool flagAlias{true}; bool flagAlias{true};
QString originAliasSuffix{};
const QSharedPointer<VPointF> GetP1() const; const QSharedPointer<VPointF> GetP1() const;
const QSharedPointer<VPointF> GetP4() const; const QSharedPointer<VPointF> GetP4() const;

View File

@ -170,7 +170,8 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name()));
ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale()); ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale());
ui->lineEditAlias->setText(path.GetAliasSuffix()); originAliasSuffix = path.GetAliasSuffix();
ui->lineEditAlias->setText(originAliasSuffix);
ValidateAlias(); ValidateAlias();
ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle()); ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle());
@ -500,10 +501,13 @@ void DialogSplinePath::FXLength2()
void DialogSplinePath::ValidateAlias() void DialogSplinePath::ValidateAlias()
{ {
QRegularExpression rx(NameRegExp()); QRegularExpression rx(NameRegExp());
VSplinePath tempPath = path; VSplinePath tempPath = path;
tempPath.SetAliasSuffix(ui->lineEditAlias->text()); tempPath.SetAliasSuffix(ui->lineEditAlias->text());
if (not ui->lineEditAlias->text().isEmpty() && if (not ui->lineEditAlias->text().isEmpty() &&
(not rx.match(tempPath.GetAlias()).hasMatch() || not data->IsUnique(tempPath.GetAlias()))) (not rx.match(tempPath.GetAlias()).hasMatch() ||
(originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(tempPath.GetAlias()))))
{ {
flagAlias = false; flagAlias = false;
ChangeColor(ui->labelAlias, errorColor); ChangeColor(ui->labelAlias, errorColor);

View File

@ -115,6 +115,8 @@ private:
bool flagError; bool flagError;
bool flagAlias{true}; bool flagAlias{true};
QString originAliasSuffix{};
void EvalAngle1(); void EvalAngle1();
void EvalAngle2(); void EvalAngle2();
void EvalLength1(); void EvalLength1();