Debugger: Response for DESTROY_OBJECT request sent correctly
authorSimjees Abraham <simjees.abraham@nokia.com>
Mon, 21 May 2012 12:22:08 +0000 (14:22 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 21 May 2012 13:55:11 +0000 (15:55 +0200)
The response for request DESTROY_OBJECT is sent after the
object has been destroyed. This enables the creator to
sync the objects tree displayed for debugging.

Change-Id: Icedaf92df4402f067fd5b8590811c770e4b9063e
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
src/plugins/qmltooling/shared/abstractviewinspector.cpp
src/plugins/qmltooling/shared/abstractviewinspector.h

index 174d70b..e5d5627 100644 (file)
@@ -91,7 +91,8 @@ AbstractViewInspector::AbstractViewInspector(QObject *parent) :
     m_enabled(false),
     m_debugService(QQmlInspectorService::instance()),
     m_eventId(0),
-    m_reloadEventId(-1)
+    m_reloadEventId(-1),
+    m_destroyEventId(-1)
 {
 }
 
@@ -269,6 +270,20 @@ bool AbstractViewInspector::touchEvent(QTouchEvent *event)
     return true;
 }
 
+void AbstractViewInspector::onQmlObjectDestroyed()
+{
+    if (m_destroyEventId == -1)
+        return;
+
+    QByteArray response;
+
+    QQmlDebugStream rs(&response, QIODevice::WriteOnly);
+    rs << QByteArray(RESPONSE) << m_destroyEventId << true;
+
+    m_debugService->sendMessage(response);
+    m_destroyEventId = -1;
+}
+
 void AbstractViewInspector::handleMessage(const QByteArray &message)
 {
     bool success = true;
@@ -329,8 +344,12 @@ void AbstractViewInspector::handleMessage(const QByteArray &message)
         } else if (command == DESTROY_OBJECT) {
             int debugId;
             ds >> debugId;
-            if (QObject *obj = QQmlDebugService::objectForId(debugId))
+            m_destroyEventId = requestId;
+            if (QObject *obj = QQmlDebugService::objectForId(debugId)) {
+                connect(obj, SIGNAL(destroyed()), SLOT(onQmlObjectDestroyed()));
                 obj->deleteLater();
+            }
+            return;
 
         } else if (command == MOVE_OBJECT) {
             int debugId, newParent;
index 8855935..3addacf 100644 (file)
@@ -110,6 +110,9 @@ protected:
     virtual bool wheelEvent(QWheelEvent *event);
     virtual bool touchEvent(QTouchEvent *event);
 
+private slots:
+    void onQmlObjectDestroyed();
+
 private:
     void setEnabled(bool value);
 
@@ -123,6 +126,7 @@ private:
     QList<AbstractTool *> m_tools;
     int m_eventId;
     int m_reloadEventId;
+    int m_destroyEventId;
 };
 
 } // namespace QmlJSDebugger