forked from qt-creator/qt-creator
QmlJSInspectorAgent: Refactor code
Try to use the watchHandler for referring to the object tree instead of caching the object tree locally. Change-Id: I68624771ef49d50f2cf0d6d580b1b34d57483178 Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
This commit is contained in:
@@ -286,14 +286,14 @@ quint32 BaseEngineDebugClient::addWatch(const ObjectReference &object,
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 BaseEngineDebugClient::addWatch(const ObjectReference &object)
|
quint32 BaseEngineDebugClient::addWatch(int objectId)
|
||||||
{
|
{
|
||||||
quint32 id = 0;
|
quint32 id = 0;
|
||||||
if (status() == Enabled) {
|
if (status() == Enabled) {
|
||||||
id = getId();
|
id = getId();
|
||||||
QByteArray message;
|
QByteArray message;
|
||||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||||
ds << QByteArray("WATCH_OBJECT") << id << object.m_debugId;
|
ds << QByteArray("WATCH_OBJECT") << id << objectId;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
@@ -341,28 +341,28 @@ quint32 BaseEngineDebugClient::queryRootContexts(const EngineReference &engine)
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 BaseEngineDebugClient::queryObject(const ObjectReference &object)
|
quint32 BaseEngineDebugClient::queryObject(int objectId)
|
||||||
{
|
{
|
||||||
quint32 id = 0;
|
quint32 id = 0;
|
||||||
if (status() == Enabled && object.m_debugId != -1) {
|
if (status() == Enabled && objectId != -1) {
|
||||||
id = getId();
|
id = getId();
|
||||||
QByteArray message;
|
QByteArray message;
|
||||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||||
ds << QByteArray("FETCH_OBJECT") << id << object.m_debugId << false <<
|
ds << QByteArray("FETCH_OBJECT") << id << objectId << false <<
|
||||||
true;
|
true;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 BaseEngineDebugClient::queryObjectRecursive(const ObjectReference &object)
|
quint32 BaseEngineDebugClient::queryObjectRecursive(int objectId)
|
||||||
{
|
{
|
||||||
quint32 id = 0;
|
quint32 id = 0;
|
||||||
if (status() == Enabled && object.m_debugId != -1) {
|
if (status() == Enabled && objectId != -1) {
|
||||||
id = getId();
|
id = getId();
|
||||||
QByteArray message;
|
QByteArray message;
|
||||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||||
ds << QByteArray("FETCH_OBJECT") << id << object.m_debugId << true <<
|
ds << QByteArray("FETCH_OBJECT") << id << objectId << true <<
|
||||||
true;
|
true;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
@@ -56,15 +56,15 @@ public:
|
|||||||
quint32 addWatch(const PropertyReference &property);
|
quint32 addWatch(const PropertyReference &property);
|
||||||
quint32 addWatch(const ContextReference &context, const QString &id);
|
quint32 addWatch(const ContextReference &context, const QString &id);
|
||||||
quint32 addWatch(const ObjectReference &object, const QString &expr);
|
quint32 addWatch(const ObjectReference &object, const QString &expr);
|
||||||
quint32 addWatch(const ObjectReference &object);
|
quint32 addWatch(int objectId);
|
||||||
quint32 addWatch(const FileReference &file);
|
quint32 addWatch(const FileReference &file);
|
||||||
|
|
||||||
void removeWatch(quint32 watch);
|
void removeWatch(quint32 watch);
|
||||||
|
|
||||||
quint32 queryAvailableEngines();
|
quint32 queryAvailableEngines();
|
||||||
quint32 queryRootContexts(const EngineReference &context);
|
quint32 queryRootContexts(const EngineReference &context);
|
||||||
quint32 queryObject(const ObjectReference &object);
|
quint32 queryObject(int objectId);
|
||||||
quint32 queryObjectRecursive(const ObjectReference &object);
|
quint32 queryObjectRecursive(int objectId);
|
||||||
quint32 queryExpressionResult(int objectDebugId,
|
quint32 queryExpressionResult(int objectDebugId,
|
||||||
const QString &expr, int engineId = -1);
|
const QString &expr, int engineId = -1);
|
||||||
virtual quint32 setBindingForObject(int objectDebugId, const QString &propertyName,
|
virtual quint32 setBindingForObject(int objectDebugId, const QString &propertyName,
|
||||||
@@ -104,6 +104,12 @@ class FileReference
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReference() : m_lineNumber(-1), m_columnNumber(-1) {}
|
FileReference() : m_lineNumber(-1), m_columnNumber(-1) {}
|
||||||
|
FileReference(const QUrl &url, int line, int column)
|
||||||
|
: m_url(url),
|
||||||
|
m_lineNumber(line),
|
||||||
|
m_columnNumber(column)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QUrl url() const { return m_url; }
|
QUrl url() const { return m_url; }
|
||||||
int lineNumber() const { return m_lineNumber; }
|
int lineNumber() const { return m_lineNumber; }
|
||||||
@@ -142,6 +148,7 @@ public:
|
|||||||
QString className() const { return m_className; }
|
QString className() const { return m_className; }
|
||||||
QString idString() const { return m_idString; }
|
QString idString() const { return m_idString; }
|
||||||
QString name() const { return m_name; }
|
QString name() const { return m_name; }
|
||||||
|
bool isValid() const { return m_debugId != -1; }
|
||||||
|
|
||||||
FileReference source() const { return m_source; }
|
FileReference source() const { return m_source; }
|
||||||
int contextDebugId() const { return m_contextDebugId; }
|
int contextDebugId() const { return m_contextDebugId; }
|
||||||
|
@@ -274,27 +274,14 @@ void QmlInspectorAdapter::engineClientStatusChanged(QmlDebug::ClientStatus statu
|
|||||||
|
|
||||||
void QmlInspectorAdapter::selectObjectsFromEditor(const QList<int> &debugIds)
|
void QmlInspectorAdapter::selectObjectsFromEditor(const QList<int> &debugIds)
|
||||||
{
|
{
|
||||||
int debugId = debugIds.first();
|
|
||||||
|
|
||||||
if (m_selectionCallbackExpected) {
|
if (m_selectionCallbackExpected) {
|
||||||
m_selectionCallbackExpected = false;
|
m_selectionCallbackExpected = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_cursorPositionChangedExternally = true;
|
m_cursorPositionChangedExternally = true;
|
||||||
|
|
||||||
ObjectReference clientRef
|
|
||||||
= agent()->objectForId(debugId);
|
|
||||||
|
|
||||||
// if children haven't been loaded yet do so first, the editor
|
|
||||||
// might actually be interested in the children!
|
|
||||||
if (clientRef.debugId() != debugId
|
|
||||||
|| clientRef.needsMoreData()) {
|
|
||||||
m_targetToSync = ToolTarget;
|
m_targetToSync = ToolTarget;
|
||||||
m_debugIdToSelect = debugId;
|
m_debugIdToSelect = debugIds.first();
|
||||||
agent()->fetchObject(debugId);
|
selectObject(ObjectReference(m_debugIdToSelect), ToolTarget);
|
||||||
} else {
|
|
||||||
selectObject(clientRef, ToolTarget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
|
void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
|
||||||
@@ -302,18 +289,9 @@ void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugId
|
|||||||
if (debugIds.isEmpty())
|
if (debugIds.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int debugId = debugIds.first();
|
|
||||||
|
|
||||||
ObjectReference clientRef
|
|
||||||
= agent()->objectForId(debugId);
|
|
||||||
|
|
||||||
if (clientRef.debugId() != debugId) {
|
|
||||||
m_targetToSync = EditorTarget;
|
m_targetToSync = EditorTarget;
|
||||||
m_debugIdToSelect = debugId;
|
m_debugIdToSelect = debugIds.first();
|
||||||
agent()->fetchObject(debugId);
|
selectObject(ObjectReference(m_debugIdToSelect), EditorTarget);
|
||||||
} else {
|
|
||||||
selectObject(clientRef, EditorTarget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
|
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
|
||||||
@@ -520,8 +498,7 @@ void QmlInspectorAdapter::gotoObjectReferenceDefinition(
|
|||||||
m_selectionCallbackExpected = true;
|
m_selectionCallbackExpected = true;
|
||||||
|
|
||||||
if (textEditor) {
|
if (textEditor) {
|
||||||
ObjectReference ref = objectReferenceForLocation(fileName);
|
if (objectIdForLocation(fileName) != obj.debugId()) {
|
||||||
if (ref.debugId() != obj.debugId()) {
|
|
||||||
m_selectionCallbackExpected = true;
|
m_selectionCallbackExpected = true;
|
||||||
editorManager->addCurrentPositionToNavigationHistory();
|
editorManager->addCurrentPositionToNavigationHistory();
|
||||||
textEditor->gotoLine(source.lineNumber());
|
textEditor->gotoLine(source.lineNumber());
|
||||||
@@ -530,7 +507,7 @@ void QmlInspectorAdapter::gotoObjectReferenceDefinition(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectReference QmlInspectorAdapter::objectReferenceForLocation(
|
int QmlInspectorAdapter::objectIdForLocation(
|
||||||
const QString &fileName, int cursorPosition) const
|
const QString &fileName, int cursorPosition) const
|
||||||
{
|
{
|
||||||
Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
|
Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
|
||||||
@@ -552,41 +529,13 @@ ObjectReference QmlInspectorAdapter::objectReferenceForLocation(
|
|||||||
= semanticInfo.declaringMemberNoProperties(cursorPosition)) {
|
= semanticInfo.declaringMemberNoProperties(cursorPosition)) {
|
||||||
if (QmlJS::AST::UiObjectMember *objMember
|
if (QmlJS::AST::UiObjectMember *objMember
|
||||||
= node->uiObjectMemberCast()) {
|
= node->uiObjectMemberCast()) {
|
||||||
return agent()->objectForLocation(
|
return agent()->objectIdForLocation(
|
||||||
objMember->firstSourceLocation().startLine,
|
objMember->firstSourceLocation().startLine,
|
||||||
objMember->firstSourceLocation().startColumn);
|
objMember->firstSourceLocation().startColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ObjectReference();
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
inline QString displayName(const ObjectReference &obj)
|
|
||||||
{
|
|
||||||
// special! state names
|
|
||||||
if (obj.className() == "State") {
|
|
||||||
foreach (const PropertyReference &prop, obj.properties()) {
|
|
||||||
if (prop.name() == "name")
|
|
||||||
return prop.value().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// has id?
|
|
||||||
if (!obj.idString().isEmpty())
|
|
||||||
return obj.idString();
|
|
||||||
|
|
||||||
// return the simplified class name then
|
|
||||||
QString objTypeName = obj.className();
|
|
||||||
QStringList declarativeStrings;
|
|
||||||
declarativeStrings << QLatin1String("QDeclarative")
|
|
||||||
<< QLatin1String("QQml");
|
|
||||||
foreach (const QString &str, declarativeStrings) {
|
|
||||||
if (objTypeName.startsWith(str)) {
|
|
||||||
objTypeName = objTypeName.mid(str.length()).section('_', 0, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QString("<%1>").arg(objTypeName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
|
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
|
||||||
@@ -602,7 +551,7 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
|
|||||||
agent()->selectObjectInTree(obj.debugId());
|
agent()->selectObjectInTree(obj.debugId());
|
||||||
|
|
||||||
m_currentSelectedDebugId = obj.debugId();
|
m_currentSelectedDebugId = obj.debugId();
|
||||||
m_currentSelectedDebugName = displayName(obj);
|
m_currentSelectedDebugName = agent()->displayName(obj.debugId());
|
||||||
emit selectionChanged();
|
emit selectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +597,7 @@ void QmlInspectorAdapter::onReloaded()
|
|||||||
|
|
||||||
void QmlInspectorAdapter::onDestroyedObject()
|
void QmlInspectorAdapter::onDestroyedObject()
|
||||||
{
|
{
|
||||||
m_agent->refreshObjectTree();
|
m_agent->queryEngineContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -107,7 +107,7 @@ private:
|
|||||||
void showConnectionStatusMessage(const QString &message);
|
void showConnectionStatusMessage(const QString &message);
|
||||||
|
|
||||||
void gotoObjectReferenceDefinition(const QmlDebug::ObjectReference &obj);
|
void gotoObjectReferenceDefinition(const QmlDebug::ObjectReference &obj);
|
||||||
QmlDebug::ObjectReference objectReferenceForLocation(
|
int objectIdForLocation(
|
||||||
const QString &fileName, int cursorPosition = -1) const;
|
const QString &fileName, int cursorPosition = -1) const;
|
||||||
|
|
||||||
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
|
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
|
||||||
|
@@ -57,7 +57,7 @@ enum {
|
|||||||
*/
|
*/
|
||||||
QmlInspectorAgent::QmlInspectorAgent(DebuggerEngine *engine, QObject *parent)
|
QmlInspectorAgent::QmlInspectorAgent(DebuggerEngine *engine, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_engine(engine)
|
, m_debuggerEngine(engine)
|
||||||
, m_engineClient(0)
|
, m_engineClient(0)
|
||||||
, m_engineQueryId(0)
|
, m_engineQueryId(0)
|
||||||
, m_rootContextQueryId(0)
|
, m_rootContextQueryId(0)
|
||||||
@@ -65,26 +65,9 @@ QmlInspectorAgent::QmlInspectorAgent(DebuggerEngine *engine, QObject *parent)
|
|||||||
{
|
{
|
||||||
connect(debuggerCore()->action(ShowQmlObjectTree),
|
connect(debuggerCore()->action(ShowQmlObjectTree),
|
||||||
SIGNAL(valueChanged(QVariant)), SLOT(updateStatus()));
|
SIGNAL(valueChanged(QVariant)), SLOT(updateStatus()));
|
||||||
}
|
m_delayQueryTimer.setSingleShot(true);
|
||||||
|
m_delayQueryTimer.setInterval(500);
|
||||||
void QmlInspectorAgent::refreshObjectTree()
|
connect(&m_delayQueryTimer, SIGNAL(timeout()), SLOT(queryEngineContext()));
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
qDebug() << __FUNCTION__ << "()";
|
|
||||||
|
|
||||||
if (!m_rootContextQueryId) {
|
|
||||||
m_objectTreeQueryIds.clear();
|
|
||||||
queryEngineContext(m_engines.value(0).debugId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlInspectorAgent::fetchObject(int debugId)
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
qDebug() << __FUNCTION__ << "(" << debugId << ")";
|
|
||||||
|
|
||||||
m_fetchCurrentObjectsQueryIds
|
|
||||||
<< fetchContextObject(ObjectReference(debugId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
|
quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
|
||||||
@@ -92,10 +75,10 @@ quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
|
|||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << debugId << expression
|
qDebug() << __FUNCTION__ << "(" << debugId << expression
|
||||||
<< m_engines.value(0).debugId() << ")";
|
<< m_engine.debugId() << ")";
|
||||||
|
|
||||||
return m_engineClient->queryExpressionResult(debugId, expression,
|
return m_engineClient->queryExpressionResult(debugId, expression,
|
||||||
m_engines.value(0).debugId());
|
m_engine.debugId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
||||||
@@ -106,8 +89,7 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
|||||||
if (data.id && !m_fetchDataIds.contains(data.id)) {
|
if (data.id && !m_fetchDataIds.contains(data.id)) {
|
||||||
// objects
|
// objects
|
||||||
m_fetchDataIds << data.id;
|
m_fetchDataIds << data.id;
|
||||||
ObjectReference ref(data.id);
|
fetchObject(data.id);
|
||||||
m_fetchCurrentObjectsQueryIds << fetchContextObject(ref);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,13 +106,12 @@ void QmlInspectorAgent::selectObjectInTree(int debugId)
|
|||||||
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
|
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << " selecting" << iname << "in tree";
|
qDebug() << " selecting" << iname << "in tree";
|
||||||
m_engine->watchHandler()->setCurrentItem(iname);
|
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
|
||||||
m_objectToSelect = 0;
|
m_objectToSelect = 0;
|
||||||
} else {
|
} else {
|
||||||
// we've to fetch it
|
// we've to fetch it
|
||||||
m_objectToSelect = debugId;
|
m_objectToSelect = debugId;
|
||||||
m_fetchCurrentObjectsQueryIds
|
fetchObject(debugId);
|
||||||
<< fetchContextObject(ObjectReference(debugId));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,49 +203,45 @@ quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId,
|
|||||||
return queryId;
|
return queryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<ObjectReference> QmlInspectorAgent::objects() const
|
|
||||||
{
|
|
||||||
QList<ObjectReference> result;
|
|
||||||
foreach (const ObjectReference &it, m_rootObjects)
|
|
||||||
result.append(objects(it));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectReference QmlInspectorAgent::objectForId(int debugId) const
|
|
||||||
{
|
|
||||||
foreach (const ObjectReference &it, m_rootObjects) {
|
|
||||||
ObjectReference result = objectForId(debugId, it);
|
|
||||||
if (result.debugId() == debugId)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return ObjectReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectReference QmlInspectorAgent::objectForId(
|
ObjectReference QmlInspectorAgent::objectForId(
|
||||||
const QString &objectId) const
|
const QString &objectId) const
|
||||||
{
|
{
|
||||||
if (!objectId.isEmpty() && objectId[0].isLower()) {
|
if (!objectId.isEmpty() && objectId[0].isLower()) {
|
||||||
const QList<ObjectReference> refs = objects();
|
QHashIterator<int, QByteArray> iter(m_debugIdToIname);
|
||||||
foreach (const ObjectReference &ref, refs) {
|
while (iter.hasNext()) {
|
||||||
if (ref.idString() == objectId)
|
iter.next();
|
||||||
return ref;
|
if (m_debuggerEngine->watchHandler()->findData(iter.value())->name == objectId)
|
||||||
|
return ObjectReference(iter.key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ObjectReference();
|
return ObjectReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectReference QmlInspectorAgent::objectForLocation(
|
int QmlInspectorAgent::objectIdForLocation(
|
||||||
int line, int column) const
|
int line, int column) const
|
||||||
{
|
{
|
||||||
const QList<ObjectReference> refs = objects();
|
QHashIterator<int, FileReference> iter(m_debugIdLocations);
|
||||||
foreach (const ObjectReference &ref, refs) {
|
while (iter.hasNext()) {
|
||||||
if (ref.source().lineNumber() == line
|
iter.next();
|
||||||
&& ref.source().columnNumber() == column)
|
const FileReference &ref = iter.value();
|
||||||
return ref;
|
if (ref.lineNumber() == line
|
||||||
|
&& ref.columnNumber() == column)
|
||||||
|
return iter.key();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ObjectReference();
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int,QString> QmlInspectorAgent::rootObjectIds() const
|
||||||
|
{
|
||||||
|
QHash<int,QString> rIds;
|
||||||
|
foreach (const QByteArray &in, m_debugIdToIname) {
|
||||||
|
const WatchData *data = m_debuggerEngine->watchHandler()->findData(in);
|
||||||
|
int debugId = data->id;
|
||||||
|
QString className = data->type;
|
||||||
|
rIds.insert(debugId, className);
|
||||||
|
}
|
||||||
|
return rIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlInspectorAgent::addObjectWatch(int objectDebugId)
|
bool QmlInspectorAgent::addObjectWatch(int objectDebugId)
|
||||||
@@ -283,14 +260,13 @@ bool QmlInspectorAgent::addObjectWatch(int objectDebugId)
|
|||||||
if (m_objectWatches.contains(objectDebugId))
|
if (m_objectWatches.contains(objectDebugId))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ObjectReference ref = objectForId(objectDebugId);
|
if (!m_debugIdToIname.contains(objectDebugId))
|
||||||
if (ref.debugId() != objectDebugId)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// is flooding the debugging output log!
|
// is flooding the debugging output log!
|
||||||
// log(LogSend, QString("WATCH_PROPERTY %1").arg(objectDebugId));
|
// log(LogSend, QString("WATCH_PROPERTY %1").arg(objectDebugId));
|
||||||
|
|
||||||
if (m_engineClient->addWatch(ref))
|
if (m_engineClient->addWatch(objectDebugId))
|
||||||
m_objectWatches.append(objectDebugId);
|
m_objectWatches.append(objectDebugId);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -356,6 +332,21 @@ void QmlInspectorAgent::setEngineClient(BaseEngineDebugClient *client)
|
|||||||
updateStatus();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QmlInspectorAgent::displayName(int objectDebugId) const
|
||||||
|
{
|
||||||
|
if (!isConnected()
|
||||||
|
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
if (m_debugIdToIname.contains(objectDebugId)) {
|
||||||
|
const WatchData *data = m_debuggerEngine->watchHandler()->findData(
|
||||||
|
m_debugIdToIname.value(objectDebugId));
|
||||||
|
QTC_ASSERT(data, return QString());
|
||||||
|
return data->name;
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::updateStatus()
|
void QmlInspectorAgent::updateStatus()
|
||||||
{
|
{
|
||||||
if (m_engineClient
|
if (m_engineClient
|
||||||
@@ -363,8 +354,7 @@ void QmlInspectorAgent::updateStatus()
|
|||||||
&& debuggerCore()->boolSetting(ShowQmlObjectTree)) {
|
&& debuggerCore()->boolSetting(ShowQmlObjectTree)) {
|
||||||
reloadEngines();
|
reloadEngines();
|
||||||
} else {
|
} else {
|
||||||
// Clear view.
|
clearObjectTree();
|
||||||
m_engine->watchHandler()->removeChildren("inspect");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,31 +373,27 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
|
|||||||
|
|
||||||
if (m_objectTreeQueryIds.contains(queryId)) {
|
if (m_objectTreeQueryIds.contains(queryId)) {
|
||||||
m_objectTreeQueryIds.removeOne(queryId);
|
m_objectTreeQueryIds.removeOne(queryId);
|
||||||
objectTreeFetched(qvariant_cast<ObjectReference>(value));
|
|
||||||
} else if (queryId == m_engineQueryId) {
|
|
||||||
m_engineQueryId = 0;
|
|
||||||
updateEngineList(qvariant_cast<QList<EngineReference> >(value));
|
|
||||||
} else if (queryId == m_rootContextQueryId) {
|
|
||||||
m_rootContextQueryId = 0;
|
|
||||||
rootContextChanged(qvariant_cast<ContextReference>(value));
|
|
||||||
} else if (m_fetchCurrentObjectsQueryIds.contains(queryId)) {
|
|
||||||
m_fetchCurrentObjectsQueryIds.removeOne(queryId);
|
|
||||||
if (value.type() == QVariant::List) {
|
if (value.type() == QVariant::List) {
|
||||||
QVariantList objList = value.toList();
|
QVariantList objList = value.toList();
|
||||||
foreach (QVariant var, objList) {
|
foreach (QVariant var, objList) {
|
||||||
// TODO: check which among the list is the actual
|
// TODO: check which among the list is the actual
|
||||||
// object that needs to be selected.
|
// object that needs to be selected.
|
||||||
ObjectReference obj
|
objectTreeFetched(qvariant_cast<ObjectReference>(var));
|
||||||
= qvariant_cast<ObjectReference>(var);
|
|
||||||
m_fetchCurrentObjects.push_front(obj);
|
|
||||||
onCurrentObjectsFetched(obj);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ObjectReference obj
|
objectTreeFetched(qvariant_cast<ObjectReference>(value));
|
||||||
= qvariant_cast<ObjectReference>(value);
|
|
||||||
m_fetchCurrentObjects.push_front(obj);
|
|
||||||
onCurrentObjectsFetched(obj);
|
|
||||||
}
|
}
|
||||||
|
} else if (queryId == m_engineQueryId) {
|
||||||
|
m_engineQueryId = 0;
|
||||||
|
QList<EngineReference> engines = qvariant_cast<QList<EngineReference> >(value);
|
||||||
|
QTC_ASSERT(engines.count(), return);
|
||||||
|
// only care about first engine atm
|
||||||
|
m_engine = engines.at(0);
|
||||||
|
queryEngineContext();
|
||||||
|
} else if (queryId == m_rootContextQueryId) {
|
||||||
|
m_rootContextQueryId = 0;
|
||||||
|
clearObjectTree();
|
||||||
|
fetchObjectsInContextRecursive(qvariant_cast<ContextReference>(value));
|
||||||
} else {
|
} else {
|
||||||
emit expressionResult(queryId, value);
|
emit expressionResult(queryId, value);
|
||||||
}
|
}
|
||||||
@@ -417,13 +403,19 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::newObject(int /*engineId*/, int /*objectId*/, int /*parentId*/)
|
void QmlInspectorAgent::newObject(int engineId, int objectId, int /*parentId*/)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "()";
|
qDebug() << __FUNCTION__ << "()";
|
||||||
|
|
||||||
log(LogReceive, QString("OBJECT_CREATED"));
|
log(LogReceive, QString("OBJECT_CREATED"));
|
||||||
refreshObjectTree();
|
|
||||||
|
if (m_engine.debugId() != engineId)
|
||||||
|
return;
|
||||||
|
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER)
|
||||||
|
fetchObject(objectId);
|
||||||
|
else
|
||||||
|
m_delayQueryTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::reloadEngines()
|
void QmlInspectorAgent::reloadEngines()
|
||||||
@@ -439,39 +431,36 @@ void QmlInspectorAgent::reloadEngines()
|
|||||||
m_engineQueryId = m_engineClient->queryAvailableEngines();
|
m_engineQueryId = m_engineClient->queryAvailableEngines();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::queryEngineContext(int id)
|
void QmlInspectorAgent::queryEngineContext()
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << id << ")";
|
qDebug() << __FUNCTION__;
|
||||||
|
|
||||||
if (id < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!isConnected()
|
if (!isConnected()
|
||||||
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log(LogSend, QString("LIST_OBJECTS %1").arg(QString::number(id)));
|
log(LogSend, QString("LIST_OBJECTS"));
|
||||||
|
|
||||||
m_rootContextQueryId
|
m_rootContextQueryId
|
||||||
= m_engineClient->queryRootContexts(EngineReference(id));
|
= m_engineClient->queryRootContexts(m_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QmlInspectorAgent::fetchContextObject(const ObjectReference &obj)
|
void QmlInspectorAgent::fetchObject(int debugId)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << obj << ")";
|
qDebug() << __FUNCTION__ << "(" << debugId << ")";
|
||||||
|
|
||||||
if (!isConnected()
|
if (!isConnected()
|
||||||
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
log(LogSend, QString("FETCH_OBJECT %1").arg(obj.idString()));
|
log(LogSend, QString("FETCH_OBJECT %1").arg(QString::number(debugId)));
|
||||||
quint32 queryId = m_engineClient->queryObject(obj);
|
quint32 queryId = m_engineClient->queryObject(debugId);
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << obj.debugId() << ")"
|
qDebug() << __FUNCTION__ << "(" << debugId << ")"
|
||||||
<< " - query id" << queryId;
|
<< " - query id" << queryId;
|
||||||
return queryId;
|
m_objectTreeQueryIds << queryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
|
void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
|
||||||
@@ -495,60 +484,32 @@ void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
|
|||||||
qDebug() << __FUNCTION__ << "(" << file << ":" << lineNumber
|
qDebug() << __FUNCTION__ << "(" << file << ":" << lineNumber
|
||||||
<< ":" << columnNumber << ")" << " - query id" << queryId;
|
<< ":" << columnNumber << ")" << " - query id" << queryId;
|
||||||
|
|
||||||
m_fetchCurrentObjectsQueryIds << queryId;
|
m_objectTreeQueryIds << queryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the root objects from the context + any child contexts
|
// fetch the root objects from the context + any child contexts
|
||||||
void QmlInspectorAgent::fetchRootObjects(const ContextReference &context,
|
void QmlInspectorAgent::fetchObjectsInContextRecursive(const ContextReference &context)
|
||||||
bool clear)
|
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << context << clear << ")";
|
qDebug() << __FUNCTION__ << "(" << context << ")";
|
||||||
|
|
||||||
if (!isConnected()
|
if (!isConnected()
|
||||||
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
|| !debuggerCore()->boolSetting(ShowQmlObjectTree))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (clear) {
|
|
||||||
m_rootObjects.clear();
|
|
||||||
m_objectTreeQueryIds.clear();
|
|
||||||
}
|
|
||||||
foreach (const ObjectReference & obj, context.objects()) {
|
foreach (const ObjectReference & obj, context.objects()) {
|
||||||
quint32 queryId = 0;
|
|
||||||
using namespace QmlDebug::Constants;
|
using namespace QmlDebug::Constants;
|
||||||
if (m_engineClient->objectName() == QML_DEBUGGER &&
|
if (m_engineClient->objectName() == QML_DEBUGGER &&
|
||||||
m_engineClient->serviceVersion() >= CURRENT_SUPPORTED_VERSION) {
|
m_engineClient->serviceVersion() >= CURRENT_SUPPORTED_VERSION) {
|
||||||
//Fetch only root objects
|
//Fetch only root objects
|
||||||
if (obj.parentId() == -1)
|
if (obj.parentId() == -1)
|
||||||
queryId = fetchContextObject(obj);
|
fetchObject(obj.debugId());
|
||||||
} else {
|
} else {
|
||||||
queryId = m_engineClient->queryObjectRecursive(obj);
|
m_objectTreeQueryIds << m_engineClient->queryObjectRecursive(obj.debugId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryId)
|
|
||||||
m_objectTreeQueryIds << queryId;
|
|
||||||
}
|
}
|
||||||
foreach (const ContextReference &child, context.contexts())
|
foreach (const ContextReference &child, context.contexts())
|
||||||
fetchRootObjects(child, false);
|
fetchObjectsInContextRecursive(child);
|
||||||
}
|
|
||||||
|
|
||||||
void QmlInspectorAgent::updateEngineList(const QList<EngineReference> &engines)
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
qDebug() << __FUNCTION__ << "(" << engines << ")";
|
|
||||||
|
|
||||||
m_engines = engines;
|
|
||||||
|
|
||||||
// only care about first engine atm
|
|
||||||
queryEngineContext(engines.first().debugId());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlInspectorAgent::rootContextChanged(const ContextReference &context)
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
qDebug() << __FUNCTION__ << "(" << context << ")";
|
|
||||||
|
|
||||||
fetchRootObjects(context, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
|
void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
|
||||||
@@ -556,90 +517,75 @@ void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
|
|||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << object << ")";
|
qDebug() << __FUNCTION__ << "(" << object << ")";
|
||||||
|
|
||||||
m_rootObjects.append(object);
|
if (!object.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
if (m_objectTreeQueryIds.isEmpty()) {
|
m_objectStack.push(object);
|
||||||
int old_count = m_debugIdHash.count();
|
|
||||||
m_debugIdHash.clear();
|
|
||||||
m_debugIdHash.reserve(old_count + 1);
|
|
||||||
m_debugIdToIname.clear();
|
|
||||||
foreach (const ObjectReference &it, m_rootObjects)
|
|
||||||
buildDebugIdHashRecursive(it);
|
|
||||||
|
|
||||||
emit objectTreeUpdated();
|
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
|
if (object.parentId() != -1 && !m_debugIdToIname.contains(object.parentId())) {
|
||||||
|
fetchObject(object.parentId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (m_objectTreeQueryIds.count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// sync tree with watchhandler
|
// sync tree with watchhandler
|
||||||
QList<WatchData> watchData;
|
QList<WatchData> watchData;
|
||||||
foreach (const ObjectReference &obj, m_rootObjects)
|
ObjectReference last;
|
||||||
watchData.append(buildWatchData(obj, WatchData()));
|
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
|
while (!m_objectStack.isEmpty()) {
|
||||||
QElapsedTimer t;
|
last = m_objectStack.pop();
|
||||||
if (debug) {
|
QByteArray parentIname;
|
||||||
t.start();
|
if (last.parentId() != -1) {
|
||||||
qDebug() << "inserting " << watchData.size()
|
QTC_ASSERT(m_debugIdToIname.contains(last.parentId()), return);
|
||||||
<< "entries into watch handler ...";
|
parentIname = m_debugIdToIname.value(last.parentId());
|
||||||
}
|
}
|
||||||
|
watchData.append(buildWatchData(last, parentIname));
|
||||||
m_engine->watchHandler()->insertData(watchData);
|
buildDebugIdHashRecursive(last);
|
||||||
|
}
|
||||||
if (debug)
|
} else {
|
||||||
qDebug() << "inserting entries took" << t.elapsed() << "ms";
|
QVectorIterator<ObjectReference> iter(m_objectStack);
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
const ObjectReference &r = iter.next();
|
||||||
|
int pid = -1;
|
||||||
|
QHashIterator<int, QList<int> > i(m_debugIdChildIds);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
QList<int> cids = i.value();
|
||||||
|
foreach (int cid, cids) {
|
||||||
|
if (cid == r.debugId()) {
|
||||||
|
pid = i.key();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pid != -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QByteArray parentIname;
|
||||||
|
if (m_debugIdToIname.contains(pid))
|
||||||
|
parentIname = m_debugIdToIname.value(r.parentId());
|
||||||
|
watchData.append(buildWatchData(r, parentIname));
|
||||||
|
buildDebugIdHashRecursive(r);
|
||||||
|
}
|
||||||
|
m_objectStack.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::onCurrentObjectsFetched(const ObjectReference &obj)
|
m_debuggerEngine->watchHandler()->insertData(watchData);
|
||||||
{
|
emit objectTreeUpdated();
|
||||||
if (debug)
|
|
||||||
qDebug() << __FUNCTION__ << "( " << obj << ")";
|
|
||||||
|
|
||||||
// get parents if not known yet
|
if (m_engineClient->objectName() == QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
if (!getObjectHierarchy(obj))
|
emit objectFetched(last);
|
||||||
return;
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
qDebug() << " adding" << m_fetchCurrentObjects << "to tree";
|
|
||||||
|
|
||||||
foreach (const ObjectReference &o, m_fetchCurrentObjects)
|
|
||||||
addObjectToTree(o, false);
|
|
||||||
|
|
||||||
ObjectReference last = m_fetchCurrentObjects.last();
|
|
||||||
m_fetchCurrentObjects.clear();
|
|
||||||
m_fetchDataIds.clear();
|
|
||||||
|
|
||||||
if (m_objectToSelect == last.debugId()) {
|
if (m_objectToSelect == last.debugId()) {
|
||||||
// select item in view
|
// select item in view
|
||||||
QByteArray iname = m_debugIdToIname.value(last.debugId());
|
QByteArray iname = m_debugIdToIname.value(last.debugId());
|
||||||
WatchHandler *handler = m_engine->watchHandler();
|
|
||||||
QTC_ASSERT(handler->hasItem(iname), return);
|
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << " selecting" << iname << "in tree";
|
qDebug() << " selecting" << iname << "in tree";
|
||||||
handler->setCurrentItem(iname);
|
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
|
||||||
m_objectToSelect = -1;
|
m_objectToSelect = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit objectFetched(last);
|
|
||||||
emit objectTreeUpdated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetches all anchestors of object. Returns if all has been fetched already.
|
|
||||||
bool QmlInspectorAgent::getObjectHierarchy(const ObjectReference &obj)
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
qDebug() << __FUNCTION__ << "(" << obj << ")";
|
|
||||||
|
|
||||||
ObjectReference parent = objectForId(obj.parentId());
|
|
||||||
//for root object
|
|
||||||
if (obj.parentId() == -1)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
//for other objects
|
|
||||||
if (parent.debugId() == -1 || parent.needsMoreData()) {
|
|
||||||
m_fetchCurrentObjectsQueryIds
|
|
||||||
<< fetchContextObject(ObjectReference(obj.parentId()));
|
|
||||||
} else {
|
|
||||||
return getObjectHierarchy(parent);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
|
void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
|
||||||
@@ -662,35 +608,35 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString filePath
|
const QString filePath
|
||||||
= m_engine->toFileInProject(fileUrl);
|
= m_debuggerEngine->toFileInProject(fileUrl);
|
||||||
|
|
||||||
// append the debug ids in the hash
|
// append the debug ids in the hash
|
||||||
QPair<QString, int> file = qMakePair<QString, int>(filePath, rev);
|
QPair<QString, int> file = qMakePair<QString, int>(filePath, rev);
|
||||||
QPair<int, int> location = qMakePair<int, int>(lineNum, colNum);
|
QPair<int, int> location = qMakePair<int, int>(lineNum, colNum);
|
||||||
if (!m_debugIdHash[file][location].contains(ref.debugId()))
|
if (!m_debugIdHash[file][location].contains(ref.debugId()))
|
||||||
m_debugIdHash[file][location].append(ref.debugId());
|
m_debugIdHash[file][location].append(ref.debugId());
|
||||||
|
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
|
||||||
foreach (const ObjectReference &it, ref.children())
|
foreach (const ObjectReference &it, ref.children())
|
||||||
buildDebugIdHashRecursive(it);
|
buildDebugIdHashRecursive(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray buildIName(const WatchData &parent, int debugId)
|
static QByteArray buildIName(const QByteArray &parentIname, int debugId)
|
||||||
{
|
{
|
||||||
if (!parent.isValid())
|
if (parentIname.isEmpty())
|
||||||
return "inspect." + QByteArray::number(debugId);
|
return "inspect." + QByteArray::number(debugId);
|
||||||
return parent.iname + "." + QByteArray::number(debugId);
|
return parentIname + "." + QByteArray::number(debugId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray buildIName(const WatchData &parent, const QString &name)
|
static QByteArray buildIName(const QByteArray &parentIname, const QString &name)
|
||||||
{
|
{
|
||||||
return parent.iname + "." + name.toLatin1();
|
return parentIname + "." + name.toLatin1();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
||||||
const WatchData &parent)
|
const QByteArray &parentIname)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << __FUNCTION__ << "(" << obj << parent.iname << ")";
|
qDebug() << __FUNCTION__ << "(" << obj << parentIname << ")";
|
||||||
|
|
||||||
QList<WatchData> list;
|
QList<WatchData> list;
|
||||||
|
|
||||||
@@ -699,11 +645,14 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
name = obj.className();
|
name = obj.className();
|
||||||
|
|
||||||
|
if (name.isEmpty())
|
||||||
|
return list;
|
||||||
|
|
||||||
// object
|
// object
|
||||||
objWatch.id = obj.debugId();
|
objWatch.id = obj.debugId();
|
||||||
objWatch.exp = name.toLatin1();
|
objWatch.exp = name.toLatin1();
|
||||||
objWatch.name = name;
|
objWatch.name = name;
|
||||||
objWatch.iname = buildIName(parent, obj.debugId());
|
objWatch.iname = buildIName(parentIname, obj.debugId());
|
||||||
objWatch.type = obj.className().toLatin1();
|
objWatch.type = obj.className().toLatin1();
|
||||||
objWatch.value = _("object");
|
objWatch.value = _("object");
|
||||||
objWatch.setHasChildren(true);
|
objWatch.setHasChildren(true);
|
||||||
@@ -712,7 +661,17 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
list.append(objWatch);
|
list.append(objWatch);
|
||||||
m_debugIdToIname.insert(objWatch.id, objWatch.iname);
|
m_debugIdToIname.insert(objWatch.id, objWatch.iname);
|
||||||
|
|
||||||
if (!m_engine->watchHandler()->isExpandedIName(objWatch.iname)
|
if (m_engineClient->objectName() != QmlDebug::Constants::QML_DEBUGGER) {
|
||||||
|
QList<int> childIds;
|
||||||
|
foreach (const ObjectReference &c, obj.children()) {
|
||||||
|
childIds << c.debugId();
|
||||||
|
}
|
||||||
|
// For 4.x, we do not get the parentId. Hence, store the child ids
|
||||||
|
// to look up correct insertion places later
|
||||||
|
m_debugIdChildIds.insert(objWatch.id, childIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_debuggerEngine->watchHandler()->isExpandedIName(objWatch.iname)
|
||||||
&& obj.needsMoreData()) {
|
&& obj.needsMoreData()) {
|
||||||
// we don't know the children yet. Not adding the 'properties'
|
// we don't know the children yet. Not adding the 'properties'
|
||||||
// element makes sure we're queried on expansion.
|
// element makes sure we're queried on expansion.
|
||||||
@@ -720,6 +679,7 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// properties
|
// properties
|
||||||
|
if (obj.properties().count()) {
|
||||||
WatchData propertiesWatch;
|
WatchData propertiesWatch;
|
||||||
propertiesWatch.id = objWatch.id;
|
propertiesWatch.id = objWatch.id;
|
||||||
propertiesWatch.exp = "";
|
propertiesWatch.exp = "";
|
||||||
@@ -736,78 +696,21 @@ QList<WatchData> QmlInspectorAgent::buildWatchData(const ObjectReference &obj,
|
|||||||
WatchData propertyWatch;
|
WatchData propertyWatch;
|
||||||
propertyWatch.exp = property.name().toLatin1();
|
propertyWatch.exp = property.name().toLatin1();
|
||||||
propertyWatch.name = property.name();
|
propertyWatch.name = property.name();
|
||||||
propertyWatch.iname = buildIName(propertiesWatch, property.name());
|
propertyWatch.iname = buildIName(propertiesWatch.iname, property.name());
|
||||||
propertyWatch.type = property.valueTypeName().toLatin1();
|
propertyWatch.type = property.valueTypeName().toLatin1();
|
||||||
propertyWatch.value = property.value().toString();
|
propertyWatch.value = property.value().toString();
|
||||||
propertyWatch.setAllUnneeded();
|
propertyWatch.setAllUnneeded();
|
||||||
propertyWatch.setHasChildren(false);
|
propertyWatch.setHasChildren(false);
|
||||||
list.append(propertyWatch);
|
list.append(propertyWatch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// recurse
|
// recurse
|
||||||
foreach (const ObjectReference &child, obj.children())
|
foreach (const ObjectReference &child, obj.children())
|
||||||
list.append(buildWatchData(child, objWatch));
|
list.append(buildWatchData(child, objWatch.iname));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::addObjectToTree(const ObjectReference &obj,
|
|
||||||
bool notify)
|
|
||||||
{
|
|
||||||
int count = m_rootObjects.count();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
int parentId = obj.parentId();
|
|
||||||
if (m_engineClient->serviceVersion() < 2
|
|
||||||
&& !m_rootObjects.contains(obj)) {
|
|
||||||
// we don't get parentId in qt 4.x
|
|
||||||
parentId = m_rootObjects[i].insertObjectInTree(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentId >= 0) {
|
|
||||||
buildDebugIdHashRecursive(obj);
|
|
||||||
if (notify)
|
|
||||||
emit objectTreeUpdated();
|
|
||||||
|
|
||||||
// find parent
|
|
||||||
QTC_ASSERT(m_debugIdToIname.contains(parentId), break);
|
|
||||||
QByteArray iname = m_debugIdToIname.value(parentId);
|
|
||||||
WatchHandler *handler = m_engine->watchHandler();
|
|
||||||
const WatchData *parent = handler->findData(iname);
|
|
||||||
if (parent) {
|
|
||||||
QList<WatchData> watches = buildWatchData(obj, *parent);
|
|
||||||
handler->insertData(watches);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectReference QmlInspectorAgent::objectForId(int debugId,
|
|
||||||
const ObjectReference &objectRef) const
|
|
||||||
{
|
|
||||||
if (objectRef.debugId() == debugId)
|
|
||||||
return objectRef;
|
|
||||||
|
|
||||||
foreach (const ObjectReference &child, objectRef.children()) {
|
|
||||||
ObjectReference result = objectForId(debugId, child);
|
|
||||||
if (result.debugId() == debugId)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ObjectReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<ObjectReference> QmlInspectorAgent::objects(
|
|
||||||
const ObjectReference &objectRef) const
|
|
||||||
{
|
|
||||||
QList<ObjectReference> result;
|
|
||||||
result.append(objectRef);
|
|
||||||
|
|
||||||
foreach (const ObjectReference &child, objectRef.children())
|
|
||||||
result.append(objects(child));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlInspectorAgent::log(QmlInspectorAgent::LogDirection direction,
|
void QmlInspectorAgent::log(QmlInspectorAgent::LogDirection direction,
|
||||||
const QString &message)
|
const QString &message)
|
||||||
{
|
{
|
||||||
@@ -818,15 +721,29 @@ void QmlInspectorAgent::log(QmlInspectorAgent::LogDirection direction,
|
|||||||
msg += _(" receiving ");
|
msg += _(" receiving ");
|
||||||
msg += message;
|
msg += message;
|
||||||
|
|
||||||
if (m_engine)
|
if (m_debuggerEngine)
|
||||||
m_engine->showMessage(msg, LogDebug);
|
m_debuggerEngine->showMessage(msg, LogDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlInspectorAgent::isConnected()
|
bool QmlInspectorAgent::isConnected() const
|
||||||
{
|
{
|
||||||
return m_engineClient
|
return m_engineClient
|
||||||
&& (m_engineClient->status() == QmlDebug::Enabled);
|
&& (m_engineClient->status() == QmlDebug::Enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlInspectorAgent::clearObjectTree()
|
||||||
|
{
|
||||||
|
// clear view
|
||||||
|
m_debuggerEngine->watchHandler()->removeChildren("inspect");
|
||||||
|
|
||||||
|
m_objectTreeQueryIds.clear();
|
||||||
|
|
||||||
|
int old_count = m_debugIdHash.count();
|
||||||
|
m_debugIdHash.clear();
|
||||||
|
m_debugIdHash.reserve(old_count + 1);
|
||||||
|
m_debugIdToIname.clear();
|
||||||
|
m_debugIdChildIds.clear();
|
||||||
|
m_objectStack.clear();
|
||||||
|
}
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Debugger
|
} // Debugger
|
||||||
|
@@ -34,6 +34,8 @@
|
|||||||
#define QMLINSPECTORAGENT_H
|
#define QMLINSPECTORAGENT_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QStack>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <qmldebug/baseenginedebugclient.h>
|
#include <qmldebug/baseenginedebugclient.h>
|
||||||
#include <watchdata.h>
|
#include <watchdata.h>
|
||||||
@@ -57,7 +59,6 @@ public:
|
|||||||
explicit QmlInspectorAgent(DebuggerEngine *engine, QObject *parent = 0);
|
explicit QmlInspectorAgent(DebuggerEngine *engine, QObject *parent = 0);
|
||||||
|
|
||||||
|
|
||||||
void refreshObjectTree();
|
|
||||||
void fetchObject(int debugId);
|
void fetchObject(int debugId);
|
||||||
quint32 queryExpressionResult(int debugId, const QString &expression);
|
quint32 queryExpressionResult(int debugId, const QString &expression);
|
||||||
|
|
||||||
@@ -75,11 +76,9 @@ public:
|
|||||||
quint32 resetBindingForObject(int objectDebugId,
|
quint32 resetBindingForObject(int objectDebugId,
|
||||||
const QString &propertyName);
|
const QString &propertyName);
|
||||||
|
|
||||||
QList<QmlDebug::ObjectReference> objects() const;
|
|
||||||
QmlDebug::ObjectReference objectForId(int debugId) const;
|
|
||||||
QmlDebug::ObjectReference objectForId(const QString &objectId) const;
|
QmlDebug::ObjectReference objectForId(const QString &objectId) const;
|
||||||
QmlDebug::ObjectReference objectForLocation(int line, int column) const;
|
int objectIdForLocation(int line, int column) const;
|
||||||
QList<QmlDebug::ObjectReference> rootObjects() const { return m_rootObjects; }
|
QHash<int, QString> rootObjectIds() const;
|
||||||
DebugIdHash debugIdHash() const { return m_debugIdHash; }
|
DebugIdHash debugIdHash() const { return m_debugIdHash; }
|
||||||
|
|
||||||
bool addObjectWatch(int objectDebugId);
|
bool addObjectWatch(int objectDebugId);
|
||||||
@@ -88,10 +87,13 @@ public:
|
|||||||
void removeAllObjectWatches();
|
void removeAllObjectWatches();
|
||||||
|
|
||||||
void setEngineClient(QmlDebug::BaseEngineDebugClient *client);
|
void setEngineClient(QmlDebug::BaseEngineDebugClient *client);
|
||||||
|
QString displayName(int objectDebugId) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void fetchContextObjectsForLocation(const QString &file,
|
void fetchContextObjectsForLocation(const QString &file,
|
||||||
int lineNumber, int columnNumber);
|
int lineNumber, int columnNumber);
|
||||||
|
void queryEngineContext();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void objectTreeUpdated();
|
void objectTreeUpdated();
|
||||||
void objectFetched(const QmlDebug::ObjectReference &ref);
|
void objectFetched(const QmlDebug::ObjectReference &ref);
|
||||||
@@ -106,28 +108,13 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void reloadEngines();
|
void reloadEngines();
|
||||||
void queryEngineContext(int id);
|
void fetchObjectsInContextRecursive(const QmlDebug::ContextReference &context);
|
||||||
quint32 fetchContextObject(const QmlDebug::ObjectReference &obj);
|
|
||||||
void fetchRootObjects(const QmlDebug::ContextReference &context, bool clear);
|
|
||||||
|
|
||||||
void updateEngineList(const QList<QmlDebug::EngineReference> &engines);
|
|
||||||
void rootContextChanged(const QmlDebug::ContextReference &context);
|
|
||||||
void objectTreeFetched(const QmlDebug::ObjectReference &result);
|
void objectTreeFetched(const QmlDebug::ObjectReference &result);
|
||||||
void onCurrentObjectsFetched(const QmlDebug::ObjectReference &result);
|
|
||||||
bool getObjectHierarchy(const QmlDebug::ObjectReference &object);
|
|
||||||
|
|
||||||
|
|
||||||
void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
|
void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
|
||||||
QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
|
QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
|
||||||
const WatchData &parent);
|
const QByteArray &parentIname);
|
||||||
void addObjectToTree(const QmlDebug::ObjectReference &obj, bool notify);
|
|
||||||
|
|
||||||
QmlDebug::ObjectReference objectForId(
|
|
||||||
int debugId,
|
|
||||||
const QmlDebug::ObjectReference &ref) const;
|
|
||||||
QList<QmlDebug::ObjectReference> objects(
|
|
||||||
const QmlDebug::ObjectReference &objectRef) const;
|
|
||||||
|
|
||||||
|
|
||||||
enum LogDirection {
|
enum LogDirection {
|
||||||
LogSend,
|
LogSend,
|
||||||
@@ -135,25 +122,27 @@ private:
|
|||||||
};
|
};
|
||||||
void log(LogDirection direction, const QString &message);
|
void log(LogDirection direction, const QString &message);
|
||||||
|
|
||||||
bool isConnected();
|
bool isConnected() const;
|
||||||
|
void clearObjectTree();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DebuggerEngine *m_engine;
|
DebuggerEngine *m_debuggerEngine;
|
||||||
QmlDebug::BaseEngineDebugClient *m_engineClient;
|
QmlDebug::BaseEngineDebugClient *m_engineClient;
|
||||||
|
|
||||||
quint32 m_engineQueryId;
|
quint32 m_engineQueryId;
|
||||||
quint32 m_rootContextQueryId;
|
quint32 m_rootContextQueryId;
|
||||||
int m_objectToSelect;
|
int m_objectToSelect;
|
||||||
QList<quint32> m_objectTreeQueryIds;
|
QList<quint32> m_objectTreeQueryIds;
|
||||||
QList<QmlDebug::ObjectReference> m_rootObjects;
|
QStack<QmlDebug::ObjectReference> m_objectStack;
|
||||||
QList<quint32> m_fetchCurrentObjectsQueryIds;
|
QmlDebug::EngineReference m_engine;
|
||||||
QList<QmlDebug::ObjectReference> m_fetchCurrentObjects;
|
|
||||||
QList<QmlDebug::EngineReference> m_engines;
|
|
||||||
QHash<int, QByteArray> m_debugIdToIname;
|
QHash<int, QByteArray> m_debugIdToIname;
|
||||||
|
QHash<int, QList<int> > m_debugIdChildIds; // This is for 4.x
|
||||||
|
QHash<int, QmlDebug::FileReference> m_debugIdLocations;
|
||||||
DebugIdHash m_debugIdHash;
|
DebugIdHash m_debugIdHash;
|
||||||
|
|
||||||
QList<int> m_objectWatches;
|
QList<int> m_objectWatches;
|
||||||
QList<int> m_fetchDataIds;
|
QList<int> m_fetchDataIds;
|
||||||
|
QTimer m_delayQueryTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
@@ -440,19 +440,6 @@ void QmlLiveTextPreview::setApplyChangesToQmlInspector(bool applyChanges)
|
|||||||
m_applyChangesToQmlInspector = applyChanges;
|
m_applyChangesToQmlInspector = applyChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QList<int> findRootObjectRecursive(const ObjectReference &object,
|
|
||||||
const Document::Ptr &doc)
|
|
||||||
{
|
|
||||||
QList<int> result;
|
|
||||||
if (object.className() == doc->componentName())
|
|
||||||
result += object.debugId();
|
|
||||||
|
|
||||||
foreach (const ObjectReference &it, object.children()) {
|
|
||||||
result += findRootObjectRecursive(it, doc);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlLiveTextPreview::updateDebugIds()
|
void QmlLiveTextPreview::updateDebugIds()
|
||||||
{
|
{
|
||||||
if (!m_initialDoc->qmlProgram())
|
if (!m_initialDoc->qmlProgram())
|
||||||
@@ -485,10 +472,12 @@ void QmlLiveTextPreview::updateDebugIds()
|
|||||||
// Map the root nodes of the document.
|
// Map the root nodes of the document.
|
||||||
if (doc->qmlProgram()->members && doc->qmlProgram()->members->member) {
|
if (doc->qmlProgram()->members && doc->qmlProgram()->members->member) {
|
||||||
UiObjectMember *root = doc->qmlProgram()->members->member;
|
UiObjectMember *root = doc->qmlProgram()->members->member;
|
||||||
|
QHashIterator<int,QString> rIds(m_inspectorAdapter->agent()->rootObjectIds());
|
||||||
QList<int> r;
|
QList<int> r;
|
||||||
foreach (const ObjectReference& it,
|
while (rIds.hasNext()) {
|
||||||
m_inspectorAdapter->agent()->rootObjects()) {
|
rIds.next();
|
||||||
r += findRootObjectRecursive(it, doc);
|
if (rIds.value() == doc->componentName())
|
||||||
|
r += rIds.key();
|
||||||
}
|
}
|
||||||
if (!r.isEmpty())
|
if (!r.isEmpty())
|
||||||
m_debugIds[root] += r;
|
m_debugIds[root] += r;
|
||||||
@@ -561,7 +550,7 @@ bool QmlLiveTextPreview::changeSelectedElements(const QList<int> offsets,
|
|||||||
QList<int> list = objectReferencesForOffset(offset);
|
QList<int> list = objectReferencesForOffset(offset);
|
||||||
|
|
||||||
if (!containsReferenceUnderCursor
|
if (!containsReferenceUnderCursor
|
||||||
&& objectRefUnderCursor.debugId() != -1) {
|
&& objectRefUnderCursor.isValid()) {
|
||||||
foreach (int id, list) {
|
foreach (int id, list) {
|
||||||
if (id == objectRefUnderCursor.debugId()) {
|
if (id == objectRefUnderCursor.debugId()) {
|
||||||
containsReferenceUnderCursor = true;
|
containsReferenceUnderCursor = true;
|
||||||
@@ -577,7 +566,7 @@ bool QmlLiveTextPreview::changeSelectedElements(const QList<int> offsets,
|
|||||||
// fallback: use ref under cursor if nothing else is found
|
// fallback: use ref under cursor if nothing else is found
|
||||||
if (selectedReferences.isEmpty()
|
if (selectedReferences.isEmpty()
|
||||||
&& !containsReferenceUnderCursor
|
&& !containsReferenceUnderCursor
|
||||||
&& objectRefUnderCursor.debugId() != -1) {
|
&& objectRefUnderCursor.isValid()) {
|
||||||
selectedReferences << objectRefUnderCursor.debugId();
|
selectedReferences << objectRefUnderCursor.debugId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,7 +602,7 @@ void QmlLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
|||||||
m_debugIds = delta(m_previousDoc, doc, m_debugIds);
|
m_debugIds = delta(m_previousDoc, doc, m_debugIds);
|
||||||
|
|
||||||
if (delta.referenceRefreshRequired)
|
if (delta.referenceRefreshRequired)
|
||||||
m_inspectorAdapter->agent()->refreshObjectTree();
|
m_inspectorAdapter->agent()->queryEngineContext();
|
||||||
|
|
||||||
|
|
||||||
if (delta.unsyncronizableChanges != NoUnsyncronizableChanges) {
|
if (delta.unsyncronizableChanges != NoUnsyncronizableChanges) {
|
||||||
|
Reference in New Issue
Block a user