From 8625ecd2b458e5476b6cf459f9652fafa166db61 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 15 Oct 2021 18:47:36 +0300 Subject: [PATCH] Fix handling numeric values passed in console mode. --- ChangeLog.txt | 1 + src/app/valentina/core/vcmdexport.cpp | 108 ++++++++++++++++++++++---- 2 files changed, 94 insertions(+), 15 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 845bdf0da..9b6c6c569 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -13,6 +13,7 @@ - [smart-pattern/valentina#150] Fix Seam allowance not correct at intersection curve and axis. - Show tooltip about defined user material in the label placeholder list. - Fix reading tiled page margins in console mode. +- Fix handling numeric values passed in console mode. # Valentina 0.7.49 July 1, 2021 - Fix crash. diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index f3e83427d..7ca6add8a 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -46,15 +46,15 @@ VCommandLinePtr VCommandLine::instance = nullptr; namespace { //--------------------------------------------------------------------------------------------------------------------- -qreal Lo2Px(const QString &src, const DialogLayoutSettings &converter) +qreal Lo2Px(const QString &src, const DialogLayoutSettings &converter, bool *ok) { - return converter.LayoutToPixels(src.toDouble()); + return converter.LayoutToPixels(src.toDouble(ok)); } //--------------------------------------------------------------------------------------------------------------------- -qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter) +qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter, bool *ok) { - return converter.PageToPixels(src.toDouble()); + return converter.PageToPixels(src.toDouble(ok)); } } // anonymous namespace @@ -175,8 +175,23 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const const_cast(this)->parser.showHelp(V_EX_USAGE); } - diag.SetPaperHeight (Pg2Px(OptionValue(LONG_OPTION_PAGEH), diag)); - diag.SetPaperWidth (Pg2Px(OptionValue(LONG_OPTION_PAGEW), diag)); + bool ok = false; + qreal height = Pg2Px(OptionValue(LONG_OPTION_PAGEH), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid page height value.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + diag.SetPaperHeight(height); + + ok = false; + qreal width = Pg2Px(OptionValue(LONG_OPTION_PAGEW), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid page width value.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + diag.SetPaperWidth(width); } else { // Not explicit page size @@ -197,7 +212,14 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const if (IsOptionSet(LONG_OPTION_GAPWIDTH)) { - diag.SetLayoutWidth(Lo2Px(OptionValue(LONG_OPTION_GAPWIDTH), diag)); + bool ok = false; + qreal width = Lo2Px(OptionValue(LONG_OPTION_GAPWIDTH), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid gap width.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + diag.SetLayoutWidth(width); } diag.SetAutoCropLength(IsOptionSet(LONG_OPTION_CROP_LENGTH)); @@ -216,22 +238,50 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const if (IsOptionSet(LONG_OPTION_LEFT_MARGIN)) { - margins.setLeft(Pg2Px(OptionValue(LONG_OPTION_LEFT_MARGIN), diag)); + bool ok = false; + qreal margin = Pg2Px(OptionValue(LONG_OPTION_LEFT_MARGIN), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid layout page left margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setLeft(margin); } if (IsOptionSet(LONG_OPTION_RIGHT_MARGIN)) { - margins.setRight(Pg2Px(OptionValue(LONG_OPTION_RIGHT_MARGIN), diag)); + bool ok = false; + qreal margin = Pg2Px(OptionValue(LONG_OPTION_RIGHT_MARGIN), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid layout page right margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setRight(margin); } if (IsOptionSet(LONG_OPTION_TOP_MARGIN)) { - margins.setTop(Pg2Px(OptionValue(LONG_OPTION_TOP_MARGIN), diag)); + bool ok = false; + qreal margin = Pg2Px(OptionValue(LONG_OPTION_TOP_MARGIN), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid layout page top margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setTop(margin); } if (IsOptionSet(LONG_OPTION_BOTTOM_MARGIN)) { - margins.setBottom(Pg2Px(OptionValue(LONG_OPTION_BOTTOM_MARGIN), diag)); + bool ok = false; + qreal margin = Pg2Px(OptionValue(LONG_OPTION_BOTTOM_MARGIN), diag, &ok); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid layout page bottom margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setBottom(margin); } diag.SetFields(margins); @@ -592,22 +642,50 @@ auto VCommandLine::TiledPageMargins() const -> QMarginsF if (IsOptionSet(LONG_OPTION_LEFT_MARGIN)) { - margins.setLeft(UnitConvertor(OptionValue(LONG_OPTION_LEFT_MARGIN).toDouble(), unit, Unit::Mm)); + bool ok = false; + qreal margin = UnitConvertor(OptionValue(LONG_OPTION_LEFT_MARGIN).toDouble(&ok), unit, Unit::Mm); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid tiled page left margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setLeft(margin); } if (IsOptionSet(LONG_OPTION_RIGHT_MARGIN)) { - margins.setRight(UnitConvertor(OptionValue(LONG_OPTION_RIGHT_MARGIN).toDouble(), unit, Unit::Mm)); + bool ok = false; + qreal margin = UnitConvertor(OptionValue(LONG_OPTION_RIGHT_MARGIN).toDouble(&ok), unit, Unit::Mm); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid tiled page right margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setLeft(margin); } if (IsOptionSet(LONG_OPTION_TOP_MARGIN)) { - margins.setTop(UnitConvertor(OptionValue(LONG_OPTION_TOP_MARGIN).toDouble(), unit, Unit::Mm)); + bool ok = false; + qreal margin = UnitConvertor(OptionValue(LONG_OPTION_TOP_MARGIN).toDouble(&ok), unit, Unit::Mm); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid tiled page top margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setLeft(margin); } if (IsOptionSet(LONG_OPTION_BOTTOM_MARGIN)) { - margins.setBottom(UnitConvertor(OptionValue(LONG_OPTION_BOTTOM_MARGIN).toDouble(), unit, Unit::Mm)); + bool ok = false; + qreal margin = UnitConvertor(OptionValue(LONG_OPTION_BOTTOM_MARGIN).toDouble(&ok), unit, Unit::Mm); + if (not ok) + { + qCritical() << translate("VCommandLine", "Invalid tiled page bottom margin.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + margins.setLeft(margin); } return margins;