New keys "gsize" and "gheight".

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-07 18:28:51 +03:00
parent afce2cb0ba
commit defbdb8e9c
5 changed files with 127 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "dialogs/dialoglayoutsettings.h"
#include "dialogs/dialogsavelayout.h"
#include "xml/vdomdocument.h"
#include "../vformat/vmeasurements.h"
VCommandLinePtr VCommandLine::instance = nullptr;
@ -56,6 +57,12 @@ const static auto SINGLE_OPTION_GROUPPING = QStringLiteral("g");
const static auto LONG_OPTION_TEST = QStringLiteral("test");
const static auto SINGLE_OPTION_TEST = QStringLiteral("t");
const static auto LONG_OPTION_GRADATIONSIZE = QStringLiteral("gsize");
const static auto SINGLE_OPTION_GRADATIONSIZE = QStringLiteral("x");
const static auto LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight");
const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("t");
//such a tricky initialization is used, because it uses static functions which relay on static variables and order of
//initialization is not defined between compiled units. i.e. - segv is possible (I hit it when
//VDomDocument::UnitsHelpString() was crashing because of not inited string vars).
@ -86,6 +93,20 @@ VCommandLine::VCommandLine() : parser()
tr("Number corresponding to output format (default = 0, export mode): ") +
DialogSaveLayout::MakeHelpFormatList(), tr("Format number"), "0")},
{LONG_OPTION_GRADATIONSIZE,
new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE,
tr("Set size value a pattern file, that was opened with standard measurements "
"(export mode). Valid values: %1cm.")
.arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
tr("The size value"))},
{LONG_OPTION_GRADATIONHEIGHT,
new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT,
tr("Set height value a pattern file, that was opened with standard measurements "
"(export mode). Valid values: %1cm.")
.arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")),
tr("The height value"))},
//===================================================================================
{LONG_OPTION_PAGETEMPLATE,
@ -439,3 +460,45 @@ bool VCommandLine::IsGuiEnabled() const
{
return isGuiEnabled;
}
//---------------------------------------------------------------------------------------------------------------------
bool VCommandLine::IsSetGradationSize() const
{
return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE));
}
//---------------------------------------------------------------------------------------------------------------------
bool VCommandLine::IsSetGradationHeight() const
{
return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT));
}
//---------------------------------------------------------------------------------------------------------------------
QString VCommandLine::OptGradationSize() const
{
const QString size = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE));
if (VMeasurement::IsGradationSizeValid(size))
{
return size;
}
else
{
qCritical() << tr("Invalid gradation size value.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VCommandLine::OptGradationHeight() const
{
const QString height = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT));
if (VMeasurement::IsGradationHeightValid(height))
{
return height;
}
else
{
qCritical() << tr("Invalid gradation height value.") << "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
}

View File

@ -80,6 +80,12 @@ public:
QStringList OptInputFileNames() const;
bool IsGuiEnabled()const;
bool IsSetGradationSize() const;
bool IsSetGradationHeight() const;
QString OptGradationSize() const;
QString OptGradationHeight() const;
};
#endif // VCMDEXPORT_H

View File

@ -78,6 +78,20 @@ int main(int argc, char *argv[])
for (int i=0, sz = args.size(); i < sz; ++i)
{
const bool loaded = w.LoadPattern(args.at(static_cast<int>(i)), app.CommandLine()->OptMeasurePath());
if (app.CommandLine()->IsTestModeEnabled() || app.CommandLine()->IsExportEnabled())
{
if (app.CommandLine()->IsSetGradationSize())
{
w.SetSize(app.CommandLine()->OptGradationSize());
}
if (app.CommandLine()->IsSetGradationHeight())
{
w.SetHeight(app.CommandLine()->OptGradationHeight());
}
}
if (not app.CommandLine()->IsTestModeEnabled())
{
if (app.CommandLine()->IsExportEnabled())

View File

@ -180,6 +180,48 @@ QStringList VMeasurement::WholeListSizes(Unit patternUnit)
return list;
}
//---------------------------------------------------------------------------------------------------------------------
bool VMeasurement::IsGradationSizeValid(const QString &size)
{
if (not size.isEmpty())
{
const QStringList sizes = VMeasurement::WholeListSizes(Unit::Cm);
if (sizes.contains(size))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
//---------------------------------------------------------------------------------------------------------------------
bool VMeasurement::IsGradationHeightValid(const QString &height)
{
if (not height.isEmpty())
{
const QStringList heights = VMeasurement::WholeListHeights(Unit::Cm);
if (heights.contains(height))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurement::ListValue(QStringList &list, qreal value, Unit patternUnit)
{

View File

@ -71,6 +71,8 @@ public:
static QStringList ListSizes(QMap<GSizes, bool> sizes, Unit patternUnit);
static QStringList WholeListHeights(Unit patternUnit);
static QStringList WholeListSizes(Unit patternUnit);
static bool IsGradationSizeValid(const QString &size);
static bool IsGradationHeightValid(const QString &height);
private:
QSharedDataPointer<VMeasurementData> d;