Alias field for tool Cubic Bezier.

This commit is contained in:
Roman Telezhynskyi 2020-11-04 14:34:22 +02:00
parent c77d4c9bd2
commit a5f65c319c
9 changed files with 66 additions and 3 deletions

View file

@ -2050,6 +2050,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCubicBezier(VPE::VProperty *prop
case 61: // AttrNotes case 61: // AttrNotes
SetNotes<VToolCubicBezier>(property); SetNotes<VToolCubicBezier>(property);
break; break;
case 62: // AttrAlias
SetAlias<VToolCubicBezier>(property);
break;
case 55: // AttrPoint1 (read only) case 55: // AttrPoint1 (read only)
case 56: // AttrPoint2 (read only) case 56: // AttrPoint2 (read only)
case 57: // AttrPoint3 (read only) case 57: // AttrPoint3 (read only)
@ -2824,6 +2827,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCubicBezier(QGraphicsItem *item
AddPropertyParentPointName(i->SecondPointName(), tr("Second point:"), AttrPoint2); AddPropertyParentPointName(i->SecondPointName(), tr("Second point:"), AttrPoint2);
AddPropertyParentPointName(i->ThirdPointName(), tr("Third point:"), AttrPoint3); AddPropertyParentPointName(i->ThirdPointName(), tr("Third point:"), AttrPoint3);
AddPropertyParentPointName(i->ForthPointName(), tr("Fourth point:"), AttrPoint4); AddPropertyParentPointName(i->ForthPointName(), tr("Fourth point:"), AttrPoint4);
AddPropertyAlias(i, tr("Alias:"));
AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics());
AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor);
AddPropertyApproximationScale(tr("Approximation scale:"), i->getSpline().GetApproximationScale()); AddPropertyApproximationScale(tr("Approximation scale:"), i->getSpline().GetApproximationScale());
@ -3655,6 +3659,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezier()
idToProperty[AttrAScale]->setValue(valueApproximationScale); idToProperty[AttrAScale]->setValue(valueApproximationScale);
idToProperty[AttrNotes]->setValue(i->GetNotes()); idToProperty[AttrNotes]->setValue(i->GetNotes());
idToProperty[AttrAlias]->setValue(i->GetAliasSuffix());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -2618,6 +2618,7 @@ void VPattern::ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement
const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine);
const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, QChar('0')); const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, QChar('0'));
const qreal approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0')); const qreal approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0'));
const QString alias = GetParametrEmptyString(domElement, AttrAlias);
auto p1 = data->GeometricObject<VPointF>(point1); auto p1 = data->GeometricObject<VPointF>(point1);
auto p2 = data->GeometricObject<VPointF>(point2); auto p2 = data->GeometricObject<VPointF>(point2);
@ -2633,6 +2634,7 @@ void VPattern::ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement
initData.spline->SetPenStyle(penStyle); initData.spline->SetPenStyle(penStyle);
initData.spline->SetPenStyle(penStyle); initData.spline->SetPenStyle(penStyle);
initData.spline->SetApproximationScale(approximationScale); initData.spline->SetApproximationScale(approximationScale);
initData.spline->SetAliasSuffix(alias);
VToolCubicBezier::Create(initData); VToolCubicBezier::Create(initData);
} }

View file

@ -475,7 +475,8 @@ QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const
{ {
name += QString("_%1").arg(GetDuplicate()); name += QString("_%1").arg(GetDuplicate());
} }
return name;
return not GetAlias().isEmpty() ? QString("%1 (%2)").arg(GetAlias(), name) : name;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -55,11 +55,21 @@ VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const V
{ {
SetValue(FromPixel(curve->GetC1Length(), patternUnit)); SetValue(FromPixel(curve->GetC1Length(), patternUnit));
SetName(c1Length_V + curve->name()); SetName(c1Length_V + curve->name());
if (not curve->GetAlias().isEmpty())
{
SetAlias(c1Length_V + curve->GetAlias());
}
} }
else else
{ {
SetValue(FromPixel(curve->GetC2Length(), patternUnit)); SetValue(FromPixel(curve->GetC2Length(), patternUnit));
SetName(c2Length_V + curve->name()); SetName(c2Length_V + curve->name());
if (not curve->GetAlias().isEmpty())
{
SetAlias(c2Length_V + curve->GetAlias());
}
} }
} }

View file

