QmlProject: Allow opening individual .ui.qml files in "lite" QDS

QDS nowadays provides an option "-qml-lite-designer" that starts it in a
"lite" mode.

When opening QDS from Qt Creator, use the "normal" QDS when a
.qmlproject file is found. Otherwise start it with "-qml-lite-designer".
Switches to Process::startDetached with "-client" and "-qml-lite-
designer" on macOS too, since "open" wouldn't work for instance sharing
depending on the "-qml-lite-designer" option that we can do with the "-
client" option.

Task-number: QTCREATORBUG-31005
Change-Id: Ia9e00e0ed5ecad8c3c383ee46a6fd2594ee7b2e7
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Eike Ziller
2025-03-17 11:52:41 +01:00
parent 1786c89507
commit 5ad0d1c4b7
3 changed files with 20 additions and 23 deletions

View File

@@ -87,7 +87,7 @@ void QdsLandingPage::openQds(bool rememberSelection)
auto editor = Core::EditorManager::currentEditor(); auto editor = Core::EditorManager::currentEditor();
if (editor) if (editor)
openInQDSWithProject(editor->document()->filePath()); openInQds(editor->document()->filePath());
} }
void QdsLandingPage::installQds() void QdsLandingPage::installQds()

View File

@@ -101,17 +101,19 @@ static void clearAlwaysOpenWithMode()
ICore::settings()->remove(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE); ICore::settings()->remove(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE);
} }
void openQDS(const FilePath &fileName) namespace {
enum class QdsMode { Lite, Full };
}
static void openQds(const FilePath &fileName, QdsMode mode)
{ {
const FilePath qdsPath = qdsInstallationEntry(); const FilePath qdsPath = qdsInstallationEntry();
bool qdsStarted = false; bool qdsStarted = false;
qputenv(Constants::enviromentLaunchedQDS, "true"); qputenv(Constants::enviromentLaunchedQDS, "true");
//-a and -client arguments help to append project to open design studio application const QStringList modeArgument = mode == QdsMode::Lite ? QStringList("-qml-lite-designer")
if (HostOsInfo::isMacHost()) : QStringList();
qdsStarted = Process::startDetached( qdsStarted = Process::startDetached(
{"/usr/bin/open", {"-a", qdsPath.path(), fileName.toUrlishString()}}); {qdsPath, modeArgument + QStringList({"-client", fileName.toUrlishString()})});
else
qdsStarted = Process::startDetached({qdsPath, {"-client", fileName.toUrlishString()}});
if (!qdsStarted) { if (!qdsStarted) {
QMessageBox::warning(ICore::dialogParent(), QMessageBox::warning(ICore::dialogParent(),
@@ -174,37 +176,33 @@ static bool findAndOpenProject(const FilePath &filePath)
{ {
if (Project *project = ProjectManager::projectForFile(filePath)) { if (Project *project = ProjectManager::projectForFile(filePath)) {
if (project->projectFilePath().suffix() == "qmlproject") { if (project->projectFilePath().suffix() == "qmlproject") {
openQDS(project->projectFilePath()); openQds(project->projectFilePath(), QdsMode::Full);
return true; return true;
} }
FilePath projectFolder = project->rootProjectDirectory(); FilePath projectFolder = project->rootProjectDirectory();
FilePath qmlProjectFile = findQmlProject(projectFolder); FilePath qmlProjectFile = findQmlProject(projectFolder);
if (qmlProjectFile.exists()) { if (qmlProjectFile.exists()) {
openQDS(qmlProjectFile); openQds(qmlProjectFile, QdsMode::Full);
return true; return true;
} }
} }
FilePath qmlProjectFile = findQmlProjectUpwards(filePath); FilePath qmlProjectFile = findQmlProjectUpwards(filePath);
if (qmlProjectFile.exists()) { if (qmlProjectFile.exists()) {
openQDS(qmlProjectFile); openQds(qmlProjectFile, QdsMode::Full);
return true; return true;
} }
return false; return false;
} }
void openInQDSWithProject(const FilePath &filePath) void openInQds(const FilePath &filePath)
{ {
if (findAndOpenProject(filePath)) { if (findAndOpenProject(filePath)) {
openQDS(filePath); openQds(filePath, QdsMode::Full);
//The first one might be ignored when QDS is starting up //The first one might be ignored when QDS is starting up
QTimer::singleShot(4000, [filePath] { openQDS(filePath); }); QTimer::singleShot(4000, [filePath] { openQds(filePath, QdsMode::Full); });
} else { } else {
AsynchronousMessageBox::warning( openQds(filePath, QdsMode::Lite);
Tr::tr("Qt Design Studio"),
Tr::tr("No project file (*.qmlproject) found for Qt Design "
"Studio.\nQt Design Studio requires a .qmlproject "
"based project to open the .ui.qml file."));
} }
} }
@@ -228,7 +226,7 @@ public:
setDisplayName(Tr::tr("Qt Design Studio")); setDisplayName(Tr::tr("Qt Design Studio"));
setMimeTypes({Utils::Constants::QMLUI_MIMETYPE}); setMimeTypes({Utils::Constants::QMLUI_MIMETYPE});
setEditorStarter([](const FilePath &filePath, [[maybe_unused]] QString *errorMessage) { setEditorStarter([](const FilePath &filePath, [[maybe_unused]] QString *errorMessage) {
openInQDSWithProject(filePath); openInQds(filePath);
return true; return true;
}); });
} }
@@ -480,7 +478,7 @@ void QmlProjectPlugin::openQds(bool permanent)
hideQmlLandingPage(); hideQmlLandingPage();
if (IEditor *editor = EditorManager::currentEditor()) if (IEditor *editor = EditorManager::currentEditor())
openInQDSWithProject(editor->document()->filePath()); openInQds(editor->document()->filePath());
} }
void QmlProjectPlugin::updateQmlLandingPageProjectInfo(const FilePath &projectFile) void QmlProjectPlugin::updateQmlLandingPageProjectInfo(const FilePath &projectFile)

View File

@@ -9,7 +9,6 @@ namespace Core { class IEditor; }
namespace QmlProjectManager::Internal { namespace QmlProjectManager::Internal {
void openQDS(const Utils::FilePath &fileName);
Utils::FilePath qdsInstallationEntry(); Utils::FilePath qdsInstallationEntry();
bool qdsInstallationExists(); bool qdsInstallationExists();
bool checkIfEditorIsuiQml(Core::IEditor *editor); bool checkIfEditorIsuiQml(Core::IEditor *editor);
@@ -17,7 +16,7 @@ Utils::FilePath projectFilePath();
Utils::FilePaths rootCmakeFiles(); Utils::FilePaths rootCmakeFiles();
QString qtVersion(const Utils::FilePath &projectFilePath); QString qtVersion(const Utils::FilePath &projectFilePath);
QString qdsVersion(const Utils::FilePath &projectFilePath); QString qdsVersion(const Utils::FilePath &projectFilePath);
void openInQDSWithProject(const Utils::FilePath &filePath); void openInQds(const Utils::FilePath &filePath);
const QString readFileContents(const Utils::FilePath &filePath); const QString readFileContents(const Utils::FilePath &filePath);
} // QmlProject::Internal } // QmlProject::Internal