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