diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 3892d0fd8..1bffa4ea2 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4626,6 +4626,9 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) #endif FullParseFile(); + /* Collect garbage only after successfully parse. This way wrongly accused items have one more time to restore + * a reference. */ + doc->GarbageCollector(true); m_progressBar->setVisible(false); #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d70adff4f..7ea004bf4 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3343,8 +3343,10 @@ QDomElement VPattern::FindIncrement(const QString &name) const } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::GarbageCollector() +void VPattern::GarbageCollector(bool commit) { + bool cleared = false; + QDomNodeList modelingList = elementsByTagName(TagModeling); for (int i=0; i < modelingList.size(); ++i) { @@ -3366,7 +3368,11 @@ void VPattern::GarbageCollector() } else { // Parent was deleted. We do not need this object anymore - modElement.removeChild(modNode); + if (commit) + { + modElement.removeChild(modNode); + cleared = true; + } } } else @@ -3378,6 +3384,11 @@ void VPattern::GarbageCollector() } } } + + if (cleared) + { + RefreshElementIdCache(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index ac1310a1c..30fb52d9d 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -53,6 +53,8 @@ public: void Parse(const Document &parse); + void GarbageCollector(bool commit = false); + void setCurrentData(); virtual void UpdateToolData(const quint32 &id, VContainer *data) Q_DECL_OVERRIDE; VContainer GetCompleteData() const; @@ -235,8 +237,6 @@ private: QDomElement MakeEmptyIncrement(const QString &name); QDomElement FindIncrement(const QString &name) const; - void GarbageCollector(); - void NewEmptyIncrement(const QString &type, const QString &name); void NewEmptyIncrementAfter(const QString &type, const QString &after, const QString &name); void RemoveIncrement(const QString &type, const QString &name);