From 0b3342fe3d10102270c2789825405db5ad331cea Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 14 Aug 2017 15:48:14 +0300 Subject: [PATCH] Translation from/to user text. --HG-- branch : feature --- src/libs/vpatterndb/vtranslatevars.cpp | 38 +++++++++++++++++++ src/libs/vpatterndb/vtranslatevars.h | 5 ++- .../dialogs/support/dialogeditlabel.cpp | 7 ++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index 39ed1c424..bdf6ddfc4 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -683,6 +683,44 @@ QString VTranslateVars::PlaceholderToUser(const QString &var) const return var; } +//--------------------------------------------------------------------------------------------------------------------- +QString VTranslateVars::PlaceholderToUserText(QString text) const +{ + QChar per('%'); + auto i = placeholders.constBegin(); + while (i != placeholders.constEnd()) + { + const QString translated = per + i.value().translate() + per; + const QString original = per + i.key() + per; + + while (text.indexOf(original) != -1) + { + text.replace(original, translated); + } + ++i; + } + return text; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VTranslateVars::PlaceholderFromUserText(QString text) const +{ + QChar per('%'); + auto i = placeholders.constBegin(); + while (i != placeholders.constEnd()) + { + const QString translated = per + i.value().translate() + per; + const QString original = per + i.key() + per; + + while (text.indexOf(translated) != -1) + { + text.replace(translated, original); + } + ++i; + } + return text; +} + //--------------------------------------------------------------------------------------------------------------------- QString VTranslateVars::VarToUser(const QString &var) const { diff --git a/src/libs/vpatterndb/vtranslatevars.h b/src/libs/vpatterndb/vtranslatevars.h index 929585fef..1ac8a7c68 100644 --- a/src/libs/vpatterndb/vtranslatevars.h +++ b/src/libs/vpatterndb/vtranslatevars.h @@ -34,8 +34,6 @@ #include "vtranslatemeasurements.h" -#define trPL(pl) QLatin1String("%") + qApp->TrVars()->PlaceholderToUser((pl)) + QLatin1String("%") - class VTranslateVars : public VTranslateMeasurements { public: @@ -50,6 +48,9 @@ public: QString InternalVarToUser(const QString &var) const; QString PlaceholderToUser(const QString &var) const; + QString PlaceholderToUserText(QString text) const; + QString PlaceholderFromUserText(QString text) const; + QString VarToUser(const QString &var) const; QString VarFromUser(const QString &var) const; diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 058e994fe..542a43137 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -427,12 +427,13 @@ void DialogEditLabel::SetupControls() //--------------------------------------------------------------------------------------------------------------------- void DialogEditLabel::InitPlaceholdersMenu() { + QChar per('%'); auto i = m_placeholders.constBegin(); while (i != m_placeholders.constEnd()) { auto value = i.value(); QAction *action = m_placeholdersMenu->addAction(value.first); - action->setData(trPL(i.key())); + action->setData(per + qApp->TrVars()->PlaceholderToUser(i.key()) + per); connect(action, &QAction::triggered, this, &DialogEditLabel::InsertPlaceholder); ++i; } @@ -500,7 +501,7 @@ QVector DialogEditLabel::PrepareLines() const if (lineItem) { VLabelTemplateLine line; - line.line = lineItem->text(); + line.line = qApp->TrVars()->PlaceholderFromUserText(lineItem->text()); line.alignment = lineItem->textAlignment(); const QFont font = lineItem->font(); @@ -524,7 +525,7 @@ void DialogEditLabel::InitEditLines(const QVector &lines) for (int i=0; iTrVars()->PlaceholderToUserText(lines.at(i).line)); item->setTextAlignment(lines.at(i).alignment); QFont font = item->font();