basefilewizardfactory.h 4.69 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.
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
****************************************************************************/
hjk's avatar
hjk committed
30

31
32
#ifndef BASEFILEWIZARDFACTORY_H
#define BASEFILEWIZARDFACTORY_H
con's avatar
con committed
33
34

#include "core_global.h"
35
#include "generatedfile.h"
con's avatar
con committed
36

Tobias Hunger's avatar
Tobias Hunger committed
37
#include <coreplugin/iwizardfactory.h>
con's avatar
con committed
38

39
#include <QList>
40
#include <QVariantMap>
con's avatar
con committed
41
42

QT_BEGIN_NAMESPACE
43
class QIcon;
con's avatar
con committed
44
45
class QWizard;
class QWizardPage;
46
class QDebug;
con's avatar
con committed
47
48
QT_END_NAMESPACE

hjk's avatar
hjk committed
49
namespace Utils { class Wizard; }
50

con's avatar
con committed
51
52
namespace Core {

Tobias Hunger's avatar
Tobias Hunger committed
53
class BaseFileWizard;
54

55
56
57
58
59
class CORE_EXPORT WizardDialogParameters
{
public:
    typedef QList<QWizardPage *> WizardPageList;

60
61
62
63
64
    enum DialogParameterEnum {
        ForceCapitalLetterForFileName = 0x01
    };
    Q_DECLARE_FLAGS(DialogParameterFlags, DialogParameterEnum)

65
    explicit WizardDialogParameters(const QString &defaultPath, const WizardPageList &extensionPages,
Orgad Shaneh's avatar
Orgad Shaneh committed
66
                                    const QString &platform, const FeatureSet &requiredFeatures,
67
68
                                    DialogParameterFlags flags,
                                    QVariantMap extraValues)
69
70
71
        : m_defaultPath(defaultPath),
          m_extensionPages(extensionPages),
          m_selectedPlatform(platform),
72
          m_requiredFeatures(requiredFeatures),
73
74
75
          m_parameterFlags(flags),
          m_extraValues(extraValues)
    {}
76
77
78
79
80
81
82
83
84
85

    QString defaultPath() const
    { return m_defaultPath; }

    WizardPageList extensionPages() const
    { return m_extensionPages; }

    QString selectedPlatform() const
    { return m_selectedPlatform; }

Orgad Shaneh's avatar
Orgad Shaneh committed
86
    FeatureSet requiredFeatures() const
87
88
    { return m_requiredFeatures; }

89
90
91
    DialogParameterFlags flags() const
    { return m_parameterFlags; }

92
93
94
    QVariantMap extraValues() const
    { return m_extraValues; }

95
96
97
98
private:
    QString m_defaultPath;
    WizardPageList m_extensionPages;
    QString m_selectedPlatform;
Orgad Shaneh's avatar
Orgad Shaneh committed
99
    FeatureSet m_requiredFeatures;
100
    DialogParameterFlags m_parameterFlags;
101
    QVariantMap m_extraValues;
102
103
};

104
class CORE_EXPORT BaseFileWizardFactory : public IWizardFactory
con's avatar
con committed
105
106
107
108
109
{
    Q_OBJECT

public:
    static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
110

con's avatar
con committed
111
112
protected:
    typedef QList<QWizardPage *> WizardPageList;
113

Tobias Hunger's avatar
Tobias Hunger committed
114
    virtual BaseFileWizard *create(QWidget *parent, const WizardDialogParameters &parameters) const = 0;
115

con's avatar
con committed
116
117
118
    virtual GeneratedFiles generateFiles(const QWizard *w,
                                         QString *errorMessage) const = 0;

119
120
    virtual bool writeFiles(const GeneratedFiles &files, QString *errorMessage);

121
    virtual bool postGenerateFiles(const QWizard *w, const GeneratedFiles &l, QString *errorMessage);
con's avatar
con committed
122

123
    static QString preferredSuffix(const QString &mimeType);
con's avatar
con committed
124
125

    enum OverwriteResult { OverwriteOk,  OverwriteError,  OverwriteCanceled };
126
    OverwriteResult promptOverwrite(GeneratedFiles *files,
con's avatar
con committed
127
                                    QString *errorMessage) const;
128
    static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = 0);
129
130
131

private:
    // IWizard
132
133
    Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
                                 const QVariantMap &extraValues) override;
con's avatar
con committed
134
135
136
137
};

} // namespace Core

138
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::GeneratedFile::Attributes)
139
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::WizardDialogParameters::DialogParameterFlags)
140

141
#endif // BASEFILEWIZARDFACTORY_H