From f55eb4b68a52dd3284e2813228cc68488a38167d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 23 Jun 2024 15:36:09 +0300 Subject: [PATCH] Fix regression. Incorrect processing placeholders in pattern label. --- src/libs/vlayout/vtextmanager.cpp | 48 +++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index d758a185b..f67dbc1d4 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -627,11 +627,18 @@ void InitPiecePlaceholders(QMap &placeholders, const VPieceLab AddPlaceholder(pl_pName, info.pieceName); AddPlaceholder(pl_pQuantity, QString::number(data.GetQuantity())); - if (data.IsOnFold() && uniquePlaceholders.contains('%' + pl_wOnFold + '%')) + if (uniquePlaceholders.contains('%' + pl_wOnFold + '%')) { - if (QSharedPointer const phTr = info.placeholderTranslator; !phTr.isNull()) + if (data.IsOnFold()) { - placeholders.insert(pl_wOnFold, phTr->translate("Placeholder", "on fold")); + if (QSharedPointer const phTr = info.placeholderTranslator; !phTr.isNull()) + { + placeholders.insert(pl_wOnFold, phTr->translate("Placeholder", "on fold")); + } + } + else + { + placeholders.insert(pl_wOnFold, QString()); } } } @@ -916,9 +923,40 @@ void VTextManager::UpdatePatternLabelInfo(const VPieceLabelInfo &info) return; // Nothing to parse } - QSet const uniquePlaceholders = UniquePlaceholders(info.labelData.GetLabelTemplate()); + QSet const uniquePlaceholders = UniquePlaceholders(lines); - const QMap placeholders = PreparePlaceholders(info, uniquePlaceholders); + QMap placeholders = PreparePlaceholders(info, uniquePlaceholders); + + if (QSharedPointer const phTr = info.placeholderTranslator; !phTr.isNull()) + { + // These placeholders must be available only in piece label + const QString errorValue = '<' + phTr->translate("Placeholder", "Error") + '>'; + auto AddPlaceholder = [&placeholders, uniquePlaceholders, errorValue](const QString &name, const QString &value) + { + const QString placeholder = '%' + name + '%'; + if (uniquePlaceholders.contains(placeholder)) + { + const QString errorMsg = + QObject::tr("Incorrect use of placeholder %1. This placeholder is not available in pattern label.") + .arg(placeholder); + VAbstractApplication::VApp()->IsPedantic() + ? throw VException(errorMsg) + : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + + placeholders.insert(name, value); + } + }; + + AddPlaceholder(pl_pLetter, errorValue); + AddPlaceholder(pl_pAnnotation, errorValue); + AddPlaceholder(pl_pOrientation, errorValue); + AddPlaceholder(pl_pRotation, errorValue); + AddPlaceholder(pl_pTilt, errorValue); + AddPlaceholder(pl_pFoldPosition, errorValue); + AddPlaceholder(pl_pName, errorValue); + AddPlaceholder(pl_pQuantity, errorValue); + AddPlaceholder(pl_wOnFold, errorValue); + } for (auto &line : lines) {