From bdc88401842628ef2c026193572b3a66885f94f9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 22 Sep 2017 19:16:16 +0300 Subject: [PATCH] Resolved issue #756. New feature. Select pieces from command line. --HG-- branch : develop --- ChangeLog.txt | 1 + dist/debian/valentina.1 | 8 ++--- src/app/valentina/core/vapplication.cpp | 3 ++ src/app/valentina/core/vcmdexport.cpp | 18 +++++++++++ src/app/valentina/core/vcmdexport.h | 3 ++ src/app/valentina/mainwindow.cpp | 40 ++++++++++++++++++++----- src/app/valentina/mainwindow.h | 2 +- src/libs/vmisc/commandoptions.cpp | 1 + src/libs/vmisc/commandoptions.h | 1 + 9 files changed, 64 insertions(+), 13 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0ef6aa188..eb83c1edf 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -19,6 +19,7 @@ - Added new language Polish (Poland). - [#755] New feature. Toggle point label. - Fixed bug. After full parse undocommand Move labe losts connection to tool. +- [#756] New feature. Select pieces from command line. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index dc731a0f8..aa5a6c99d 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 "10 March, 2017" "valentina man page" +.TH valentina 1 "22 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 " @@ -199,8 +201,4 @@ Run the program in a test mode. The program in this mode loads a single pattern .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/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index db40c053a..cd3ec0029 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -504,6 +504,7 @@ void VApplication::BeginLogging() //--------------------------------------------------------------------------------------------------------------------- void VApplication::ClearOldLogs() const { + const QString workingDirectory = QDir::currentPath();// Save the app working directory QDir logsDir(LogDirPath()); logsDir.setNameFilters(QStringList("*.log")); logsDir.setCurrent(LogDirPath()); @@ -541,6 +542,8 @@ void VApplication::ClearOldLogs() const { qCDebug(vApp, "There are no old logs."); } + + QDir::setCurrent(workingDirectory); // Restore working directory } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 5e0862e07..9b985e222 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -114,6 +114,12 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap "positioned in the details mode. Any layout related" " options will be ignored."))); + optionsIndex.insert(LONG_OPTION_EXPORTSUCHDETAILS, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_EXPORTSUCHDETAILS, + translate("VCommandLine", "Export only details that match a piece name " + "regex."), + translate("VCommandLine", "The name regex"))); + optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++); options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE, translate("VCommandLine", "Set size value a pattern file, that was opened " @@ -649,6 +655,18 @@ int VCommandLine::IsExportOnlyDetails() const return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXPORTONLYDETAILS))); } +//--------------------------------------------------------------------------------------------------------------------- +QString VCommandLine::OptExportSuchDetails() const +{ + QString path; + if (IsExportEnabled()) + { + path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXPORTSUCHDETAILS))); + } + + return path; +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VCommandLine::OptInputFileNames() const { diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index 429947578..936e731a8 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -79,6 +79,9 @@ public: int IsTextAsPaths() const; int IsExportOnlyDetails() const; + //@brief returns the piece name regex or empty string if not set + QString OptExportSuchDetails() 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 3e1b0fcf3..a63c9a0c7 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4168,10 +4168,18 @@ MainWindow::~MainWindow() * @brief LoadPattern open pattern file. * @param fileName name of file. */ -bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasureFile) +bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) { qCDebug(vMainWindow, "Loading new file %s.", qUtf8Printable(fileName)); + { // Convert to absolute path is need + QFileInfo info(fileName); + if (info.isRelative()) + { + fileName = QDir::currentPath() + QLatin1Char('/') + fileName; + } + } + //We have unsaved changes or load more then one file per time if (OpenNewValentina(fileName)) { @@ -4811,14 +4819,31 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) } else { - QHash::const_iterator i = allDetails->constBegin(); - while (i != allDetails->constEnd()) + const QString nameRegex = expParams->OptExportSuchDetails(); + if (nameRegex.isEmpty()) { - if (i.value().IsInLayout()) + QHash::const_iterator i = allDetails->constBegin(); + while (i != allDetails->constEnd()) { - details.insert(i.key(), i.value()); + if (i.value().IsInLayout()) + { + details.insert(i.key(), i.value()); + } + ++i; + } + } + else + { + const QRegularExpression nameRe(nameRegex); + QHash::const_iterator i = allDetails->constBegin(); + while (i != allDetails->constEnd()) + { + if (nameRe.match(i.value().GetName()).hasMatch()) + { + details.insert(i.key(), i.value()); + } + ++i; } - ++i; } if (details.count() == 0) @@ -4870,7 +4895,8 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) } catch (const VException &e) { - qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Export error.")), qUtf8Printable(e.ErrorMessage())); + qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Export error.")), + qUtf8Printable(e.ErrorMessage())); qApp->exit(V_EX_DATAERR); return; } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 39e3656ed..47a5d651c 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -61,7 +61,7 @@ public: explicit MainWindow(QWidget *parent = nullptr); virtual ~MainWindow() Q_DECL_OVERRIDE; - bool LoadPattern(const QString &fileName, const QString &customMeasureFile = QString()); + bool LoadPattern(QString fileName, const QString &customMeasureFile = QString()); public slots: void ProcessCMD(); diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp index 0d45a6df4..49f087257 100644 --- a/src/libs/vmisc/commandoptions.cpp +++ b/src/libs/vmisc/commandoptions.cpp @@ -52,6 +52,7 @@ const QString SINGLE_OPTION_EXP2FORMAT = QStringLiteral("f"); const QString LONG_OPTION_BINARYDXF = QStringLiteral("bdxf"); const QString LONG_OPTION_TEXT2PATHS = QStringLiteral("text2paths"); const QString LONG_OPTION_EXPORTONLYDETAILS = QStringLiteral("exportOnlyDetails"); +const QString LONG_OPTION_EXPORTSUCHDETAILS = QStringLiteral("exportSuchDetails"); const QString LONG_OPTION_ROTATE = QStringLiteral("rotate"); const QString SINGLE_OPTION_ROTATE = QStringLiteral("r"); diff --git a/src/libs/vmisc/commandoptions.h b/src/libs/vmisc/commandoptions.h index 0ac1af09c..5a3cc581b 100644 --- a/src/libs/vmisc/commandoptions.h +++ b/src/libs/vmisc/commandoptions.h @@ -49,6 +49,7 @@ extern const QString SINGLE_OPTION_EXP2FORMAT; extern const QString LONG_OPTION_BINARYDXF; extern const QString LONG_OPTION_TEXT2PATHS; extern const QString LONG_OPTION_EXPORTONLYDETAILS; +extern const QString LONG_OPTION_EXPORTSUCHDETAILS; extern const QString LONG_OPTION_ROTATE; extern const QString SINGLE_OPTION_ROTATE;