56 #include <QtCore/qdebug.h> |
56 #include <QtCore/qdebug.h> |
57 #include <QtCore/qmetaobject.h> |
57 #include <QtCore/qmetaobject.h> |
58 |
58 |
59 QT_BEGIN_NAMESPACE |
59 QT_BEGIN_NAMESPACE |
60 |
60 |
61 QList<QDeclarativeEngine *> QDeclarativeEngineDebugServer::m_engines; |
61 Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer); |
|
62 |
|
63 QDeclarativeEngineDebugServer *QDeclarativeEngineDebugServer::instance() |
|
64 { |
|
65 return qmlEngineDebugServer(); |
|
66 } |
|
67 |
62 QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent) |
68 QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent) |
63 : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), |
69 : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), |
64 m_watch(new QDeclarativeWatcher(this)) |
70 m_watch(new QDeclarativeWatcher(this)) |
65 { |
71 { |
66 QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)), |
72 QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)), |
180 |
186 |
181 return QLatin1String("<unknown value>"); |
187 return QLatin1String("<unknown value>"); |
182 } |
188 } |
183 |
189 |
184 void QDeclarativeEngineDebugServer::buildObjectDump(QDataStream &message, |
190 void QDeclarativeEngineDebugServer::buildObjectDump(QDataStream &message, |
185 QObject *object, bool recur) |
191 QObject *object, bool recur, bool dumpProperties) |
186 { |
192 { |
187 message << objectData(object); |
193 message << objectData(object); |
188 |
194 |
189 // Some children aren't added to an object until particular properties are read |
195 // Some children aren't added to an object until particular properties are read |
190 // - e.g. child state objects aren't added until the 'states' property is read - |
196 // - e.g. child state objects aren't added until the 'states' property is read - |
207 QObject *child = children.at(ii); |
213 QObject *child = children.at(ii); |
208 if (qobject_cast<QDeclarativeContext*>(child)) |
214 if (qobject_cast<QDeclarativeContext*>(child)) |
209 continue; |
215 continue; |
210 QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); |
216 QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); |
211 if (signal) { |
217 if (signal) { |
|
218 if (!dumpProperties) |
|
219 continue; |
212 QDeclarativeObjectProperty prop; |
220 QDeclarativeObjectProperty prop; |
213 prop.type = QDeclarativeObjectProperty::SignalProperty; |
221 prop.type = QDeclarativeObjectProperty::SignalProperty; |
214 prop.hasNotifySignal = false; |
222 prop.hasNotifySignal = false; |
215 QDeclarativeExpression *expr = signal->expression(); |
223 QDeclarativeExpression *expr = signal->expression(); |
216 if (expr) { |
224 if (expr) { |
227 } |
235 } |
228 } |
236 } |
229 fakeProperties << prop; |
237 fakeProperties << prop; |
230 } else { |
238 } else { |
231 if (recur) |
239 if (recur) |
232 buildObjectDump(message, child, recur); |
240 buildObjectDump(message, child, recur, dumpProperties); |
233 else |
241 else |
234 message << objectData(child); |
242 message << objectData(child); |
235 } |
243 } |
236 } |
244 } |
237 |
245 |
|
246 if (!dumpProperties) { |
|
247 message << 0; |
|
248 return; |
|
249 } |
|
250 |
238 message << (object->metaObject()->propertyCount() + fakeProperties.count()); |
251 message << (object->metaObject()->propertyCount() + fakeProperties.count()); |
239 |
252 |
240 for (int ii = 0; ii < object->metaObject()->propertyCount(); ++ii) |
253 for (int ii = 0; ii < object->metaObject()->propertyCount(); ++ii) |
241 message << propertyData(object, ii); |
254 message << propertyData(object, ii); |
242 |
255 |
255 |
268 |
256 int count = 0; |
269 int count = 0; |
257 |
270 |
258 QDeclarativeContextData *child = p->childContexts; |
271 QDeclarativeContextData *child = p->childContexts; |
259 while (child) { |
272 while (child) { |
260 if (!child->isInternal) |
273 ++count; |
261 ++count; |
|
262 child = child->nextChild; |
274 child = child->nextChild; |
263 } |
275 } |
264 |
276 |
265 message << count; |
277 message << count; |
266 |
278 |
267 child = p->childContexts; |
279 child = p->childContexts; |
268 while (child) { |
280 while (child) { |
269 if (!child->isInternal) |
281 buildObjectList(message, child->asQDeclarativeContext()); |
270 buildObjectList(message, child->asQDeclarativeContext()); |
|
271 child = child->nextChild; |
282 child = child->nextChild; |
272 } |
283 } |
273 |
284 |
274 // Clean deleted objects |
285 // Clean deleted objects |
275 QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(ctxt); |
286 QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(ctxt); |
370 sendMessage(reply); |
381 sendMessage(reply); |
371 } else if (type == "FETCH_OBJECT") { |
382 } else if (type == "FETCH_OBJECT") { |
372 int queryId; |
383 int queryId; |
373 int objectId; |
384 int objectId; |
374 bool recurse; |
385 bool recurse; |
375 |
386 bool dumpProperties = true; |
376 ds >> queryId >> objectId >> recurse; |
387 |
|
388 ds >> queryId >> objectId >> recurse >> dumpProperties; |
377 |
389 |
378 QObject *object = QDeclarativeDebugService::objectForId(objectId); |
390 QObject *object = QDeclarativeDebugService::objectForId(objectId); |
379 |
391 |
380 QByteArray reply; |
392 QByteArray reply; |
381 QDataStream rs(&reply, QIODevice::WriteOnly); |
393 QDataStream rs(&reply, QIODevice::WriteOnly); |
382 rs << QByteArray("FETCH_OBJECT_R") << queryId; |
394 rs << QByteArray("FETCH_OBJECT_R") << queryId; |
383 |
395 |
384 if (object) |
396 if (object) |
385 buildObjectDump(rs, object, recurse); |
397 buildObjectDump(rs, object, recurse, dumpProperties); |
386 |
398 |
387 sendMessage(reply); |
399 sendMessage(reply); |
388 } else if (type == "WATCH_OBJECT") { |
400 } else if (type == "WATCH_OBJECT") { |
389 int queryId; |
401 int queryId; |
390 int objectId; |
402 int objectId; |
483 QObject *object = objectForId(objectId); |
495 QObject *object = objectForId(objectId); |
484 QDeclarativeContext *context = qmlContext(object); |
496 QDeclarativeContext *context = qmlContext(object); |
485 |
497 |
486 if (object && context) { |
498 if (object && context) { |
487 |
499 |
|
500 QDeclarativeProperty property(object, propertyName, context); |
488 if (isLiteralValue) { |
501 if (isLiteralValue) { |
489 QDeclarativeProperty literalProperty(object, propertyName, context); |
502 property.write(expression); |
490 literalProperty.write(expression); |
503 } else if (hasValidSignal(object, propertyName)) { |
|
504 QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); |
|
505 QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); |
|
506 } else if (property.isProperty()) { |
|
507 QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); |
|
508 binding->setTarget(property); |
|
509 binding->setNotifyOnValueChanged(true); |
|
510 QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); |
|
511 if (oldBinding) |
|
512 oldBinding->destroy(); |
|
513 binding->update(); |
491 } else { |
514 } else { |
492 if (hasValidSignal(object, propertyName)) { |
515 qWarning() << "QDeclarativeEngineDebugServer::setBinding: unable to set property" << propertyName << "on object" << object; |
493 QDeclarativeProperty property(object, propertyName); |
|
494 QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); |
|
495 QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); |
|
496 } else { |
|
497 QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); |
|
498 QDeclarativeProperty property(object, propertyName, context); |
|
499 binding->setTarget(property); |
|
500 binding->setNotifyOnValueChanged(true); |
|
501 QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); |
|
502 if (oldBinding) |
|
503 oldBinding->destroy(); |
|
504 binding->update(); |
|
505 } |
|
506 } |
516 } |
507 } |
517 } |
508 } |
518 } |
509 |
519 |
510 void QDeclarativeEngineDebugServer::resetBinding(int objectId, const QString &propertyName) |
520 void QDeclarativeEngineDebugServer::resetBinding(int objectId, const QString &propertyName) |
592 Q_ASSERT(m_engines.contains(engine)); |
602 Q_ASSERT(m_engines.contains(engine)); |
593 |
603 |
594 m_engines.removeAll(engine); |
604 m_engines.removeAll(engine); |
595 } |
605 } |
596 |
606 |
|
607 void QDeclarativeEngineDebugServer::objectCreated(QDeclarativeEngine *engine, QObject *object) |
|
608 { |
|
609 Q_ASSERT(engine); |
|
610 Q_ASSERT(m_engines.contains(engine)); |
|
611 |
|
612 int engineId = QDeclarativeDebugService::idForObject(engine); |
|
613 int objectId = QDeclarativeDebugService::idForObject(object); |
|
614 |
|
615 QByteArray reply; |
|
616 QDataStream rs(&reply, QIODevice::WriteOnly); |
|
617 |
|
618 rs << QByteArray("OBJECT_CREATED") << engineId << objectId; |
|
619 sendMessage(reply); |
|
620 } |
|
621 |
597 QT_END_NAMESPACE |
622 QT_END_NAMESPACE |