|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
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 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QFont> |
|
44 #include <QtTest/QtTest> |
|
45 #include <QCheckBox> |
|
46 #include <QLabel> |
|
47 #include <QLineEdit> |
|
48 #include <QList> |
|
49 #include <QPushButton> |
|
50 #include <QToolButton> |
|
51 #include <QVBoxLayout> |
|
52 #include <QWizard> |
|
53 #include <QStyle> |
|
54 #include <QPlastiqueStyle> |
|
55 #include <QTreeWidget> |
|
56 |
|
57 //TESTED_CLASS= |
|
58 //TESTED_FILES= |
|
59 |
|
60 static QImage grabWidget(QWidget *window) |
|
61 { |
|
62 return QPixmap::grabWidget(window).toImage(); |
|
63 } |
|
64 |
|
65 class tst_QWizard : public QObject |
|
66 { |
|
67 Q_OBJECT |
|
68 |
|
69 public: |
|
70 tst_QWizard(); |
|
71 |
|
72 public slots: |
|
73 void init(); |
|
74 void cleanup(); |
|
75 |
|
76 private slots: |
|
77 void buttonText(); |
|
78 void setButtonLayout(); |
|
79 void setButton(); |
|
80 void setTitleFormatEtc(); |
|
81 void setPixmap(); |
|
82 void setDefaultProperty(); |
|
83 void addPage(); |
|
84 void setPage(); |
|
85 void setStartId(); |
|
86 void setOption_IndependentPages(); |
|
87 void setOption_IgnoreSubTitles(); |
|
88 void setOption_ExtendedWatermarkPixmap(); |
|
89 void setOption_NoDefaultButton(); |
|
90 void setOption_NoBackButtonOnStartPage(); |
|
91 void setOption_NoBackButtonOnLastPage(); |
|
92 void setOption_DisabledBackButtonOnLastPage(); |
|
93 void setOption_HaveNextButtonOnLastPage(); |
|
94 void setOption_HaveFinishButtonOnEarlyPages(); |
|
95 void setOption_NoCancelButton(); |
|
96 void setOption_CancelButtonOnLeft(); |
|
97 void setOption_HaveHelpButton(); |
|
98 void setOption_HelpButtonOnRight(); |
|
99 void setOption_HaveCustomButtonX(); |
|
100 void combinations_data(); |
|
101 void combinations(); |
|
102 void showCurrentPageOnly(); |
|
103 void setButtonText(); |
|
104 void setCommitPage(); |
|
105 void setWizardStyle(); |
|
106 void removePage(); |
|
107 |
|
108 // task-specific tests below me: |
|
109 void task161660_buttonSpacing(); |
|
110 void task177716_disableCommitButton(); |
|
111 void task183550_stretchFactor(); |
|
112 void task161658_alignments(); |
|
113 void task177022_setFixedSize(); |
|
114 void task248107_backButton(); |
|
115 void task255350_fieldObjectDestroyed(); |
|
116 |
|
117 /* |
|
118 Things that could be added: |
|
119 |
|
120 1. Test virtual functions that are called, signals that are |
|
121 emitted, etc. |
|
122 |
|
123 2. Test QWizardPage more thorougly. |
|
124 |
|
125 3. Test the look and field a bit more (especially the |
|
126 different wizard styles, and how they interact with |
|
127 pixmaps, titles, subtitles, etc.). |
|
128 |
|
129 4. Test minimum sizes, sizes, maximum sizes, resizing, etc. |
|
130 |
|
131 5. Try setting various options and wizard styles in various |
|
132 orders and check that the results are the same every time, |
|
133 no matter the order in which the properties were set. |
|
134 |
|
135 -> Initial version done (tst_QWizard::combinations()) |
|
136 |
|
137 6. Test done() and restart(). |
|
138 |
|
139 7. Test default properties of built-in widgets. |
|
140 |
|
141 8. Test mutual exclusiveness of Next and Commit buttons. |
|
142 */ |
|
143 }; |
|
144 |
|
145 tst_QWizard::tst_QWizard() |
|
146 { |
|
147 } |
|
148 |
|
149 void tst_QWizard::init() |
|
150 { |
|
151 #ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
152 qApp->setAutoMaximizeThreshold(-1); |
|
153 #endif |
|
154 } |
|
155 |
|
156 void tst_QWizard::cleanup() |
|
157 { |
|
158 } |
|
159 |
|
160 void tst_QWizard::buttonText() |
|
161 { |
|
162 QWizard wizard; |
|
163 wizard.setWizardStyle(QWizard::ClassicStyle); |
|
164 |
|
165 // Check the buttons' original text in Classic and Modern styles. |
|
166 for (int pass = 0; pass < 2; ++pass) { |
|
167 QCOMPARE(wizard.buttonText(QWizard::BackButton), QString("< &Back")); |
|
168 QVERIFY(wizard.buttonText(QWizard::NextButton).contains("Next")); |
|
169 QVERIFY(wizard.buttonText(QWizard::FinishButton).endsWith("Finish")); |
|
170 QVERIFY(wizard.buttonText(QWizard::CancelButton).endsWith("Cancel")); |
|
171 QVERIFY(wizard.buttonText(QWizard::HelpButton).endsWith("Help")); |
|
172 |
|
173 QVERIFY(wizard.buttonText(QWizard::CustomButton1).isEmpty()); |
|
174 QVERIFY(wizard.buttonText(QWizard::CustomButton2).isEmpty()); |
|
175 QVERIFY(wizard.buttonText(QWizard::CustomButton3).isEmpty()); |
|
176 |
|
177 // robustness |
|
178 QVERIFY(wizard.buttonText(QWizard::Stretch).isEmpty()); |
|
179 QVERIFY(wizard.buttonText(QWizard::NoButton).isEmpty()); |
|
180 QVERIFY(wizard.buttonText(QWizard::NStandardButtons).isEmpty()); |
|
181 QVERIFY(wizard.buttonText(QWizard::NButtons).isEmpty()); |
|
182 |
|
183 wizard.setWizardStyle(QWizard::ModernStyle); |
|
184 } |
|
185 |
|
186 // Check the buttons' original text in Mac style. |
|
187 wizard.setWizardStyle(QWizard::MacStyle); |
|
188 |
|
189 QCOMPARE(wizard.buttonText(QWizard::BackButton), QString("Go Back")); |
|
190 QCOMPARE(wizard.buttonText(QWizard::NextButton), QString("Continue")); |
|
191 QCOMPARE(wizard.buttonText(QWizard::FinishButton), QString("Done")); |
|
192 QCOMPARE(wizard.buttonText(QWizard::CancelButton), QString("Cancel")); |
|
193 QCOMPARE(wizard.buttonText(QWizard::HelpButton), QString("Help")); |
|
194 |
|
195 QVERIFY(wizard.buttonText(QWizard::CustomButton1).isEmpty()); |
|
196 QVERIFY(wizard.buttonText(QWizard::CustomButton2).isEmpty()); |
|
197 QVERIFY(wizard.buttonText(QWizard::CustomButton3).isEmpty()); |
|
198 |
|
199 // robustness |
|
200 QVERIFY(wizard.buttonText(QWizard::Stretch).isEmpty()); |
|
201 QVERIFY(wizard.buttonText(QWizard::NoButton).isEmpty()); |
|
202 QVERIFY(wizard.buttonText(QWizard::NStandardButtons).isEmpty()); |
|
203 QVERIFY(wizard.buttonText(QWizard::NButtons).isEmpty()); |
|
204 |
|
205 // Modify the buttons' text and see what happens. |
|
206 wizard.setButtonText(QWizard::NextButton, "N&este"); |
|
207 wizard.setButtonText(QWizard::CustomButton2, "&Cucu"); |
|
208 wizard.setButtonText(QWizard::Stretch, "Stretch"); |
|
209 |
|
210 QCOMPARE(wizard.buttonText(QWizard::BackButton), QString("Go Back")); |
|
211 QCOMPARE(wizard.buttonText(QWizard::NextButton), QString("N&este")); |
|
212 QCOMPARE(wizard.buttonText(QWizard::FinishButton), QString("Done")); |
|
213 QCOMPARE(wizard.buttonText(QWizard::CancelButton), QString("Cancel")); |
|
214 QCOMPARE(wizard.buttonText(QWizard::HelpButton), QString("Help")); |
|
215 |
|
216 QVERIFY(wizard.buttonText(QWizard::CustomButton1).isEmpty()); |
|
217 QCOMPARE(wizard.buttonText(QWizard::CustomButton2), QString("&Cucu")); |
|
218 QVERIFY(wizard.buttonText(QWizard::CustomButton3).isEmpty()); |
|
219 |
|
220 // robustness |
|
221 QVERIFY(wizard.buttonText(QWizard::Stretch).isEmpty()); |
|
222 QVERIFY(wizard.buttonText(QWizard::NoButton).isEmpty()); |
|
223 QVERIFY(wizard.buttonText(QWizard::NStandardButtons).isEmpty()); |
|
224 QVERIFY(wizard.buttonText(QWizard::NButtons).isEmpty()); |
|
225 |
|
226 // Switch back to Classic style and see what happens. |
|
227 wizard.setWizardStyle(QWizard::ClassicStyle); |
|
228 |
|
229 for (int pass = 0; pass < 2; ++pass) { |
|
230 QCOMPARE(wizard.buttonText(QWizard::BackButton), QString("< &Back")); |
|
231 QCOMPARE(wizard.buttonText(QWizard::NextButton), QString("N&este")); |
|
232 QVERIFY(wizard.buttonText(QWizard::FinishButton).endsWith("Finish")); |
|
233 QVERIFY(wizard.buttonText(QWizard::CancelButton).endsWith("Cancel")); |
|
234 QVERIFY(wizard.buttonText(QWizard::HelpButton).endsWith("Help")); |
|
235 |
|
236 QVERIFY(wizard.buttonText(QWizard::CustomButton1).isEmpty()); |
|
237 QCOMPARE(wizard.buttonText(QWizard::CustomButton2), QString("&Cucu")); |
|
238 QVERIFY(wizard.buttonText(QWizard::CustomButton3).isEmpty()); |
|
239 |
|
240 // robustness |
|
241 QVERIFY(wizard.buttonText(QWizard::Stretch).isEmpty()); |
|
242 QVERIFY(wizard.buttonText(QWizard::NoButton).isEmpty()); |
|
243 QVERIFY(wizard.buttonText(QWizard::NStandardButtons).isEmpty()); |
|
244 QVERIFY(wizard.buttonText(QWizard::NButtons).isEmpty()); |
|
245 |
|
246 wizard.setOptions(QWizard::NoDefaultButton |
|
247 | QWizard::NoBackButtonOnStartPage |
|
248 | QWizard::NoBackButtonOnLastPage |
|
249 | QWizard::DisabledBackButtonOnLastPage |
|
250 | QWizard::NoCancelButton |
|
251 | QWizard::CancelButtonOnLeft |
|
252 | QWizard::HaveHelpButton |
|
253 | QWizard::HelpButtonOnRight |
|
254 | QWizard::HaveCustomButton1 |
|
255 | QWizard::HaveCustomButton2 |
|
256 | QWizard::HaveCustomButton3); |
|
257 } |
|
258 } |
|
259 |
|
260 void tst_QWizard::setButtonLayout() |
|
261 { |
|
262 QList<QWizard::WizardButton> layout; |
|
263 |
|
264 QWizard wizard; |
|
265 wizard.setWizardStyle(QWizard::ClassicStyle); |
|
266 wizard.setOptions(0); |
|
267 wizard.setButtonLayout(layout); |
|
268 wizard.show(); |
|
269 qApp->processEvents(); |
|
270 |
|
271 // if these crash, this means there's a bug in QWizard |
|
272 QVERIFY(wizard.button(QWizard::NextButton)->text().contains("Next")); |
|
273 QVERIFY(wizard.button(QWizard::BackButton)->text().contains("Back")); |
|
274 QVERIFY(wizard.button(QWizard::FinishButton)->text().contains("Finish")); |
|
275 QVERIFY(wizard.button(QWizard::CancelButton)->text().contains("Cancel")); |
|
276 QVERIFY(wizard.button(QWizard::HelpButton)->text().contains("Help")); |
|
277 QVERIFY(wizard.button(QWizard::CustomButton1)->text().isEmpty()); |
|
278 QVERIFY(wizard.button(QWizard::CustomButton2)->text().isEmpty()); |
|
279 QVERIFY(wizard.button(QWizard::CustomButton3)->text().isEmpty()); |
|
280 QVERIFY(!wizard.button(QWizard::Stretch)); |
|
281 QVERIFY(!wizard.button(QWizard::NoButton)); |
|
282 |
|
283 QVERIFY(!wizard.button(QWizard::NextButton)->isVisible()); |
|
284 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
285 QVERIFY(!wizard.button(QWizard::HelpButton)->isVisible()); |
|
286 |
|
287 layout << QWizard::NextButton << QWizard::HelpButton; |
|
288 wizard.setButtonLayout(layout); |
|
289 qApp->processEvents(); |
|
290 |
|
291 QVERIFY(!wizard.button(QWizard::NextButton)->isVisible()); |
|
292 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
293 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
294 |
|
295 wizard.addPage(new QWizardPage); |
|
296 wizard.addPage(new QWizardPage); |
|
297 qApp->processEvents(); |
|
298 |
|
299 QVERIFY(!wizard.button(QWizard::NextButton)->isVisible()); |
|
300 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
301 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
302 |
|
303 wizard.restart(); |
|
304 qApp->processEvents(); |
|
305 |
|
306 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
307 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
308 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
309 |
|
310 layout.clear(); |
|
311 layout << QWizard::NextButton << QWizard::HelpButton << QWizard::BackButton |
|
312 << QWizard::FinishButton << QWizard::CancelButton << QWizard::Stretch |
|
313 << QWizard::CustomButton2; |
|
314 |
|
315 // Turn on all the button-related wizard options. Some of these |
|
316 // should have no impact on a custom layout; others should. |
|
317 wizard.setButtonLayout(layout); |
|
318 wizard.setOptions(QWizard::NoDefaultButton |
|
319 | QWizard::NoBackButtonOnStartPage |
|
320 | QWizard::NoBackButtonOnLastPage |
|
321 | QWizard::DisabledBackButtonOnLastPage |
|
322 | QWizard::HaveNextButtonOnLastPage |
|
323 | QWizard::HaveFinishButtonOnEarlyPages |
|
324 | QWizard::NoCancelButton |
|
325 | QWizard::CancelButtonOnLeft |
|
326 | QWizard::HaveHelpButton |
|
327 | QWizard::HelpButtonOnRight |
|
328 | QWizard::HaveCustomButton1 |
|
329 | QWizard::HaveCustomButton2 |
|
330 | QWizard::HaveCustomButton3); |
|
331 qApp->processEvents(); |
|
332 |
|
333 // we're on first page |
|
334 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
335 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
336 QVERIFY(wizard.button(QWizard::CancelButton)->isVisible()); // NoCancelButton overridden |
|
337 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
338 QVERIFY(!wizard.button(QWizard::CustomButton1)->isVisible()); |
|
339 QVERIFY(wizard.button(QWizard::CustomButton2)->isVisible()); // HaveCustomButton2 overridden |
|
340 QVERIFY(!wizard.button(QWizard::CustomButton3)->isVisible()); |
|
341 |
|
342 wizard.next(); |
|
343 qApp->processEvents(); |
|
344 |
|
345 // we're on last page |
|
346 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
347 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
348 QVERIFY(!wizard.button(QWizard::NextButton)->isEnabled()); |
|
349 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
350 QVERIFY(wizard.button(QWizard::FinishButton)->isEnabled()); |
|
351 QVERIFY(wizard.button(QWizard::CancelButton)->isVisible()); // NoCancelButton overridden |
|
352 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
353 QVERIFY(!wizard.button(QWizard::CustomButton1)->isVisible()); |
|
354 QVERIFY(wizard.button(QWizard::CustomButton2)->isVisible()); // HaveCustomButton2 overridden |
|
355 QVERIFY(!wizard.button(QWizard::CustomButton3)->isVisible()); |
|
356 |
|
357 // Check that the buttons are in the right order on screen. |
|
358 for (int pass = 0; pass < 2; ++pass) { |
|
359 wizard.setLayoutDirection(pass == 0 ? Qt::LeftToRight : Qt::RightToLeft); |
|
360 qApp->processEvents(); |
|
361 |
|
362 int sign = (pass == 0) ? +1 : -1; |
|
363 |
|
364 int p[5]; |
|
365 p[0] = sign * wizard.button(QWizard::NextButton)->x(); |
|
366 p[1] = sign * wizard.button(QWizard::HelpButton)->x(); |
|
367 p[2] = sign * wizard.button(QWizard::FinishButton)->x(); |
|
368 p[3] = sign * wizard.button(QWizard::CancelButton)->x(); |
|
369 p[4] = sign * wizard.button(QWizard::CustomButton2)->x(); |
|
370 |
|
371 QVERIFY(p[0] < p[1]); |
|
372 QVERIFY(p[1] < p[2]); |
|
373 QVERIFY(p[2] < p[3]); |
|
374 QVERIFY(p[3] < p[4]); |
|
375 } |
|
376 |
|
377 layout.clear(); |
|
378 wizard.setButtonLayout(layout); |
|
379 qApp->processEvents(); |
|
380 |
|
381 for (int i = -1; i < 50; ++i) { |
|
382 QAbstractButton *button = wizard.button(QWizard::WizardButton(i)); |
|
383 QVERIFY(!button || !button->isVisible()); |
|
384 } |
|
385 } |
|
386 |
|
387 void tst_QWizard::setButton() |
|
388 { |
|
389 QPointer<QToolButton> toolButton = new QToolButton; |
|
390 |
|
391 QWizard wizard; |
|
392 wizard.setWizardStyle(QWizard::ClassicStyle); |
|
393 wizard.setButton(QWizard::NextButton, toolButton); |
|
394 wizard.setButton(QWizard::CustomButton2, new QCheckBox("Kustom 2")); |
|
395 |
|
396 QVERIFY(qobject_cast<QToolButton *>(wizard.button(QWizard::NextButton))); |
|
397 QVERIFY(qobject_cast<QCheckBox *>(wizard.button(QWizard::CustomButton2))); |
|
398 QVERIFY(qobject_cast<QPushButton *>(wizard.button(QWizard::CustomButton1))); |
|
399 |
|
400 QVERIFY(toolButton != 0); |
|
401 |
|
402 // resetting the same button does nothing |
|
403 wizard.setButton(QWizard::NextButton, toolButton); |
|
404 QVERIFY(toolButton != 0); |
|
405 |
|
406 // revert to default button |
|
407 wizard.setButton(QWizard::NextButton, 0); |
|
408 QVERIFY(toolButton == 0); |
|
409 QVERIFY(qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))); |
|
410 QVERIFY(wizard.button(QWizard::NextButton)->text().contains("Next")); |
|
411 } |
|
412 |
|
413 void tst_QWizard::setTitleFormatEtc() |
|
414 { |
|
415 QWizard wizard; |
|
416 QVERIFY(wizard.titleFormat() == Qt::AutoText); |
|
417 QVERIFY(wizard.subTitleFormat() == Qt::AutoText); |
|
418 |
|
419 wizard.setTitleFormat(Qt::RichText); |
|
420 QVERIFY(wizard.titleFormat() == Qt::RichText); |
|
421 QVERIFY(wizard.subTitleFormat() == Qt::AutoText); |
|
422 |
|
423 wizard.setSubTitleFormat(Qt::PlainText); |
|
424 QVERIFY(wizard.titleFormat() == Qt::RichText); |
|
425 QVERIFY(wizard.subTitleFormat() == Qt::PlainText); |
|
426 } |
|
427 |
|
428 void tst_QWizard::setPixmap() |
|
429 { |
|
430 QPixmap p1(1, 1); |
|
431 QPixmap p2(2, 2); |
|
432 QPixmap p3(3, 3); |
|
433 QPixmap p4(4, 4); |
|
434 QPixmap p5(5, 5); |
|
435 |
|
436 QWizard wizard; |
|
437 QWizardPage *page = new QWizardPage; |
|
438 QWizardPage *page2 = new QWizardPage; |
|
439 |
|
440 wizard.addPage(page); |
|
441 wizard.addPage(page2); |
|
442 |
|
443 QVERIFY(wizard.pixmap(QWizard::BannerPixmap).isNull()); |
|
444 QVERIFY(wizard.pixmap(QWizard::LogoPixmap).isNull()); |
|
445 QVERIFY(wizard.pixmap(QWizard::WatermarkPixmap).isNull()); |
|
446 #ifdef Q_WS_MAC |
|
447 if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_3) |
|
448 QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull() == false); |
|
449 else // fall through since the image doesn't exist on a 10.3 system. |
|
450 QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); |
|
451 #else |
|
452 QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull()); |
|
453 #endif |
|
454 |
|
455 QVERIFY(page->pixmap(QWizard::BannerPixmap).isNull()); |
|
456 QVERIFY(page->pixmap(QWizard::LogoPixmap).isNull()); |
|
457 QVERIFY(page->pixmap(QWizard::WatermarkPixmap).isNull()); |
|
458 #ifdef Q_WS_MAC |
|
459 if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_3) |
|
460 QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull() == false); |
|
461 else // fall through since the image doesn't exist on a 10.3 system. |
|
462 QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); |
|
463 #else |
|
464 QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); |
|
465 #endif |
|
466 wizard.setPixmap(QWizard::BannerPixmap, p1); |
|
467 wizard.setPixmap(QWizard::LogoPixmap, p2); |
|
468 wizard.setPixmap(QWizard::WatermarkPixmap, p3); |
|
469 wizard.setPixmap(QWizard::BackgroundPixmap, p4); |
|
470 |
|
471 page->setPixmap(QWizard::LogoPixmap, p5); |
|
472 |
|
473 QVERIFY(wizard.pixmap(QWizard::BannerPixmap).size() == p1.size()); |
|
474 QVERIFY(wizard.pixmap(QWizard::LogoPixmap).size() == p2.size()); |
|
475 QVERIFY(wizard.pixmap(QWizard::WatermarkPixmap).size() == p3.size()); |
|
476 QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).size() == p4.size()); |
|
477 |
|
478 QVERIFY(page->pixmap(QWizard::BannerPixmap).size() == p1.size()); |
|
479 QVERIFY(page->pixmap(QWizard::LogoPixmap).size() == p5.size()); |
|
480 QVERIFY(page->pixmap(QWizard::WatermarkPixmap).size() == p3.size()); |
|
481 QVERIFY(page->pixmap(QWizard::BackgroundPixmap).size() == p4.size()); |
|
482 |
|
483 QVERIFY(page2->pixmap(QWizard::BannerPixmap).size() == p1.size()); |
|
484 QVERIFY(page2->pixmap(QWizard::LogoPixmap).size() == p2.size()); |
|
485 QVERIFY(page2->pixmap(QWizard::WatermarkPixmap).size() == p3.size()); |
|
486 QVERIFY(page2->pixmap(QWizard::BackgroundPixmap).size() == p4.size()); |
|
487 } |
|
488 |
|
489 class MyPage1 : public QWizardPage |
|
490 { |
|
491 public: |
|
492 MyPage1() { |
|
493 edit1 = new QLineEdit("Bla 1", this); |
|
494 |
|
495 edit2 = new QLineEdit("Bla 2", this); |
|
496 edit2->setInputMask("Mask"); |
|
497 |
|
498 edit3 = new QLineEdit("Bla 3", this); |
|
499 edit3->setMaxLength(25); |
|
500 |
|
501 edit4 = new QLineEdit("Bla 4", this); |
|
502 } |
|
503 |
|
504 void registerField(const QString &name, QWidget *widget, |
|
505 const char *property = 0, |
|
506 const char *changedSignal = 0) |
|
507 { QWizardPage::registerField(name, widget, property, changedSignal); } |
|
508 |
|
509 QLineEdit *edit1; |
|
510 QLineEdit *edit2; |
|
511 QLineEdit *edit3; |
|
512 QLineEdit *edit4; |
|
513 }; |
|
514 |
|
515 void tst_QWizard::setDefaultProperty() |
|
516 { |
|
517 QWizard wizard; |
|
518 MyPage1 *page = new MyPage1; |
|
519 wizard.addPage(page); |
|
520 |
|
521 page->registerField("edit1", page->edit1); |
|
522 |
|
523 wizard.setDefaultProperty("QLineEdit", "inputMask", 0); |
|
524 page->registerField("edit2", page->edit2); |
|
525 |
|
526 wizard.setDefaultProperty("QLineEdit", "maxLength", 0); |
|
527 page->registerField("edit3", page->edit3); |
|
528 |
|
529 wizard.setDefaultProperty("QLineEdit", "text", SIGNAL(textChanged(QString))); |
|
530 page->registerField("edit3bis", page->edit3); |
|
531 |
|
532 wizard.setDefaultProperty("QWidget", "enabled", 0); // less specific, i.e. ignored |
|
533 page->registerField("edit4", page->edit4); |
|
534 QTest::ignoreMessage(QtWarningMsg,"QWizard::setField: Couldn't write to property 'customProperty'"); |
|
535 wizard.setDefaultProperty("QLineEdit", "customProperty", 0); |
|
536 page->registerField("edit4bis", page->edit4); |
|
537 |
|
538 QCOMPARE(wizard.field("edit1").toString(), QString("Bla 1")); |
|
539 QCOMPARE(wizard.field("edit2").toString(), page->edit2->inputMask()); |
|
540 QCOMPARE(wizard.field("edit3").toInt(), 25); |
|
541 QCOMPARE(wizard.field("edit3bis").toString(), QString("Bla 3")); |
|
542 QCOMPARE(wizard.field("edit4").toString(), QString("Bla 4")); |
|
543 QCOMPARE(wizard.field("edit4bis").toString(), QString()); |
|
544 |
|
545 wizard.setField("edit1", "Alpha"); |
|
546 wizard.setField("edit2", "Beta"); |
|
547 wizard.setField("edit3", 50); |
|
548 wizard.setField("edit3bis", "Gamma"); |
|
549 wizard.setField("edit4", "Delta"); |
|
550 wizard.setField("edit4bis", "Epsilon"); |
|
551 |
|
552 QCOMPARE(wizard.field("edit1").toString(), QString("Alpha")); |
|
553 QVERIFY(wizard.field("edit2").toString().contains("Beta")); |
|
554 QCOMPARE(wizard.field("edit3").toInt(), 50); |
|
555 QCOMPARE(wizard.field("edit3bis").toString(), QString("Gamma")); |
|
556 QCOMPARE(wizard.field("edit4").toString(), QString("Delta")); |
|
557 QCOMPARE(wizard.field("edit4bis").toString(), QString("Epsilon")); |
|
558 |
|
559 // make sure the data structure is reasonable |
|
560 for (int i = 0; i < 200000; ++i) { |
|
561 wizard.setDefaultProperty("QLineEdit", "x" + QByteArray::number(i), 0); |
|
562 wizard.setDefaultProperty("QLabel", "y" + QByteArray::number(i), 0); |
|
563 } |
|
564 } |
|
565 |
|
566 void tst_QWizard::addPage() |
|
567 { |
|
568 QWidget *parent = new QWidget; |
|
569 QWizard wizard; |
|
570 const int N = 100; |
|
571 QWizardPage *pages[N]; |
|
572 |
|
573 for (int i = 0; i < N; ++i) { |
|
574 pages[i] = new QWizardPage(parent); |
|
575 QCOMPARE(wizard.addPage(pages[i]), i); |
|
576 QCOMPARE(pages[i]->window(), (QWidget *)&wizard); |
|
577 QCOMPARE(wizard.startId(), 0); |
|
578 } |
|
579 |
|
580 for (int i = 0; i < N; ++i) { |
|
581 QVERIFY(pages[i] == wizard.page(i)); |
|
582 } |
|
583 QVERIFY(!wizard.page(-1)); |
|
584 QVERIFY(!wizard.page(N)); |
|
585 QVERIFY(!wizard.page(N + 1)); |
|
586 |
|
587 wizard.setPage(N + 50, new QWizardPage); |
|
588 wizard.setPage(-3000, new QWizardPage); |
|
589 |
|
590 QWizardPage *pageX = new QWizardPage; |
|
591 QCOMPARE(wizard.addPage(pageX), N + 51); |
|
592 QCOMPARE(wizard.page(N + 51), pageX); |
|
593 |
|
594 QCOMPARE(wizard.addPage(new QWizardPage), N + 52); |
|
595 |
|
596 QTest::ignoreMessage(QtWarningMsg,"QWizard::setPage: Cannot insert null page"); |
|
597 wizard.addPage(0); // generates a warning |
|
598 delete parent; |
|
599 } |
|
600 |
|
601 #define CHECK_VISITED(wizard, list) \ |
|
602 do { \ |
|
603 QList<int> myList = list; \ |
|
604 QCOMPARE((wizard).visitedPages(), myList); \ |
|
605 Q_FOREACH(int id, myList) \ |
|
606 QVERIFY((wizard).hasVisitedPage(id)); \ |
|
607 } while (0) |
|
608 |
|
609 void tst_QWizard::setPage() |
|
610 { |
|
611 QWidget *parent = new QWidget; |
|
612 QWizard wizard; |
|
613 QWizardPage *page; |
|
614 |
|
615 QCOMPARE(wizard.startId(), -1); |
|
616 QCOMPARE(wizard.currentId(), -1); |
|
617 QVERIFY(!wizard.currentPage()); |
|
618 QCOMPARE(wizard.nextId(), -1); |
|
619 |
|
620 page = new QWizardPage(parent); |
|
621 QTest::ignoreMessage(QtWarningMsg,"QWizard::setPage: Cannot insert page with ID -1"); |
|
622 wizard.setPage(-1, page); // gives a warning and does nothing |
|
623 QVERIFY(!wizard.page(-2)); |
|
624 QVERIFY(!wizard.page(-1)); |
|
625 QVERIFY(!wizard.page(0)); |
|
626 QCOMPARE(wizard.startId(), -1); |
|
627 QCOMPARE(wizard.currentId(), -1); |
|
628 QVERIFY(!wizard.currentPage()); |
|
629 QCOMPARE(wizard.nextId(), -1); |
|
630 CHECK_VISITED(wizard, QList<int>()); |
|
631 |
|
632 page = new QWizardPage(parent); |
|
633 wizard.setPage(0, page); |
|
634 QCOMPARE(page->window(), (QWidget *)&wizard); |
|
635 QCOMPARE(wizard.page(0), page); |
|
636 QCOMPARE(wizard.startId(), 0); |
|
637 QCOMPARE(wizard.currentId(), -1); |
|
638 QVERIFY(!wizard.currentPage()); |
|
639 QCOMPARE(wizard.nextId(), -1); |
|
640 CHECK_VISITED(wizard, QList<int>()); |
|
641 |
|
642 page = new QWizardPage(parent); |
|
643 wizard.setPage(-2, page); |
|
644 QCOMPARE(page->window(), (QWidget *)&wizard); |
|
645 QCOMPARE(wizard.page(-2), page); |
|
646 QCOMPARE(wizard.startId(), -2); |
|
647 QCOMPARE(wizard.currentId(), -1); |
|
648 QVERIFY(!wizard.currentPage()); |
|
649 QCOMPARE(wizard.nextId(), -1); |
|
650 CHECK_VISITED(wizard, QList<int>()); |
|
651 |
|
652 wizard.restart(); |
|
653 QCOMPARE(wizard.page(-2), page); |
|
654 QCOMPARE(wizard.startId(), -2); |
|
655 QCOMPARE(wizard.currentId(), -2); |
|
656 QVERIFY(wizard.currentPage() == page); |
|
657 QCOMPARE(wizard.nextId(), 0); |
|
658 CHECK_VISITED(wizard, QList<int>() << -2); |
|
659 |
|
660 page = new QWizardPage(parent); |
|
661 wizard.setPage(2, page); |
|
662 QCOMPARE(wizard.page(2), page); |
|
663 QCOMPARE(wizard.startId(), -2); |
|
664 QCOMPARE(wizard.currentId(), -2); |
|
665 QVERIFY(wizard.currentPage() == wizard.page(-2)); |
|
666 QCOMPARE(wizard.nextId(), 0); |
|
667 CHECK_VISITED(wizard, QList<int>() << -2); |
|
668 |
|
669 wizard.restart(); |
|
670 QCOMPARE(wizard.startId(), -2); |
|
671 QCOMPARE(wizard.currentId(), -2); |
|
672 QVERIFY(wizard.currentPage() == wizard.page(-2)); |
|
673 QCOMPARE(wizard.nextId(), 0); |
|
674 CHECK_VISITED(wizard, QList<int>() << -2); |
|
675 |
|
676 page = new QWizardPage(parent); |
|
677 wizard.setPage(-3, page); |
|
678 QCOMPARE(wizard.page(-3), page); |
|
679 QCOMPARE(wizard.startId(), -3); |
|
680 QCOMPARE(wizard.currentId(), -2); |
|
681 QVERIFY(wizard.currentPage() == wizard.page(-2)); |
|
682 QCOMPARE(wizard.nextId(), 0); |
|
683 CHECK_VISITED(wizard, QList<int>() << -2); |
|
684 |
|
685 wizard.restart(); |
|
686 QCOMPARE(wizard.startId(), -3); |
|
687 QCOMPARE(wizard.currentId(), -3); |
|
688 QVERIFY(wizard.currentPage() == wizard.page(-3)); |
|
689 QCOMPARE(wizard.nextId(), -2); |
|
690 CHECK_VISITED(wizard, QList<int>() << -3); |
|
691 |
|
692 wizard.next(); |
|
693 QCOMPARE(wizard.startId(), -3); |
|
694 QCOMPARE(wizard.currentId(), -2); |
|
695 QVERIFY(wizard.currentPage() == wizard.page(-2)); |
|
696 QCOMPARE(wizard.nextId(), 0); |
|
697 CHECK_VISITED(wizard, QList<int>() << -3 << -2); |
|
698 |
|
699 wizard.next(); |
|
700 QCOMPARE(wizard.startId(), -3); |
|
701 QCOMPARE(wizard.currentId(), 0); |
|
702 QVERIFY(wizard.currentPage() == wizard.page(0)); |
|
703 QCOMPARE(wizard.nextId(), 2); |
|
704 CHECK_VISITED(wizard, QList<int>() << -3 << -2 << 0); |
|
705 |
|
706 for (int i = 0; i < 100; ++i) { |
|
707 wizard.next(); |
|
708 QCOMPARE(wizard.startId(), -3); |
|
709 QCOMPARE(wizard.currentId(), 2); |
|
710 QVERIFY(wizard.currentPage() == wizard.page(2)); |
|
711 QCOMPARE(wizard.nextId(), -1); |
|
712 CHECK_VISITED(wizard, QList<int>() << -3 << -2 << 0 << 2); |
|
713 } |
|
714 |
|
715 wizard.back(); |
|
716 QCOMPARE(wizard.startId(), -3); |
|
717 QCOMPARE(wizard.currentId(), 0); |
|
718 QVERIFY(wizard.currentPage() == wizard.page(0)); |
|
719 QCOMPARE(wizard.nextId(), 2); |
|
720 CHECK_VISITED(wizard, QList<int>() << -3 << -2 << 0); |
|
721 |
|
722 wizard.back(); |
|
723 QCOMPARE(wizard.startId(), -3); |
|
724 QCOMPARE(wizard.currentId(), -2); |
|
725 QVERIFY(wizard.currentPage() == wizard.page(-2)); |
|
726 QCOMPARE(wizard.nextId(), 0); |
|
727 CHECK_VISITED(wizard, QList<int>() << -3 << -2); |
|
728 |
|
729 for (int i = 0; i < 100; ++i) { |
|
730 wizard.back(); |
|
731 QCOMPARE(wizard.startId(), -3); |
|
732 QCOMPARE(wizard.currentId(), -3); |
|
733 QVERIFY(wizard.currentPage() == wizard.page(-3)); |
|
734 QCOMPARE(wizard.nextId(), -2); |
|
735 CHECK_VISITED(wizard, QList<int>() << -3); |
|
736 } |
|
737 |
|
738 for (int i = 0; i < 100; ++i) { |
|
739 wizard.restart(); |
|
740 QCOMPARE(wizard.startId(), -3); |
|
741 QCOMPARE(wizard.currentId(), -3); |
|
742 QVERIFY(wizard.currentPage() == wizard.page(-3)); |
|
743 QCOMPARE(wizard.nextId(), -2); |
|
744 CHECK_VISITED(wizard, QList<int>() << -3); |
|
745 } |
|
746 delete parent; |
|
747 } |
|
748 |
|
749 void tst_QWizard::setStartId() |
|
750 { |
|
751 QWizard wizard; |
|
752 QCOMPARE(wizard.startId(), -1); |
|
753 |
|
754 wizard.setPage(INT_MIN, new QWizardPage); |
|
755 QCOMPARE(wizard.startId(), INT_MIN); |
|
756 |
|
757 wizard.setPage(-2, new QWizardPage); |
|
758 QCOMPARE(wizard.startId(), INT_MIN); |
|
759 |
|
760 wizard.setPage(0, new QWizardPage); |
|
761 QCOMPARE(wizard.startId(), INT_MIN); |
|
762 |
|
763 wizard.setPage(1, new QWizardPage); |
|
764 QCOMPARE(wizard.startId(), INT_MIN); |
|
765 |
|
766 wizard.setPage(INT_MAX, new QWizardPage); |
|
767 QCOMPARE(wizard.startId(), INT_MIN); |
|
768 |
|
769 QTest::ignoreMessage(QtWarningMsg,"QWizard::setStartId: Invalid page ID -1"); |
|
770 wizard.setStartId(-1); |
|
771 QCOMPARE(wizard.startId(), INT_MIN); |
|
772 |
|
773 wizard.setStartId(-2); |
|
774 QCOMPARE(wizard.startId(), -2); |
|
775 QCOMPARE(wizard.nextId(), -1); |
|
776 |
|
777 wizard.restart(); |
|
778 QCOMPARE(wizard.startId(), -2); |
|
779 QCOMPARE(wizard.currentId(), -2); |
|
780 QVERIFY(wizard.currentPage() == wizard.page(-2)); |
|
781 QCOMPARE(wizard.nextId(), 0); |
|
782 |
|
783 wizard.next(); |
|
784 QCOMPARE(wizard.startId(), -2); |
|
785 QCOMPARE(wizard.currentId(), 0); |
|
786 QVERIFY(wizard.currentPage() == wizard.page(0)); |
|
787 QCOMPARE(wizard.nextId(), 1); |
|
788 |
|
789 wizard.setStartId(INT_MIN); |
|
790 QCOMPARE(wizard.startId(), INT_MIN); |
|
791 QCOMPARE(wizard.currentId(), 0); |
|
792 QVERIFY(wizard.currentPage() == wizard.page(0)); |
|
793 QCOMPARE(wizard.nextId(), 1); |
|
794 |
|
795 wizard.next(); |
|
796 QCOMPARE(wizard.startId(), INT_MIN); |
|
797 QCOMPARE(wizard.currentId(), 1); |
|
798 QVERIFY(wizard.currentPage() == wizard.page(1)); |
|
799 QCOMPARE(wizard.nextId(), INT_MAX); |
|
800 |
|
801 wizard.next(); |
|
802 QCOMPARE(wizard.startId(), INT_MIN); |
|
803 QCOMPARE(wizard.currentId(), INT_MAX); |
|
804 QVERIFY(wizard.currentPage() == wizard.page(INT_MAX)); |
|
805 QCOMPARE(wizard.nextId(), -1); |
|
806 CHECK_VISITED(wizard, QList<int>() << -2 << 0 << 1 << INT_MAX); |
|
807 } |
|
808 |
|
809 struct MyPage2 : public QWizardPage |
|
810 { |
|
811 public: |
|
812 MyPage2() : init(0), cleanup(0), validate(0) {} |
|
813 |
|
814 void initializePage() { ++init; QWizardPage::initializePage(); checkInvariant(); } |
|
815 void cleanupPage() { ++cleanup; QWizardPage::cleanupPage(); checkInvariant(); } |
|
816 bool validatePage() { ++validate; return QWizardPage::validatePage(); } |
|
817 |
|
818 void check(int init, int cleanup) |
|
819 { Q_ASSERT(init == this->init && cleanup == this->cleanup); Q_UNUSED(init); Q_UNUSED(cleanup); } |
|
820 |
|
821 int init; |
|
822 int cleanup; |
|
823 int validate; |
|
824 |
|
825 private: |
|
826 void checkInvariant() { Q_ASSERT(init == cleanup || init - 1 == cleanup); } |
|
827 }; |
|
828 |
|
829 #define CHECK_PAGE_INIT(i0, c0, i1, c1, i2, c2) \ |
|
830 page0->check((i0), (c0)); \ |
|
831 page1->check((i1), (c1)); \ |
|
832 page2->check((i2), (c2)); |
|
833 |
|
834 void tst_QWizard::setOption_IndependentPages() |
|
835 { |
|
836 MyPage2 *page0 = new MyPage2; |
|
837 MyPage2 *page1 = new MyPage2; |
|
838 MyPage2 *page2 = new MyPage2; |
|
839 |
|
840 QWizard wizard; |
|
841 wizard.addPage(page0); |
|
842 wizard.addPage(page1); |
|
843 wizard.addPage(page2); |
|
844 |
|
845 QVERIFY(!wizard.testOption(QWizard::IndependentPages)); |
|
846 |
|
847 wizard.restart(); |
|
848 |
|
849 // Make sure initializePage() and cleanupPage() are called are |
|
850 // they should when the |
|
851 // wizard.testOption(QWizard::IndependentPages option is off. |
|
852 for (int i = 0; i < 10; ++i) { |
|
853 CHECK_PAGE_INIT(i + 1, i, i, i, i, i); |
|
854 |
|
855 wizard.next(); |
|
856 CHECK_PAGE_INIT(i + 1, i, i + 1, i, i, i); |
|
857 |
|
858 wizard.next(); |
|
859 CHECK_PAGE_INIT(i + 1, i, i + 1, i, i + 1, i); |
|
860 |
|
861 wizard.next(); |
|
862 CHECK_PAGE_INIT(i + 1, i, i + 1, i, i + 1, i); |
|
863 |
|
864 wizard.back(); |
|
865 CHECK_PAGE_INIT(i + 1, i, i + 1, i, i + 1, i + 1); |
|
866 |
|
867 wizard.back(); |
|
868 CHECK_PAGE_INIT(i + 1, i, i + 1, i + 1, i + 1, i + 1); |
|
869 |
|
870 wizard.back(); |
|
871 CHECK_PAGE_INIT(i + 1, i, i + 1, i + 1, i + 1, i + 1); |
|
872 |
|
873 wizard.restart(); |
|
874 } |
|
875 |
|
876 CHECK_PAGE_INIT(11, 10, 10, 10, 10, 10); |
|
877 |
|
878 wizard.next(); |
|
879 CHECK_PAGE_INIT(11, 10, 11, 10, 10, 10); |
|
880 |
|
881 // Now, turn on the option and check that they're called at the |
|
882 // appropiate times (which aren't the same). |
|
883 wizard.setOption(QWizard::IndependentPages, true); |
|
884 CHECK_PAGE_INIT(11, 10, 11, 10, 10, 10); |
|
885 |
|
886 wizard.back(); |
|
887 CHECK_PAGE_INIT(11, 10, 11, 10, 10, 10); |
|
888 |
|
889 wizard.next(); |
|
890 CHECK_PAGE_INIT(11, 10, 11, 10, 10, 10); |
|
891 |
|
892 wizard.next(); |
|
893 CHECK_PAGE_INIT(11, 10, 11, 10, 11, 10); |
|
894 |
|
895 wizard.next(); |
|
896 CHECK_PAGE_INIT(11, 10, 11, 10, 11, 10); |
|
897 |
|
898 wizard.back(); |
|
899 CHECK_PAGE_INIT(11, 10, 11, 10, 11, 10); |
|
900 |
|
901 wizard.setStartId(2); |
|
902 |
|
903 wizard.restart(); |
|
904 CHECK_PAGE_INIT(11, 11, 11, 11, 12, 11); |
|
905 |
|
906 wizard.back(); |
|
907 CHECK_PAGE_INIT(11, 11, 11, 11, 12, 11); |
|
908 |
|
909 wizard.next(); |
|
910 CHECK_PAGE_INIT(11, 11, 11, 11, 12, 11); |
|
911 |
|
912 wizard.setStartId(0); |
|
913 wizard.restart(); |
|
914 CHECK_PAGE_INIT(12, 11, 11, 11, 12, 12); |
|
915 |
|
916 wizard.next(); |
|
917 CHECK_PAGE_INIT(12, 11, 12, 11, 12, 12); |
|
918 |
|
919 wizard.next(); |
|
920 CHECK_PAGE_INIT(12, 11, 12, 11, 13, 12); |
|
921 |
|
922 wizard.back(); |
|
923 CHECK_PAGE_INIT(12, 11, 12, 11, 13, 12); |
|
924 |
|
925 // Fun stuff here. |
|
926 |
|
927 wizard.setOption(QWizard::IndependentPages, false); |
|
928 CHECK_PAGE_INIT(12, 11, 12, 11, 13, 13); |
|
929 |
|
930 wizard.setOption(QWizard::IndependentPages, true); |
|
931 CHECK_PAGE_INIT(12, 11, 12, 11, 13, 13); |
|
932 |
|
933 wizard.setOption(QWizard::IndependentPages, false); |
|
934 CHECK_PAGE_INIT(12, 11, 12, 11, 13, 13); |
|
935 |
|
936 wizard.back(); |
|
937 CHECK_PAGE_INIT(12, 11, 12, 12, 13, 13); |
|
938 |
|
939 wizard.back(); |
|
940 CHECK_PAGE_INIT(12, 11, 12, 12, 13, 13); |
|
941 } |
|
942 |
|
943 void tst_QWizard::setOption_IgnoreSubTitles() |
|
944 { |
|
945 #if defined(Q_OS_WINCE) |
|
946 QSKIP("Skipped because of limited resources and potential crash. (Task: 166824)", SkipAll); |
|
947 #endif |
|
948 QWizard wizard1; |
|
949 wizard1.setButtonLayout(QList<QWizard::WizardButton>() << QWizard::CancelButton); |
|
950 wizard1.resize(500, 500); |
|
951 QVERIFY(!wizard1.testOption(QWizard::IgnoreSubTitles)); |
|
952 QWizardPage *page11 = new QWizardPage; |
|
953 page11->setTitle("Page X"); |
|
954 page11->setSubTitle("Some subtitle"); |
|
955 |
|
956 QWizardPage *page12 = new QWizardPage; |
|
957 page12->setTitle("Page X"); |
|
958 |
|
959 wizard1.addPage(page11); |
|
960 wizard1.addPage(page12); |
|
961 |
|
962 QWizard wizard2; |
|
963 wizard2.setButtonLayout(QList<QWizard::WizardButton>() << QWizard::CancelButton); |
|
964 wizard2.resize(500, 500); |
|
965 wizard2.setOption(QWizard::IgnoreSubTitles, true); |
|
966 QWizardPage *page21 = new QWizardPage; |
|
967 page21->setTitle("Page X"); |
|
968 page21->setSubTitle("Some subtitle"); |
|
969 |
|
970 QWizardPage *page22 = new QWizardPage; |
|
971 page22->setTitle("Page X"); |
|
972 |
|
973 wizard2.addPage(page21); |
|
974 wizard2.addPage(page22); |
|
975 |
|
976 wizard1.show(); |
|
977 wizard2.show(); |
|
978 |
|
979 // Check that subtitles are shown when they should (i.e., |
|
980 // they're set and IgnoreSubTitles is off). |
|
981 |
|
982 qApp->setActiveWindow(0); // ensure no focus rectangle around cancel button |
|
983 QImage i11 = grabWidget(&wizard1); |
|
984 QImage i21 = grabWidget(&wizard2); |
|
985 QVERIFY(i11 != i21); |
|
986 |
|
987 wizard1.next(); |
|
988 wizard2.next(); |
|
989 |
|
990 QImage i12 = grabWidget(&wizard1); |
|
991 QImage i22 = grabWidget(&wizard2); |
|
992 QVERIFY(i12 == i22); |
|
993 QVERIFY(i21 == i22); |
|
994 |
|
995 wizard1.back(); |
|
996 wizard2.back(); |
|
997 |
|
998 QImage i13 = grabWidget(&wizard1); |
|
999 QImage i23 = grabWidget(&wizard2); |
|
1000 QVERIFY(i13 == i11); |
|
1001 QVERIFY(i23 == i21); |
|
1002 |
|
1003 wizard1.setOption(QWizard::IgnoreSubTitles, true); |
|
1004 wizard2.setOption(QWizard::IgnoreSubTitles, false); |
|
1005 |
|
1006 QImage i14 = grabWidget(&wizard1); |
|
1007 QImage i24 = grabWidget(&wizard2); |
|
1008 QVERIFY(i14 == i21); |
|
1009 QVERIFY(i24 == i11); |
|
1010 |
|
1011 // Check the impact of subtitles on the rest of the layout, by |
|
1012 // using a subtitle that looks empty (but that isn't). In |
|
1013 // Classic and Modern styles, this should be enough to trigger a |
|
1014 // "header"; in Mac style, this only creates a QLabel, with no |
|
1015 // text, i.e. it doesn't affect the layout. |
|
1016 |
|
1017 page11->setSubTitle("<b></b>"); // not quite empty, but looks empty |
|
1018 |
|
1019 for (int i = 0; i < 3; ++i) { |
|
1020 for (int j = 0; j < 2; ++j) { |
|
1021 wizard1.setOption(QWizard::IgnoreSubTitles, j == 0); |
|
1022 |
|
1023 wizard1.setWizardStyle(i == 0 ? QWizard::ClassicStyle |
|
1024 : i == 1 ? QWizard::ModernStyle |
|
1025 : QWizard::MacStyle); |
|
1026 wizard1.restart(); |
|
1027 QImage i1 = grabWidget(&wizard1); |
|
1028 |
|
1029 wizard1.next(); |
|
1030 QImage i2 = grabWidget(&wizard1); |
|
1031 |
|
1032 if (j == 0 || wizard1.wizardStyle() == QWizard::MacStyle) { |
|
1033 QVERIFY(i1 == i2); |
|
1034 } else { |
|
1035 QVERIFY(i1 != i2); |
|
1036 } |
|
1037 } |
|
1038 } |
|
1039 } |
|
1040 |
|
1041 void tst_QWizard::setOption_ExtendedWatermarkPixmap() |
|
1042 { |
|
1043 #if defined(Q_OS_WINCE) |
|
1044 QSKIP("Skipped because of limited resources and potential crash. (Task: 166824)", SkipAll); |
|
1045 #endif |
|
1046 QPixmap watermarkPixmap(200, 400); |
|
1047 watermarkPixmap.fill(Qt::black); |
|
1048 |
|
1049 QWizard wizard1; |
|
1050 wizard1.setButtonLayout(QList<QWizard::WizardButton>() << QWizard::CancelButton); |
|
1051 QVERIFY(!wizard1.testOption(QWizard::ExtendedWatermarkPixmap)); |
|
1052 QWizardPage *page11 = new QWizardPage; |
|
1053 page11->setTitle("Page X"); |
|
1054 page11->setPixmap(QWizard::WatermarkPixmap, watermarkPixmap); |
|
1055 |
|
1056 QWizardPage *page12 = new QWizardPage; |
|
1057 page12->setTitle("Page X"); |
|
1058 |
|
1059 wizard1.addPage(page11); |
|
1060 wizard1.addPage(page12); |
|
1061 |
|
1062 QWizard wizard2; |
|
1063 wizard2.setButtonLayout(QList<QWizard::WizardButton>() << QWizard::CancelButton); |
|
1064 wizard2.setOption(QWizard::ExtendedWatermarkPixmap, true); |
|
1065 QWizardPage *page21 = new QWizardPage; |
|
1066 page21->setTitle("Page X"); |
|
1067 page21->setPixmap(QWizard::WatermarkPixmap, watermarkPixmap); |
|
1068 |
|
1069 QWizardPage *page22 = new QWizardPage; |
|
1070 page22->setTitle("Page X"); |
|
1071 |
|
1072 wizard2.addPage(page21); |
|
1073 wizard2.addPage(page22); |
|
1074 |
|
1075 wizard1.show(); |
|
1076 wizard2.show(); |
|
1077 |
|
1078 // Check the impact of watermark pixmaps on the rest of the layout. |
|
1079 |
|
1080 for (int i = 0; i < 3; ++i) { |
|
1081 QImage i1[2]; |
|
1082 QImage i2[2]; |
|
1083 for (int j = 0; j < 2; ++j) { |
|
1084 wizard1.setOption(QWizard::ExtendedWatermarkPixmap, j == 0); |
|
1085 |
|
1086 wizard1.setWizardStyle(i == 0 ? QWizard::ClassicStyle |
|
1087 : i == 1 ? QWizard::ModernStyle |
|
1088 : QWizard::MacStyle); |
|
1089 wizard1.restart(); |
|
1090 wizard1.setMaximumSize(1000, 1000); |
|
1091 wizard1.resize(600, 600); |
|
1092 i1[j] = grabWidget(&wizard1); |
|
1093 |
|
1094 wizard1.next(); |
|
1095 wizard1.setMaximumSize(1000, 1000); |
|
1096 wizard1.resize(600, 600); |
|
1097 i2[j] = grabWidget(&wizard1); |
|
1098 } |
|
1099 |
|
1100 if (wizard1.wizardStyle() == QWizard::MacStyle) { |
|
1101 QVERIFY(i1[0] == i1[1]); |
|
1102 QVERIFY(i2[0] == i2[1]); |
|
1103 QVERIFY(i1[0] == i2[0]); |
|
1104 } else { |
|
1105 QVERIFY(i1[0] != i1[1]); |
|
1106 QVERIFY(i2[0] == i2[1]); |
|
1107 QVERIFY(i1[0] != i2[0]); |
|
1108 QVERIFY(i1[1] != i2[1]); |
|
1109 } |
|
1110 } |
|
1111 } |
|
1112 |
|
1113 void tst_QWizard::setOption_NoDefaultButton() |
|
1114 { |
|
1115 QWizard wizard; |
|
1116 wizard.setOption(QWizard::NoDefaultButton, false); |
|
1117 wizard.setOption(QWizard::HaveFinishButtonOnEarlyPages, true); |
|
1118 wizard.addPage(new QWizardPage); |
|
1119 wizard.page(0)->setFinalPage(true); |
|
1120 wizard.addPage(new QWizardPage); |
|
1121 |
|
1122 if (QPushButton *pb = qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))) |
|
1123 pb->setAutoDefault(false); |
|
1124 if (QPushButton *pb = qobject_cast<QPushButton *>(wizard.button(QWizard::FinishButton))) |
|
1125 pb->setAutoDefault(false); |
|
1126 |
|
1127 wizard.show(); |
|
1128 qApp->processEvents(); |
|
1129 QVERIFY(qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))->isDefault()); |
|
1130 QVERIFY(wizard.button(QWizard::FinishButton)->isEnabled()); |
|
1131 |
|
1132 wizard.next(); |
|
1133 QVERIFY(qobject_cast<QPushButton *>(wizard.button(QWizard::FinishButton))->isDefault()); |
|
1134 |
|
1135 wizard.back(); |
|
1136 QVERIFY(qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))->isDefault()); |
|
1137 |
|
1138 wizard.setOption(QWizard::NoDefaultButton, true); |
|
1139 QVERIFY(!qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))->isDefault()); |
|
1140 QVERIFY(!qobject_cast<QPushButton *>(wizard.button(QWizard::FinishButton))->isDefault()); |
|
1141 |
|
1142 wizard.next(); |
|
1143 QVERIFY(!qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))->isDefault()); |
|
1144 QVERIFY(!qobject_cast<QPushButton *>(wizard.button(QWizard::FinishButton))->isDefault()); |
|
1145 |
|
1146 wizard.back(); |
|
1147 QVERIFY(!qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))->isDefault()); |
|
1148 QVERIFY(!qobject_cast<QPushButton *>(wizard.button(QWizard::FinishButton))->isDefault()); |
|
1149 |
|
1150 wizard.setOption(QWizard::NoDefaultButton, false); |
|
1151 QVERIFY(qobject_cast<QPushButton *>(wizard.button(QWizard::NextButton))->isDefault()); |
|
1152 } |
|
1153 |
|
1154 void tst_QWizard::setOption_NoBackButtonOnStartPage() |
|
1155 { |
|
1156 QWizard wizard; |
|
1157 wizard.setOption(QWizard::NoBackButtonOnStartPage, true); |
|
1158 wizard.addPage(new QWizardPage); |
|
1159 wizard.addPage(new QWizardPage); |
|
1160 wizard.addPage(new QWizardPage); |
|
1161 |
|
1162 wizard.setStartId(1); |
|
1163 wizard.show(); |
|
1164 qApp->processEvents(); |
|
1165 |
|
1166 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1167 |
|
1168 wizard.setOption(QWizard::NoBackButtonOnStartPage, false); |
|
1169 qApp->processEvents(); |
|
1170 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1171 |
|
1172 wizard.setOption(QWizard::NoBackButtonOnStartPage, true); |
|
1173 qApp->processEvents(); |
|
1174 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1175 |
|
1176 wizard.next(); |
|
1177 qApp->processEvents(); |
|
1178 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1179 |
|
1180 wizard.setOption(QWizard::NoBackButtonOnStartPage, false); |
|
1181 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1182 |
|
1183 wizard.setOption(QWizard::NoBackButtonOnStartPage, true); |
|
1184 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1185 |
|
1186 wizard.back(); |
|
1187 qApp->processEvents(); |
|
1188 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1189 } |
|
1190 |
|
1191 void tst_QWizard::setOption_NoBackButtonOnLastPage() |
|
1192 { |
|
1193 for (int i = 0; i < 2; ++i) { |
|
1194 QWizard wizard; |
|
1195 wizard.setOption(QWizard::NoBackButtonOnStartPage, false); |
|
1196 wizard.setOption(QWizard::NoBackButtonOnLastPage, true); |
|
1197 wizard.setOption(QWizard::DisabledBackButtonOnLastPage, i == 0); // changes nothing |
|
1198 wizard.addPage(new QWizardPage); |
|
1199 wizard.addPage(new QWizardPage); |
|
1200 wizard.page(1)->setFinalPage(true); // changes nothing (final != last in general) |
|
1201 wizard.addPage(new QWizardPage); |
|
1202 |
|
1203 wizard.setStartId(1); |
|
1204 wizard.show(); |
|
1205 qApp->processEvents(); |
|
1206 |
|
1207 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1208 |
|
1209 wizard.next(); |
|
1210 qApp->processEvents(); |
|
1211 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1212 |
|
1213 wizard.next(); |
|
1214 qApp->processEvents(); |
|
1215 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1216 |
|
1217 wizard.back(); |
|
1218 qApp->processEvents(); |
|
1219 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1220 |
|
1221 wizard.next(); |
|
1222 qApp->processEvents(); |
|
1223 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1224 |
|
1225 wizard.setOption(QWizard::NoBackButtonOnLastPage, false); |
|
1226 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1227 |
|
1228 wizard.setOption(QWizard::NoBackButtonOnLastPage, true); |
|
1229 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); |
|
1230 |
|
1231 wizard.addPage(new QWizardPage); |
|
1232 QVERIFY(!wizard.button(QWizard::BackButton)->isVisible()); // this is maybe wrong |
|
1233 } |
|
1234 } |
|
1235 |
|
1236 void tst_QWizard::setOption_DisabledBackButtonOnLastPage() |
|
1237 { |
|
1238 QWizard wizard; |
|
1239 wizard.setOption(QWizard::NoBackButtonOnStartPage, false); |
|
1240 wizard.setOption(QWizard::DisabledBackButtonOnLastPage, true); |
|
1241 wizard.addPage(new QWizardPage); |
|
1242 wizard.addPage(new QWizardPage); |
|
1243 wizard.page(1)->setFinalPage(true); // changes nothing (final != last in general) |
|
1244 wizard.addPage(new QWizardPage); |
|
1245 |
|
1246 wizard.setStartId(1); |
|
1247 wizard.show(); |
|
1248 qApp->processEvents(); |
|
1249 |
|
1250 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1251 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
1252 |
|
1253 wizard.next(); |
|
1254 qApp->processEvents(); |
|
1255 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
1256 |
|
1257 wizard.next(); |
|
1258 qApp->processEvents(); |
|
1259 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
1260 |
|
1261 wizard.back(); |
|
1262 qApp->processEvents(); |
|
1263 QVERIFY(wizard.button(QWizard::BackButton)->isVisible()); |
|
1264 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
1265 |
|
1266 wizard.next(); |
|
1267 qApp->processEvents(); |
|
1268 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
1269 |
|
1270 wizard.setOption(QWizard::DisabledBackButtonOnLastPage, false); |
|
1271 QVERIFY(wizard.button(QWizard::BackButton)->isEnabled()); |
|
1272 |
|
1273 wizard.setOption(QWizard::DisabledBackButtonOnLastPage, true); |
|
1274 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
1275 |
|
1276 wizard.addPage(new QWizardPage); |
|
1277 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); // this is maybe wrong |
|
1278 } |
|
1279 |
|
1280 void tst_QWizard::setOption_HaveNextButtonOnLastPage() |
|
1281 { |
|
1282 QWizard wizard; |
|
1283 wizard.setOption(QWizard::HaveNextButtonOnLastPage, false); |
|
1284 wizard.addPage(new QWizardPage); |
|
1285 wizard.addPage(new QWizardPage); |
|
1286 wizard.page(1)->setFinalPage(true); // changes nothing (final != last in general) |
|
1287 wizard.addPage(new QWizardPage); |
|
1288 |
|
1289 wizard.setStartId(1); |
|
1290 wizard.show(); |
|
1291 qApp->processEvents(); |
|
1292 |
|
1293 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
1294 QVERIFY(wizard.button(QWizard::NextButton)->isEnabled()); |
|
1295 |
|
1296 wizard.next(); |
|
1297 QVERIFY(!wizard.button(QWizard::NextButton)->isVisible()); |
|
1298 |
|
1299 wizard.setOption(QWizard::HaveNextButtonOnLastPage, true); |
|
1300 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
1301 QVERIFY(!wizard.button(QWizard::NextButton)->isEnabled()); |
|
1302 |
|
1303 wizard.next(); |
|
1304 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
1305 QVERIFY(!wizard.button(QWizard::NextButton)->isEnabled()); |
|
1306 |
|
1307 wizard.back(); |
|
1308 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
1309 QVERIFY(wizard.button(QWizard::NextButton)->isEnabled()); |
|
1310 |
|
1311 wizard.setOption(QWizard::HaveNextButtonOnLastPage, false); |
|
1312 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
1313 QVERIFY(wizard.button(QWizard::NextButton)->isEnabled()); |
|
1314 |
|
1315 wizard.next(); |
|
1316 QVERIFY(!wizard.button(QWizard::NextButton)->isVisible()); |
|
1317 |
|
1318 wizard.setOption(QWizard::HaveNextButtonOnLastPage, true); |
|
1319 QVERIFY(wizard.button(QWizard::NextButton)->isVisible()); |
|
1320 QVERIFY(!wizard.button(QWizard::NextButton)->isEnabled()); |
|
1321 } |
|
1322 |
|
1323 void tst_QWizard::setOption_HaveFinishButtonOnEarlyPages() |
|
1324 { |
|
1325 QWizard wizard; |
|
1326 QVERIFY(!wizard.testOption(QWizard::HaveFinishButtonOnEarlyPages)); |
|
1327 wizard.addPage(new QWizardPage); |
|
1328 wizard.addPage(new QWizardPage); |
|
1329 wizard.page(1)->setFinalPage(true); |
|
1330 wizard.addPage(new QWizardPage); |
|
1331 |
|
1332 wizard.show(); |
|
1333 qApp->processEvents(); |
|
1334 |
|
1335 QVERIFY(!wizard.button(QWizard::FinishButton)->isVisible()); |
|
1336 |
|
1337 wizard.next(); |
|
1338 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
1339 |
|
1340 wizard.next(); |
|
1341 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
1342 |
|
1343 wizard.back(); |
|
1344 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
1345 |
|
1346 wizard.back(); |
|
1347 QVERIFY(!wizard.button(QWizard::FinishButton)->isVisible()); |
|
1348 |
|
1349 wizard.setOption(QWizard::HaveFinishButtonOnEarlyPages, true); |
|
1350 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
1351 |
|
1352 wizard.next(); |
|
1353 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
1354 |
|
1355 wizard.setOption(QWizard::HaveFinishButtonOnEarlyPages, false); |
|
1356 QVERIFY(wizard.button(QWizard::FinishButton)->isVisible()); |
|
1357 |
|
1358 wizard.back(); |
|
1359 QVERIFY(!wizard.button(QWizard::FinishButton)->isVisible()); |
|
1360 } |
|
1361 |
|
1362 void tst_QWizard::setOption_NoCancelButton() |
|
1363 { |
|
1364 for (int i = 0; i < 2; ++i) { |
|
1365 QWizard wizard; |
|
1366 wizard.setOption(QWizard::NoCancelButton, true); |
|
1367 wizard.setOption(QWizard::CancelButtonOnLeft, i == 0); |
|
1368 wizard.addPage(new QWizardPage); |
|
1369 wizard.addPage(new QWizardPage); |
|
1370 wizard.show(); |
|
1371 qApp->processEvents(); |
|
1372 |
|
1373 QVERIFY(!wizard.button(QWizard::CancelButton)->isVisible()); |
|
1374 |
|
1375 wizard.next(); |
|
1376 QVERIFY(!wizard.button(QWizard::CancelButton)->isVisible()); |
|
1377 |
|
1378 wizard.setOption(QWizard::NoCancelButton, false); |
|
1379 QVERIFY(wizard.button(QWizard::CancelButton)->isVisible()); |
|
1380 |
|
1381 wizard.back(); |
|
1382 QVERIFY(wizard.button(QWizard::CancelButton)->isVisible()); |
|
1383 |
|
1384 wizard.setOption(QWizard::NoCancelButton, true); |
|
1385 QVERIFY(!wizard.button(QWizard::CancelButton)->isVisible()); |
|
1386 } |
|
1387 } |
|
1388 |
|
1389 void tst_QWizard::setOption_CancelButtonOnLeft() |
|
1390 { |
|
1391 for (int i = 0; i < 2; ++i) { |
|
1392 int sign = (i == 0) ? +1 : -1; |
|
1393 |
|
1394 QWizard wizard; |
|
1395 wizard.setLayoutDirection(i == 0 ? Qt::LeftToRight : Qt::RightToLeft); |
|
1396 wizard.setOption(QWizard::NoCancelButton, false); |
|
1397 wizard.setOption(QWizard::CancelButtonOnLeft, true); |
|
1398 wizard.setOption(QWizard::NoBackButtonOnStartPage, false); |
|
1399 wizard.addPage(new QWizardPage); |
|
1400 wizard.addPage(new QWizardPage); |
|
1401 wizard.show(); |
|
1402 qApp->processEvents(); |
|
1403 |
|
1404 const QAbstractButton *refButton = wizard.button((wizard.wizardStyle() == QWizard::AeroStyle) |
|
1405 ? QWizard::NextButton : QWizard::BackButton); |
|
1406 const QAbstractButton *refButton2 = wizard.button((wizard.wizardStyle() == QWizard::AeroStyle) |
|
1407 ? QWizard::FinishButton : QWizard::BackButton); |
|
1408 |
|
1409 QVERIFY(sign * wizard.button(QWizard::CancelButton)->x() < sign * refButton->x()); |
|
1410 |
|
1411 wizard.next(); |
|
1412 qApp->processEvents(); |
|
1413 QVERIFY(sign * wizard.button(QWizard::CancelButton)->x() < sign * refButton->x()); |
|
1414 |
|
1415 wizard.setOption(QWizard::CancelButtonOnLeft, false); |
|
1416 qApp->processEvents(); |
|
1417 QVERIFY(sign * wizard.button(QWizard::CancelButton)->x() > sign * refButton2->x()); |
|
1418 |
|
1419 wizard.back(); |
|
1420 qApp->processEvents(); |
|
1421 QVERIFY(sign * wizard.button(QWizard::CancelButton)->x() > sign * refButton->x()); |
|
1422 } |
|
1423 } |
|
1424 |
|
1425 void tst_QWizard::setOption_HaveHelpButton() |
|
1426 { |
|
1427 for (int i = 0; i < 2; ++i) { |
|
1428 QWizard wizard; |
|
1429 QVERIFY(!wizard.testOption(QWizard::HaveHelpButton)); |
|
1430 wizard.setOption(QWizard::HaveHelpButton, false); |
|
1431 wizard.setOption(QWizard::HelpButtonOnRight, i == 0); |
|
1432 wizard.addPage(new QWizardPage); |
|
1433 wizard.addPage(new QWizardPage); |
|
1434 wizard.show(); |
|
1435 qApp->processEvents(); |
|
1436 |
|
1437 QVERIFY(!wizard.button(QWizard::HelpButton)->isVisible()); |
|
1438 |
|
1439 wizard.next(); |
|
1440 QVERIFY(!wizard.button(QWizard::HelpButton)->isVisible()); |
|
1441 |
|
1442 wizard.setOption(QWizard::HaveHelpButton, true); |
|
1443 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
1444 |
|
1445 wizard.back(); |
|
1446 QVERIFY(wizard.button(QWizard::HelpButton)->isVisible()); |
|
1447 |
|
1448 wizard.setOption(QWizard::HaveHelpButton, false); |
|
1449 QVERIFY(!wizard.button(QWizard::HelpButton)->isVisible()); |
|
1450 } |
|
1451 } |
|
1452 |
|
1453 void tst_QWizard::setOption_HelpButtonOnRight() |
|
1454 { |
|
1455 for (int i = 0; i < 2; ++i) { |
|
1456 int sign = (i == 0) ? +1 : -1; |
|
1457 |
|
1458 QWizard wizard; |
|
1459 wizard.setLayoutDirection(i == 0 ? Qt::LeftToRight : Qt::RightToLeft); |
|
1460 wizard.setOption(QWizard::HaveHelpButton, true); |
|
1461 wizard.setOption(QWizard::HelpButtonOnRight, false); |
|
1462 wizard.setOption(QWizard::NoBackButtonOnStartPage, false); |
|
1463 wizard.addPage(new QWizardPage); |
|
1464 wizard.addPage(new QWizardPage); |
|
1465 wizard.show(); |
|
1466 qApp->processEvents(); |
|
1467 |
|
1468 const QAbstractButton *refButton = wizard.button((wizard.wizardStyle() == QWizard::AeroStyle) |
|
1469 ? QWizard::NextButton : QWizard::BackButton); |
|
1470 |
|
1471 QVERIFY(sign * wizard.button(QWizard::HelpButton)->x() < sign * refButton->x()); |
|
1472 |
|
1473 wizard.next(); |
|
1474 qApp->processEvents(); |
|
1475 QVERIFY(sign * wizard.button(QWizard::HelpButton)->x() < sign * refButton->x()); |
|
1476 |
|
1477 wizard.setOption(QWizard::HelpButtonOnRight, true); |
|
1478 qApp->processEvents(); |
|
1479 QVERIFY(sign * wizard.button(QWizard::HelpButton)->x() > sign * refButton->x()); |
|
1480 |
|
1481 wizard.back(); |
|
1482 qApp->processEvents(); |
|
1483 QVERIFY(sign * wizard.button(QWizard::HelpButton)->x() > sign * refButton->x()); |
|
1484 } |
|
1485 } |
|
1486 |
|
1487 void tst_QWizard::setOption_HaveCustomButtonX() |
|
1488 { |
|
1489 for (int i = 0; i < 2; ++i) { |
|
1490 for (int j = 0; j < 2; ++j) { |
|
1491 for (int k = 0; k < 2; ++k) { |
|
1492 QWizard wizard; |
|
1493 wizard.setLayoutDirection(Qt::LeftToRight); |
|
1494 wizard.addPage(new QWizardPage); |
|
1495 wizard.addPage(new QWizardPage); |
|
1496 wizard.show(); |
|
1497 |
|
1498 wizard.setButtonText(QWizard::CustomButton1, "Foo"); |
|
1499 wizard.setButton(QWizard::CustomButton2, new QCheckBox("Bar")); |
|
1500 wizard.button(QWizard::CustomButton3)->setText("Baz"); |
|
1501 |
|
1502 wizard.setOption(QWizard::HaveCustomButton1, i == 0); |
|
1503 wizard.setOption(QWizard::HaveCustomButton2, j == 0); |
|
1504 wizard.setOption(QWizard::HaveCustomButton3, k == 0); |
|
1505 |
|
1506 QVERIFY(wizard.button(QWizard::CustomButton1)->isHidden() == (i != 0)); |
|
1507 QVERIFY(wizard.button(QWizard::CustomButton2)->isHidden() == (j != 0)); |
|
1508 QVERIFY(wizard.button(QWizard::CustomButton3)->isHidden() == (k != 0)); |
|
1509 |
|
1510 if (i + j + k == 0) { |
|
1511 qApp->processEvents(); |
|
1512 QVERIFY(wizard.button(QWizard::CustomButton1)->x() |
|
1513 < wizard.button(QWizard::CustomButton2)->x()); |
|
1514 QVERIFY(wizard.button(QWizard::CustomButton2)->x() |
|
1515 < wizard.button(QWizard::CustomButton3)->x()); |
|
1516 } |
|
1517 } |
|
1518 } |
|
1519 } |
|
1520 } |
|
1521 |
|
1522 class Operation |
|
1523 { |
|
1524 public: |
|
1525 virtual void apply(QWizard *) const = 0; |
|
1526 virtual QString describe() const = 0; |
|
1527 protected: |
|
1528 virtual ~Operation() {} |
|
1529 }; |
|
1530 |
|
1531 class SetPage : public Operation |
|
1532 { |
|
1533 void apply(QWizard *wizard) const |
|
1534 { |
|
1535 wizard->restart(); |
|
1536 for (int j = 0; j < page; ++j) |
|
1537 wizard->next(); |
|
1538 } |
|
1539 QString describe() const { return QString("set page %1").arg(page); } |
|
1540 const int page; |
|
1541 public: |
|
1542 SetPage(int page) : page(page) {} |
|
1543 }; |
|
1544 |
|
1545 class SetStyle : public Operation |
|
1546 { |
|
1547 void apply(QWizard *wizard) const { wizard->setWizardStyle(style); } |
|
1548 QString describe() const { return QString("set style %1").arg(style); } |
|
1549 const QWizard::WizardStyle style; |
|
1550 public: |
|
1551 SetStyle(QWizard::WizardStyle style) : style(style) {} |
|
1552 }; |
|
1553 |
|
1554 class SetOption : public Operation |
|
1555 { |
|
1556 void apply(QWizard *wizard) const { wizard->setOption(option, on); } |
|
1557 QString describe() const; |
|
1558 const QWizard::WizardOption option; |
|
1559 const bool on; |
|
1560 public: |
|
1561 SetOption(QWizard::WizardOption option, bool on) : option(option), on(on) {} |
|
1562 }; |
|
1563 |
|
1564 class OptionInfo |
|
1565 { |
|
1566 OptionInfo() |
|
1567 { |
|
1568 tags[QWizard::IndependentPages] = "0/IPP"; |
|
1569 tags[QWizard::IgnoreSubTitles] = "1/IST"; |
|
1570 tags[QWizard::ExtendedWatermarkPixmap] = "2/EWP"; |
|
1571 tags[QWizard::NoDefaultButton] = "3/NDB"; |
|
1572 tags[QWizard::NoBackButtonOnStartPage] = "4/BSP"; |
|
1573 tags[QWizard::NoBackButtonOnLastPage] = "5/BLP"; |
|
1574 tags[QWizard::DisabledBackButtonOnLastPage] = "6/DLP"; |
|
1575 tags[QWizard::HaveNextButtonOnLastPage] = "7/NLP"; |
|
1576 tags[QWizard::HaveFinishButtonOnEarlyPages] = "8/FEP"; |
|
1577 tags[QWizard::NoCancelButton] = "9/NCB"; |
|
1578 tags[QWizard::CancelButtonOnLeft] = "10/CBL"; |
|
1579 tags[QWizard::HaveHelpButton] = "11/HHB"; |
|
1580 tags[QWizard::HelpButtonOnRight] = "12/HBR"; |
|
1581 tags[QWizard::HaveCustomButton1] = "13/CB1"; |
|
1582 tags[QWizard::HaveCustomButton2] = "14/CB2"; |
|
1583 tags[QWizard::HaveCustomButton3] = "15/CB3"; |
|
1584 |
|
1585 for (int i = 0; i < 2; ++i) { |
|
1586 QMap<QWizard::WizardOption, Operation *> operations_; |
|
1587 foreach (QWizard::WizardOption option, tags.keys()) |
|
1588 operations_[option] = new SetOption(option, i == 1); |
|
1589 operations << operations_; |
|
1590 } |
|
1591 } |
|
1592 OptionInfo(OptionInfo const&); |
|
1593 OptionInfo& operator=(OptionInfo const&); |
|
1594 QMap<QWizard::WizardOption, QString> tags; |
|
1595 QList<QMap<QWizard::WizardOption, Operation *> > operations; |
|
1596 public: |
|
1597 static OptionInfo &instance() |
|
1598 { |
|
1599 static OptionInfo optionInfo; |
|
1600 return optionInfo; |
|
1601 } |
|
1602 |
|
1603 QString tag(QWizard::WizardOption option) const { return tags.value(option); } |
|
1604 Operation * operation(QWizard::WizardOption option, bool on) const |
|
1605 { return operations.at(on).value(option); } |
|
1606 QList<QWizard::WizardOption> options() const { return tags.keys(); } |
|
1607 }; |
|
1608 |
|
1609 QString SetOption::describe() const |
|
1610 { |
|
1611 return QString("set opt %1 %2").arg(OptionInfo::instance().tag(option)).arg(on); |
|
1612 } |
|
1613 |
|
1614 Q_DECLARE_METATYPE(Operation *) |
|
1615 Q_DECLARE_METATYPE(SetPage *) |
|
1616 Q_DECLARE_METATYPE(SetStyle *) |
|
1617 Q_DECLARE_METATYPE(SetOption *) |
|
1618 Q_DECLARE_METATYPE(QList<Operation *>) |
|
1619 |
|
1620 class TestGroup |
|
1621 { |
|
1622 public: |
|
1623 enum Type {Equality, NonEquality}; |
|
1624 |
|
1625 TestGroup(const QString &name = QString("no name"), Type type = Equality) |
|
1626 : name(name), type(type), nRows_(0) {} |
|
1627 |
|
1628 void reset(const QString &name, Type type = Equality) |
|
1629 { |
|
1630 this->name = name; |
|
1631 this->type = type; |
|
1632 combinations.clear(); |
|
1633 } |
|
1634 |
|
1635 QList<Operation *> &add() |
|
1636 { combinations << new QList<Operation *>; return *(combinations.last()); } |
|
1637 |
|
1638 void createTestRows() |
|
1639 { |
|
1640 for (int i = 0; i < combinations.count(); ++i) { |
|
1641 QTest::newRow((name + QString(", row %1").arg(i)).toLatin1().data()) |
|
1642 << (i == 0) << (type == Equality) << *(combinations.at(i)); |
|
1643 ++nRows_; |
|
1644 } |
|
1645 } |
|
1646 |
|
1647 int nRows() const { return nRows_; } |
|
1648 |
|
1649 private: |
|
1650 QString name; |
|
1651 Type type; |
|
1652 int nRows_; |
|
1653 QList<QList<Operation *> *> combinations; |
|
1654 }; |
|
1655 |
|
1656 class IntroPage : public QWizardPage |
|
1657 { |
|
1658 Q_OBJECT |
|
1659 public: |
|
1660 IntroPage() |
|
1661 { |
|
1662 setTitle(tr("Intro")); |
|
1663 setSubTitle(tr("Intro Subtitle")); |
|
1664 QVBoxLayout *layout = new QVBoxLayout; |
|
1665 layout->addWidget(new QLabel(tr("Intro Label"))); |
|
1666 setLayout(layout); |
|
1667 } |
|
1668 }; |
|
1669 |
|
1670 class MiddlePage : public QWizardPage |
|
1671 { |
|
1672 Q_OBJECT |
|
1673 public: |
|
1674 MiddlePage() |
|
1675 { |
|
1676 setTitle(tr("Middle")); |
|
1677 setSubTitle(tr("Middle Subtitle")); |
|
1678 QVBoxLayout *layout = new QVBoxLayout; |
|
1679 layout->addWidget(new QLabel(tr("Middle Label"))); |
|
1680 setLayout(layout); |
|
1681 } |
|
1682 }; |
|
1683 |
|
1684 class ConclusionPage : public QWizardPage |
|
1685 { |
|
1686 Q_OBJECT |
|
1687 public: |
|
1688 ConclusionPage() |
|
1689 { |
|
1690 setTitle(tr("Conclusion")); |
|
1691 setSubTitle(tr("Conclusion Subtitle")); |
|
1692 QVBoxLayout *layout = new QVBoxLayout; |
|
1693 layout->addWidget(new QLabel(tr("Conclusion Label"))); |
|
1694 setLayout(layout); |
|
1695 } |
|
1696 }; |
|
1697 |
|
1698 class TestWizard : public QWizard |
|
1699 { |
|
1700 Q_OBJECT |
|
1701 QList<int> pageIds; |
|
1702 QString opsDescr; |
|
1703 public: |
|
1704 TestWizard() |
|
1705 { |
|
1706 setPixmap(QWizard::BannerPixmap, QPixmap(":/images/banner.png")); |
|
1707 setPixmap(QWizard::BackgroundPixmap, QPixmap(":/images/background.png")); |
|
1708 setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png")); |
|
1709 setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png")); |
|
1710 setButtonText(QWizard::CustomButton1, "custom 1"); |
|
1711 setButtonText(QWizard::CustomButton2, "custom 2"); |
|
1712 setButtonText(QWizard::CustomButton3, "custom 3"); |
|
1713 pageIds << addPage(new IntroPage); |
|
1714 pageIds << addPage(new MiddlePage); |
|
1715 pageIds << addPage(new ConclusionPage); |
|
1716 |
|
1717 // Disable antialiased font rendering since this may sometimes result in tiny |
|
1718 // and (apparent) non-deterministic pixel variations between images expected to be |
|
1719 // identical. This may only be a problem on X11. |
|
1720 QFont f = font(); |
|
1721 f.setStyleStrategy(QFont::NoAntialias); |
|
1722 setFont(f); |
|
1723 |
|
1724 // ### Required to work with a deficiency(?) in QWizard: |
|
1725 // setFixedSize(800, 600); |
|
1726 } |
|
1727 |
|
1728 ~TestWizard() |
|
1729 { |
|
1730 foreach (int id, pageIds) |
|
1731 delete page(id); |
|
1732 } |
|
1733 |
|
1734 void applyOperations(const QList<Operation *> &operations) |
|
1735 { |
|
1736 foreach (Operation * op, operations) { |
|
1737 if (op) { |
|
1738 op->apply(this); |
|
1739 opsDescr += QString("(%1) ").arg(op->describe()); |
|
1740 } |
|
1741 } |
|
1742 } |
|
1743 |
|
1744 QImage createImage() const |
|
1745 { |
|
1746 return QPixmap::grabWidget(const_cast<TestWizard *>(this)) |
|
1747 .toImage().convertToFormat(QImage::Format_ARGB32); |
|
1748 } |
|
1749 |
|
1750 QString operationsDescription() const { return opsDescr; } |
|
1751 }; |
|
1752 |
|
1753 class CombinationsTestData |
|
1754 { |
|
1755 TestGroup testGroup; |
|
1756 QList<Operation *> pageOps; |
|
1757 QList<Operation *> styleOps; |
|
1758 QMap<bool, QList<Operation *> *> setAllOptions; |
|
1759 public: |
|
1760 CombinationsTestData() |
|
1761 { |
|
1762 QTest::addColumn<bool>("ref"); |
|
1763 QTest::addColumn<bool>("testEquality"); |
|
1764 QTest::addColumn<QList<Operation *> >("operations"); |
|
1765 pageOps << new SetPage(0) << new SetPage(1) << new SetPage(2); |
|
1766 styleOps << new SetStyle(QWizard::ClassicStyle) << new SetStyle(QWizard::ModernStyle) |
|
1767 << new SetStyle(QWizard::MacStyle); |
|
1768 #define SETPAGE(page) pageOps.at(page) |
|
1769 #define SETSTYLE(style) styleOps.at(style) |
|
1770 #define OPT(option, on) OptionInfo::instance().operation(option, on) |
|
1771 #define CLROPT(option) OPT(option, false) |
|
1772 #define SETOPT(option) OPT(option, true) |
|
1773 setAllOptions[false] = new QList<Operation *>; |
|
1774 setAllOptions[true] = new QList<Operation *>; |
|
1775 foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { |
|
1776 *setAllOptions.value(false) << CLROPT(option); |
|
1777 *setAllOptions.value(true) << SETOPT(option); |
|
1778 } |
|
1779 #define CLRALLOPTS *setAllOptions.value(false) |
|
1780 #define SETALLOPTS *setAllOptions.value(true) |
|
1781 } |
|
1782 |
|
1783 int nRows() const { return testGroup.nRows(); } |
|
1784 |
|
1785 // Creates "all" possible test rows. (WARNING: This typically makes the test take too long!) |
|
1786 void createAllTestRows() |
|
1787 { |
|
1788 testGroup.reset("testAll 1.1"); |
|
1789 testGroup.add(); // i.e. no operations applied! |
|
1790 testGroup.add() << SETPAGE(0); |
|
1791 testGroup.add() << SETSTYLE(0); |
|
1792 testGroup.add() << SETPAGE(0) << SETSTYLE(0); |
|
1793 testGroup.add() << SETSTYLE(0) << SETPAGE(0); |
|
1794 testGroup.createTestRows(); |
|
1795 |
|
1796 testGroup.reset("testAll 2.1"); |
|
1797 testGroup.add(); |
|
1798 testGroup.add() << CLRALLOPTS; |
|
1799 testGroup.createTestRows(); |
|
1800 |
|
1801 testGroup.reset("testAll 2.2"); |
|
1802 testGroup.add() << SETALLOPTS; |
|
1803 testGroup.add() << SETALLOPTS << SETALLOPTS; |
|
1804 testGroup.createTestRows(); |
|
1805 |
|
1806 testGroup.reset("testAll 2.3"); |
|
1807 testGroup.add() << CLRALLOPTS; |
|
1808 testGroup.add() << CLRALLOPTS << CLRALLOPTS; |
|
1809 testGroup.createTestRows(); |
|
1810 |
|
1811 testGroup.reset("testAll 2.4"); |
|
1812 testGroup.add() << CLRALLOPTS; |
|
1813 testGroup.add() << SETALLOPTS << CLRALLOPTS; |
|
1814 testGroup.createTestRows(); |
|
1815 |
|
1816 testGroup.reset("testAll 2.5"); |
|
1817 testGroup.add() << SETALLOPTS; |
|
1818 testGroup.add() << CLRALLOPTS << SETALLOPTS; |
|
1819 testGroup.createTestRows(); |
|
1820 |
|
1821 testGroup.reset("testAll 2.6"); |
|
1822 testGroup.add() << SETALLOPTS; |
|
1823 testGroup.add() << SETALLOPTS << CLRALLOPTS << SETALLOPTS; |
|
1824 testGroup.createTestRows(); |
|
1825 |
|
1826 testGroup.reset("testAll 2.7"); |
|
1827 testGroup.add() << CLRALLOPTS; |
|
1828 testGroup.add() << CLRALLOPTS << SETALLOPTS << CLRALLOPTS; |
|
1829 testGroup.createTestRows(); |
|
1830 |
|
1831 for (int i = 0; i < 2; ++i) { |
|
1832 QList<Operation *> setOptions = *setAllOptions.value(i == 1); |
|
1833 |
|
1834 testGroup.reset("testAll 3.1"); |
|
1835 testGroup.add() << setOptions; |
|
1836 testGroup.add() << SETPAGE(0) << setOptions; |
|
1837 testGroup.add() << setOptions << SETPAGE(0); |
|
1838 testGroup.add() << SETSTYLE(0) << setOptions; |
|
1839 testGroup.add() << setOptions << SETSTYLE(0); |
|
1840 testGroup.add() << setOptions << SETPAGE(0) << SETSTYLE(0); |
|
1841 testGroup.add() << SETPAGE(0) << setOptions << SETSTYLE(0); |
|
1842 testGroup.add() << SETPAGE(0) << SETSTYLE(0) << setOptions; |
|
1843 testGroup.add() << setOptions << SETSTYLE(0) << SETPAGE(0); |
|
1844 testGroup.add() << SETSTYLE(0) << setOptions << SETPAGE(0); |
|
1845 testGroup.add() << SETSTYLE(0) << SETPAGE(0) << setOptions; |
|
1846 testGroup.createTestRows(); |
|
1847 } |
|
1848 |
|
1849 foreach (Operation *pageOp, pageOps) { |
|
1850 testGroup.reset("testAll 4.1"); |
|
1851 testGroup.add() << pageOp; |
|
1852 testGroup.add() << pageOp << pageOp; |
|
1853 testGroup.createTestRows(); |
|
1854 |
|
1855 for (int i = 0; i < 2; ++i) { |
|
1856 QList<Operation *> optionOps = *setAllOptions.value(i == 1); |
|
1857 testGroup.reset("testAll 4.2"); |
|
1858 testGroup.add() << optionOps << pageOp; |
|
1859 testGroup.add() << pageOp << optionOps; |
|
1860 testGroup.createTestRows(); |
|
1861 |
|
1862 foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { |
|
1863 Operation *optionOp = OPT(option, i == 1); |
|
1864 testGroup.reset("testAll 4.3"); |
|
1865 testGroup.add() << optionOp << pageOp; |
|
1866 testGroup.add() << pageOp << optionOp; |
|
1867 testGroup.createTestRows(); |
|
1868 } |
|
1869 } |
|
1870 } |
|
1871 |
|
1872 foreach (Operation *styleOp, styleOps) { |
|
1873 testGroup.reset("testAll 5.1"); |
|
1874 testGroup.add() << styleOp; |
|
1875 testGroup.add() << styleOp << styleOp; |
|
1876 testGroup.createTestRows(); |
|
1877 |
|
1878 for (int i = 0; i < 2; ++i) { |
|
1879 QList<Operation *> optionOps = *setAllOptions.value(i == 1); |
|
1880 testGroup.reset("testAll 5.2"); |
|
1881 testGroup.add() << optionOps << styleOp; |
|
1882 testGroup.add() << styleOp << optionOps; |
|
1883 testGroup.createTestRows(); |
|
1884 |
|
1885 foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { |
|
1886 Operation *optionOp = OPT(option, i == 1); |
|
1887 testGroup.reset("testAll 5.3"); |
|
1888 testGroup.add() << optionOp << styleOp; |
|
1889 testGroup.add() << styleOp << optionOp; |
|
1890 testGroup.createTestRows(); |
|
1891 } |
|
1892 } |
|
1893 } |
|
1894 |
|
1895 foreach (Operation *pageOp, pageOps) { |
|
1896 foreach (Operation *styleOp, styleOps) { |
|
1897 |
|
1898 testGroup.reset("testAll 6.1"); |
|
1899 testGroup.add() << pageOp; |
|
1900 testGroup.add() << pageOp << pageOp; |
|
1901 testGroup.createTestRows(); |
|
1902 |
|
1903 testGroup.reset("testAll 6.2"); |
|
1904 testGroup.add() << styleOp; |
|
1905 testGroup.add() << styleOp << styleOp; |
|
1906 testGroup.createTestRows(); |
|
1907 |
|
1908 testGroup.reset("testAll 6.3"); |
|
1909 testGroup.add() << pageOp << styleOp; |
|
1910 testGroup.add() << styleOp << pageOp; |
|
1911 testGroup.createTestRows(); |
|
1912 |
|
1913 for (int i = 0; i < 2; ++i) { |
|
1914 QList<Operation *> optionOps = *setAllOptions.value(i == 1); |
|
1915 testGroup.reset("testAll 6.4"); |
|
1916 testGroup.add() << optionOps << pageOp << styleOp; |
|
1917 testGroup.add() << pageOp << optionOps << styleOp; |
|
1918 testGroup.add() << pageOp << styleOp << optionOps; |
|
1919 testGroup.add() << optionOps << styleOp << pageOp; |
|
1920 testGroup.add() << styleOp << optionOps << pageOp; |
|
1921 testGroup.add() << styleOp << pageOp << optionOps; |
|
1922 testGroup.createTestRows(); |
|
1923 |
|
1924 foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { |
|
1925 Operation *optionOp = OPT(option, i == 1); |
|
1926 testGroup.reset("testAll 6.5"); |
|
1927 testGroup.add() << optionOp << pageOp << styleOp; |
|
1928 testGroup.add() << pageOp << optionOp << styleOp; |
|
1929 testGroup.add() << pageOp << styleOp << optionOp; |
|
1930 testGroup.add() << optionOp << styleOp << pageOp; |
|
1931 testGroup.add() << styleOp << optionOp << pageOp; |
|
1932 testGroup.add() << styleOp << pageOp << optionOp; |
|
1933 testGroup.createTestRows(); |
|
1934 } |
|
1935 } |
|
1936 } |
|
1937 } |
|
1938 |
|
1939 testGroup.reset("testAll 7.1", TestGroup::NonEquality); |
|
1940 testGroup.add() << SETPAGE(0); |
|
1941 testGroup.add() << SETPAGE(1); |
|
1942 testGroup.add() << SETPAGE(2); |
|
1943 testGroup.createTestRows(); |
|
1944 |
|
1945 testGroup.reset("testAll 7.2", TestGroup::NonEquality); |
|
1946 testGroup.add() << SETSTYLE(0); |
|
1947 testGroup.add() << SETSTYLE(1); |
|
1948 testGroup.add() << SETSTYLE(2); |
|
1949 testGroup.createTestRows(); |
|
1950 |
|
1951 // more to follow ... |
|
1952 } |
|
1953 |
|
1954 // Creates a "small" number of interesting test rows. |
|
1955 void createTestRows1() |
|
1956 { |
|
1957 testGroup.reset("test1 1"); |
|
1958 testGroup.add() << SETPAGE(0) << SETOPT(QWizard::HaveCustomButton3); |
|
1959 testGroup.add() << SETOPT(QWizard::HaveCustomButton3); |
|
1960 testGroup.createTestRows(); |
|
1961 |
|
1962 testGroup.reset("test1 2"); |
|
1963 testGroup.add() << SETOPT(QWizard::HaveFinishButtonOnEarlyPages) << SETPAGE(0); |
|
1964 testGroup.add() << SETPAGE(0) << SETOPT(QWizard::HaveFinishButtonOnEarlyPages); |
|
1965 testGroup.createTestRows(); |
|
1966 |
|
1967 testGroup.reset("test1 3"); |
|
1968 testGroup.add() << SETPAGE(2) << SETOPT(QWizard::HaveNextButtonOnLastPage); |
|
1969 testGroup.add() << SETOPT(QWizard::HaveNextButtonOnLastPage) << SETPAGE(2); |
|
1970 testGroup.createTestRows(); |
|
1971 } |
|
1972 }; |
|
1973 |
|
1974 void tst_QWizard::combinations_data() |
|
1975 { |
|
1976 CombinationsTestData combTestData; |
|
1977 // combTestData.createAllTestRows(); |
|
1978 combTestData.createTestRows1(); |
|
1979 |
|
1980 // qDebug() << "test rows:" << combTestData.nRows(); |
|
1981 } |
|
1982 |
|
1983 void tst_QWizard::combinations() |
|
1984 { |
|
1985 #ifdef Q_OS_WINCE |
|
1986 QSKIP("Too much memory usage for testing on CE emulator", SkipAll); |
|
1987 #endif |
|
1988 |
|
1989 QFETCH(bool, ref); |
|
1990 QFETCH(bool, testEquality); |
|
1991 QFETCH(QList<Operation *>, operations); |
|
1992 |
|
1993 TestWizard wizard; |
|
1994 #if !defined(QT_NO_STYLE_WINDOWSVISTA) |
|
1995 if (wizard.wizardStyle() == QWizard::AeroStyle) |
|
1996 return; // ### TODO: passes/fails in a unpredictable way, so disable for now |
|
1997 #endif |
|
1998 wizard.applyOperations(operations); |
|
1999 wizard.show(); // ### TODO: Required, but why? Should wizard.createImage() care? |
|
2000 |
|
2001 static QImage refImage; |
|
2002 static QSize refMinSize; |
|
2003 static QString refDescr; |
|
2004 |
|
2005 if (ref) { |
|
2006 refImage = wizard.createImage(); |
|
2007 refMinSize = wizard.minimumSizeHint(); |
|
2008 refDescr = wizard.operationsDescription(); |
|
2009 return; |
|
2010 } |
|
2011 |
|
2012 QImage image = wizard.createImage(); |
|
2013 |
|
2014 bool minSizeTest = wizard.minimumSizeHint() != refMinSize; |
|
2015 bool imageTest = image != refImage; |
|
2016 QLatin1String otor("!="); |
|
2017 QLatin1String reason("differ"); |
|
2018 |
|
2019 if (!testEquality) { |
|
2020 minSizeTest = false; // the image test is sufficient! |
|
2021 imageTest = !imageTest; |
|
2022 otor = QLatin1String("=="); |
|
2023 reason = QLatin1String("are equal"); |
|
2024 } |
|
2025 |
|
2026 if (minSizeTest) |
|
2027 qDebug() << "minimum sizes" << reason.latin1() << ";" << wizard.minimumSizeHint() |
|
2028 << otor.latin1() << refMinSize; |
|
2029 |
|
2030 if (imageTest) |
|
2031 qDebug() << "images" << reason.latin1(); |
|
2032 |
|
2033 if (minSizeTest || imageTest) { |
|
2034 qDebug() << "\t row 0 operations:" << refDescr.toLatin1(); |
|
2035 qDebug() << "\tcurrent row operations:" << wizard.operationsDescription().toLatin1(); |
|
2036 QVERIFY(false); |
|
2037 } |
|
2038 } |
|
2039 |
|
2040 class WizardPage : public QWizardPage |
|
2041 { |
|
2042 Q_OBJECT |
|
2043 bool shown_; |
|
2044 void showEvent(QShowEvent *) { shown_ = true; } |
|
2045 void hideEvent(QHideEvent *) { shown_ = false; } |
|
2046 public: |
|
2047 WizardPage() : shown_(false) {} |
|
2048 bool shown() const { return shown_; } |
|
2049 }; |
|
2050 |
|
2051 class WizardPages |
|
2052 { |
|
2053 QList<WizardPage *> pages; |
|
2054 public: |
|
2055 void add(WizardPage *page) { pages << page; } |
|
2056 QList<WizardPage *> all() const { return pages; } |
|
2057 QList<WizardPage *> shown() const |
|
2058 { |
|
2059 QList<WizardPage *> result; |
|
2060 foreach (WizardPage *page, pages) |
|
2061 if (page->shown()) |
|
2062 result << page; |
|
2063 return result; |
|
2064 } |
|
2065 }; |
|
2066 |
|
2067 void tst_QWizard::showCurrentPageOnly() |
|
2068 { |
|
2069 QWizard wizard; |
|
2070 WizardPages pages; |
|
2071 for (int i = 0; i < 5; ++i) { |
|
2072 pages.add(new WizardPage); |
|
2073 wizard.addPage(pages.all().last()); |
|
2074 } |
|
2075 |
|
2076 wizard.show(); |
|
2077 |
|
2078 QCOMPARE(pages.shown().count(), 1); |
|
2079 QCOMPARE(pages.shown().first(), pages.all().first()); |
|
2080 |
|
2081 const int steps = 2; |
|
2082 for (int i = 0; i < steps; ++i) |
|
2083 wizard.next(); |
|
2084 |
|
2085 QCOMPARE(pages.shown().count(), 1); |
|
2086 QCOMPARE(pages.shown().first(), pages.all().at(steps)); |
|
2087 |
|
2088 wizard.restart(); |
|
2089 |
|
2090 QCOMPARE(pages.shown().count(), 1); |
|
2091 QCOMPARE(pages.shown().first(), pages.all().first()); |
|
2092 } |
|
2093 |
|
2094 void tst_QWizard::setButtonText() |
|
2095 { |
|
2096 QWizard wizard; |
|
2097 wizard.setWizardStyle(QWizard::ClassicStyle); |
|
2098 QWizardPage* page1 = new QWizardPage; |
|
2099 QWizardPage* page2 = new QWizardPage; |
|
2100 wizard.addPage(page1); |
|
2101 wizard.addPage(page2); |
|
2102 |
|
2103 wizard.show(); |
|
2104 qApp->processEvents(); |
|
2105 QVERIFY(wizard.button(QWizard::NextButton)->text().contains("Next")); |
|
2106 QVERIFY(wizard.buttonText(QWizard::NextButton).contains("Next")); |
|
2107 QVERIFY(page1->buttonText(QWizard::NextButton).contains("Next")); |
|
2108 QVERIFY(page2->buttonText(QWizard::NextButton).contains("Next")); |
|
2109 |
|
2110 page2->setButtonText(QWizard::NextButton, "Page2"); |
|
2111 QVERIFY(wizard.button(QWizard::NextButton)->text().contains("Next")); |
|
2112 QVERIFY(wizard.buttonText(QWizard::NextButton).contains("Next")); |
|
2113 QVERIFY(page1->buttonText(QWizard::NextButton).contains("Next")); |
|
2114 QCOMPARE(page2->buttonText(QWizard::NextButton), QString("Page2")); |
|
2115 |
|
2116 wizard.next(); |
|
2117 qApp->processEvents(); |
|
2118 QCOMPARE(wizard.button(QWizard::NextButton)->text(), QString("Page2")); |
|
2119 QVERIFY(wizard.buttonText(QWizard::NextButton).contains("Next")); |
|
2120 QVERIFY(page1->buttonText(QWizard::NextButton).contains("Next")); |
|
2121 QCOMPARE(page2->buttonText(QWizard::NextButton), QString("Page2")); |
|
2122 |
|
2123 wizard.back(); |
|
2124 qApp->processEvents(); |
|
2125 QVERIFY(wizard.button(QWizard::NextButton)->text().contains("Next")); |
|
2126 QVERIFY(wizard.buttonText(QWizard::NextButton).contains("Next")); |
|
2127 QVERIFY(page1->buttonText(QWizard::NextButton).contains("Next")); |
|
2128 QCOMPARE(page2->buttonText(QWizard::NextButton), QString("Page2")); |
|
2129 |
|
2130 wizard.setButtonText(QWizard::NextButton, "Wizard"); |
|
2131 QVERIFY(wizard.button(QWizard::NextButton)->text().contains("Wizard")); |
|
2132 QCOMPARE(wizard.buttonText(QWizard::NextButton), QString("Wizard")); |
|
2133 QCOMPARE(page1->buttonText(QWizard::NextButton), QString("Wizard")); |
|
2134 QCOMPARE(page2->buttonText(QWizard::NextButton), QString("Page2")); |
|
2135 |
|
2136 wizard.next(); |
|
2137 qApp->processEvents(); |
|
2138 QCOMPARE(wizard.button(QWizard::NextButton)->text(), QString("Page2")); |
|
2139 QVERIFY(wizard.buttonText(QWizard::NextButton).contains("Wizard")); |
|
2140 QCOMPARE(page1->buttonText(QWizard::NextButton), QString("Wizard")); |
|
2141 QCOMPARE(page2->buttonText(QWizard::NextButton), QString("Page2")); |
|
2142 } |
|
2143 |
|
2144 void tst_QWizard::setCommitPage() |
|
2145 { |
|
2146 QWizard wizard; |
|
2147 QWizardPage* page1 = new QWizardPage; |
|
2148 QWizardPage* page2 = new QWizardPage; |
|
2149 wizard.addPage(page1); |
|
2150 wizard.addPage(page2); |
|
2151 wizard.show(); |
|
2152 qApp->processEvents(); |
|
2153 |
|
2154 QVERIFY(!page1->isCommitPage()); |
|
2155 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
2156 |
|
2157 wizard.next(); |
|
2158 QVERIFY(wizard.button(QWizard::BackButton)->isEnabled()); |
|
2159 |
|
2160 page1->setCommitPage(true); |
|
2161 QVERIFY(page1->isCommitPage()); |
|
2162 |
|
2163 wizard.back(); |
|
2164 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
2165 |
|
2166 wizard.next(); |
|
2167 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
2168 |
|
2169 page1->setCommitPage(false); |
|
2170 QVERIFY(!page1->isCommitPage()); |
|
2171 |
|
2172 wizard.back(); |
|
2173 QVERIFY(!wizard.button(QWizard::BackButton)->isEnabled()); |
|
2174 |
|
2175 wizard.next(); |
|
2176 QVERIFY(wizard.button(QWizard::BackButton)->isEnabled()); |
|
2177 |
|
2178 // ### test relabeling of the Cancel button to "Close" once this is implemented |
|
2179 } |
|
2180 |
|
2181 void tst_QWizard::setWizardStyle() |
|
2182 { |
|
2183 QWizard wizard; |
|
2184 wizard.addPage(new QWizardPage); |
|
2185 wizard.show(); |
|
2186 qApp->processEvents(); |
|
2187 |
|
2188 // defaults |
|
2189 const bool styleHintMatch = |
|
2190 wizard.wizardStyle() == |
|
2191 QWizard::WizardStyle(wizard.style()->styleHint(QStyle::SH_WizardStyle, 0, &wizard)); |
|
2192 #if !defined(QT_NO_STYLE_WINDOWSVISTA) |
|
2193 QVERIFY(styleHintMatch || wizard.wizardStyle() == QWizard::AeroStyle); |
|
2194 #else |
|
2195 QVERIFY(styleHintMatch); |
|
2196 #endif |
|
2197 |
|
2198 // set/get consistency |
|
2199 for (int wstyle = 0; wstyle < QWizard::NStyles; ++wstyle) { |
|
2200 wizard.setWizardStyle((QWizard::WizardStyle)wstyle); |
|
2201 QCOMPARE((int)wizard.wizardStyle(), wstyle); |
|
2202 } |
|
2203 } |
|
2204 |
|
2205 void tst_QWizard::removePage() |
|
2206 { |
|
2207 QWizard wizard; |
|
2208 QWizardPage *page0 = new QWizardPage; |
|
2209 QWizardPage *page1 = new QWizardPage; |
|
2210 QWizardPage *page2 = new QWizardPage; |
|
2211 QWizardPage *page3 = new QWizardPage; |
|
2212 |
|
2213 wizard.setPage(0, page0); |
|
2214 wizard.setPage(1, page1); |
|
2215 wizard.setPage(2, page2); |
|
2216 wizard.setPage(3, page3); |
|
2217 |
|
2218 wizard.restart(); |
|
2219 QCOMPARE(wizard.pageIds().size(), 4); |
|
2220 QCOMPARE(wizard.visitedPages().size(), 1); |
|
2221 |
|
2222 // Removing a non-existent page |
|
2223 wizard.removePage(4); |
|
2224 QCOMPARE(wizard.pageIds().size(), 4); |
|
2225 |
|
2226 // Removing and then reinserting a page |
|
2227 QCOMPARE(wizard.pageIds().size(), 4); |
|
2228 QVERIFY(wizard.pageIds().contains(2)); |
|
2229 wizard.removePage(2); |
|
2230 QCOMPARE(wizard.pageIds().size(), 3); |
|
2231 QVERIFY(!wizard.pageIds().contains(2)); |
|
2232 wizard.setPage(2, page2); |
|
2233 QCOMPARE(wizard.pageIds().size(), 4); |
|
2234 QVERIFY(wizard.pageIds().contains(2)); |
|
2235 |
|
2236 // Removing the same page twice |
|
2237 wizard.removePage(2); // restore |
|
2238 QCOMPARE(wizard.pageIds().size(), 3); |
|
2239 QVERIFY(!wizard.pageIds().contains(2)); |
|
2240 wizard.removePage(2); |
|
2241 QCOMPARE(wizard.pageIds().size(), 3); |
|
2242 QVERIFY(!wizard.pageIds().contains(2)); |
|
2243 |
|
2244 // Removing a page not in the history |
|
2245 wizard.setPage(2, page2); // restore |
|
2246 wizard.restart(); |
|
2247 wizard.next(); |
|
2248 QCOMPARE(wizard.visitedPages().size(), 2); |
|
2249 QCOMPARE(wizard.currentPage(), page1); |
|
2250 wizard.removePage(2); |
|
2251 QCOMPARE(wizard.visitedPages().size(), 2); |
|
2252 QVERIFY(!wizard.pageIds().contains(2)); |
|
2253 QCOMPARE(wizard.currentPage(), page1); |
|
2254 |
|
2255 // Removing a page in the history before the current page |
|
2256 wizard.setPage(2, page2); // restore |
|
2257 wizard.restart(); |
|
2258 wizard.next(); |
|
2259 QCOMPARE(wizard.visitedPages().size(), 2); |
|
2260 QCOMPARE(wizard.currentPage(), page1); |
|
2261 wizard.removePage(0); |
|
2262 QCOMPARE(wizard.visitedPages().size(), 1); |
|
2263 QVERIFY(!wizard.visitedPages().contains(0)); |
|
2264 QVERIFY(!wizard.pageIds().contains(0)); |
|
2265 QCOMPARE(wizard.currentPage(), page1); |
|
2266 |
|
2267 // Remove the current page which is not the first one in the history |
|
2268 wizard.setPage(0, page0); // restore |
|
2269 wizard.restart(); |
|
2270 wizard.next(); |
|
2271 QCOMPARE(wizard.visitedPages().size(), 2); |
|
2272 QCOMPARE(wizard.currentPage(), page1); |
|
2273 wizard.removePage(1); |
|
2274 QCOMPARE(wizard.visitedPages().size(), 1); |
|
2275 QVERIFY(!wizard.visitedPages().contains(1)); |
|
2276 QVERIFY(!wizard.pageIds().contains(1)); |
|
2277 QCOMPARE(wizard.currentPage(), page0); |
|
2278 |
|
2279 // Remove the current page which is the first (and only) one in the history |
|
2280 wizard.removePage(0); |
|
2281 QCOMPARE(wizard.visitedPages().size(), 1); |
|
2282 QVERIFY(!wizard.visitedPages().contains(0)); |
|
2283 QCOMPARE(wizard.pageIds().size(), 2); |
|
2284 QVERIFY(!wizard.pageIds().contains(0)); |
|
2285 QCOMPARE(wizard.currentPage(), page2); |
|
2286 // |
|
2287 wizard.removePage(2); |
|
2288 QCOMPARE(wizard.visitedPages().size(), 1); |
|
2289 QVERIFY(!wizard.visitedPages().contains(2)); |
|
2290 QCOMPARE(wizard.pageIds().size(), 1); |
|
2291 QVERIFY(!wizard.pageIds().contains(2)); |
|
2292 QCOMPARE(wizard.currentPage(), page3); |
|
2293 // |
|
2294 wizard.removePage(3); |
|
2295 QVERIFY(wizard.visitedPages().empty()); |
|
2296 QVERIFY(wizard.pageIds().empty()); |
|
2297 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage *>(0)); |
|
2298 } |
|
2299 |
|
2300 void tst_QWizard::task161660_buttonSpacing() |
|
2301 { |
|
2302 #ifndef QT_NO_STYLE_PLASTIQUE |
|
2303 QString origStyle = QApplication::style()->objectName(); |
|
2304 QApplication::setStyle(new QPlastiqueStyle); |
|
2305 QWizard wizard; |
|
2306 wizard.addPage(new QWizardPage); |
|
2307 wizard.show(); |
|
2308 const QAbstractButton *finishButton = wizard.button(QWizard::FinishButton); |
|
2309 const QAbstractButton *cancelButton = wizard.button(QWizard::CancelButton); |
|
2310 const int spacing = cancelButton->geometry().left() - finishButton->geometry().right() - 1; |
|
2311 QCOMPARE(spacing, wizard.style()->layoutSpacing( |
|
2312 QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal)); |
|
2313 QApplication::setStyle(origStyle); |
|
2314 #endif |
|
2315 } |
|
2316 |
|
2317 class task177716_CommitPage : public QWizardPage |
|
2318 { |
|
2319 Q_OBJECT |
|
2320 public: |
|
2321 task177716_CommitPage() |
|
2322 { |
|
2323 setCommitPage(true); |
|
2324 QVBoxLayout *layout = new QVBoxLayout; |
|
2325 ledit = new QLineEdit(this); |
|
2326 registerField("foo*", ledit); |
|
2327 layout->addWidget(ledit); |
|
2328 setLayout(layout); |
|
2329 } |
|
2330 QLineEdit *ledit; |
|
2331 }; |
|
2332 |
|
2333 void tst_QWizard::task177716_disableCommitButton() |
|
2334 { |
|
2335 QWizard wizard; |
|
2336 task177716_CommitPage *commitPage = new task177716_CommitPage; |
|
2337 wizard.addPage(commitPage); |
|
2338 // the following page must be there to prevent the first page from replacing the Commit button |
|
2339 // with the Finish button: |
|
2340 wizard.addPage(new QWizardPage); |
|
2341 wizard.show(); |
|
2342 QVERIFY(!wizard.button(QWizard::CommitButton)->isEnabled()); |
|
2343 commitPage->ledit->setText("some non-empty text"); |
|
2344 QVERIFY(wizard.button(QWizard::CommitButton)->isEnabled()); |
|
2345 commitPage->ledit->setText(""); |
|
2346 QVERIFY(!wizard.button(QWizard::CommitButton)->isEnabled()); |
|
2347 } |
|
2348 |
|
2349 class WizardPage_task183550 : public QWizardPage |
|
2350 { |
|
2351 public: |
|
2352 WizardPage_task183550(QWidget *parent = 0) |
|
2353 : QWizardPage(parent) |
|
2354 , treeWidget(new QTreeWidget) |
|
2355 , verticalPolicy(QSizePolicy::MinimumExpanding) {} |
|
2356 void enableVerticalExpansion() { verticalPolicy = QSizePolicy::MinimumExpanding; } |
|
2357 void disableVerticalExpansion() { verticalPolicy = QSizePolicy::Preferred; } |
|
2358 int treeWidgetHeight() const { return treeWidget->height(); } |
|
2359 int treeWidgetSizeHintHeight() const { return treeWidget->sizeHint().height(); } |
|
2360 |
|
2361 private: |
|
2362 QTreeWidget *treeWidget; |
|
2363 QSizePolicy::Policy verticalPolicy; |
|
2364 |
|
2365 void initializePage() |
|
2366 { |
|
2367 if (layout()) |
|
2368 delete layout(); |
|
2369 if (treeWidget) |
|
2370 delete treeWidget; |
|
2371 |
|
2372 QLayout *layout_ = new QVBoxLayout(this); |
|
2373 layout_->addWidget(treeWidget = new QTreeWidget); |
|
2374 |
|
2375 QSizePolicy policy = sizePolicy(); |
|
2376 policy.setVerticalPolicy(verticalPolicy); |
|
2377 treeWidget->setSizePolicy(policy); |
|
2378 } |
|
2379 }; |
|
2380 |
|
2381 void tst_QWizard::task183550_stretchFactor() |
|
2382 { |
|
2383 QWizard wizard; |
|
2384 WizardPage_task183550 *page1 = new WizardPage_task183550; |
|
2385 WizardPage_task183550 *page2 = new WizardPage_task183550; |
|
2386 wizard.addPage(page1); |
|
2387 wizard.addPage(page2); |
|
2388 wizard.resize(500, 2 * page2->treeWidgetSizeHintHeight()); |
|
2389 wizard.show(); |
|
2390 |
|
2391 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page1)); |
|
2392 |
|
2393 // ---- |
|
2394 page2->disableVerticalExpansion(); |
|
2395 wizard.next(); |
|
2396 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page2)); |
|
2397 QVERIFY(page2->treeWidgetHeight() == page2->treeWidgetSizeHintHeight()); |
|
2398 |
|
2399 wizard.back(); |
|
2400 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page1)); |
|
2401 |
|
2402 // ---- |
|
2403 page2->enableVerticalExpansion(); |
|
2404 wizard.next(); |
|
2405 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page2)); |
|
2406 QVERIFY(page2->treeWidgetHeight() > page2->treeWidgetSizeHintHeight()); |
|
2407 |
|
2408 wizard.back(); |
|
2409 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page1)); |
|
2410 |
|
2411 // ---- |
|
2412 page2->disableVerticalExpansion(); |
|
2413 wizard.next(); |
|
2414 QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page2)); |
|
2415 QVERIFY(page2->treeWidgetHeight() == page2->treeWidgetSizeHintHeight()); |
|
2416 } |
|
2417 |
|
2418 void tst_QWizard::task161658_alignments() |
|
2419 { |
|
2420 QWizard wizard; |
|
2421 wizard.setWizardStyle(QWizard::MacStyle); |
|
2422 |
|
2423 QWizardPage page; |
|
2424 page.setTitle("Title"); |
|
2425 page.setSubTitle("SUBTITLE#: The subtitle bust be alligned with the rest of the widget"); |
|
2426 |
|
2427 QLabel label1("Field:"); |
|
2428 QLineEdit lineEdit1; |
|
2429 QGridLayout *layout = new QGridLayout; |
|
2430 layout->addWidget(&label1, 0, 0); |
|
2431 layout->addWidget(&lineEdit1, 0, 1); |
|
2432 page.setLayout(layout); |
|
2433 |
|
2434 int idx = wizard.addPage(&page); |
|
2435 wizard.setStartId(idx); |
|
2436 wizard.show(); |
|
2437 QTest::qWait(100); |
|
2438 |
|
2439 foreach (QLabel *subtitleLabel, qFindChildren<QLabel *>(&wizard)) { |
|
2440 if (subtitleLabel->text().startsWith("SUBTITLE#")) { |
|
2441 QCOMPARE(lineEdit1.mapToGlobal(lineEdit1.contentsRect().bottomRight()).x(), |
|
2442 subtitleLabel->mapToGlobal(subtitleLabel->contentsRect().bottomRight()).x()); |
|
2443 return; |
|
2444 } |
|
2445 } |
|
2446 QFAIL("Subtitle label not found"); |
|
2447 } |
|
2448 |
|
2449 void tst_QWizard::task177022_setFixedSize() |
|
2450 { |
|
2451 int width = 300; |
|
2452 int height = 200; |
|
2453 QWizard wiz; |
|
2454 QWizardPage page1; |
|
2455 QWizardPage page2; |
|
2456 wiz.addPage(&page1); |
|
2457 wiz.addPage(&page2); |
|
2458 wiz.setFixedSize(width, height); |
|
2459 if (wiz.wizardStyle() == QWizard::AeroStyle) |
|
2460 QEXPECT_FAIL("", "this probably relates to non-client area hack for AeroStyle titlebar " |
|
2461 "effect; not sure if it qualifies as a bug or not", Continue); |
|
2462 QCOMPARE(wiz.size(), QSize(width, height)); |
|
2463 QCOMPARE(wiz.minimumWidth(), width); |
|
2464 QCOMPARE(wiz.minimumHeight(), height); |
|
2465 QCOMPARE(wiz.maximumWidth(), width); |
|
2466 QCOMPARE(wiz.maximumHeight(), height); |
|
2467 |
|
2468 wiz.show(); |
|
2469 QTest::qWait(100); |
|
2470 QCOMPARE(wiz.size(), QSize(width, height)); |
|
2471 QCOMPARE(wiz.minimumWidth(), width); |
|
2472 QCOMPARE(wiz.minimumHeight(), height); |
|
2473 QCOMPARE(wiz.maximumWidth(), width); |
|
2474 QCOMPARE(wiz.maximumHeight(), height); |
|
2475 |
|
2476 wiz.next(); |
|
2477 QTest::qWait(100); |
|
2478 QCOMPARE(wiz.size(), QSize(width, height)); |
|
2479 QCOMPARE(wiz.minimumWidth(), width); |
|
2480 QCOMPARE(wiz.minimumHeight(), height); |
|
2481 QCOMPARE(wiz.maximumWidth(), width); |
|
2482 QCOMPARE(wiz.maximumHeight(), height); |
|
2483 |
|
2484 } |
|
2485 |
|
2486 void tst_QWizard::task248107_backButton() |
|
2487 { |
|
2488 QWizard wizard; |
|
2489 QWizardPage page1; |
|
2490 QWizardPage page2; |
|
2491 QWizardPage page3; |
|
2492 QWizardPage page4; |
|
2493 wizard.addPage(&page1); |
|
2494 wizard.addPage(&page2); |
|
2495 wizard.addPage(&page3); |
|
2496 wizard.addPage(&page4); |
|
2497 |
|
2498 wizard.show(); |
|
2499 QTest::qWait(100); |
|
2500 QCOMPARE(wizard.currentPage(), &page1); |
|
2501 |
|
2502 QTest::mouseClick(wizard.button(QWizard::NextButton), Qt::LeftButton); |
|
2503 QCOMPARE(wizard.currentPage(), &page2); |
|
2504 |
|
2505 QTest::mouseClick(wizard.button(QWizard::NextButton), Qt::LeftButton); |
|
2506 QCOMPARE(wizard.currentPage(), &page3); |
|
2507 |
|
2508 QTest::mouseClick(wizard.button(QWizard::NextButton), Qt::LeftButton); |
|
2509 QCOMPARE(wizard.currentPage(), &page4); |
|
2510 |
|
2511 QTest::mouseClick(wizard.button(QWizard::BackButton), Qt::LeftButton); |
|
2512 QCOMPARE(wizard.currentPage(), &page3); |
|
2513 |
|
2514 QTest::mouseClick(wizard.button(QWizard::BackButton), Qt::LeftButton); |
|
2515 QCOMPARE(wizard.currentPage(), &page2); |
|
2516 |
|
2517 QTest::mouseClick(wizard.button(QWizard::BackButton), Qt::LeftButton); |
|
2518 QCOMPARE(wizard.currentPage(), &page1); |
|
2519 } |
|
2520 |
|
2521 class WizardPage_task255350 : public QWizardPage |
|
2522 { |
|
2523 public: |
|
2524 QLineEdit *lineEdit; |
|
2525 WizardPage_task255350() |
|
2526 : lineEdit(new QLineEdit) |
|
2527 { |
|
2528 registerField("dummy*", lineEdit); |
|
2529 } |
|
2530 }; |
|
2531 |
|
2532 void tst_QWizard::task255350_fieldObjectDestroyed() |
|
2533 { |
|
2534 QWizard wizard; |
|
2535 WizardPage_task255350 *page = new WizardPage_task255350; |
|
2536 int id = wizard.addPage(page); |
|
2537 delete page->lineEdit; |
|
2538 wizard.removePage(id); // don't crash! |
|
2539 delete page; |
|
2540 } |
|
2541 |
|
2542 QTEST_MAIN(tst_QWizard) |
|
2543 #include "tst_qwizard.moc" |