From 7eb5f7b3e0630d59bfa7e4e185df6f34c237e584 Mon Sep 17 00:00:00 2001 From: Simjees Abraham Date: Fri, 11 May 2012 14:37:33 +0200 Subject: Inspector:Modified Apply changes on Save for unsync. changes Changes done to reload the view if the user opts to do so after making unsynchronizable changes. Inspector informs the QmlEngine about the changes which caches it. The cache is used to load the files which were changed when reloading the view. Change-Id: I22d476cace294d6ecf4e428dac104a557c3f7dde Reviewed-by: Aaron Kennedy --- .../qmldbg_qtquick2/qquickviewinspector.cpp | 51 +++++++++++++++++++++- .../qmldbg_qtquick2/qquickviewinspector.h | 5 +++ .../qmltooling/shared/abstractviewinspector.cpp | 28 +++++++++++- .../qmltooling/shared/abstractviewinspector.h | 4 ++ 4 files changed, 85 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp index 243a821cc5..dbe511957c 100644 --- a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp @@ -44,6 +44,7 @@ #include "highlight.h" #include "inspecttool.h" +#include #include #include @@ -120,7 +121,8 @@ QQuickViewInspector::QQuickViewInspector(QQuickView *view, QObject *parent) : AbstractViewInspector(parent), m_view(view), m_overlay(new QQuickItem), - m_inspectTool(new InspectTool(this, view)) + m_inspectTool(new InspectTool(this, view)), + m_sendQmlReloadedMessage(false) { // Try to make sure the overlay is always on top m_overlay->setZ(FLT_MAX); @@ -130,6 +132,8 @@ QQuickViewInspector::QQuickViewInspector(QQuickView *view, QObject *parent) : view->installEventFilter(this); appendTool(m_inspectTool); + connect(view, SIGNAL(statusChanged(QQuickView::Status)), + this, SLOT(onViewStatus(QQuickView::Status))); } void QQuickViewInspector::changeCurrentObjects(const QList &objects) @@ -310,5 +314,50 @@ QString QQuickViewInspector::titleForItem(QQuickItem *item) const return constructedName; } +void QQuickViewInspector::reloadQmlFile(const QHash &changesHash) +{ + clearComponentCache(); + + // Reset the selection since we are reloading the main qml + setSelectedItems(QList()); + + QHash debugCache; + + foreach (const QString &str, changesHash.keys()) + debugCache.insert(QUrl(str), changesHash.value(str, QByteArray())); + + // Updating the cache in engine private such that the QML Data loader + // gets the changes from the cache. + QQmlEnginePrivate::get(declarativeEngine())->setDebugChangesCache(debugCache); + + m_sendQmlReloadedMessage = true; + // reloading the view such that the changes done for the files are + // reflected in view + view()->setSource(view()->source()); +} + +void QQuickViewInspector::onViewStatus(QQuickView::Status status) +{ + bool success = false; + switch (status) { + case QQuickView::Loading: + return; + case QQuickView::Ready: + if (view()->errors().count()) + break; + success = true; + break; + case QQuickView::Null: + case QQuickView::Error: + break; + default: + break; + } + if (m_sendQmlReloadedMessage) { + m_sendQmlReloadedMessage = false; + sendQmlFileReloaded(success); + } +} + } // namespace QtQuick2 } // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h index d6258c5ec1..d687d6ba0e 100644 --- a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h @@ -46,6 +46,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QQuickView; @@ -83,6 +84,8 @@ public: QString titleForItem(QQuickItem *item) const; void showSelectedItemName(QQuickItem *item, const QPointF &point); + void reloadQmlFile(const QHash &changesHash); + protected: bool eventFilter(QObject *obj, QEvent *event); @@ -90,6 +93,7 @@ protected: private slots: void removeFromSelectedItems(QObject *); + void onViewStatus(QQuickView::Status status); private: bool syncSelectedItems(const QList &items); @@ -101,6 +105,7 @@ private: QList > m_selectedItems; QHash m_highlightItems; + bool m_sendQmlReloadedMessage; }; } // namespace QtQuick2 diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.cpp b/src/plugins/qmltooling/shared/abstractviewinspector.cpp index 02a85e2e2e..174d70b20e 100644 --- a/src/plugins/qmltooling/shared/abstractviewinspector.cpp +++ b/src/plugins/qmltooling/shared/abstractviewinspector.cpp @@ -56,10 +56,12 @@ //INSPECTOR SERVICE PROTOCOL //
//
: [] -// : {"enable", "disable", "select", "setAnimationSpeed", +// : {"enable", "disable", "select", "reload", "setAnimationSpeed", // "showAppOnTop", "createObject", "destroyObject", "moveObject", // "clearCache"} // : select: +// reload: +// // setAnimationSpeed: // showAppOnTop: // createObject: @@ -73,6 +75,7 @@ const char EVENT[] = "event"; const char ENABLE[] = "enable"; const char DISABLE[] = "disable"; const char SELECT[] = "select"; +const char RELOAD[] = "reload"; const char SET_ANIMATION_SPEED[] = "setAnimationSpeed"; const char SHOW_APP_ON_TOP[] = "showAppOnTop"; const char CREATE_OBJECT[] = "createObject"; @@ -87,7 +90,8 @@ AbstractViewInspector::AbstractViewInspector(QObject *parent) : QObject(parent), m_enabled(false), m_debugService(QQmlInspectorService::instance()), - m_eventId(0) + m_eventId(0), + m_reloadEventId(-1) { } @@ -296,6 +300,13 @@ void AbstractViewInspector::handleMessage(const QByteArray &message) if (m_enabled) changeCurrentObjects(selectedObjects); + } else if (command == RELOAD) { + QHash changesHash; + ds >> changesHash; + m_reloadEventId = requestId; + reloadQmlFile(changesHash); + return; + } else if (command == SET_ANIMATION_SPEED) { qreal speed; ds >> speed; @@ -362,6 +373,19 @@ void AbstractViewInspector::sendCurrentObjects(const QList &objects) m_debugService->sendMessage(message); } +void AbstractViewInspector::sendQmlFileReloaded(bool success) +{ + if (m_reloadEventId == -1) + return; + + QByteArray response; + + QQmlDebugStream rs(&response, QIODevice::WriteOnly); + rs << QByteArray(RESPONSE) << m_reloadEventId << success; + + m_debugService->sendMessage(response); +} + QString AbstractViewInspector::idStringForObject(QObject *obj) const { QQmlContext *context = qmlContext(obj); diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.h b/src/plugins/qmltooling/shared/abstractviewinspector.h index d2dd9557da..8855935e46 100644 --- a/src/plugins/qmltooling/shared/abstractviewinspector.h +++ b/src/plugins/qmltooling/shared/abstractviewinspector.h @@ -83,6 +83,8 @@ public: void sendCurrentObjects(const QList &); + void sendQmlFileReloaded(bool success); + QString idStringForObject(QObject *obj) const; virtual void changeCurrentObjects(const QList &objects) = 0; @@ -90,6 +92,7 @@ public: virtual Qt::WindowFlags windowFlags() const = 0; virtual void setWindowFlags(Qt::WindowFlags flags) = 0; virtual QQmlEngine *declarativeEngine() const = 0; + virtual void reloadQmlFile(const QHash &changesHash) = 0; void appendTool(AbstractTool *tool); void removeTool(AbstractTool *tool); @@ -119,6 +122,7 @@ private: QQmlInspectorService *m_debugService; QList m_tools; int m_eventId; + int m_reloadEventId; }; } // namespace QmlJSDebugger -- cgit v1.2.3