From 030c513784c865f754e293f468d4edb32ae3fdfc Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 20 Aug 2019 15:23:31 +0300 Subject: [PATCH] Resolved issue #976. The pattern does not open. --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 42 +++++++++++++++++++-------- src/libs/ifc/xml/vabstractpattern.cpp | 6 ++++ src/libs/ifc/xml/vabstractpattern.h | 1 + 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 9331f3059..c327922de 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4745,23 +4745,41 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) m_curFileFormatVersion = converter->GetCurrentFormatVersion(); m_curFileFormatVersionStr = converter->GetFormatVersionStr(); doc->setXMLContent(converter->Convert()); - if (!customMeasureFile.isEmpty()) - { - doc->SetMPath(RelativeMPath(fileName, customMeasureFile)); - } - qApp->setPatternUnit(doc->MUnit()); } - else + + if (!customMeasureFile.isEmpty()) { - if (!customMeasureFile.isEmpty()) - { - doc->SetMPath(RelativeMPath(fileName, customMeasureFile)); - } - qApp->setPatternUnit(doc->MUnit()); + doc->SetMPath(RelativeMPath(fileName, customMeasureFile)); } - const QString path = AbsoluteMPath(fileName, doc->MPath()); + qApp->setPatternUnit(doc->MUnit()); + + QString path = AbsoluteMPath(fileName, doc->MPath()); QString fixedMPath; + // See issue #976. Pattern can lost link to measurements + if (path.isEmpty() && doc->RequiresMeasurements()) + { + const QString fakeName = QStringLiteral("unknown_measurements.vit"); + // Check if exist + fixedMPath = CheckPathToMeasurements(fileName, fakeName); + if (fixedMPath.isEmpty()) + { + qApp->setOpeningPattern();// End opening file + Clear(); + qCCritical(vMainWindow, "%s", qUtf8Printable(tr("The measurements file '%1' could not be found.") + .arg(fakeName))); + if (not VApplication::IsGUIMode()) + { + qApp->exit(V_EX_NOINPUT); + } + return false; + } + else + { + path = AbsoluteMPath(fileName, doc->MPath()); + } + } + if (not path.isEmpty()) { // Check if exist diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 3ee2117af..0a39c321e 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -298,6 +298,12 @@ VAbstractPattern::~VAbstractPattern() toolsOnRemove.clear(); } +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractPattern::RequiresMeasurements() const +{ + return not ListMeasurements().isEmpty(); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::ListMeasurements() const { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 01a731992..6c2bcf37a 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -86,6 +86,7 @@ public: explicit VAbstractPattern(QObject *parent = nullptr); virtual ~VAbstractPattern(); + bool RequiresMeasurements() const; QStringList ListMeasurements() const; QVector ListExpressions() const; QVector ListIncrementExpressions() const;