From b673ec0fc73bc84f23fae37bc1322a401cb8137f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 28 Sep 2017 16:05:04 +0300 Subject: [PATCH] Command line options to export final measurements. --HG-- branch : feature --- dist/OBS_debian/debian.valentina.1 | 364 ++++++++++++++++++- dist/debian/valentina.1 | 358 +++++++++++++++++- src/app/tape/tmainwindow.cpp | 3 +- src/app/valentina/core/vcmdexport.cpp | 90 ++++- src/app/valentina/core/vcmdexport.h | 14 + src/app/valentina/mainwindow.cpp | 117 ++++-- src/app/valentina/mainwindow.h | 3 +- src/app/valentina/mainwindowsnogui.cpp | 21 +- src/app/valentina/mainwindowsnogui.h | 2 +- src/libs/vmisc/commandoptions.cpp | 11 +- src/libs/vmisc/commandoptions.h | 5 + src/libs/vmisc/dialogs/dialogexporttocsv.cpp | 37 +- src/libs/vmisc/dialogs/dialogexporttocsv.h | 3 + src/libs/vmisc/qxtcsvmodel.cpp | 14 +- src/libs/vmisc/qxtcsvmodel.h | 5 +- 15 files changed, 986 insertions(+), 61 deletions(-) diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index dc731a0f8..56766c989 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -1,6 +1,6 @@ .\" Manpage for valentina. .\" Contact dismine@gmail.com to correct errors. -.TH valentina 1 "10 March, 2017" "valentina man page" +.TH valentina 1 "28 September, 2017" "valentina man page" .SH NAME Valentina \- Pattern making program. .SH SYNOPSIS @@ -106,6 +106,8 @@ The path to output destination folder. By default the directory at which the app .RB "Export text as paths." .IP "--exportOnlyDetails" .RB "Export only details. Export details as they positioned in the details mode. Any layout related options will be ignored." +.IP "--exportSuchDetails " +.RB "Export only details that match a piece name regex." .IP "-x, --gsize " .RB "Set size value a pattern file, that was opened with multisize measurements " "(export mode)" ". Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm." .IP "-e, --gheight " @@ -193,14 +195,366 @@ The path to output destination folder. By default the directory at which the app Run the program in a test mode. The program in this mode loads a single pattern file and silently quit without showing the main window. The key have priority before key \*(lqbasename\*(rq. .IP "--no-scaling" .RB "Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable." +.IP "--csvWithHeader" +.RB "Export to csv with header. By default disabled." +.IP "--csvCodec " +.RB "Specify codec that will be used to save data. List of supported codecs provided by Qt. Default value depend from system. On Windows, the codec will be based on a system locale. On Unix systems, the codec will might fall back to using the iconv library if no builtin codec for the locale can be found. Valid values usually these:" +.RS +.BR "*" " US-ASCII," +.RE +.RS +.BR "*" " US-ASCII," +.RE +.RS +.BR "*" " ISO-8859-1," +.RE +.RS +.BR "*" " ISO-8859-2," +.RE +.RS +.BR "*" " ISO-8859-3," +.RE +.RS +.BR "*" " ISO-8859-4," +.RE +.RS +.BR "*" " ISO-8859-5," +.RE +.RS +.BR "*" " ISO-8859-6," +.RE +.RS +.BR "*" " ISO-8859-7," +.RE +.RS +.BR "*" " ISO-8859-8," +.RE +.RS +.BR "*" " ISO-8859-9," +.RE +.RS +.BR "*" " ISO-8859-10," +.RE +.RS +.BR "*" " ISO-2022-JP-1," +.RE +.RS +.BR "*" " Shift_JIS," +.RE +.RS +.BR "*" " EUC-JP," +.RE +.RS +.BR "*" " US-ASCII," +.RE +.RS +.BR "*" " windows-949," +.RE +.RS +.BR "*" " ISO-2022-KR," +.RE +.RS +.BR "*" " windows-949," +.RE +.RS +.BR "*" " ISO-2022-JP," +.RE +.RS +.BR "*" " ISO-2022-JP-2," +.RE +.RS +.BR "*" " GBK," +.RE +.RS +.BR "*" " ISO-8859-6," +.RE +.RS +.BR "*" " ISO-8859-6," +.RE +.RS +.BR "*" " ISO-8859-8," +.RE +.RS +.BR "*" " ISO-8859-8," +.RE +.RS +.BR "*" " ISO-2022-CN," +.RE +.RS +.BR "*" " ISO-2022-CN-EXT," +.RE +.RS +.BR "*" " UTF-8," +.RE +.RS +.BR "*" " ISO-8859-13," +.RE +.RS +.BR "*" " ISO-8859-14," +.RE +.RS +.BR "*" " ISO-8859-15," +.RE +.RS +.BR "*" " GBK," +.RE +.RS +.BR "*" " GB18030," +.RE +.RS +.BR "*" " UTF-16," +.RE +.RS +.BR "*" " UTF-32," +.RE +.RS +.BR "*" " SCSU," +.RE +.RS +.BR "*" " UTF-7," +.RE +.RS +.BR "*" " UTF-16BE," +.RE +.RS +.BR "*" " UTF-16LE," +.RE +.RS +.BR "*" " UTF-16," +.RE +.RS +.BR "*" " CESU-8," +.RE +.RS +.BR "*" " UTF-32," +.RE +.RS +.BR "*" " UTF-32BE," +.RE +.RS +.BR "*" " UTF-32LE," +.RE +.RS +.BR "*" " BOCU-1," +.RE +.RS +.BR "*" " hp-roman8," +.RE +.RS +.BR "*" " Adobe-Standard-Encoding," +.RE +.RS +.BR "*" " IBM850," +.RE +.RS +.BR "*" " IBM862," +.RE +.RS +.BR "*" " IBM-Thai," +.RE +.RS +.BR "*" " Shift_JIS," +.RE +.RS +.BR "*" " GBK," +.RE +.RS +.BR "*" " Big5," +.RE +.RS +.BR "*" " macintosh," +.RE +.RS +.BR "*" " IBM037," +.RE +.RS +.BR "*" " IBM273," +.RE +.RS +.BR "*" " IBM277," +.RE +.RS +.BR "*" " IBM278," +.RE +.RS +.BR "*" " IBM280," +.RE +.RS +.BR "*" " IBM284," +.RE +.RS +.BR "*" " IBM285," +.RE +.RS +.BR "*" " IBM290," +.RE +.RS +.BR "*" " IBM297," +.RE +.RS +.BR "*" " IBM420," +.RE +.RS +.BR "*" " IBM424," +.RE +.RS +.BR "*" " IBM437," +.RE +.RS +.BR "*" " IBM500," +.RE +.RS +.BR "*" " cp851," +.RE +.RS +.BR "*" " IBM852," +.RE +.RS +.BR "*" " IBM855," +.RE +.RS +.BR "*" " IBM857," +.RE +.RS +.BR "*" " IBM860," +.RE +.RS +.BR "*" " IBM861," +.RE +.RS +.BR "*" " IBM863," +.RE +.RS +.BR "*" " IBM864," +.RE +.RS +.BR "*" " IBM865," +.RE +.RS +.BR "*" " IBM868," +.RE +.RS +.BR "*" " IBM869," +.RE +.RS +.BR "*" " IBM870," +.RE +.RS +.BR "*" " IBM871," +.RE +.RS +.BR "*" " IBM918," +.RE +.RS +.BR "*" " IBM1026," +.RE +.RS +.BR "*" " KOI8-R," +.RE +.RS +.BR "*" " HZ-GB-2312," +.RE +.RS +.BR "*" " IBM866," +.RE +.RS +.BR "*" " IBM775," +.RE +.RS +.BR "*" " KOI8-U," +.RE +.RS +.BR "*" " IBM00858," +.RE +.RS +.BR "*" " IBM01140," +.RE +.RS +.BR "*" " IBM01141," +.RE +.RS +.BR "*" " IBM01142," +.RE +.RS +.BR "*" " IBM01143," +.RE +.RS +.BR "*" " IBM01144," +.RE +.RS +.BR "*" " IBM01145," +.RE +.RS +.BR "*" " IBM01146," +.RE +.RS +.BR "*" " IBM01147," +.RE +.RS +.BR "*" " IBM01148," +.RE +.RS +.BR "*" " IBM01149," +.RE +.RS +.BR "*" " Big5-HKSCS," +.RE +.RS +.BR "*" " IBM1047," +.RE +.RS +.BR "*" " windows-1250," +.RE +.RS +.BR "*" " windows-1251," +.RE +.RS +.BR "*" " windows-1252," +.RE +.RS +.BR "*" " windows-1253," +.RE +.RS +.BR "*" " windows-1254," +.RE +.RS +.BR "*" " windows-1255," +.RE +.RS +.BR "*" " windows-1256," +.RE +.RS +.BR "*" " windows-1257," +.RE +.RS +.BR "*" " windows-1258," +.RE +.RS +.BR "*" " TIS-620," +.RE +.RS +.BR "*" " TSCII." +.RE +.IP "--csvSeparator " +.RB "Specify csv separator character. Default value is ','. Valid characters:" +.RS +.BR "*" " 'Tab'," +.RE +.RS +.BR "*" " ';'," +.RE +.RS +.BR "*" " 'Space'," +.RE +.RS +.BR "*" " ','." +.RE +.IP "--csvExportFM " +.RB "Calling this command enable exporting final measurements. Specify path to csv file with final measurements. The path must contain path to directory and name of file. It can be absolute or relatetive. In case of relative path will be used current working directory to calc a destination path." .IP Arguments: .I filename \- a pattern file. .SH AUTHOR .RI "This manual page was written by Roman Telezhynskyi <" dismine@gmail.com ">" .SH "SEE ALSO" -.RB "Full " "User Manual" " is availiable in" -.UR https://bitbucket.org/dismine/valentina/wiki/manual/Content -.UE - .BR tape (1) diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index aa5a6c99d..56766c989 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -1,6 +1,6 @@ .\" Manpage for valentina. .\" Contact dismine@gmail.com to correct errors. -.TH valentina 1 "22 September, 2017" "valentina man page" +.TH valentina 1 "28 September, 2017" "valentina man page" .SH NAME Valentina \- Pattern making program. .SH SYNOPSIS @@ -195,6 +195,362 @@ The path to output destination folder. By default the directory at which the app Run the program in a test mode. The program in this mode loads a single pattern file and silently quit without showing the main window. The key have priority before key \*(lqbasename\*(rq. .IP "--no-scaling" .RB "Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable." +.IP "--csvWithHeader" +.RB "Export to csv with header. By default disabled." +.IP "--csvCodec " +.RB "Specify codec that will be used to save data. List of supported codecs provided by Qt. Default value depend from system. On Windows, the codec will be based on a system locale. On Unix systems, the codec will might fall back to using the iconv library if no builtin codec for the locale can be found. Valid values usually these:" +.RS +.BR "*" " US-ASCII," +.RE +.RS +.BR "*" " US-ASCII," +.RE +.RS +.BR "*" " ISO-8859-1," +.RE +.RS +.BR "*" " ISO-8859-2," +.RE +.RS +.BR "*" " ISO-8859-3," +.RE +.RS +.BR "*" " ISO-8859-4," +.RE +.RS +.BR "*" " ISO-8859-5," +.RE +.RS +.BR "*" " ISO-8859-6," +.RE +.RS +.BR "*" " ISO-8859-7," +.RE +.RS +.BR "*" " ISO-8859-8," +.RE +.RS +.BR "*" " ISO-8859-9," +.RE +.RS +.BR "*" " ISO-8859-10," +.RE +.RS +.BR "*" " ISO-2022-JP-1," +.RE +.RS +.BR "*" " Shift_JIS," +.RE +.RS +.BR "*" " EUC-JP," +.RE +.RS +.BR "*" " US-ASCII," +.RE +.RS +.BR "*" " windows-949," +.RE +.RS +.BR "*" " ISO-2022-KR," +.RE +.RS +.BR "*" " windows-949," +.RE +.RS +.BR "*" " ISO-2022-JP," +.RE +.RS +.BR "*" " ISO-2022-JP-2," +.RE +.RS +.BR "*" " GBK," +.RE +.RS +.BR "*" " ISO-8859-6," +.RE +.RS +.BR "*" " ISO-8859-6," +.RE +.RS +.BR "*" " ISO-8859-8," +.RE +.RS +.BR "*" " ISO-8859-8," +.RE +.RS +.BR "*" " ISO-2022-CN," +.RE +.RS +.BR "*" " ISO-2022-CN-EXT," +.RE +.RS +.BR "*" " UTF-8," +.RE +.RS +.BR "*" " ISO-8859-13," +.RE +.RS +.BR "*" " ISO-8859-14," +.RE +.RS +.BR "*" " ISO-8859-15," +.RE +.RS +.BR "*" " GBK," +.RE +.RS +.BR "*" " GB18030," +.RE +.RS +.BR "*" " UTF-16," +.RE +.RS +.BR "*" " UTF-32," +.RE +.RS +.BR "*" " SCSU," +.RE +.RS +.BR "*" " UTF-7," +.RE +.RS +.BR "*" " UTF-16BE," +.RE +.RS +.BR "*" " UTF-16LE," +.RE +.RS +.BR "*" " UTF-16," +.RE +.RS +.BR "*" " CESU-8," +.RE +.RS +.BR "*" " UTF-32," +.RE +.RS +.BR "*" " UTF-32BE," +.RE +.RS +.BR "*" " UTF-32LE," +.RE +.RS +.BR "*" " BOCU-1," +.RE +.RS +.BR "*" " hp-roman8," +.RE +.RS +.BR "*" " Adobe-Standard-Encoding," +.RE +.RS +.BR "*" " IBM850," +.RE +.RS +.BR "*" " IBM862," +.RE +.RS +.BR "*" " IBM-Thai," +.RE +.RS +.BR "*" " Shift_JIS," +.RE +.RS +.BR "*" " GBK," +.RE +.RS +.BR "*" " Big5," +.RE +.RS +.BR "*" " macintosh," +.RE +.RS +.BR "*" " IBM037," +.RE +.RS +.BR "*" " IBM273," +.RE +.RS +.BR "*" " IBM277," +.RE +.RS +.BR "*" " IBM278," +.RE +.RS +.BR "*" " IBM280," +.RE +.RS +.BR "*" " IBM284," +.RE +.RS +.BR "*" " IBM285," +.RE +.RS +.BR "*" " IBM290," +.RE +.RS +.BR "*" " IBM297," +.RE +.RS +.BR "*" " IBM420," +.RE +.RS +.BR "*" " IBM424," +.RE +.RS +.BR "*" " IBM437," +.RE +.RS +.BR "*" " IBM500," +.RE +.RS +.BR "*" " cp851," +.RE +.RS +.BR "*" " IBM852," +.RE +.RS +.BR "*" " IBM855," +.RE +.RS +.BR "*" " IBM857," +.RE +.RS +.BR "*" " IBM860," +.RE +.RS +.BR "*" " IBM861," +.RE +.RS +.BR "*" " IBM863," +.RE +.RS +.BR "*" " IBM864," +.RE +.RS +.BR "*" " IBM865," +.RE +.RS +.BR "*" " IBM868," +.RE +.RS +.BR "*" " IBM869," +.RE +.RS +.BR "*" " IBM870," +.RE +.RS +.BR "*" " IBM871," +.RE +.RS +.BR "*" " IBM918," +.RE +.RS +.BR "*" " IBM1026," +.RE +.RS +.BR "*" " KOI8-R," +.RE +.RS +.BR "*" " HZ-GB-2312," +.RE +.RS +.BR "*" " IBM866," +.RE +.RS +.BR "*" " IBM775," +.RE +.RS +.BR "*" " KOI8-U," +.RE +.RS +.BR "*" " IBM00858," +.RE +.RS +.BR "*" " IBM01140," +.RE +.RS +.BR "*" " IBM01141," +.RE +.RS +.BR "*" " IBM01142," +.RE +.RS +.BR "*" " IBM01143," +.RE +.RS +.BR "*" " IBM01144," +.RE +.RS +.BR "*" " IBM01145," +.RE +.RS +.BR "*" " IBM01146," +.RE +.RS +.BR "*" " IBM01147," +.RE +.RS +.BR "*" " IBM01148," +.RE +.RS +.BR "*" " IBM01149," +.RE +.RS +.BR "*" " Big5-HKSCS," +.RE +.RS +.BR "*" " IBM1047," +.RE +.RS +.BR "*" " windows-1250," +.RE +.RS +.BR "*" " windows-1251," +.RE +.RS +.BR "*" " windows-1252," +.RE +.RS +.BR "*" " windows-1253," +.RE +.RS +.BR "*" " windows-1254," +.RE +.RS +.BR "*" " windows-1255," +.RE +.RS +.BR "*" " windows-1256," +.RE +.RS +.BR "*" " windows-1257," +.RE +.RS +.BR "*" " windows-1258," +.RE +.RS +.BR "*" " TIS-620," +.RE +.RS +.BR "*" " TSCII." +.RE +.IP "--csvSeparator " +.RB "Specify csv separator character. Default value is ','. Valid characters:" +.RS +.BR "*" " 'Tab'," +.RE +.RS +.BR "*" " ';'," +.RE +.RS +.BR "*" " 'Space'," +.RE +.RS +.BR "*" " ','." +.RE +.IP "--csvExportFM " +.RB "Calling this command enable exporting final measurements. Specify path to csv file with final measurements. The path must contain path to directory and name of file. It can be absolute or relatetive. In case of relative path will be used current working directory to calc a destination path." .IP Arguments: .I filename \- a pattern file. diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 914b4b848..0eda95711 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -707,7 +707,8 @@ void TMainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int } } - csv.toCSV(fileName, withHeader, separator, QTextCodec::codecForMib(mib)); + QString error; + csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 9b985e222..286778938 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -33,8 +33,10 @@ #include "../vformat/vmeasurements.h" #include "../vmisc/commandoptions.h" #include "../vmisc/vsettings.h" +#include "../vmisc/dialogs/dialogexporttocsv.h" #include "../vlayout/vlayoutgenerator.h" #include +#include VCommandLinePtr VCommandLine::instance = nullptr; @@ -278,6 +280,46 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap "enabled). Alternatively you can use the " "%1 environment variable.") .arg("QT_AUTO_SCREEN_SCALE_FACTOR=0"))); + + //================================================================================================================= + optionsIndex.insert(LONG_OPTION_CSVWITHHEADER, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_CSVWITHHEADER, + translate("VCommandLine", "Export to csv with header. By default " + "disabled."))); + + optionsIndex.insert(LONG_OPTION_CSVCODEC, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_CSVCODEC, + translate("VCommandLine", "Specify codec that will be used to save data. List" + " of supported codecs provided by Qt. Default " + "value depend from system. On Windows, the codec " + "will be based on a system locale. On Unix " + "systems, the codec will might fall back to using " + "the iconv library if no builtin codec for the " + "locale can be found. Valid values for this " + "installation:") + + DialogExportToCSV::MakeHelpCodecsList(), + translate("VCommandLine", "Codec name"), QString("%1") + .arg(QString(QTextCodec::codecForLocale()->name())))); + + optionsIndex.insert(LONG_OPTION_CSVSEPARATOR, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_CSVSEPARATOR, + translate("VCommandLine", "Specify csv separator character. Default value " + "is '%1'. Valid characters:") + .arg(VCommonSettings::GetDefCSVSeparator()) + + DialogExportToCSV::MakeHelpSeparatorList(), + translate("VCommandLine", "Separator character"), QString("%1") + .arg(VCommonSettings::GetDefCSVSeparator()))); + + optionsIndex.insert(LONG_OPTION_CSVEXPORTFM, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_CSVEXPORTFM, + translate("VCommandLine", "Calling this command enable exporting final " + "measurements. Specify path to csv file with " + "final measurements. The path must contain path " + "to directory and name of file. It can be " + "absolute or relatetive. In case of " + "relative path will be used current working " + "directory to calc a destination path."), + translate("VCommandLine", "Path to csv file"))); } //------------------------------------------------------------------------------------------------------ @@ -499,7 +541,9 @@ VCommandLinePtr VCommandLine::Get(const QCoreApplication& app) instance->parser.process(app); //fixme: in case of additional options/modes which will need to disable GUI - add it here too - instance->isGuiEnabled = not (instance->IsExportEnabled() || instance->IsTestModeEnabled()); + instance->isGuiEnabled = not (instance->IsExportEnabled() + || instance->IsTestModeEnabled() + || instance->IsExportFMEnabled()); return instance; } @@ -547,6 +591,18 @@ bool VCommandLine::IsExportEnabled() const return r; } +//--------------------------------------------------------------------------------------------------------------------- +bool VCommandLine::IsExportFMEnabled() const +{ + const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CSVEXPORTFM))); + if (r && parser.positionalArguments().size() != 1) + { + qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + return r; +} + //------------------------------------------------------------------------------------------------------ DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const { @@ -655,6 +711,12 @@ int VCommandLine::IsExportOnlyDetails() const return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXPORTONLYDETAILS))); } +//--------------------------------------------------------------------------------------------------------------------- +int VCommandLine::IsCSVWithHeader() const +{ + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CSVWITHHEADER))); +} + //--------------------------------------------------------------------------------------------------------------------- QString VCommandLine::OptExportSuchDetails() const { @@ -667,6 +729,32 @@ QString VCommandLine::OptExportSuchDetails() const return path; } +//--------------------------------------------------------------------------------------------------------------------- +QString VCommandLine::OptCSVCodecName() const +{ + return parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CSVCODEC))); +} + +//--------------------------------------------------------------------------------------------------------------------- +QChar VCommandLine::OptCSVSeparator() const +{ + const QString value = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CSVSEPARATOR))); + if (not value.isEmpty()) + { + return value.at(0); + } + else + { + return QChar(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VCommandLine::OptExportFMTo() const +{ + return parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CSVEXPORTFM))); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VCommandLine::OptInputFileNames() const { diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index 936e731a8..96d1e310e 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -62,6 +62,10 @@ public: //export enabled bool IsExportEnabled() const; + //@brief tests if user enabled export final measurements from cmd, throws exception if not exactly 1 input VAL + //file supplied in case export enabled + bool IsExportFMEnabled() const; + //@brief returns path to custom measure file or empty string QString OptMeasurePath() const; @@ -78,10 +82,20 @@ public: int IsBinaryDXF() const; int IsTextAsPaths() const; int IsExportOnlyDetails() const; + int IsCSVWithHeader() const; //@brief returns the piece name regex or empty string if not set QString OptExportSuchDetails() const; + //@brief returns user selected csv codec or empty string if not set + QString OptCSVCodecName() const; + + //@brief returns user selected csv separator or empty string if not set + QChar OptCSVSeparator() const; + + //@brief returns the destination path for export final measurements or empty string if not set + QString OptExportFMTo() const; + //generator creation is moved here ... because most options are for it only, so no need to create extra getters... //@brief creates VLayoutGenerator VLayoutGeneratorPtr DefaultGenerator() const; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 3800f0275..960a1700b 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1535,7 +1535,8 @@ void MainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int m SavePreviewCalculation(false); SavePreviewCalculation(true); - csv.toCSV(fileName, withHeader, separator, QTextCodec::codecForMib(mib)); + QString error; + csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib)); } //--------------------------------------------------------------------------------------------------------------------- @@ -4841,7 +4842,7 @@ void MainWindow::ZoomFirstShow() } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::DoExport(const VCommandLinePtr &expParams) +bool MainWindow::DoExport(const VCommandLinePtr &expParams) { QHash details; if(not qApp->getOpeningPattern()) @@ -4851,7 +4852,7 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) { qCCritical(vMainWindow, "%s", qUtf8Printable(tr("You can't export empty scene."))); qApp->exit(V_EX_DATAERR); - return; + return false; } else { @@ -4887,7 +4888,7 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) qCCritical(vMainWindow, "%s", qUtf8Printable(tr("You can't export empty scene. Please, " "include at least one detail in layout."))); qApp->exit(V_EX_DATAERR); - return; + return false; } } } @@ -4910,7 +4911,7 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) { qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Export error.")), qUtf8Printable(e.ErrorMessage())); qApp->exit(V_EX_DATAERR); - return; + return false; } } else @@ -4934,16 +4935,61 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Export error.")), qUtf8Printable(e.ErrorMessage())); qApp->exit(V_EX_DATAERR); - return; + return false; } } else { - return; + qApp->exit(V_EX_DATAERR); + return false; } } - qApp->exit(V_EX_OK); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief DoFMExport process export final measurements + * @param expParams command line options + * @return true if succesfull + */ +bool MainWindow::DoFMExport(const VCommandLinePtr &expParams) +{ + QString filePath = expParams->OptExportFMTo(); + + if (filePath.isEmpty()) + { + qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Export final measurements error.")), + qUtf8Printable(tr("Destination path is empty."))); + qApp->exit(V_EX_DATAERR); + return false; + } + + QFileInfo info(filePath); + if (info.isRelative()) + { + filePath = QDir::currentPath() + QLatin1Char('/') + filePath; + } + + const QString codecName = expParams->OptCSVCodecName(); + int mib = QTextCodec::codecForLocale()->mibEnum(); + if (not codecName.isEmpty()) + { + if (QTextCodec *codec = QTextCodec::codecForName(codecName.toLatin1())) + { + mib = codec->mibEnum(); + } + } + + QChar separator = expParams->OptCSVSeparator(); + if (separator.isNull()) + { + separator = VCommonSettings::GetDefCSVSeparator(); + } + + return ExportFMeasurementsToCSVData(filePath, expParams->IsCSVWithHeader(), mib, separator); + } //--------------------------------------------------------------------------------------------------------------------- @@ -5043,6 +5089,11 @@ void MainWindow::ProcessCMD() if (VApplication::IsGUIMode()) { ReopenFilesAfterCrash(args); + + for (int i=0, sz = args.size(); i < sz; ++i) + { + LoadPattern(args.at(i)); + } } else { @@ -5052,53 +5103,45 @@ void MainWindow::ProcessCMD() qApp->exit(V_EX_NOINPUT); return; } - } - for (int i=0, sz = args.size(); i < sz; ++i) - { - const bool loaded = LoadPattern(args.at(static_cast(i)), cmd->OptMeasurePath()); + const bool loaded = LoadPattern(args.first(), cmd->OptMeasurePath()); - if (not loaded && not VApplication::IsGUIMode()) + if (not loaded) { return; // process only one input file } bool hSetted = true; bool sSetted = true; - if (loaded && (cmd->IsTestModeEnabled() || cmd->IsExportEnabled())) + if (cmd->IsSetGradationSize()) { - if (cmd->IsSetGradationSize()) - { - sSetted = SetSize(cmd->OptGradationSize()); - } + sSetted = SetSize(cmd->OptGradationSize()); + } - if (cmd->IsSetGradationHeight()) - { - hSetted = SetHeight(cmd->OptGradationHeight()); - } + if (cmd->IsSetGradationHeight()) + { + hSetted = SetHeight(cmd->OptGradationHeight()); + } + + if (not (hSetted && sSetted)) + { + qApp->exit(V_EX_DATAERR); + return; } if (not cmd->IsTestModeEnabled()) { - if (cmd->IsExportEnabled()) + if (cmd->IsExportEnabled() && not DoExport(cmd)) { - if (loaded && hSetted && sSetted) - { - DoExport(cmd); - return; // process only one input file - } - else - { - qApp->exit(V_EX_DATAERR); - return; - } - break; + return; + } + + if (cmd->IsExportFMEnabled() && not DoFMExport(cmd)) + { + return; } } - } - if (not VApplication::IsGUIMode()) - { qApp->exit(V_EX_OK);// close program after processing in console mode } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 627820e6e..7f5aa5f39 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -351,7 +351,8 @@ private: void CheckRequiredMeasurements(const VMeasurements *m); void ReopenFilesAfterCrash(QStringList &args); - void DoExport(const VCommandLinePtr& expParams); + bool DoExport(const VCommandLinePtr& expParams); + bool DoFMExport(const VCommandLinePtr& expParams); bool SetSize(const QString &text); bool SetHeight(const QString & text); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index fa11912d2..53e92b835 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1572,7 +1572,7 @@ void MainWindowsNoGUI::SetSizeHeightForIndividualM() const } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib, +bool MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator) const { QxtCsvModel csv; @@ -1617,7 +1617,7 @@ void MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, boo { qApp->exit(V_EX_DATAERR); } - return; + return false; } } catch (qmu::QmuParserError &e) @@ -1628,12 +1628,25 @@ void MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, boo { qApp->exit(V_EX_DATAERR); } - return; + return false; } } } - csv.toCSV(fileName, withHeader, separator, QTextCodec::codecForMib(mib)); + QString error; + const bool success = csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib)); + + if (not success) + { + qCritical("%s\n\n%s", qUtf8Printable(tr("Export final measurements error.")), + qUtf8Printable(tr("File error %1.").arg(error))); + if (not VApplication::IsGUIMode()) + { + qApp->exit(V_EX_CANTCREAT); + } + } + + return success; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 4df454544..6591f0bc4 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -103,7 +103,7 @@ protected: QString FileName() const; void SetSizeHeightForIndividualM() const; - void ExportFMeasurementsToCSVData(const QString &fileName, + bool ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator) const; private slots: void PrintPages (QPrinter *printer); diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp index 7ed308473..54c70ce06 100644 --- a/src/libs/vmisc/commandoptions.cpp +++ b/src/libs/vmisc/commandoptions.cpp @@ -111,6 +111,11 @@ const QString SINGLE_OPTION_TOP_MARGIN = QStringLiteral("T"); const QString LONG_OPTION_BOTTOM_MARGIN = QStringLiteral("bmargin"); const QString SINGLE_OPTION_BOTTOM_MARGIN = QStringLiteral("B"); +const QString LONG_OPTION_CSVWITHHEADER = QStringLiteral("csvWithHeader"); +const QString LONG_OPTION_CSVCODEC = QStringLiteral("csvCodec"); +const QString LONG_OPTION_CSVSEPARATOR = QStringLiteral("csvSeparator"); +const QString LONG_OPTION_CSVEXPORTFM = QStringLiteral("csvExportFM"); + //--------------------------------------------------------------------------------------------------------------------- QStringList AllKeys() { @@ -143,7 +148,11 @@ QStringList AllKeys() << LONG_OPTION_RIGHT_MARGIN << SINGLE_OPTION_RIGHT_MARGIN << LONG_OPTION_TOP_MARGIN << SINGLE_OPTION_TOP_MARGIN << LONG_OPTION_BOTTOM_MARGIN << SINGLE_OPTION_BOTTOM_MARGIN - << LONG_OPTION_NO_HDPI_SCALING; + << LONG_OPTION_NO_HDPI_SCALING + << LONG_OPTION_CSVWITHHEADER + << LONG_OPTION_CSVCODEC + << LONG_OPTION_CSVSEPARATOR + << LONG_OPTION_CSVEXPORTFM; return list; } diff --git a/src/libs/vmisc/commandoptions.h b/src/libs/vmisc/commandoptions.h index 5a3cc581b..9386e1f07 100644 --- a/src/libs/vmisc/commandoptions.h +++ b/src/libs/vmisc/commandoptions.h @@ -108,6 +108,11 @@ extern const QString SINGLE_OPTION_TOP_MARGIN; extern const QString LONG_OPTION_BOTTOM_MARGIN; extern const QString SINGLE_OPTION_BOTTOM_MARGIN; +extern const QString LONG_OPTION_CSVWITHHEADER; +extern const QString LONG_OPTION_CSVCODEC; +extern const QString LONG_OPTION_CSVSEPARATOR; +extern const QString LONG_OPTION_CSVEXPORTFM; + QStringList AllKeys(); #endif // COMMANDOPTIONS_H diff --git a/src/libs/vmisc/dialogs/dialogexporttocsv.cpp b/src/libs/vmisc/dialogs/dialogexporttocsv.cpp index 8584d305c..89a845712 100644 --- a/src/libs/vmisc/dialogs/dialogexporttocsv.cpp +++ b/src/libs/vmisc/dialogs/dialogexporttocsv.cpp @@ -51,7 +51,7 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent) ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(VCommonSettings::GetDefCSVCodec())); - SetSeparator(qApp->Settings()->GetDefCSVSeparator()); + SetSeparator(VCommonSettings::GetDefCSVSeparator()); QPushButton *bDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults); SCASSERT(bDefaults != nullptr) @@ -60,7 +60,7 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent) ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetDefCSVWithHeader()); ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(VCommonSettings::GetDefCSVCodec())); - SetSeparator(qApp->Settings()->GetDefCSVSeparator()); + SetSeparator(VCommonSettings::GetDefCSVSeparator()); }); } @@ -126,7 +126,7 @@ QChar DialogExportToCSV::GetSeparator() const } else { - return QChar(','); + return VCommonSettings::GetDefCSVSeparator(); } } @@ -184,3 +184,34 @@ void DialogExportToCSV::SetSeparator(const QChar &separator) break; } } + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogExportToCSV::MakeHelpCodecsList() +{ + QString out("\n"); + const QList list = QTextCodec::availableMibs(); + for (int i = 0; i < list.size(); ++i) + { + out += QLatin1String("\t* ") + QTextCodec::codecForMib(list.at(i))->name(); + if (i < list.size()-1) + { + out += QLatin1String(",\n"); + } + else + { + out += QLatin1String(".\n"); + } + } + return out; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogExportToCSV::MakeHelpSeparatorList() +{ + QString out("\n"); + out += QLatin1String("\t* 'Tab',\n"); + out += QLatin1String("\t* ';',\n"); + out += QLatin1String("\t* 'Space',\n"); + out += QLatin1String("\t* ','.\n"); + return out; +} diff --git a/src/libs/vmisc/dialogs/dialogexporttocsv.h b/src/libs/vmisc/dialogs/dialogexporttocsv.h index d1782aa26..8e59334b8 100644 --- a/src/libs/vmisc/dialogs/dialogexporttocsv.h +++ b/src/libs/vmisc/dialogs/dialogexporttocsv.h @@ -53,6 +53,9 @@ public: QChar GetSeparator() const; void SetSeparator(const QChar &separator); + static QString MakeHelpCodecsList(); + static QString MakeHelpSeparatorList(); + protected: virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; diff --git a/src/libs/vmisc/qxtcsvmodel.cpp b/src/libs/vmisc/qxtcsvmodel.cpp index 33573205a..a5644303b 100644 --- a/src/libs/vmisc/qxtcsvmodel.cpp +++ b/src/libs/vmisc/qxtcsvmodel.cpp @@ -591,7 +591,7 @@ static QString qxt_addCsvQuotes(QxtCsvModel::QuoteMode mode, QString field) to output a row of headers at the top of the file. */ // cppcheck-suppress funcArgNamesDifferent -void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator, QTextCodec* codec) const +bool QxtCsvModel::toCSV(QIODevice* dest, QString &error, bool withHeader, QChar separator, QTextCodec* codec) const { const QxtCsvModelPrivate& d_ptr = qxt_d(); int row, col, rows, cols; @@ -600,7 +600,11 @@ void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator, QText QString data; if (not dest->isOpen()) { - dest->open(QIODevice::WriteOnly | QIODevice::Truncate); + if ( not dest->open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + error = dest->errorString(); + return false; + } } QTextStream stream(dest); if (codec) @@ -643,6 +647,7 @@ void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator, QText } stream << flush; dest->close(); + return true; } /*! @@ -653,10 +658,11 @@ void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator, QText Fields in the output file will be separated by \a separator. Set \a withHeader to true to output a row of headers at the top of the file. */ -void QxtCsvModel::toCSV(const QString &filename, bool withHeader, QChar separator, QTextCodec* codec) const +bool QxtCsvModel::toCSV(const QString &filename, QString &error, bool withHeader, QChar separator, + QTextCodec* codec) const { QFile dest(filename); - toCSV(&dest, withHeader, separator, codec); + return toCSV(&dest, error, withHeader, separator, codec); } /*! diff --git a/src/libs/vmisc/qxtcsvmodel.h b/src/libs/vmisc/qxtcsvmodel.h index b43a6c340..3c380eba8 100644 --- a/src/libs/vmisc/qxtcsvmodel.h +++ b/src/libs/vmisc/qxtcsvmodel.h @@ -93,8 +93,9 @@ public: void setSource(const QString &filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr); - void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr) const; - void toCSV(const QString &filename, bool withHeader = false, QChar separator = ',', + bool toCSV(QIODevice *file, QString &error, bool withHeader = false, QChar separator = ',', + QTextCodec* codec = nullptr) const; + bool toCSV(const QString &filename, QString &error, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr) const; enum QuoteOption { NoQuotes = 0,