Support synthesized oblique and bold in SceneGraph
[profile/ivi/qtbase.git] / doc / src / tutorials / modelview.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 documentation of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:FDL$
10 ** GNU Free Documentation License
11 ** Alternatively, this file may be used under the terms of the GNU Free
12 ** Documentation License version 1.3 as published by the Free Software
13 ** Foundation and appearing in the file included in the packaging of
14 ** this file.
15 **
16 ** Other Usage
17 ** Alternatively, this file may be used in accordance with the terms
18 ** and conditions contained in a signed written agreement between you
19 ** and Nokia.
20 **
21 **
22 **
23 **
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29     \page modelview.html
30     \ingroup tutorials
31     \startpage {index.html}{Qt Reference Documentation}
32
33     \title Model/View Tutorial
34     \brief An introduction to ModelView programming
35
36     Every UI developer should know about ModelView programming and the goal of
37     this tutorial is to provide you with an easily understandable introduction
38     to this topic.
39
40     Table, list and tree widgets are components frequently used in GUIs. There
41     are 2 different ways how these widgets can access their data. The
42     traditional way involves widgets which include internal containers for
43     storing data. This approach is very intuitive, however, in many non-trivial
44     applications, it leads to data synchronization issues.
45     The second approach is model/view programming, in
46     which widgets do not maintain internal data containers. They access external
47     data through a standardized interface and therefore avoid data duplication.
48     This may seem complicated at first, but once you take a closer look, it is
49     not only easy to grasp, but the many benefits of model/view programming also
50     become clearer.
51
52     \image treeview.png
53
54     In the process, we will learn about some basic technologies provided by Qt,
55     such as:
56
57     \list
58     \o The difference between standard and model/view widgets
59     \o Adapters betweeen forms and models
60     \o Developing a simple model/view application
61     \o Predefined models
62     \o Intermediate topics such as:
63       \list
64       \o Tree views
65       \o Selection
66       \o Delegates
67       \o Debugging with model test
68       \endlist
69     \endlist
70
71     You will also learn whether your new application can be written easier with
72     model/view programming or if classic widgets will work just as well.
73
74     This tutorial includes example code for you to edit and integrate into your
75     project. The tutorial's source code is located in Qt's
76     \c examples/tutorials/modelview directory.
77
78     For more detailed information you may also want to look at the
79     \l{model-view-programming.html}{reference documentation}
80
81     If you are completely new to Qt, please read \l{How to Learn Qt} if you
82     have not already done so.
83
84
85     \section1 1. Introduction
86
87     Model/View is a technology used to separate data from views in widgets that
88     handle data sets. Standard widgets are not designed for separating data
89     from views and this is why Qt 4 has two different types of widgets. Both
90     types of widgets look the same, but they interact with data differently.
91
92     \table
93         \row
94             \o  Standard widgets use data that is part of the widget.
95             \o  \image standardwidget.png
96         \row
97             \o  View classes operate on external data (the model)
98             \o  \image modelview.png
99     \endtable
100
101     \section2 1.1 Standard Widgets
102
103     Let's have a closer look at a standard table widget. A table widget is a 2D
104     array of the data elements that the user can change. The table widget can be
105     integrated into a program flow by reading and writing the data elements that
106     the table widget provides. 
107     This method is very intuitive and useful in many applications, but displaying 
108     and editing a database table with a standard table widget can be problematic.
109     Two copies of the data have to be coordinated: one outside the
110     widget; one inside the widget. The developer is responsible for
111     synchronizing both versions. Besides this, the tight coupling of presentation and data
112     makes it harder to write unit tests.
113
114     \section2 1.2 Model/View to the Rescue
115
116     Model/view stepped up to provide a solution that uses a more versatile
117     architecture. Model/view eliminates the data consistency problems that may
118     occur with standard widgets. Model/view also makes it easier to use more
119     than one view of the same data because one model can be passed on to many
120     views. The most important difference is that model/view widgets do not store
121     data behind the table cells. In fact, they operate directly from your data.
122     Since view classes do not know your data's structure, you need to provide a
123     wrapper to make your data conform to the QAbstractItemModel interface. A
124     view uses this interface to read from and write to your data. Any instance
125     of a class that implements QAbstractItemModel is said to be a model. Once
126     the view receives a pointer to a model, it will read and display its content
127     and be its editor.
128
129     \section2 1.3 Overview of the Model/View Widgets
130
131     Here is an overview of the model/view widgets and their corresponding
132     standard widgets.
133
134     \table
135         \header
136             \o  Widget
137             \o  Standard Widget\br
138                 (an item based convenience class)
139             \o  Model/View View Class\br
140                 (for use with external data)
141         \row
142             \o  \inlineimage listview.png
143             \o  \l QListWidget
144             \o  \l QListView
145         \row
146             \o  \inlineimage tableview.png
147             \o  \l QTableWidget
148             \o  \l QTableView
149         \row
150             \o  \inlineimage treeview.png
151             \o  \l QTreeWidget
152             \o  \l QTreeView
153         \row
154             \o  \inlineimage columnview.png
155             \o
156             \o  \l QColumnView shows a tree as a hierarchy of lists
157         \row
158             \o  \inlineimage modelview-combobox.png
159             \o {2, 1} \l QComboBox can work as both a view class and also
160                       as a traditional widget
161     \endtable
162
163     \section2 1.4 Using Adapters between Forms and Models
164
165     Having adapters between forms and models can come in handy.
166
167     We can edit data stored in tables directly from within the table itself, but
168     it's much more comfortable to edit data in text fields. There is no direct
169     model/view counterpart that separates data and views for widgets that
170     operate on one value (QLineEdit, QCheckBox ...) instead of a dataset, so we
171     need an adapter in order to connect the form to the source of data.
172
173     \l QDataWidgetMapper is a great solution because it maps form widgets to a
174     table row and makes it very easy to build forms for database tables.
175
176     \image widgetmapper.png
177
178     Another example of an adapter is \l QCompleter. Qt has \l QCompleter for
179     providing auto-completions in Qt widgets such as \l QComboBox and, as shown
180     below, \l QLineEdit. \l QCompleter uses a model as its data source.
181
182     \image qcompleter.png
183
184
185     \section1 2. A Simple Model/View Application
186     If you want to develop a model/view application, where should you start? 
187     We recommend starting with a simple example and extending it step-by-step. 
188     This makes understanding the architecture a lot easier. Trying to understand 
189     the model/view architecture in detail before invoking the IDE has proven 
190     to be less convenient for many developers. It is substantially easier to 
191     start with a simple model/view application that has demo data. Give it a 
192     try! Simply replace the data in the examples below with your own.
193
194     Below are 7 very simple and independent applications that show different
195     sides of model/view programming. The source code can be found inside the
196     \c{examples/tutorials/modelview} directory.
197
198     \section2 2.1 A Read Only Table
199
200     We start with an application that uses a QTableView to show data. We will
201     add editing capabilities later.
202
203     (file source: examples/tutorials/modelview/1_readonly/main.cpp)
204     \snippet examples/tutorials/modelview/1_readonly/main.cpp Quoting ModelView Tutorial
205
206     We have the usual \l {modelview-part2-main-cpp.html}{main()} function:
207
208     Here is the interesting part: We create an instance of MyModel and use 
209     \l{QTableView::setModel()}{tableView.setModel(&myModel);} to pass a
210     pointer of it to to \l{QTableView}{tableView}. \l{QTableView}{tableView}
211     will invoke the methods of the pointer it has received to find out two
212     things:
213
214     \list
215        \o How many rows and columns should be displayed.
216        \o What content should be printed into each cell.
217     \endlist
218
219     The model needs some code to respond to this.
220
221     We have a table data set, so let's start with QAbstractTableModel since it
222     is easier to use than the more general QAbstractItemModel.
223
224     (file source: examples/tutorials/modelview/1_readonly/mymodel.h)
225     \snippet examples/tutorials/modelview/1_readonly/mymodel.h Quoting ModelView Tutorial
226
227     QAbstractTableModel requires the implementation of three abstract methods.
228
229     (file source: examples/tutorials/modelview/1_readonly/mymodel.cpp)
230     \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp Quoting ModelView Tutorial
231
232     The number of rows and columns is provided by
233     \l{QAbstractItemModel::rowCount()}{MyModel::rowCount()} and
234     \l{QAbstractItemModel::columnCount()}{MyModel::columnCount()}. When the view
235     has to know what the cell's text is, it calls the method
236     \l{QAbstractItemModel::data()}{MyModel::data()}. Row and column information
237     is specified with parameter \c index and the role is set to
238     \l{Qt::ItemDataRole}{Qt::DisplayRole}. Other roles are covered in the next
239     section. In our example, the data that should be displayed is generated. In
240     a real application, \c MyModel would have a member called \c MyData, which
241     serves as the target for all reading and writing operations.
242
243     This small example demonstrates the passive nature of a model. The model
244     does not know when it will be used or which data is needed. It simply
245     provides data each time the view requests it.
246
247     What happens when the model's data needs to be changed? How does the view
248     realize that data has changed and needs to be read again? The model has to
249     emit a signal that indicates what range of cells has changed.  This will be
250     demonstrated in section 2.3.
251
252     \section2 2.2 Extending the Read Only Example with Roles
253
254     In addition to controlling what text the view displays, the model also
255     controls the text's appearance. When we slightly change the model, we get
256     the following result: \image readonlytable_role.png
257
258     In fact, nothing except for the \l{QAbstractItemModel::}{data()} method
259     needs to be changed to set fonts, background colour, alignment and a
260     checkbox.
261     Below is the \l{QAbstractItemModel::data()}{data()} method that produces the
262     result shown above. The difference is that this time we use parameter int
263     role to return different pieces of information depending on its value.
264
265     (file source: examples/tutorials/modelview/2_formatting/mymodel.cpp)
266     \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp Quoting ModelView Tutorial
267
268     Each formatting property will be requested from the model with a separate
269     call to the \l{QAbstractItemModel::data()}{data()} method. The \c role
270     parameter is used to let the model know which property is being requested:
271
272     \table
273         \header
274             \o \l{Qt::ItemDataRole}{enum Qt::ItemDataRole}
275             \o  Meaning
276             \o  Type
277         \row
278             \o \l{Qt::ItemDataRole}{}Qt::DisplayRole
279             \o  text
280             \o  QString
281         \row
282             \o \l{Qt::ItemDataRole}{Qt::FontRole}
283             \o  font
284             \o  QFont
285         \row
286             \o \l{Qt::ItemDataRole}{BackgroundRole}
287             \o  brush for the background of the cell
288             \o  QBrush
289         \row
290             \o \l{Qt::ItemDataRole}{Qt::TextAlignmentRole}
291             \o  text alignment
292             \o  \l{Qt::AlignmentFlag}{enum Qt::AlignmentFlag}
293         \row
294         \o {1, 3}  \l{Qt::ItemDataRole}{Qt::CheckStateRole}
295         \o {1, 3} suppresses checkboxes with \l{QVariant}{QVariant()},
296
297               sets checkboxes with \l{Qt::CheckState}{Qt::Checked}
298
299               or \l{Qt::CheckState}{Qt::Unchecked}
300         \o {1, 3}  \l{Qt::ItemDataRole}{enum Qt::ItemDataRole}
301     \endtable
302
303     Refer to the Qt namespace documentation to learn more about the
304     \l{Qt::ItemDataRole}{Qt::ItemDataRole} enum's capabilities.
305
306     Now we need to determine how using a separated model impacts the
307     application's performance, so let's trace how often the view calls the
308     \l{QAbstractItemModel::}{data()} method. In order to track how often the
309     view calls the model, we have put a debug statement in the
310     \l{QAbstractItemModel::}{data()} method, which logs onto the error output
311     stream. In our small example, \l{QAbstractItemModel::}{data()} will be
312     called 42 times.
313     Each time you hover the cursor over the field,
314     \l{QAbstractItemModel::}{data()} will be called again \mdash 7 times for
315     each cell. That's why it is important to make sure that your data is
316     available when \l{QAbstractItemModel::}{data()} is invoked and expensive
317     lookup operations are cached.
318
319     \section2 2.3 A Clock inside a Table Cell
320
321     \image clock.png
322
323     We still have a read only table, but this time the content changes every
324     second because we are showing the current time.
325
326     (file source: examples/tutorials/modelview/3_changingmodel/mymodel.cpp)
327     \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_QVariant
328
329     Something is missing to make the clock tick. We need to tell the view every
330     second that the time has changed and that it needs to be read again. We do
331     this with a timer. In the constructor, we set its interval to 1 second and
332     connect its timeout signal.
333
334     (file source: examples/tutorials/modelview/3_changingmodel/mymodel.cpp)
335     \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_a
336
337     Here is the corresponding slot:
338
339     (file source: examples/tutorials/modelview/3_changingmodel/mymodel.cpp)
340     \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_b
341
342     We ask the view to read the data in the top left cell again by emitting the
343     \l{QAbstractItemModel::}{dataChanged()} signal.  Note that we did not
344     explicitly connect the \l{QAbstractItemModel::}{dataChanged()} signal to the
345     view. This happened automatically when we called \l{QTableView::}{setModel()}.
346
347     \section2 2.4 Setting up Headers for Columns and Rows
348
349     Headers can be hidden via a view method: \c{tableView->verticalHeader()->hide();}
350     \image modelview-header.png
351
352     The header content, however, is set via the model, so we reimplement the
353     \l{QAbstractItemModel::headerData()}{headerData()} method:
354
355     (file source: examples/tutorials/modelview/4_headers/mymodel.cpp)
356     \snippet examples/tutorials/modelview/4_headers/mymodel.cpp quoting mymodel_c
357
358     Note that method \l{QAbstractItemModel::headerData()}{headerData()} also has
359     a parameter role which has the same meaning as in
360     \l{QAbstractItemModel::data()}{MyModel::data()}.
361
362     \section2 2.5 The Minimal Editing Example
363
364     In this example, we are going to build an application that automatically
365     populates a window title with content by repeating values entered into table
366     cells. To be able to access the window title easily we put the QTableView in
367     a QMainWindow.
368
369     The model decides whether editing capabilities are available. We only have
370     to modify the model in order for the available editing capabilities to be
371     enabled. This is done by reimplementing the following virtual methods:
372     \l{QAbstractItemModel::}{setData()} and \l{QAbstractItemModel::}{flags()}.
373
374     (file source: examples/tutorials/modelview/5_edit/mymodel.h)
375     \snippet examples/tutorials/modelview/5_edit/mymodel.h Quoting ModelView Tutorial
376
377     We use \c the two-dimensional array QString \c m_gridData to store our data.
378     This makes \c m_gridData the core of \c MyModel.  The rest of \c MyModel acts
379     like a wrapper and adapts \c m_gridData to the QAbstractItemModel
380     interface. We have also introduced the \c editCompleted() signal, which
381     makes it possible to transfer the modified text to the window title.
382
383     (file source: examples/tutorials/modelview/5_edit/mymodel.cpp)
384     \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_e
385
386     \l{QAbstractItemModel::setData()}{setData()} will be called each time the
387     user edits a cell. The \c index parameter tells us which field has been
388     edited and \c value  provides the result of the editing process. The role
389     will always be set to \l Qt::EditRole because our cells only contain text.
390     If a checkbox were present and user permissions are set to allow the
391     checkbox to be selected, calls would also be made with the role set to
392     \l Qt::CheckStateRole.
393
394     (file source: examples/tutorials/modelview/5_edit/mymodel.cpp)
395     \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_f
396
397     Various properties of a cell can be adjusted with
398     \l{QAbstractItemModel::flags()}{flags()}.
399
400     Returning \l{Qt::ItemFlag}{Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled}
401     is enough to show an editor that a cell can be selected.
402
403     If editing one cell modifies more data than the data in that particular
404     cell, the model must emit a \l{QAbstractItemModel::}{dataChanged()} signal
405     in order for the data that has been changed to be read.
406
407
408     \section1 3. Intermediate Topics
409
410     \section2 3.1 TreeView
411
412     You can convert the example above into an application with a tree view.
413     Simply replace QTableView with QTreeView, which results in a read/write
414     tree. No changes have to be made to the model. The tree won't have any
415     hierarchies because there aren't any hierarchies in the model itself.
416
417     \image dummy_tree.png
418
419     QListView, QTableView and QTreeView all use a model abstraction, which is a
420     merged list, table and tree. This makes it possible to use several different
421     types of view classes from the same model.
422
423     \image list_table_tree.png
424
425     This is how our example model looks so far:
426
427     \image example_model.png
428
429     We want to present a real tree. We have wrapped our data in the examples
430     above in order to make a model. This time we use QStandardItemModel, which
431     is a container for hierarchical data that also implements
432     QAbstractItemModel. To show a tree, QStandardItemModel must be populated
433     with \l{QStandardItem}s, which are able to hold all the standard properties
434     of items like text, fonts, checkboxes or brushes.
435
436     \image tree_2_with_algorithm.png
437
438     (file source: examples/tutorials/modelview/6_treeview/mainwindow.cpp)
439     \snippet examples/tutorials/modelview/6_treeview/mainwindow.cpp Quoting ModelView Tutorial
440
441     We simply instantiate a QStandardItemModel and add a couple of
442     \l{QStandardItem}{QStandardItems} to the constructor. We can then make a
443     hierarchical data structure because a QStandardItem can hold other
444     \l{QStandardItem}{QStandardItems}. Nodes are collapsed and expanded within
445     the view.
446
447     \section2 3.2 Working with Selections
448
449     We want to access a selected item's content in order to output it into the
450     window title together with the hierarchy level.
451
452     \image selection2.png
453
454     So let's create a couple of items:
455
456     (file source: examples/tutorials/modelview/7_selections/mainwindow.cpp)
457     \snippet examples/tutorials/modelview/7_selections/mainwindow.cpp quoting modelview_a
458
459     Views manage selections within a separate selection model, which can be
460     retrieved with the \l{QAbstractItemView::}{selectionModel()} method. We
461     retrieve the selection Model in order to connect a slot to its
462     \l{QAbstractItemView::}{selectionChanged()} signal.
463
464     (file source: examples/tutorials/modelview/7_selections/mainwindow.cpp)
465     \snippet examples/tutorials/modelview/7_selections/mainwindow.cpp quoting modelview_b
466
467     We get the model index that corresponds to the selection by calling
468     \l{QItemSelectionModel::currentIndex()}{treeView->selectionModel()->currentIndex()}
469     and we get the the field's string by using the model index. Then we just
470     calculate the item's \c hierarchyLevel.  Top level items do not have parents
471     and the \l{QAbstractItemModel::}{parent()} method will return a default
472     constructed \l{QModelIndex}{QModelIndex()}. This is why we use the
473     \l{QAbstractItemModel::}{parent()} method to iterate to the top level while
474     counting the steps performed during iteration.
475
476     The selection model (as shown above) can be retrieved, but it can also be
477     set with \l{QAbstractItemView}{QAbstractItemView::setSelectionModel}. This
478     is how it's possible to have 3 view classes with synchronised selections
479     because only one instance of a selection model is used. To share a selection
480     model between 3 views use \l{QAbstractItemView::}{selectionModel()} and
481     assign the result to the second and third view class with
482     \l{QAbstractItemView::}{setSelectionModel()}.
483
484     \section2 3.3 Predefined Models
485
486     The typical way to use model/view is to wrap specific data to make it usable
487     with view classes. Qt, however, also provides predefined models for common
488     underlying data structures. If one of the available data structures is
489     suitable for your application, a predefined model can be a good choice.
490
491     \table
492         \row
493             \o  QStringListModel
494             \o  Stores a list of strings
495         \row
496             \o  QStandardItemModel
497             \o  Stores arbitrary hierarchical items
498         \row
499             \o  QFileSystemModel\br
500                 QDirModel
501             \o  Encapsulate the local file system
502         \row
503             \o  QSqlQueryModel
504             \o  Encapsulate an SQL result set
505         \row
506             \o  QSqlTableModel
507             \o  Encapsulates an SQL table
508         \row
509             \o  QSqlRelationalTableModel
510             \o  Encapsulates an SQL table with foreign keys
511         \row
512             \o  QSortFilterProxyModel
513             \o  Sorts and/or filters another model
514
515     \endtable
516
517     \section2 3.4 Delegates
518
519     In all examples so far, data is presented as text or a checkbox in a cell
520     and is edited as text or a checkbox. The component that provides these
521     presentation and editing services is called a \e delegate. We are only just
522     beginning to work with the delegate because the view uses a default
523     delegate. But imagine that we want to have a different editor (e.g., a
524     slider or a drop down list) Or imagine that we want to present data as
525     graphics.
526     Let's take a look at an example called \l{Star Delegate Example}{Star
527     Delegate}, in which stars are used to show a rating:
528
529     \image stardelegate.png
530
531     The view has a \l{QAbstractItemView::}{setItemDelegate()} method that
532     replaces the default delegate and installs a custom delegate.
533     A new delegate can be written by creating a class that inherits from
534     QStyledItemDelegate. In order to write a delegate that displays stars and
535     has no input capabilities, we only need to override 2 methods.
536
537     \code
538      class StarDelegate : public QStyledItemDelegate
539      {
540          Q_OBJECT
541      public:
542          StarDelegate(QWidget *parent = 0);
543          void paint(QPainter *painter, const QStyleOptionViewItem &option,
544                     const QModelIndex &index) const;
545          QSize sizeHint(const QStyleOptionViewItem &option,
546                         const QModelIndex &index) const;
547      };
548     \endcode
549
550     \l{QStyledItemDelegate::}{paint()} draws stars depending on the content of
551     the underlying data.  The data can be looked up by calling
552     \l{QModelIndex::data()}{index.data()}. The delegate's
553     \l{QAbstractItemDelegate::}{sizeHint()} method is used to obtain each
554     star's dimensions, so the the cell will provide enough height and width to
555     accommodate the stars.
556
557     Writing custom delegates is the right choice if you want to show your data
558     with a custom graphical representation inside the grid of the view class. If
559     you want to leave the grid, you would not use a custom delegate but a custom
560     view class.
561
562     Other references to delegates in Qt Documentation:
563
564     \list
565     \o \l{Spin Box Delegate Example}
566     \o \l{QAbstractItemDelegate}{QAbstractItemDelegate Class Reference}
567     \o \l{QSqlRelationalDelegate}{QSqlRelationalDelegate Class Reference}
568     \o \l{QStyledItemDelegate}{QStyledItemDelegate Class Reference}
569     \o \l{QItemDelegate}{QItemDelegate Class Reference}
570     \endlist
571
572
573     \section2 3.5 Debugging with ModelTest
574
575     The passive nature of models provides new challenges for programmers.
576     Inconsistencies in the model can cause the application to crash. Since the
577     model is hit by numerous calls from the view, it is hard to find out which
578     call has crashed the application and which operation has introduced the
579     problem.
580
581     Qt Labs provides software called
582     \l{http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest}{ModelTest},
583     which checks models while your programming is running. Every time the model
584     is changed, ModelTest scans the model and reports errors with an assert.
585     This is especially important for tree models, since their hierarchical
586     nature leaves many possibilities for subtle inconsistencies.
587
588     Unlike view classes, ModelTest uses out of range indexes to test the model.
589     This means your application may crash with ModelTest even if it runs
590     perfectly without it. So you also need to handle all of the indexes that are
591     out of range when using ModelTest.
592
593
594     \section1 4. Good Sources of Additional Information
595
596     \section2 4.1 Books
597
598     Model/View programming is covered quite extensively in the documentation of
599     Qt but also in several good books.
600
601     \list 1
602        \o \bold{C++ GUI Programming with Qt 4} / Jasmin Blanchette, Mark Summerfield,
603           \e{Prentice Hall, 2nd edition}, ISBN 0-13-235416-0. Also available in
604           German: \bold{C++ GUI Programmierung mit Qt 4: Die offizielle Einführung},
605           \e{Addison-Wesley}, ISBN 3-827327-29-6
606        \o \bold{The Book of Qt4, The Art of Building Qt Applications} / Daniel Molkentin,
607           \e{Open Source Press}, ISBN 1-59327-147-6.
608           Translated from \bold{Qt 4, Einführung in die Applikationsentwicklung},
609           \e{Open Source Press}, ISBN 3-937514-12-0.
610        \o \bold{Foundations of Qt Development} / Johan Thelin, \e{Apress}, ISBN 1-59059-831-8.
611        \o \bold{Advanced Qt Programming} / Mark Summerfield, \e{Prentice Hall}, ISBN 0-321-63590-6. 
612           This book covers Model/View programming on more than 150 pages. 
613     \endlist
614
615     More information about these books is available on the
616     \l{Books about Qt Programming}{Qt Web site}.
617
618     The following list provides an overview of example programs contained in the first three
619     books listed above. Some of them make very good templates for developing similar
620     applications.
621
622     \table
623         \header
624             \o  Example name
625             \o  View class used
626             \o  Model used
627             \o  Aspects covered
628             \o
629         \row
630             \o  Team Leaders
631             \o  QListview
632             \o  QStringListModel
633             \o
634             \o  Book 1, Chapter 10, Figure 10.6
635         \row
636             \o  Directory Viewer
637             \o  QTreeView
638             \o  QDirModel
639             \o
640             \o  Book 1, Chapter 10, Figure 10.7
641         \row
642             \o  Color Names
643             \o  QListView
644             \o  QSortFilterProxyModel
645                 applied to QStringListModel
646             \o
647             \o  Book 1, Chapter 10, Figure 10.8
648         \row
649             \o  Currencies
650             \o  QTableView
651             \o  custom model based on
652                 QAbstractTableModel
653             \o  Read only
654             \o  Book 1, Chapter 10, Figure 10.10
655         \row
656             \o  Cities
657             \o  QTableView
658             \o  Custom model based on
659                 QAbstractTableModel
660             \o  Read / write
661             \o  Book 1, Chapter 10, Figure 10.12
662         \row
663             \o  Boolean Parser
664             \o  QTreeView
665             \o  Custom model based on
666                 QAbstractItemModel
667             \o  Read only
668             \o  Book 1, Chapter 10, Figure 10.14
669         \row
670             \o  Track Editor
671             \o  {2, 1} QTableWidget
672             \o  Custom delegate providing a custom editor
673             \o  Book 1, Chapter 10, Figure 10.15
674
675         \row
676             \o  Four directory views
677             \o  QListView
678                 QTableView
679                 QTreeView
680             \o  QDirModel
681             \o  Demonstrates the use of multiple views
682             \o  Book2, Chapter 8.2
683         \row
684             \o  Address Book
685             \o  QListView
686                 QTableView
687                 QTreeView
688             \o  Custom model based on
689                 QAbstractTableModel
690             \o  Read / write
691             \o  Book2, Chapter 8.4
692         \row
693             \o  Address Book with sorting
694             \o
695             \o  QProxyModel
696             \o  Introducing sort and filter capabilities
697             \o  Book2, Chapter 8.5
698         \row
699             \o  Address Book
700                 with checkboxes
701             \o
702             \o
703             \o  Introducing checkboxes in model/view
704             \o  Book2, Chapter 8.6
705         \row
706             \o  Address Book with transposed grid
707             \o
708             \o  Custom proxy Model based on QAbstractProxyModel
709             \o  Introducing a custom model
710             \o  Book2, Chapter 8.7
711         \row
712             \o  Address Book with drag and drop
713             \o
714             \o
715             \o  Introducing drag and drop support
716             \o  Book2, Chapter 8.8
717         \row
718             \o  Address Book with custom editor
719             \o
720             \o
721             \o  Introducing custom delegates
722             \o  Book2, Chapter 8.9
723         \row
724             \o  Views
725             \o  QListView
726                 QTableView
727                 QTreeView
728             \o  QStandardItemModel
729             \o  Read only
730             \o  Book 3, Chapter 5, figure 5-3
731         \row
732             \o  Bardelegate
733             \o  QTableView
734             \o
735             \o  Custom delegate for presentation based on QAbstractItemDelegate
736             \o  Book 3, Chapter 5, figure 5-5
737         \row
738             \o  Editdelegate
739             \o  QTableView
740             \o
741             \o  Custom delegate for editing based on QAbstractItemDelegate
742             \o  Book 3, Chapter 5, figure 5-6
743         \row
744             \o  Singleitemview
745             \o  Custom view based on QAbstractItemView
746             \o
747             \o  Custom view
748             \o  Book 3,
749                 Chapter 5,
750                 figure 5-7
751         \row
752             \o  listmodel
753             \o  QTableView
754             \o  Custom Model based on QAbstractTableModel
755             \o  Read only
756             \o  Book 3, Chapter 5, Figure 5-8
757         \row
758             \o  treemodel
759             \o  QTreeView
760             \o  Custom Model based on QAbstractItemModel
761             \o  Read only
762             \o  Book 3, Chapter 5, Figure 5-10
763         \row
764             \o  edit integers
765             \o  QListView
766             \o  Custom Model based on QAbstractListModel
767             \o  Read / write
768             \o  Book 3, Chapter 5, Listing 5-37, Figure 5-11
769         \row
770             \o  sorting
771             \o  QTableView
772             \o  QSortFilterProxyModel applied to QStringListModel
773             \o  Demonstrates sorting
774             \o  Book 3, Chapter 5, Figure 5-12
775     \endtable
776
777
778     \section2 4.2 Qt Documentation
779
780     Qt 5.0 comes with 19 examples for model/view.
781     The examples can be found on the \l{Item Views Examples} page.
782
783     \table
784         \header
785             \o  Example name
786             \o  View class used
787             \o  Model used
788             \o  Aspects covered
789         \row
790             \o  Address Book
791             \o  QTableView
792             \o  QAbstractTableModel
793                 QSortFilterProxyModel
794             \o  Usage of QSortFilterProxyModel to generate different
795                 subsets from one data pool
796         \row
797             \o  Basic Sort/Filter Model
798             \o  QTreeView
799             \o  QStandardItemModel
800                 QSortFilterProxyModel
801             \o
802         \row
803             \o  Chart
804             \o  Custom view
805             \o  QStandardItemModel
806             \o  Designing custom views that cooperate with selection models
807         \row
808             \o  Color Editor Factory
809             \o  {2, 1}  QTableWidget
810             \o  Enhancing the standard delegate with a new custom editor to choose colours
811         \row
812             \o  Combo Widget Mapper
813             \o  QDataWidgetMapper to map QLineEdit, QTextEdit and QComboBox
814             \o  QStandardItemModel
815             \o  Shows how a QComboBox can serve as a view class
816         \row
817             \o  Custom Sort/Filter Model
818             \o  QTreeView
819             \o  QStandardItemModel
820                 QSortFilterProxyModel
821             \o  Subclass QSortFilterProxyModel for advanced sorting and filtering
822         \row
823             \o  Dir View
824             \o  QTreeView
825             \o  QDirModel
826             \o  Very small example to demonstrate how to assign a model to a view
827         \row
828             \o  Editable Tree Model
829             \o  QTreeView
830             \o  Custom tree model
831             \o  Comprehensive example for working with trees, demonstrates
832                 editing cells and tree structure with an underlying custom
833                 model
834         \row
835             \o  Fetch More
836             \o  QListView
837             \o  Custom list model
838             \o  Dynamically changing model
839         \row
840             \o  Frozen Column
841             \o  QTableView
842             \o  QStandardItemModel
843             \o
844         \row
845             \o  Interview
846             \o  Multiple
847             \o  Custom item model
848             \o  Multiple views
849         \row
850             \o  Pixelator
851             \o  QTableView
852             \o  Custom table model
853             \o  Implementation of a custom delegate
854         \row
855             \o  Puzzle
856             \o  QListView
857             \o  Custom list model
858             \o  Model/view with drag and drop
859         \row
860             \o  Simple DOM Model
861             \o  QTreeView
862             \o  Custom tree model
863             \o  Read only example for a custom tree model
864         \row
865             \o  Simple Tree Model
866             \o  QTreeView
867             \o  Custom tree model
868             \o  Read only example for a custom tree model
869         \row
870             \o  Simple Widget Mapper
871             \o  QDataWidgetMapper to map QLineEdit, QTextEdit and QSpinBox
872             \o  QStandardItemModel
873             \o  Basic QDataWidgetMapper usage
874         \row
875             \o  Spin Box Delegate
876             \o  QTableView
877             \o  QStandardItemModel
878             \o  Custom delegate that uses a spin box as a cell editor
879         \row
880             \o  Spreadsheet
881             \o  {2, 1}  QTableView
882             \o  Custom delegates
883         \row
884             \o  Star Delegate
885             \o  {2, 1}  QTableWidget
886             \o  Comprehensive custom delegate example.
887     \endtable
888
889     A \l{Model/View Programming}{reference document} for model/view technology
890     is also available.
891 */
892
893 /*!
894     \page modelview-part2-main-cpp.html
895     \title main.cpp
896     \quotefile tutorials/modelview/1_readonly/main.cpp
897 */