Refactoring validating size and height value.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-07 19:34:46 +03:00
parent defbdb8e9c
commit 719598b97b

View File

@ -505,21 +505,23 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
parser.addPositionalArgument("filename", tr("The measurement file.")); parser.addPositionalArgument("filename", tr("The measurement file."));
//----- //-----
QCommandLineOption heightOption(QStringList() << "e" << "height", QCommandLineOption heightOption(QStringList() << "e" << "height",
tr("Open with the base height: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182 or " tr("Open with the base height. Vali values: %1cm.")
"188 cm."), tr("The base height")); .arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")),
tr("The base height"));
parser.addOption(heightOption); parser.addOption(heightOption);
//----- //-----
QCommandLineOption sizeOption(QStringList() << "s" << "size", QCommandLineOption sizeOption(QStringList() << "s" << "size",
tr("Open with the base size: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54 or 56 cm."), tr("Open with the base size. Valid values: %1cm.").arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
tr("The base size")); tr("The base size"));
parser.addOption(sizeOption); parser.addOption(sizeOption);
//----- //-----
QCommandLineOption unitOption(QStringList() << "u" << "unit", QCommandLineOption unitOption(QStringList() << "u" << "unit",
tr("Set pattern file unit: cm, mm, inch."), tr("The pattern unit")); tr("Set pattern file unit: cm, mm, inch."),
tr("The pattern unit"));
parser.addOption(unitOption); parser.addOption(unitOption);
//----- //-----
QCommandLineOption testOption(QStringList() << "test", QCommandLineOption testOption(QStringList() << "test",
tr("Use for unit testing. Run the program and open a file without showing a window.")); tr("Use for unit testing. Run the program and open a file without showing a window."));
parser.addOption(testOption); parser.addOption(testOption);
//----- //-----
parser.process(arguments); parser.process(arguments);
@ -532,44 +534,32 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
int height = 0; int height = 0;
Unit unit = Unit::Cm; Unit unit = Unit::Cm;
{
const QString heightValue = parser.value(heightOption); const QString heightValue = parser.value(heightOption);
if (not heightValue.isEmpty()) if (VMeasurement::IsGradationHeightValid(heightValue))
{ {
const QStringList heights = VMeasurement::WholeListHeights(Unit::Cm); flagHeight = true;
if (heights.contains(heightValue)) height = heightValue.toInt();
{
flagHeight = true;
height = heightValue.toInt();
}
else
{
qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base height argument. Must be 92, 98, 104, 110, 116, 122, 128, 134, "
"140, 146, 152, 158, 164, 170, 176, 182 or 188 cm.")));
parser.showHelp(V_EX_USAGE);
}
} }
else
{
qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base height argument. Must be %1cm.")
.arg(VMeasurement::WholeListHeights(Unit::Cm).join(", "))));
parser.showHelp(V_EX_USAGE);
} }
{
const QString sizeValue = parser.value(sizeOption); const QString sizeValue = parser.value(sizeOption);
if (not sizeValue.isEmpty()) if (VMeasurement::IsGradationSizeValid(sizeValue))
{ {
const QStringList sizes = VMeasurement::WholeListSizes(Unit::Cm); flagSize = true;
if (sizes.contains(sizeValue)) size = sizeValue.toInt();
{
flagSize = true;
size = sizeValue.toInt();
}
else
{
qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base size argument. Must be 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, "
"42, 44, 46, 48, 50, 52, 54 or 56 cm.")));
parser.showHelp(V_EX_USAGE);
}
} }
else
{
qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base size argument. Must be %1cm.")
.arg(VMeasurement::WholeListSizes(Unit::Cm).join(", "))));
parser.showHelp(V_EX_USAGE);
} }
{ {