~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qt4projectmanager/wizards/qtquickappwizard.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
 
** Contact: http://www.qt-project.org/legal
5
 
**
6
 
** This file is part of Qt Creator.
7
 
**
8
 
** Commercial License Usage
9
 
** Licensees holding valid commercial Qt licenses may use this file in
10
 
** accordance with the commercial license agreement provided with the
11
 
** Software or, alternatively, in accordance with the terms contained in
12
 
** a written agreement between you and Digia.  For licensing terms and
13
 
** conditions see http://qt.digia.com/licensing.  For further information
14
 
** use the contact form at http://qt.digia.com/contact-us.
15
 
**
16
 
** GNU Lesser General Public License Usage
17
 
** Alternatively, this file may be used under the terms of the GNU Lesser
18
 
** General Public License version 2.1 as published by the Free Software
19
 
** Foundation and appearing in the file LICENSE.LGPL included in the
20
 
** packaging of this file.  Please review the following information to
21
 
** ensure the GNU Lesser General Public License version 2.1 requirements
22
 
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
 
**
24
 
** In addition, as a special exception, Digia gives you certain additional
25
 
** rights.  These rights are described in the Digia Qt LGPL Exception
26
 
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
 
**
28
 
****************************************************************************/
29
 
 
30
 
#include "qtquickappwizard.h"
31
 
 
32
 
#include "qtquickapp.h"
33
 
#include "qtquickappwizardpages.h"
34
 
#include "../qmakeprojectmanagerconstants.h"
35
 
 
36
 
#include <qtsupport/qtsupportconstants.h>
37
 
#include <qtsupport/baseqtversion.h>
38
 
#include <projectexplorer/projectexplorerconstants.h>
39
 
#include <projectexplorer/targetsetuppage.h>
40
 
 
41
 
#include <QIcon>
42
 
#include <QDebug>
43
 
 
44
 
namespace QmakeProjectManager {
45
 
namespace Internal {
46
 
 
47
 
class QtQuickAppWizardDialog : public AbstractMobileAppWizardDialog
48
 
{
49
 
    Q_OBJECT
50
 
 
51
 
public:
52
 
    explicit QtQuickAppWizardDialog(QWidget *parent, const Core::WizardDialogParameters &parameters,
53
 
                                    QtQuickAppWizard::Kind kind);
54
 
 
55
 
protected:
56
 
    bool validateCurrentPage();
57
 
 
58
 
private:
59
 
    QtQuickComponentSetOptionsPage *m_componentOptionsPage;
60
 
    int m_componentOptionsPageId;
61
 
 
62
 
    Utils::WizardProgressItem *m_componentItem;
63
 
 
64
 
    friend class QtQuickAppWizard;
65
 
};
66
 
 
67
 
QtQuickAppWizardDialog::QtQuickAppWizardDialog(QWidget *parent,
68
 
                                               const Core::WizardDialogParameters &parameters,
69
 
                                               QtQuickAppWizard::Kind kind)
70
 
    : AbstractMobileAppWizardDialog(parent,
71
 
                                    QtSupport::QtVersionNumber(4, 7, 0),
72
 
                                    QtSupport::QtVersionNumber(5, INT_MAX, INT_MAX), parameters)
73
 
{
74
 
    setWindowTitle(tr("New Qt Quick Application"));
75
 
    setIntroDescription(tr("This wizard generates a Qt Quick application project."));
76
 
 
77
 
    if (kind == QtQuickAppWizard::ImportQml || kind == QtQuickAppWizard::ImportQml2) { //Choose existing qml file
78
 
        m_componentOptionsPage = new Internal::QtQuickComponentSetOptionsPage;
79
 
        m_componentOptionsPageId = addPageWithTitle(m_componentOptionsPage, tr("Select existing QML file"));
80
 
        m_componentItem = wizardProgress()->item(m_componentOptionsPageId);
81
 
    }
82
 
 
83
 
    AbstractMobileAppWizardDialog::addMobilePages();
84
 
 
85
 
    if (kind == QtQuickAppWizard::ImportQml || kind == QtQuickAppWizard::ImportQml2) {
86
 
        if (targetsPageItem())
87
 
            m_componentItem->setNextItems(QList<Utils::WizardProgressItem *>()
88
 
                                          << targetsPageItem());
89
 
    }
90
 
}
91
 
 
92
 
bool QtQuickAppWizardDialog::validateCurrentPage()
93
 
{
94
 
    if (currentPage() == m_componentOptionsPage)
95
 
        setIgnoreGenericOptionsPage(false);
96
 
    return AbstractMobileAppWizardDialog::validateCurrentPage();
97
 
}
98
 
 
99
 
class QtQuickAppWizardPrivate
100
 
{
101
 
    class QtQuickApp *app;
102
 
    class QtQuickAppWizardDialog *wizardDialog;
103
 
    QtQuickAppWizard::Kind kind;
104
 
    friend class QtQuickAppWizard;
105
 
};
106
 
 
107
 
QtQuickAppWizard::QtQuickAppWizard()
108
 
