qtwizard.cpp 10.7 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "qtwizard.h"
Tobias Hunger's avatar
Tobias Hunger committed
31

32
#include "modulespage.h"
con's avatar
con committed
33

34 35 36
#include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakeprojectmanager.h>
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
37

38
#include <coreplugin/icore.h>
39

40
#include <cpptools/cpptoolsconstants.h>
41

42
#include <projectexplorer/projectexplorer.h>
43
#include <projectexplorer/projectexplorerconstants.h>
44
#include <projectexplorer/targetsetuppage.h>
Tobias Hunger's avatar
Tobias Hunger committed
45
#include <qtsupport/qtkitinformation.h>
Tobias Hunger's avatar
Tobias Hunger committed
46
#include <qtsupport/qtsupportconstants.h>
47 48 49

#include <extensionsystem/pluginmanager.h>

50 51
#include <QCoreApplication>
#include <QVariant>
con's avatar
con committed
52

53
using namespace ProjectExplorer;
54 55
using namespace QmakeProjectManager;
using namespace QmakeProjectManager::Internal;
con's avatar
con committed
56 57

// -------------------- QtWizard
hjk's avatar
hjk committed
58
QtWizard::QtWizard()
con's avatar
con committed
59
{
Tobias Hunger's avatar
Tobias Hunger committed
60
    setWizardKind(Core::IWizardFactory::ProjectWizard);
con's avatar
con committed
61 62
}

63
QString QtWizard::sourceSuffix()
con's avatar
con committed
64
{
65
    return preferredSuffix(QLatin1String(ProjectExplorer::Constants::CPP_SOURCE_MIMETYPE));
con's avatar
con committed
66 67
}

68
QString QtWizard::headerSuffix()
con's avatar
con committed
69
{
70
    return preferredSuffix(QLatin1String(ProjectExplorer::Constants::CPP_HEADER_MIMETYPE));
con's avatar
con committed
71 72
}

73
QString QtWizard::formSuffix()
con's avatar
con committed
74
{
75
    return preferredSuffix(QLatin1String(ProjectExplorer::Constants::FORM_MIMETYPE));
con's avatar
con committed
76 77
}

78
QString QtWizard::profileSuffix()
con's avatar
con committed
79 80 81 82
{
    return preferredSuffix(QLatin1String(Constants::PROFILE_MIMETYPE));
}

83
bool QtWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
84 85 86 87
{
    return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
}

88 89 90
bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w,
                                           const Core::GeneratedFiles &generatedFiles,
                                           QString *errorMessage)
con's avatar
con committed
91
{
92
    const BaseQmakeProjectWizardDialog *dialog = qobject_cast<const BaseQmakeProjectWizardDialog *>(w);
93

94 95 96 97 98 99
    // Generate user settings
    foreach (const Core::GeneratedFile &file, generatedFiles)
        if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
            dialog->writeUserFile(file.path());
            break;
        }
100

101 102
    // Post-Generate: Open the projects/editors
    return ProjectExplorer::CustomProjectWizard::postGenerateOpen(generatedFiles ,errorMessage);
con's avatar
con committed
103 104
}

105
QString QtWizard::templateDir()
con's avatar
con committed
106
{
hjk's avatar
hjk committed
107
    QString rc = Core::ICore::resourcePath();
con's avatar
con committed
108 109 110
    rc += QLatin1String("/templates/qt4project");
    return rc;
}
111 112 113 114 115 116 117

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;
hjk's avatar
hjk committed
118
    return Core::ICore::settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
119 120
}

121 122 123 124 125 126 127 128 129 130
bool QtWizard::showModulesPageForApplications()
{
    return false;
}

bool QtWizard::showModulesPageForLibraries()
{
    return true;
}

131 132
// ------------ CustomQmakeProjectWizard
CustomQmakeProjectWizard::CustomQmakeProjectWizard()
133 134 135
{
}

136 137
QWizard *CustomQmakeProjectWizard::create(QWidget *parent,
                                          const Core::WizardDialogParameters &parameters) const
