diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-07-11 09:59:20 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-07-13 11:53:12 +0000 |
commit | 9dd273027bfc3fc527b9f398309b9e057b7af290 (patch) | |
tree | b4d35f50aea9e6064a4952ce8a74aa4d610f9225 /src/plugins/qmltooling/qmldbg_preview | |
parent | f0613e2467416f32e61a7640e9f0011645f4b068 (diff) |
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_preview')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp | 15 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.h | 1 |
2 files changed, 16 insertions, 0 deletions
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<QQmlPreviewFileEngineHandler> m_fileEngine; QScopedPointer<QQmlPreviewFileLoader> m_loader; QQmlPreviewHandler m_handler; + QUrl m_currentUrl; }; QT_END_NAMESPACE |