@ -72,6 +72,8 @@ DialogCubicBezier::DialogCubicBezier(const VContainer *data, quint32 toolId, QWi
connect(ui->comboBoxP4, &QComboBox::currentTextChanged, connect(ui->comboBoxP4, &QComboBox::currentTextChanged,
this, &DialogCubicBezier::PointNameChanged); this, &DialogCubicBezier::PointNameChanged);
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogCubicBezier::ValidateAlias);
vis = new VisToolCubicBezier(data); vis = new VisToolCubicBezier(data);
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
@ -106,6 +108,9 @@ 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());
ValidateAlias();
auto path = qobject_cast<VisToolCubicBezier *>(vis); auto path = qobject_cast<VisToolCubicBezier *>(vis);
SCASSERT(path != nullptr) SCASSERT(path != nullptr)
path->setApproximationScale(spl.GetApproximationScale()); path->setApproximationScale(spl.GetApproximationScale());
@ -241,6 +246,7 @@ void DialogCubicBezier::SaveData()
spl.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); spl.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value());
spl.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine)); spl.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine));
spl.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack)); spl.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack));
spl.SetAliasSuffix(ui->lineEditAlias->text());
const quint32 d = spl.GetDuplicate();//Save previous value const quint32 d = spl.GetDuplicate();//Save previous value
newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast<quint32>(newDuplicate)); newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast<quint32>(newDuplicate));
@ -256,6 +262,25 @@ void DialogCubicBezier::SaveData()
path->RefreshGeometry(); path->RefreshGeometry();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezier::ValidateAlias()
{
VCubicBezier spline = spl;
spline.SetAliasSuffix(ui->lineEditAlias->text());
if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(spline.GetAlias()))
{
flagAlias = false;
ChangeColor(ui->labelAlias, errorColor);
}
else
{
flagAlias = true;
ChangeColor(ui->labelAlias, OkColor(this));
}
CheckState();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
const QSharedPointer<VPointF> DialogCubicBezier::GetP1() const const QSharedPointer<VPointF> DialogCubicBezier::GetP1() const
{ {

View file

@ -68,6 +68,9 @@ protected:
*/ */
virtual void SaveData() override; virtual void SaveData() override;
virtual bool IsValid() const final; virtual bool IsValid() const final;
private slots:
void ValidateAlias();
private: private:
Q_DISABLE_COPY(DialogCubicBezier) Q_DISABLE_COPY(DialogCubicBezier)
Ui::DialogCubicBezier *ui; Ui::DialogCubicBezier *ui;
@ -78,6 +81,7 @@ private:
qint32 newDuplicate; qint32 newDuplicate;
bool flagError; bool flagError;
bool flagAlias{true};
const QSharedPointer<VPointF> GetP1() const; const QSharedPointer<VPointF> GetP1() const;
const QSharedPointer<VPointF> GetP2() const; const QSharedPointer<VPointF> GetP2() const;
@ -88,7 +92,7 @@ private:
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline bool DialogCubicBezier::IsValid() const inline bool DialogCubicBezier::IsValid() const
{ {
return flagError; return flagError && flagAlias;
} }
#endif // DIALOGCUBICBEZIER_H #endif // DIALOGCUBICBEZIER_H

View file

@ -154,6 +154,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0">
<widget class="QLabel" name="labelAlias">
<property name="text">
<string>Alias:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="lineEditAlias">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_2"> <widget class="QWidget" name="tab_2">

View file

@ -203,7 +203,7 @@ QString VAbstractSpline::MakeToolTip() const
"</table>") "</table>")
.arg(tr("Length")) .arg(tr("Length"))
.arg(qApp->fromPixel(curve->GetLength())) .arg(qApp->fromPixel(curve->GetLength()))
.arg(UnitsToStr(qApp->patternUnits(), true), tr("Label"), curve->name()); .arg(UnitsToStr(qApp->patternUnits(), true), tr("Label"), curve->ObjectName());
return toolTip; return toolTip;
} }

View file

@ -292,4 +292,5 @@ void VToolCubicBezier::SetSplineAttributes(QDomElement &domElement, const VCubic
doc->SetAttribute(domElement, AttrPenStyle, spl.GetPenStyle()); doc->SetAttribute(domElement, AttrPenStyle, spl.GetPenStyle());
doc->SetAttribute(domElement, AttrAScale, spl.GetApproximationScale()); doc->SetAttribute(domElement, AttrAScale, spl.GetApproximationScale());
doc->SetAttributeOrRemoveIf(domElement, AttrDuplicate, spl.GetDuplicate(), spl.GetDuplicate() <= 0); doc->SetAttributeOrRemoveIf(domElement, AttrDuplicate, spl.GetDuplicate(), spl.GetDuplicate() <= 0);
doc->SetAttributeOrRemoveIf(domElement, AttrAlias, spl.GetAliasSuffix(), spl.GetAliasSuffix().isEmpty());
} }