138
{
139
    BaseQmakeProjectWizardDialog *wizard = new BaseQmakeProjectWizardDialog(false, parent, parameters);
140

141
    if (!parameters.extraValues().contains(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS)))
jkobus's avatar
jkobus committed
142
        wizard->addTargetSetupPage(targetPageId);
143

144
    initProjectWizardDialog(wizard, parameters.defaultPath(), parameters.extensionPages());
145 146 147
    return wizard;
}

148
bool CustomQmakeProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
149 150 151 152
{
    return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
}

153 154
// ----------------- BaseQmakeProjectWizardDialog
BaseQmakeProjectWizardDialog::BaseQmakeProjectWizardDialog(bool showModulesPage, QWidget *parent,
155 156
                                                       const Core::WizardDialogParameters &parameters) :
    ProjectExplorer::BaseProjectWizardDialog(parent, parameters),
157
    m_modulesPage(0),
158
    m_targetSetupPage(0),
159 160
    m_profileIds(parameters.extraValues().value(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS))
                 .value<QList<Core::Id> >())
161 162 163 164
{
    init(showModulesPage);
}

165
BaseQmakeProjectWizardDialog::BaseQmakeProjectWizardDialog(bool showModulesPage,
166
                                                       Utils::ProjectIntroPage *introPage,
167 168 169
                                                       int introId, QWidget *parent,
                                                       const Core::WizardDialogParameters &parameters) :
    ProjectExplorer::BaseProjectWizardDialog(introPage, introId, parent, parameters),
170
    m_modulesPage(0),
171
    m_targetSetupPage(0),
172 173
    m_profileIds(parameters.extraValues().value(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS))
                 .value<QList<Core::Id> >())
174 175 176 177
{
    init(showModulesPage);
}

178
BaseQmakeProjectWizardDialog::~BaseQmakeProjectWizardDialog()
Tobias Hunger's avatar
Tobias Hunger committed
179
{
180 181
    if (m_targetSetupPage && !m_targetSetupPage->parent())
        delete m_targetSetupPage;
Tobias Hunger's avatar
Tobias Hunger committed
182 183 184 185
    if (m_modulesPage && !m_modulesPage->parent())
        delete m_modulesPage;
}

186
void BaseQmakeProjectWizardDialog::init(bool showModulesPage)
187 188 189
{
    if (showModulesPage)
        m_modulesPage = new ModulesPage;
190
    connect(this, SIGNAL(projectParametersChanged(QString,QString)),
191
            this, SLOT(generateProfileName(QString,QString)));
192
}
193

194
int BaseQmakeProjectWizardDialog::addModulesPage(int id)
195
{
196 197 198 199
    if (!m_modulesPage)
        return -1;
    if (id >= 0) {
        setPage(id, m_modulesPage);
200
        wizardProgress()->item(id)->setTitle(tr("Modules"));
201
        return id;
202
    }
203 204 205
    const int newId = addPage(m_modulesPage);
    wizardProgress()->item(newId)->setTitle(tr("Modules"));
    return newId;
206 207
}

jkobus's avatar
jkobus committed
208
int BaseQmakeProjectWizardDialog::addTargetSetupPage(int id)
209
{
210
    m_targetSetupPage = new ProjectExplorer::TargetSetupPage;
Tobias Hunger's avatar
Tobias Hunger committed
211
    const QString platform = selectedPlatform();
jkobus's avatar
jkobus committed
212
    Core::FeatureSet features = Core::FeatureSet(QtSupport::Constants::FEATURE_DESKTOP);
Tobias Hunger's avatar
Tobias Hunger committed
213
    if (platform.isEmpty())
Tobias Hunger's avatar
Tobias Hunger committed
214
        m_targetSetupPage->setPreferredKitMatcher(new QtSupport::QtVersionKitMatcher(features));
Tobias Hunger's avatar
Tobias Hunger committed
215
    else
Tobias Hunger's avatar
Tobias Hunger committed
216
        m_targetSetupPage->setPreferredKitMatcher(new QtSupport::QtPlatformKitMatcher(platform));
217

Tobias Hunger's avatar
Tobias Hunger committed
218
    m_targetSetupPage->setRequiredKitMatcher(new QtSupport::QtVersionKitMatcher(requiredFeatures()));
Tobias Hunger's avatar
Tobias Hunger committed
219 220

    resize(900, 450);
221 222 223 224
    if (id >= 0)
        setPage(id, m_targetSetupPage);
    else
        id = addPage(m_targetSetupPage);
225
    wizardProgress()->item(id)->setTitle(tr("Kits"));
226 227

    return id;
228 229
}

