aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorSimjees Abraham <simjees.abraham@nokia.com>2012-05-11 14:37:33 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-14 13:58:03 +0200
commit7eb5f7b3e0630d59bfa7e4e185df6f34c237e584 (patch)
treef4a769907beec334e628266032ce8b7436016b00 /src/plugins
parentfd5c099eea26a8101e2cc0dc3237d1250158b895 (diff)
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 <aaron.kennedy@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp51
-rw-r--r--src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h5
-rw-r--r--src/plugins/qmltooling/shared/abstractviewinspector.cpp28
-rw-r--r--src/plugins/qmltooling/shared/abstractviewinspector.h4
4 files changed, 85 insertions, 3 deletions
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 <QtQml/private/qqmlengine_p.h>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/QQuickView>
@@ -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<QObject*> &objects)
@@ -310,5 +314,50 @@ QString QQuickViewInspector::titleForItem(QQuickItem *item) const
return constructedName;
}
+void QQuickViewInspector::reloadQmlFile(const QHash<QString, QByteArray> &changesHash)
+{
+ clearComponentCache();
+
+ // Reset the selection since we are reloading the main qml
+ setSelectedItems(QList<QQuickItem *>());
+
+ QHash<QUrl, QByteArray> 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 <QtCore/QPointer>
#include <QtCore/QHash>
+#include <QtQuick/QQuickView>
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<QString, QByteArray> &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<QQuickItem*> &items);
@@ -101,6 +105,7 @@ private:
QList<QPointer<QQuickItem> > m_selectedItems;
QHash<QQuickItem*, SelectionHighlight*> 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
// <HEADER><COMMAND><DATA>
// <HEADER> : <type{request, response, event}><requestId/eventId>[<response_success_bool>]
-// <COMMAND> : {"enable", "disable", "select", "setAnimationSpeed",
+// <COMMAND> : {"enable", "disable", "select", "reload", "setAnimationSpeed",
// "showAppOnTop", "createObject", "destroyObject", "moveObject",
// "clearCache"}
// <DATA> : select: <debugIds_int_list>
+// reload: <list of relative paths w.r.t project of changed files>
+// <list of changed file contents>
// setAnimationSpeed: <speed_real>
// showAppOnTop: <set_bool>
// createObject: <qml_string><parentId_int><imports_string_list><filename_string>
@@ -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<QString, QByteArray> 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<QObject*> &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<QObject*> &);
+ void sendQmlFileReloaded(bool success);
+
QString idStringForObject(QObject *obj) const;
virtual void changeCurrentObjects(const QList<QObject*> &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<QString, QByteArray> &changesHash) = 0;
void appendTool(AbstractTool *tool);
void removeTool(AbstractTool *tool);
@@ -119,6 +122,7 @@ private:
QQmlInspectorService *m_debugService;
QList<AbstractTool *> m_tools;
int m_eventId;
+ int m_reloadEventId;
};
} // namespace QmlJSDebugger