Alias field for tool Arc with length.

This commit is contained in:
Roman Telezhynskyi 2020-11-04 17:36:40 +02:00
parent 1246aba24d
commit 7542fc5dc2
10 changed files with 97 additions and 5 deletions

View File

@ -1359,6 +1359,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolArcWithLength(VPE::VProperty *pr
case 61: // AttrNotes
SetNotes<VToolArcWithLength>(property);
break;
case 62: // AttrAlias
SetAlias<VToolArcWithLength>(property);
break;
default:
qWarning()<<"Unknown property type. id = "<<id;
break;
@ -2491,6 +2494,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolArcWithLength(QGraphicsItem *it
AddPropertyFormula(tr("Radius:"), i->GetFormulaRadius(), AttrRadius);
AddPropertyFormula(tr("First angle:"), i->GetFormulaF1(), AttrAngle1);
AddPropertyFormula(tr("Length:"), i->GetFormulaLength(), AttrLength);
AddPropertyAlias(i, tr("Alias:"));
AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics());
AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor);
AddPropertyApproximationScale(tr("Approximation scale:"), i->GetApproximationScale());
@ -3088,6 +3092,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArcWithLength()
{
auto *i = qgraphicsitem_cast<VToolArcWithLength *>(currentItem);
idToProperty[AttrName]->setValue(i->name());
QVariant valueRadius;
valueRadius.setValue(i->GetFormulaRadius());
idToProperty[AttrRadius]->setValue(valueRadius);
@ -3119,6 +3125,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArcWithLength()
idToProperty[AttrAScale]->setValue(valueApproximationScale);
idToProperty[AttrNotes]->setValue(i->GetNotes());
idToProperty[AttrAlias]->setValue(i->GetAliasSuffix());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -3182,6 +3182,7 @@ void VPattern::ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &do
initData.color = GetParametrString(domElement, AttrColor, ColorBlack);
initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine);
initData.approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0'));
initData.aliasSuffix = GetParametrEmptyString(domElement, AttrAlias);
VToolArcWithLength::Create(initData);
//Rewrite attribute formula. Need for situation when we have wrong formula.

View File

@ -266,6 +266,12 @@ quint32 VContainer::AddGObject(const QSharedPointer<VGObject> &obj)
}
uniqueNames[d->nspace].insert(obj->name());
if (not obj->GetAlias().isEmpty())
{
uniqueNames[d->nspace].insert(obj->GetAlias());
}
const quint32 id = getNextId();
obj->setId(id);

View File

@ -403,6 +403,11 @@ void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
SCASSERT(not obj.isNull())
UpdateObject(id, obj);
uniqueNames[d->nspace].insert(obj->name());
if (not obj->GetAlias().isEmpty())
{
uniqueNames[d->nspace].insert(obj->GetAlias());
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -123,7 +123,7 @@ DialogArc::DialogArc(const VContainer *data, quint32 toolId, QWidget *parent)
connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArc::DeployF1TextEdit);
connect(ui->pushButtonGrowLengthF2, &QPushButton::clicked, this, &DialogArc::DeployF2TextEdit);
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogArc::GetAliasSuffix);
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogArc::ValidateAlias);
vis = new VisToolArc(data);

View File

