Files
qt-creator/src/plugins/qt4projectmanager/wizards/qtwizard.cpp

329 lines
11 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "qtwizard.h"
2010-02-17 14:26:42 +01:00
2008-12-02 12:01:29 +01:00
#include "qt4project.h"
2010-03-29 17:57:18 +02:00
#include "qt4projectmanager.h"
2008-12-02 12:01:29 +01:00
#include "qt4projectmanagerconstants.h"
#include "qt4target.h"
#include "modulespage.h"
2010-03-29 17:57:18 +02:00
#include "targetsetuppage.h"
2008-12-02 12:01:29 +01:00
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cpptoolsconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h>
2008-12-02 12:01:29 +01:00
#include <QtCore/QCoreApplication>
#include <QtCore/QVariant>
2008-12-02 12:01:29 +01:00
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
static inline Core::BaseFileWizardParameters
wizardParameters(const QString &id,
2010-01-13 18:44:15 +01:00
const QString &category,
const QString &categoryTranslationScope,
const QString &displayCategory,
const QString &name,
2008-12-02 12:01:29 +01:00
const QString &description,
const QIcon &icon)
{
Core::BaseFileWizardParameters rc(Core::IWizard::ProjectWizard);
2010-01-13 18:44:15 +01:00
rc.setCategory(category);
rc.setDisplayCategory(QCoreApplication::translate(categoryTranslationScope.toLatin1(),
displayCategory.toLatin1()));
2008-12-02 12:01:29 +01:00
rc.setIcon(icon);
rc.setDisplayName(name);
rc.setId(id);
2008-12-02 12:01:29 +01:00
rc.setDescription(description);
return rc;
}
// -------------------- QtWizard
2010-01-13 18:44:15 +01:00
QtWizard::QtWizard(const QString &id,
const QString &category,
const QString &categoryTranslationScope,
const QString &displayCategory,
const QString &name,
const QString &description, const QIcon &icon) :
2010-01-13 18:44:15 +01:00
Core::BaseFileWizard(wizardParameters(id,
category,
categoryTranslationScope,
displayCategory,
name,
description,
icon))
2008-12-02 12:01:29 +01:00
{
}
QString QtWizard::sourceSuffix()
2008-12-02 12:01:29 +01:00
{
return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
}
QString QtWizard::headerSuffix()
2008-12-02 12:01:29 +01:00
{
return preferredSuffix(QLatin1String(Constants::CPP_HEADER_MIMETYPE));
}
QString QtWizard::formSuffix()
2008-12-02 12:01:29 +01:00
{
return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
}
QString QtWizard::profileSuffix()
2008-12-02 12:01:29 +01:00
{
return preferredSuffix(QLatin1String(Constants::PROFILE_MIMETYPE));
}
bool QtWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
{
return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
}
bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w,
const Core::GeneratedFiles &generatedFiles,
QString *errorMessage)
2008-12-02 12:01:29 +01:00
{
const BaseQt4ProjectWizardDialog *dialog = qobject_cast<const BaseQt4ProjectWizardDialog *>(w);
// Generate user settings
foreach (const Core::GeneratedFile &file, generatedFiles)
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
dialog->writeUserFile(file.path());
break;
}
// Post-Generate: Open the projects/editors
return ProjectExplorer::CustomProjectWizard::postGenerateOpen(generatedFiles ,errorMessage);
2008-12-02 12:01:29 +01:00
}
QString QtWizard::templateDir()
2008-12-02 12:01:29 +01:00
{
QString rc = Core::ICore::instance()->resourcePath();
2008-12-02 12:01:29 +01:00
rc += QLatin1String("/templates/qt4project");
return rc;
}
bool QtWizard::lowerCaseFiles()
{
QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
lowerCaseSettingsKey += QLatin1Char('/');
lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
return Core::ICore::instance()->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
}
bool QtWizard::showModulesPageForApplications()
{
return false;
}
bool QtWizard::showModulesPageForLibraries()
{
return true;
}
// ------------ CustomQt4ProjectWizard
CustomQt4ProjectWizard::CustomQt4ProjectWizard(const Core::BaseFileWizardParameters& baseFileParameters,
QObject *parent) :
ProjectExplorer::CustomProjectWizard(baseFileParameters, parent)
{
}
QWizard *CustomQt4ProjectWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
{
BaseQt4ProjectWizardDialog *wizard = new BaseQt4ProjectWizardDialog(false, parent);
initProjectWizardDialog(wizard, defaultPath, extensionPages);
if (wizard->pageIds().contains(targetPageId))
qWarning("CustomQt4ProjectWizard: Unable to insert target page at %d", int(targetPageId));
2010-03-30 15:55:45 +02:00
wizard->addTargetSetupPage(QSet<QString>(), false, targetPageId);
return wizard;
}
bool CustomQt4ProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
{
return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
}
void CustomQt4ProjectWizard::registerSelf()
{
ProjectExplorer::CustomWizard::registerFactory<CustomQt4ProjectWizard>(QLatin1String("qt4project"));
}
// ----------------- BaseQt4ProjectWizardDialog
BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage, QWidget *parent) :
ProjectExplorer::BaseProjectWizardDialog(parent),
m_modulesPage(0),
2010-03-29 17:57:18 +02:00
m_targetSetupPage(0)
{
init(showModulesPage);
}
BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage,
Utils::ProjectIntroPage *introPage,
int introId, QWidget *parent) :
ProjectExplorer::BaseProjectWizardDialog(introPage, introId, parent),
m_modulesPage(0),
2010-03-29 17:57:18 +02:00
m_targetSetupPage(0)
{
init(showModulesPage);
}
BaseQt4ProjectWizardDialog::~BaseQt4ProjectWizardDialog()
{
2010-03-29 17:57:18 +02:00
if (m_targetSetupPage && !m_targetSetupPage->parent())
delete m_targetSetupPage;
if (m_modulesPage && !m_modulesPage->parent())
delete m_modulesPage;
}
void BaseQt4ProjectWizardDialog::init(bool showModulesPage)
{
if (showModulesPage)
m_modulesPage = new ModulesPage;
connect(this, SIGNAL(introPageLeft(QString,QString)),
this, SLOT(generateProfileName(QString,QString)));
}
int BaseQt4ProjectWizardDialog::addModulesPage(int id)
{
if (!m_modulesPage)
return -1;
if (id >= 0) {
setPage(id, m_modulesPage);
2010-03-31 14:48:08 +02:00
wizardProgress()->item(id)->setTitle(tr("Modules"));
return id;
}
2010-03-31 14:48:08 +02:00
const int newId = addPage(m_modulesPage);
wizardProgress()->item(newId)->setTitle(tr("Modules"));
return newId;
}
2010-03-30 15:55:45 +02:00
int BaseQt4ProjectWizardDialog::addTargetSetupPage(QSet<QString> targets, bool mobile, int id)
{
2010-03-29 17:57:18 +02:00
m_targetSetupPage = new TargetSetupPage;
connect(this, SIGNAL(projectLocationChanged(QString)),
m_targetSetupPage, SLOT(setProFilePath(QString)));
QList<TargetSetupPage::ImportInfo> infos = TargetSetupPage::importInfosForKnownQtVersions();
2010-03-29 17:57:18 +02:00
if (!targets.isEmpty())
infos = TargetSetupPage::filterImportInfos(targets, infos);
m_targetSetupPage->setImportDirectoryBrowsingEnabled(false);
2010-03-30 15:55:45 +02:00
m_targetSetupPage->setPreferMobile(mobile);
2010-03-29 17:57:18 +02:00
if (infos.count() <= 1)
return -1;
2010-03-29 17:57:18 +02:00
m_targetSetupPage->setImportInfos(infos);
if (id >= 0)
setPage(id, m_targetSetupPage);
else
id = addPage(m_targetSetupPage);
2010-03-31 14:48:08 +02:00
wizardProgress()->item(id)->setTitle(tr("Qt Versions"));
2010-03-29 17:57:18 +02:00
return id;
}
QString BaseQt4ProjectWizardDialog::selectedModules() const
{
return m_modulesPage ? m_modulesPage->selectedModules() : m_selectedModules;
}
void BaseQt4ProjectWizardDialog::setSelectedModules(const QString &modules, bool lock)
{
if (m_modulesPage) {
foreach(const QString &module, modules.split(QLatin1Char(' '))) {
m_modulesPage->setModuleSelected(module, true);
m_modulesPage->setModuleEnabled(module, !lock);
}
} else {
m_selectedModules = modules;
}
}
QString BaseQt4ProjectWizardDialog::deselectedModules() const
{
return m_modulesPage ? m_modulesPage->deselectedModules() : m_deselectedModules;
}
void BaseQt4ProjectWizardDialog::setDeselectedModules(const QString &modules)
{
if (m_modulesPage) {
foreach(const QString &module, modules.split(QLatin1Char(' ')))
m_modulesPage->setModuleSelected(module, false);
} else {
m_deselectedModules = modules;
}
}
2010-03-29 17:57:18 +02:00
bool BaseQt4ProjectWizardDialog::writeUserFile(const QString &proFileName) const
{
if (!m_targetSetupPage)
return false;
Qt4Manager *manager = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
Q_ASSERT(manager);
Qt4Project *pro = new Qt4Project(manager, proFileName);
bool success = m_targetSetupPage->setupProject(pro);
if (success)
pro->saveSettings();
delete pro;
return success;
}
bool BaseQt4ProjectWizardDialog::setupProject(Qt4Project *project) const
{
2010-03-29 17:57:18 +02:00
return m_targetSetupPage->setupProject(project);
}
2010-03-29 17:57:18 +02:00
bool BaseQt4ProjectWizardDialog::isTargetSelected(const QString &targetid) const
{
2010-03-29 17:57:18 +02:00
return m_targetSetupPage->isTargetSelected(targetid);
}
void BaseQt4ProjectWizardDialog::generateProfileName(const QString &name, const QString &path)
{
const QString proFile = QDir::fromNativeSeparators(path) + QChar('/') + name + QChar('/') + name + QLatin1String(".pro");
emit projectLocationChanged(proFile);
}
QSet<QString> BaseQt4ProjectWizardDialog::desktopTarget()
{
QSet<QString> rc;
rc.insert(QLatin1String(Constants::DESKTOP_TARGET_ID));
return rc;
}