From 1e0a741a81cbe7800a15c76caabe6601d2edf39d Mon Sep 17 00:00:00 2001 From: Simjees Abraham Date: Wed, 23 May 2012 13:57:56 +0200 Subject: [PATCH] Debugger : Handling destruction of multiple elements. Changes made to handle the case where multiple elements are removed in the editor and saved when "Apply on Save" is active. The respsonse is sent with the correct Id. Change-Id: I76dc1487a0a5ebf859d2ef54cc64a4a5fc4008ca Reviewed-by: Aurindam Jana --- src/plugins/qmltooling/shared/abstractviewinspector.cpp | 17 +++++++++-------- src/plugins/qmltooling/shared/abstractviewinspector.h | 5 +++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.cpp b/src/plugins/qmltooling/shared/abstractviewinspector.cpp index e5d5627..c3eb24e 100644 --- a/src/plugins/qmltooling/shared/abstractviewinspector.cpp +++ b/src/plugins/qmltooling/shared/abstractviewinspector.cpp @@ -91,8 +91,7 @@ AbstractViewInspector::AbstractViewInspector(QObject *parent) : m_enabled(false), m_debugService(QQmlInspectorService::instance()), m_eventId(0), - m_reloadEventId(-1), - m_destroyEventId(-1) + m_reloadEventId(-1) { } @@ -270,18 +269,20 @@ bool AbstractViewInspector::touchEvent(QTouchEvent *event) return true; } -void AbstractViewInspector::onQmlObjectDestroyed() +void AbstractViewInspector::onQmlObjectDestroyed(QObject *object) { - if (m_destroyEventId == -1) + if (!m_hashObjectsTobeDestroyed.contains(object)) return; + int removeId = m_hashObjectsTobeDestroyed.take(object); + QQmlDebugService::removeInvalidObjectsFromHash(); + QByteArray response; QQmlDebugStream rs(&response, QIODevice::WriteOnly); - rs << QByteArray(RESPONSE) << m_destroyEventId << true; + rs << QByteArray(RESPONSE) << removeId << true; m_debugService->sendMessage(response); - m_destroyEventId = -1; } void AbstractViewInspector::handleMessage(const QByteArray &message) @@ -344,9 +345,9 @@ void AbstractViewInspector::handleMessage(const QByteArray &message) } else if (command == DESTROY_OBJECT) { int debugId; ds >> debugId; - m_destroyEventId = requestId; if (QObject *obj = QQmlDebugService::objectForId(debugId)) { - connect(obj, SIGNAL(destroyed()), SLOT(onQmlObjectDestroyed())); + m_hashObjectsTobeDestroyed.insert(obj, requestId); + connect(obj, SIGNAL(destroyed(QObject*)), SLOT(onQmlObjectDestroyed(QObject*))); obj->deleteLater(); } return; diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.h b/src/plugins/qmltooling/shared/abstractviewinspector.h index 3addacf..ad42ba7 100644 --- a/src/plugins/qmltooling/shared/abstractviewinspector.h +++ b/src/plugins/qmltooling/shared/abstractviewinspector.h @@ -111,7 +111,7 @@ protected: virtual bool touchEvent(QTouchEvent *event); private slots: - void onQmlObjectDestroyed(); + void onQmlObjectDestroyed(QObject *object); private: void setEnabled(bool value); @@ -126,7 +126,8 @@ private: QList m_tools; int m_eventId; int m_reloadEventId; - int m_destroyEventId; + // Hash< object to be destroyed, destroy eventId > + QHash m_hashObjectsTobeDestroyed; }; } // namespace QmlJSDebugger -- 2.7.4