230
QStringList BaseQmakeProjectWizardDialog::selectedModulesList() const
231
{
232
    return m_modulesPage ? m_modulesPage->selectedModulesList() : m_selectedModules;
233
}
234

235
void BaseQmakeProjectWizardDialog::setSelectedModules(const QString &modules, bool lock)
236
{
237
    const QStringList modulesList = modules.split(QLatin1Char(' '));
238
    if (m_modulesPage) {
239
        foreach (const QString &module, modulesList) {
240 241 242 243
            m_modulesPage->setModuleSelected(module, true);
            m_modulesPage->setModuleEnabled(module, !lock);
        }
    } else {
244
        m_selectedModules = modulesList;
245 246
    }
}
247

248
QStringList BaseQmakeProjectWizardDialog::deselectedModulesList() const
249
{
250
    return m_modulesPage ? m_modulesPage->deselectedModulesList() : m_deselectedModules;
251
}
252

253
void BaseQmakeProjectWizardDialog::setDeselectedModules(const QString &modules)
254
{
255
    const QStringList modulesList = modules.split(QLatin1Char(' '));
256
    if (m_modulesPage) {
257
        foreach (const QString &module, modulesList)
258 259
            m_modulesPage->setModuleSelected(module, false);
    } else {
260
        m_deselectedModules = modulesList;
261 262
    }
}
263

264
bool BaseQmakeProjectWizardDialog::writeUserFile(const QString &proFileName) const
265 266 267 268
{
    if (!m_targetSetupPage)
        return false;

269
    QmakeManager *manager = ExtensionSystem::PluginManager::getObject<QmakeManager>();
270 271
    Q_ASSERT(manager);

272
    QmakeProject *pro = new QmakeProject(manager, proFileName);
273 274 275 276 277 278 279
    bool success = m_targetSetupPage->setupProject(pro);
    if (success)
        pro->saveSettings();
    delete pro;
    return success;
}

280
bool BaseQmakeProjectWizardDialog::setupProject(QmakeProject *project) const
281
{
282 283
    if (!m_targetSetupPage)
        return true;
284
    return m_targetSetupPage->setupProject(project);
285 286
}

287
bool BaseQmakeProjectWizardDialog::isQtPlatformSelected(const QString &platform) const
288
{
Tobias Hunger's avatar
Tobias Hunger committed
289
    QList<Core::Id> selectedKitList = selectedKits();
290

291
    foreach (Kit *k, KitManager::matchingKits(QtSupport::QtPlatformKitMatcher(platform)))
292
        if (selectedKitList.contains(k->id()))
293
            return true;
294

295 296 297
    return false;
}

298
QList<Core::Id> BaseQmakeProjectWizardDialog::selectedKits() const
299 300 301
{
    if (!m_targetSetupPage)
        return m_profileIds;
Tobias Hunger's avatar
Tobias Hunger committed
302
    return m_targetSetupPage->selectedKits();
303
}
304

305
void BaseQmakeProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wizardPageList)
306 307
{
    foreach (QWizardPage *p,wizardPageList)
308
        Core::BaseFileWizardFactory::applyExtensionPageShortTitle(this, addPage(p));
309 310
}

311
void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name, const QString &path)
312
{
313 314 315
    if (!m_targetSetupPage)
        return;

316 317 318
    const QString proFile =
        QDir::cleanPath(path + QLatin1Char('/') + name + QLatin1Char('/')
                        + name + QLatin1String(".pro"));
319

320
    m_targetSetupPage->setProjectPath(proFile);
321
}