Fixed issue #905. Valentina crashes with error: This id is not unique.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2018-11-28 12:00:40 +02:00
parent 6b93b77247
commit b970f056d9
8 changed files with 37 additions and 1 deletions

View File

@ -1,5 +1,6 @@
# Version 0.6.2 (unreleased) # Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path. - [#903] Bug in tool Cut Spline path.
- [#905] Valentina crashes with error: This id is not unique.
# Version 0.6.1 October 23, 2018 # Version 0.6.1 October 23, 2018
- [#885] Regression. Broken support for multi size measurements. - [#885] Regression. Broken support for multi size measurements.

View File

@ -272,6 +272,11 @@ bool VDomDocument::find(QHash<quint32, QDomElement> &cache, const QDomElement &n
{ {
const quint32 elementId = GetParametrUInt(node, AttrId, NULL_ID_STR); 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); cache.insert(elementId, node);
if (elementId == id) if (elementId == id)
{ {
@ -596,7 +601,7 @@ void VDomDocument::CollectId(const QDomElement &node, QVector<quint32> &vector)
const quint32 id = GetParametrId(node); const quint32 id = GetParametrId(node);
if (vector.contains(id)) 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); vector.append(id);
} }

View File

@ -40,6 +40,7 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../ifc/xml/vdomdocument.h" #include "../ifc/xml/vdomdocument.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../../undocommands/addtocalc.h" #include "../../undocommands/addtocalc.h"
#include "../../undocommands/savetooloptions.h" #include "../../undocommands/savetooloptions.h"
#include "../qmuparser/qmuparsererror.h" #include "../qmuparser/qmuparsererror.h"
@ -229,6 +230,12 @@ void VDrawTool::ChangeLabelVisibility(quint32 id, bool visible)
*/ */
void VDrawTool::AddToCalculation(const QDomElement &domElement) 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); AddToCalc *addToCal = new AddToCalc(domElement, doc);
connect(addToCal, &AddToCalc::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); connect(addToCal, &AddToCalc::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
qApp->getUndoStack()->push(addToCal); qApp->getUndoStack()->push(addToCal);

View File

@ -37,6 +37,7 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../vgeometry/vgobject.h" #include "../vgeometry/vgobject.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
@ -175,6 +176,12 @@ void VAbstractNode::ToolCreation(const Source &typeCreation)
*/ */
void VAbstractNode::AddToModeling(const QDomElement &domElement) 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; QDomElement modeling;
if (m_drawName.isEmpty()) if (m_drawName.isEmpty())
{ {

View File

@ -69,6 +69,7 @@ VToolPin *VToolPin::Create(VToolPinInitData initData)
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
{ // Possible case. Parent was deleted, but the node object is still here. { // Possible case. Parent was deleted, but the node object is still here.
Q_UNUSED(e) Q_UNUSED(e)
initData.data->UpdateId(initData.id);
return nullptr;// Just ignore return nullptr;// Just ignore
} }
VPointF *pinPoint = new VPointF(*point); VPointF *pinPoint = new VPointF(*point);

View File

@ -97,6 +97,7 @@ VToolPlaceLabel *VToolPlaceLabel::Create(VToolPlaceLabelInitData &initData)
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
{ // Possible case. Parent was deleted, but the node object is still here. { // Possible case. Parent was deleted, but the node object is still here.
Q_UNUSED(e) Q_UNUSED(e)
initData.data->UpdateId(initData.id);
return nullptr;// Just ignore return nullptr;// Just ignore
} }
node->setName(point->name()); node->setName(point->name());

View File

@ -44,6 +44,7 @@
#include "../vgeometry/vsplinepath.h" #include "../vgeometry/vsplinepath.h"
#include "../vgeometry/vplacelabelitem.h" #include "../vgeometry/vplacelabelitem.h"
#include "../ifc/xml/vpatternconverter.h" #include "../ifc/xml/vpatternconverter.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../undocommands/addpiece.h" #include "../undocommands/addpiece.h"
#include "../undocommands/deletepiece.h" #include "../undocommands/deletepiece.h"
#include "../undocommands/movepiece.h" #include "../undocommands/movepiece.h"
@ -962,6 +963,12 @@ void VToolSeamAllowance::FullUpdateFromGuiApply()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::AddToFile() 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); const VPiece piece = VAbstractTool::data.GetPiece(m_id);
QDomElement domElement = doc->createElement(getTagName()); QDomElement domElement = doc->createElement(getTagName());

View File

@ -45,6 +45,7 @@
#include "../ifc/xml/vabstractconverter.h" #include "../ifc/xml/vabstractconverter.h"
#include "../ifc/xml/vdomdocument.h" #include "../ifc/xml/vdomdocument.h"
#include "../ifc/xml/vpatternconverter.h" #include "../ifc/xml/vpatternconverter.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
#include "../vgeometry/vellipticalarc.h" #include "../vgeometry/vellipticalarc.h"
#include "../vgeometry/vsplinepath.h" #include "../vgeometry/vsplinepath.h"
@ -1835,6 +1836,12 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, const VPiece &d) cons
*/ */
void VToolUnionDetails::AddToModeling(const QDomElement &domElement) 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); const QString drawName = DrawName(doc, d1id, d2id);
SCASSERT(not drawName.isEmpty()) SCASSERT(not drawName.isEmpty())