Immediately exit in console mode.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-05 12:56:43 +03:00
parent bd2e1063e3
commit 7eff8e8b9c

View File

@ -289,7 +289,14 @@ bool MainWindow::LoadMeasurements(const QString &path)
{ {
qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")), qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")),
qUtf8Printable(tr("Application doesn't support standard table with inches."))); qUtf8Printable(tr("Application doesn't support standard table with inches.")));
return false; if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_DATAERR);
}
} }
m->SetDataSize(); m->SetDataSize();
m->SetDataHeight(); m->SetDataHeight();
@ -306,7 +313,14 @@ bool MainWindow::LoadMeasurements(const QString &path)
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
delete m; delete m;
return false; if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
return true; return true;
} }
@ -2126,41 +2140,83 @@ void MainWindow::FullParseFile()
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);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
catch (const VExceptionConversionError &e) catch (const VExceptionConversionError &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
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);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
catch (const std::bad_alloc &) catch (const std::bad_alloc &)
{ {
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);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
QString patternPiece = QString(); QString patternPiece = QString();
@ -2200,14 +2256,28 @@ void MainWindow::GlobalChangePP(const QString &patternPiece)
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Bad id.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Bad id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
SetEnabledGUI(false); SetEnabledGUI(false);
return; if (VApplication::CheckGUI())
{
return;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
} }
@ -3174,13 +3244,31 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
if (path.isEmpty()) if (path.isEmpty())
{ {
Clear(); Clear();
return false; qCCritical(vMainWindow, "%s", qUtf8Printable(tr("The measurements file '%1' could not be found.")
.arg(path)));
if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
if (not LoadMeasurements(path)) if (not LoadMeasurements(path))
{ {
qCCritical(vMainWindow, "%s", qUtf8Printable(tr("The measurements file '%1' could not be found.")
.arg(path)));
Clear(); Clear();
return false; if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_NOINPUT);
}
} }
else else
{ {
@ -3378,116 +3466,117 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
{ {
if (!qApp->CheckGUI()) if (!qApp->CheckGUI())
{ {
vStdErr() << tr("The measurements file \"") << path << tr("\" could not be found.\n"); return QString();// console mode doesn't support fixing path to a measurement file
return QString();
}
QString text = tr("The measurements file <br/><br/> <b>%1</b> <br/><br/> %3").arg(path)
.arg(tr("could not be found. Do you want to update the file location"));
QMessageBox::StandardButton res = QMessageBox::question(this, "Loading measurements file", text,
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (res == QMessageBox::No)
{
return QString();
} }
else else
{ {
MeasurementsType patternType; const QString text = tr("The measurements file <br/><br/> <b>%1</b> <br/><br/> could not be found. Do you "
if (table.suffix() == QLatin1String("vst")) "want to update the file location").arg(path);
QMessageBox::StandardButton res = QMessageBox::question(this, tr("Loading measurements file"), text,
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (res == QMessageBox::No)
{ {
patternType = MeasurementsType::Standard; return QString();
}
else if (table.suffix() == QLatin1String("vit"))
{
patternType = MeasurementsType::Individual;
} }
else else
{ {
patternType = MeasurementsType::Unknown; MeasurementsType patternType;
} if (table.suffix() == QLatin1String("vst"))
QString mPath;
if (patternType == MeasurementsType::Standard)
{
const QString filter = tr("Standard measurements (*.vst)");
//Use standard path to standard measurements
const QString path = qApp->ValentinaSettings()->GetPathStandardMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
}
else if (patternType == MeasurementsType::Individual)
{
const QString filter = tr("Individual measurements (*.vit)");
//Use standard path to individual measurements
const QString path = qApp->ValentinaSettings()->GetPathIndividualMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
}
else
{
const QString filter = tr("Individual measurements (*.vit);;Standard measurements (*.vst)");
//Use standard path to individual measurements
const QString path = qApp->ValentinaSettings()->GetPathIndividualMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
}
if (mPath.isEmpty())
{
return mPath;
}
else
{
VMeasurements *m = new VMeasurements(pattern);
m->setXMLContent(mPath);
patternType = m->Type();
if (patternType == MeasurementsType::Unknown)
{ {
VException e(tr("Measurement file has unknown format.")); patternType = MeasurementsType::Standard;
throw e;
} }
else if (table.suffix() == QLatin1String("vit"))
if (patternType == MeasurementsType::Standard)
{ {
VVSTConverter converter(mPath); patternType = MeasurementsType::Individual;
converter.Convert();
VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, mPath);
} }
else else
{ {
VVITConverter converter(mPath); patternType = MeasurementsType::Unknown;
converter.Convert();
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, mPath);
} }
m->setXMLContent(mPath);// Read again after conversion QString mPath;
if (patternType == MeasurementsType::Standard)
if (not m->IsDefinedKnownNamesValid())
{ {
VException e(tr("Measurement file contains invalid known measurement(s).")); const QString filter = tr("Standard measurements (*.vst)");
throw e; //Use standard path to standard measurements
const QString path = qApp->ValentinaSettings()->GetPathStandardMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
} }
else if (patternType == MeasurementsType::Individual)
const QStringList mList = m->ListAll();
const QStringList pList = doc->ListMeasurements();
delete m;
const QSet<QString> match = pList.toSet().subtract(mList.toSet());
if (not match.isEmpty())
{ {
VException e(tr("Measurement file doesn't include all required measurements.")); const QString filter = tr("Individual measurements (*.vit)");
e.AddMoreInformation(tr("Please, additionaly provide: %1") //Use standard path to individual measurements
.arg(QStringList(match.toList()).join(", "))); const QString path = qApp->ValentinaSettings()->GetPathIndividualMeasurements();
throw e; mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
}
else
{
const QString filter = tr("Individual measurements (*.vit);;Standard measurements (*.vst)");
//Use standard path to individual measurements
const QString path = qApp->ValentinaSettings()->GetPathIndividualMeasurements();
mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
} }
doc->SetPath(RelativeMPath(patternPath, mPath)); if (mPath.isEmpty())
PatternWasModified(false); {
qApp->setPatternType(patternType); return mPath;
return mPath; }
else
{
VMeasurements *m = new VMeasurements(pattern);
m->setXMLContent(mPath);
patternType = m->Type();
if (patternType == MeasurementsType::Unknown)
{
VException e(tr("Measurement file has unknown format."));
throw e;
}
if (patternType == MeasurementsType::Standard)
{
VVSTConverter converter(mPath);
converter.Convert();
VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, mPath);
}
else
{
VVITConverter converter(mPath);
converter.Convert();
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, mPath);
}
m->setXMLContent(mPath);// Read again after conversion
if (not m->IsDefinedKnownNamesValid())
{
VException e(tr("Measurement file contains invalid known measurement(s)."));
throw e;
}
const QStringList mList = m->ListAll();
const QStringList pList = doc->ListMeasurements();
delete m;
const QSet<QString> match = pList.toSet().subtract(mList.toSet());
if (not match.isEmpty())
{
VException e(tr("Measurement file doesn't include all required measurements."));
e.AddMoreInformation(tr("Please, additionaly provide: %1")
.arg(QStringList(match.toList()).join(", ")));
throw e;
}
doc->SetPath(RelativeMPath(patternPath, mPath));
PatternWasModified(false);
qApp->setPatternType(patternType);
return mPath;
}
} }
} }
} }