@ -47,6 +47,7 @@
#include "../vmisc/vcommonsettings.h"
#include "../../visualization/visualization.h"
#include "ui_dialogarcwithlength.h"
#include "../vgeometry/varc.h"
//---------------------------------------------------------------------------------------------------------------------
DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent)
@ -115,6 +116,8 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId,
connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArcWithLength::DeployF1TextEdit);
connect(ui->pushButtonGrowLengthArcLength, &QPushButton::clicked, this, &DialogArcWithLength::DeployLengthTextEdit);
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogArcWithLength::ValidateAlias);
vis = new VisToolArcWithLength(data);
ui->tabWidget->setCurrentIndex(0);
@ -263,6 +266,19 @@ QString DialogArcWithLength::GetNotes() const
return ui->plainTextEditToolNotes->toPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::SetAliasSuffix(const QString &alias)
{
ui->lineEditAlias->setText(alias);
ValidateAlias();
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetAliasSuffix() const
{
return ui->lineEditAlias->text();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type)
{
@ -374,6 +390,25 @@ void DialogArcWithLength::closeEvent(QCloseEvent *event)
DialogTool::closeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::ValidateAlias()
{
VArc arc;
arc.SetAliasSuffix(GetAliasSuffix());
if (not GetAliasSuffix().isEmpty() && not data->IsUnique(arc.GetAlias()))
{
flagAlias = false;
ChangeColor(ui->labelAlias, errorColor);
}
else
{
flagAlias = true;
ChangeColor(ui->labelAlias, OkColor(this));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::Radius()
{

View File

@ -74,6 +74,9 @@ public:
void SetNotes(const QString &notes);
QString GetNotes() const;
void SetAliasSuffix(const QString &alias);
QString GetAliasSuffix() const;
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/**
@ -96,6 +99,9 @@ protected:
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private slots:
void ValidateAlias();
private:
Q_DISABLE_COPY(DialogArcWithLength)
Ui::DialogArcWithLength *ui;
@ -108,6 +114,8 @@ private:
bool flagLength;
bool flagAlias{true};
/** @brief timerRadius timer of check formula of radius */
QTimer *timerRadius;
@ -137,7 +145,7 @@ private:
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogArcWithLength::IsValid() const
{
return flagRadius && flagF1 && flagLength;
return flagRadius && flagF1 && flagLength && flagAlias;
}
#endif // DIALOGARCWITHLENGTH_H

View File

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

View File

@ -505,9 +505,19 @@ QString VAbstractSpline::GetAliasSuffix() const
void VAbstractSpline::SetAliasSuffix(const QString &alias)
{
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(m_id);
const QString oldAliasSuffix = curve->GetAliasSuffix();
curve->SetAliasSuffix(alias);
QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve);
SaveOption(obj);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias()))
{
QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve);
SaveOption(obj);
}
else
{
curve->SetAliasSuffix(oldAliasSuffix);
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -84,6 +84,7 @@ void VToolArcWithLength::setDialog()
dialogTool->SetPenStyle(arc->GetPenStyle());
dialogTool->SetApproximationScale(arc->GetApproximationScale());
dialogTool->SetNotes(m_notes);
dialogTool->SetAliasSuffix(arc->GetAliasSuffix());
}
//---------------------------------------------------------------------------------------------------------------------
@ -108,6 +109,7 @@ VToolArcWithLength *VToolArcWithLength::Create(const QPointer<DialogTool> &dialo
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
initData.notes = dialogTool->GetNotes();
initData.aliasSuffix = dialogTool->GetAliasSuffix();
VToolArcWithLength* point = Create(initData);
if (point != nullptr)
@ -131,6 +133,7 @@ VToolArcWithLength *VToolArcWithLength::Create(VToolArcWithLengthInitData &initD
arc->SetColor(initData.color);
arc->SetPenStyle(initData.penStyle);
arc->SetApproximationScale(initData.approximationScale);
arc->SetAliasSuffix(initData.aliasSuffix);
if (initData.typeCreation == Source::FromGui)
{
@ -317,6 +320,8 @@ void VToolArcWithLength::SaveDialog(QDomElement &domElement, QList<quint32> &old
doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor());
doc->SetAttribute(domElement, AttrPenStyle, dialogTool->GetPenStyle());
doc->SetAttribute(domElement, AttrAScale, dialogTool->GetApproximationScale());
doc->SetAttributeOrRemoveIf(domElement, AttrAlias, dialogTool->GetAliasSuffix(),
dialogTool->GetAliasSuffix().isEmpty());
const QString notes = dialogTool->GetNotes();
doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty());
@ -377,6 +382,6 @@ QString VToolArcWithLength::MakeToolTip() const
.arg(arc->GetStartAngle())
.arg(tr("End angle"))
.arg(arc->GetEndAngle())
.arg(tr("Label"), arc->name());
.arg(tr("Label"), arc->ObjectName());
return toolTip;
}