    : d(new QtQuickAppWizardPrivate)
109
 
{
110
 
    setWizardKind(ProjectWizard);
111
 
    setIcon(QIcon(QLatin1String(QmakeProjectManager::Constants::ICON_QTQUICK_APP)));
112
 
    setId(QLatin1String("D.QMLA Application"));
113
 
    setCategory(QLatin1String(ProjectExplorer::Constants::QT_APPLICATION_WIZARD_CATEGORY));
114
 
    setDisplayCategory(QLatin1String(ProjectExplorer::Constants::QT_APPLICATION_WIZARD_CATEGORY_DISPLAY));
115
 
 
116
 
    d->app = new QtQuickApp;
117
 
    d->wizardDialog = 0;
118
 
}
119
 
 
120
 
QtQuickAppWizard::~QtQuickAppWizard()
121
 
{
122
 
    delete d->app;
123
 
    delete d;
124
 
}
125
 
 
126
 
void QtQuickAppWizard::createInstances(ExtensionSystem::IPlugin *plugin)
127
 
{
128
 
    const QString basicDescription = tr("Creates a Qt Quick 1 application project that can contain "
129
 
                                        "both QML and C++ code and includes a QDeclarativeView.\n\n");
130
 
    const QString basicDescription2 = tr("Creates a Qt Quick 2 application project that can contain "
131
 
                                        "both QML and C++ code and includes a QQuickView.\n\n");
132
 
 
133
 
    Core::FeatureSet basicFeatures = Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_1);
134
 
 
135
 
    QtQuickAppWizard *wizard = new QtQuickAppWizard;
136
 
    wizard->setQtQuickKind(QtQuick1_1);
137
 
    wizard->setDisplayName(tr("Qt Quick 1 Application (Built-in Types)"));
138
 
    wizard->setDescription(basicDescription + tr("The built-in QML types in the QtQuick 1 namespace allow "
139
 
                                                   "you to write cross-platform applications with "
140
 
                                                   "a custom look and feel.\n\nRequires <b>Qt 4.8.0</b> or newer."));
141
 
    wizard->setRequiredFeatures(basicFeatures);
142
 
    plugin->addAutoReleasedObject(wizard);
143
 
 
144
 
 
145
 
    wizard = new QtQuickAppWizard;
146
 
    wizard->setQtQuickKind(QtQuick2_0);
147
 
    wizard->setDisplayName(tr("Qt Quick 2 Application (Built-in Types)"));
148
 
    wizard->setDescription(basicDescription2 + tr("The built-in QML types in the QtQuick 2 namespace allow "
149
 
                                                    "you to write cross-platform applications with "
150
 
                                                    "a custom look and feel.\n\nRequires <b>Qt 5.0</b> or newer."));
151
 
    wizard->setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_2));
152
 
    plugin->addAutoReleasedObject(wizard);
153
 
 
154
 
 
155
 
    wizard = new QtQuickAppWizard;
156
 
    wizard->setQtQuickKind(ImportQml);
157
 
    wizard->setDisplayName(tr("Qt Quick 1 Application (from Existing QML File)"));
158
 
    wizard->setDescription(basicDescription +  tr("Creates a deployable Qt Quick application from "
159
 
                                                    "existing QML files. All files and directories that "
160
 
                                                    "reside in the same directory as the main .qml file "
161
 
                                                    "are deployed. You can modify the contents of the "
162
 
                                                    "directory any time before deploying.\n\nRequires <b>Qt 4.8.0</b> or newer."));
163
 
    wizard->setRequiredFeatures(basicFeatures);
164
 
    plugin->addAutoReleasedObject(wizard);
165
 
 
166
 
 
167
 
    wizard = new QtQuickAppWizard;
168
 
    wizard->setQtQuickKind(ImportQml2);
169
 
    wizard->setDisplayName(tr("Qt Quick 2 Application (from Existing QML File)"));
170
 
    wizard->setDescription(basicDescription2 + tr("Creates a deployable Qt Quick application from "
171
 
                                                    "existing QML files. All files and directories that "
172
 
                                                    "reside in the same directory as the main .qml file "
173
 
                                                    "are deployed. You can modify the contents of the "
174
 
                                                    "directory any time before deploying.\n\nRequires <b>Qt 5.0</b> or newer."));
175
 
 
176
 
    wizard->setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_2));
177
 
    plugin->addAutoReleasedObject(wizard);
178
 
 
179
 
    wizard = new QtQuickAppWizard;
