Perform test for unique id after parsing.

In most cases this is very rare issue. Many checs will cover this case anyway.
Instead of wait we will perform check when calculation done.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-11-17 14:59:45 +02:00
parent f44484a364
commit bac4e0872b
3 changed files with 74 additions and 6 deletions

View File

@ -88,6 +88,8 @@
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QProgressBar> #include <QProgressBar>
#include <QGlobalStatic> #include <QGlobalStatic>
#include <QFuture>
#include <QtConcurrent>
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
#include <QWinTaskbarButton> #include <QWinTaskbarButton>
@ -3003,51 +3005,45 @@ void MainWindow::FullParseFile()
qCDebug(vMainWindow, "Full parsing file"); qCDebug(vMainWindow, "Full parsing file");
toolOptions->ClearPropertyBrowser(); toolOptions->ClearPropertyBrowser();
QFuture<void> futureTestUniqueId;
auto WaitForFutureFinish = [](QFuture<void> &futureTestUniqueId)
{
try try
{ {
futureTestUniqueId.waitForFinished();
}
catch (...)
{
// ignore
}
};
try
{
if (qApp->getOpeningPattern())
{
futureTestUniqueId = QtConcurrent::run(static_cast<VDomDocument *>(doc), &VDomDocument::TestUniqueId);
}
SetEnabledGUI(true); SetEnabledGUI(true);
doc->Parse(Document::FullParse); doc->Parse(Document::FullParse);
if (qApp->getOpeningPattern())
{
futureTestUniqueId.waitForFinished();
}
} }
catch (const VExceptionUndo &e) catch (const VExceptionUndo &e)
{ {
Q_UNUSED(e) Q_UNUSED(e)
/* If user want undo last operation before undo we need finish broken redo operation. For those we post event /* 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.*/ * myself. Later in method customEvent call undo.*/
QApplication::postEvent(this, new UndoEvent()); if (qApp->getOpeningPattern())
return;
}
catch (const VExceptionObjectError &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")), //-V807 try
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false);
if (not VApplication::IsGUIMode())
{ {
qApp->exit(V_EX_DATAERR); futureTestUniqueId.waitForFinished();
}
return;
}
catch (const VExceptionConversionError &e)
{
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 (not VApplication::IsGUIMode())
{
qApp->exit(V_EX_DATAERR);
}
return;
}
catch (const VExceptionEmptyParameter &e)
{
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false);
if (not VApplication::IsGUIMode())
{
qApp->exit(V_EX_DATAERR);
}
return;
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
@ -3060,11 +3056,79 @@ void MainWindow::FullParseFile()
} }
return; return;
} }
}
QApplication::postEvent(this, new UndoEvent());
return;
}
catch (const VExceptionObjectError &e)
{
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);
}
return;
}
catch (const VExceptionConversionError &e)
{
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);
}
return;
}
catch (const VExceptionEmptyParameter &e)
{
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);
}
return;
}
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 (qApp->getOpeningPattern())
{
WaitForFutureFinish(futureTestUniqueId);
}
if (not VApplication::IsGUIMode())
{
qApp->exit(V_EX_DATAERR);
}
return;
}
catch (VException &e) catch (VException &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error parsing file.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
if (qApp->getOpeningPattern())
{
WaitForFutureFinish(futureTestUniqueId);
}
if (not VApplication::IsGUIMode()) if (not VApplication::IsGUIMode())
{ {
qApp->exit(V_EX_DATAERR); qApp->exit(V_EX_DATAERR);
@ -3075,6 +3139,10 @@ void MainWindow::FullParseFile()
{ {
qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc)."))); qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Error parsing file (std::bad_alloc).")));
SetEnabledGUI(false); SetEnabledGUI(false);
if (qApp->getOpeningPattern())
{
WaitForFutureFinish(futureTestUniqueId);
}
if (not VApplication::IsGUIMode()) if (not VApplication::IsGUIMode())
{ {
qApp->exit(V_EX_DATAERR); qApp->exit(V_EX_DATAERR);
@ -4566,9 +4634,6 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
#endif #endif
FullParseFile(); 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); m_progressBar->setVisible(false);
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #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) if (guiEnabled)
{ // No errors occurred { // 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(); patternReadOnly = doc->IsReadOnly();
SetEnableWidgets(true); SetEnableWidgets(true);
setCurrentFile(fileName); setCurrentFile(fileName);

View File

@ -4239,7 +4239,6 @@ void VPattern::PrepareForParse(const Document &parse)
SCASSERT(sceneDetail != nullptr) SCASSERT(sceneDetail != nullptr)
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
TestUniqueId();
RefreshElementIdCache(); RefreshElementIdCache();
sceneDraw->clear(); sceneDraw->clear();
sceneDraw->InitOrigins(); sceneDraw->InitOrigins();

View File

@ -134,12 +134,12 @@ public:
QVector<VLabelTemplateLine> GetLabelTemplate(const QDomElement &element) const; QVector<VLabelTemplateLine> GetLabelTemplate(const QDomElement &element) const;
void SetLabelTemplate(QDomElement &element, const QVector<VLabelTemplateLine> &lines); void SetLabelTemplate(QDomElement &element, const QVector<VLabelTemplateLine> &lines);
void TestUniqueId() const;
protected: protected:
bool setTagText(const QString &tag, const QString &text); bool setTagText(const QString &tag, const QString &text);
bool setTagText(const QDomElement &domElement, const QString &text); bool setTagText(const QDomElement &domElement, const QString &text);
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
void TestUniqueId() const;
void CollectId(const QDomElement &node, QVector<quint32> &vector)const; void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
protected slots: protected slots: