[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
[2] | 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
[846] | 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
| 14 | ** written agreement between you and Nokia.
|
---|
[2] | 15 | **
|
---|
[846] | 16 | ** GNU Free Documentation License
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
| 20 | ** file.
|
---|
[2] | 21 | **
|
---|
[561] | 22 | ** If you have questions regarding the use of this file, please contact
|
---|
| 23 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 24 | ** $QT_END_LICENSE$
|
---|
| 25 | **
|
---|
| 26 | ****************************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*!
|
---|
| 29 | \example dialogs/classwizard
|
---|
| 30 | \title Class Wizard Example
|
---|
| 31 |
|
---|
| 32 | The License Wizard example shows how to implement linear
|
---|
| 33 | wizards using QWizard.
|
---|
| 34 |
|
---|
| 35 | \image classwizard.png Screenshot of the Class Wizard example
|
---|
| 36 |
|
---|
| 37 | Most wizards have a linear structure, with page 1 followed by
|
---|
| 38 | page 2 and so on until the last page. Some wizards are more
|
---|
| 39 | complex in that they allow different traversal paths based on the
|
---|
| 40 | information provided by the user. The
|
---|
| 41 | \l{dialogs/licensewizard}{License Wizard} example shows how to
|
---|
| 42 | create such wizards.
|
---|
| 43 |
|
---|
| 44 | The Class Wizard example consists of the following classes:
|
---|
| 45 |
|
---|
| 46 | \list
|
---|
| 47 | \o \c ClassWizard inherits QWizard and provides a
|
---|
| 48 | three-step wizard that generates the skeleton of a C++ class
|
---|
| 49 | based on the user's input.
|
---|
| 50 | \o \c IntroPage, \c ClassInfoPage, \c CodeStylePage, \c
|
---|
| 51 | OutputFilesPage, and \c ConclusionPage are QWizardPage
|
---|
| 52 | subclasses that implement the wizard pages.
|
---|
| 53 | \endlist
|
---|
| 54 |
|
---|
| 55 | \section1 ClassWizard Class Definition
|
---|
| 56 |
|
---|
| 57 | \image classwizard-flow.png The Class Wizard pages
|
---|
| 58 |
|
---|
| 59 | We will see how to subclass QWizard to implement our own wizard.
|
---|
| 60 | The concrete wizard class is called \c ClassWizard and provides
|
---|
| 61 | five pages:
|
---|
| 62 |
|
---|
| 63 | \list
|
---|
| 64 | \o The first page is an introduction page, telling the user what
|
---|
| 65 | the wizard is going to do.
|
---|
| 66 | \o The second page asks for a class name and a base class, and
|
---|
| 67 | allows the user to specify whether the class should have a \c
|
---|
| 68 | Q_OBJECT macro and what constructors it should provide.
|
---|
| 69 | \o The third page allows the user to set some options related to the code
|
---|
| 70 | style, such as the macro used to protect the header file from
|
---|
| 71 | multiple inclusion (e.g., \c MYDIALOG_H).
|
---|
| 72 | \o The fourth page allows the user to specify the names of the
|
---|
| 73 | output files.
|
---|
| 74 | \o The fifth page is a conclusion page.
|
---|
| 75 | \endlist
|
---|
| 76 |
|
---|
| 77 | Although the program is just an example, if you press \gui Finish
|
---|
| 78 | (\gui Done on Mac OS X), actual C++ source files will actually be
|
---|
| 79 | generated.
|
---|
| 80 |
|
---|
| 81 | \section1 The ClassWizard Class
|
---|
| 82 |
|
---|
| 83 | Here's the \c ClassWizard definition:
|
---|
| 84 |
|
---|
| 85 | \snippet examples/dialogs/classwizard/classwizard.h 0
|
---|
| 86 |
|
---|
| 87 | The class reimplements QDialog's \l{QDialog::}{accept()} slot.
|
---|
| 88 | This slot is called when the user clicks \gui{Finish}.
|
---|
| 89 |
|
---|
| 90 | Here's the constructor:
|
---|
| 91 |
|
---|
| 92 | \snippet examples/dialogs/classwizard/classwizard.cpp 1
|
---|
| 93 |
|
---|
| 94 | We instantiate the five pages and insert them into the wizard
|
---|
| 95 | using QWizard::addPage(). The order in which they are inserted
|
---|
| 96 | is also the order in which they will be shown later on.
|
---|
| 97 |
|
---|
| 98 | We call QWizard::setPixmap() to set the banner and the
|
---|
| 99 | background pixmaps for all pages. The banner is used as a
|
---|
| 100 | background for the page header when the wizard's style is
|
---|
| 101 | \l{QWizard::}{ModernStyle}; the background is used as the
|
---|
| 102 | dialog's background in \l{QWizard::}{MacStyle}. (See \l{Elements
|
---|
| 103 | of a Wizard Page} for more information.)
|
---|
| 104 |
|
---|
| 105 | \snippet examples/dialogs/classwizard/classwizard.cpp 3
|
---|
| 106 | \snippet examples/dialogs/classwizard/classwizard.cpp 4
|
---|
| 107 | \dots
|
---|
| 108 | \snippet examples/dialogs/classwizard/classwizard.cpp 5
|
---|
| 109 | \snippet examples/dialogs/classwizard/classwizard.cpp 6
|
---|
| 110 |
|
---|
| 111 | If the user clicks \gui Finish, we extract the information from
|
---|
| 112 | the various pages using QWizard::field() and generate the files.
|
---|
| 113 | The code is long and tedious (and has barely anything to do with
|
---|
| 114 | noble art of designing wizards), so most of it is skipped here.
|
---|
| 115 | See the actual example in the Qt distribution for the details if
|
---|
| 116 | you're curious.
|
---|
| 117 |
|
---|
| 118 | \section1 The IntroPage Class
|
---|
| 119 |
|
---|
| 120 | The pages are defined in \c classwizard.h and implemented in \c
|
---|
| 121 | classwizard.cpp, together with \c ClassWizard. We will start with
|
---|
| 122 | the easiest page:
|
---|
| 123 |
|
---|
| 124 | \snippet examples/dialogs/classwizard/classwizard.h 1
|
---|
| 125 | \codeline
|
---|
| 126 | \snippet examples/dialogs/classwizard/classwizard.cpp 7
|
---|
| 127 |
|
---|
| 128 | A page inherits from QWizardPage. We set a
|
---|
| 129 | \l{QWizardPage::}{title} and a
|
---|
| 130 | \l{QWizard::WatermarkPixmap}{watermark pixmap}. By not setting
|
---|
| 131 | any \l{QWizardPage::}{subTitle}, we ensure that no header is
|
---|
| 132 | displayed for this page. (On Windows, it is customary for wizards
|
---|
| 133 | to display a watermark pixmap on the first and last pages, and to
|
---|
| 134 | have a header on the other pages.)
|
---|
| 135 |
|
---|
| 136 | Then we create a QLabel and add it to a layout.
|
---|
| 137 |
|
---|
| 138 | \section1 The ClassInfoPage Class
|
---|
| 139 |
|
---|
| 140 | The second page is defined and implemented as follows:
|
---|
| 141 |
|
---|
| 142 | \snippet examples/dialogs/classwizard/classwizard.h 2
|
---|
| 143 | \codeline
|
---|
| 144 | \snippet examples/dialogs/classwizard/classwizard.cpp 9
|
---|
| 145 | \dots
|
---|
| 146 | \snippet examples/dialogs/classwizard/classwizard.cpp 12
|
---|
| 147 | \dots
|
---|
| 148 | \snippet examples/dialogs/classwizard/classwizard.cpp 13
|
---|
| 149 |
|
---|
| 150 | First, we set the page's \l{QWizardPage::}{title},
|
---|
| 151 | \l{QWizardPage::}{subTitle}, and \l{QWizard::LogoPixmap}{logo
|
---|
| 152 | pixmap}. The logo pixmap is displayed in the page's header in
|
---|
| 153 | \l{QWizard::}{ClassicStyle} and \l{QWizard::}{ModernStyle}.
|
---|
| 154 |
|
---|
| 155 | Then we create the child widgets, create \l{Registering and Using
|
---|
| 156 | Fields}{wizard fields} associated with them, and put them into
|
---|
| 157 | layouts. The \c className field is created with an asterisk (\c
|
---|
| 158 | *) next to its name. This makes it a \l{mandatory field}, that
|
---|
| 159 | is, a field that must be filled before the user can press the
|
---|
| 160 | \gui Next button (\gui Continue on Mac OS X). The fields' values
|
---|
| 161 | can be accessed from any other page using QWizardPage::field(),
|
---|
| 162 | or from the wizard code using QWizard::field().
|
---|
| 163 |
|
---|
| 164 | \section1 The CodeStylePage Class
|
---|
| 165 |
|
---|
| 166 | The third page is defined and implemented as follows:
|
---|
| 167 |
|
---|
| 168 | \snippet examples/dialogs/classwizard/classwizard.h 3
|
---|
| 169 | \codeline
|
---|
| 170 | \snippet examples/dialogs/classwizard/classwizard.cpp 14
|
---|
| 171 | \dots
|
---|
| 172 | \snippet examples/dialogs/classwizard/classwizard.cpp 15
|
---|
| 173 | \codeline
|
---|
| 174 | \snippet examples/dialogs/classwizard/classwizard.cpp 16
|
---|
| 175 |
|
---|
| 176 | The code in the constructor is very similar to what we did for \c
|
---|
| 177 | ClassInfoPage, so we skipped most of it.
|
---|
| 178 |
|
---|
| 179 | The \c initializePage() function is what makes this class
|
---|
| 180 | interesting. It is reimplemented from QWizardPage and is used to
|
---|
| 181 | initialize some of the page's fields with values from the
|
---|
| 182 | previous page (namely, \c className and \c baseClass). For
|
---|
| 183 | example, if the class name on page 2 is \c SuperDuperWidget, the
|
---|
| 184 | default macro name on page 3 is \c SUPERDUPERWIDGET_H.
|
---|
| 185 |
|
---|
| 186 | The \c OutputFilesPage and \c ConclusionPage classes are very
|
---|
| 187 | similar to \c CodeStylePage, so we won't review them here.
|
---|
| 188 |
|
---|
| 189 | \sa QWizard, {License Wizard Example}, {Trivial Wizard Example}
|
---|
| 190 | */
|
---|