diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2019-12-10 16:25:41 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2020-01-13 15:48:47 +0000 |
commit | fb171ebc5bc6e9c88764ce9dcacf08628a7523da (patch) | |
tree | afcad7db577b897d5335b9071ec6c7f3fc96d84f /src | |
parent | 266c808117c3af879dbc8385c41ac19a30149384 (diff) |
QmlDesigner: use current file to start preview
- Maybe we need a check if it is a qml file.
Task-number: QDS-1299
Change-Id: I2b54514f311fb78d3508e588783c0d04c7a7bc0b
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmlpreview/qmlpreviewruncontrol.cpp | 33 | ||||
-rw-r--r-- | src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp | 5 | ||||
-rw-r--r-- | src/plugins/qmlprojectmanager/qmlmainfileaspect.h | 2 | ||||
-rw-r--r-- | src/plugins/qmlprojectmanager/qmlproject.h | 2 |
4 files changed, 37 insertions, 5 deletions
diff --git a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp index 26e34563387..9f22796689e 100644 --- a/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp +++ b/src/plugins/qmlpreview/qmlpreviewruncontrol.cpp @@ -25,6 +25,9 @@ #include "qmlpreviewruncontrol.h" +#include <qmlprojectmanager/qmlproject.h> +#include <qmlprojectmanager/qmlmainfileaspect.h> + #include <projectexplorer/projectexplorer.h> #include <projectexplorer/session.h> #include <projectexplorer/target.h> @@ -36,6 +39,7 @@ #include <utils/port.h> #include <utils/qtcprocess.h> #include <utils/url.h> +#include <utils/fileutils.h> namespace QmlPreview { @@ -77,7 +81,7 @@ QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl, if (!runControl->isRunning()) return; - connect(runControl, &ProjectExplorer::RunControl::stopped, runControl, [runControl]() { + this->connect(runControl, &ProjectExplorer::RunControl::stopped, runControl, [runControl]() { ProjectExplorer::ProjectExplorerPlugin::runRunConfiguration( runControl->runConfiguration(), ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE, true); @@ -124,12 +128,33 @@ LocalQmlPreviewSupport::LocalQmlPreviewSupport(ProjectExplorer::RunControl *runC addStartDependency(preview); setStarter([this, runControl, serverUrl] { - ProjectExplorer::Runnable run = runControl->runnable(); + ProjectExplorer::Runnable runnable = runControl->runnable(); + QStringList qmlProjectRunConfigurationArguments = runnable.commandLine().splitArguments(); + + const auto currentTarget = runControl->target(); + const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem()); + + const auto aspect = runControl->aspect<QmlProjectManager::QmlMainFileAspect>(); + const QString mainScript = aspect->mainScript(); + const QString currentFile = aspect->currentFile(); + + const QString mainScriptFromProject = qmlBuildSystem->targetFile( + Utils::FilePath::fromString(mainScript)).toString(); + + const QString currentFileFromProject = qmlBuildSystem->targetFile( + Utils::FilePath::fromString(currentFile)).toString(); + + if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) { + qmlProjectRunConfigurationArguments.removeLast(); + auto commandLine = Utils::CommandLine(runnable.commandLine().executable(), qmlProjectRunConfigurationArguments); + commandLine.addArg(currentFile); + runnable.setCommandLine(commandLine); + } - Utils::QtcProcess::addArg(&run.commandLineArguments, + Utils::QtcProcess::addArg(&runnable.commandLineArguments, QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlPreviewServices, serverUrl.path())); - doStart(run, {}); + doStart(runnable, {}); }); } diff --git a/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp b/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp index 818f6e9da46..b1bc7994375 100644 --- a/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp +++ b/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp @@ -212,6 +212,11 @@ QString QmlMainFileAspect::mainScript() const return m_currentFileFilename; } +QString QmlMainFileAspect::currentFile() const +{ + return m_currentFileFilename; +} + void QmlMainFileAspect::changeCurrentFile(Core::IEditor *editor) { if (!editor) diff --git a/src/plugins/qmlprojectmanager/qmlmainfileaspect.h b/src/plugins/qmlprojectmanager/qmlmainfileaspect.h index 286d000d3d3..61a7b337b7f 100644 --- a/src/plugins/qmlprojectmanager/qmlmainfileaspect.h +++ b/src/plugins/qmlprojectmanager/qmlmainfileaspect.h @@ -46,6 +46,7 @@ class QmlBuildSystem; class QMLPROJECTMANAGER_EXPORT QmlMainFileAspect : public ProjectExplorer::ProjectConfigurationAspect { + Q_OBJECT public: explicit QmlMainFileAspect(ProjectExplorer::Target *target); ~QmlMainFileAspect() override; @@ -67,6 +68,7 @@ public: void setScriptSource(MainScriptSource source, const QString &settingsPath = QString()); QString mainScript() const; + QString currentFile() const; void changeCurrentFile(Core::IEditor *editor = nullptr); bool isQmlFilePresent(); QmlBuildSystem *qmlBuildSystem() const; diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index f12da342fe3..b1b4c6bd536 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -40,7 +40,7 @@ namespace QmlProjectManager { class QmlProject; class QmlProjectItem; -class QmlBuildSystem : public ProjectExplorer::BuildSystem +class QMLPROJECTMANAGER_EXPORT QmlBuildSystem : public ProjectExplorer::BuildSystem { Q_OBJECT |