145
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the examples of the Qt Toolkit.
|
|
7 **
|
|
8 ** $QT_BEGIN_LICENSE:LGPL$
|
|
9 ** Commercial Usage
|
|
10 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
11 ** accordance with the Qt Commercial License Agreement provided with the
|
|
12 ** Software or, alternatively, in accordance with the terms contained in
|
|
13 ** a written agreement between you and Nokia.
|
|
14 **
|
|
15 ** GNU Lesser General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
17 ** General Public License version 2.1 as published by the Free Software
|
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
19 ** packaging of this file. Please review the following information to
|
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
22 **
|
|
23 ** In addition, as a special exception, Nokia gives you certain
|
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL
|
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|
26 ** package.
|
|
27 **
|
|
28 ** GNU General Public License Usage
|
|
29 ** Alternatively, this file may be used under the terms of the GNU
|
|
30 ** General Public License version 3.0 as published by the Free Software
|
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the
|
|
32 ** packaging of this file. Please review the following information to
|
|
33 ** ensure the GNU General Public License version 3.0 requirements will be
|
|
34 ** met: http://www.gnu.org/copyleft/gpl.html.
|
|
35 **
|
|
36 ** If you are unsure which license is appropriate for your use, please
|
|
37 ** contact the sales department at qt-sales@nokia.com.
|
|
38 ** $QT_END_LICENSE$
|
|
39 **
|
|
40 ****************************************************************************/
|
|
41 module classwizard;
|
|
42
|
|
43
|
|
44 import qt.gui.QWizardPage;
|
|
45 import qt.gui.QCheckBox;
|
|
46 import qt.gui.QGroupBox;
|
|
47 import qt.gui.QLabel;
|
|
48 import qt.gui.QLineEdit;
|
|
49 import qt.gui.QRadioButton;
|
|
50 import qt.gui.QMessageBox;
|
|
51 import qt.gui.QVBoxLayout;
|
|
52 import qt.gui.QGridLayout;
|
|
53 import qt.core.QFile;
|
|
54 import qt.core.QDir;
|
|
55 import qt.core.QRegExp;
|
|
56
|
215
|
57 import std.string;
|
145
|
58
|
|
59
|
|
60 class ClassWizard : public QWizard
|
|
61 {
|
|
62 public:
|
|
63
|
|
64 this(QWidget parent = null)
|
|
65 {
|
|
66 super(parent);
|
|
67 addPage(new IntroPage);
|
|
68 addPage(new ClassInfoPage);
|
|
69 addPage(new CodeStylePage);
|
|
70 addPage(new OutputFilesPage);
|
|
71 addPage(new ConclusionPage);
|
|
72
|
|
73 setPixmap(QWizard.BannerPixmap, new QPixmap(":/images/banner.png"));
|
|
74 setPixmap(QWizard.BackgroundPixmap, new QPixmap(":/images/background.png"));
|
|
75
|
|
76 setWindowTitle(tr("Class Wizard"));
|
|
77 }
|
|
78
|
|
79 void accept()
|
|
80 {
|
|
81 string className = field("className").toString();
|
|
82 string baseClass = field("baseClass").toString();
|
|
83 string macroName = field("macroName").toString();
|
|
84 string baseInclude = field("baseInclude").toString();
|
|
85
|
|
86 string outputDir = field("outputDir").toString();
|
|
87 string header = field("header").toString();
|
|
88 string implementation = field("implementation").toString();
|
|
89
|
|
90 string block;
|
|
91
|
|
92 if (field("comment").toBool()) {
|
|
93 block ~= "/*\n";
|
|
94 block ~= " " ~ header ~ "\n";
|
|
95 block ~= "*/\n";
|
|
96 block ~= "\n";
|
|
97 }
|
|
98 if (field("protect").toBool()) {
|
|
99 block ~= "#ifndef " ~ macroName ~ "\n";
|
|
100 block ~= "#define " ~ macroName ~ "\n";
|
|
101 block ~= "\n";
|
|
102 }
|
|
103 if (field("includeBase").toBool()) {
|
|
104 block ~= "#include " ~ baseInclude ~ "\n";
|
|
105 block ~= "\n";
|
|
106 }
|
|
107
|
|
108 block ~= "class " ~ className;
|
|
109 if (baseClass.length)
|
|
110 block ~= " : public " ~ baseClass;
|
|
111 block ~= "\n";
|
|
112 block ~= "{\n";
|
|
113
|
|
114 /* qmake ignore */
|
|
115
|
|
116 if (field("qobjectMacro").toBool()) {
|
|
117 block ~= " \n";
|
|
118 block ~= "\n";
|
|
119 }
|
|
120 block ~= "public:\n";
|
|
121
|
|
122 if (field("qobjectCtor").toBool()) {
|
|
123 block ~= " " ~ className ~ "(QObject *parent = 0);\n";
|
|
124 } else if (field("qwidgetCtor").toBool()) {
|
|
125 block ~= " " ~ className ~ "(QWidget *parent = 0);\n";
|
|
126 } else if (field("defaultCtor").toBool()) {
|
|
127 block ~= " " ~ className ~ "();\n";
|
|
128 if (field("copyCtor").toBool()) {
|
|
129 block ~= " " ~ className ~ "(const " ~ className ~ " &other);\n";
|
|
130 block ~= "\n";
|
|
131 block ~= " " ~ className ~ " &operator=" ~ "(const " ~ className ~ " &other);\n";
|
|
132 }
|
|
133 }
|
|
134 block ~= "};\n";
|
|
135
|
|
136 if (field("protect").toBool()) {
|
|
137 block ~= "\n";
|
|
138 block ~= "#endif\n";
|
|
139 }
|
|
140
|
|
141 auto headerFile = new QFile(outputDir ~ "/" ~ header);
|
|
142 if (!headerFile.open(QFile.WriteOnly | QFile.Text)) {
|
|
143 QMessageBox.warning(null, tr("Simple Wizard"),
|
215
|
144 format(tr("Cannot write file %s:\n%s"),
|
145
|
145 headerFile.fileName(),
|
|
146 headerFile.errorString()));
|
|
147 return;
|
|
148 }
|
180
|
149 headerFile.write(block);
|
145
|
150
|
|
151 block.length = 0;
|
|
152
|
|
153 if (field("comment").toBool()) {
|
|
154 block ~= "/*\n";
|
|
155 block ~= " " ~ implementation ~ "\n";
|
|
156 block ~= "*/\n";
|
|
157 block ~= "\n";
|
|
158 }
|
|
159 block ~= "#include \"" ~ header ~ "\"\n";
|
|
160 block ~= "\n";
|
|
161
|
|
162 if (field("qobjectCtor").toBool()) {
|
|
163 block ~= className ~ "." ~ className ~ "(QObject *parent)\n";
|
|
164 block ~= " : " ~ baseClass ~ "(parent)\n";
|
|
165 block ~= "{\n";
|
|
166 block ~= "}\n";
|
|
167 } else if (field("qwidgetCtor").toBool()) {
|
|
168 block ~= className ~ "." ~ className ~ "(QWidget *parent)\n";
|
|
169 block ~= " : " ~ baseClass ~ "(parent)\n";
|
|
170 block ~= "{\n";
|
|
171 block ~= "}\n";
|
|
172 } else if (field("defaultCtor").toBool()) {
|
|
173 block ~= className ~ "." ~ className ~ "()\n";
|
|
174 block ~= "{\n";
|
|
175 block ~= " // missing code\n";
|
|
176 block ~= "}\n";
|
|
177
|
|
178 if (field("copyCtor").toBool()) {
|
|
179 block ~= "\n";
|
|
180 block ~= className ~ "." ~ className ~ "(const " ~ className ~ " &other)\n";
|
|
181 block ~= "{\n";
|
|
182 block ~= " *this = other;\n";
|
|
183 block ~= "}\n";
|
|
184 block ~= "\n";
|
|
185 block ~= className ~ " &" ~ className ~ ".operator=(const " ~ className ~ " &other)\n";
|
|
186 block ~= "{\n";
|
|
187 if (baseClass.length)
|
|
188 block ~= " " ~ baseClass ~ ".operator=(other);\n";
|
|
189 block ~= " // missing code\n";
|
|
190 block ~= " return *this;\n";
|
|
191 block ~= "}\n";
|
|
192 }
|
|
193 }
|
|
194
|
|
195 auto implementationFile = new QFile(outputDir ~ "/" ~ implementation);
|
|
196 if (!implementationFile.open(QFile.WriteOnly | QFile.Text)) {
|
|
197 QMessageBox.warning(null, tr("Simple Wizard"),
|
215
|
198 format(tr("Cannot write file %s:\n%s"),
|
145
|
199 implementationFile.fileName(),
|
|
200 implementationFile.errorString()));
|
|
201 return;
|
|
202 }
|
180
|
203 implementationFile.write(block);
|
145
|
204
|
|
205 QDialog.accept();
|
|
206 }
|
|
207 }
|
|
208
|
|
209
|
|
210 class IntroPage : public QWizardPage
|
|
211 {
|
|
212 public:
|
|
213
|
|
214 this(QWidget parent = null)
|
|
215 {
|
|
216 super(parent);
|
|
217 setTitle(tr("Introduction"));
|
|
218 setPixmap(QWizard.WatermarkPixmap, new QPixmap(":/images/watermark1.png"));
|
|
219
|
|
220 label = new QLabel(tr("This wizard will generate a skeleton C++ class "
|
|
221 "definition, including a few functions. You simply "
|
|
222 "need to specify the class name and set a few "
|
|
223 "options to produce a header file and an "
|
|
224 "implementation file for your new C++ class."));
|
|
225 label.setWordWrap(true);
|
|
226
|
|
227 QVBoxLayout layout = new QVBoxLayout;
|
|
228 layout.addWidget(label);
|
|
229 setLayout(layout);
|
|
230 }
|
|
231
|
|
232 private:
|
|
233
|
|
234 QLabel label;
|
|
235 }
|
|
236
|
|
237 class ClassInfoPage : public QWizardPage
|
|
238 {
|
|
239 public:
|
|
240
|
|
241 this(QWidget parent = null)
|
|
242 {
|
|
243 super(parent);
|
|
244 setTitle(tr("Class Information"));
|
|
245 setSubTitle(tr("Specify basic information about the class for which you want to generate skeleton source code files."));
|
|
246 setPixmap(QWizard.LogoPixmap, new QPixmap(":/images/logo1.png"));
|
|
247
|
|
248 classNameLabel = new QLabel(tr("&Class name:"));
|
|
249 classNameLineEdit = new QLineEdit;
|
|
250 classNameLabel.setBuddy(classNameLineEdit);
|
|
251
|
|
252 baseClassLabel = new QLabel(tr("B&ase class:"));
|
|
253 baseClassLineEdit = new QLineEdit;
|
|
254 baseClassLabel.setBuddy(baseClassLineEdit);
|
|
255
|
|
256 qobjectMacroCheckBox = new QCheckBox(tr("Generate ¯o"));
|
|
257
|
|
258 groupBox = new QGroupBox(tr("C&onstructor"));
|
|
259
|
|
260 qobjectCtorRadioButton = new QRadioButton(tr("&QObject-style constructor"));
|
|
261 qwidgetCtorRadioButton = new QRadioButton(tr("Q&Widget-style constructor"));
|
|
262 defaultCtorRadioButton = new QRadioButton(tr("&Default constructor"));
|
|
263 copyCtorCheckBox = new QCheckBox(tr("&Generate copy constructor and operator="));
|
|
264
|
|
265 defaultCtorRadioButton.setChecked(true);
|
|
266 defaultCtorRadioButton.toggled.connect(©CtorCheckBox.setEnabled);
|
|
267
|
|
268 registerField("className*", classNameLineEdit);
|
|
269 registerField("baseClass", baseClassLineEdit);
|
|
270 registerField("qobjectMacro", qobjectMacroCheckBox);
|
|
271 registerField("qobjectCtor", qobjectCtorRadioButton);
|
|
272 registerField("qwidgetCtor", qwidgetCtorRadioButton);
|
|
273 registerField("defaultCtor", defaultCtorRadioButton);
|
|
274 registerField("copyCtor", copyCtorCheckBox);
|
|
275
|
|
276 QVBoxLayout groupBoxLayout = new QVBoxLayout;
|
|
277
|
|
278 groupBoxLayout.addWidget(qobjectCtorRadioButton);
|
|
279 groupBoxLayout.addWidget(qwidgetCtorRadioButton);
|
|
280 groupBoxLayout.addWidget(defaultCtorRadioButton);
|
|
281 groupBoxLayout.addWidget(copyCtorCheckBox);
|
|
282 groupBox.setLayout(groupBoxLayout);
|
|
283
|
|
284 QGridLayout layout = new QGridLayout;
|
|
285 layout.addWidget(classNameLabel, 0, 0);
|
|
286 layout.addWidget(classNameLineEdit, 0, 1);
|
|
287 layout.addWidget(baseClassLabel, 1, 0);
|
|
288 layout.addWidget(baseClassLineEdit, 1, 1);
|
|
289 layout.addWidget(qobjectMacroCheckBox, 2, 0, 1, 2);
|
|
290 layout.addWidget(groupBox, 3, 0, 1, 2);
|
|
291 setLayout(layout);
|
|
292 }
|
|
293
|
|
294 private:
|
|
295
|
|
296 QLabel classNameLabel;
|
|
297 QLabel baseClassLabel;
|
|
298 QLineEdit classNameLineEdit;
|
|
299 QLineEdit baseClassLineEdit;
|
|
300 QCheckBox qobjectMacroCheckBox;
|
|
301 QGroupBox groupBox;
|
|
302 QRadioButton qobjectCtorRadioButton;
|
|
303 QRadioButton qwidgetCtorRadioButton;
|
|
304 QRadioButton defaultCtorRadioButton;
|
|
305 QCheckBox copyCtorCheckBox;
|
|
306 }
|
|
307
|
|
308 class CodeStylePage : public QWizardPage
|
|
309 {
|
|
310 public:
|
|
311
|
|
312 this(QWidget parent = null)
|
|
313 {
|
|
314 super(parent);
|
|
315 setTitle(tr("Code Style Options"));
|
|
316 setSubTitle(tr("Choose the formatting of the generated code."));
|
|
317 setPixmap(QWizard.LogoPixmap, new QPixmap(":/images/logo2.png"));
|
|
318
|
|
319 commentCheckBox = new QCheckBox(tr("&Start generated files with a comment"));
|
|
320 commentCheckBox.setChecked(true);
|
|
321
|
|
322 protectCheckBox = new QCheckBox(tr("&Protect header file against multiple inclusions"));
|
|
323 protectCheckBox.setChecked(true);
|
|
324
|
|
325 macroNameLabel = new QLabel(tr("&Macro name:"));
|
|
326 macroNameLineEdit = new QLineEdit;
|
|
327 macroNameLabel.setBuddy(macroNameLineEdit);
|
|
328
|
|
329 includeBaseCheckBox = new QCheckBox(tr("&Include base class definition"));
|
|
330 baseIncludeLabel = new QLabel(tr("Base class include:"));
|
|
331 baseIncludeLineEdit = new QLineEdit;
|
|
332 baseIncludeLabel.setBuddy(baseIncludeLineEdit);
|
|
333
|
|
334 protectCheckBox.toggled.connect(¯oNameLabel.setEnabled);
|
|
335 protectCheckBox.toggled.connect(¯oNameLabel.setEnabled);
|
|
336 includeBaseCheckBox.toggled.connect(¯oNameLabel.setEnabled);
|
|
337 includeBaseCheckBox.toggled.connect(¯oNameLabel.setEnabled);
|
|
338
|
|
339 registerField("comment", commentCheckBox);
|
|
340 registerField("protect", protectCheckBox);
|
|
341 registerField("macroName", macroNameLineEdit);
|
|
342 registerField("includeBase", includeBaseCheckBox);
|
|
343 registerField("baseInclude", baseIncludeLineEdit);
|
|
344
|
|
345 QGridLayout layout = new QGridLayout;
|
|
346 layout.setColumnMinimumWidth(0, 20);
|
|
347 layout.addWidget(commentCheckBox, 0, 0, 1, 3);
|
|
348 layout.addWidget(protectCheckBox, 1, 0, 1, 3);
|
|
349 layout.addWidget(macroNameLabel, 2, 1);
|
|
350 layout.addWidget(macroNameLineEdit, 2, 2);
|
|
351 layout.addWidget(includeBaseCheckBox, 3, 0, 1, 3);
|
|
352 layout.addWidget(baseIncludeLabel, 4, 1);
|
|
353 layout.addWidget(baseIncludeLineEdit, 4, 2);
|
|
354
|
|
355 setLayout(layout);
|
|
356 }
|
|
357
|
|
358 protected:
|
|
359
|
|
360 void initializePage()
|
|
361 {
|
|
362 string className = field("className").toString();
|
211
|
363 macroNameLineEdit.setText(toupper(className) ~ "_H");
|
145
|
364
|
|
365 string baseClass = field("baseClass").toString();
|
|
366
|
|
367 includeBaseCheckBox.setChecked(baseClass.length != 0);
|
|
368 includeBaseCheckBox.setEnabled(baseClass.length != 0);
|
|
369 baseIncludeLabel.setEnabled(baseClass.length != 0);
|
|
370 baseIncludeLineEdit.setEnabled(baseClass.length != 0);
|
|
371
|
|
372 if (baseClass.length == 0) {
|
|
373 baseIncludeLineEdit.clear();
|
|
374 } else if ((new QRegExp("Q[A-Z].*")).exactMatch(baseClass)) {
|
|
375 baseIncludeLineEdit.setText("<" ~ baseClass ~ ">");
|
|
376 } else {
|
211
|
377 baseIncludeLineEdit.setText("\"" ~ tolower(baseClass) ~ ".h\"");
|
145
|
378 }
|
|
379 }
|
|
380
|
|
381 private:
|
|
382
|
|
383 QCheckBox commentCheckBox;
|
|
384 QCheckBox protectCheckBox;
|
|
385 QCheckBox includeBaseCheckBox;
|
|
386 QLabel macroNameLabel;
|
|
387 QLabel baseIncludeLabel;
|
|
388 QLineEdit macroNameLineEdit;
|
|
389 QLineEdit baseIncludeLineEdit;
|
|
390 }
|
|
391
|
|
392 class OutputFilesPage : public QWizardPage
|
|
393 {
|
|
394 public:
|
|
395
|
|
396 this(QWidget parent = null)
|
|
397 {
|
|
398 super(parent);
|
|
399 setTitle(tr("Output Files"));
|
|
400 setSubTitle(tr("Specify where you want the wizard to put the generated skeleton code."));
|
|
401 setPixmap(QWizard.LogoPixmap, new QPixmap(":/images/logo3.png"));
|
|
402
|
|
403 outputDirLabel = new QLabel(tr("&Output directory:"));
|
|
404 outputDirLineEdit = new QLineEdit;
|
|
405 outputDirLabel.setBuddy(outputDirLineEdit);
|
|
406
|
|
407 headerLabel = new QLabel(tr("&Header file name:"));
|
|
408 headerLineEdit = new QLineEdit;
|
|
409 headerLabel.setBuddy(headerLineEdit);
|
|
410
|
|
411 implementationLabel = new QLabel(tr("&Implementation file name:"));
|
|
412 implementationLineEdit = new QLineEdit;
|
|
413 implementationLabel.setBuddy(implementationLineEdit);
|
|
414
|
|
415 registerField("outputDir*", outputDirLineEdit);
|
|
416 registerField("header*", headerLineEdit);
|
|
417 registerField("implementation*", implementationLineEdit);
|
|
418
|
|
419 QGridLayout layout = new QGridLayout;
|
|
420 layout.addWidget(outputDirLabel, 0, 0);
|
|
421 layout.addWidget(outputDirLineEdit, 0, 1);
|
|
422 layout.addWidget(headerLabel, 1, 0);
|
|
423 layout.addWidget(headerLineEdit, 1, 1);
|
|
424 layout.addWidget(implementationLabel, 2, 0);
|
|
425 layout.addWidget(implementationLineEdit, 2, 1);
|
|
426 setLayout(layout);
|
|
427 }
|
|
428
|
|
429 protected:
|
|
430
|
|
431 void initializePage()
|
|
432 {
|
|
433 string className = field("className").toString();
|
211
|
434 headerLineEdit.setText(tolower(className) ~ ".h");
|
|
435 implementationLineEdit.setText(tolower(className) ~ ".cpp");
|
145
|
436 outputDirLineEdit.setText(QDir.convertSeparators(QDir.tempPath()));
|
|
437 }
|
|
438
|
|
439 private:
|
|
440
|
|
441 QLabel outputDirLabel;
|
|
442 QLabel headerLabel;
|
|
443 QLabel implementationLabel;
|
|
444 QLineEdit outputDirLineEdit;
|
|
445 QLineEdit headerLineEdit;
|
|
446 QLineEdit implementationLineEdit;
|
|
447 }
|
|
448
|
|
449 class ConclusionPage : public QWizardPage
|
|
450 {
|
|
451 public:
|
|
452
|
|
453 this(QWidget parent = null)
|
|
454 {
|
|
455 super(parent);
|
|
456 setTitle(tr("Conclusion"));
|
|
457 setPixmap(QWizard.WatermarkPixmap, new QPixmap(":/images/watermark2.png"));
|
|
458
|
|
459 label = new QLabel;
|
|
460 label.setWordWrap(true);
|
|
461
|
|
462 QVBoxLayout layout = new QVBoxLayout;
|
|
463 layout.addWidget(label);
|
|
464 setLayout(layout);
|
|
465 }
|
|
466
|
|
467 protected:
|
|
468
|
|
469 void initializePage()
|
|
470 {
|
211
|
471 string finishText = wizard().buttonText(QWizard.FinishButton);
|
215
|
472 // TODO: port to D2: auto pos = remove(finishText, '&');
|
|
473 label.setText(format(tr("Click %s to generate the class skeleton."), finishText));
|
145
|
474 }
|
|
475
|
|
476 private:
|
|
477
|
|
478 QLabel label;
|
|
479 }
|