8#include <QtCore/qtranslator.h>
9#include <QtCore/qdebug.h>
10#include <QtCore/qlibraryinfo.h>
11#include <QtCore/qdir.h>
12#include <QtCore/qfile.h>
13#include <QtCore/qtimer.h>
14#include <QtCore/qhash.h>
15#include <QtCore/qpointer.h>
17#include <private/qqmldebugtranslationprotocol_p.h>
18#include <private/qqmldebugconnector_p.h>
19#include <private/qversionedpacket_p.h>
21#include <private/qqmlbinding_p.h>
22#include <private/qqmlbinding_p.h>
23#include <private/qquickstategroup_p.h>
24#include <private/qquickitem_p.h>
25#include <private/qquicktext_p.h>
26#include <private/qdebug_p.h>
28#include <QtQuick/qquickitem.h>
39 error.setUrl(translationBindingInformation.compilationUnit->url());
40 error.setLine(translationBindingInformation.line);
41 error.setColumn(translationBindingInformation.column);
44 "QDebug translation binding"
79 currentStateName = stateGroup->state();
81 packet << Reply::StateChanged << currentStateName;
82 emit q->messageToClient(
q->name(), packet.
data());
88 packet << Reply::StateList;
99 qmlStates.
append(qmlState);
104 emit q->messageToClient(
q->name(), packet.
data());
111 qWarning() <<
"disable WatchTextElides is not implemented";
114 QObject *scopeObject = information.scopeObject;
115 int elideIndex = scopeObject->metaObject()->indexOfProperty(
"elide");
116 if (elideIndex >= 0) {
117 auto elideProperty = scopeObject->metaObject()->
property(elideIndex);
129 styleName.
append(
"Bold ");
131 styleName.
append(
"Italic " );
133 styleName.
append(
"StrikeThrough ");
135 styleName.
append(
"Underline ");
143 packet << Reply::TranslatableTextOccurrences;
149 QObject *scopeObject = information.scopeObject;
150 auto compilationUnit = information.compilationUnit;
153 int textIndex =
metaObject->indexOfProperty(information.propertyName.toLatin1());
154 if (textIndex >= 0) {
158 qmlElement.
codeMarker = codeMarker(information);
160 auto textProperty = scopeObject->metaObject()->
property(textIndex);
162 qmlElement.
translationId = information.translation.idForQmlDebug();
163 qmlElement.
translatedText = textProperty.read(scopeObject).toString();
178 qmlElements.
append(qmlElement);
181 QString warningMessage =
"(QQmlDebugTranslationService can not resolve %1 - %2:"\
182 " this should never happen)";
184 qWarning().noquote() << warningMessage.
arg(
id, information.propertyName);
187 std::sort(qmlElements.
begin(), qmlElements.
end(), [](
const auto &l1,
const auto &l2){
188 return l1.codeMarker < l2.codeMarker;
191 packet << qmlElements;
192 emit q->messageToClient(
q->name(), packet.
data());
198 packet << Reply::LanguageChanged;
199 emit q->messageToClient(
q->name(), packet.
data());
205 packet << Reply::TranslationIssues;
211 issue.
type = TranslationIssue::Type::Missing;
217 QObject *scopeObject = information.scopeObject;
222 issue.
type = TranslationIssue::Type::Elided;
229 std::sort(issues.
begin(), issues.
end(), [](
const auto &l1,
const auto &l2){
230 return l1.codeMarker < l2.codeMarker;
233 emit q->messageToClient(
q->name(), packet.
data());
250 return service->currentRootItem();
258 CodeMarker codeMarker(
const TranslationBindingInformation &information)
261 c.url = information.compilationUnit->url();
262 c.line = information.line;
263 c.column = information.column;
350 qWarning() <<
"DebugTranslationService: received unknown command: " <<
static_cast<int>(command);
376 QObject *scopeObject = translationBindingInformation.scopeObject;
386#include "moc_qqmldebugtranslationservice.cpp"
388#include <qqmldebugtranslationservice.moc>
void removeEngine(QQmlEngine *engine)
void languageChanged(const QLocale &locale)
bool hasTranslation(const TranslationBindingInformation &translationBindingInformation) const
void addEngine(QQmlEngine *engine)
void setLanguage(const QUrl &context, const QLocale &locale)
QString currentUILanguages() const
QString family() const
Returns the requested font family name.
QString styleName() const
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
bool underline() const
Returns true if underline has been set; otherwise returns false.
int pointSize() const
Returns the point size of the font.
bool bold() const
Returns true if weight() is a value greater than \l{Weight}{QFont::Medium}; otherwise returns false.
The QJSEngine class provides an environment for evaluating JavaScript code.
void append(parameter_type t)
iterator insert(const Key &key, const T &value)
size_type remove(const Key &key)
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
QVariant property(const char *name) const
Returns the value of the object's name property.
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
const QByteArray & data() const
Returns a reference to the raw packet data.
QString nameForObject(const QObject *) const
Returns the name of object in this context, or an empty string if object is not named in the context.
QQmlDebugTranslationServiceImpl(QObject *parent=nullptr)
void messageReceived(const QByteArray &message) override
void foundTranslationBinding(const TranslationBindingInformation &translationBindingInformation) override
void engineAboutToBeAdded(QJSEngine *engine) override
~QQmlDebugTranslationServiceImpl()
void state(const QString &stateName)
void engineAboutToBeRemoved(QJSEngine *engine) override
void watchTextElides(bool)
void sendTranslatableTextOccurrences()
void language(const QUrl &context, const QLocale &locale)
ProxyTranslator * proxyTranslator
QQmlDebugTranslationServiceImpl * q
QQuickItem * currentRootItem()
QHash< QObject *, QVector< QMetaObject::Connection > > elideConnections
QQuickView * currentQuickView
void sendTranslatableTextOccurrences()
QQmlDebugTranslationServicePrivate(QQmlDebugTranslationServiceImpl *parent)
QMultiMap< QObject *, TranslationBindingInformation > objectTranslationBindingMultiMap
bool enableWatchTranslations
QTimer translatableTextOccurrenceTimer
void setState(const QString &stateName)
void sendLanguageChanged()
QString getStyleNameForFont(const QFont &font)
void setWatchTextElides(bool s)
void sendTranslationIssues()
QList< QPointer< QQuickItem > > translatableTextOccurrences
The QQmlEngine class provides an environment for instantiating QML components.
The QQmlError class encapsulates a QML error.
QString qmlTypeName() const
QByteArray typeName() const
QQuickStateGroup * _states()
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
QQuickState * findState(const QString &name) const
QQmlListProperty< QQuickState > states
void setState(const QString &)
void stateChanged(const QString &)
The QQuickView class provides a window for displaying a Qt Quick user interface.
QQuickItem * rootObject() const
Returns the view's root \l {QQuickItem} {item}.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
QString & append(QChar c)
QString trimmed() const &
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
@ TranslatableTextOccurrences
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLuint GLsizei const GLchar * message
GLdouble GLdouble GLdouble GLdouble q
QQmlEngine * qmlEngine(const QObject *obj)
QQmlContext * qmlContext(const QObject *obj)
QDebug operator<<(QDebug debug, const TranslationBindingInformation &translationBindingInformation)
const QQuickItem * rootItem(const I &item)
#define qPrintable(string)
QLatin1StringView QLatin1String
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
obj metaObject() -> className()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent