1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\example dialogs/licensewizard
\title License Wizard Example
The License Wizard example shows how to implement complex wizards in
Qt.
\image licensewizard-example.png Screenshot of the License Wizard example
Most wizards have a linear structure, with page 1 followed by
page 2 and so on until the last page. The
\l{dialogs/classwizard}{Class Wizard} example shows how to create
such wizards.
Some wizards are more complex in that they allow different
traversal paths based on the information provided by the user.
The License Wizard example illustrates this. It provides five
wizard pages; depending on which options are selected, the user
can reach different pages.
\image licensewizard-flow.png The License Wizard pages
The example consists of the following classes:
\list
\o \c LicenseWizard inherits QWizard and implements a non-linear
five-page wizard that leads the user through the process of
choosing a license agreement.
\o \c IntroPage, \c EvaluatePage, \c RegisterPage, \c
DetailsPage, and \c ConclusionPage are QWizardPage subclasses
that implement the wizard pages.
\endlist
\section1 The LicenseWizard Class
The \c LicenseWizard class derives from QWizard and provides a
five-page wizard that guides the user through the process of
registering their copy of a fictitious software product. Here's
the class definition:
\snippet examples/dialogs/licensewizard/licensewizard.h 1
The class's public API is limited to a constructor and an enum.
The enum defines the IDs associated with the various pages:
\table
\header \o Class name \o Enum value \o Page ID
\row \o \c IntroPage \o \c Page_Intro \o 0
\row \o \c EvaluatePage \o \c Page_Evaluate \o 1
\row \o \c RegisterPage \o \c Page_Register \o 2
\row \o \c DetailsPage \o \c Page_Details \o 3
\row \o \c ConclusionPage \o \c Page_Conclusion \o 4
\endtable
For this example, the IDs are arbitrary. The only constraints are
that they must be unique and different from -1. IDs allow us to
refer to pages.
\snippet examples/dialogs/licensewizard/licensewizard.cpp 2
In the constructor, we create the five pages, insert them into
the wizard using QWizard::setPage(), and set \c Page_Intro to be
the first page.
\snippet examples/dialogs/licensewizard/licensewizard.cpp 3
\snippet examples/dialogs/licensewizard/licensewizard.cpp 4
We set the style to \l{QWizard::}{ModernStyle} on all platforms
except Mac OS X,
\snippet examples/dialogs/licensewizard/licensewizard.cpp 5
\snippet examples/dialogs/licensewizard/licensewizard.cpp 6
We configure the QWizard to show a \gui Help button, which is
connected to our \c showHelp() slot. We also set the
\l{QWizard::}{LogoPixmap} for all pages that have a header (i.e.,
\c EvaluatePage, \c RegisterPage, and \c DetailsPage).
\snippet examples/dialogs/licensewizard/licensewizard.cpp 9
\snippet examples/dialogs/licensewizard/licensewizard.cpp 11
\dots
\snippet examples/dialogs/licensewizard/licensewizard.cpp 13
In \c showHelp(), we display help texts that are appropiate for
the current page. If the user clicks \gui Help twice for the same
page, we say, "Sorry, I already gave what help I could. Maybe you
should try asking a human?"
\section1 The IntroPage Class
The pages are defined in \c licensewizard.h and implemented in \c
licensewizard.cpp, together with \c LicenseWizard.
Here's the definition and implementation of \c{IntroPage}:
\snippet examples/dialogs/licensewizard/licensewizard.h 4
\codeline
\snippet examples/dialogs/licensewizard/licensewizard.cpp 16
A page inherits from QWizardPage. We set a
\l{QWizardPage::}{title} and a
\l{QWizard::WatermarkPixmap}{watermark pixmap}. By not setting
any \l{QWizardPage::}{subTitle}, we ensure that no header is
displayed for this page. (On Windows, it is customary for wizards
to display a watermark pixmap on the first and last pages, and to
have a header on the other pages.)
\snippet examples/dialogs/licensewizard/licensewizard.cpp 17
\snippet examples/dialogs/licensewizard/licensewizard.cpp 19
The \c nextId() function returns the ID for \c EvaluatePage if
the \gui{Evaluate the product for 30 days} option is checked;
otherwise it returns the ID for \c RegisterPage.
\section1 The EvaluatePage Class
The \c EvaluatePage is slightly more involved:
\snippet examples/dialogs/licensewizard/licensewizard.h 5
\codeline
\snippet examples/dialogs/licensewizard/licensewizard.cpp 20
\dots
\snippet examples/dialogs/licensewizard/licensewizard.cpp 21
\dots
\snippet examples/dialogs/licensewizard/licensewizard.cpp 22
First, we set the page's \l{QWizardPage::}{title}
and \l{QWizardPage::}{subTitle}.
Then we create the child widgets, create \l{Registering and Using
Fields}{wizard fields} associated with them, and put them into
layouts. The fields are created with an asterisk (\c
*) next to their name. This makes them \l{mandatory fields}, that
is, fields that must be filled before the user can press the
\gui Next button (\gui Continue on Mac OS X). The fields' values
can be accessed from any other page using QWizardPage::field().
Resetting the page amounts to clearing the two text fields.
\snippet examples/dialogs/licensewizard/licensewizard.cpp 23
The next page is always the \c ConclusionPage.
\section1 The ConclusionPage Class
The \c RegisterPage and \c DetailsPage are very similar to \c
EvaluatePage. Let's go directly to the \c ConclusionPage:
\snippet examples/dialogs/licensewizard/licensewizard.h 6
This time, we reimplement QWizardPage::initializePage() and
QWidget::setVisible(), in addition to
\l{QWizardPage::}{nextId()}. We also declare a private slot:
\c printButtonClicked().
\snippet examples/dialogs/licensewizard/licensewizard.cpp 18
The default implementation of QWizardPage::nextId() returns
the page with the next ID, or -1 if the current page has the
highest ID. This behavior would work here, because \c
Page_Conclusion equals 5 and there is no page with a higher ID,
but to avoid relying on such subtle behavior, we reimplement
\l{QWizardPage::}{nextId()} to return -1.
\snippet examples/dialogs/licensewizard/licensewizard.cpp 27
We use QWizard::hasVisitedPage() to determine the type of
license agreement the user has chosen. If the user filled the \c
EvaluatePage, the license text refers to an Evaluation License
Agreement. If the user filled the \c DetailsPage, the license
text is a First-Time License Agreement. If the user provided an
upgrade key and skipped the \c DetailsPage, the license text is
an Update License Agreement.
\snippet examples/dialogs/licensewizard/licensewizard.cpp 28
We want to display a \gui Print button in the wizard when the \c
ConclusionPage is up. One way to accomplish this is to reimplement
QWidget::setVisible():
\list
\o If the page is shown, we set the \l{QWizard::}{CustomButton1} button's
text to \gui{\underline{P}rint}, we enable the \l{QWizard::}{HaveCustomButton1}
option, and we connect the QWizard's \l{QWizard::}{customButtonClicked()}
signal to our \c printButtonClicked() slot.
\o If the page is hidden, we disable the \l{QWizard::}{HaveCustomButton1}
option and disconnect the \c printButtonClicked() slot.
\endlist
\sa QWizard, {Class Wizard Example}, {Trivial Wizard Example}
*/
|