diff --git a/src/libs/utils/projectintropage.cpp b/src/libs/utils/projectintropage.cpp index e5890ac2edf..07470ab6d2b 100644 --- a/src/libs/utils/projectintropage.cpp +++ b/src/libs/utils/projectintropage.cpp @@ -114,14 +114,14 @@ QString ProjectIntroPage::projectName() const return d->m_ui.nameLineEdit->text(); } -QString ProjectIntroPage::path() const +FilePath ProjectIntroPage::filePath() const { - return d->m_ui.pathChooser->filePath().toString(); + return d->m_ui.pathChooser->filePath(); } -void ProjectIntroPage::setPath(const QString &path) +void ProjectIntroPage::setFilePath(const FilePath &path) { - d->m_ui.pathChooser->setPath(path); + d->m_ui.pathChooser->setFilePath(path); } void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression ®Ex) @@ -178,14 +178,15 @@ bool ProjectIntroPage::validate() } // Check existence of the directory - const QFileInfo projectDirFile(path() + QLatin1Char('/') - + QDir::fromNativeSeparators(d->m_ui.nameLineEdit->text())); - if (!projectDirFile.exists()) { // All happy + const FilePath projectDir = + filePath().pathAppended(QDir::fromNativeSeparators(d->m_ui.nameLineEdit->text())); + + if (!projectDir.exists()) { // All happy hideStatusLabel(); return true; } - if (projectDirFile.isDir()) { + if (projectDir.isDir()) { displayStatusMessage(InfoLabel::Warning, tr("The project already exists.")); return true; } diff --git a/src/libs/utils/projectintropage.h b/src/libs/utils/projectintropage.h index 37ea875091c..63e2f656713 100644 --- a/src/libs/utils/projectintropage.h +++ b/src/libs/utils/projectintropage.h @@ -26,8 +26,10 @@ #pragma once #include "utils_global.h" -#include "wizardpage.h" + +#include "filepath.h" #include "infolabel.h" +#include "wizardpage.h" namespace Utils { @@ -37,7 +39,7 @@ class QTCREATOR_UTILS_EXPORT ProjectIntroPage : public WizardPage { Q_OBJECT Q_PROPERTY(QString description READ description WRITE setDescription DESIGNABLE true) - Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true) + Q_PROPERTY(FilePath filePath READ filePath WRITE setFilePath DESIGNABLE true) Q_PROPERTY(QString projectName READ projectName WRITE setProjectName DESIGNABLE true) Q_PROPERTY(bool useAsDefaultPath READ useAsDefaultPath WRITE setUseAsDefaultPath DESIGNABLE true) Q_PROPERTY(bool forceSubProject READ forceSubProject WRITE setForceSubProject DESIGNABLE true) @@ -47,7 +49,7 @@ public: ~ProjectIntroPage() override; QString projectName() const; - QString path() const; + FilePath filePath() const; QString description() const; bool useAsDefaultPath() const; @@ -68,7 +70,7 @@ signals: void activated(); public slots: - void setPath(const QString &path); + void setFilePath(const FilePath &path); void setProjectName(const QString &name); void setDescription(const QString &description); void setUseAsDefaultPath(bool u); diff --git a/src/plugins/projectexplorer/baseprojectwizarddialog.cpp b/src/plugins/projectexplorer/baseprojectwizarddialog.cpp index ef93d5b6f78..b173688623f 100644 --- a/src/plugins/projectexplorer/baseprojectwizarddialog.cpp +++ b/src/plugins/projectexplorer/baseprojectwizarddialog.cpp @@ -41,6 +41,8 @@ as default projects' folder should the user wish to do that. */ +using namespace Utils; + namespace ProjectExplorer { struct BaseProjectWizardDialogPrivate { @@ -66,20 +68,20 @@ BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFacto Core::BaseFileWizard(factory, parameters.extraValues(), parent), d(std::make_unique(new Utils::ProjectIntroPage)) { - setPath(parameters.defaultPath()); + setFilePath(FilePath::fromString(parameters.defaultPath())); setSelectedPlatform(parameters.selectedPlatform()); setRequiredFeatures(parameters.requiredFeatures()); init(); } BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFactory *factory, - Utils::ProjectIntroPage *introPage, int introId, + ProjectIntroPage *introPage, int introId, QWidget *parent, const Core::WizardDialogParameters ¶meters) : Core::BaseFileWizard(factory, parameters.extraValues(), parent), d(std::make_unique(introPage, introId)) { - setPath(parameters.defaultPath()); + setFilePath(FilePath::fromString(parameters.defaultPath())); setSelectedPlatform(parameters.selectedPlatform()); setRequiredFeatures(parameters.requiredFeatures()); init(); @@ -103,9 +105,9 @@ QString BaseProjectWizardDialog::projectName() const return d->introPage->projectName(); } -QString BaseProjectWizardDialog::path() const +FilePath BaseProjectWizardDialog::filePath() const { - return d->introPage->path(); + return d->introPage->filePath(); } void BaseProjectWizardDialog::setIntroDescription(const QString &des) @@ -113,9 +115,9 @@ void BaseProjectWizardDialog::setIntroDescription(const QString &des) d->introPage->setDescription(des); } -void BaseProjectWizardDialog::setPath(const QString &path) +void BaseProjectWizardDialog::setFilePath(const FilePath &path) { - d->introPage->setPath(path); + d->introPage->setFilePath(path); } void BaseProjectWizardDialog::setProjectName(const QString &name) @@ -142,7 +144,7 @@ void BaseProjectWizardDialog::slotAccepted() { if (d->introPage->useAsDefaultPath()) { // Store the path as default path for new projects if desired. - Core::DocumentManager::setProjectsDirectory(Utils::FilePath::fromString(path())); + Core::DocumentManager::setProjectsDirectory(filePath()); Core::DocumentManager::setUseProjectsDirectory(true); } } @@ -150,7 +152,7 @@ void BaseProjectWizardDialog::slotAccepted() bool BaseProjectWizardDialog::validateCurrentPage() { if (currentId() == d->introPageId) - emit projectParametersChanged(d->introPage->projectName(), d->introPage->path()); + emit projectParametersChanged(d->introPage->projectName(), d->introPage->filePath().toString()); return Core::BaseFileWizard::validateCurrentPage(); } diff --git a/src/plugins/projectexplorer/baseprojectwizarddialog.h b/src/plugins/projectexplorer/baseprojectwizarddialog.h index 7b2fd3c546f..19306600114 100644 --- a/src/plugins/projectexplorer/baseprojectwizarddialog.h +++ b/src/plugins/projectexplorer/baseprojectwizarddialog.h @@ -32,7 +32,10 @@ #include -namespace Utils { class ProjectIntroPage; } +namespace Utils { +class FilePath; +class ProjectIntroPage; +} // Utils namespace ProjectExplorer { @@ -55,14 +58,14 @@ public: ~BaseProjectWizardDialog() override; QString projectName() const; - QString path() const; + Utils::FilePath filePath() const; // Generate a new project name (untitled) in path. static QString uniqueProjectName(const QString &path); void addExtensionPages(const QList &wizardPageList); void setIntroDescription(const QString &d); - void setPath(const QString &path); + void setFilePath(const Utils::FilePath &path); void setProjectName(const QString &name); void setProjectList(const QStringList &projectList); void setProjectDirectories(const QStringList &directories); diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index f062a74b765..8f85f26d600 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -240,7 +240,7 @@ static inline QString scriptWorkingDirectory(const QSharedPointer &p) { if (p->filesGeneratorScriptWorkingDirectory.isEmpty()) - return ctx->targetPath; + return ctx->targetPath.toString(); QString path = p->filesGeneratorScriptWorkingDirectory; CustomWizardContext::replaceFields(ctx->replacements, &path); return path; @@ -253,7 +253,7 @@ GeneratedFiles CustomWizard::generateFiles(const QWizard *dialog, QString *error QTC_ASSERT(cwp, return {}); CustomWizardContextPtr ctx = context(); - ctx->path = ctx->targetPath = cwp->path(); + ctx->path = ctx->targetPath = cwp->filePath(); ctx->replacements = replacementMap(dialog); if (CustomWizardPrivate::verbose) { QString logText; @@ -330,7 +330,8 @@ GeneratedFiles CustomWizard::generateWizardFiles(QString *errorMessage) const } // Add the template files specified by the elements. for (const CustomWizardFile &file : qAsConst(d->m_parameters->files)) - if (!createFile(file, d->m_parameters->directory, ctx->targetPath, context()->replacements, &rc, errorMessage)) + if (!createFile(file, d->m_parameters->directory, ctx->targetPath.toString(), context()->replacements, + &rc, errorMessage)) return {}; return rc; @@ -525,7 +526,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w, } for (QWizardPage *ep : extensionPages) w->addPage(ep); - w->setPath(defaultPath); + w->setFilePath(FilePath::fromString(defaultPath)); w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath)); connect(w, &BaseProjectWizardDialog::projectParametersChanged, @@ -541,8 +542,8 @@ GeneratedFiles CustomProjectWizard::generateFiles(const QWizard *w, QString *err QTC_ASSERT(dialog, return {}); // Add project name as macro. Path is here under project directory CustomWizardContextPtr ctx = context(); - ctx->path = dialog->path(); - ctx->targetPath = ctx->path + QLatin1Char('/') + dialog->projectName(); + ctx->path = dialog->filePath(); + ctx->targetPath = ctx->path.pathAppended(dialog->projectName()); FieldReplacementMap fieldReplacementMap = replacementMap(dialog); fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName()); ctx->replacements = fieldReplacementMap; diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp index 60838462fcf..0e256bd9fc3 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp @@ -404,8 +404,8 @@ QMap CustomWizardFieldPage::replacementMap(const QWizard *w, fieldReplacementMap.insert(field.name, value); } // Insert paths for generator scripts. - fieldReplacementMap.insert(QLatin1String("Path"), QDir::toNativeSeparators(ctx->path)); - fieldReplacementMap.insert(QLatin1String("TargetPath"), QDir::toNativeSeparators(ctx->targetPath)); + fieldReplacementMap.insert(QLatin1String("Path"), ctx->path.toUserOutput()); + fieldReplacementMap.insert(QLatin1String("TargetPath"), ctx->targetPath.toUserOutput()); return fieldReplacementMap; } @@ -432,9 +432,9 @@ CustomWizardPage::CustomWizardPage(const QSharedPointer &ct connect(m_pathChooser, &PathChooser::validChanged, this, &QWizardPage::completeChanged); } -QString CustomWizardPage::path() const +FilePath CustomWizardPage::filePath() const { - return m_pathChooser->filePath().toString(); + return m_pathChooser->filePath(); } void CustomWizardPage::setPath(const QString &path) diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.h b/src/plugins/projectexplorer/customwizard/customwizardpage.h index 5ba82d6d92a..47d60f47d32 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.h +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.h @@ -25,6 +25,8 @@ #pragma once +#include + #include #include #include @@ -115,14 +117,16 @@ private: }; // Documentation inside. -class CustomWizardPage : public CustomWizardFieldPage { +class CustomWizardPage : public CustomWizardFieldPage +{ Q_OBJECT + public: explicit CustomWizardPage(const QSharedPointer &ctx, const QSharedPointer ¶meters, QWidget *parent = nullptr); - QString path() const; + Utils::FilePath filePath() const; void setPath(const QString &path); bool isComplete() const override; diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.h b/src/plugins/projectexplorer/customwizard/customwizardparameters.h index 884834a818c..95c41648326 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.h +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.h @@ -27,6 +27,8 @@ #include +#include + #include #include #include @@ -151,10 +153,10 @@ public: FieldReplacementMap baseReplacements; FieldReplacementMap replacements; - QString path; + Utils::FilePath path; // Where files should be created, that is, 'path' for simple wizards // or "path + project" for project wizards. - QString targetPath; + Utils::FilePath targetPath; }; extern const char customWizardFileOpenEditorAttributeC[]; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp index fcddd7ffd80..e864d3030f5 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp @@ -34,35 +34,34 @@ #include #include +using namespace Utils; + namespace ProjectExplorer { -JsonProjectPage::JsonProjectPage(QWidget *parent) : Utils::ProjectIntroPage(parent) +JsonProjectPage::JsonProjectPage(QWidget *parent) : ProjectIntroPage(parent) { } void JsonProjectPage::initializePage() { auto wiz = qobject_cast(wizard()); QTC_ASSERT(wiz, return); - setPath(wiz->stringValue(QLatin1String("InitialPath"))); + setFilePath(FilePath::fromString(wiz->stringValue(QLatin1String("InitialPath")))); - setProjectName(uniqueProjectName(path())); + setProjectName(uniqueProjectName(filePath().toString())); } bool JsonProjectPage::validatePage() { if (isComplete() && useAsDefaultPath()) { // Store the path as default path for new projects if desired. - Core::DocumentManager::setProjectsDirectory(Utils::FilePath::fromString(path())); + Core::DocumentManager::setProjectsDirectory(filePath()); Core::DocumentManager::setUseProjectsDirectory(true); } - QString target = path(); - if (!target.endsWith(QLatin1Char('/'))) - target += QLatin1Char('/'); - target += projectName(); + const FilePath target = filePath().pathAppended(projectName()); - wizard()->setProperty("ProjectDirectory", target); - wizard()->setProperty("TargetPath", target); + wizard()->setProperty("ProjectDirectory", target.toString()); + wizard()->setProperty("TargetPath", target.toString()); return Utils::ProjectIntroPage::validatePage(); } diff --git a/src/plugins/qmakeprojectmanager/customwidgetwizard/customwidgetwizard.cpp b/src/plugins/qmakeprojectmanager/customwidgetwizard/customwidgetwizard.cpp index 30007d802a2..f1cc3b9151e 100644 --- a/src/plugins/qmakeprojectmanager/customwidgetwizard/customwidgetwizard.cpp +++ b/src/plugins/qmakeprojectmanager/customwidgetwizard/customwidgetwizard.cpp @@ -33,6 +33,8 @@ #include +#include + #include namespace QmakeProjectManager { @@ -66,7 +68,7 @@ Core::GeneratedFiles CustomWidgetWizard::generateFiles(const QWizard *w, Q_ASSERT(w); GenerationParameters p; p.fileName = cw->projectName(); - p.path = cw->path(); + p.path = cw->filePath().toString(); p.templatePath = QtWizard::templateDir(); p.templatePath += QLatin1String("/customwidgetwizard"); return PluginGenerator::generatePlugin(p, *(cw->pluginOptions()), errorMessage); diff --git a/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizarddialog.cpp b/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizarddialog.cpp index bb615395023..d292ab8568e 100644 --- a/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizarddialog.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizarddialog.cpp @@ -24,8 +24,11 @@ ****************************************************************************/ #include "subdirsprojectwizarddialog.h" + #include +#include + namespace QmakeProjectManager { namespace Internal { @@ -52,7 +55,7 @@ QtProjectParameters SubdirsProjectWizardDialog::parameters() const QtProjectParameters rc; rc.type = QtProjectParameters::EmptyProject; rc.fileName = projectName(); - rc.path = path(); + rc.path = filePath().toString(); return rc; }