summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTapani Mattila <tapani.mattila@qt.io>2022-02-21 21:10:51 +0200
committerTapani Mattila <tapani.mattila@qt.io>2022-02-22 17:08:11 +0000
commit7dd05f8937e484344a5525b2e62cdf5283c0a639 (patch)
tree555ca9bbb296a76e384770b19d2f51609f80b2fe
parent12f690b8a957e135376f8e60eb6a6127fad600cf (diff)
downloadqt-creator-7dd05f8937e484344a5525b2e62cdf5283c0a639.tar.gz
CMake project converter: Automatically open new project after creating it
Task-number: QDS-6249 Change-Id: I5ba1a396c7812a6aa736751fd0e7d7155d2de2d8 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>
-rw-r--r--src/plugins/qmldesigner/cmakeprojectconverter.cpp40
-rw-r--r--src/plugins/qmldesigner/cmakeprojectconverter.h11
2 files changed, 34 insertions, 17 deletions
diff --git a/src/plugins/qmldesigner/cmakeprojectconverter.cpp b/src/plugins/qmldesigner/cmakeprojectconverter.cpp
index 5244883577..87c8731708 100644
--- a/src/plugins/qmldesigner/cmakeprojectconverter.cpp
+++ b/src/plugins/qmldesigner/cmakeprojectconverter.cpp
@@ -29,7 +29,9 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
+#include <coreplugin/icore.h>
+#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
@@ -100,10 +102,16 @@ bool CmakeProjectConverter::convertProject(const QmlProjectManager::QmlProject *
bool retVal = prepareAndExecute();
- if (retVal)
- QMessageBox::information(nullptr, SUCCESS_TITLE, SUCCESS_TEXT);
- else
- QMessageBox::critical(nullptr, ERROR_TITLE, ERROR_TEXT.arg(m_errorText));
+ if (retVal) {
+ QMessageBox::information(Core::ICore::dialogParent(), SUCCESS_TITLE, SUCCESS_TEXT);
+ ProjectExplorer::ProjectExplorerPlugin::OpenProjectResult result
+ = ProjectExplorer::ProjectExplorerPlugin::openProject(newProjectFile());
+ if (!result)
+ ProjectExplorer::ProjectExplorerPlugin::showOpenProjectError(result);
+ }
+ else {
+ QMessageBox::critical(Core::ICore::dialogParent(), ERROR_TITLE, ERROR_TEXT.arg(m_errorText));
+ }
return retVal;
}
@@ -298,31 +306,36 @@ bool CmakeProjectConverter::createPreparedProject()
return true;
}
-const FilePath CmakeProjectConverter::contentDir()
+const FilePath CmakeProjectConverter::contentDir() const
{
return m_newProjectDir.pathAppended(DIRNAME_CONTENT);
}
-const FilePath CmakeProjectConverter::sourceDir()
+const FilePath CmakeProjectConverter::sourceDir() const
{
return m_newProjectDir.pathAppended(DIRNAME_CPP);
}
-const FilePath CmakeProjectConverter::importDir()
+const FilePath CmakeProjectConverter::importDir() const
{
return m_newProjectDir.pathAppended(DIRNAME_IMPORT);
}
-const FilePath CmakeProjectConverter::assetDir()
+const FilePath CmakeProjectConverter::assetDir() const
{
return contentDir().pathAppended(DIRNAME_ASSET);
}
-const FilePath CmakeProjectConverter::assetImportDir()
+const FilePath CmakeProjectConverter::assetImportDir() const
{
return m_newProjectDir.pathAppended(DIRNAME_ASSETIMPORT);
}
+const FilePath CmakeProjectConverter::newProjectFile() const
+{
+ return m_newProjectDir.pathAppended(m_project->projectFilePath().fileName());
+}
+
const FilePath CmakeProjectConverter::projectMainFile() const
{
auto *target = m_project->activeTarget();
@@ -370,17 +383,20 @@ bool CmakeProjectConverter::modifyProjectFile()
QString projectFileName = m_project->projectFilePath().fileName();
FilePath projectFilePath = m_newProjectDir.pathAppended(projectFileName);
QFile projectFile(projectFilePath.toString());
- projectFile.open(QIODevice::ReadWrite);
+ projectFile.open(QIODevice::ReadOnly);
if (!projectFile.isOpen())
return false;
-
QString projectFileContent = QString::fromUtf8(projectFile.readAll());
+ projectFile.close();
+
const QRegularExpression mainFilePattern("^\\s*mainFile:\\s*\".*\"", QRegularExpression::MultilineOption);
const QString mainFileString(" mainFile: \"content/App.qml\"");
projectFileContent.replace(mainFilePattern, mainFileString);
- projectFile.reset();
+ projectFile.open(QIODevice::WriteOnly|QIODevice::Truncate);
+ if (!projectFile.isOpen())
+ return false;
projectFile.write(projectFileContent.toUtf8());
projectFile.close();
diff --git a/src/plugins/qmldesigner/cmakeprojectconverter.h b/src/plugins/qmldesigner/cmakeprojectconverter.h
index 4b21d65ac8..3356311aa2 100644
--- a/src/plugins/qmldesigner/cmakeprojectconverter.h
+++ b/src/plugins/qmldesigner/cmakeprojectconverter.h
@@ -68,11 +68,12 @@ private:
const Utils::FilePath &original, const Utils::FilePath &target);
bool createPreparedProject();
- const Utils::FilePath contentDir();
- const Utils::FilePath sourceDir();
- const Utils::FilePath importDir();
- const Utils::FilePath assetDir();
- const Utils::FilePath assetImportDir();
+ const Utils::FilePath contentDir() const;
+ const Utils::FilePath sourceDir() const;
+ const Utils::FilePath importDir() const;
+ const Utils::FilePath assetDir() const;
+ const Utils::FilePath assetImportDir() const;
+ const Utils::FilePath newProjectFile() const;
const QString environmentVariable(const QString &key) const;
const Utils::FilePath projectMainFile() const;