source: trunk/doc/src/model-view-programming.qdoc@ 551

Last change on this file since 551 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 113.1 KB
Line 
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 \page model-view-programming.html
44 \nextpage An Introduction to Model/View Programming
45 \startpage index.html Qt Reference Documentation
46
47 \title Model/View Programming
48 \ingroup architecture
49 \brief A guide to the extensible model/view architecture used by Qt's
50 item view classes.
51
52 \list
53 \o \l{An Introduction to Model/View Programming}
54 \tableofcontents{1 An Introduction to Model/View Programming}
55 \o \l{Using Models and Views}
56 \tableofcontents{1 Using Models and Views}
57 \o \l{Model Classes}
58 \tableofcontents{1 Model Classes}
59 \o \l{Creating New Models}
60 \tableofcontents{1 Creating New Models}
61 \o \l{View Classes}
62 \tableofcontents{1 View Classes}
63 \o \l{Handling Selections in Item Views}
64 \tableofcontents{1 Handling Selections in Item Views}
65 \o \l{Delegate Classes}
66 \tableofcontents{1 Delegate Classes}
67 \o \l{Item View Convenience Classes}
68 \tableofcontents{1 Item View Convenience Classes}
69 \o \l{Using Drag and Drop with Item Views}
70 \tableofcontents{1 Using Drag and Drop with Item Views}
71 \o \l{Proxy Models}
72 \tableofcontents{1 Proxy Models}
73 \o \l{Model Subclassing Reference}
74 \tableofcontents{1 Model Subclassing Reference}
75 \endlist
76
77 See also the list of \l{Model/View Classes}.
78
79 \section1 Related Examples
80
81 \list
82 \o \l{itemviews/dirview}{Dir View}
83 \o \l{itemviews/spinboxdelegate}{Spin Box Delegate}
84 \o \l{itemviews/pixelator}{Pixelator}
85 \o \l{itemviews/simpletreemodel}{Simple Tree Model}
86 \o \l{itemviews/chart}{Chart}
87 \endlist
88*/
89
90/*!
91 \page model-view-introduction.html
92 \previouspage Model/View Programming
93 \nextpage Using Models and Views
94 \startpage index.html Qt Reference Documentation
95
96 \title An Introduction to Model/View Programming
97
98 \tableofcontents
99
100 Qt 4 introduces a new set of item view classes that use a model/view
101 architecture to manage the relationship between data and the way it
102 is presented to the user. The separation of functionality introduced by
103 this architecture gives developers greater flexibility to customize the
104 presentation of items, and provides a standard model interface to allow
105 a wide range of data sources to be used with existing item views.
106 In this document, we give a brief introduction to the model/view paradigm,
107 outline the concepts involved, and describe the architecture of the item
108 view system. Each of the components in the architecture is explained,
109 and examples are given that show how to use the classes provided.
110
111 \section1 The Model/View Architecture
112
113 Model-View-Controller (MVC) is a design pattern originating from
114 Smalltalk that is often used when building user interfaces.
115 In \l{Design Patterns}, Gamma et al. write:
116
117 \quotation
118 MVC consists of three kinds of objects. The Model is the application
119 object, the View is its screen presentation, and the Controller defines
120 the way the user interface reacts to user input. Before MVC, user
121 interface designs tended to lump these objects together. MVC decouples
122 them to increase flexibility and reuse.
123 \endquotation
124
125 If the view and the controller objects are combined, the result is
126 the model/view architecture. This still separates the way that data
127 is stored from the way that it is presented to the user, but provides
128 a simpler framework based on the same principles. This separation
129 makes it possible to display the same data in several different views,
130 and to implement new types of views, without changing the underlying
131 data structures.
132 To allow flexible handling of user input, we introduce the concept of