From defbdb8e9c75d6abec6f51d9ba4a4ae4e49589e4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 7 Oct 2015 18:28:51 +0300 Subject: [PATCH] New keys "gsize" and "gheight". --HG-- branch : develop --- src/app/valentina/core/vcmdexport.cpp | 63 +++++++++++++++++++ src/app/valentina/core/vcmdexport.h | 6 ++ src/app/valentina/main.cpp | 14 +++++ .../vpatterndb/variables/vmeasurement.cpp | 42 +++++++++++++ src/libs/vpatterndb/variables/vmeasurement.h | 2 + 5 files changed, 127 insertions(+) diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 47fe16429..f74121ac3 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -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(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(this)->parser.showHelp(V_EX_USAGE); + } +} diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index 908b35efb..390a6722e 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -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 diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp index 3c3b34e76..24eb5da11 100644 --- a/src/app/valentina/main.cpp +++ b/src/app/valentina/main.cpp @@ -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(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()) diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index e72c8bd6c..1a85eb2ca 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -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) { diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index 6fb8a3f93..c6e08688f 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -71,6 +71,8 @@ public: static QStringList ListSizes(QMap 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 d;