From 483c7a0e568bb09ffcb1ed036aca4bb0d1731e34 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 4 Sep 2014 08:20:41 +0300 Subject: [PATCH] Check if point name unique. --HG-- branch : feature --- src/app/container/vcontainer.cpp | 16 ++++++++++++++++ src/app/container/vcontainer.h | 5 +++++ src/app/widgets/vtooloptionspropertybrowser.cpp | 3 +-- src/app/xml/vpattern.cpp | 4 ++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 0e9960bd4..865c79c56 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -37,6 +37,7 @@ quint32 VContainer::_id = NULL_ID; qreal VContainer::_size = 50; qreal VContainer::_height = 176; +QSet VContainer::uniqueNames = QSet(); //--------------------------------------------------------------------------------------------------------------------- /** @@ -138,6 +139,7 @@ quint32 VContainer::AddGObject(VGObject *obj) { SCASSERT(obj != nullptr); QSharedPointer pointer(obj); + uniqueNames.insert(obj->name()); return AddObject(d->gObjects, pointer); } @@ -210,6 +212,7 @@ void VContainer::Clear() d->details.clear(); ClearVariables(); ClearGObjects(); + ClearUniqueNames(); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,6 +337,7 @@ void VContainer::UpdateGObject(quint32 id, VGObject* obj) SCASSERT(obj != nullptr); QSharedPointer pointer(obj); UpdateObject(d->gObjects, id, pointer); + uniqueNames.insert(obj->name()); } //--------------------------------------------------------------------------------------------------------------------- @@ -407,6 +411,12 @@ const QMap > VContainer::DataAngleLines() co return DataVar(VarType::LineAngle); } +//--------------------------------------------------------------------------------------------------------------------- +bool VContainer::IsUnique(const QString &name) +{ + return !uniqueNames.contains(name); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VariableExist check if exist variable this same name. @@ -442,6 +452,12 @@ void VContainer::ClearDetails() d->details.clear(); } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearUniqueNames() +{ + uniqueNames.clear(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetSize set value of size diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 08cc0fa86..18eff2599 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -37,6 +37,7 @@ #include #include +#include #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -186,6 +187,7 @@ public: } } d->variables[name] = QSharedPointer(var); + uniqueNames.insert(name); } void UpdateGObject(quint32 id, VGObject* obj); @@ -196,6 +198,7 @@ public: void ClearCalculationGObjects(); void ClearVariables(const VarType &type = VarType::Unknown); void ClearDetails(); + static void ClearUniqueNames(); void SetSize(qreal size); void SetSizeName(const QString &name); @@ -221,6 +224,7 @@ public: const QMap > DataLengthArcs() const; const QMap > DataAngleLines() const; + static bool IsUnique(const QString &name); private: /** @@ -229,6 +233,7 @@ private: static quint32 _id; static qreal _size; static qreal _height; + static QSet uniqueNames; QSharedDataPointer d; diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 8a4167768..d224da1b3 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -369,13 +369,12 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) return; } - if (name.isEmpty()) + if (name.isEmpty() || VContainer::IsUnique(name) == false) { idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } else { - //TODO check if label name is unique i->setName(name); } } diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 9142e6e4e..bbab2102d 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2326,6 +2326,10 @@ void VPattern::PrepareForParse(const Document &parse) cursor = 0; history.clear(); } + else if (parse == Document::LiteParse) + { + data->ClearUniqueNames(); + } } //---------------------------------------------------------------------------------------------------------------------