Редактирование: The Wizard Magically Reappears
Материал из Wiki.crossplatform.ru
Внимание: Вы не представились системе. Ваш IP-адрес будет записан в историю изменений этой страницы.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия | Ваш текст | ||
Строка 3: | Строка 3: | ||
by Jo Asplin | by Jo Asplin | ||
- | '''После исчезновения в клубах дыма, с выходом Qt4, QWizard сново часть Qt. QWizard и его | + | '''После исчезновения в клубах дыма, с выходом Qt4, QWizard сново часть Qt. QWizard и его нвоый подмастерье, QWizardPage, отработавшие свое краткое время в Qt4 Solutions, и теперь насыщенные возможностями, которые сделают работу програмиста мастеров легче, чем когда либо.''' |
__TOC__ | __TOC__ | ||
- | [[Qt:Документация_4.3.2/qwizard | QWizard]] | + | [[Qt:Документация_4.3.2/qwizard | QWizard]] provides a framework for writing wizards (also calledassistants). The purpose of a wizard is to guide the user through aprocess step by step. Compared with the [[Qt:Документация_4.3.2/qwizard | QWizard]] class foundin Qt 3 and the <tt>Q3Wizard</tt> compatibility class of Qt 4, the newwizard provides the following features: |
* '''Естественный внешний вид и поведение на всех платформах'''<br />[[Qt:Документация_4.3.2/qwizard | QWizard]] supports four different looks — Classic (Windows 95 and X11), Modern(Windows 98 to XP), Aero (Windows Vista), and Mac (Mac OS X). By default,[[Qt:Документация_4.3.2/qwizard | QWizard]] automatically chooses the most appropriate style for theuser's platform, but this can be overridden.<br /> | * '''Естественный внешний вид и поведение на всех платформах'''<br />[[Qt:Документация_4.3.2/qwizard | QWizard]] supports four different looks — Classic (Windows 95 and X11), Modern(Windows 98 to XP), Aero (Windows Vista), and Mac (Mac OS X). By default,[[Qt:Документация_4.3.2/qwizard | QWizard]] automatically chooses the most appropriate style for theuser's platform, but this can be overridden.<br /> | ||
Строка 17: | Строка 17: | ||
In this article, we will focus on the control and data flow aspectsof wizards: What happens when the user navigates between pages, whenis the user allowed to navigate between pages, and how do we accessdata on which to base these decisions? | In this article, we will focus on the control and data flow aspectsof wizards: What happens when the user navigates between pages, whenis the user allowed to navigate between pages, and how do we accessdata on which to base these decisions? | ||
- | === | + | ===A Ferry Booking Example=== |
- | + | We will use a ferry trip booking wizard to illustrate a number ofthe concepts of the new wizard framework. The five pages involved areintentionally very simple: A page for selecting a sailing date, apage for entering the name of a single passenger, a page for choosinga cabin type, a page for specifying a car registration number in caseyou want to bring your car, and finally a page for entering a creditcard number. | |
- | + | The following diagram depicts the possible navigation paths throughthe wizard: | |
[[Image:qq22-ferryexample.png|center]] | [[Image:qq22-ferryexample.png|center]] | ||
- | + | The initial implementation looks like this: | |
<source lang="cpp-qt"> | <source lang="cpp-qt"> | ||
class BookingWizard : public QWizard | class BookingWizard : public QWizard | ||
Строка 70: | Строка 70: | ||
} | } | ||
</source> | </source> | ||
- | + | The following code snippet shows how to open the wizard and collectresults from it: | |
<source lang="cpp-qt"> | <source lang="cpp-qt"> | ||
BookingWizard wizard; | BookingWizard wizard; | ||
Строка 80: | Строка 80: | ||
} | } | ||
</source> | </source> | ||
- | + | Notice how the <tt>BookingWizard</tt> class has to keep pointers to theinput widgets of all the pages in order to implement its publicinterface. In addition, if a page needs to access an input widget ofanother page, the pointer to the input widget would have to be passedto both pages. | |
+ | |||
===Регистрация и использование полей=== | ===Регистрация и использование полей=== | ||
Строка 136: | Строка 137: | ||
registerField("passenger", passenger); | registerField("passenger", passenger); | ||
</source> | </source> | ||
- | + | What about the property and the change signal? These could have beenpassed as the third and fourth arguments to <tt>registerField()</tt>, butby omitting them (effectively passing null pointers instead), we tell[[Qt:Документация_4.3.2/qwizardpage | QWizardPage]] that we would like to use default values here.[[Qt:Документация_4.3.2/qwizardpage | QWizardPage]] knows about the most common types of input widgets.Since [[Qt:Документация_4.3.2/qlineedit | QLineEdit]] is among the lucky ones (a subclass would alsodo), the text property and the <tt>textChanged()</tt> signal isautomatically used. | |
- | + | Alternatively, we could have added [[Qt:Документация_4.3.2/qcalendarwidget | QCalendarWidget]] to[[Qt:Документация_4.3.2/qwizard | QWizard]]'s list of recognized field types once and for all: | |
<source lang="cpp-qt"> | <source lang="cpp-qt"> | ||
setDefaultProperty("QCalendarWidget", "selectedDate", SIGNAL(selectionChanged())); | setDefaultProperty("QCalendarWidget", "selectedDate", SIGNAL(selectionChanged())); | ||
</source> | </source> | ||
- | === | + | ===Validate Before It's Too Late=== |
- | + | If some information in the wizard is invalid or inconsistent (e.g.,the passenger name is empty), it is currently not detected untilafter the wizard is closed. The wizard would then have to bereopened, and all the information, including the field that was incorrectin the first place, would have to be entered again. This is a verytedious, error-prone, and repetitive process that defeats thepurpose of using a wizard. | |
When hitting '''Next''' or '''Finish''' to accept the currentstate of a wizard, the user would intuitively expect the result to beacceptable. We would like errors to be caught and dealt with as earlyas possible. | When hitting '''Next''' or '''Finish''' to accept the currentstate of a wizard, the user would intuitively expect the result to beacceptable. We would like errors to be caught and dealt with as earlyas possible. | ||
Строка 192: | Строка 193: | ||
===Пропуск страницы в середине=== | ===Пропуск страницы в середине=== | ||
- | + | We are now going to support another peculiarity of the ferry company:Cars are not allowed on Saturdays. If the user has selected Saturdayas the sailing date, the '''Car''' page is skipped altogether. | |
[[Image:qq22-skipcar.png|center]] | [[Image:qq22-skipcar.png|center]] | ||
Строка 228: | Строка 229: | ||
</source> | </source> | ||
Use <tt>nextId()</tt> with care to avoid cycles and non-existent page IDs.Fortunately, [[Qt:Документация_4.3.2/qwizard | QWizard]] will warn about these cases at run-time. | Use <tt>nextId()</tt> with care to avoid cycles and non-existent page IDs.Fortunately, [[Qt:Документация_4.3.2/qwizard | QWizard]] will warn about these cases at run-time. | ||
+ | |||
===Пропуск последней страницы=== | ===Пропуск последней страницы=== |