Mercurial > projects > qtd
comparison examples/dialogs/classwizard/classwizard.d @ 211:7ea67ec3cf29
another fixes in examples
author | SokoL_SD |
---|---|
date | Tue, 14 Jul 2009 12:50:04 +0000 |
parents | 39921f499a22 |
children | 8aaa84d48451 |
comparison
equal
deleted
inserted
replaced
210:3ea0efe4d31e | 211:7ea67ec3cf29 |
---|---|
52 import qt.gui.QGridLayout; | 52 import qt.gui.QGridLayout; |
53 import qt.core.QFile; | 53 import qt.core.QFile; |
54 import qt.core.QDir; | 54 import qt.core.QDir; |
55 import qt.core.QRegExp; | 55 import qt.core.QRegExp; |
56 | 56 |
57 import tango.text.convert.Format; | 57 version(Tango) |
58 import tango.core.Array; | 58 { |
59 import tango.text.Ascii; | 59 import tango.text.convert.Format: Format = format; |
60 import tango.core.Array; | |
61 import tango.text.Ascii; | |
62 alias toUpper toupper; | |
63 alias toLower tolower; | |
64 | |
65 const string cannot_write_file_str = tr("Cannot write file {}:\n{}"); | |
66 } | |
67 else { | |
68 import std.string; | |
69 import std.algorithm; | |
70 const string cannot_write_file_str = tr("Cannot write file %s:\n%s"); | |
71 } | |
60 | 72 |
61 | 73 |
62 class ClassWizard : public QWizard | 74 class ClassWizard : public QWizard |
63 { | 75 { |
64 public: | 76 public: |
78 setWindowTitle(tr("Class Wizard")); | 90 setWindowTitle(tr("Class Wizard")); |
79 } | 91 } |
80 | 92 |
81 void accept() | 93 void accept() |
82 { | 94 { |
95 version(Tango) | |
96 const string cannot_write_file_str = tr("Cannot write file {}:\n{}"); | |
97 else | |
98 const string cannot_write_file_str = tr("Cannot write file %s:\n%s"); | |
99 | |
100 | |
83 string className = field("className").toString(); | 101 string className = field("className").toString(); |
84 string baseClass = field("baseClass").toString(); | 102 string baseClass = field("baseClass").toString(); |
85 string macroName = field("macroName").toString(); | 103 string macroName = field("macroName").toString(); |
86 string baseInclude = field("baseInclude").toString(); | 104 string baseInclude = field("baseInclude").toString(); |
87 | 105 |
141 } | 159 } |
142 | 160 |
143 auto headerFile = new QFile(outputDir ~ "/" ~ header); | 161 auto headerFile = new QFile(outputDir ~ "/" ~ header); |
144 if (!headerFile.open(QFile.WriteOnly | QFile.Text)) { | 162 if (!headerFile.open(QFile.WriteOnly | QFile.Text)) { |
145 QMessageBox.warning(null, tr("Simple Wizard"), | 163 QMessageBox.warning(null, tr("Simple Wizard"), |
146 Format("Cannot write file {}:\n{}", | 164 format(cannot_write_file_str, |
147 headerFile.fileName(), | 165 headerFile.fileName(), |
148 headerFile.errorString())); | 166 headerFile.errorString())); |
149 return; | 167 return; |
150 } | 168 } |
151 headerFile.write(block); | 169 headerFile.write(block); |
195 } | 213 } |
196 | 214 |
197 auto implementationFile = new QFile(outputDir ~ "/" ~ implementation); | 215 auto implementationFile = new QFile(outputDir ~ "/" ~ implementation); |
198 if (!implementationFile.open(QFile.WriteOnly | QFile.Text)) { | 216 if (!implementationFile.open(QFile.WriteOnly | QFile.Text)) { |
199 QMessageBox.warning(null, tr("Simple Wizard"), | 217 QMessageBox.warning(null, tr("Simple Wizard"), |
200 Format(tr("Cannot write file {}:\n{}"), | 218 format(cannot_write_file_str, |
201 implementationFile.fileName(), | 219 implementationFile.fileName(), |
202 implementationFile.errorString())); | 220 implementationFile.errorString())); |
203 return; | 221 return; |
204 } | 222 } |
205 implementationFile.write(block); | 223 implementationFile.write(block); |
360 protected: | 378 protected: |
361 | 379 |
362 void initializePage() | 380 void initializePage() |
363 { | 381 { |
364 string className = field("className").toString(); | 382 string className = field("className").toString(); |
365 macroNameLineEdit.setText(className.toUpper() ~ "_H"); | 383 macroNameLineEdit.setText(toupper(className) ~ "_H"); |
366 | 384 |
367 string baseClass = field("baseClass").toString(); | 385 string baseClass = field("baseClass").toString(); |
368 | 386 |
369 includeBaseCheckBox.setChecked(baseClass.length != 0); | 387 includeBaseCheckBox.setChecked(baseClass.length != 0); |
370 includeBaseCheckBox.setEnabled(baseClass.length != 0); | 388 includeBaseCheckBox.setEnabled(baseClass.length != 0); |
374 if (baseClass.length == 0) { | 392 if (baseClass.length == 0) { |
375 baseIncludeLineEdit.clear(); | 393 baseIncludeLineEdit.clear(); |
376 } else if ((new QRegExp("Q[A-Z].*")).exactMatch(baseClass)) { | 394 } else if ((new QRegExp("Q[A-Z].*")).exactMatch(baseClass)) { |
377 baseIncludeLineEdit.setText("<" ~ baseClass ~ ">"); | 395 baseIncludeLineEdit.setText("<" ~ baseClass ~ ">"); |
378 } else { | 396 } else { |
379 baseIncludeLineEdit.setText("\"" ~ baseClass.toLower() ~ ".h\""); | 397 baseIncludeLineEdit.setText("\"" ~ tolower(baseClass) ~ ".h\""); |
380 } | 398 } |
381 } | 399 } |
382 | 400 |
383 private: | 401 private: |
384 | 402 |
431 protected: | 449 protected: |
432 | 450 |
433 void initializePage() | 451 void initializePage() |
434 { | 452 { |
435 string className = field("className").toString(); | 453 string className = field("className").toString(); |
436 headerLineEdit.setText(toLower(className) ~ ".h"); | 454 headerLineEdit.setText(tolower(className) ~ ".h"); |
437 implementationLineEdit.setText(toLower(className) ~ ".cpp"); | 455 implementationLineEdit.setText(tolower(className) ~ ".cpp"); |
438 outputDirLineEdit.setText(QDir.convertSeparators(QDir.tempPath())); | 456 outputDirLineEdit.setText(QDir.convertSeparators(QDir.tempPath())); |
439 } | 457 } |
440 | 458 |
441 private: | 459 private: |
442 | 460 |
468 | 486 |
469 protected: | 487 protected: |
470 | 488 |
471 void initializePage() | 489 void initializePage() |
472 { | 490 { |
473 string finishText = wizard().buttonText(QWizard.FinishButton).dup; | 491 string finishText = wizard().buttonText(QWizard.FinishButton); |
474 auto pos = remove(finishText, '&'); | 492 version(Tango) |
475 label.setText(Format(tr("Click {} to generate the class skeleton."), finishText)); | 493 { |
494 auto pos = remove(finishText, '&'); | |
495 const string str = tr("Click {} to generate the class skeleton."); | |
496 } | |
497 else | |
498 { | |
499 const string str = tr("Click %s to generate the class skeleton."); | |
500 // TODO: port to D2. | |
501 } | |
502 label.setText(format(str, finishText)); | |
476 } | 503 } |
477 | 504 |
478 private: | 505 private: |
479 | 506 |
480 QLabel label; | 507 QLabel label; |