Fix measurements path correction.

After user finds new path to measurements file the path must be saved to
pattern file automatically. But because of optimization we read file again and
thus override the change.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-01-03 20:50:56 +02:00
parent 2f717fd365
commit dcea610da2

View File

@ -4590,12 +4590,13 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
qApp->setPatternUnit(doc->MUnit()); qApp->setPatternUnit(doc->MUnit());
} }
const QString path = AbsoluteMPath(fileName, doc->MPath()); const QString path = AbsoluteMPath(fileName, doc->MPath());
QString fixedMPath;
if (not path.isEmpty()) if (not path.isEmpty())
{ {
// Check if exist // Check if exist
const QString newPath = CheckPathToMeasurements(fileName, path); fixedMPath = CheckPathToMeasurements(fileName, path);
if (newPath.isEmpty()) if (fixedMPath.isEmpty())
{ {
qApp->setOpeningPattern();// End opening file qApp->setOpeningPattern();// End opening file
Clear(); Clear();
@ -4608,11 +4609,11 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
return false; return false;
} }
if (not LoadMeasurements(newPath)) if (not LoadMeasurements(fixedMPath))
{ {
qCCritical(vMainWindow, "%s", qUtf8Printable(tr("The measurements file '%1' could not be found or " qCCritical(vMainWindow, "%s", qUtf8Printable(tr("The measurements file '%1' could not be found or "
"provides not enough information.") "provides not enough information.")
.arg(newPath))); .arg(fixedMPath)));
qApp->setOpeningPattern();// End opening file qApp->setOpeningPattern();// End opening file
Clear(); Clear();
if (not VApplication::IsGUIMode()) if (not VApplication::IsGUIMode())
@ -4624,7 +4625,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
else else
{ {
ui->actionUnloadMeasurements->setEnabled(true); ui->actionUnloadMeasurements->setEnabled(true);
watcher->addPath(newPath); watcher->addPath(fixedMPath);
ui->actionEditCurrent->setEnabled(true); ui->actionEditCurrent->setEnabled(true);
} }
} }
@ -4645,6 +4646,10 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
{ {
doc->SetMPath(RelativeMPath(fileName, customMeasureFile)); doc->SetMPath(RelativeMPath(fileName, customMeasureFile));
} }
else if (not path.isEmpty() && fixedMPath != path)
{
doc->SetMPath(RelativeMPath(fileName, fixedMPath));
}
qApp->setPatternUnit(doc->MUnit()); qApp->setPatternUnit(doc->MUnit());
} }
} }
@ -4995,8 +5000,7 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
if (usedNotExistedDir) if (usedNotExistedDir)
{ {
QDir directory(dirPath); QDir(dirPath).rmpath(QChar('.'));
directory.rmpath(QChar('.'));
} }
return mPath; return mPath;
@ -5109,7 +5113,6 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
qApp->setPatternType(patternType); qApp->setPatternType(patternType);
doc->SetMPath(RelativeMPath(patternPath, mPath)); doc->SetMPath(RelativeMPath(patternPath, mPath));
PatternChangesWereSaved(false);
return mPath; return mPath;
} }
} }