customwizard.h 5.29 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
** 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
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30

31
32
#ifndef CUSTOMWIZARD_H
#define CUSTOMWIZARD_H
33
34
35

#include "../projectexplorer_export.h"

36
#include <coreplugin/basefilewizardfactory.h>
37

38
39
40
#include <QSharedPointer>
#include <QList>
#include <QMap>
41
42
43
44
45

QT_BEGIN_NAMESPACE
class QDir;
QT_END_NAMESPACE

46
namespace Utils { class Wizard; }
47

48
49
50
51
52
namespace ProjectExplorer {
class CustomWizard;
class BaseProjectWizardDialog;

namespace Internal {
Tobias Hunger's avatar
Tobias Hunger committed
53
54
55
class CustomWizardPrivate;
class CustomWizardContext;
class CustomWizardParameters;
56
57
}

58
// Documentation inside.
59
class PROJECTEXPLORER_EXPORT ICustomWizardMetaFactory : public QObject
hjk's avatar
hjk committed
60
{
61
62
    Q_OBJECT

63
public:
64
    ICustomWizardMetaFactory(const QString &klass, Core::IWizardFactory::WizardKind kind) :
65
66
67
68
69
70
71
72
73
        m_klass(klass), m_kind(kind)
    { }

    virtual CustomWizard *create() const = 0;
    QString klass() const { return m_klass; }
    int kind() const { return m_kind; }

private:
    QString m_klass;
Tobias Hunger's avatar
Tobias Hunger committed
74
    Core::IWizardFactory::WizardKind m_kind;
75
76
};

77
// Convenience template to create wizard factory classes.
78
template <class Wizard> class CustomWizardMetaFactory : public ICustomWizardMetaFactory
hjk's avatar
hjk committed
79
{
80
public:
81
82
    CustomWizardMetaFactory(const QString &klass, Core::IWizardFactory::WizardKind kind) : ICustomWizardMetaFactory(klass, kind) { }
    CustomWizardMetaFactory(Core::IWizardFactory::WizardKind kind) : ICustomWizardMetaFactory(QString(), kind) { }
83
    CustomWizard *create() const { return new Wizard; }
84
85
};

86
// Documentation inside.
87
class PROJECTEXPLORER_EXPORT CustomWizard : public Core::BaseFileWizardFactory
88
89
{
    Q_OBJECT
hjk's avatar
hjk committed
90

91
92
93
public:
    typedef QMap<QString, QString> FieldReplacementMap;

hjk's avatar
hjk committed
94
    CustomWizard();
95
    ~CustomWizard();
96
97
98

    // Can be reimplemented to create custom wizards. initWizardDialog() needs to be
    // called.
Tobias Hunger's avatar
Tobias Hunger committed
99
    Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const;
100

101
    Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
102
103
104

    // Create all wizards. As other plugins might register factories for derived
    // classes, call it in extensionsInitialized().
105
    static QList<IWizardFactory *> createWizards();
106

107
108
109
    static void setVerbose(int);
    static int verbose();

110
111
protected:
    typedef QSharedPointer<Internal::CustomWizardParameters> CustomWizardParametersPtr;
112
    typedef QSharedPointer<Internal::CustomWizardContext> CustomWizardContextPtr;
113
114

    // generate files in path
115
    Core::GeneratedFiles generateWizardFiles(QString *errorMessage) const;
116
117
    // Create replacement map as static base fields + QWizard fields
    FieldReplacementMap replacementMap(const QWizard *w) const;
118
    bool writeFiles(const Core::GeneratedFiles &files, QString *errorMessage);
119
120

    CustomWizardParametersPtr parameters() const;
121
    CustomWizardContextPtr context() const;
122

Tobias Hunger's avatar
Tobias Hunger committed
123
    static CustomWizard *createWizard(const CustomWizardParametersPtr &p);
hjk's avatar
hjk committed
124

125
126
127
private:
    void setParameters(const CustomWizardParametersPtr &p);

Tobias Hunger's avatar
Tobias Hunger committed
128
    Internal::CustomWizardPrivate *d;
129
130
};

131
// Documentation inside.
132
133
134
class PROJECTEXPLORER_EXPORT CustomProjectWizard : public CustomWizard
{
    Q_OBJECT
hjk's avatar
hjk committed
135

136
public:
hjk's avatar
hjk committed
137
    CustomProjectWizard();
138

hjk's avatar
hjk committed
139
    static bool postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage = 0);
140

hjk's avatar
hjk committed
141
protected:
Tobias Hunger's avatar
Tobias Hunger committed
142
    Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const;
143

hjk's avatar
hjk committed
144
    Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
145

146
147
148
signals:
    void projectLocationChanged(const QString &path);

149
protected:
150
    bool postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage);
151
152
153

    void initProjectWizardDialog(BaseProjectWizardDialog *w, const QString &defaultPath,
                                 const WizardPageList &extensionPages) const;
154
155

private slots:
156
    void projectParametersChanged(const QString &project, const QString &path);
157
158
159
160
};

} // namespace ProjectExplorer

161
#endif // CUSTOMWIZARD_H