From 936a7fef075cff6b2cfe68f9c6c79641b50b7827 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 19 Feb 2016 16:34:32 +0200 Subject: [PATCH] Fixed issue #405. Crash after deleting first pattern piece in the list. --HG-- branch : develop --- ChangeLog.txt | 3 ++ src/app/valentina/xml/vpattern.cpp | 3 ++ .../undocommands/deletepatternpiece.cpp | 34 +++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index cdb2804f2..a8cf8804b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,9 @@ - New icon for VAL file. Updated Tape logo. Updated ico for standard measurements. - [#325] Check pattern for inverse compatibility. +# Version 0.4.3 +- [#405] Fixed crash after deleting first pattern piece in the list. + # Version 0.4.2 February 17, 2016 - Measurement Diagram is not shown on Mac OS X. - In dialog 'tool Spline Path' fixed broken selecting new point into the list of points. diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 7e21a3adc..077e5164b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2783,7 +2783,10 @@ void VPattern::PrepareForParse(const Document &parse) data->ClearForFullParse(); nameActivPP.clear(); patternPieces.clear(); + qDeleteAll(toolsOnRemove);//Remove all invisible on a scene objects. + toolsOnRemove.clear(); + tools.clear(); cursor = 0; history.clear(); diff --git a/src/libs/vtools/undocommands/deletepatternpiece.cpp b/src/libs/vtools/undocommands/deletepatternpiece.cpp index 65e774f1e..f7e38a19e 100644 --- a/src/libs/vtools/undocommands/deletepatternpiece.cpp +++ b/src/libs/vtools/undocommands/deletepatternpiece.cpp @@ -36,10 +36,13 @@ DeletePatternPiece::DeletePatternPiece(VAbstractPattern *doc, const QString &nam { setText(tr("delete pattern piece %1").arg(namePP)); - QDomElement patternP = doc->GetPPElement(namePP); + const QDomElement patternP = doc->GetPPElement(namePP); patternPiece = patternP.cloneNode().toElement(); - QDomNode previousPP = patternP.previousSibling();//find previous pattern piece - previousPPName = doc->GetParametrString(previousPP.toElement(), VAbstractPattern::AttrName, ""); + const QDomElement previousPP = patternP.previousSibling().toElement();//find previous pattern piece + if (not previousPP.isNull() && previousPP.tagName() == VAbstractPattern::TagDraw) + { + previousPPName = doc->GetParametrString(previousPP, VAbstractPattern::AttrName, ""); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -52,11 +55,28 @@ void DeletePatternPiece::undo() qCDebug(vUndo, "Undo."); QDomElement rootElement = doc->documentElement(); - QDomNode previousPP = doc->GetPPElement(previousPPName); - rootElement.insertAfter(patternPiece, previousPP); + + if (not previousPPName.isEmpty()) + { // not first in the list, add after tag draw + const QDomNode previousPP = doc->GetPPElement(previousPPName); + rootElement.insertAfter(patternPiece, previousPP); + } + else + { // first in the list, add after tag increments + const QDomNodeList list = rootElement.elementsByTagName(VAbstractPattern::TagIncrements); + QDomElement increment; + + if (not list.isEmpty()) + { + increment = list.at(0).toElement(); + } + + Q_ASSERT_X(not increment.isNull(), Q_FUNC_INFO, "Couldn't' find tag Increments"); + rootElement.insertAfter(patternPiece, increment); + } emit NeedFullParsing(); - doc->ChangedActivPP(namePP); + doc->ChangeActivPP(namePP); } //--------------------------------------------------------------------------------------------------------------------- @@ -65,7 +85,7 @@ void DeletePatternPiece::redo() qCDebug(vUndo, "Redo."); QDomElement rootElement = doc->documentElement(); - QDomElement patternPiece = doc->GetPPElement(namePP); + const QDomElement patternPiece = doc->GetPPElement(namePP); rootElement.removeChild(patternPiece); emit NeedFullParsing(); }