diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-07-15 11:15:52 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2022-08-15 11:20:32 +0200 |
commit | e9dc0ac68134bc6a9cc6522eaca6d893ee10b86d (patch) | |
tree | f584dbb5ff239bbe7f931f35d2b8e46465f3ff60 /src/qml/debugger | |
parent | 70074e1acaca16afd6306a9c967ce4d15966c333 (diff) |
Create Translation Bindings without CompiledData::Binding
To add translation bindings to qmltc, the methods used to create
translation bindings need to be adapted to work without
QV4::CompiledData::Binding as it is not available from qmltc. Instead,
information already available from the QQmlJSScope should be used, along
with a newly introduced helper class QQmlTranslation.
Details:
Add a QQmlTranslation class that represents a call to qsTr, qsTrId etc
that knows how to translate itself (without needing any
ExecutableCompilationUnit or Binding). It encapsulates the
information needed to create a translation binding.
ExecutableCompilationUnit::bindingValueAsString refactored
so its functionality can be used without Binding.
Instead, it uses only the translationId, see
ExecutableCompilationUnit::translateFromId
and
ExecutableCompilationUnit::translateFrom.
Refactored QQmlTranslationBinding to work with QQmlTranslation instead
of CompiledData::Binding.
Same for QQmlCppBinding::createTranslationBindingForBindable,
QQmlTranslationPropertyBinding::create and
QQmlCppBinding::createTranslationBindingForNonBindable.
Changed TranslationBindingInformation to work without
CompiledData::Binding, and also removed static unused
QString ProxyTranslator::originStringFromInformation(
const TranslationBindingInformation &translationBindingInformation)
as I could not find out what this origin string is.
Same for the translation debugging in qmldb_preview.
Added QmltcCodeGenerator::generate_createTranslationBindingOnProperty.
Added #if to avoid compilation error for standalone DOM compilation due
to the new QQmlTranslation class.
Task-number: QTBUG-105345
Change-Id: Iccd94d5cba4eaf63901233451fec48051c855c2a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/debugger')
-rw-r--r-- | src/qml/debugger/qqmldebugserviceinterfaces.cpp | 38 | ||||
-rw-r--r-- | src/qml/debugger/qqmldebugserviceinterfaces_p.h | 13 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/qml/debugger/qqmldebugserviceinterfaces.cpp b/src/qml/debugger/qqmldebugserviceinterfaces.cpp index 7597a381b7..4067d1f5d1 100644 --- a/src/qml/debugger/qqmldebugserviceinterfaces.cpp +++ b/src/qml/debugger/qqmldebugserviceinterfaces.cpp @@ -45,6 +45,44 @@ QQmlDebugStatesDelegate *QQmlEngineDebugService::createStatesDelegate() #if QT_CONFIG(translation) QQmlDebugTranslationService::~QQmlDebugTranslationService() = default; + +const TranslationBindingInformation TranslationBindingInformation::create( + const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, + const QV4::CompiledData::Binding *binding, QObject *scopeObject, + QQmlRefPointer<QQmlContextData> ctxt) +{ + QQmlTranslation translation({}); + if (binding->type() == QV4::CompiledData::Binding::Type_TranslationById) { + const QV4::CompiledData::TranslationData data = + compilationUnit->data->translations()[binding->value.translationDataIndex]; + const QString id = compilationUnit->stringAt(data.stringIndex); + const int n = data.number; + + translation = QQmlTranslation(QQmlTranslation::QsTrIdData(id, n)); + } else { + Q_ASSERT(binding->type() == QV4::CompiledData::Binding::Type_Translation); + + const QV4::CompiledData::TranslationData data = + compilationUnit->data->translations()[binding->value.translationDataIndex]; + const QString context = + QQmlTranslation::contextFromQmlFilename(compilationUnit->fileName()); + const QString text = compilationUnit->stringAt(data.stringIndex); + const QString comment = compilationUnit->stringAt(data.commentIndex); + const int n = data.number; + + translation = QQmlTranslation(QQmlTranslation::QsTrData(context, text, comment, n)); + } + + return { compilationUnit, + scopeObject, + ctxt, + + compilationUnit->stringAt(binding->propertyNameIndex), + translation, + + binding->location.line(), + binding->location.column() }; +} #endif QT_END_NAMESPACE diff --git a/src/qml/debugger/qqmldebugserviceinterfaces_p.h b/src/qml/debugger/qqmldebugserviceinterfaces_p.h index 33db3a65c3..7c0b736463 100644 --- a/src/qml/debugger/qqmldebugserviceinterfaces_p.h +++ b/src/qml/debugger/qqmldebugserviceinterfaces_p.h @@ -22,6 +22,7 @@ #endif #include <private/qqmldebugstatesdelegate_p.h> #include <private/qqmlboundsignal_p.h> +#include <private/qqmltranslation_p.h> #include <limits> @@ -143,10 +144,20 @@ protected: #if QT_CONFIG(translation) struct TranslationBindingInformation { + static const TranslationBindingInformation + create(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, + const QV4::CompiledData::Binding *binding, QObject *scopeObject, + QQmlRefPointer<QQmlContextData> ctxt); + QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit; - const QV4::CompiledData::Binding *compiledBinding; QObject *scopeObject; QQmlRefPointer<QQmlContextData> ctxt; + + QString propertyName; + QQmlTranslation translation; + + quint32 line; + quint32 column; }; class Q_QML_PRIVATE_EXPORT QQmlDebugTranslationService : public QQmlDebugService |