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: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2021-11-22 16:42:48 +01:00
committed by Henning Gründl
parent a4791debf0
commit 6f27359f15

View File

@@ -30,9 +30,13 @@
#include <designersettings.h> #include <designersettings.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <android/androidconstants.h>
#include <QLabel> #include <QLabel>
#include <QComboBox> #include <QComboBox>
@@ -44,18 +48,37 @@ using namespace ProjectExplorer;
const Utils::Icon previewIcon({ const Utils::Icon previewIcon({
{":/qmlpreviewplugin/images/live_preview.png", Utils::Theme::IconsBaseColor}}); {":/qmlpreviewplugin/images/live_preview.png", Utils::Theme::IconsBaseColor}});
const QByteArray livePreviewId = "LivePreview";
static void handleAction(const SelectionContext &context) static void handleAction(const SelectionContext &context)
{ {
if (context.view()->isAttached()) { if (context.view()->isAttached()) {
if (context.toggled()) if (context.toggled()) {
ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE); bool skipDeploy = false;
else 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(); QmlPreviewPlugin::stopAllRunControls();
} }
} }
}
QmlPreviewAction::QmlPreviewAction() : ModelNodeAction("LivePreview", QmlPreviewAction::QmlPreviewAction() : ModelNodeAction(livePreviewId,
"Live Preview", "Live Preview",
previewIcon.icon(), previewIcon.icon(),
QmlPreviewPlugin::tr("Show Live Preview"), QmlPreviewPlugin::tr("Show Live Preview"),