1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "qtwizard.h"
#include "qt4project.h"
#include "qt4projectmanager.h"
#include "qt4projectmanagerconstants.h"
#include "qt4target.h"
#include "modulespage.h"
#include "targetsetuppage.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cpptoolsconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/task.h>
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QVariant>
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
static inline Core::BaseFileWizardParameters
wizardParameters(const QString &id,
const QString &category,
const QString &categoryTranslationScope,
const QString &displayCategory,
const QString &name,
const QString &description,
const QIcon &icon)
{
Core::BaseFileWizardParameters rc(Core::IWizard::ProjectWizard);
rc.setCategory(category);
rc.setDisplayCategory(QCoreApplication::translate(categoryTranslationScope.toLatin1(),
displayCategory.toLatin1()));
rc.setIcon(icon);
rc.setDisplayName(name);
rc.setId(id);
rc.setDescription(description);
return rc;
}
// -------------------- QtWizard
QtWizard::QtWizard(const QString &id,
const QString &category,
const QString &categoryTranslationScope,
const QString &displayCategory,
const QString &name,
const QString &description, const QIcon &icon) :
Core::BaseFileWizard(wizardParameters(id,
category,
categoryTranslationScope,
displayCategory,
name,
description,
icon))
{
}
QString QtWizard::sourceSuffix()
{
return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
}
QString QtWizard::headerSuffix()
{
return preferredSuffix(QLatin1String(Constants::CPP_HEADER_MIMETYPE));
}
QString QtWizard::formSuffix()
{
return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
}
QString QtWizard::profileSuffix()
{
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)
{
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);
}
QString QtWizard::templateDir()
{
QString rc = Core::ICore::instance()->resourcePath();
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));
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),
m_targetSetupPage(0)
{
init(showModulesPage);
}
BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage,
Utils::ProjectIntroPage *introPage,
int introId, QWidget *parent) :
ProjectExplorer::BaseProjectWizardDialog(introPage, introId, parent),
m_modulesPage(0),
m_targetSetupPage(0)
{
init(showModulesPage);
}
BaseQt4ProjectWizardDialog::~BaseQt4ProjectWizardDialog()
{
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(projectParametersChanged(QString,QString)),
this, SLOT(generateProfileName(QString,QString)));
}
int BaseQt4ProjectWizardDialog::addModulesPage(int id)
{
if (!m_modulesPage)
return -1;
if (id >= 0) {
setPage(id, m_modulesPage);
wizardProgress()->item(id)->setTitle(tr("Modules"));
return id;
}
const int newId = addPage(m_modulesPage);
wizardProgress()->item(newId)->setTitle(tr("Modules"));
return newId;
}
int BaseQt4ProjectWizardDialog::addTargetSetupPage(QSet<QString> targets, bool mobile, int id)
{
m_targetSetupPage = new TargetSetupPage;
m_targets = targets;
resize(900, 450);
m_targetSetupPage->setPreferMobile(mobile);
if (id >= 0)
setPage(id, m_targetSetupPage);
else
id = addPage(m_targetSetupPage);
wizardProgress()->item(id)->setTitle(tr("Targets"));
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;
}
}
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
{
return m_targetSetupPage->setupProject(project);
}
bool BaseQt4ProjectWizardDialog::isTargetSelected(const QString &targetid) const
{
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");
m_targetSetupPage->setProFilePath(proFile);
}
QSet<QString> BaseQt4ProjectWizardDialog::desktopTarget()
{
QSet<QString> rc;
rc.insert(QLatin1String(Constants::DESKTOP_TARGET_ID));
return rc;
}
|