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();
}
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)
@@ -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;
}

View File

@@ -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);

View File

@@ -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<BaseProjectWizardDialogPrivate>(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 &parameters) :
Core::BaseFileWizard(factory, parameters.extraValues(), parent),
d(std::make_unique<BaseProjectWizardDialogPrivate>(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();
}

View File

@@ -32,7 +32,10 @@
#include <memory>
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<n>) in path.
static QString uniqueProjectName(const QString &path);
void addExtensionPages(const QList<QWizardPage *> &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);

View File

@@ -240,7 +240,7 @@ static inline QString scriptWorkingDirectory(const QSharedPointer<CustomWizardCo
const QSharedPointer<CustomWizardParameters> &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 <file> 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;

View File

@@ -404,8 +404,8 @@ QMap<QString, QString> 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<CustomWizardContext> &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)

View File

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

View File

@@ -27,6 +27,8 @@
#include <coreplugin/iwizardfactory.h>
#include <utils/filepath.h>
#include <QStringList>
#include <QMap>
#include <QSharedPointer>
@@ -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[];

View File

@@ -34,35 +34,34 @@
#include <QDir>
#include <QVariant>
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<JsonWizard *>(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();
}

View File

@@ -33,6 +33,8 @@
#include <qtsupport/qtsupportconstants.h>
#include <utils/filepath.h>
#include <QCoreApplication>
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);

View File

@@ -24,8 +24,11 @@
****************************************************************************/
#include "subdirsprojectwizarddialog.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/filepath.h>
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;
}