Collect garbage only after successfully parse. This way wrongly accused items

have one more time to restore a reference.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-05-09 18:09:40 +03:00
parent 56780fa337
commit 1158b06425
3 changed files with 18 additions and 4 deletions

View File

@ -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)

View File

@ -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();
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);