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,17 +505,19 @@ 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",
@ -532,12 +534,8 @@ 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);
if (heights.contains(heightValue))
{ {
flagHeight = true; flagHeight = true;
height = heightValue.toInt(); height = heightValue.toInt();
@ -545,19 +543,13 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
else else
{ {
qCCritical(mApp, "%s\n", qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base height argument. Must be 92, 98, 104, 110, 116, 122, 128, 134, " qPrintable(tr("Invalid base height argument. Must be %1cm.")
"140, 146, 152, 158, 164, 170, 176, 182 or 188 cm."))); .arg(VMeasurement::WholeListHeights(Unit::Cm).join(", "))));
parser.showHelp(V_EX_USAGE); 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);
if (sizes.contains(sizeValue))
{ {
flagSize = true; flagSize = true;
size = sizeValue.toInt(); size = sizeValue.toInt();
@ -565,12 +557,10 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
else else
{ {
qCCritical(mApp, "%s\n", qCCritical(mApp, "%s\n",
qPrintable(tr("Invalid base size argument. Must be 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, " qPrintable(tr("Invalid base size argument. Must be %1cm.")
"42, 44, 46, 48, 50, 52, 54 or 56 cm."))); .arg(VMeasurement::WholeListSizes(Unit::Cm).join(", "))));
parser.showHelp(V_EX_USAGE); parser.showHelp(V_EX_USAGE);
} }
}
}
{ {
const QString unitValue = parser.value(unitOption); const QString unitValue = parser.value(unitOption);