180
 
    wizard->setQtQuickKind(QtQuick_Controls_1_0);
181
 
 
182
 
    wizard->setDisplayName(tr("Qt Quick 2 Application (Qt Quick Controls)"));
183
 
    wizard->setDescription(basicDescription +  tr("Creates a deployable Qt Quick application using "
184
 
                                                  "Qt Quick Controls. All files and directories that "
185
 
                                                  "reside in the same directory as the main .qml file "
186
 
                                                  "are deployed. You can modify the contents of the "
187
 
                                                  "directory any time before deploying.\n\nRequires <b>Qt 5.1.0</b> or newer."));
188
 
    wizard->setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_2)
189
 
                                | Core::Feature(QtSupport::Constants::FEATURE_QT_QUICK_CONTROLS));
190
 
    plugin->addAutoReleasedObject(wizard);
191
 
}
192
 
 
193
 
AbstractMobileAppWizardDialog *QtQuickAppWizard::createWizardDialogInternal(QWidget *parent,
194
 
                                                                            const Core::WizardDialogParameters &parameters) const
195
 
{
196
 
    d->wizardDialog = new QtQuickAppWizardDialog(parent, parameters, qtQuickKind());
197
 
 
198
 
    switch (qtQuickKind()) {
199
 
    case QtQuick1_1:
200
 
        d->app->setComponentSet(QtQuickApp::QtQuick10Components);
201
 
        d->app->setMainQml(QtQuickApp::ModeGenerate);
202
 
        break;
203
 
    case ImportQml:
204
 
        d->app->setComponentSet(QtQuickApp::QtQuick10Components);
205
 
        d->app->setMainQml(QtQuickApp::ModeImport);
206
 
        break;
207
 
    case ImportQml2:
208
 
        d->app->setComponentSet(QtQuickApp::QtQuick20Components);
209
 
        d->app->setMainQml(QtQuickApp::ModeImport);
210
 
        break;
211
 
    case QtQuick2_0:
212
 
        d->app->setComponentSet(QtQuickApp::QtQuick20Components);
213
 
        d->app->setMainQml(QtQuickApp::ModeGenerate);
214
 
        break;
215
 
    case QtQuick_Controls_1_0:
216
 
        d->app->setComponentSet(QtQuickApp::QtQuickControls10);
217
 
        d->app->setMainQml(QtQuickApp::ModeGenerate);
218
 
        break;
219
 
    default:
220
 
        qWarning() << "QtQuickAppWizard illegal subOption:" << qtQuickKind();
221
 
        break;
222
 
    }
223
 
 
224
 
    return d->wizardDialog;
225
 
}
226
 
 
227
 
void QtQuickAppWizard::projectPathChanged(const QString &path) const
228
 
{
229
 
    if (d->wizardDialog->targetsPage())
230
 
        d->wizardDialog->targetsPage()->setProjectPath(path);
231
 
}
232
 
 
233
 
void QtQuickAppWizard::prepareGenerateFiles(const QWizard *w,
234
 
    QString *errorMessage) const
235
 
{
236
 
    Q_UNUSED(errorMessage)
237
 
    const QtQuickAppWizardDialog *wizard = qobject_cast<const QtQuickAppWizardDialog*>(w);
238
 
 
239
 
    if (d->app->mainQmlMode() == QtQuickApp::ModeGenerate) {
240
 
        d->app->setMainQml(QtQuickApp::ModeGenerate);
241
 
    } else {
242
 
        const QString mainQmlFile = wizard->m_componentOptionsPage->mainQmlFile();
243
 
        d->app->setMainQml(QtQuickApp::ModeImport, mainQmlFile);
244
 
    }
245
 
}
246
 
 
247
 
void QtQuickAppWizard::setQtQuickKind(QtQuickAppWizard::Kind kind)
248
 
{
249
 
    d->kind = kind;
250
 
}
251
 
 
252
 
QtQuickAppWizard::Kind QtQuickAppWizard::qtQuickKind() const
253
 
{
254
 
    return d->kind;
255
 
}
256
 
 
257
 
QString QtQuickAppWizard::fileToOpenPostGeneration() const
258
 
{
259
 
    return d->app->path(QtQuickApp::MainQml);
260
 
}
261
 
 
262
 
AbstractMobileApp *QtQuickAppWizard::app() const
263
 
{
264
 
    return d->app;
265
 
}
266
 
 
267
 
AbstractMobileAppWizardDialog *QtQuickAppWizard::wizardDialog() const
268
 
{
269
 
    return d->wizardDialog;
270
 
}
271
 
 
272
 
} // namespace Internal
273
 
} // namespace QmakeProjectManager
274
 
 
275
 
#include "qtquickappwizard.moc"