iwizardfactory.h 5.59 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
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
** 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.
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
****************************************************************************/
hjk's avatar
hjk committed
30

Tobias Hunger's avatar
Tobias Hunger committed
31
32
#ifndef IWIZARDFACTORY_H
#define IWIZARDFACTORY_H
con's avatar
con committed
33
34

#include <coreplugin/core_global.h>
hjk's avatar
hjk committed
35
#include <coreplugin/featureprovider.h>
36

hjk's avatar
hjk committed
37
#include <QIcon>
38
#include <QObject>
39
#include <QString>
con's avatar
con committed
40

41
42
#include <functional>

43
44
QT_FORWARD_DECLARE_CLASS(QAction)

45
46
namespace Utils { class Wizard; }

con's avatar
con committed
47
48
namespace Core {

49
50
namespace Internal { class CorePlugin; }

Tobias Hunger's avatar
Tobias Hunger committed
51
class CORE_EXPORT IWizardFactory
con's avatar
con committed
52
53
54
55
    : public QObject
{
    Q_OBJECT
public:
56
57
    enum WizardKind {
        FileWizard = 0x01,
58
        ProjectWizard = 0x02
con's avatar
con committed
59
    };
60
    enum WizardFlag {
61
62
        PlatformIndependent = 0x01,
        ForceCapitalLetterForFileName = 0x02
63
64
    };
    Q_DECLARE_FLAGS(WizardFlags, WizardFlag)
con's avatar
con committed
65

66
    Id id() const { return m_id; }
Tobias Hunger's avatar
Tobias Hunger committed
67
68
69
70
71
72
73
    WizardKind kind() const { return m_kind; }
    QIcon icon() const { return m_icon; }
    QString description() const { return m_description; }
    QString displayName() const { return m_displayName; }
    QString category() const { return m_category; }
    QString displayCategory() const { return m_displayCategory; }
    QString descriptionImage() const { return m_descriptionImage; }
74
    QSet<Id> requiredFeatures() const { return m_requiredFeatures; }
Tobias Hunger's avatar
Tobias Hunger committed
75
76
    WizardFlags flags() const { return m_flags; }

77
    void setId(const Id id) { m_id = id; }
Tobias Hunger's avatar
Tobias Hunger committed
78
79
80
81
82
83
84
    void setWizardKind(WizardKind kind) { m_kind = kind; }
    void setIcon(const QIcon &icon) { m_icon = icon; }
    void setDescription(const QString &description) { m_description = description; }
    void setDisplayName(const QString &displayName) { m_displayName = displayName; }
    void setCategory(const QString &category) { m_category = category; }
    void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
    void setDescriptionImage(const QString &descriptionImage) { m_descriptionImage = descriptionImage; }
85
86
    void setRequiredFeatures(const QSet<Id> &featureSet) { m_requiredFeatures = featureSet; }
    void addRequiredFeature(const Id &feature) { m_requiredFeatures |= feature; }
Tobias Hunger's avatar
Tobias Hunger committed
87
    void setFlags(WizardFlags flags) { m_flags = flags; }
88

89
90
    QString runPath(const QString &defaultPath);

91
    // Does bookkeeping and the calls runWizardImpl. Please implement that.
92
93
    virtual Utils::Wizard *runWizard(const QString &path, QWidget *parent, const QString &platform,
                                     const QVariantMap &variables);
94

95
    virtual bool isAvailable(const QString &platformName) const;
96
    QStringList supportedPlatforms() const;
97

98
99
100
    typedef std::function<QList<IWizardFactory *>()> FactoryCreator;
    static void registerFactoryCreator(const FactoryCreator &creator);

101
    // Utility to find all registered wizards
Tobias Hunger's avatar
Tobias Hunger committed
102
    static QList<IWizardFactory*> allWizardFactories();
103
    // Utility to find all registered wizards of a certain kind
Tobias Hunger's avatar
Tobias Hunger committed
104
    static QList<IWizardFactory*> wizardFactoriesOfKind(WizardKind kind);
105
106
    static QStringList allAvailablePlatforms();
    static QString displayNameForPlatform(const QString &string);
hjk's avatar
hjk committed
107

108
109
    static void registerFeatureProvider(IFeatureProvider *provider);

110
111
    static bool isWizardRunning();

112
113
114
115
116
    static void requestNewItemDialog(const QString &title,
                                     const QList<IWizardFactory *> &factories,
                                     const QString &defaultLocation,
                                     const QVariantMap &extraVariables);

117
protected:
118
119
    QSet<Id> pluginFeatures() const;
    QSet<Id> availableFeatures(const QString &platformName) const;
120

121
122
    virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
                                         const QVariantMap &variables) = 0;
123

hjk's avatar
hjk committed
124
private:
125
    static void initialize();
126
127
    static void destroyFeatureProvider();

128
129
130
    static void clearWizardFactories();

    QAction *m_action = 0;
Tobias Hunger's avatar
Tobias Hunger committed
131
132
133
134
135
136
    QIcon m_icon;
    QString m_description;
    QString m_displayName;
    QString m_category;
    QString m_displayCategory;
    QString m_descriptionImage;
137
    Id m_id;
138
    QSet<Id> m_requiredFeatures;
139
    WizardKind m_kind = FileWizard;
140
    WizardFlags m_flags = 0;
141
142

    friend class Internal::CorePlugin;
con's avatar
con committed
143
};
hjk's avatar
hjk committed
144

con's avatar
con committed
145
146
} // namespace Core

Tobias Hunger's avatar
Tobias Hunger committed
147
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IWizardFactory::WizardFlags)
148

Tobias Hunger's avatar
Tobias Hunger committed
149
#endif // IWIZARDFACTORY_H