1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
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
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
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.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \example itemviews/chart
|
---|
30 | \title Chart Example
|
---|
31 |
|
---|
32 | The Chart example shows how to create a custom view for the model/view framework.
|
---|
33 |
|
---|
34 | \image chart-example.png
|
---|
35 |
|
---|
36 | In this example, the items in a table model are represented as slices in a pie chart,
|
---|
37 | relying on the flexibility of the model/view architecture to handle custom editing
|
---|
38 | and selection features.
|
---|
39 |
|
---|
40 | \bold{Note that you only need to create a new view class if your data requires a
|
---|
41 | specialized representation.} You should first consider using a standard QListView,
|
---|
42 | QTableView, or QTreeView with a custom QItemDelegate subclass if you need to
|
---|
43 | represent data in a special way.
|
---|
44 |
|
---|
45 | \omit
|
---|
46 | \section1 PieView Class Definition
|
---|
47 |
|
---|
48 | The \c PieView class is a subclass of QAbstractItemView. The base class provides
|
---|
49 | much of the functionality required by view classes, so we only need to provide
|
---|
50 | implementations for three public functions: visualRect(), scrollTo(), and
|
---|
51 | indexAt(). However, the view needs to maintain strict control over its look and
|
---|
52 | feel, so we also provide implementations for a number of other functions:
|
---|
53 |
|
---|
54 | \snippet examples/itemviews/chart/pieview.h 0
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | \section1 PieView Class Implementation
|
---|
59 |
|
---|
60 | The paint event renders the data from the standard item model as a pie chart.
|
---|
61 | We interpret the data in the following way:
|
---|
62 |
|
---|
63 | \list
|
---|
64 | \o Column 0 contains data in two different roles:
|
---|
65 | The \l{Qt::ItemDataRole}{DisplayRole} contains a label, and the
|
---|
66 | \l{Qt::ItemDataRole}{DecorationRole} contains the color of the pie slice.
|
---|
67 | \o Column 1 contains a quantity which we will convert to the angular extent of
|
---|
68 | the slice.
|
---|
69 | \endlist
|
---|
70 |
|
---|
71 | The figure is always drawn with the chart on the left and the key on
|
---|
72 | the right. This means that we must try and obtain an area that is wider
|
---|
73 | than it is tall. We do this by imposing a particular aspect ratio on
|
---|
74 | the chart and applying it to the available vertical space. This ensures
|
---|
75 | that we always obtain the maximum horizontal space for the aspect ratio
|
---|
76 | used.
|
---|
77 | We also apply fixed size margin around the figure.
|
---|
78 |
|
---|
79 | We use logical coordinates to draw the chart and key, and position them
|
---|
80 | on the view using viewports.
|
---|
81 | \endomit
|
---|
82 | */
|
---|