Changes in command line options. New key "basename" and "destination".
--HG-- branch : develop
This commit is contained in:
parent
7eff8e8b9c
commit
67240af260
|
@ -5,8 +5,11 @@
|
||||||
|
|
||||||
VCommandLinePtr VCommandLine::instance = nullptr;
|
VCommandLinePtr VCommandLine::instance = nullptr;
|
||||||
|
|
||||||
const static auto LONG_OPTION_OUTFILE = QStringLiteral("outfile");
|
const static auto LONG_OPTION_BASENAME = QStringLiteral("basename");
|
||||||
const static auto SINGLE_OPTION_OUTFILE = QStringLiteral("o");
|
const static auto SINGLE_OPTION_BASENAME = QStringLiteral("b");
|
||||||
|
|
||||||
|
const static auto LONG_OPTION_DESTINATION = QStringLiteral("destination");
|
||||||
|
const static auto SINGLE_OPTION_DESTINATION = QStringLiteral("d");
|
||||||
|
|
||||||
const static auto LONG_OPTION_MEASUREFILE = QStringLiteral("mfile");
|
const static auto LONG_OPTION_MEASUREFILE = QStringLiteral("mfile");
|
||||||
const static auto SINGLE_OPTION_MEASUREFILE = QStringLiteral("m");
|
const static auto SINGLE_OPTION_MEASUREFILE = QStringLiteral("m");
|
||||||
|
@ -62,10 +65,16 @@ VCommandLine::VCommandLine() : parser()
|
||||||
//keep in mind order here - that is how user will see it, so group-up for usability
|
//keep in mind order here - that is how user will see it, so group-up for usability
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
{LONG_OPTION_OUTFILE,
|
{LONG_OPTION_BASENAME,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_OUTFILE << LONG_OPTION_OUTFILE,
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME,
|
||||||
tr("Path to output exported layout file. Use it to enable console export mode."),
|
tr("The base filename of exported layout files. Use it to enable console export "
|
||||||
tr("The exported layout file"))},
|
"mode."),
|
||||||
|
tr("The base filename of layout files"))},
|
||||||
|
|
||||||
|
{LONG_OPTION_DESTINATION,
|
||||||
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION,
|
||||||
|
tr("The path to output destination folder."),
|
||||||
|
tr("The destination folder"))},
|
||||||
|
|
||||||
{LONG_OPTION_MEASUREFILE,
|
{LONG_OPTION_MEASUREFILE,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
|
||||||
|
@ -87,18 +96,18 @@ VCommandLine::VCommandLine() : parser()
|
||||||
|
|
||||||
{LONG_OPTION_PAGEW,
|
{LONG_OPTION_PAGEW,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
|
||||||
tr("Page width in current units like 12.0 (cannot be used with \"")
|
tr("Page width in current units like 12.0 (cannot be used with \"%1\", export "
|
||||||
+LONG_OPTION_PAGETEMPLATE+tr("\", export mode)."), tr("The page width"))},
|
"mode).").arg(LONG_OPTION_PAGETEMPLATE), tr("The page width"))},
|
||||||
|
|
||||||
{LONG_OPTION_PAGEH,
|
{LONG_OPTION_PAGEH,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
|
||||||
tr("Page height in current units like 12.0 (cannot be used with \"")
|
tr("Page height in current units like 12.0 (cannot be used with \"%1\", export "
|
||||||
+LONG_OPTION_PAGETEMPLATE+tr("\", export mode)."), ("The page height"))},
|
"mode).").arg(LONG_OPTION_PAGETEMPLATE), ("The page height"))},
|
||||||
|
|
||||||
{LONG_OPTION_PAGEUNITS,
|
{LONG_OPTION_PAGEUNITS,
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
|
||||||
tr("Page height/width measure units (cannot be used with \"")+
|
tr("Page height/width measure units (cannot be used with \"%1\", export mode): ")
|
||||||
LONG_OPTION_PAGETEMPLATE+tr("\", export mode): ") + VDomDocument::UnitsHelpString(),
|
.arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(),
|
||||||
tr("The measure unit"))},
|
tr("The measure unit"))},
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
@ -145,7 +154,7 @@ VCommandLine::VCommandLine() : parser()
|
||||||
new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST,
|
new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST,
|
||||||
tr("Run the program in a test mode. The program this mode load a single pattern "
|
tr("Run the program in a test mode. The program this mode load a single pattern "
|
||||||
"file and silently quit without showing the main window. The key have priority "
|
"file and silently quit without showing the main window. The key have priority "
|
||||||
"before key '%1'.").arg(LONG_OPTION_OUTFILE))}
|
"before key '%1'.").arg(LONG_OPTION_BASENAME))}
|
||||||
}),
|
}),
|
||||||
isGuiEnabled(false)
|
isGuiEnabled(false)
|
||||||
{
|
{
|
||||||
|
@ -327,7 +336,7 @@ bool VCommandLine::IsTestModeEnabled() const
|
||||||
//------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------
|
||||||
bool VCommandLine::IsExportEnabled() const
|
bool VCommandLine::IsExportEnabled() const
|
||||||
{
|
{
|
||||||
const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_OUTFILE));
|
const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_BASENAME));
|
||||||
if (r && parser.positionalArguments().size() != 1)
|
if (r && parser.positionalArguments().size() != 1)
|
||||||
{
|
{
|
||||||
qCritical() << tr("Export options can be used with single input file only.") << "/n";
|
qCritical() << tr("Export options can be used with single input file only.") << "/n";
|
||||||
|
@ -384,19 +393,31 @@ QString VCommandLine::OptMeasurePath() const
|
||||||
return measure;
|
return measure;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VCommandLine::OptExportPath() const
|
QString VCommandLine::OptBaseName() const
|
||||||
{
|
{
|
||||||
QString path;
|
QString path;
|
||||||
if (IsExportEnabled())
|
if (IsExportEnabled())
|
||||||
{
|
{
|
||||||
path = parser.value(*optionsUsed.value(LONG_OPTION_OUTFILE));
|
path = parser.value(*optionsUsed.value(LONG_OPTION_BASENAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VCommandLine::OptDestinationPath() const
|
||||||
|
{
|
||||||
|
QString path;
|
||||||
|
if (IsExportEnabled())
|
||||||
|
{
|
||||||
|
path = parser.value(*optionsUsed.value(LONG_OPTION_DESTINATION));
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int VCommandLine::OptExportType() const
|
int VCommandLine::OptExportType() const
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
|
@ -63,8 +63,11 @@ public:
|
||||||
//@brief returns path to custom measure file or empty string
|
//@brief returns path to custom measure file or empty string
|
||||||
QString OptMeasurePath() const;
|
QString OptMeasurePath() const;
|
||||||
|
|
||||||
//@brief returns export path or empty string if not set
|
//@brief returns the base name of layout files or empty string if not set
|
||||||
QString OptExportPath() const;
|
QString OptBaseName() const;
|
||||||
|
|
||||||
|
//@brief returns the absolute path to output destination directory or path to application's current directory if not set
|
||||||
|
QString OptDestinationPath() const;
|
||||||
|
|
||||||
//@brief returns export type set, defaults 0 - svg
|
//@brief returns export type set, defaults 0 - svg
|
||||||
int OptExportType() const;
|
int OptExportType() const;
|
||||||
|
|
|
@ -40,10 +40,13 @@
|
||||||
|
|
||||||
using namespace nm_DialogSaveLayout;
|
using namespace nm_DialogSaveLayout;
|
||||||
|
|
||||||
|
const QString baseFilenameRegExp = QStringLiteral("^[\\w\\-. ]+$");
|
||||||
|
|
||||||
bool VFrmWithTest::havePdf = false;
|
bool VFrmWithTest::havePdf = false;
|
||||||
bool VFrmWithTest::tested = false;
|
bool VFrmWithTest::tested = false;
|
||||||
|
|
||||||
const std::vector<VFrmWithTest> DialogSaveLayout::availFormats = {
|
const std::vector<VFrmWithTest> DialogSaveLayout::availFormats =
|
||||||
|
{
|
||||||
VFrmWithTest(tr("Svg files (*.svg)"), ".svg"),
|
VFrmWithTest(tr("Svg files (*.svg)"), ".svg"),
|
||||||
VFrmWithTest(tr("PDF files (*.pdf)"), ".pdf"),
|
VFrmWithTest(tr("PDF files (*.pdf)"), ".pdf"),
|
||||||
VFrmWithTest(tr("Images (*.png)"), ".png"),
|
VFrmWithTest(tr("Images (*.png)"), ".png"),
|
||||||
|
@ -55,8 +58,7 @@ const std::vector<VFrmWithTest> DialogSaveLayout::availFormats = {
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName,
|
DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget *parent)
|
||||||
QWidget *parent)
|
|
||||||
:QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count)
|
:QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
@ -67,16 +69,33 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName,
|
||||||
SCASSERT(bOk != nullptr);
|
SCASSERT(bOk != nullptr);
|
||||||
bOk->setEnabled(false);
|
bOk->setEnabled(false);
|
||||||
|
|
||||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(QRegularExpression("^[\\w\\-. ]+$"), this);
|
QRegularExpressionValidator *validator = new QRegularExpressionValidator(QRegularExpression(baseFilenameRegExp),
|
||||||
|
this);
|
||||||
ui->lineEditFileName->setValidator(validator);
|
ui->lineEditFileName->setValidator(validator);
|
||||||
ui->lineEditFileName->setText(fileName+"_");
|
const QString mask = fileName+QLatin1Literal("_");
|
||||||
|
if (VApplication::CheckGUI())
|
||||||
|
{
|
||||||
|
ui->lineEditFileName->setText(mask);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (QRegularExpression(baseFilenameRegExp).match(mask).hasMatch())
|
||||||
|
{
|
||||||
|
ui->lineEditFileName->setText(mask);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCritical() << tr("The base filename has not match regular expression.");
|
||||||
|
std::exit(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (auto& v , availFormats)
|
foreach (auto& v , availFormats)
|
||||||
{
|
{
|
||||||
if (v.test())
|
if (v.test())
|
||||||
{
|
{
|
||||||
ui->comboBoxFormat->addItem(v.pair.first, QVariant(v.pair.second));
|
ui->comboBoxFormat->addItem(v.pair.first, QVariant(v.pair.second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
|
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
|
||||||
connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample);
|
connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample);
|
||||||
|
@ -126,17 +145,30 @@ QString DialogSaveLayout::MakeHelpFormatList()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogSaveLayout::SetFullPath(const QString &cmdFileName)
|
void DialogSaveLayout::SetDestinationPath(const QString &cmdDestinationPath)
|
||||||
{
|
{
|
||||||
QFileInfo fn(cmdFileName);
|
QString path;
|
||||||
fn.makeAbsolute();
|
if (cmdDestinationPath.isEmpty())
|
||||||
auto p = fn.dir().absolutePath();
|
{
|
||||||
auto n = fn.fileName()+"_";
|
path = QDir::currentPath();
|
||||||
QTextStream sout(stdout);
|
}
|
||||||
|
else if (QDir(cmdDestinationPath).isAbsolute())
|
||||||
|
{
|
||||||
|
path = cmdDestinationPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QDir dir;
|
||||||
|
if (not dir.cd(cmdDestinationPath))
|
||||||
|
{
|
||||||
|
qCritical() << tr("The destination directory doesn't exists or is not readable.");
|
||||||
|
std::exit(V_EX_DATAERR);
|
||||||
|
}
|
||||||
|
path = dir.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
sout << tr("Output full path: ") << fn.filePath() << "\n";
|
qDebug() << "Output full path: " << path << "\n";
|
||||||
ui->lineEditPath->setText(p);
|
ui->lineEditPath->setText(path);
|
||||||
ui->lineEditFileName->setText(n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
QString Formate() const;
|
QString Formate() const;
|
||||||
void SelectFormate(const size_t formate);
|
void SelectFormate(const size_t formate);
|
||||||
static QString MakeHelpFormatList();
|
static QString MakeHelpFormatList();
|
||||||
void SetFullPath(const QString& cmdFileName);
|
void SetDestinationPath(const QString& cmdDestinationPath);
|
||||||
public slots:
|
public slots:
|
||||||
void Save();
|
void Save();
|
||||||
void ShowExample();
|
void ShowExample();
|
||||||
|
|
|
@ -3654,8 +3654,8 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams)
|
||||||
}
|
}
|
||||||
PrepareDetailsForLayout(details);
|
PrepareDetailsForLayout(details);
|
||||||
LayoutSettings(*settings.get());
|
LayoutSettings(*settings.get());
|
||||||
DialogSaveLayout dialog(scenes.size(), expParams->OptExportPath(), this);
|
DialogSaveLayout dialog(scenes.size(), expParams->OptBaseName(), this);
|
||||||
dialog.SetFullPath(expParams->OptExportPath());
|
dialog.SetDestinationPath(expParams->OptDestinationPath());
|
||||||
dialog.SelectFormate(expParams->OptExportType());
|
dialog.SelectFormate(expParams->OptExportType());
|
||||||
ExportLayout(dialog);
|
ExportLayout(dialog);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,10 @@ void TST_ValentinaCommandLine::ExportMode_data() const
|
||||||
QTest::addColumn<bool>("result");
|
QTest::addColumn<bool>("result");
|
||||||
QTest::addColumn<int>("exitCode");
|
QTest::addColumn<int>("exitCode");
|
||||||
|
|
||||||
|
const QString tmp = QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder;
|
||||||
|
|
||||||
QTest::newRow("Issue #372")<< "issue_372.val"
|
QTest::newRow("Issue #372")<< "issue_372.val"
|
||||||
<< "-p;;0;;-o;;output"
|
<< QString("-p;;0;;-d;;%1;;-b;;output").arg(tmp)
|
||||||
<< true
|
<< true
|
||||||
<< V_EX_OK;
|
<< V_EX_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user