aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/debugger
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2020-02-07 08:13:41 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2021-04-26 13:13:44 +0200
commit784c62441333de8d13d31c719ac01e6096247c01 (patch)
treec9916e04f0e7d7ddf1cf6467f0f9ad643267e58a /src/qml/debugger
parentf9b85604179e162c68ac8c42f97b1b3329c79b0a (diff)
Implement debugtranslationservice
- moves the language feature from the preview service to an own debugtranslationservice - with the help of a proxytranslator the service gets all translate requests Change-Id: Ic26677bb1706abbea2db23e6aafe7a3f00648962 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/debugger')
-rw-r--r--src/qml/debugger/qqmldebugserviceinterfaces.cpp3
-rw-r--r--src/qml/debugger/qqmldebugserviceinterfaces_p.h18
-rw-r--r--src/qml/debugger/qqmldebugtranslationprotocol_p.h260
3 files changed, 275 insertions, 6 deletions
diff --git a/src/qml/debugger/qqmldebugserviceinterfaces.cpp b/src/qml/debugger/qqmldebugserviceinterfaces.cpp
index 3357b0237c..39de9e1b06 100644
--- a/src/qml/debugger/qqmldebugserviceinterfaces.cpp
+++ b/src/qml/debugger/qqmldebugserviceinterfaces.cpp
@@ -48,8 +48,9 @@ const QString QQmlProfilerService::s_key = QStringLiteral("CanvasFrameRate");
const QString QDebugMessageService::s_key = QStringLiteral("DebugMessages");
const QString QQmlEngineControlService::s_key = QStringLiteral("EngineControl");
const QString QQmlNativeDebugService::s_key = QStringLiteral("NativeQmlDebugger");
+#if QT_CONFIG(translation)
const QString QQmlDebugTranslationService::s_key = QStringLiteral("DebugTranslation");
-
+#endif
static QQmlDebugStatesDelegate *(*statesDelegateFactory)() = nullptr;
void QQmlEngineDebugService::setStatesDelegateFactory(QQmlDebugStatesDelegate *(*factory)())
{
diff --git a/src/qml/debugger/qqmldebugserviceinterfaces_p.h b/src/qml/debugger/qqmldebugserviceinterfaces_p.h
index a58a075848..02367d1984 100644
--- a/src/qml/debugger/qqmldebugserviceinterfaces_p.h
+++ b/src/qml/debugger/qqmldebugserviceinterfaces_p.h
@@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE
class QWindow;
class QQuickWindow;
-class QQmlTranslationBinding;
+
#if !QT_CONFIG(qml_debug)
@@ -107,8 +107,7 @@ class QQmlNativeDebugService {};
class QQmlDebugTranslationService {
public:
virtual QString foundElidedText(QObject *, const QString &, const QString &) {return {};}
- virtual void foundTranslationBinding(QQmlTranslationBinding *, QObject *,
- const QQmlRefPointer<QQmlContextData> &) {}
+ virtual void foundTranslationBinding(const TranslationBindingInformation &) {}
};
#else
@@ -170,6 +169,15 @@ protected:
QQmlBoundSignal *nextSignal(QQmlBoundSignal *prev) { return prev->m_nextSignal; }
};
+#if QT_CONFIG(translation)
+struct TranslationBindingInformation
+{
+ QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
+ const QV4::CompiledData::Binding *compiledBinding;
+ QObject *scopeObject;
+ QQmlRefPointer<QQmlContextData> ctxt;
+};
+
class Q_QML_PRIVATE_EXPORT QQmlDebugTranslationService : public QQmlDebugService
{
Q_OBJECT
@@ -177,8 +185,7 @@ public:
static const QString s_key;
virtual QString foundElidedText(QObject *qQuickTextObject, const QString &layoutText, const QString &elideText) = 0;
- virtual void foundTranslationBinding(QQmlTranslationBinding *binding, QObject *scopeObject,
- const QQmlRefPointer<QQmlContextData> &contextData) = 0;
+ virtual void foundTranslationBinding(const TranslationBindingInformation &translationBindingInformation) = 0;
protected:
friend class QQmlDebugConnector;
@@ -186,6 +193,7 @@ protected:
QQmlDebugService(s_key, version, parent) {}
};
+#endif //QT_CONFIG(translation)
class Q_QML_PRIVATE_EXPORT QQmlInspectorService : public QQmlDebugService
{
diff --git a/src/qml/debugger/qqmldebugtranslationprotocol_p.h b/src/qml/debugger/qqmldebugtranslationprotocol_p.h
new file mode 100644
index 0000000000..467b34d509
--- /dev/null
+++ b/src/qml/debugger/qqmldebugtranslationprotocol_p.h
@@ -0,0 +1,260 @@
+
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QQMLDEBUGTRANSLATIONPROTOCOL_P_H
+#define QQMLDEBUGTRANSLATIONPROTOCOL_P_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include <QtCore/qdatastream.h>
+#include <QtCore/qbuffer.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qobjectdefs.h>
+#include <QtCore/qmetaobject.h>
+#include <tuple>
+
+QT_BEGIN_NAMESPACE
+
+namespace QQmlDebugTranslation {
+
+enum class Request {
+ ChangeLanguage = 1,
+ StateList,
+ ChangeState,
+ MissingTranslations,
+ TranslatableTextOccurrences,
+ WatchTextElides,
+ DisableWatchTextElides,
+};
+
+enum class Reply {
+ LanguageChanged = 101,
+ StateList,
+ StateChanged,
+ MissingTranslations,
+ TranslatableTextOccurrences,
+ TextElided,
+};
+
+inline QByteArray createChangeLanguageRequest(QDataStream &packet, const QUrl &url,
+ const QString &locale)
+{
+ packet << Request::ChangeLanguage << url << locale;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+inline QByteArray createChangeStateRequest(QDataStream &packet, const QString &state)
+{
+ packet << Request::ChangeState << state;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+inline QByteArray createMissingTranslationsRequest(QDataStream &packet)
+{
+ packet << Request::MissingTranslations;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+inline QByteArray createTranslatableTextOccurrencesRequest(QDataStream &packet)
+{
+ packet << Request::TranslatableTextOccurrences;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+inline QByteArray createStateListRequest(QDataStream &packet)
+{
+ packet << Request::StateList;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+inline QByteArray createWatchTextElidesRequest(QDataStream &packet)
+{
+ packet << Request::WatchTextElides;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+inline QByteArray createDisableWatchTextElidesRequest(QDataStream &packet)
+{
+ packet << Request::DisableWatchTextElides;
+ return qobject_cast<QBuffer *>(packet.device())->data();
+}
+
+class CodeMarker
+{
+public:
+ friend QDataStream &operator>>(QDataStream &stream, CodeMarker &codeMarker)
+ {
+ return stream >> codeMarker.url
+ >> codeMarker.line
+ >> codeMarker.column;
+ }
+
+ friend QDataStream &operator<<(QDataStream &stream, const CodeMarker &codeMarker)
+ {
+ return stream << codeMarker.url
+ << codeMarker.line
+ << codeMarker.column;
+ }
+
+ friend bool operator<(const CodeMarker &first, const CodeMarker &second)
+ {
+ return std::tie(first.url, first.line, first.column)
+ < std::tie(second.url, second.line, second.column);
+ }
+
+ friend bool operator==(const CodeMarker &first, const CodeMarker &second)
+ {
+ return first.line == second.line
+ && first.column == second.column
+ && first.url == second.url;
+ }
+
+ QUrl url;
+ int line = -1;
+ int column = -1;
+};
+class TranslationIssue
+{
+public:
+ enum class Type{
+ Missing,
+ Elided
+ };
+
+ friend QDataStream &operator>>(QDataStream &stream, TranslationIssue &issue)
+ {
+ return stream >> issue.codeMarker
+ >> issue.language
+ >> issue.type;
+ }
+
+ friend QDataStream &operator<<(QDataStream &stream, const TranslationIssue &issue)
+ {
+ return stream << issue.codeMarker
+ << issue.language
+ << issue.type;
+ }
+
+ friend bool operator==(const TranslationIssue &first, const TranslationIssue &second)
+ {
+ return first.type == second.type
+ && first.language == second.language
+ && first.codeMarker == second.codeMarker;
+ }
+
+ QString toDebugString() const
+ {
+ QString debugString(QLatin1String(
+ "TranslationIssue(type=%1, line=%2, column=%3, url=%4, language=%5)"));
+ return debugString.arg(type == TranslationIssue::Type::Missing ? QLatin1String("Missing")
+ : QLatin1String("Elided"),
+ QString::number(codeMarker.line), QString::number(codeMarker.column),
+ codeMarker.url.toString(), language);
+ }
+
+ QString language;
+ Type type = Type::Missing;
+ CodeMarker codeMarker;
+};
+class QmlElement
+{
+public:
+ QmlElement() = default;
+
+ friend QDataStream &operator>>(QDataStream &stream, QmlElement &qmlElement)
+ {
+ return stream >> qmlElement.codeMarker >> qmlElement.elementId >> qmlElement.elementType
+ >> qmlElement.propertyName >> qmlElement.translationId >> qmlElement.translatedText
+ >> qmlElement.fontFamily >> qmlElement.fontPointSize >> qmlElement.fontPixelSize
+ >> qmlElement.fontStyleName >> qmlElement.horizontalAlignment
+ >> qmlElement.verticalAlignment;
+ }
+
+ friend QDataStream &operator<<(QDataStream &stream, const QmlElement &qmlElement)
+ {
+ return stream << qmlElement.codeMarker << qmlElement.elementId << qmlElement.elementType
+ << qmlElement.propertyName << qmlElement.translationId
+ << qmlElement.translatedText << qmlElement.fontFamily
+ << qmlElement.fontPointSize << qmlElement.fontPixelSize
+ << qmlElement.fontStyleName << qmlElement.horizontalAlignment
+ << qmlElement.verticalAlignment;
+ }
+
+ CodeMarker codeMarker;
+ QString propertyName;
+ QString translationId;
+ QString translatedText;
+ QString fontFamily;
+ QString fontStyleName;
+ QString elementId;
+ QString elementType;
+ qreal fontPointSize = 0.0;
+ int fontPixelSize = 0;
+ int horizontalAlignment = 0;
+ int verticalAlignment = 0;
+};
+class QmlState
+{
+public:
+ QmlState() = default;
+
+ friend QDataStream &operator>>(QDataStream &stream, QmlState &qmlState)
+ {
+ return stream >> qmlState.name;
+ }
+
+ friend QDataStream &operator<<(QDataStream &stream, const QmlState &qmlState)
+ {
+ return stream << qmlState.name;
+ }
+
+ QString name;
+};
+}
+
+QT_END_NAMESPACE
+
+#endif // QQMLDEBUGTRANSLATIONPROTOCOL_P_H