diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index cc49e6f97..9a838b9bd 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -88,6 +88,8 @@ #include #include #include +#include +#include #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #include @@ -3003,16 +3005,58 @@ void MainWindow::FullParseFile() qCDebug(vMainWindow, "Full parsing file"); toolOptions->ClearPropertyBrowser(); + QFuture futureTestUniqueId; + + auto WaitForFutureFinish = [](QFuture &futureTestUniqueId) + { + try + { + futureTestUniqueId.waitForFinished(); + } + catch (...) + { + // ignore + } + }; + try { + if (qApp->getOpeningPattern()) + { + futureTestUniqueId = QtConcurrent::run(static_cast(doc), &VDomDocument::TestUniqueId); + } + SetEnabledGUI(true); doc->Parse(Document::FullParse); + + if (qApp->getOpeningPattern()) + { + futureTestUniqueId.waitForFinished(); + } } catch (const VExceptionUndo &e) { Q_UNUSED(e) /* If user want undo last operation before undo we need finish broken redo operation. For those we post event * myself. Later in method customEvent call undo.*/ + if (qApp->getOpeningPattern()) + { + try + { + futureTestUniqueId.waitForFinished(); + } + catch (const VExceptionWrongId &e) + { + qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + SetEnabledGUI(false); + if (not VApplication::IsGUIMode()) + { + qApp->exit(V_EX_DATAERR); + } + return; + } + } QApplication::postEvent(this, new UndoEvent()); return; } @@ -3021,6 +3065,10 @@ void MainWindow::FullParseFile() qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")), //-V807 qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); SetEnabledGUI(false); + if (qApp->getOpeningPattern()) + { + WaitForFutureFinish(futureTestUniqueId); + } if (not VApplication::IsGUIMode()) { qApp->exit(V_EX_DATAERR); @@ -3032,6 +3080,10 @@ void MainWindow::FullParseFile() qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value.")), qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); SetEnabledGUI(false); + if (qApp->getOpeningPattern()) + { + WaitForFutureFinish(futureTestUniqueId); + } if (not VApplication::IsGUIMode()) { qApp->exit(V_EX_DATAERR); @@ -3043,6 +3095,10 @@ void MainWindow::FullParseFile() qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")), qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); SetEnabledGUI(false); + if (qApp->getOpeningPattern()) + { + WaitForFutureFinish(futureTestUniqueId); + } if (not VApplication::IsGUIMode()) { qApp->exit(V_EX_DATAERR); @@ -3054,6 +3110,10 @@ void MainWindow::FullParseFile() qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")), qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); SetEnabledGUI(false); + if (qApp->getOpeningPattern()) + { + WaitForFutureFinish(futureTestUniqueId); + } if (not VApplication::IsGUIMode()) { qApp->exit(V_EX_DATAERR); @@ -3065,6 +3125,10 @@ void MainWindow::FullParseFile() qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")), qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); SetEnabledGUI(false); + if (qApp->getOpeningPattern()) + { + WaitForFutureFinish(futureTestUniqueId); + } if (not VApplication::IsGUIMode()) { qApp->exit(V_EX_DATAERR); @@ -3075,6 +3139,10 @@ void MainWindow::FullParseFile() { qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc)."))); SetEnabledGUI(false); + if (qApp->getOpeningPattern()) + { + WaitForFutureFinish(futureTestUniqueId); + } if (not VApplication::IsGUIMode()) { qApp->exit(V_EX_DATAERR); @@ -4566,9 +4634,6 @@ 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) @@ -4578,6 +4643,10 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) if (guiEnabled) { // No errors occurred + /* Collect garbage only after successfully parse. This way wrongly accused items have one more time to restore + * a reference. */ + doc->GarbageCollector(true); + patternReadOnly = doc->IsReadOnly(); SetEnableWidgets(true); setCurrentFile(fileName); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 2c3d58f1a..0701d5829 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -4239,7 +4239,6 @@ void VPattern::PrepareForParse(const Document &parse) SCASSERT(sceneDetail != nullptr) if (parse == Document::FullParse) { - TestUniqueId(); RefreshElementIdCache(); sceneDraw->clear(); sceneDraw->InitOrigins(); diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 623f1f442..564d6c500 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -134,12 +134,12 @@ public: QVector GetLabelTemplate(const QDomElement &element) const; void SetLabelTemplate(QDomElement &element, const QVector &lines); + void TestUniqueId() const; + protected: bool setTagText(const QString &tag, const QString &text); bool setTagText(const QDomElement &domElement, const QString &text); QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; - - void TestUniqueId() const; void CollectId(const QDomElement &node, QVector &vector)const; protected slots: