All created instances are stored under the root context.
Check for the creation context of the object when building
up the tree. Do the same when building up the states list.
Change-Id: I8716d9966a61b8f7cb3ad4b7ab5acd4c94b4cd03
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
//
#include <QtQml/qtqmlglobal.h>
+#include <QtCore/QList>
+#include <QtCore/QPointer>
QT_BEGIN_HEADER
public:
virtual ~QQmlDebugStatesDelegate() {}
- virtual void buildStatesList(QQmlContext *ctxt, bool cleanList) = 0;
+ virtual void buildStatesList(bool cleanList,
+ const QList<QPointer<QObject> > &instances) = 0;
virtual void updateBinding(QQmlContext *context,
const QQmlProperty &property,
const QVariant &expression, bool isLiteralValue,
}
-void QQmlEngineDebugService::buildObjectList(QDataStream &message, QQmlContext *ctxt)
+void QQmlEngineDebugService::buildObjectList(QDataStream &message,
+ QQmlContext *ctxt,
+ const QList<QPointer<QObject> > &instances)
{
QQmlContextData *p = QQmlContextData::get(ctxt);
child = p->childContexts;
while (child) {
- buildObjectList(message, child->asQQmlContext());
+ buildObjectList(message, child->asQQmlContext(), instances);
child = child->nextChild;
}
- // Clean deleted objects
- QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(ctxt);
- for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) {
- if (!ctxtPriv->instances.at(ii)) {
- ctxtPriv->instances.removeAt(ii);
- --ii;
- }
+ count = 0;
+ for (int ii = 0; ii < instances.count(); ++ii) {
+ QQmlData *data = QQmlData::get(instances.at(ii));
+ if (data->context == p)
+ count ++;
}
+ message << count;
- message << ctxtPriv->instances.count();
- for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) {
- message << objectData(ctxtPriv->instances.at(ii));
+ for (int ii = 0; ii < instances.count(); ++ii) {
+ QQmlData *data = QQmlData::get(instances.at(ii));
+ if (data->context == p)
+ message << objectData(instances.at(ii));
}
}
-void QQmlEngineDebugService::buildStatesList(QQmlContext *ctxt, bool cleanList)
+void QQmlEngineDebugService::buildStatesList(bool cleanList,
+ const QList<QPointer<QObject> > &instances)
{
if (m_statesDelegate)
- m_statesDelegate->buildStatesList(ctxt, cleanList);
+ m_statesDelegate->buildStatesList(cleanList, instances);
}
QQmlEngineDebugService::QQmlObjectData
rs << QByteArray("LIST_OBJECTS_R") << queryId;
if (engine) {
- buildObjectList(rs, engine->rootContext());
- buildStatesList(engine->rootContext(), true);
+ QQmlContext *rootContext = engine->rootContext();
+ // Clean deleted objects
+ QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(rootContext);
+ for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) {
+ if (!ctxtPriv->instances.at(ii)) {
+ ctxtPriv->instances.removeAt(ii);
+ --ii;
+ }
+ }
+ buildObjectList(rs, rootContext, ctxtPriv->instances);
+ buildStatesList(true, ctxtPriv->instances);
}
sendMessage(reply);
#include <QtCore/qurl.h>
#include <QtCore/qvariant.h>
+#include <QtCore/QPointer>
QT_BEGIN_NAMESPACE
private:
void prepareDeferredObjects(QObject *);
- void buildObjectList(QDataStream &, QQmlContext *);
+ void buildObjectList(QDataStream &, QQmlContext *,
+ const QList<QPointer<QObject> > &instances);
void buildObjectDump(QDataStream &, QObject *, bool, bool);
- void buildStatesList(QQmlContext *, bool);
+ void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances);
QQmlObjectData objectData(QObject *);
QQmlObjectProperty propertyData(QObject *, int);
QVariant valueContents(const QVariant &defaultValue) const;
public:
QQmlQtQuick2DebugStatesDelegate();
virtual ~QQmlQtQuick2DebugStatesDelegate();
- virtual void buildStatesList(QQmlContext *ctxt, bool cleanList);
+ virtual void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances);
virtual void updateBinding(QQmlContext *context,
const QQmlProperty &property,
const QVariant &expression, bool isLiteralValue,
{
}
-void QQmlQtQuick2DebugStatesDelegate::buildStatesList(QQmlContext *ctxt, bool cleanList)
+void QQmlQtQuick2DebugStatesDelegate::buildStatesList(bool cleanList,
+ const QList<QPointer<QObject> > &instances)
{
if (cleanList)
m_allStates.clear();
- QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(ctxt);
- for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) {
- buildStatesList(ctxtPriv->instances.at(ii));
- }
-
- QQmlContextData *child = QQmlContextData::get(ctxt)->childContexts;
- while (child) {
- buildStatesList(child->asQQmlContext());
- child = child->nextChild;
+ //only root context has all instances
+ for (int ii = 0; ii < instances.count(); ++ii) {
+ buildStatesList(instances.at(ii));
}
}
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
waitForQuery(q_context);
- if (q_context->rootContext().objects().count() == 0)
+ if (q_context->rootContext().contexts().count() == 0 ||
+ q_context->rootContext().contexts().last().objects().count() == 0)
return QQmlDebugObjectReference();
+
+ //Contexts are in a stack
+ int count = q_context->rootContext().contexts().count();
QQmlDebugObjectQuery *q_obj = recursive ?
- m_dbg->queryObjectRecursive(q_context->rootContext().objects()[context], this) :
- m_dbg->queryObject(q_context->rootContext().objects()[context], this);
+ m_dbg->queryObjectRecursive(q_context->rootContext().contexts()[count - context - 1].objects()[0], this) :
+ m_dbg->queryObject(q_context->rootContext().contexts()[count - context - 1].objects()[0], this);
waitForQuery(q_obj);
QQmlDebugObjectReference result = q_obj->object();
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
waitForQuery(q_context);
- QVERIFY(q_context->rootContext().objects().count() > 0);
- QQmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this);
+ QVERIFY(q_context->rootContext().contexts().count());
+ QVERIFY(q_context->rootContext().contexts().last().objects().count() > 0);
+ QQmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().contexts().last().objects()[0], this);
waitForQuery(q_obj);
QQmlDebugObjectReference obj = q_obj->object();
QCOMPARE(context.debugId(), QQmlDebugService::idForObject(actualContext));
QCOMPARE(context.name(), actualContext->objectName());
- QCOMPARE(context.objects().count(), 4); // 4 qml component objects created for context in main()
-
// root context query sends only root object data - it doesn't fill in
// the children or property info
- QCOMPARE(context.objects()[0].properties().count(), 0);
- QCOMPARE(context.objects()[0].children().count(), 0);
+ QCOMPARE(context.objects().count(), 0);
QCOMPARE(context.contexts().count(), 5);
QVERIFY(context.contexts()[0].debugId() >= 0);
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
waitForQuery(q_context);
- QQmlDebugObjectReference rootObject = q_context->rootContext().objects()[0];
+ QQmlDebugObjectReference rootObject = q_context->rootContext().contexts().last().objects()[0];
QQmlDebugObjectQuery *q_obj = 0;
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
waitForQuery(q_context);
- int objectId = q_context->rootContext().objects()[0].debugId();
+ int objectId = q_context->rootContext().contexts().last().objects()[0].debugId();
QQmlDebugExpressionQuery *q_expr;
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
waitForQuery(q_context);
- QVERIFY(q_context->rootContext().objects().count() > sourceIndex);
- QQmlDebugObjectReference rootObject = q_context->rootContext().objects()[sourceIndex];
+ QVERIFY(q_context->rootContext().contexts().count() >= sourceIndex);
+ int count = q_context->rootContext().contexts().count();
+ QQmlDebugObjectReference rootObject = q_context->rootContext().contexts()[count - sourceIndex - 1].objects()[0];
QQmlDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(rootObject, this);
waitForQuery(q_obj);