Template recognizes new placeholders.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-30 09:32:39 +03:00
parent a97821edce
commit c33b178e3c
5 changed files with 41 additions and 5 deletions

View File

@ -145,8 +145,8 @@ void DialogPatternMaterials::SetPatternMaterials(const QMap<int, QString> &list)
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i) for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
{ {
QTableWidgetItem *item = new QTableWidgetItem(per + qApp->TrVars()->PlaceholderToUser(pl_userMaterial) + const QString translated = qApp->TrVars()->PlaceholderToUser(pl_userMaterial + QString::number(i + 1));
QString::number(i + 1) + per); QTableWidgetItem *item = new QTableWidgetItem(per + translated + per);
item->setFlags(item->flags() ^ Qt::ItemIsEditable); item->setFlags(item->flags() ^ Qt::ItemIsEditable);
item->setTextAlignment(Qt::AlignLeft); item->setTextAlignment(Qt::AlignLeft);

View File

@ -102,6 +102,20 @@ QMap<QString, QString> PreparePlaceholders(const VAbstractPattern *doc)
placeholders.insert(pl_height, curHeight); placeholders.insert(pl_height, curHeight);
placeholders.insert(pl_mExt, mExt); placeholders.insert(pl_mExt, mExt);
const QMap<int, QString> materials = doc->GetPatternMaterials();
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
{
const QString number = QString::number(i + 1);
QString value;
if (materials.contains(i + 1))
{
value = materials.value(i + 1);
}
placeholders.insert(pl_userMaterial + number, value);
}
// Piece tags // Piece tags
placeholders.insert(pl_pLetter, ""); placeholders.insert(pl_pLetter, "");
placeholders.insert(pl_pAnnotation, ""); placeholders.insert(pl_pAnnotation, "");

View File

@ -688,11 +688,18 @@ QString VTranslateVars::InternalVarToUser(const QString &var) const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::PlaceholderToUser(const QString &var) const QString VTranslateVars::PlaceholderToUser(QString var) const
{ {
QString number;
if (var.startsWith(pl_userMaterial) && var.length() > pl_userMaterial.length())
{
number = var.right(var.length() - pl_userMaterial.length());
var = pl_userMaterial;
}
if (placeholders.contains(var)) if (placeholders.contains(var))
{ {
return placeholders.value(var).translate(); return placeholders.value(var).translate() + number;
} }
return var; return var;

View File

@ -46,7 +46,7 @@ public:
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const; bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
QString InternalVarToUser(const QString &var) const; QString InternalVarToUser(const QString &var) const;
QString PlaceholderToUser(const QString &var) const; QString PlaceholderToUser(QString var) const;
QString PlaceholderToUserText(QString text) const; QString PlaceholderToUserText(QString text) const;
QString PlaceholderFromUserText(QString text) const; QString PlaceholderFromUserText(QString text) const;

View File

@ -506,6 +506,21 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert(pl_height, qMakePair(tr("Height"), curHeight)); m_placeholders.insert(pl_height, qMakePair(tr("Height"), curHeight));
m_placeholders.insert(pl_mExt, qMakePair(tr("Measurments extension"), mExt)); m_placeholders.insert(pl_mExt, qMakePair(tr("Measurments extension"), mExt));
const QString materialDescription = tr("User material");
const QMap<int, QString> materials = m_doc->GetPatternMaterials();
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
{
const QString number = QString::number(i + 1);
QString value;
if (materials.contains(i + 1))
{
value = materials.value(i + 1);
}
m_placeholders.insert(pl_userMaterial + number, qMakePair(materialDescription + number, value));
}
// Piece tags // Piece tags
m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString(""))); m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString("")));
m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString(""))); m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString("")));