Improve object alias validation.

Property browser not correctly validates an object alias.
This commit is contained in:
Roman Telezhynskyi 2020-11-21 15:44:55 +02:00
parent 8aea612202
commit c31966145e
4 changed files with 19 additions and 9 deletions

View File

@ -502,14 +502,17 @@ QString VAbstractSpline::GetAliasSuffix() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractSpline::SetAliasSuffix(const QString &alias) void VAbstractSpline::SetAliasSuffix(QString alias)
{ {
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(m_id); QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(m_id);
const QString oldAliasSuffix = curve->GetAliasSuffix(); const QString oldAliasSuffix = curve->GetAliasSuffix();
alias = alias.simplified().replace(QChar(QChar::Space), QChar('_'));
curve->SetAliasSuffix(alias); curve->SetAliasSuffix(alias);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) QRegularExpression rx(NameRegExp());
if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias())))
{ {
QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve); QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve);
SaveOption(obj); SaveOption(obj);

View File

@ -97,7 +97,7 @@ public:
quint32 GetDuplicate() const; quint32 GetDuplicate() const;
QString GetAliasSuffix() const; QString GetAliasSuffix() const;
void SetAliasSuffix(const QString &alias); void SetAliasSuffix(QString alias);
virtual void GroupVisibility(quint32 object, bool visible) override; virtual void GroupVisibility(quint32 object, bool visible) override;
public slots: public slots:

View File

@ -42,6 +42,7 @@
#include "../../../../vabstracttool.h" #include "../../../../vabstracttool.h"
#include "../../../vdrawtool.h" #include "../../../vdrawtool.h"
#include "../vtoolsinglepoint.h" #include "../vtoolsinglepoint.h"
#include "../qmuparser/qmudef.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VToolCut::VToolCut(const VToolCutInitData &initData, QGraphicsItem *parent) VToolCut::VToolCut(const VToolCutInitData &initData, QGraphicsItem *parent)
@ -108,14 +109,17 @@ QString VToolCut::GetAliasSuffix1() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolCut::SetAliasSuffix1(const QString &alias) void VToolCut::SetAliasSuffix1(QString alias)
{ {
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId); QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId);
const QString oldAliasSuffix = curve->GetAliasSuffix(); const QString oldAliasSuffix = curve->GetAliasSuffix();
alias = alias.simplified().replace(QChar(QChar::Space), QChar('_'));
curve->SetAliasSuffix(alias); curve->SetAliasSuffix(alias);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) QRegularExpression rx(NameRegExp());
if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias())))
{ {
m_aliasSuffix1 = alias; m_aliasSuffix1 = alias;
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
@ -134,14 +138,17 @@ QString VToolCut::GetAliasSuffix2() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolCut::SetAliasSuffix2(const QString &alias) void VToolCut::SetAliasSuffix2(QString alias)
{ {
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId); QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(baseCurveId);
const QString oldAliasSuffix = curve->GetAliasSuffix(); const QString oldAliasSuffix = curve->GetAliasSuffix();
alias = alias.simplified().replace(QChar(QChar::Space), QChar('_'));
curve->SetAliasSuffix(alias); curve->SetAliasSuffix(alias);
if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) QRegularExpression rx(NameRegExp());
if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias())))
{ {
m_aliasSuffix2 = alias; m_aliasSuffix2 = alias;
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);

View File

@ -69,10 +69,10 @@ public:
void SetFormulaLength(const VFormula &value); void SetFormulaLength(const VFormula &value);
QString GetAliasSuffix1() const; QString GetAliasSuffix1() const;
void SetAliasSuffix1(const QString &alias); void SetAliasSuffix1(QString alias);
QString GetAliasSuffix2() const; QString GetAliasSuffix2() const;
void SetAliasSuffix2(const QString &alias); void SetAliasSuffix2(QString alias);
QString CurveName() const; QString CurveName() const;