Improve Find measurements location dialog.

When Valentina can't find a measurements file it asks if user want to point to
new location. In my pratcise usually a file is near the pattern file. In old way
Valentina ignored that fact and pointed to standard locations. From now one it
will first check if searched name is near the pattern file.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-09-07 09:58:26 +03:00
parent 4ab42b2cef
commit 4ca0139af0

View File

@ -4575,6 +4575,29 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
return path; return path;
} }
auto FindLocation = [this](const QString &filter, const QString &dirPath)
{
VCommonSettings::PrepareMultisizeTables(VCommonSettings::GetDefPathMultisizeMeasurements());
bool usedNotExistedDir = false;
QDir directory(dirPath);
if (not directory.exists())
{
usedNotExistedDir = directory.mkpath(".");
}
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), dirPath, filter, nullptr,
QFileDialog::DontUseNativeDialog);
if (usedNotExistedDir)
{
QDir directory(dirPath);
directory.rmpath(".");
}
return mPath;
};
QFileInfo table(path); QFileInfo table(path);
if (table.exists() == false) if (table.exists() == false)
{ {
@ -4600,70 +4623,43 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
{ {
patternType = MeasurementsType::Multisize; patternType = MeasurementsType::Multisize;
} }
else if (table.suffix() == QLatin1String("vit"))
{
patternType = MeasurementsType::Individual;
}
else else
{ {
patternType = MeasurementsType::Unknown; patternType = MeasurementsType::Individual; // or Unknown
} }
auto DirPath = [patternPath, table](const QString &defPath)
{
QString dirPath;
const QDir patternDir = QFileInfo(patternPath).absoluteDir();
if (patternDir.exists(table.fileName()))
{
dirPath = patternDir.absolutePath();
}
else
{
dirPath = defPath;
}
return dirPath;
};
QString mPath; QString mPath;
if (patternType == MeasurementsType::Multisize) if (patternType == MeasurementsType::Multisize)
{ {
const QString filter = tr("Multisize measurements") + QLatin1String(" (*.vst)"); const QString filter = tr("Multisize measurements") + QLatin1String(" (*.vst);;") +
tr("Individual measurements") + QLatin1String(" (*.vit)");
//Use standard path to multisize measurements //Use standard path to multisize measurements
QString path = qApp->ValentinaSettings()->GetPathMultisizeMeasurements(); const QString dirPath = DirPath(qApp->ValentinaSettings()->GetPathMultisizeMeasurements());
path = VCommonSettings::PrepareMultisizeTables(path); mPath = FindLocation(filter, dirPath);
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr,
QFileDialog::DontUseNativeDialog);
}
else if (patternType == MeasurementsType::Individual)
{
const QString filter = tr("Individual measurements") + QLatin1String(" (*.vit)");
//Use standard path to individual measurements
const QString path = qApp->ValentinaSettings()->GetPathIndividualMeasurements();
bool usedNotExistedDir = false;
QDir directory(path);
if (not directory.exists())
{
usedNotExistedDir = directory.mkpath(".");
}
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr,
QFileDialog::DontUseNativeDialog);
if (usedNotExistedDir)
{
QDir directory(path);
directory.rmpath(".");
}
} }
else else
{ {
const QString filter = tr("Individual measurements") + QLatin1String(" (*.vit);;") + const QString filter = tr("Individual measurements") + QLatin1String(" (*.vit);;") +
tr("Multisize measurements") + QLatin1String(" (*.vst)"); tr("Multisize measurements") + QLatin1String(" (*.vst)");
//Use standard path to individual measurements //Use standard path to individual measurements
const QString path = qApp->ValentinaSettings()->GetPathIndividualMeasurements(); const QString dirPath = DirPath(qApp->ValentinaSettings()->GetPathIndividualMeasurements());
VCommonSettings::PrepareMultisizeTables(VCommonSettings::GetDefPathMultisizeMeasurements()); mPath = FindLocation(filter, dirPath);
bool usedNotExistedDir = false;
QDir directory(path);
if (not directory.exists())
{
usedNotExistedDir = directory.mkpath(".");
}
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr,
QFileDialog::DontUseNativeDialog);
if (usedNotExistedDir)
{
QDir directory(path);
directory.rmpath(".");
}
} }
if (mPath.isEmpty()) if (mPath.isEmpty())