From 6f27359f15449442d829f69468b114d89144226f Mon Sep 17 00:00:00 2001 From: Henning Gruendl Date: Mon, 22 Nov 2021 16:42:48 +0100 Subject: [PATCH] QmlDesigner: Make live preview work with AVD Make the live preview work with Android Virtual Device. This allows to start the emulator with the currently active project via the live preview toolbar button. Task-number: QDS-5383 Change-Id: I3f44ea8fcb6f23d938d9775d78314b23c69768ec Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: Thomas Hartmann --- .../qmlpreviewplugin/qmlpreviewactions.cpp | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp index bcdd87b749a..09375ba69ff 100644 --- a/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp +++ b/src/plugins/qmldesigner/qmlpreviewplugin/qmlpreviewactions.cpp @@ -30,9 +30,13 @@ #include #include +#include #include #include #include +#include + +#include #include #include @@ -44,18 +48,37 @@ using namespace ProjectExplorer; const Utils::Icon previewIcon({ {":/qmlpreviewplugin/images/live_preview.png", Utils::Theme::IconsBaseColor}}); +const QByteArray livePreviewId = "LivePreview"; static void handleAction(const SelectionContext &context) { if (context.view()->isAttached()) { - if (context.toggled()) - ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE); - else + if (context.toggled()) { + bool skipDeploy = false; + if (const Target *startupTarget = SessionManager::startupTarget()) { + const Kit *kit = startupTarget->kit(); + if (kit + && (kit->supportedPlatforms().contains(Android::Constants::ANDROID_DEVICE_TYPE) + || DeviceTypeKitAspect::deviceTypeId(kit) + == Android::Constants::ANDROID_DEVICE_TYPE)) { + skipDeploy = true; + // In case of an android kit we don't want the live preview button to be toggled + // when the emulator is started as we don't have control over its run status. + DesignerActionManager &designerActionManager = QmlDesignerPlugin::instance() + ->designerActionManager(); + if (const ActionInterface *interface = designerActionManager.actionByMenuId( + livePreviewId)) + interface->action()->setChecked(false); + } + } + ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE, skipDeploy); + } else { QmlPreviewPlugin::stopAllRunControls(); + } } } -QmlPreviewAction::QmlPreviewAction() : ModelNodeAction("LivePreview", +QmlPreviewAction::QmlPreviewAction() : ModelNodeAction(livePreviewId, "Live Preview", previewIcon.icon(), QmlPreviewPlugin::tr("Show Live Preview"),