Commit 7bef0764 authored by Olivier Goffart's avatar Olivier Goffart
Browse files

Qml Live Preview: Update the QmlJSLiveTextPreview When the document is reloaded.

When the document is reloaded by the server, we need to refresh
refresh what was the loaded document, and refresh the debugIds
parent f0912bfe
......@@ -119,7 +119,7 @@ void ClientProxy::refreshObjectTree()
m_objectTreeQuery = m_client->queryObjectRecursive(m_rootObject, this);
if (!m_objectTreeQuery->isWaiting()) {
objectTreeFetched();
objectTreeFetched(m_objectTreeQuery->state());
} else {
connect(m_objectTreeQuery,
SIGNAL(stateChanged(QDeclarativeDebugQuery::State)),
......@@ -143,12 +143,13 @@ void ClientProxy::onCurrentObjectsChanged(const QList<int> &debugIds)
// So the only choice that remains is to update the complete tree when we have an unknown debug id.
if (!m_objectTreeQuery)
m_objectTreeQuery = m_client->queryObjectRecursive(m_rootObject, this);
break;
}
}
if (m_objectTreeQuery) {
if (!m_objectTreeQuery->isWaiting()) {
objectTreeFetched();
objectTreeFetched(m_objectTreeQuery->state());
} else {
connect(m_objectTreeQuery,
SIGNAL(stateChanged(QDeclarativeDebugQuery::State)),
......@@ -222,6 +223,7 @@ void ClientProxy::connectionStateChanged()
SIGNAL(animationSpeedChanged(qreal)), SIGNAL(animationSpeedChanged(qreal)));
connect(m_designClient,
SIGNAL(designModeBehaviorChanged(bool)), SIGNAL(designModeBehaviorChanged(bool)));
connect(m_designClient, SIGNAL(reloaded()), this, SIGNAL(serverReloaded()));
}
(void) new DebuggerClient(m_conn);
......@@ -373,6 +375,11 @@ void ClientProxy::contextChanged()
void ClientProxy::objectTreeFetched(QDeclarativeDebugQuery::State state)
{
if (state == QDeclarativeDebugQuery::Error) {
delete m_objectTreeQuery;
m_objectTreeQuery = 0;
}
if (state != QDeclarativeDebugQuery::Completed) {
m_rootObject = QDeclarativeDebugObjectReference();
return;
......
......@@ -93,6 +93,7 @@ signals:
void zoomToolActivated();
void animationSpeedChanged(qreal slowdownFactor);
void designModeBehaviorChanged(bool inDesignMode);
void serverReloaded();
public slots:
void queryEngineContext(int id);
......
......@@ -96,6 +96,8 @@ void QmlJSDesignDebugClient::messageReceived(const QByteArray &message)
bool inDesignMode;
ds >> inDesignMode;
emit designModeBehaviorChanged(inDesignMode);
} else if (type == "RELOADED") {
emit reloaded();
}
}
......
......@@ -81,6 +81,7 @@ signals:
void zoomToolActivated();
void animationSpeedChanged(qreal slowdownFactor);
void designModeBehaviorChanged(bool inDesignMode);
void reloaded(); // the server has reloaded the document
protected:
virtual void messageReceived(const QByteArray &);
......
......@@ -139,6 +139,7 @@ Inspector::Inspector(QObject *parent)
connect(m_clientProxy, SIGNAL(aboutToReloadEngines()), SLOT(aboutToReloadEngines()));
connect(m_clientProxy, SIGNAL(enginesChanged()), SLOT(updateEngineList()));
connect(m_clientProxy, SIGNAL(aboutToDisconnect()), SLOT(disconnectWidgets()));
connect(m_clientProxy, SIGNAL(serverReloaded()), this, SLOT(serverReloaded()));
connect(Debugger::DebuggerPlugin::instance(),
SIGNAL(stateChanged(int)), this, SLOT(debuggerStateChanged(int)));
......@@ -224,21 +225,41 @@ void Inspector::initializeDocuments()
if (!modelManager())
return;
QmlJS::Snapshot snapshot = modelManager()->snapshot();
m_loadedSnapshot = modelManager()->snapshot();
Core::EditorManager *em = Core::EditorManager::instance();
connect(em, SIGNAL(editorAboutToClose(Core::IEditor*)), SLOT(removePreviewForEditor(Core::IEditor*)));
connect(em, SIGNAL(editorOpened(Core::IEditor*)), SLOT(createPreviewForEditor(Core::IEditor*)));
// initial update
foreach (QmlJS::Document::Ptr doc, snapshot) {
QmlJSLiveTextPreview *preview = new QmlJSLiveTextPreview(doc, this);
#if 0
foreach (Core::IEditor *editor, em->openedEditors()) {
createPreviewForEditor(editor);
}
#else
foreach (QmlJS::Document::Ptr doc, m_loadedSnapshot) {
QmlJSLiveTextPreview *preview = new QmlJSLiveTextPreview(doc, doc, this);
connect(preview,
SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)),
SLOT(changeSelectedItems(QList<QDeclarativeDebugObjectReference>)));
m_textPreviews.insert(doc->fileName(), preview);
}
#endif
}
void Inspector::serverReloaded()
{
QmlJS::Snapshot snapshot = modelManager()->snapshot();
m_loadedSnapshot = snapshot;
for (QHash<QString, QmlJSLiveTextPreview *>::const_iterator it = m_textPreviews.constBegin();
it != m_textPreviews.constEnd(); ++it) {
Document::Ptr doc = snapshot.document(it.key());
it.value()->resetInitialDoc(doc);
}
ClientProxy::instance()->queryEngineContext(0);
//ClientProxy::instance()->refreshObjectTree();
}
void Inspector::removePreviewForEditor(Core::IEditor *oldEditor)
{
if (QmlJSLiveTextPreview *preview = m_textPreviews.value(oldEditor->file()->fileName())) {
......@@ -253,12 +274,14 @@ void Inspector::createPreviewForEditor(Core::IEditor *newEditor)
QmlJS::Document::Ptr doc = modelManager()->snapshot().document(filename);
if (!doc || !doc->qmlProgram())
return;
QmlJS::Document::Ptr initdoc = m_loadedSnapshot.document(filename);
if (!initdoc)
initdoc = doc;
if (m_textPreviews.contains(filename)) {
m_textPreviews.value(filename)->associateEditor(newEditor);
} else {
QmlJSLiveTextPreview *preview = new QmlJSLiveTextPreview(doc, this);
QmlJSLiveTextPreview *preview = new QmlJSLiveTextPreview(doc, initdoc, this);
connect(preview,
SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)),
SLOT(changeSelectedItems(QList<QDeclarativeDebugObjectReference>)));
......
......@@ -99,6 +99,7 @@ signals:
public slots:
void setSimpleDockWidgetArrangement();
void reloadQmlViewer();
void serverReloaded();
private slots:
void gotoObjectReferenceDefinition(const QDeclarativeDebugObjectReference &obj);
......@@ -152,6 +153,7 @@ private:
// Qml/JS integration
QHash<QString, QmlJSLiveTextPreview *> m_textPreviews;
QmlJS::Snapshot m_loadedSnapshot; //the snapshot loaded by the viewer
};
} // Internal
......
......@@ -131,9 +131,10 @@ void QmlJSLiveTextPreview::unassociateEditor(Core::IEditor *oldEditor)
}
}
QmlJSLiveTextPreview::QmlJSLiveTextPreview(QmlJS::Document::Ptr doc, QObject *parent) :
QObject(parent), m_previousDoc(doc), m_initialDoc(doc)
QmlJSLiveTextPreview::QmlJSLiveTextPreview(const QmlJS::Document::Ptr &doc, const QmlJS::Document::Ptr &initDoc, QObject* parent) :
QObject(parent), m_previousDoc(doc), m_initialDoc(initDoc)
{
Q_ASSERT(doc->fileName() == initDoc->fileName());
ClientProxy *clientProxy = ClientProxy::instance();
m_filename = doc->fileName();
......@@ -151,6 +152,15 @@ QmlJSLiveTextPreview::QmlJSLiveTextPreview(QmlJS::Document::Ptr doc, QObject *pa
associateEditor(editor);
}
void QmlJSLiveTextPreview::resetInitialDoc(const QmlJS::Document::Ptr &doc)
{
m_initialDoc = doc;
m_previousDoc = doc;
m_createdObjects.clear();
m_debugIds.clear();
}
QList<QDeclarativeDebugObjectReference > QmlJSLiveTextPreview::objectReferencesForOffset(quint32 offset) const
{
QList<QDeclarativeDebugObjectReference > result;
......@@ -234,9 +244,11 @@ void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference
doc->qmlProgram()->accept(&visitor);
m_debugIds = visitor.result;
Delta delta;
delta.doNotSendChanges = true;
m_debugIds = delta(doc, m_previousDoc, m_debugIds);
if (doc != m_previousDoc) {
Delta delta;
delta.doNotSendChanges = true;
m_debugIds = delta(doc, m_previousDoc, m_debugIds);
}
}
const QmlJS::Document::Ptr &doc = m_previousDoc;
......@@ -264,9 +276,11 @@ void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference
doc->qmlProgram()->accept(&visitor);
Delta::DebugIdMap debugIds = visitor.result;
Delta delta;
delta.doNotSendChanges = true;
debugIds = delta(doc, m_previousDoc, debugIds);
if (doc != m_previousDoc) {
Delta delta;
delta.doNotSendChanges = true;
debugIds = delta(doc, m_previousDoc, debugIds);
}
for(Delta::DebugIdMap::const_iterator it2 = debugIds.constBegin();
it2 != debugIds.constEnd(); ++it2) {
m_debugIds[it2.key()] += it2.value();
......
......@@ -33,7 +33,7 @@ class QmlJSLiveTextPreview : public QObject
Q_OBJECT
public:
explicit QmlJSLiveTextPreview(QmlJS::Document::Ptr doc, QObject *parent = 0);
explicit QmlJSLiveTextPreview(const QmlJS::Document::Ptr &doc, const QmlJS::Document::Ptr &initDoc, QObject *parent = 0);
static QmlJS::ModelManagerInterface *modelManager();
//void updateDocuments();
......@@ -41,6 +41,7 @@ public:
void unassociateEditor(Core::IEditor *editor);
void setActiveObject(const QDeclarativeDebugObjectReference &object);
void mapObjectToQml(const QDeclarativeDebugObjectReference &object);
void resetInitialDoc(const QmlJS::Document::Ptr &doc);
signals:
void selectedItemsChanged(const QList<QDeclarativeDebugObjectReference> &objects);
......
......@@ -117,3 +117,14 @@ void QDeclarativeDesignDebugServer::setAnimationSpeed(qreal slowdownFactor)
sendMessage(message);
}
void QDeclarativeDesignDebugServer::reloaded()
{
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("RELOADED");
sendMessage(message);
}
......@@ -62,6 +62,7 @@ public:
void setCurrentObjects(QList<QObject*> items);
void setAnimationSpeed(qreal slowdownFactor);
void setCurrentTool(QmlViewer::Constants::DesignTool toolId);
void reloaded();
Q_SIGNALS:
void currentObjectsChanged(const QList<QObject*> &objects);
......
......@@ -202,8 +202,8 @@ void QDeclarativeDesignView::createQmlObject(const QString &qml, QObject *parent
QObject *newObject = component.create(parentContext);
if (newObject) {
newObject->setParent(parent);
QDeclarativeItem *parentItem = dynamic_cast<QDeclarativeItem*>(parent);
QDeclarativeItem *newItem = dynamic_cast<QDeclarativeItem*>(newObject);
QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent);
QDeclarativeItem *newItem = qobject_cast<QDeclarativeItem*>(newObject);
if (parentItem && newItem) {
newItem->setParentItem(parentItem);
}
......@@ -533,6 +533,7 @@ void QDeclarativeDesignView::onStatusChanged(QDeclarativeView::Status status)
m_subcomponentEditorTool->pushContext(rootObject());
emit executionStarted(1.0f);
}
qmlDesignDebugServer()->reloaded();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment