Utils: User FilePath in ProjectIntroPage

... and fix some fallout.

Change-Id: I8f4ae8304e29614417f7d6b664e165f618b57f71
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-08-09 15:10:21 +02:00
parent 9312963f5e
commit 6405f9c436
11 changed files with 69 additions and 50 deletions

View File

@@ -114,14 +114,14 @@ QString ProjectIntroPage::projectName() const
return d->m_ui.nameLineEdit->text(); 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 &regEx) void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression &regEx)
@@ -178,14 +178,15 @@ bool ProjectIntroPage::validate()
} }
// Check existence of the directory // Check existence of the directory
const QFileInfo projectDirFile(path() + QLatin1Char('/') const FilePath projectDir =
+ QDir::fromNativeSeparators(d->m_ui.nameLineEdit->text())); filePath().pathAppended(QDir::fromNativeSeparators(d->m_ui.nameLineEdit->text()));
if (!projectDirFile.exists()) { // All happy
if (!projectDir.exists()) { // All happy
hideStatusLabel(); hideStatusLabel();
return true; return true;
} }
if (projectDirFile.isDir()) { if (projectDir.isDir()) {
displayStatusMessage(InfoLabel::Warning, tr("The project already exists.")); displayStatusMessage(InfoLabel::Warning, tr("The project already exists."));
return true; return true;
} }

View File

@@ -26,8 +26,10 @@
#pragma once #pragma once
#include "utils_global.h" #include "utils_global.h"
#include "wizardpage.h"
#include "filepath.h"
#include "infolabel.h" #include "infolabel.h"
#include "wizardpage.h"
namespace Utils { namespace Utils {
@@ -37,7 +39,7 @@ class QTCREATOR_UTILS_EXPORT ProjectIntroPage : public WizardPage
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString description READ description WRITE setDescription DESIGNABLE true) 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(QString projectName READ projectName WRITE setProjectName DESIGNABLE true)
Q_PROPERTY(bool useAsDefaultPath READ useAsDefaultPath WRITE setUseAsDefaultPath DESIGNABLE true) Q_PROPERTY(bool useAsDefaultPath READ useAsDefaultPath WRITE setUseAsDefaultPath DESIGNABLE true)
Q_PROPERTY(bool forceSubProject READ forceSubProject WRITE setForceSubProject DESIGNABLE true) Q_PROPERTY(bool forceSubProject READ forceSubProject WRITE setForceSubProject DESIGNABLE true)
@@ -47,7 +49,7 @@ public:
~ProjectIntroPage() override; ~ProjectIntroPage() override;
QString projectName() const; QString projectName() const;
QString path() const; FilePath filePath() const;
QString description() const; QString description() const;
bool useAsDefaultPath() const; bool useAsDefaultPath() const;
@@ -68,7 +70,7 @@ signals:
void activated(); void activated();
public slots: public slots:
void setPath(const QString &path); void setFilePath(const FilePath &path);
void setProjectName(const QString &name); void setProjectName(const QString &name);
void setDescription(const QString &description); void setDescription(const QString &description);
void setUseAsDefaultPath(bool u); void setUseAsDefaultPath(bool u);

View File

@@ -41,6 +41,8 @@
as default projects' folder should the user wish to do that. as default projects' folder should the user wish to do that.
*/ */
using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer {
struct BaseProjectWizardDialogPrivate { struct BaseProjectWizardDialogPrivate {
@@ -66,20 +68,20 @@ BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFacto
Core::BaseFileWizard(factory, parameters.extraValues(), parent), Core::BaseFileWizard(factory, parameters.extraValues(), parent),
d(std::make_unique<BaseProjectWizardDialogPrivate>(new Utils::ProjectIntroPage)) d(std::make_unique<BaseProjectWizardDialogPrivate>(new Utils::ProjectIntroPage))
{ {
setPath(parameters.defaultPath()); setFilePath(FilePath::fromString(parameters.defaultPath()));
setSelectedPlatform(parameters.selectedPlatform()); setSelectedPlatform(parameters.selectedPlatform());
setRequiredFeatures(parameters.requiredFeatures()); setRequiredFeatures(parameters.requiredFeatures());
init(); init();
} }
BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFactory *factory, BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFactory *factory,
Utils::ProjectIntroPage *introPage, int introId, ProjectIntroPage *introPage, int introId,
QWidget *parent, QWidget *parent,
const Core::WizardDialogParameters &parameters) : const Core::WizardDialogParameters &parameters) :
Core::BaseFileWizard(factory, parameters.extraValues(), parent), Core::BaseFileWizard(factory, parameters.extraValues(), parent),
d(std::make_unique<BaseProjectWizardDialogPrivate>(introPage, introId)) d(std::make_unique<BaseProjectWizardDialogPrivate>(introPage, introId))
{ {
setPath(parameters.defaultPath()); setFilePath(FilePath::fromString(parameters.defaultPath()));
setSelectedPlatform(parameters.selectedPlatform()); setSelectedPlatform(parameters.selectedPlatform());
setRequiredFeatures(parameters.requiredFeatures()); setRequiredFeatures(parameters.requiredFeatures());
init(); init();
@@ -103,9 +105,9 @@ QString BaseProjectWizardDialog::projectName() const
return d->introPage->projectName(); 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) void BaseProjectWizardDialog::setIntroDescription(const QString &des)
@@ -113,9 +115,9 @@ void BaseProjectWizardDialog::setIntroDescription(const QString &des)
d->introPage->setDescription(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) void BaseProjectWizardDialog::setProjectName(const QString &name)
@@ -142,7 +144,7 @@ void BaseProjectWizardDialog::slotAccepted()
{ {
if (d->introPage->useAsDefaultPath()) { if (d->introPage->useAsDefaultPath()) {
// Store the path as default path for new projects if desired. // 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); Core::DocumentManager::setUseProjectsDirectory(true);
} }
} }
@@ -150,7 +152,7 @@ void BaseProjectWizardDialog::slotAccepted()
bool BaseProjectWizardDialog::validateCurrentPage() bool BaseProjectWizardDialog::validateCurrentPage()
{ {
if (currentId() == d->introPageId) 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(); return Core::BaseFileWizard::validateCurrentPage();
} }

View File

@@ -32,7 +32,10 @@
#include <memory> #include <memory>
namespace Utils { class ProjectIntroPage; } namespace Utils {
class FilePath;
class ProjectIntroPage;
} // Utils
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -55,14 +58,14 @@ public:
~BaseProjectWizardDialog() override; ~BaseProjectWizardDialog() override;
QString projectName() const; QString projectName() const;
QString path() const; Utils::FilePath filePath() const;
// Generate a new project name (untitled<n>) in path. // Generate a new project name (untitled<n>) in path.
static QString uniqueProjectName(const QString &path); static QString uniqueProjectName(const QString &path);
void addExtensionPages(const QList<QWizardPage *> &wizardPageList); void addExtensionPages(const QList<QWizardPage *> &wizardPageList);
void setIntroDescription(const QString &d); void setIntroDescription(const QString &d);
void setPath(const QString &path); void setFilePath(const Utils::FilePath &path);
void setProjectName(const QString &name); void setProjectName(const QString &name);
void setProjectList(const QStringList &projectList); void setProjectList(const QStringList &projectList);
void setProjectDirectories(const QStringList &directories); void setProjectDirectories(const QStringList &directories);

View File

@@ -240,7 +240,7 @@ static inline QString scriptWorkingDirectory(const QSharedPointer<CustomWizardCo
const QSharedPointer<CustomWizardParameters> &p) const QSharedPointer<CustomWizardParameters> &p)
{ {
if (p->filesGeneratorScriptWorkingDirectory.isEmpty()) if (p->filesGeneratorScriptWorkingDirectory.isEmpty())
return ctx->targetPath; return ctx->targetPath.toString();
QString path = p->filesGeneratorScriptWorkingDirectory; QString path = p->filesGeneratorScriptWorkingDirectory;
CustomWizardContext::replaceFields(ctx->replacements, &path); CustomWizardContext::replaceFields(ctx->replacements, &path);
return path; return path;
@@ -253,7 +253,7 @@ GeneratedFiles CustomWizard::generateFiles(const QWizard *dialog, QString *error
QTC_ASSERT(cwp, return {}); QTC_ASSERT(cwp, return {});
CustomWizardContextPtr ctx = context(); CustomWizardContextPtr ctx = context();
ctx->path = ctx->targetPath = cwp->path(); ctx->path = ctx->targetPath = cwp->filePath();
ctx->replacements = replacementMap(dialog); ctx->replacements = replacementMap(dialog);
if (CustomWizardPrivate::verbose) { if (CustomWizardPrivate::verbose) {
QString logText; QString logText;
@@ -330,7 +330,8 @@ GeneratedFiles CustomWizard::generateWizardFiles(QString *errorMessage) const
} }
// Add the template files specified by the <file> elements. // Add the template files specified by the <file> elements.
for (const CustomWizardFile &file : qAsConst(d->m_parameters->files)) 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 {};
return rc; return rc;
@@ -525,7 +526,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w,
} }
for (QWizardPage *ep : extensionPages) for (QWizardPage *ep : extensionPages)
w->addPage(ep); w->addPage(ep);
w->setPath(defaultPath); w->setFilePath(FilePath::fromString(defaultPath));
w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath)); w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath));
connect(w, &BaseProjectWizardDialog::projectParametersChanged, connect(w, &BaseProjectWizardDialog::projectParametersChanged,
@@ -541,8 +542,8 @@ GeneratedFiles CustomProjectWizard::generateFiles(const QWizard *w, QString *err
QTC_ASSERT(dialog, return {}); QTC_ASSERT(dialog, return {});
// Add project name as macro. Path is here under project directory // Add project name as macro. Path is here under project directory
CustomWizardContextPtr ctx = context(); CustomWizardContextPtr ctx = context();
ctx->path = dialog->path(); ctx->path = dialog->filePath();
ctx->targetPath = ctx->path + QLatin1Char('/') + dialog->projectName(); ctx->targetPath = ctx->path.pathAppended(dialog->projectName());
FieldReplacementMap fieldReplacementMap = replacementMap(dialog); FieldReplacementMap fieldReplacementMap = replacementMap(dialog);
fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName()); fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName());
ctx->replacements = fieldReplacementMap; ctx->replacements = fieldReplacementMap;

View File

@@ -404,8 +404,8 @@ QMap<QString, QString> CustomWizardFieldPage::replacementMap(const QWizard *w,
fieldReplacementMap.insert(field.name, value); fieldReplacementMap.insert(field.name, value);
} }
// Insert paths for generator scripts. // Insert paths for generator scripts.
fieldReplacementMap.insert(QLatin1String("Path"), QDir::toNativeSeparators(ctx->path)); fieldReplacementMap.insert(QLatin1String("Path"), ctx->path.toUserOutput());
fieldReplacementMap.insert(QLatin1String("TargetPath"), QDir::toNativeSeparators(ctx->targetPath)); fieldReplacementMap.insert(QLatin1String("TargetPath"), ctx->targetPath.toUserOutput());
return fieldReplacementMap; return fieldReplacementMap;
} }
@@ -432,9 +432,9 @@ CustomWizardPage::CustomWizardPage(const QSharedPointer<CustomWizardContext> &ct
connect(m_pathChooser, &PathChooser::validChanged, this, &QWizardPage::completeChanged); 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) void CustomWizardPage::setPath(const QString &path)

View File

@@ -25,6 +25,8 @@
#pragma once #pragma once
#include <utils/filepath.h>
#include <QComboBox> #include <QComboBox>
#include <QCheckBox> #include <QCheckBox>
#include <QWizardPage> #include <QWizardPage>
@@ -115,14 +117,16 @@ private:
}; };
// Documentation inside. // Documentation inside.
class CustomWizardPage : public CustomWizardFieldPage { class CustomWizardPage : public CustomWizardFieldPage
{
Q_OBJECT Q_OBJECT
public: public:
explicit CustomWizardPage(const QSharedPointer<CustomWizardContext> &ctx, explicit CustomWizardPage(const QSharedPointer<CustomWizardContext> &ctx,
const QSharedPointer<CustomWizardParameters> &parameters, const QSharedPointer<CustomWizardParameters> &parameters,
QWidget *parent = nullptr); QWidget *parent = nullptr);
QString path() const; Utils::FilePath filePath() const;
void setPath(const QString &path); void setPath(const QString &path);
bool isComplete() const override; bool isComplete() const override;

View File

@@ -27,6 +27,8 @@
#include <coreplugin/iwizardfactory.h> #include <coreplugin/iwizardfactory.h>
#include <utils/filepath.h>
#include <QStringList> #include <QStringList>
#include <QMap> #include <QMap>
#include <QSharedPointer> #include <QSharedPointer>
@@ -151,10 +153,10 @@ public:
FieldReplacementMap baseReplacements; FieldReplacementMap baseReplacements;
FieldReplacementMap replacements; FieldReplacementMap replacements;
QString path; Utils::FilePath path;
// Where files should be created, that is, 'path' for simple wizards // Where files should be created, that is, 'path' for simple wizards
// or "path + project" for project wizards. // or "path + project" for project wizards.
QString targetPath; Utils::FilePath targetPath;
}; };
extern const char customWizardFileOpenEditorAttributeC[]; extern const char customWizardFileOpenEditorAttributeC[];

