Resolved issue #865. New feature. Dynamic Way to define Material in piece label.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-07-18 20:18:30 +03:00
parent 9da4cbb329
commit 2c7b21b98d
12 changed files with 114 additions and 3 deletions

View File

@ -51,6 +51,7 @@
- [#826] New Feature. Add and remove items to groups from the context menu.
- Mouse double click zoom fit best current pattern piece.
- [#862] Force Valentina to immediately terminate if a pattern contains a parsing warning.
- [#865] New feature. Dynamic Way to define Material in piece label.
# Version 0.5.1 (unreleased)
- [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "13 July, 2018" "valentina man page"
.TH valentina 1 "18 July, 2018" "valentina man page"
.SH NAME
Valentina \- Pattern making program.
.SH SYNOPSIS
@ -112,6 +112,8 @@ The path to output destination folder. By default the directory at which the app
.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 <The height value>"
.RB "Set height value a pattern file, that was opened with multisize measurements (" "export mode" "). Valid values: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182, 188, 194, 200cm."
.IP "--userMaterial <User material>"
.RB "Use this option to override user material defined in pattern. The value must be in form <number>@<user matrial name>. The number should be in range from 1 to 20. For example, 1@Fabric2. The key can be used multiple times. Has no effect in GUI mode."
.IP "-p, --pageformat <Template number>"
.RB "Number corresponding to layout page template (default = 0, " "export mode" "):"
.RS

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "13 July, 2018" "valentina man page"
.TH valentina 1 "18 July, 2018" "valentina man page"
.SH NAME
Valentina \- Pattern making program.
.SH SYNOPSIS
@ -112,6 +112,8 @@ The path to output destination folder. By default the directory at which the app
.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 <The height value>"
.RB "Set height value a pattern file, that was opened with multisize measurements (" "export mode" "). Valid values: 92, 98, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 164, 170, 176, 182, 188, 194, 200cm."
.IP "--userMaterial <User material>"
.RB "Use this option to override user material defined in pattern. The value must be in form <number>@<user matrial name>. The number should be in range from 1 to 20. For example, 1@Fabric2. The key can be used multiple times. Has no effect in GUI mode."
.IP "-p, --pageformat <Template number>"
.RB "Number corresponding to layout page template (default = 0, " "export mode" "):"
.RS

8
scripts/man2pdf.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# Use to conver man pages to pdf
# usage:
# $ ./man2pdf.sh
man -t ../dist/debian/valentina.1 | ps2pdf - valentina.pdf
man -t ../dist/debian/tape.1 | ps2pdf - tape.pdf

View File

@ -138,6 +138,16 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap<QString, int>
.arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")),
translate("VCommandLine", "The height value")));
optionsIndex.insert(LONG_OPTION_USER_MATERIAL, index++);
options.append(new QCommandLineOption(QStringList() << LONG_OPTION_USER_MATERIAL,
translate("VCommandLine",
"Use this option to override user material defined in pattern. The "
"value must be in form <number>@<user matrial name>. The number "
"should be in range from 1 to %1. For example, 1@Fabric2. The key "
"can be used multiple times. Has no effect in GUI mode.")
.arg(userMaterialPlaceholdersQuantity),
translate("VCommandLine", "User material")));
//=================================================================================================================
optionsIndex.insert(LONG_OPTION_PAGETEMPLATE, index++);
options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
@ -796,6 +806,37 @@ QString VCommandLine::OptExportFMTo() const
return parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CSVEXPORTFM)));
}
//---------------------------------------------------------------------------------------------------------------------
QMap<int, QString> VCommandLine::OptUserMaterials() const
{
QMap<int, QString> userMaterials;
const QStringList values = parser.values(*optionsUsed.value(optionsIndex.value(LONG_OPTION_USER_MATERIAL)));
for(auto &value : values)
{
const QStringList parts = value.split('@');
if (parts.size() != 2)
{
qCritical() << translate("VCommandLine", "Invalid user material '%1'. Separator is missing.").arg(value)
<< "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
bool ok = false;
const int number = parts.first().toInt(&ok);
if (not ok or number < 1 or number > userMaterialPlaceholdersQuantity)
{
qCritical() << translate("VCommandLine", "Invalid user material '%1'. Wrong material number.").arg(value)
<< "\n";
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
userMaterials.insert(number, parts.last());
}
return userMaterials;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VCommandLine::OptInputFileNames() const
{

View File

@ -100,6 +100,9 @@ public:
//@brief returns the destination path for export final measurements or empty string if not set
QString OptExportFMTo() const;
//@brief returns list of user defined materials
QMap<int, QString> OptUserMaterials() 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;

View File

@ -5425,6 +5425,8 @@ void MainWindow::ProcessCMD()
return;
}
qApp->SetUserMaterials(cmd->OptUserMaterials());
const bool loaded = LoadPattern(args.first(), cmd->OptMeasurePath());
if (not loaded)

View File

@ -236,6 +236,30 @@ void GatherTokens(QSet<QString> &tokens, const QList<QString> &tokenList)
{
tokens = tokens.unite(tokenList.toSet());
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief AdjustMaterials help function that combine user materials from pattern and cli.
* @param materials materials from pattern
* @return combined list
*/
QMap<int, QString> AdjustMaterials(QMap<int, QString> materials)
{
const QMap<int, QString> cliMaterials = qApp->GetUserMaterials();
QMap<int, QString>::const_iterator i = cliMaterials.constBegin();
while (i != cliMaterials.constEnd())
{
if (not materials.contains(i.key()))
{
qWarning() << QObject::tr("User material number %1 was not defined in this pattern.").arg(i.key());
}
materials.insert(i.key(), i.value());
++i;
}
return materials;
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -1445,7 +1469,7 @@ QMap<int, QString> VAbstractPattern::GetPatternMaterials() const
patternMaterials = GetMaterials(list.at(0).toElement());
}
return patternMaterials;
return AdjustMaterials(patternMaterials);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -98,6 +98,8 @@ const QString SINGLE_OPTION_GRADATIONSIZE = QStringLiteral("x");
const QString LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight");
const QString SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e");
const QString LONG_OPTION_USER_MATERIAL = QStringLiteral("userMaterial");
const QString LONG_OPTION_IGNORE_MARGINS = QStringLiteral("ignoremargins");
const QString SINGLE_OPTION_IGNORE_MARGINS = QStringLiteral("i");
@ -126,6 +128,10 @@ const QString LONG_OPTION_TILED_PDF_BOTTOM_MARGIN = QStringLiteral("tiledbmargin
const QString LONG_OPTION_TILED_PDF_LANDSCAPE = QStringLiteral("tiledLandscape");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief AllKeys return list with all command line keys (short and long forms). Used for testing on conflicts.
* @return list with all command line keys
*/
QStringList AllKeys()
{
QStringList list;
@ -150,8 +156,10 @@ QStringList AllKeys()
<< LONG_OPTION_GAPWIDTH << SINGLE_OPTION_GAPWIDTH
<< LONG_OPTION_GROUPPING << SINGLE_OPTION_GROUPPING
<< LONG_OPTION_TEST << SINGLE_OPTION_TEST
<< LONG_OPTION_PENDANTIC
<< LONG_OPTION_GRADATIONSIZE << SINGLE_OPTION_GRADATIONSIZE
<< LONG_OPTION_GRADATIONHEIGHT << SINGLE_OPTION_GRADATIONHEIGHT
<< LONG_OPTION_USER_MATERIAL
<< LONG_OPTION_IGNORE_MARGINS << SINGLE_OPTION_IGNORE_MARGINS
<< LONG_OPTION_LEFT_MARGIN << SINGLE_OPTION_LEFT_MARGIN
<< LONG_OPTION_RIGHT_MARGIN << SINGLE_OPTION_RIGHT_MARGIN

View File

@ -95,6 +95,8 @@ extern const QString SINGLE_OPTION_GRADATIONSIZE;
extern const QString LONG_OPTION_GRADATIONHEIGHT;
extern const QString SINGLE_OPTION_GRADATIONHEIGHT;
extern const QString LONG_OPTION_USER_MATERIAL;
extern const QString LONG_OPTION_IGNORE_MARGINS;
extern const QString SINGLE_OPTION_IGNORE_MARGINS;

View File

@ -60,6 +60,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
sceneView(nullptr),
doc(nullptr),
m_customerName(),
m_userMaterials(),
openingPattern(false)
{
QString rules;

View File

@ -118,6 +118,9 @@ public:
static QString ClearMessage(QString msg);
QMap<int, QString> GetUserMaterials() const;
void SetUserMaterials(const QMap<int, QString> &userMaterials);
protected:
QUndoStack *undoStack;
@ -152,6 +155,8 @@ private:
VAbstractPattern *doc;
QString m_customerName;
QMap<int, QString> m_userMaterials;
/**
* @brief openingPattern true when we opening pattern. If something will be wrong in formula this help understand if
* we can allow user use Undo option.
@ -185,6 +190,18 @@ inline void VAbstractApplication::SetPatternPath(const QString &value)
patternFilePath = value;
}
//---------------------------------------------------------------------------------------------------------------------
inline QMap<int, QString> VAbstractApplication::GetUserMaterials() const
{
return m_userMaterials;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstractApplication::SetUserMaterials(const QMap<int, QString> &userMaterials)
{
m_userMaterials = userMaterials;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline QString VAbstractApplication::LocaleToString(const T &value)