From 9dd273027bfc3fc527b9f398309b9e057b7af290 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 11 Jul 2018 09:59:20 +0200 Subject: QML Preview: Add heuristic for auto-loading the root component This allows the client to skip the initial "Load" command if the first .qml file loaded is the source for the root component. Furthermore, it can just pass an empty URL to Load in order to have the service reload the last loaded URL. Change-Id: Iae5b9bdd20dbc8a772f46d97f91adf7092df1ef3 Reviewed-by: Simon Hausmann --- .../qmltooling/qmldbg_preview/qqmlpreviewservice.cpp | 15 +++++++++++++++ .../qmltooling/qmldbg_preview/qqmlpreviewservice.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp index 4e96fc62ef..70e895e78c 100644 --- a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp +++ b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp @@ -74,6 +74,17 @@ void QQmlPreviewServiceImpl::messageReceived(const QByteArray &data) QByteArray contents; packet >> path >> contents; emit file(path, contents); + + // Replace the whole scene with the first file successfully loaded over the debug + // connection. This is an OK approximation of the root component, and if the client wants + // something specific, it will send an explicit Load anyway. + if (m_currentUrl.isEmpty() && path.endsWith(".qml")) { + if (path.startsWith(':')) + m_currentUrl = QUrl("qrc" + path); + else + m_currentUrl = QUrl::fromLocalFile(path); + emit load(m_currentUrl); + } break; } case Directory: { @@ -86,6 +97,10 @@ void QQmlPreviewServiceImpl::messageReceived(const QByteArray &data) case Load: { QUrl url; packet >> url; + if (url.isEmpty()) + url = m_currentUrl; + else + m_currentUrl = url; emit load(url); break; } diff --git a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.h b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.h index 084d3a14b1..6c35ef52dd 100644 --- a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.h +++ b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.h @@ -90,6 +90,7 @@ private: QScopedPointer m_fileEngine; QScopedPointer m_loader; QQmlPreviewHandler m_handler; + QUrl m_currentUrl; }; QT_END_NAMESPACE -- cgit v1.2.3