From b970f056d966ae2173286eb92f2dd2216d05bce6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 28 Nov 2018 12:00:40 +0200 Subject: [PATCH] Fixed issue #905. Valentina crashes with error: This id is not unique. --HG-- branch : release --- ChangeLog.txt | 1 + src/libs/ifc/xml/vdomdocument.cpp | 7 ++++++- src/libs/vtools/tools/drawTools/vdrawtool.cpp | 7 +++++++ src/libs/vtools/tools/nodeDetails/vabstractnode.cpp | 7 +++++++ src/libs/vtools/tools/nodeDetails/vtoolpin.cpp | 1 + src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp | 1 + src/libs/vtools/tools/vtoolseamallowance.cpp | 7 +++++++ src/libs/vtools/tools/vtooluniondetails.cpp | 7 +++++++ 8 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 53a5b5436..494bd6bc9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ # Version 0.6.2 (unreleased) - [#903] Bug in tool Cut Spline path. +- [#905] Valentina crashes with error: This id is not unique. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 0533fe49b..4841f683d 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -272,6 +272,11 @@ bool VDomDocument::find(QHash &cache, const QDomElement &n { const quint32 elementId = GetParametrUInt(node, AttrId, NULL_ID_STR); + if (cache.contains(elementId)) + { + qWarning() << tr("Not unique id (%1)").arg(elementId); + } + cache.insert(elementId, node); if (elementId == id) { @@ -596,7 +601,7 @@ void VDomDocument::CollectId(const QDomElement &node, QVector &vector) const quint32 id = GetParametrId(node); if (vector.contains(id)) { - throw VExceptionWrongId(QString("This id (%1) is not unique.").arg(id), node); + throw VExceptionWrongId(tr("This id (%1) is not unique.").arg(id), node); } vector.append(id); } diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index dcd82b5d4..654cb3037 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -40,6 +40,7 @@ #include "../ifc/ifcdef.h" #include "../ifc/xml/vdomdocument.h" #include "../ifc/xml/vabstractpattern.h" +#include "../ifc/exception/vexceptionwrongid.h" #include "../../undocommands/addtocalc.h" #include "../../undocommands/savetooloptions.h" #include "../qmuparser/qmuparsererror.h" @@ -229,6 +230,12 @@ void VDrawTool::ChangeLabelVisibility(quint32 id, bool visible) */ void VDrawTool::AddToCalculation(const QDomElement &domElement) { + const QDomElement duplicate = doc->elementById(m_id); + if (not duplicate.isNull()) + { + throw VExceptionWrongId(tr("This id (%1) is not unique.").arg(m_id), duplicate); + } + AddToCalc *addToCal = new AddToCalc(domElement, doc); connect(addToCal, &AddToCalc::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); qApp->getUndoStack()->push(addToCal); diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index 9b4db29e8..6cdcc3da5 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -37,6 +37,7 @@ #include "../ifc/ifcdef.h" #include "../ifc/xml/vabstractpattern.h" +#include "../ifc/exception/vexceptionwrongid.h" #include "../vgeometry/vgobject.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/def.h" @@ -175,6 +176,12 @@ void VAbstractNode::ToolCreation(const Source &typeCreation) */ void VAbstractNode::AddToModeling(const QDomElement &domElement) { + const QDomElement duplicate = doc->elementById(m_id); + if (not duplicate.isNull()) + { + throw VExceptionWrongId(tr("This id (%1) is not unique.").arg(m_id), duplicate); + } + QDomElement modeling; if (m_drawName.isEmpty()) { diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp index 32b42e305..201be9e06 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp @@ -69,6 +69,7 @@ VToolPin *VToolPin::Create(VToolPinInitData initData) catch (const VExceptionBadId &e) { // Possible case. Parent was deleted, but the node object is still here. Q_UNUSED(e) + initData.data->UpdateId(initData.id); return nullptr;// Just ignore } VPointF *pinPoint = new VPointF(*point); diff --git a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp index bbac16b57..c82ae5eb5 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolplacelabel.cpp @@ -97,6 +97,7 @@ VToolPlaceLabel *VToolPlaceLabel::Create(VToolPlaceLabelInitData &initData) catch (const VExceptionBadId &e) { // Possible case. Parent was deleted, but the node object is still here. Q_UNUSED(e) + initData.data->UpdateId(initData.id); return nullptr;// Just ignore } node->setName(point->name()); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 44f8f10fd..98e696dc5 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -44,6 +44,7 @@ #include "../vgeometry/vsplinepath.h" #include "../vgeometry/vplacelabelitem.h" #include "../ifc/xml/vpatternconverter.h" +#include "../ifc/exception/vexceptionwrongid.h" #include "../undocommands/addpiece.h" #include "../undocommands/deletepiece.h" #include "../undocommands/movepiece.h" @@ -962,6 +963,12 @@ void VToolSeamAllowance::FullUpdateFromGuiApply() //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AddToFile() { + const QDomElement duplicate = doc->elementById(m_id); + if (not duplicate.isNull()) + { + throw VExceptionWrongId(tr("This id (%1) is not unique.").arg(m_id), duplicate); + } + const VPiece piece = VAbstractTool::data.GetPiece(m_id); QDomElement domElement = doc->createElement(getTagName()); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index ef9b10a11..3ae47fa0f 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -45,6 +45,7 @@ #include "../ifc/xml/vabstractconverter.h" #include "../ifc/xml/vdomdocument.h" #include "../ifc/xml/vpatternconverter.h" +#include "../ifc/exception/vexceptionwrongid.h" #include "../vgeometry/varc.h" #include "../vgeometry/vellipticalarc.h" #include "../vgeometry/vsplinepath.h" @@ -1835,6 +1836,12 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, const VPiece &d) cons */ void VToolUnionDetails::AddToModeling(const QDomElement &domElement) { + const QDomElement duplicate = doc->elementById(m_id); + if (not duplicate.isNull()) + { + throw VExceptionWrongId(tr("This id (%1) is not unique.").arg(m_id), duplicate); + } + const QString drawName = DrawName(doc, d1id, d2id); SCASSERT(not drawName.isEmpty())