OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / customwizard / customwizardparameters.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef CUSTOMPROJECTWIZARDPARAMETERS_H
34 #define CUSTOMPROJECTWIZARDPARAMETERS_H
35
36 #include <coreplugin/basefilewizard.h>
37
38 #include <QtCore/QStringList>
39 #include <QtCore/QMap>
40 #include <QtCore/QSharedPointer>
41
42 QT_BEGIN_NAMESPACE
43 class QIODevice;
44 class QDebug;
45 class QTemporaryFile;
46 class QScriptEngine;
47 QT_END_NAMESPACE
48
49 namespace ProjectExplorer {
50 namespace Internal {
51
52 struct CustomWizardField {
53     // Parameters of the widget control are stored as map
54     typedef QMap<QString, QString> ControlAttributeMap;
55     CustomWizardField();
56     void clear();
57
58     // Attribute map keys for combo entries
59     static QString comboEntryValueKey(int i);
60     static QString comboEntryTextKey(int i);
61
62     QString description;
63     QString name;
64     ControlAttributeMap controlAttributes;
65     bool mandatory;
66 };
67
68 struct CustomWizardFile {
69     CustomWizardFile();
70
71     QString source;
72     QString target;
73     bool openEditor;
74     bool openProject;
75     bool binary;
76 };
77
78 // A validation rule based on Javascript-expressions over the field placeholders.
79 // Placeholder replacement is performed on the condition and it is evaluated
80 // using Javascript. So, for example '"%ProjectName%" != "untitled" would block
81 // default names. On failure, the message is displayed in a red warning label
82 // in the wizard page. Placeholder replacement is also performed on the message
83 // prior to displaying.
84 struct CustomWizardValidationRule {
85     // Validate a set of rules and return false + message on the first failing one.
86     static bool validateRules(const QList<CustomWizardValidationRule> &rules,
87                               const QMap<QString, QString> &replacementMap,
88                               QString *errorMessage);
89     bool validate(QScriptEngine &, const QMap<QString, QString> &replacementMap) const;
90     QString condition;
91     QString message;
92 };
93
94 // Argument to the generator script containing placeholders to
95 // be replaced by field values or file names
96 // as in '--class-name=%ClassName%' or '--description=%Description%'.
97 struct GeneratorScriptArgument {
98     enum Flags {
99         // Omit this arguments if all field placeholders expanded to empty strings.
100         OmitEmpty = 0x1,
101         // Do use the actual field value, but write it to a temporary
102         // text file and inserts its file name (suitable for multiline texts).
103         WriteFile = 0x2 };
104
105     explicit GeneratorScriptArgument(const QString &value = QString());
106
107     QString value;
108     unsigned flags;
109 };
110
111 struct CustomWizardParameters
112 {
113 public:
114     enum ParseResult { ParseOk, ParseDisabled, ParseFailed };
115
116     CustomWizardParameters();
117     void clear();
118     ParseResult parse(QIODevice &device, const QString &configFileFullPath,
119                       Core::BaseFileWizardParameters *bp, QString *errorMessage);
120     ParseResult parse(const QString &configFileFullPath,
121                       Core::BaseFileWizardParameters *bp, QString *errorMessage);
122     QString toString() const;
123
124     QString directory;
125     QString klass;
126     QList<CustomWizardFile> files;
127     QStringList filesGeneratorScript; // Complete binary, such as 'cmd /c myscript.pl'.
128     QString filesGeneratorScriptWorkingDirectory;
129     QList<GeneratorScriptArgument> filesGeneratorScriptArguments;
130
131     QString fieldPageTitle;
132     QList<CustomWizardField> fields;
133     QList<CustomWizardValidationRule> rules;
134     int firstPageId;
135 };
136
137 // Context used for one wizard run, shared between CustomWizard
138 // and the CustomWizardPage as it is used for the QLineEdit-type fields'
139 // default texts as well. Contains basic replacement fields
140 // like  '%CppSourceSuffix%', '%CppHeaderSuffix%' (settings-dependent)
141 // reset() should be called before each wizard run to refresh them.
142 // CustomProjectWizard additionally inserts '%ProjectName%' from
143 // the intro page to have it available for default texts.
144
145 struct CustomWizardContext {
146     typedef QMap<QString, QString> FieldReplacementMap;
147     typedef QSharedPointer<QTemporaryFile> TemporaryFilePtr;
148     typedef QList<TemporaryFilePtr> TemporaryFilePtrList;
149
150     void reset();
151
152     // Replace field values delimited by '%' with special modifiers:
153     // %Field% -> simple replacement
154     // %Field:l% -> replace with everything changed to lower case
155     // %Field:u% -> replace with everything changed to upper case
156     // %Field:c% -> replace with first character capitalized
157     // %Field:h% -> replace with something usable as header guard
158     // %Field:s% -> replace with something usable as structure or class name
159     // The return value indicates whether non-empty
160     // replacements were encountered.
161     static bool replaceFields(const FieldReplacementMap &fm, QString *s);
162
163     // Special replaceFields() overload used for the arguments of a generator
164     // script: Write the expanded field values out to temporary files and
165     // inserts file names instead of the expanded fields in string 's'.
166     static bool replaceFields(const FieldReplacementMap &fm, QString *s,
167                               TemporaryFilePtrList *files);
168
169     static QString processFile(const FieldReplacementMap &fm, QString in);
170
171     FieldReplacementMap baseReplacements;
172     FieldReplacementMap replacements;
173
174     QString path;
175     // Where files should be created, that is, 'path' for simple wizards
176     // or "path + project" for project wizards.
177     QString targetPath;
178 };
179
180 extern const char customWizardFileOpenEditorAttributeC[];
181 extern const char customWizardFileOpenProjectAttributeC[];
182
183 } // namespace Internal
184 } // namespace ProjectExplorer
185
186 #endif // CUSTOMPROJECTWIZARDPARAMETERS_H