1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \example itemviews/combowidgetmapper
|
---|
44 | \title Combo Widget Mapper Example
|
---|
45 |
|
---|
46 | The Delegate Widget Mapper example shows how to use a custom delegate to
|
---|
47 | map information from a model to specific widgets on a form.
|
---|
48 |
|
---|
49 | \image combo-widget-mapper.png
|
---|
50 |
|
---|
51 | In the \l{Simple Widget Mapper Example}, we showed the basic use of a
|
---|
52 | widget mapper to relate data exposed by a model to simple input widgets
|
---|
53 | in a user interface. However, sometimes we want to use input widgets that
|
---|
54 | expose data as choices to the user, such as QComboBox, and we need a way
|
---|
55 | to relate their input to the values stored in the model.
|
---|
56 |
|
---|
57 | This example is very similar to the \l{Simple Widget Mapper Example}.
|
---|
58 | Again, we create a \c Window class with an almost identical user interface,
|
---|
59 | except that, instead of providing a spin box so that each person's age
|
---|
60 | can be entered, we provide a combo box to allow their addresses to be
|
---|
61 | classified as "Home", "Work" or "Other".
|
---|
62 |
|
---|
63 | \section1 Window Class Definition
|
---|
64 |
|
---|
65 | The class provides a constructor, a slot to keep the buttons up to date,
|
---|
66 | and a private function to set up the model:
|
---|
67 |
|
---|
68 | \snippet examples/itemviews/combowidgetmapper/window.h Window definition
|
---|
69 |
|
---|
70 | In addition to the QDataWidgetMapper object and the controls used to make
|
---|
71 | up the user interface, we use a QStandardItemModel to hold our data and
|
---|
72 | a QStringListModel to hold information about the types of address that
|
---|
73 | can be applied to each person's data.
|
---|
74 |
|
---|
75 | \section1 Window Class Implementation
|
---|
76 |
|
---|
77 | The constructor of the \c Window class can be explained in three parts.
|
---|
78 | In the first part, we set up the widgets used for the user interface:
|
---|
79 |
|
---|
80 | \snippet examples/itemviews/combowidgetmapper/window.cpp Set up widgets
|
---|
81 |
|
---|
82 | Note that we set up the mapping the combo box in the same way as for other
|
---|
83 | widgets, but that we apply its own model to it so that it will display
|
---|
|
---|