Keep order of options.
--HG-- branch : feature
This commit is contained in:
parent
e7e177898c
commit
01a23b5e08
|
@ -66,17 +66,19 @@ const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e");
|
||||||
#define translate(context, source) QCoreApplication::translate((context), (source))
|
#define translate(context, source) QCoreApplication::translate((context), (source))
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VCommandLine::VCommandLine() : parser(), optionsUsed(InitOptionsUsed()), isGuiEnabled(false)
|
VCommandLine::VCommandLine() : parser(), optionsUsed(), optionsIndex(), isGuiEnabled(false)
|
||||||
{
|
{
|
||||||
parser.setApplicationDescription(translate("VCommandLine", "Pattern making program."));
|
parser.setApplicationDescription(translate("VCommandLine", "Pattern making program."));
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
parser.addPositionalArgument("filename", translate("VCommandLine", "Pattern file."));
|
parser.addPositionalArgument("filename", translate("VCommandLine", "Pattern file."));
|
||||||
|
|
||||||
QMap<QString, QCommandLineOption *>::const_iterator i = optionsUsed.constBegin();
|
InitOptions(optionsUsed, optionsIndex);
|
||||||
|
|
||||||
|
VCommandLineOptions::const_iterator i = optionsUsed.constBegin();
|
||||||
while (i != optionsUsed.constEnd())
|
while (i != optionsUsed.constEnd())
|
||||||
{
|
{
|
||||||
parser.addOption(*i.value());
|
parser.addOption(*((*i)));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,45 +96,44 @@ qreal VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& conver
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QMap<QString, QCommandLineOption *> VCommandLine::InitOptionsUsed()
|
void VCommandLine::InitOptions(VCommandLineOptions &options, QMap<QString, int> &optionsIndex)
|
||||||
{
|
{
|
||||||
QMap<QString, QCommandLineOption *> options;
|
int index = 0;
|
||||||
|
|
||||||
//keep in mind order here - that is how user will see it, so group-up for usability
|
//keep in mind order here - that is how user will see it, so group-up for usability
|
||||||
//=================================================================================================================
|
//=================================================================================================================
|
||||||
options.insert(LONG_OPTION_BASENAME,
|
optionsIndex.insert(LONG_OPTION_BASENAME, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME,
|
||||||
translate("VCommandLine", "The base filename of exported layout files. Use "
|
translate("VCommandLine", "The base filename of exported layout files. Use "
|
||||||
"it to enable console export mode."),
|
"it to enable console export mode."),
|
||||||
translate("VCommandLine", "The base filename of layout files")));
|
translate("VCommandLine", "The base filename of layout files")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_DESTINATION,
|
optionsIndex.insert(LONG_OPTION_DESTINATION, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION,
|
||||||
translate("VCommandLine", "The path to output destination folder."),
|
translate("VCommandLine", "The path to output destination folder."),
|
||||||
translate("VCommandLine", "The destination folder")));
|
translate("VCommandLine", "The destination folder")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_MEASUREFILE,
|
optionsIndex.insert(LONG_OPTION_MEASUREFILE, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
|
||||||
translate("VCommandLine", "Path to custom measure file (export mode)."),
|
translate("VCommandLine", "Path to custom measure file (export mode)."),
|
||||||
translate("VCommandLine", "The measure file")));
|
translate("VCommandLine", "The measure file")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_EXP2FORMAT,
|
optionsIndex.insert(LONG_OPTION_EXP2FORMAT, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT,
|
||||||
translate("VCommandLine", "Number corresponding to output format (default = "
|
translate("VCommandLine", "Number corresponding to output format (default = "
|
||||||
"0, export mode): ") +
|
"0, export mode): ") +
|
||||||
DialogSaveLayout::MakeHelpFormatList(),
|
DialogSaveLayout::MakeHelpFormatList(),
|
||||||
translate("VCommandLine", "Format number"), "0"));
|
translate("VCommandLine", "Format number"), "0"));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_GRADATIONSIZE,
|
optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE,
|
||||||
translate("VCommandLine", "Set size value a pattern file, that was opened "
|
translate("VCommandLine", "Set size value a pattern file, that was opened "
|
||||||
"with standard measurements (export mode). Valid "
|
"with standard measurements (export mode). Valid "
|
||||||
"values: %1cm.")
|
"values: %1cm.")
|
||||||
.arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
|
.arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
|
||||||
translate("VCommandLine", "The size value")));
|
translate("VCommandLine", "The size value")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_GRADATIONHEIGHT,
|
optionsIndex.insert(LONG_OPTION_GRADATIONHEIGHT, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT,
|
||||||
translate("VCommandLine", "Set height value a pattern file, that was opened "
|
translate("VCommandLine", "Set height value a pattern file, that was opened "
|
||||||
"with standard measurements (export mode). Valid "
|
"with standard measurements (export mode). Valid "
|
||||||
"values: %1cm.")
|
"values: %1cm.")
|
||||||
|
@ -140,91 +141,86 @@ QMap<QString, QCommandLineOption *> VCommandLine::InitOptionsUsed()
|
||||||
translate("VCommandLine", "The height value")));
|
translate("VCommandLine", "The height value")));
|
||||||
|
|
||||||
//=================================================================================================================
|
//=================================================================================================================
|
||||||
|
optionsIndex.insert(LONG_OPTION_PAGETEMPLATE, index++);
|
||||||
options.insert(LONG_OPTION_PAGETEMPLATE,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
|
|
||||||
translate("VCommandLine", "Number corresponding to page template (default = "
|
translate("VCommandLine", "Number corresponding to page template (default = "
|
||||||
"0, export mode): ") +
|
"0, export mode): ") +
|
||||||
DialogLayoutSettings::MakeHelpTemplateList(),
|
DialogLayoutSettings::MakeHelpTemplateList(),
|
||||||
translate("VCommandLine", "Template number"), "0"));
|
translate("VCommandLine", "Template number"), "0"));
|
||||||
|
|
||||||
|
optionsIndex.insert(LONG_OPTION_PAGEW, index++);
|
||||||
options.insert(LONG_OPTION_PAGEW,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
|
|
||||||
translate("VCommandLine", "Page width in current units like 12.0 (cannot be "
|
translate("VCommandLine", "Page width in current units like 12.0 (cannot be "
|
||||||
"used with \"%1\", export mode).")
|
"used with \"%1\", export mode).")
|
||||||
.arg(LONG_OPTION_PAGETEMPLATE),
|
.arg(LONG_OPTION_PAGETEMPLATE),
|
||||||
translate("VCommandLine", "The page width")));
|
translate("VCommandLine", "The page width")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_PAGEH,
|
optionsIndex.insert(LONG_OPTION_PAGEH, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
|
||||||
translate("VCommandLine", "Page height in current units like 12.0 (cannot "
|
translate("VCommandLine", "Page height in current units like 12.0 (cannot "
|
||||||
"be used with \"%1\", export mode).")
|
"be used with \"%1\", export mode).")
|
||||||
.arg(LONG_OPTION_PAGETEMPLATE),
|
.arg(LONG_OPTION_PAGETEMPLATE),
|
||||||
("The page height")));
|
("The page height")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_PAGEUNITS,
|
optionsIndex.insert(LONG_OPTION_PAGEUNITS, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
|
||||||
translate("VCommandLine", "Page height/width measure units (cannot be used "
|
translate("VCommandLine", "Page height/width measure units (cannot be used "
|
||||||
"with \"%1\", export mode): ")
|
"with \"%1\", export mode): ")
|
||||||
.arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(),
|
.arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(),
|
||||||
translate("VCommandLine", "The measure unit")));
|
translate("VCommandLine", "The measure unit")));
|
||||||
|
|
||||||
//=================================================================================================================
|
//=================================================================================================================
|
||||||
|
optionsIndex.insert(LONG_OPTION_ROTATE, index++);
|
||||||
options.insert(LONG_OPTION_ROTATE,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE,
|
|
||||||
translate("VCommandLine", "Rotation in degrees (one of predefined). Default "
|
translate("VCommandLine", "Rotation in degrees (one of predefined). Default "
|
||||||
"(or 0) is no-rotate (export mode)."),
|
"(or 0) is no-rotate (export mode)."),
|
||||||
translate("VCommandLine", "Angle")));
|
translate("VCommandLine", "Angle")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_CROP,
|
optionsIndex.insert(LONG_OPTION_CROP, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
|
||||||
translate("VCommandLine", "Auto crop unused length (export mode).")));
|
translate("VCommandLine", "Auto crop unused length (export mode).")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_UNITE,
|
optionsIndex.insert(LONG_OPTION_UNITE, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE,
|
||||||
translate("VCommandLine", "Unite pages if possible (export mode).")));
|
translate("VCommandLine", "Unite pages if possible (export mode).")));
|
||||||
|
|
||||||
//=================================================================================================================
|
//=================================================================================================================
|
||||||
|
optionsIndex.insert(LONG_OPTION_SAVELENGTH, index++);
|
||||||
options.insert(LONG_OPTION_SAVELENGTH,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
|
|
||||||
translate("VCommandLine",
|
translate("VCommandLine",
|
||||||
"Save length of the sheet if set. (export mode).")));
|
"Save length of the sheet if set. (export mode).")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_SHIFTUNITS,
|
optionsIndex.insert(LONG_OPTION_SHIFTUNITS, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS,
|
||||||
translate("VCommandLine",
|
translate("VCommandLine",
|
||||||
"Layout units (as paper's one except px, export mode)."),
|
"Layout units (as paper's one except px, export mode)."),
|
||||||
translate("VCommandLine", "The unit")));
|
translate("VCommandLine", "The unit")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_SHIFTLENGTH,
|
optionsIndex.insert(LONG_OPTION_SHIFTLENGTH, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH,
|
||||||
translate("VCommandLine", "Shift layout length measured in layout units "
|
translate("VCommandLine", "Shift layout length measured in layout units "
|
||||||
"(export mode)."),
|
"(export mode)."),
|
||||||
translate("VCommandLine", "Shift length")));
|
translate("VCommandLine", "Shift length")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_GAPWIDTH,
|
optionsIndex.insert(LONG_OPTION_GAPWIDTH, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH,
|
||||||
translate("VCommandLine",
|
translate("VCommandLine",
|
||||||
"Gap width x2, measured in layout units. (export mode)."),
|
"Gap width x2, measured in layout units. (export mode)."),
|
||||||
translate("VCommandLine", "The gap width")));
|
translate("VCommandLine", "The gap width")));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_GROUPPING,
|
optionsIndex.insert(LONG_OPTION_GROUPPING, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING,
|
||||||
translate("VCommandLine", "Sets layout groupping (export mode): ")
|
translate("VCommandLine", "Sets layout groupping (export mode): ")
|
||||||
+ DialogLayoutSettings::MakeGroupsHelp(),
|
+ DialogLayoutSettings::MakeGroupsHelp(),
|
||||||
translate("VCommandLine", "Grouping type"), "2"));
|
translate("VCommandLine", "Grouping type"), "2"));
|
||||||
|
|
||||||
options.insert(LONG_OPTION_TEST,
|
optionsIndex.insert(LONG_OPTION_TEST, index++);
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST,
|
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST,
|
||||||
translate("VCommandLine", "Run the program in a test mode. The program this "
|
translate("VCommandLine", "Run the program in a test mode. The program this "
|
||||||
"mode load a single pattern file and silently "
|
"mode load a single pattern file and silently "
|
||||||
"quit without showing the main window. The key "
|
"quit without showing the main window. The key "
|
||||||
"have priority before key '%1'.")
|
"have priority before key '%1'.")
|
||||||
.arg(LONG_OPTION_BASENAME)));
|
.arg(LONG_OPTION_BASENAME)));
|
||||||
return options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------
|
||||||
|
@ -237,11 +233,11 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
||||||
|
|
||||||
{
|
{
|
||||||
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
||||||
bool x = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE));
|
bool x = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE)));
|
||||||
|
|
||||||
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH));
|
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH)));
|
||||||
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEW));
|
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW)));
|
||||||
bool c = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEUNITS));
|
bool c = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
|
||||||
|
|
||||||
if ((a || b || c) && x)
|
if ((a || b || c) && x)
|
||||||
{
|
{
|
||||||
|
@ -260,8 +256,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
||||||
|
|
||||||
{
|
{
|
||||||
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
||||||
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH));
|
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH)));
|
||||||
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS));
|
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)));
|
||||||
|
|
||||||
if ((a || b) && !(a && b))
|
if ((a || b) && !(a && b))
|
||||||
{
|
{
|
||||||
|
@ -272,8 +268,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
||||||
|
|
||||||
{
|
{
|
||||||
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
//just anonymous namespace ...don' like to have a,b,c,d everywhere defined
|
||||||
bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH));
|
bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH)));
|
||||||
bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS));
|
bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)));
|
||||||
|
|
||||||
if ((a || b) && !(a && b))
|
if ((a || b) && !(a && b))
|
||||||
{
|
{
|
||||||
|
@ -302,46 +298,44 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
|
||||||
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
|
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH))) //at this point we already sure 3 are set or none
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))))
|
||||||
{
|
{ //at this point we already sure 3 are set or none
|
||||||
|
|
||||||
if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(LONG_OPTION_PAGEUNITS))))
|
if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)))))
|
||||||
{
|
{
|
||||||
qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n";
|
qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n";
|
||||||
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
|
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEH)), diag));
|
diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))), diag));
|
||||||
diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEW)), diag));
|
diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW))), diag));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS))))
|
||||||
{
|
{
|
||||||
if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTUNITS))))
|
if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)))))
|
||||||
{
|
{
|
||||||
qCritical() << translate("VCommandLine", "Unsupported layout units.") << "\n";
|
qCritical() << translate("VCommandLine", "Unsupported layout units.") << "\n";
|
||||||
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
|
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))))
|
||||||
{
|
{
|
||||||
|
|
||||||
diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)), diag));
|
diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))), diag));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH)))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))))
|
||||||
{
|
{
|
||||||
diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_GAPWIDTH)), diag));
|
diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))), diag));
|
||||||
}
|
}
|
||||||
|
|
||||||
diag.SetAutoCrop(parser.isSet(*optionsUsed.value(LONG_OPTION_CROP)));
|
diag.SetAutoCrop(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CROP))));
|
||||||
diag.SetUnitePages(parser.isSet(*optionsUsed.value(LONG_OPTION_UNITE)));
|
diag.SetUnitePages(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_UNITE))));
|
||||||
diag.SetSaveLength(parser.isSet(*optionsUsed.value(LONG_OPTION_SAVELENGTH)));
|
diag.SetSaveLength(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SAVELENGTH))));
|
||||||
diag.SetGroup(OptGroup());
|
diag.SetGroup(OptGroup());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
diag.DialogAccepted(); // filling VLayoutGenerator
|
diag.DialogAccepted(); // filling VLayoutGenerator
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -378,7 +372,7 @@ void VCommandLine::Reset()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VCommandLine::IsTestModeEnabled() const
|
bool VCommandLine::IsTestModeEnabled() const
|
||||||
{
|
{
|
||||||
const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_TEST));
|
const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEST)));
|
||||||
if (r && parser.positionalArguments().size() != 1)
|
if (r && parser.positionalArguments().size() != 1)
|
||||||
{
|
{
|
||||||
qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n";
|
qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n";
|
||||||
|
@ -390,7 +384,7 @@ bool VCommandLine::IsTestModeEnabled() const
|
||||||
//------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------
|
||||||
bool VCommandLine::IsExportEnabled() const
|
bool VCommandLine::IsExportEnabled() const
|
||||||
{
|
{
|
||||||
const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_BASENAME));
|
const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME)));
|
||||||
if (r && parser.positionalArguments().size() != 1)
|
if (r && parser.positionalArguments().size() != 1)
|
||||||
{
|
{
|
||||||
qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n";
|
qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n";
|
||||||
|
@ -403,9 +397,9 @@ bool VCommandLine::IsExportEnabled() const
|
||||||
DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
|
DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
|
||||||
{
|
{
|
||||||
int ppsize = 0;
|
int ppsize = 0;
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))))
|
||||||
{
|
{
|
||||||
ppsize = parser.value(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)).toInt();
|
ppsize = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))).toInt();
|
||||||
}
|
}
|
||||||
return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize);
|
return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize);
|
||||||
}
|
}
|
||||||
|
@ -414,9 +408,9 @@ DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const
|
||||||
int VCommandLine::OptRotation() const
|
int VCommandLine::OptRotation() const
|
||||||
{
|
{
|
||||||
int rotate = 0;
|
int rotate = 0;
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_ROTATE)))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))))
|
||||||
{
|
{
|
||||||
rotate = parser.value(*optionsUsed.value(LONG_OPTION_ROTATE)).toInt();
|
rotate = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
return rotate;
|
return rotate;
|
||||||
|
@ -425,7 +419,7 @@ int VCommandLine::OptRotation() const
|
||||||
//------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------
|
||||||
Cases VCommandLine::OptGroup() const
|
Cases VCommandLine::OptGroup() const
|
||||||
{
|
{
|
||||||
int r = parser.value(*optionsUsed.value(LONG_OPTION_GROUPPING)).toInt();
|
int r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GROUPPING))).toInt();
|
||||||
if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase))
|
if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase))
|
||||||
{
|
{
|
||||||
r = 0;
|
r = 0;
|
||||||
|
@ -437,11 +431,11 @@ Cases VCommandLine::OptGroup() const
|
||||||
QString VCommandLine::OptMeasurePath() const
|
QString VCommandLine::OptMeasurePath() const
|
||||||
{
|
{
|
||||||
QString measure;
|
QString measure;
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_MEASUREFILE))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE)))
|
||||||
&& IsExportEnabled() //todo: don't want yet to allow user set measure file for general loading, because need to fix multiply opened windows as well
|
&& IsExportEnabled() //todo: don't want yet to allow user set measure file for general loading, because need to fix multiply opened windows as well
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
measure = parser.value(*optionsUsed.value(LONG_OPTION_MEASUREFILE));
|
measure = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return measure;
|
return measure;
|
||||||
|
@ -453,7 +447,7 @@ QString VCommandLine::OptBaseName() const
|
||||||
QString path;
|
QString path;
|
||||||
if (IsExportEnabled())
|
if (IsExportEnabled())
|
||||||
{
|
{
|
||||||
path = parser.value(*optionsUsed.value(LONG_OPTION_BASENAME));
|
path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
@ -465,7 +459,7 @@ QString VCommandLine::OptDestinationPath() const
|
||||||
QString path;
|
QString path;
|
||||||
if (IsExportEnabled())
|
if (IsExportEnabled())
|
||||||
{
|
{
|
||||||
path = parser.value(*optionsUsed.value(LONG_OPTION_DESTINATION));
|
path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_DESTINATION)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
@ -475,9 +469,9 @@ QString VCommandLine::OptDestinationPath() const
|
||||||
int VCommandLine::OptExportType() const
|
int VCommandLine::OptExportType() const
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (parser.isSet(*optionsUsed.value(LONG_OPTION_EXP2FORMAT)))
|
if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))))
|
||||||
{
|
{
|
||||||
r = parser.value(*optionsUsed.value(LONG_OPTION_EXP2FORMAT)).toInt();
|
r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))).toInt();
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -497,19 +491,19 @@ bool VCommandLine::IsGuiEnabled() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VCommandLine::IsSetGradationSize() const
|
bool VCommandLine::IsSetGradationSize() const
|
||||||
{
|
{
|
||||||
return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE));
|
return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VCommandLine::IsSetGradationHeight() const
|
bool VCommandLine::IsSetGradationHeight() const
|
||||||
{
|
{
|
||||||
return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT));
|
return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VCommandLine::OptGradationSize() const
|
QString VCommandLine::OptGradationSize() const
|
||||||
{
|
{
|
||||||
const QString size = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE));
|
const QString size = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE)));
|
||||||
if (VMeasurement::IsGradationSizeValid(size))
|
if (VMeasurement::IsGradationSizeValid(size))
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
|
@ -524,7 +518,7 @@ QString VCommandLine::OptGradationSize() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VCommandLine::OptGradationHeight() const
|
QString VCommandLine::OptGradationHeight() const
|
||||||
{
|
{
|
||||||
const QString height = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT));
|
const QString height = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT)));
|
||||||
if (VMeasurement::IsGradationHeightValid(height))
|
if (VMeasurement::IsGradationHeightValid(height))
|
||||||
{
|
{
|
||||||
return height;
|
return height;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class VCommandLine;
|
class VCommandLine;
|
||||||
typedef std::shared_ptr<VCommandLine> VCommandLinePtr;
|
typedef std::shared_ptr<VCommandLine> VCommandLinePtr;
|
||||||
|
typedef QList<QCommandLineOption *> VCommandLineOptions;
|
||||||
|
|
||||||
//@brief: class used to install export command line options and parse their values
|
//@brief: class used to install export command line options and parse their values
|
||||||
//QCommandLineParser* object must exists until this object alive
|
//QCommandLineParser* object must exists until this object alive
|
||||||
|
@ -81,14 +82,15 @@ private:
|
||||||
Q_DISABLE_COPY(VCommandLine)
|
Q_DISABLE_COPY(VCommandLine)
|
||||||
static VCommandLinePtr instance;
|
static VCommandLinePtr instance;
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
QMap<QString, QCommandLineOption *> optionsUsed;
|
VCommandLineOptions optionsUsed;
|
||||||
|
QMap<QString, int> optionsIndex;
|
||||||
bool isGuiEnabled;
|
bool isGuiEnabled;
|
||||||
friend class VApplication;
|
friend class VApplication;
|
||||||
|
|
||||||
static qreal Lo2Px(const QString& src, const DialogLayoutSettings& converter);
|
static qreal Lo2Px(const QString& src, const DialogLayoutSettings& converter);
|
||||||
static qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter);
|
static qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter);
|
||||||
|
|
||||||
static QMap<QString, QCommandLineOption *> InitOptionsUsed();
|
static void InitOptions(VCommandLineOptions &options, QMap<QString, int> &optionsIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VCMDEXPORT_H
|
#endif // VCMDEXPORT_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user