View File

@@ -34,35 +34,34 @@
#include <QDir> #include <QDir>
#include <QVariant> #include <QVariant>
using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer {
JsonProjectPage::JsonProjectPage(QWidget *parent) : Utils::ProjectIntroPage(parent) JsonProjectPage::JsonProjectPage(QWidget *parent) : ProjectIntroPage(parent)
{ } { }
void JsonProjectPage::initializePage() void JsonProjectPage::initializePage()
{ {
auto wiz = qobject_cast<JsonWizard *>(wizard()); auto wiz = qobject_cast<JsonWizard *>(wizard());
QTC_ASSERT(wiz, return); 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() bool JsonProjectPage::validatePage()
{ {
if (isComplete() && useAsDefaultPath()) { if (isComplete() && useAsDefaultPath()) {
// Store the path as default path for new projects if desired. // 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); Core::DocumentManager::setUseProjectsDirectory(true);
} }
QString target = path(); const FilePath target = filePath().pathAppended(projectName());
if (!target.endsWith(QLatin1Char('/')))
target += QLatin1Char('/');
target += projectName();
wizard()->setProperty("ProjectDirectory", target); wizard()->setProperty("ProjectDirectory", target.toString());
wizard()->setProperty("TargetPath", target); wizard()->setProperty("TargetPath", target.toString());
return Utils::ProjectIntroPage::validatePage(); return Utils::ProjectIntroPage::validatePage();
} }

View File

@@ -33,6 +33,8 @@
#include <qtsupport/qtsupportconstants.h> #include <qtsupport/qtsupportconstants.h>
#include <utils/filepath.h>
#include <QCoreApplication> #include <QCoreApplication>
namespace QmakeProjectManager { namespace QmakeProjectManager {
@@ -66,7 +68,7 @@ Core::GeneratedFiles CustomWidgetWizard::generateFiles(const QWizard *w,
Q_ASSERT(w); Q_ASSERT(w);
GenerationParameters p; GenerationParameters p;
p.fileName = cw->projectName(); p.fileName = cw->projectName();
p.path = cw->path(); p.path = cw->filePath().toString();
p.templatePath = QtWizard::templateDir(); p.templatePath = QtWizard::templateDir();
p.templatePath += QLatin1String("/customwidgetwizard"); p.templatePath += QLatin1String("/customwidgetwizard");
return PluginGenerator::generatePlugin(p, *(cw->pluginOptions()), errorMessage); return PluginGenerator::generatePlugin(p, *(cw->pluginOptions()), errorMessage);

View File

@@ -24,8 +24,11 @@
****************************************************************************/ ****************************************************************************/
#include "subdirsprojectwizarddialog.h" #include "subdirsprojectwizarddialog.h"
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/filepath.h>
namespace QmakeProjectManager { namespace QmakeProjectManager {
namespace Internal { namespace Internal {
@@ -52,7 +55,7 @@ QtProjectParameters SubdirsProjectWizardDialog::parameters() const
QtProjectParameters rc; QtProjectParameters rc;
rc.type = QtProjectParameters::EmptyProject; rc.type = QtProjectParameters::EmptyProject;
rc.fileName = projectName(); rc.fileName = projectName();
rc.path = path(); rc.path = filePath().toString();
return rc; return rc;
} }