2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2009-11-26 18:03:16 +01:00
|
|
|
|
|
|
|
|
#include "baseprojectwizarddialog.h"
|
|
|
|
|
|
2023-01-13 12:38:22 +01:00
|
|
|
#include "projectexplorertr.h"
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2009-11-26 18:03:16 +01:00
|
|
|
#include <utils/projectintropage.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::BaseProjectWizardDialog
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The BaseProjectWizardDialog class is the base class for project
|
|
|
|
|
wizards.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2011-05-10 15:19:38 +02:00
|
|
|
Presents the introductory page and takes care of setting the folder chosen
|
2011-04-14 12:58:14 +02:00
|
|
|
as default projects' folder should the user wish to do that.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-08-09 15:10:21 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2009-11-26 18:03:16 +01:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
2021-09-27 13:27:59 +02:00
|
|
|
struct BaseProjectWizardDialogPrivate
|
|
|
|
|
{
|
|
|
|
|
explicit BaseProjectWizardDialogPrivate(ProjectIntroPage *page, int id = -1)
|
|
|
|
|
: desiredIntroPageId(id), introPage(page)
|
|
|
|
|
{}
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2010-03-22 15:33:33 +01:00
|
|
|
const int desiredIntroPageId;
|
2021-09-27 13:27:59 +02:00
|
|
|
ProjectIntroPage *introPage;
|
|
|
|
|
int introPageId = -1;
|
|
|
|
|
Id selectedPlatform;
|
|
|
|
|
QSet<Id> requiredFeatureSet;
|
2009-11-26 18:03:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-05-29 17:25:40 +02:00
|
|
|
BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFactory *factory,
|
|
|
|
|
QWidget *parent,
|
2012-02-08 17:25:35 +01:00
|
|
|
const Core::WizardDialogParameters ¶meters) :
|
2015-05-29 17:25:40 +02:00
|
|
|
Core::BaseFileWizard(factory, parameters.extraValues(), parent),
|
2021-09-27 13:27:59 +02:00
|
|
|
d(std::make_unique<BaseProjectWizardDialogPrivate>(new ProjectIntroPage))
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2021-09-27 18:06:38 +02:00
|
|
|
setFilePath(parameters.defaultPath());
|
2012-02-08 17:25:35 +01:00
|
|
|
setSelectedPlatform(parameters.selectedPlatform());
|
|
|
|
|
setRequiredFeatures(parameters.requiredFeatures());
|
2009-11-26 18:03:16 +01:00
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 17:25:40 +02:00
|
|
|
BaseProjectWizardDialog::BaseProjectWizardDialog(const Core::BaseFileWizardFactory *factory,
|
2021-08-09 15:10:21 +02:00
|
|
|
ProjectIntroPage *introPage, int introId,
|
2012-02-03 18:00:08 +01:00
|
|
|
QWidget *parent,
|
2012-02-08 17:25:35 +01:00
|
|
|
const Core::WizardDialogParameters ¶meters) :
|
2015-05-29 17:25:40 +02:00
|
|
|
Core::BaseFileWizard(factory, parameters.extraValues(), parent),
|
2018-07-16 13:59:39 +02:00
|
|
|
d(std::make_unique<BaseProjectWizardDialogPrivate>(introPage, introId))
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2021-09-27 18:06:38 +02:00
|
|
|
setFilePath(parameters.defaultPath());
|
2012-02-08 17:25:35 +01:00
|
|
|
setSelectedPlatform(parameters.selectedPlatform());
|
|
|
|
|
setRequiredFeatures(parameters.requiredFeatures());
|
2009-11-26 18:03:16 +01:00
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseProjectWizardDialog::init()
|
|
|
|
|
{
|
2010-03-22 15:33:33 +01:00
|
|
|
if (d->introPageId == -1) {
|
|
|
|
|
d->introPageId = addPage(d->introPage);
|
|
|
|
|
} else {
|
|
|
|
|
d->introPageId = d->desiredIntroPageId;
|
|
|
|
|
setPage(d->desiredIntroPageId, d->introPage);
|
|
|
|
|
}
|
2015-09-22 16:06:20 +02:00
|
|
|
connect(this, &QDialog::accepted, this, &BaseProjectWizardDialog::slotAccepted);
|
2009-11-26 18:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-16 13:59:39 +02:00
|
|
|
BaseProjectWizardDialog::~BaseProjectWizardDialog() = default;
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString BaseProjectWizardDialog::projectName() const
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
return d->introPage->projectName();
|
2009-11-26 18:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-09 15:10:21 +02:00
|
|
|
FilePath BaseProjectWizardDialog::filePath() const
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2021-08-09 15:10:21 +02:00
|
|
|
return d->introPage->filePath();
|
2009-11-26 18:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseProjectWizardDialog::setIntroDescription(const QString &des)
|
|
|
|
|
{
|
|
|
|
|
d->introPage->setDescription(des);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 15:10:21 +02:00
|
|
|
void BaseProjectWizardDialog::setFilePath(const FilePath &path)
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2021-08-09 15:10:21 +02:00
|
|
|
d->introPage->setFilePath(path);
|
2009-11-26 18:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
void BaseProjectWizardDialog::setProjectName(const QString &name)
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
d->introPage->setProjectName(name);
|
2009-11-26 18:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseProjectWizardDialog::slotAccepted()
|
|
|
|
|
{
|
|
|
|
|
if (d->introPage->useAsDefaultPath()) {
|
2010-03-22 15:33:33 +01:00
|
|
|
// Store the path as default path for new projects if desired.
|
2021-08-09 15:10:21 +02:00
|
|
|
Core::DocumentManager::setProjectsDirectory(filePath());
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::DocumentManager::setUseProjectsDirectory(true);
|
2009-11-26 18:03:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-22 15:52:25 +02:00
|
|
|
bool BaseProjectWizardDialog::validateCurrentPage()
|
2010-03-22 15:33:33 +01:00
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (currentId() == d->introPageId)
|
2022-06-17 17:10:51 +02:00
|
|
|
emit projectParametersChanged(d->introPage->projectName(), d->introPage->filePath());
|
2015-09-22 15:52:25 +02:00
|
|
|
return Core::BaseFileWizard::validateCurrentPage();
|
2010-03-22 15:33:33 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 13:27:59 +02:00
|
|
|
ProjectIntroPage *BaseProjectWizardDialog::introPage() const
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
|
|
|
|
return d->introPage;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 18:06:38 +02:00
|
|
|
QString BaseProjectWizardDialog::uniqueProjectName(const FilePath &path)
|
2009-11-26 18:03:16 +01:00
|
|
|
{
|
2021-09-27 18:06:38 +02:00
|
|
|
const QDir pathDir(path.toString());
|
2010-02-15 11:08:23 +01:00
|
|
|
//: File path suggestion for a new project. If you choose
|
2012-01-16 13:50:48 +01:00
|
|
|
//: to translate it, make sure it is a valid path name without blanks
|
|
|
|
|
//: and using only ascii chars.
|
2023-01-13 12:38:22 +01:00
|
|
|
const QString prefix = Tr::tr("untitled");
|
2011-04-19 15:42:14 +02:00
|
|
|
for (unsigned i = 0; ; ++i) {
|
2009-11-26 18:03:16 +01:00
|
|
|
QString name = prefix;
|
|
|
|
|
if (i)
|
|
|
|
|
name += QString::number(i);
|
|
|
|
|
if (!pathDir.exists(name))
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
return prefix;
|
|
|
|
|
}
|
2012-02-08 17:25:35 +01:00
|
|
|
|
2012-02-14 15:21:21 +01:00
|
|
|
void BaseProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wizardPageList)
|
|
|
|
|
{
|
2021-09-27 13:27:59 +02:00
|
|
|
for (QWizardPage *p : wizardPageList)
|
2014-05-30 11:38:08 +02:00
|
|
|
addPage(p);
|
2012-02-14 15:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-27 13:27:59 +02:00
|
|
|
Id BaseProjectWizardDialog::selectedPlatform() const
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
|
|
|
|
return d->selectedPlatform;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 13:27:59 +02:00
|
|
|
void BaseProjectWizardDialog::setSelectedPlatform(Id platform)
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
|
|
|
|
d->selectedPlatform = platform;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 13:27:59 +02:00
|
|
|
QSet<Id> BaseProjectWizardDialog::requiredFeatures() const
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
|
|
|
|
return d->requiredFeatureSet;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 13:27:59 +02:00
|
|
|
void BaseProjectWizardDialog::setRequiredFeatures(const QSet<Id> &featureSet)
|
2012-02-08 17:25:35 +01:00
|
|
|
{
|
|
|
|
|
d->requiredFeatureSet = featureSet;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-26 18:03:16 +01:00
|
|
|
} // namespace ProjectExplorer
|