@@ -1,155 +1,155 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | import QmlCustomModel 1.0 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | anchors.fill: parent |
|
27 | 27 | |
|
28 | 28 | //![1] |
|
29 | 29 | ChartView { |
|
30 | 30 | id: chartView |
|
31 | 31 | title: "Top-5 car brand shares in Finland" |
|
32 | 32 | anchors.fill: parent |
|
33 | 33 | axisX.max: 10 |
|
34 | 34 | axisX.min: 0 |
|
35 | 35 | axisY.max: 20 |
|
36 | 36 | axisY.min: 0 |
|
37 | 37 | animationOptions: ChartView.SeriesAnimations |
|
38 | 38 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] |
|
39 | 39 | // ... |
|
40 | 40 | //![1] |
|
41 | 41 | |
|
42 | 42 | //![2] |
|
43 | 43 | CustomModel { |
|
44 | 44 | id: customModel |
|
45 | 45 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] |
|
46 | 46 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
47 | 47 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } |
|
48 | 48 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } |
|
49 | 49 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } |
|
50 | 50 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } |
|
51 | 51 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
52 | 52 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
53 | 53 | } |
|
54 | 54 | //![2] |
|
55 | 55 | |
|
56 | 56 | //![5] |
|
57 | 57 | BarSeries { |
|
58 | 58 | name: "Others" |
|
59 | 59 | barWidth: 0.9 |
|
60 | 60 | visible: false |
|
61 | 61 | HBarModelMapper { |
|
62 | 62 | model: customModel |
|
63 | 63 | firstBarSetRow: 6 |
|
64 | 64 | lastBarSetRow: 6 |
|
65 | 65 | firstColumn: 2 |
|
66 | 66 | } |
|
67 | 67 | } |
|
68 | 68 | //![5] |
|
69 | 69 | |
|
70 | 70 | //![4] |
|
71 | 71 | LineSeries { |
|
72 | 72 | name: "Volkswagen" |
|
73 | 73 | visible: false |
|
74 | 74 | HXYModelMapper { |
|
75 | 75 | model: customModel |
|
76 | 76 | xRow: 0 |
|
77 | 77 | yRow: 1 |
|
78 | first: 2 | |
|
78 | firstColumn: 2 | |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | //![4] |
|
82 | 82 | |
|
83 | 83 | LineSeries { |
|
84 | 84 | name: "Toyota" |
|
85 | 85 | visible: false |
|
86 | 86 | HXYModelMapper { |
|
87 | 87 | model: customModel |
|
88 | 88 | xRow: 0 |
|
89 | 89 | yRow: 2 |
|
90 | first: 2 | |
|
90 | firstColumn: 2 | |
|
91 | 91 | } |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | LineSeries { |
|
95 | 95 | name: "Ford" |
|
96 | 96 | visible: false |
|
97 | 97 | HXYModelMapper { |
|
98 | 98 | model: customModel |
|
99 | 99 | xRow: 0 |
|
100 | 100 | yRow: 3 |
|
101 | first: 2 | |
|
101 | firstColumn: 2 | |
|
102 | 102 | } |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | LineSeries { |
|
106 | 106 | name: "Skoda" |
|
107 | 107 | visible: false |
|
108 | 108 | HXYModelMapper { |
|
109 | 109 | model: customModel |
|
110 | 110 | xRow: 0 |
|
111 | 111 | yRow: 4 |
|
112 | first: 2 | |
|
112 | firstColumn: 2 | |
|
113 | 113 | } |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | LineSeries { |
|
117 | 117 | name: "Volvo" |
|
118 | 118 | visible: false |
|
119 | 119 | HXYModelMapper { |
|
120 | 120 | model: customModel |
|
121 | 121 | xRow: 0 |
|
122 | 122 | yRow: 5 |
|
123 | first: 2 | |
|
123 | firstColumn: 2 | |
|
124 | 124 | } |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | //![3] |
|
128 | 128 | PieSeries { |
|
129 | 129 | id: pieSeries |
|
130 | 130 | size: 0.4 |
|
131 | 131 | horizontalPosition: 0.7 |
|
132 | 132 | verticalPosition: 0.4 |
|
133 | 133 | onClicked: { |
|
134 | 134 | // Show the selection by exploding the slice |
|
135 | 135 | slice.exploded = !slice.exploded; |
|
136 | 136 | |
|
137 | 137 | // Update the line series to show the yearly data for this slice |
|
138 | 138 | for (var i = 0; i < chartView.count; i++) { |
|
139 | 139 | if (chartView.series(i).name == slice.label) { |
|
140 | 140 | chartView.series(i).visible = slice.exploded; |
|
141 | 141 | } |
|
142 | 142 | } |
|
143 | 143 | } |
|
144 | 144 | } |
|
145 | 145 | //![3] |
|
146 | 146 | |
|
147 | 147 | VPieModelMapper { |
|
148 | 148 | series: pieSeries |
|
149 | 149 | model: customModel |
|
150 | 150 | labelsColumn: 1 |
|
151 | 151 | valuesColumn: 2 |
|
152 | 152 | firstRow: 1 |
|
153 | 153 | } |
|
154 | 154 | } |
|
155 | 155 | } |
@@ -1,100 +1,100 | |||
|
1 | 1 | /*! |
|
2 | 2 | \page classes.html |
|
3 | 3 | \title QtCommercial Charts API |
|
4 | 4 | \keyword All Classes |
|
5 | 5 | |
|
6 | 6 | Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However |
|
7 | 7 | there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget. |
|
8 | 8 | The API supports following chart types: |
|
9 | 9 | |
|
10 | 10 | \list |
|
11 | 11 | \o line |
|
12 | 12 | \o area |
|
13 | 13 | \o scatter |
|
14 | 14 | \o spline |
|
15 | 15 | \o pie |
|
16 | 16 | \o grouped bar |
|
17 | 17 | \o percent bar |
|
18 | 18 | \o stacked bar |
|
19 | 19 | \endlist |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance. |
|
23 | 23 | \code |
|
24 | 24 | QLineSeries* series = new QLineSeries(); |
|
25 | 25 | series->add(0, 6); |
|
26 | 26 | series->add(2, 4); |
|
27 | 27 | ... |
|
28 | 28 | chartView->chart()->addSeries(series); |
|
29 | 29 | \endcode |
|
30 | 30 | |
|
31 | 31 | \raw HTML |
|
32 | 32 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
33 | 33 | <tr> |
|
34 | 34 | <th class="titleheader" width="25%"> |
|
35 | 35 | Common and global |
|
36 | 36 | </th> |
|
37 | 37 | <th class="titleheader" width="25%"> |
|
38 | 38 | XY chart |
|
39 | 39 | </th> |
|
40 | 40 | </tr> |
|
41 | 41 | <tr> |
|
42 | 42 | <td valign="top"> |
|
43 | 43 | <ul> |
|
44 | 44 | <li><a href="qchart.html">QChart</a></li> |
|
45 | 45 | <li><a href="qaxis.html">QAxis</a></li> |
|
46 | 46 | <li><a href="qaxiscategories.html">QAxisCategories</a></li> |
|
47 | 47 | <li><a href="qchartview.html">QChartView</a></li> |
|
48 | 48 | <li><a href="qlegend.html">QLegend</a></li> |
|
49 | 49 | <li><a href="qabstractseries.html">QAbstractSeries</a></li> |
|
50 | 50 | <li><a href="qchartglobal.html">QChartGlobal</a></li> |
|
51 | 51 | </ul> |
|
52 | 52 | </td> |
|
53 | 53 | <td valign="top"> |
|
54 | 54 | <ul> |
|
55 | <li><a href="qxyseries.html">QXYSeries</a></li> | |
|
55 | 56 | <li><a href="qlineseries.html">QLineSeries</a></li> |
|
56 | 57 | <li><a href="qareaseries.html">QAreaSeries</a></li> |
|
57 | 58 | <li><a href="qscatterseries.html">QScatterSeries</a></li> |
|
58 | 59 | <li><a href="qsplineseries.html">QSplineSeries</a></li> |
|
59 | <li><a href="qxymodelmapper.html">QXYModelMapper</a></li> | |
|
60 | 60 | <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li> |
|
61 | 61 | <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li> |
|
62 | 62 | </ul> |
|
63 | 63 | </td> |
|
64 | 64 | </tr> |
|
65 | 65 | </table> |
|
66 | 66 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
67 | 67 | <tr> |
|
68 | 68 | <th class="titleheader" width="25%"> |
|
69 | 69 | Pie chart |
|
70 | 70 | </th> |
|
71 | 71 | <th class="titleheader" width="25%"> |
|
72 | 72 | Bar chart |
|
73 | 73 | </th> |
|
74 | 74 | <tr> |
|
75 | 75 | <td valign="top"> |
|
76 | 76 | <ul> |
|
77 | 77 | <li><a href="qpieseries.html">QPieSeries</a></li> |
|
78 | 78 | <li><a href="qpieslice.html">QPieSlice</a></li> |
|
79 | 79 | <li><a href="qpiemodelmapper.html">QPieModelMapper</a></li> |
|
80 | 80 | <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li> |
|
81 | 81 | <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li> |
|
82 | 82 | </ul> |
|
83 | 83 | </td> |
|
84 | 84 | <td valign="top"> |
|
85 | 85 | <ul> |
|
86 | 86 | <li><a href="qbarseries.html">QBarSeries</a></li> |
|
87 | 87 | <li><a href="qbarset.html">QBarSet</a></li> |
|
88 | 88 | <li><a href="qgroupedbarseries.html">QGroupedBarSeries</a></li> |
|
89 | 89 | <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li> |
|
90 | 90 | <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li> |
|
91 | 91 | <li><a href="qbarmodelmapper.html">QBarModelMapper</a></li> |
|
92 | 92 | <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li> |
|
93 | 93 | <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li> |
|
94 | 94 | </ul> |
|
95 | 95 | </td> |
|
96 | 96 | </tr> |
|
97 | 97 | </table> |
|
98 | 98 | \endraw |
|
99 | 99 | |
|
100 | 100 | */ |
@@ -1,98 +1,206 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qhxymodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QHXYModelMapper |
|
27 | \brief part of QtCommercial chart API. | |
|
28 | 27 | \mainclass |
|
29 | 28 | |
|
30 | 29 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 30 | Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. |
|
32 | 31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. |
|
33 | 32 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | 33 | */ |
|
35 | 34 | |
|
36 | 35 | /*! |
|
36 | \property QHXYModelMapper::series | |
|
37 | \brief Defines the QXYSeries object that is used by the mapper. | |
|
38 | ||
|
39 | All the data in the series is discarded when it is set to the mapper. | |
|
40 | When new series is specified the old series is disconnected (it preserves its data) | |
|
41 | */ | |
|
42 | ||
|
43 | /*! | |
|
44 | \property QHXYModelMapper::model | |
|
45 | \brief Defines the model that is used by the mapper. | |
|
46 | */ | |
|
47 | ||
|
48 | /*! | |
|
37 | 49 | \property QHXYModelMapper::xRow |
|
38 | 50 | \brief Defines which row of the model is kept in sync with the x values of the QXYSeries |
|
39 | 51 | Default value is: -1 (invalid mapping) |
|
40 | 52 | */ |
|
41 | 53 | |
|
42 | 54 | /*! |
|
43 | 55 | \property QHXYModelMapper::yRow |
|
44 | 56 | \brief Defines which row of the model is kept in sync with the y values of the QXYSeries |
|
45 | 57 | |
|
46 | 58 | Default value is: -1 (invalid mapping) |
|
47 | 59 | */ |
|
48 | 60 | |
|
49 | 61 | /*! |
|
62 | \property QHXYModelMapper::firstColumn | |
|
63 | \brief Defines which column of the model contains the data for the first point of the series. | |
|
64 | Minimal and default value is: 0 | |
|
65 | */ | |
|
66 | /*! | |
|
67 | \qmlproperty int QHXYModelMapper::firstColumn | |
|
68 | Defines which column of the model contains the data for the first point of the series. | |
|
69 | The default value is 0. | |
|
70 | */ | |
|
71 | ||
|
72 | /*! | |
|
73 | \property QHXYModelMapper::columnCount | |
|
74 | \brief Defines the number of columns of the model that are mapped as the data for series | |
|
75 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
|
76 | */ | |
|
77 | /*! | |
|
78 | \qmlproperty int QHXYModelMapper::columnCount | |
|
79 | Defines the number of columns of the model that are mapped as the data for series. The default value is | |
|
80 | -1 (count limited by the number of columns in the model) | |
|
81 | */ | |
|
82 | ||
|
83 | /*! | |
|
84 | \fn void QHXYModelMapper::seriesReplaced() | |
|
85 | ||
|
86 | Emitted when the series to which mapper is connected to has changed. | |
|
87 | */ | |
|
88 | ||
|
89 | /*! | |
|
90 | \fn void QHXYModelMapper::modelReplaced() | |
|
91 | ||
|
92 | Emitted when the model to which mapper is connected to has changed. | |
|
93 | */ | |
|
94 | ||
|
95 | /*! | |
|
50 | 96 | \fn void QHXYModelMapper::xRowChanged() |
|
51 | 97 | |
|
52 | 98 | Emitted when the xRow has changed. |
|
53 | 99 | */ |
|
54 | 100 | |
|
55 | 101 | /*! |
|
56 | 102 | \fn void QHXYModelMapper::yRowChanged() |
|
57 | 103 | |
|
58 | 104 | Emitted when the yRow has changed. |
|
59 | 105 | */ |
|
60 | 106 | |
|
61 | 107 | /*! |
|
108 | \fn void QHXYModelMapper::firstColumnChanged() | |
|
109 | Emitted when the firstColumn has changed. | |
|
110 | */ | |
|
111 | ||
|
112 | /*! | |
|
113 | \fn void QHXYModelMapper::columnCountChanged() | |
|
114 | Emitted when the columnCount has changed. | |
|
115 | */ | |
|
116 | ||
|
117 | /*! | |
|
62 | 118 | Constructs a mapper object which is a child of \a parent. |
|
63 | 119 | */ |
|
64 | 120 | QHXYModelMapper::QHXYModelMapper(QObject *parent) : |
|
65 | 121 | QXYModelMapper(parent) |
|
66 | 122 | { |
|
67 | 123 | QXYModelMapper::setOrientation(Qt::Horizontal); |
|
68 | 124 | } |
|
69 | 125 | |
|
126 | QAbstractItemModel* QHXYModelMapper::model() const | |
|
127 | { | |
|
128 | return QXYModelMapper::model(); | |
|
129 | } | |
|
130 | ||
|
131 | void QHXYModelMapper::setModel(QAbstractItemModel *model) | |
|
132 | { | |
|
133 | if (model != QXYModelMapper::model()) { | |
|
134 | QXYModelMapper::setModel(model); | |
|
135 | emit modelReplaced(); | |
|
136 | } | |
|
137 | } | |
|
138 | ||
|
139 | QXYSeries* QHXYModelMapper::series() const | |
|
140 | { | |
|
141 | return QXYModelMapper::series(); | |
|
142 | } | |
|
143 | ||
|
144 | void QHXYModelMapper::setSeries(QXYSeries *series) | |
|
145 | { | |
|
146 | if (series != QXYModelMapper::series()) { | |
|
147 | QXYModelMapper::setSeries(series); | |
|
148 | emit seriesReplaced(); | |
|
149 | } | |
|
150 | } | |
|
151 | ||
|
70 | 152 | int QHXYModelMapper::xRow() const |
|
71 | 153 | { |
|
72 | 154 | return QXYModelMapper::xSection(); |
|
73 | 155 | } |
|
74 | 156 | |
|
75 | 157 | void QHXYModelMapper::setXRow(int xRow) |
|
76 | 158 | { |
|
77 | 159 | if (xRow != xSection()) { |
|
78 | 160 | return QXYModelMapper::setXSection(xRow); |
|
79 | 161 | emit xRowChanged(); |
|
80 | 162 | } |
|
81 | 163 | } |
|
82 | 164 | |
|
83 | 165 | int QHXYModelMapper::yRow() const |
|
84 | 166 | { |
|
85 | 167 | return QXYModelMapper::ySection(); |
|
86 | 168 | } |
|
87 | 169 | |
|
88 | 170 | void QHXYModelMapper::setYRow(int yRow) |
|
89 | 171 | { |
|
90 | 172 | if (yRow != ySection()) { |
|
91 | 173 | return QXYModelMapper::setYSection(yRow); |
|
92 | 174 | emit yRowChanged(); |
|
93 | 175 | } |
|
94 | 176 | } |
|
95 | 177 | |
|
178 | int QHXYModelMapper::firstColumn() const | |
|
179 | { | |
|
180 | return first(); | |
|
181 | } | |
|
182 | ||
|
183 | void QHXYModelMapper::setFirstColumn(int firstColumn) | |
|
184 | { | |
|
185 | if (firstColumn != first()) { | |
|
186 | setFirst(firstColumn); | |
|
187 | emit firstColumnChanged(); | |
|
188 | } | |
|
189 | } | |
|
190 | ||
|
191 | int QHXYModelMapper::columnCount() const | |
|
192 | { | |
|
193 | return count(); | |
|
194 | } | |
|
195 | ||
|
196 | void QHXYModelMapper::setColumnCount(int columnCount) | |
|
197 | { | |
|
198 | if (columnCount != count()) { | |
|
199 | setCount(columnCount); | |
|
200 | emit firstColumnChanged(); | |
|
201 | } | |
|
202 | } | |
|
203 | ||
|
96 | 204 | #include "moc_qhxymodelmapper.cpp" |
|
97 | 205 | |
|
98 | 206 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,70 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QHXYMODELMAPPER_H |
|
22 | 22 | #define QHXYMODELMAPPER_H |
|
23 | 23 | |
|
24 | 24 | #include <QXYModelMapper> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper |
|
29 | 29 | { |
|
30 | 30 | Q_OBJECT |
|
31 | Q_PROPERTY(QXYSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
|
32 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
|
31 | 33 | Q_PROPERTY(int xRow READ xRow WRITE setXRow NOTIFY xRowChanged) |
|
32 | 34 | Q_PROPERTY(int yRow READ yRow WRITE setYRow NOTIFY yRowChanged) |
|
35 | Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) | |
|
36 | Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) | |
|
33 | 37 | |
|
34 | 38 | public: |
|
35 | 39 | explicit QHXYModelMapper(QObject *parent = 0); |
|
40 | ||
|
41 | QAbstractItemModel* model() const; | |
|
42 | void setModel(QAbstractItemModel *model); | |
|
43 | ||
|
44 | QXYSeries* series() const; | |
|
45 | void setSeries(QXYSeries *series); | |
|
36 | 46 | |
|
37 | 47 | int xRow() const; |
|
38 | 48 | void setXRow(int xRow); |
|
39 | 49 | |
|
40 | 50 | int yRow() const; |
|
41 | 51 | void setYRow(int yRow); |
|
42 | 52 | |
|
53 | int firstColumn() const; | |
|
54 | void setFirstColumn(int firstColumn); | |
|
55 | ||
|
56 | int columnCount() const; | |
|
57 | void setColumnCount(int columnCount); | |
|
58 | ||
|
43 | 59 | Q_SIGNALS: |
|
60 | void seriesReplaced(); | |
|
61 | void modelReplaced(); | |
|
44 | 62 | void xRowChanged(); |
|
45 | 63 | void yRowChanged(); |
|
64 | void firstColumnChanged(); | |
|
65 | void columnCountChanged(); | |
|
46 | 66 | }; |
|
47 | 67 | |
|
48 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | 69 | |
|
50 | 70 | #endif // QHXYMODELMAPPER_H |
@@ -1,99 +1,207 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qvxymodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVXYModelMapper |
|
27 | \brief part of QtCommercial chart API. | |
|
28 | 27 | \mainclass |
|
29 | 28 | |
|
30 | 29 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 30 | Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. |
|
32 | 31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. |
|
33 | 32 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | 33 | */ |
|
35 | 34 | |
|
36 | 35 | /*! |
|
36 | \property QVXYModelMapper::series | |
|
37 | \brief Defines the QXYSeries object that is used by the mapper. | |
|
38 | ||
|
39 | All the data in the series is discarded when it is set to the mapper. | |
|
40 | When new series is specified the old series is disconnected (it preserves its data) | |
|
41 | */ | |
|
42 | ||
|
43 | /*! | |
|
44 | \property QVXYModelMapper::model | |
|
45 | \brief Defines the model that is used by the mapper. | |
|
46 | */ | |
|
47 | ||
|
48 | /*! | |
|
37 | 49 | \property QVXYModelMapper::xColumn |
|
38 | 50 | \brief Defines which column of the model is kept in sync with the x values of QXYSeries |
|
39 | 51 | |
|
40 | 52 | Default value is: -1 (invalid mapping) |
|
41 | 53 | */ |
|
42 | 54 | |
|
43 | 55 | /*! |
|
44 | 56 | \property QVXYModelMapper::yColumn |
|
45 | 57 | \brief Defines which column of the model is kept in sync with the y values of QXYSeries |
|
46 | 58 | |
|
47 | 59 | Default value is: -1 (invalid mapping) |
|
48 | 60 | */ |
|
49 | 61 | |
|
50 | 62 | /*! |
|
63 | \property QVXYModelMapper::firstRow | |
|
64 | \brief Defines which row of the model contains the data for the first point of the series. | |
|
65 | Minimal and default value is: 0 | |
|
66 | */ | |
|
67 | /*! | |
|
68 | \qmlproperty int QVXYModelMapper::firstRow | |
|
69 | Defines which row of the model contains the data for the first point of the series. | |
|
70 | The default value is 0. | |
|
71 | */ | |
|
72 | ||
|
73 | /*! | |
|
74 | \property QVXYModelMapper::rowCount | |
|
75 | \brief Defines the number of rows of the model that are mapped as the data for series | |
|
76 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
|
77 | */ | |
|
78 | /*! | |
|
79 | \qmlproperty int QVXYModelMapper::columnCount | |
|
80 | Defines the number of rows of the model that are mapped as the data for series. The default value is | |
|
81 | -1 (count limited by the number of rows in the model) | |
|
82 | */ | |
|
83 | ||
|
84 | /*! | |
|
85 | \fn void QVXYModelMapper::seriesReplaced() | |
|
86 | ||
|
87 | Emitted when the series to which mapper is connected to has changed. | |
|
88 | */ | |
|
89 | ||
|
90 | /*! | |
|
91 | \fn void QVXYModelMapper::modelReplaced() | |
|
92 | ||
|
93 | Emitted when the model to which mapper is connected to has changed. | |
|
94 | */ | |
|
95 | ||
|
96 | /*! | |
|
51 | 97 | \fn void QVXYModelMapper::xColumnChanged() |
|
52 | 98 | |
|
53 | 99 | Emitted when the xColumn has changed. |
|
54 | 100 | */ |
|
55 | 101 | |
|
56 | 102 | /*! |
|
57 | 103 | \fn void QVXYModelMapper::yColumnChanged() |
|
58 | 104 | |
|
59 | 105 | Emitted when the yColumn has changed. |
|
60 | 106 | */ |
|
61 | 107 | |
|
62 | 108 | /*! |
|
109 | \fn void QVXYModelMapper::firstRowChanged() | |
|
110 | Emitted when the firstRow has changed. | |
|
111 | */ | |
|
112 | ||
|
113 | /*! | |
|
114 | \fn void QVXYModelMapper::rowCountChanged() | |
|
115 | Emitted when the rowCount has changed. | |
|
116 | */ | |
|
117 | ||
|
118 | /*! | |
|
63 | 119 | Constructs a mapper object which is a child of \a parent. |
|
64 | 120 | */ |
|
65 | 121 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : |
|
66 | 122 | QXYModelMapper(parent) |
|
67 | 123 | { |
|
68 | 124 | QXYModelMapper::setOrientation(Qt::Vertical); |
|
69 | 125 | } |
|
70 | 126 | |
|
127 | QAbstractItemModel* QVXYModelMapper::model() const | |
|
128 | { | |
|
129 | return QXYModelMapper::model(); | |
|
130 | } | |
|
131 | ||
|
132 | void QVXYModelMapper::setModel(QAbstractItemModel *model) | |
|
133 | { | |
|
134 | if (model != QXYModelMapper::model()) { | |
|
135 | QXYModelMapper::setModel(model); | |
|
136 | emit modelReplaced(); | |
|
137 | } | |
|
138 | } | |
|
139 | ||
|
140 | QXYSeries* QVXYModelMapper::series() const | |
|
141 | { | |
|
142 | return QXYModelMapper::series(); | |
|
143 | } | |
|
144 | ||
|
145 | void QVXYModelMapper::setSeries(QXYSeries *series) | |
|
146 | { | |
|
147 | if (series != QXYModelMapper::series()) { | |
|
148 | QXYModelMapper::setSeries(series); | |
|
149 | emit seriesReplaced(); | |
|
150 | } | |
|
151 | } | |
|
152 | ||
|
71 | 153 | int QVXYModelMapper::xColumn() const |
|
72 | 154 | { |
|
73 | 155 | return QXYModelMapper::xSection(); |
|
74 | 156 | } |
|
75 | 157 | |
|
76 | 158 | void QVXYModelMapper::setXColumn(int xColumn) |
|
77 | 159 | { |
|
78 | 160 | if (xColumn != xSection()) { |
|
79 | 161 | return QXYModelMapper::setXSection(xColumn); |
|
80 | 162 | emit xColumnChanged(); |
|
81 | 163 | } |
|
82 | 164 | } |
|
83 | 165 | |
|
84 | 166 | int QVXYModelMapper::yColumn() const |
|
85 | 167 | { |
|
86 | 168 | return QXYModelMapper::ySection(); |
|
87 | 169 | } |
|
88 | 170 | |
|
89 | 171 | void QVXYModelMapper::setYColumn(int yColumn) |
|
90 | 172 | { |
|
91 | 173 | if (yColumn != ySection()) { |
|
92 | 174 | return QXYModelMapper::setYSection(yColumn); |
|
93 | 175 | emit yColumnChanged(); |
|
94 | 176 | } |
|
95 | 177 | } |
|
96 | 178 | |
|
179 | int QVXYModelMapper::firstRow() const | |
|
180 | { | |
|
181 | return first(); | |
|
182 | } | |
|
183 | ||
|
184 | void QVXYModelMapper::setFirstRow(int firstRow) | |
|
185 | { | |
|
186 | if (firstRow != first()) { | |
|
187 | setFirst(firstRow); | |
|
188 | emit firstRowChanged(); | |
|
189 | } | |
|
190 | } | |
|
191 | ||
|
192 | int QVXYModelMapper::rowCount() const | |
|
193 | { | |
|
194 | return count(); | |
|
195 | } | |
|
196 | ||
|
197 | void QVXYModelMapper::setRowCount(int rowCount) | |
|
198 | { | |
|
199 | if (rowCount != count()) { | |
|
200 | setCount(rowCount); | |
|
201 | emit firstRowChanged(); | |
|
202 | } | |
|
203 | } | |
|
204 | ||
|
97 | 205 | #include "moc_qvxymodelmapper.cpp" |
|
98 | 206 | |
|
99 | 207 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,70 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QVXYMODELMAPPER_H |
|
22 | 22 | #define QVXYMODELMAPPER_H |
|
23 | 23 | |
|
24 | 24 | #include <QXYModelMapper> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper |
|
29 | 29 | { |
|
30 | 30 | Q_OBJECT |
|
31 | Q_PROPERTY(QXYSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
|
32 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
|
31 | 33 | Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn NOTIFY xColumnChanged) |
|
32 | 34 | Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn NOTIFY yColumnChanged) |
|
35 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) | |
|
36 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) | |
|
33 | 37 | |
|
34 | 38 | public: |
|
35 | 39 | explicit QVXYModelMapper(QObject *parent = 0); |
|
40 | ||
|
41 | QAbstractItemModel* model() const; | |
|
42 | void setModel(QAbstractItemModel *model); | |
|
43 | ||
|
44 | QXYSeries* series() const; | |
|
45 | void setSeries(QXYSeries *series); | |
|
36 | 46 | |
|
37 | 47 | int xColumn() const; |
|
38 | 48 | void setXColumn(int xColumn); |
|
39 | 49 | |
|
40 | 50 | int yColumn() const; |
|
41 | 51 | void setYColumn(int yColumn); |
|
42 | 52 | |
|
53 | int firstRow() const; | |
|
54 | void setFirstRow(int firstRow); | |
|
55 | ||
|
56 | int rowCount() const; | |
|
57 | void setRowCount(int rowCount); | |
|
58 | ||
|
43 | 59 | Q_SIGNALS: |
|
60 | void seriesReplaced(); | |
|
61 | void modelReplaced(); | |
|
44 | 62 | void xColumnChanged(); |
|
45 | 63 | void yColumnChanged(); |
|
64 | void firstRowChanged(); | |
|
65 | void rowCountChanged(); | |
|
46 | 66 | }; |
|
47 | 67 | |
|
48 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | 69 | |
|
50 | 70 | #endif // QVXYMODELMAPPER_H |
@@ -1,558 +1,493 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qxymodelmapper.h" |
|
22 | 22 | #include "qxymodelmapper_p.h" |
|
23 | 23 | #include "qxyseries.h" |
|
24 | 24 | #include <QAbstractItemModel> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | \class QXYModelMapper | |
|
30 | \brief part of QtCommercial chart API. | |
|
31 | \mainclass | |
|
32 | ||
|
33 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
|
34 | The instance of this class cannot be created directly. QHXYModelMapper of QVXYModelMapper should be used instead. This class is used to create a connection between QXYSeries and QAbstractItemModel derived model object. | |
|
35 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. | |
|
36 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
|
37 | */ | |
|
38 | ||
|
39 | /*! | |
|
40 | \property QXYModelMapper::series | |
|
41 | \brief Defines the QPieSeries object that is used by the mapper. | |
|
42 | ||
|
43 | All the data in the series is discarded when it is set to the mapper. | |
|
44 | When new series is specified the old series is disconnected (it preserves its data) | |
|
45 | */ | |
|
46 | ||
|
47 | /*! | |
|
48 | \property QXYModelMapper::model | |
|
49 | \brief Defines the model that is used by the mapper. | |
|
50 | */ | |
|
51 | ||
|
52 | /*! | |
|
53 | \property QXYModelMapper::first | |
|
54 | \brief Defines which item of the model's row/column should be mapped as the first x/y pair | |
|
55 | ||
|
56 | Minimal and default value is: 0 | |
|
57 | */ | |
|
58 | ||
|
59 | /*! | |
|
60 | \property QXYModelMapper::count | |
|
61 | \brief Defines the number of rows/columns of the model that are mapped as the data for QXYSeries | |
|
62 | ||
|
63 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
|
64 | */ | |
|
65 | ||
|
66 | /*! | |
|
67 | \fn void QXYModelMapper::seriesReplaced() | |
|
68 | ||
|
69 | Emitted when the series to which mapper is connected to has changed. | |
|
70 | */ | |
|
71 | ||
|
72 | /*! | |
|
73 | \fn void QXYModelMapper::modelReplaced() | |
|
74 | ||
|
75 | Emitted when the model to which mapper is connected to has changed. | |
|
76 | */ | |
|
77 | ||
|
78 | /*! | |
|
79 | \fn void QXYModelMapper::firstChanged() | |
|
80 | ||
|
81 | Emitted when the value for the first has changed. | |
|
82 | */ | |
|
83 | ||
|
84 | /*! | |
|
85 | \fn void QXYModelMapper::countChanged() | |
|
86 | ||
|
87 | Emitted when the value for the count has changed. | |
|
88 | */ | |
|
89 | ||
|
90 | /*! | |
|
91 | 29 | Constructs a mapper object which is a child of \a parent. |
|
92 | 30 | */ |
|
93 | 31 | QXYModelMapper::QXYModelMapper(QObject *parent): |
|
94 | 32 | QObject(parent), |
|
95 | 33 | d_ptr(new QXYModelMapperPrivate(this)) |
|
96 | 34 | { |
|
97 | 35 | } |
|
98 | 36 | |
|
37 | /*! | |
|
38 | \internal | |
|
39 | */ | |
|
99 | 40 | QAbstractItemModel* QXYModelMapper::model() const |
|
100 | 41 | { |
|
101 | 42 | Q_D(const QXYModelMapper); |
|
102 | 43 | return d->m_model; |
|
103 | 44 | } |
|
104 | 45 | |
|
46 | /*! | |
|
47 | \internal | |
|
48 | */ | |
|
105 | 49 | void QXYModelMapper::setModel(QAbstractItemModel *model) |
|
106 | 50 | { |
|
107 | 51 | if (model == 0) |
|
108 | 52 | return; |
|
109 | 53 | |
|
110 | 54 | Q_D(QXYModelMapper); |
|
111 | 55 | if (d->m_model) { |
|
112 | 56 | disconnect(d->m_model, 0, d, 0); |
|
113 | 57 | } |
|
114 | 58 | |
|
115 | 59 | d->m_model = model; |
|
116 | 60 | d->initializeXYFromModel(); |
|
117 | 61 | // connect signals from the model |
|
118 | 62 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
119 | 63 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
120 | 64 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
121 | 65 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
122 | 66 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
123 | ||
|
124 | emit modelReplaced(); | |
|
125 | 67 | } |
|
126 | 68 | |
|
69 | /*! | |
|
70 | \internal | |
|
71 | */ | |
|
127 | 72 | QXYSeries* QXYModelMapper::series() const |
|
128 | 73 | { |
|
129 | 74 | Q_D(const QXYModelMapper); |
|
130 | 75 | return d->m_series; |
|
131 | 76 | } |
|
132 | 77 | |
|
78 | /*! | |
|
79 | \internal | |
|
80 | */ | |
|
133 | 81 | void QXYModelMapper::setSeries(QXYSeries *series) |
|
134 | 82 | { |
|
135 | 83 | Q_D(QXYModelMapper); |
|
136 | 84 | if (d->m_series) { |
|
137 | 85 | disconnect(d->m_series, 0, d, 0); |
|
138 | 86 | } |
|
139 | 87 | |
|
140 | 88 | if (series == 0) |
|
141 | 89 | return; |
|
142 | 90 | |
|
143 | 91 | d->m_series = series; |
|
144 | 92 | d->initializeXYFromModel(); |
|
145 | 93 | // connect the signals from the series |
|
146 | 94 | connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); |
|
147 | 95 | connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); |
|
148 | 96 | connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); |
|
149 | ||
|
150 | emit seriesReplaced(); | |
|
151 | 97 | } |
|
152 | 98 | |
|
99 | /*! | |
|
100 | \internal | |
|
101 | */ | |
|
153 | 102 | int QXYModelMapper::first() const |
|
154 | 103 | { |
|
155 | 104 | Q_D(const QXYModelMapper); |
|
156 | 105 | return d->m_first; |
|
157 | 106 | } |
|
158 | 107 | |
|
108 | /*! | |
|
109 | \internal | |
|
110 | */ | |
|
159 | 111 | void QXYModelMapper::setFirst(int first) |
|
160 | 112 | { |
|
161 | 113 | Q_D(QXYModelMapper); |
|
162 | if (first != d->m_first) { | |
|
163 | d->m_first = qMax(first, 0); | |
|
164 | d->initializeXYFromModel(); | |
|
165 | ||
|
166 | emit firstChanged(); | |
|
167 | } | |
|
114 | d->m_first = qMax(first, 0); | |
|
115 | d->initializeXYFromModel(); | |
|
168 | 116 | } |
|
169 | 117 | |
|
118 | /*! | |
|
119 | \internal | |
|
120 | */ | |
|
170 | 121 | int QXYModelMapper::count() const |
|
171 | 122 | { |
|
172 | 123 | Q_D(const QXYModelMapper); |
|
173 | 124 | return d->m_count; |
|
174 | 125 | } |
|
175 | 126 | |
|
127 | /*! | |
|
128 | \internal | |
|
129 | */ | |
|
176 | 130 | void QXYModelMapper::setCount(int count) |
|
177 | 131 | { |
|
178 | 132 | Q_D(QXYModelMapper); |
|
179 | if (count != d->m_count) { | |
|
180 | d->m_count = qMax(count, -1); | |
|
181 | d->initializeXYFromModel(); | |
|
182 | ||
|
183 | emit countChanged(); | |
|
184 | } | |
|
133 | d->m_count = qMax(count, -1); | |
|
134 | d->initializeXYFromModel(); | |
|
185 | 135 | } |
|
186 | 136 | |
|
187 | 137 | /*! |
|
188 | 138 | Returns the orientation that is used when QXYModelMapper accesses the model. |
|
189 | 139 | This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal) |
|
190 | 140 | or from columns (Qt::Vertical) |
|
191 | 141 | */ |
|
192 | 142 | Qt::Orientation QXYModelMapper::orientation() const |
|
193 | 143 | { |
|
194 | 144 | Q_D(const QXYModelMapper); |
|
195 | 145 | return d->m_orientation; |
|
196 | 146 | } |
|
197 | 147 | |
|
198 | 148 | /*! |
|
199 | 149 | Returns the \a orientation that is used when QXYModelMapper accesses the model. |
|
200 | 150 | This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal) |
|
201 | 151 | or from columns (Qt::Vertical) |
|
202 | 152 | */ |
|
203 | 153 | void QXYModelMapper::setOrientation(Qt::Orientation orientation) |
|
204 | 154 | { |
|
205 | 155 | Q_D(QXYModelMapper); |
|
206 | 156 | d->m_orientation = orientation; |
|
207 | 157 | d->initializeXYFromModel(); |
|
208 | 158 | } |
|
209 | 159 | |
|
210 | 160 | /*! |
|
211 | 161 | Returns which section of the model is kept in sync with the x values of the QXYSeries |
|
212 | 162 | */ |
|
213 | 163 | int QXYModelMapper::xSection() const |
|
214 | 164 | { |
|
215 | 165 | Q_D(const QXYModelMapper); |
|
216 | 166 | return d->m_xSection; |
|
217 | 167 | } |
|
218 | 168 | |
|
219 | 169 | /*! |
|
220 | 170 | Sets the model section that is kept in sync with the x values of the QXYSeries. |
|
221 | 171 | Parameter \a xSection specifies the section of the model. |
|
222 | 172 | */ |
|
223 | 173 | void QXYModelMapper::setXSection(int xSection) |
|
224 | 174 | { |
|
225 | 175 | Q_D(QXYModelMapper); |
|
226 | 176 | d->m_xSection = qMax(-1, xSection); |
|
227 | 177 | d->initializeXYFromModel(); |
|
228 | 178 | } |
|
229 | 179 | |
|
230 | 180 | /*! |
|
231 | 181 | Returns which section of the model is kept in sync with the y values of the QXYSeries |
|
232 | 182 | */ |
|
233 | 183 | int QXYModelMapper::ySection() const |
|
234 | 184 | { |
|
235 | 185 | Q_D(const QXYModelMapper); |
|
236 | 186 | return d->m_ySection; |
|
237 | 187 | } |
|
238 | 188 | |
|
239 | 189 | /*! |
|
240 | 190 | Sets the model section that is kept in sync with the y values of the QXYSeries. |
|
241 | 191 | Parameter \a ySection specifies the section of the model. |
|
242 | 192 | */ |
|
243 | 193 | void QXYModelMapper::setYSection(int ySection) |
|
244 | 194 | { |
|
245 | 195 | Q_D(QXYModelMapper); |
|
246 | 196 | d->m_ySection = qMax(-1, ySection); |
|
247 | 197 | d->initializeXYFromModel(); |
|
248 | 198 | } |
|
249 | 199 | |
|
250 | /*! | |
|
251 | Resets the QXYModelMapper to the default state. | |
|
252 | first: 0; count: -1; xSection: -1; ySection: -1; | |
|
253 | */ | |
|
254 | void QXYModelMapper::reset() | |
|
255 | { | |
|
256 | Q_D(QXYModelMapper); | |
|
257 | d->m_first = 0; | |
|
258 | d->m_count = -1; | |
|
259 | d->m_orientation = Qt::Vertical; | |
|
260 | d->m_xSection = -1; | |
|
261 | d->m_ySection = -1; | |
|
262 | d->initializeXYFromModel(); | |
|
263 | } | |
|
264 | ||
|
265 | 200 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
266 | 201 | |
|
267 | 202 | QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : |
|
268 | 203 | m_series(0), |
|
269 | 204 | m_model(0), |
|
270 | 205 | m_first(0), |
|
271 | 206 | m_count(-1), |
|
272 | 207 | m_orientation(Qt::Vertical), |
|
273 | 208 | m_xSection(-1), |
|
274 | 209 | m_ySection(-1), |
|
275 | 210 | m_seriesSignalsBlock(false), |
|
276 | 211 | m_modelSignalsBlock(false), |
|
277 | 212 | q_ptr(q) |
|
278 | 213 | { |
|
279 | 214 | } |
|
280 | 215 | |
|
281 | 216 | void QXYModelMapperPrivate::blockModelSignals(bool block) |
|
282 | 217 | { |
|
283 | 218 | m_modelSignalsBlock = block; |
|
284 | 219 | } |
|
285 | 220 | |
|
286 | 221 | void QXYModelMapperPrivate::blockSeriesSignals(bool block) |
|
287 | 222 | { |
|
288 | 223 | m_seriesSignalsBlock = block; |
|
289 | 224 | } |
|
290 | 225 | |
|
291 | 226 | QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos) |
|
292 | 227 | { |
|
293 | 228 | if (m_count != -1 && xPos >= m_count) |
|
294 | 229 | return QModelIndex(); // invalid |
|
295 | 230 | |
|
296 | 231 | if (m_orientation == Qt::Vertical) |
|
297 | 232 | return m_model->index(xPos + m_first, m_xSection); |
|
298 | 233 | else |
|
299 | 234 | return m_model->index(m_xSection, xPos + m_first); |
|
300 | 235 | } |
|
301 | 236 | |
|
302 | 237 | QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos) |
|
303 | 238 | { |
|
304 | 239 | if (m_count != -1 && yPos >= m_count) |
|
305 | 240 | return QModelIndex(); // invalid |
|
306 | 241 | |
|
307 | 242 | if (m_orientation == Qt::Vertical) |
|
308 | 243 | return m_model->index(yPos + m_first, m_ySection); |
|
309 | 244 | else |
|
310 | 245 | return m_model->index(m_ySection, yPos + m_first); |
|
311 | 246 | } |
|
312 | 247 | |
|
313 | 248 | void QXYModelMapperPrivate::handlePointAdded(int pointPos) |
|
314 | 249 | { |
|
315 | 250 | if (m_seriesSignalsBlock) |
|
316 | 251 | return; |
|
317 | 252 | |
|
318 | 253 | if (m_count != -1) |
|
319 | 254 | m_count += 1; |
|
320 | 255 | |
|
321 | 256 | blockModelSignals(); |
|
322 | 257 | if (m_orientation == Qt::Vertical) |
|
323 | 258 | m_model->insertRows(pointPos + m_first, 1); |
|
324 | 259 | else |
|
325 | 260 | m_model->insertColumns(pointPos + m_first, 1); |
|
326 | 261 | |
|
327 | 262 | m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); |
|
328 | 263 | m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); |
|
329 | 264 | blockModelSignals(false); |
|
330 | 265 | } |
|
331 | 266 | |
|
332 | 267 | void QXYModelMapperPrivate::handlePointRemoved(int pointPos) |
|
333 | 268 | { |
|
334 | 269 | if (m_seriesSignalsBlock) |
|
335 | 270 | return; |
|
336 | 271 | |
|
337 | 272 | if (m_count != -1) |
|
338 | 273 | m_count -= 1; |
|
339 | 274 | |
|
340 | 275 | blockModelSignals(); |
|
341 | 276 | if (m_orientation == Qt::Vertical) |
|
342 | 277 | m_model->removeRow(pointPos + m_first); |
|
343 | 278 | else |
|
344 | 279 | m_model->removeColumn(pointPos + m_first); |
|
345 | 280 | blockModelSignals(false); |
|
346 | 281 | } |
|
347 | 282 | |
|
348 | 283 | void QXYModelMapperPrivate::handlePointReplaced(int pointPos) |
|
349 | 284 | { |
|
350 | 285 | if (m_seriesSignalsBlock) |
|
351 | 286 | return; |
|
352 | 287 | |
|
353 | 288 | blockModelSignals(); |
|
354 | 289 | m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); |
|
355 | 290 | m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); |
|
356 | 291 | blockModelSignals(false); |
|
357 | 292 | } |
|
358 | 293 | |
|
359 | 294 | void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
360 | 295 | { |
|
361 | 296 | if (m_model == 0 || m_series == 0) |
|
362 | 297 | return; |
|
363 | 298 | |
|
364 | 299 | if (m_modelSignalsBlock) |
|
365 | 300 | return; |
|
366 | 301 | |
|
367 | 302 | blockSeriesSignals(); |
|
368 | 303 | QModelIndex index; |
|
369 | 304 | QPointF oldPoint; |
|
370 | 305 | QPointF newPoint; |
|
371 | 306 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
372 | 307 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
373 | 308 | index = topLeft.sibling(row, column); |
|
374 | 309 | if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) { |
|
375 | 310 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
376 | 311 | QModelIndex xIndex = xModelIndex(index.row() - m_first); |
|
377 | 312 | QModelIndex yIndex = yModelIndex(index.row() - m_first); |
|
378 | 313 | if (xIndex.isValid() && yIndex.isValid()) { |
|
379 | 314 | oldPoint = m_series->points().at(index.row() - m_first); |
|
380 | 315 | newPoint.setX(m_model->data(xIndex).toReal()); |
|
381 | 316 | newPoint.setY(m_model->data(yIndex).toReal()); |
|
382 | 317 | } |
|
383 | 318 | } |
|
384 | 319 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) { |
|
385 | 320 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { |
|
386 | 321 | QModelIndex xIndex = xModelIndex(index.column() - m_first); |
|
387 | 322 | QModelIndex yIndex = yModelIndex(index.column() - m_first); |
|
388 | 323 | if (xIndex.isValid() && yIndex.isValid()) { |
|
389 | 324 | oldPoint = m_series->points().at(index.column() - m_first); |
|
390 | 325 | newPoint.setX(m_model->data(xIndex).toReal()); |
|
391 | 326 | newPoint.setY(m_model->data(yIndex).toReal()); |
|
392 | 327 | } |
|
393 | 328 | } |
|
394 | 329 | } else { |
|
395 | 330 | continue; |
|
396 | 331 | } |
|
397 | 332 | m_series->replace(oldPoint, newPoint); |
|
398 | 333 | } |
|
399 | 334 | } |
|
400 | 335 | blockSeriesSignals(false); |
|
401 | 336 | } |
|
402 | 337 | |
|
403 | 338 | void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
404 | 339 | { |
|
405 | 340 | Q_UNUSED(parent); |
|
406 | 341 | if (m_modelSignalsBlock) |
|
407 | 342 | return; |
|
408 | 343 | |
|
409 | 344 | blockSeriesSignals(); |
|
410 | 345 | if (m_orientation == Qt::Vertical) |
|
411 | 346 | insertData(start, end); |
|
412 | 347 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
413 | 348 | initializeXYFromModel(); |
|
414 | 349 | blockSeriesSignals(false); |
|
415 | 350 | } |
|
416 | 351 | |
|
417 | 352 | void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
418 | 353 | { |
|
419 | 354 | Q_UNUSED(parent); |
|
420 | 355 | if (m_modelSignalsBlock) |
|
421 | 356 | return; |
|
422 | 357 | |
|
423 | 358 | blockSeriesSignals(); |
|
424 | 359 | if (m_orientation == Qt::Vertical) |
|
425 | 360 | removeData(start, end); |
|
426 | 361 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
427 | 362 | initializeXYFromModel(); |
|
428 | 363 | blockSeriesSignals(false); |
|
429 | 364 | } |
|
430 | 365 | |
|
431 | 366 | void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
432 | 367 | { |
|
433 | 368 | Q_UNUSED(parent); |
|
434 | 369 | if (m_modelSignalsBlock) |
|
435 | 370 | return; |
|
436 | 371 | |
|
437 | 372 | blockSeriesSignals(); |
|
438 | 373 | if (m_orientation == Qt::Horizontal) |
|
439 | 374 | insertData(start, end); |
|
440 | 375 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
441 | 376 | initializeXYFromModel(); |
|
442 | 377 | blockSeriesSignals(false); |
|
443 | 378 | } |
|
444 | 379 | |
|
445 | 380 | void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
446 | 381 | { |
|
447 | 382 | Q_UNUSED(parent); |
|
448 | 383 | if (m_modelSignalsBlock) |
|
449 | 384 | return; |
|
450 | 385 | |
|
451 | 386 | blockSeriesSignals(); |
|
452 | 387 | if (m_orientation == Qt::Horizontal) |
|
453 | 388 | removeData(start, end); |
|
454 | 389 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
455 | 390 | initializeXYFromModel(); |
|
456 | 391 | blockSeriesSignals(false); |
|
457 | 392 | } |
|
458 | 393 | |
|
459 | 394 | void QXYModelMapperPrivate::insertData(int start, int end) |
|
460 | 395 | { |
|
461 | 396 | if (m_model == 0 || m_series == 0) |
|
462 | 397 | return; |
|
463 | 398 | |
|
464 | 399 | if (m_count != -1 && start >= m_first + m_count) { |
|
465 | 400 | return; |
|
466 | 401 | } else { |
|
467 | 402 | int addedCount = end - start + 1; |
|
468 | 403 | if (m_count != -1 && addedCount > m_count) |
|
469 | 404 | addedCount = m_count; |
|
470 | 405 | int first = qMax(start, m_first); |
|
471 | 406 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
472 | 407 | for (int i = first; i <= last; i++) { |
|
473 | 408 | QPointF point; |
|
474 | 409 | QModelIndex xIndex = xModelIndex(i - m_first); |
|
475 | 410 | QModelIndex yIndex = yModelIndex(i - m_first); |
|
476 | 411 | if (xIndex.isValid() && yIndex.isValid()) { |
|
477 | 412 | point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble()); |
|
478 | 413 | point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble()); |
|
479 | 414 | m_series->insert(i - m_first, point); |
|
480 | 415 | } |
|
481 | 416 | } |
|
482 | 417 | |
|
483 | 418 | // remove excess of slices (abouve m_count) |
|
484 | 419 | if (m_count != -1 && m_series->points().size() > m_count) |
|
485 | 420 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { |
|
486 | 421 | m_series->remove(m_series->points().at(i)); |
|
487 | 422 | } |
|
488 | 423 | } |
|
489 | 424 | } |
|
490 | 425 | |
|
491 | 426 | void QXYModelMapperPrivate::removeData(int start, int end) |
|
492 | 427 | { |
|
493 | 428 | if (m_model == 0 || m_series == 0) |
|
494 | 429 | return; |
|
495 | 430 | |
|
496 | 431 | int removedCount = end - start + 1; |
|
497 | 432 | if (m_count != -1 && start >= m_first + m_count) { |
|
498 | 433 | return; |
|
499 | 434 | } else { |
|
500 | 435 | int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed |
|
501 | 436 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
502 | 437 | int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed. |
|
503 | 438 | for (int i = last; i >= first; i--) { |
|
504 | 439 | m_series->remove(m_series->points().at(i - m_first)); |
|
505 | 440 | } |
|
506 | 441 | |
|
507 | 442 | if (m_count != -1) { |
|
508 | 443 | int itemsAvailable; // check how many are available to be added |
|
509 | 444 | if (m_orientation == Qt::Vertical) |
|
510 | 445 | itemsAvailable = m_model->rowCount() - m_first - m_series->count(); |
|
511 | 446 | else |
|
512 | 447 | itemsAvailable = m_model->columnCount() - m_first - m_series->count(); |
|
513 | 448 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled. |
|
514 | 449 | int currentSize = m_series->count(); |
|
515 | 450 | if (toBeAdded > 0) |
|
516 | 451 | for (int i = m_series->count(); i < currentSize + toBeAdded; i++) { |
|
517 | 452 | QPointF point; |
|
518 | 453 | QModelIndex xIndex = xModelIndex(i); |
|
519 | 454 | QModelIndex yIndex = yModelIndex(i); |
|
520 | 455 | if (xIndex.isValid() && yIndex.isValid()) { |
|
521 | 456 | point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble()); |
|
522 | 457 | point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble()); |
|
523 | 458 | m_series->insert(i, point); |
|
524 | 459 | } |
|
525 | 460 | } |
|
526 | 461 | } |
|
527 | 462 | } |
|
528 | 463 | } |
|
529 | 464 | |
|
530 | 465 | void QXYModelMapperPrivate::initializeXYFromModel() |
|
531 | 466 | { |
|
532 | 467 | if (m_model == 0 || m_series == 0) |
|
533 | 468 | return; |
|
534 | 469 | |
|
535 | 470 | blockSeriesSignals(); |
|
536 | 471 | // clear current content |
|
537 | 472 | m_series->clear(); |
|
538 | 473 | |
|
539 | 474 | // create the initial slices set |
|
540 | 475 | int pointPos = 0; |
|
541 | 476 | QModelIndex xIndex = xModelIndex(pointPos); |
|
542 | 477 | QModelIndex yIndex = yModelIndex(pointPos); |
|
543 | 478 | while (xIndex.isValid() && yIndex.isValid()) { |
|
544 | 479 | QPointF point; |
|
545 | 480 | point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble()); |
|
546 | 481 | point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble()); |
|
547 | 482 | m_series->append(point); |
|
548 | 483 | pointPos++; |
|
549 | 484 | xIndex = xModelIndex(pointPos); |
|
550 | 485 | yIndex = yModelIndex(pointPos); |
|
551 | 486 | } |
|
552 | 487 | blockSeriesSignals(false); |
|
553 | 488 | } |
|
554 | 489 | |
|
555 | 490 | #include "moc_qxymodelmapper.cpp" |
|
556 | 491 | #include "moc_qxymodelmapper_p.cpp" |
|
557 | 492 | |
|
558 | 493 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,69 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QXYMODELMAPPER_H |
|
22 | 22 | #define QXYMODELMAPPER_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QObject> |
|
26 | 26 | |
|
27 | 27 | class QAbstractItemModel; |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QXYModelMapperPrivate; |
|
32 | 32 | class QXYSeries; |
|
33 | 33 | |
|
34 | 34 | class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | Q_PROPERTY(QXYSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
|
38 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
|
39 | Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged) | |
|
40 | Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) | |
|
41 | Q_ENUMS(Qt::Orientation) | |
|
42 | 37 | |
|
43 | 38 | protected: |
|
44 | 39 | explicit QXYModelMapper(QObject *parent = 0); |
|
45 | 40 | |
|
46 | public: | |
|
47 | 41 | QAbstractItemModel* model() const; |
|
48 | 42 | void setModel(QAbstractItemModel *model); |
|
49 | 43 | |
|
50 | 44 | QXYSeries* series() const; |
|
51 | 45 | void setSeries(QXYSeries *series); |
|
52 | 46 | |
|
53 | 47 | int first() const; |
|
54 | 48 | void setFirst(int first); |
|
55 | 49 | |
|
56 | 50 | int count() const; |
|
57 | 51 | void setCount(int count); |
|
58 | 52 | |
|
59 | void reset(); | |
|
60 | ||
|
61 | protected: | |
|
62 | 53 | Qt::Orientation orientation() const; |
|
63 | 54 | void setOrientation(Qt::Orientation orientation); |
|
64 | 55 | |
|
65 | 56 | int xSection() const; |
|
66 | 57 | void setXSection(int xSection); |
|
67 | 58 | |
|
68 | 59 | int ySection() const; |
|
69 | 60 | void setYSection(int ySection); |
|
70 | 61 | |
|
71 | Q_SIGNALS: | |
|
72 | void seriesReplaced(); | |
|
73 | void modelReplaced(); | |
|
74 | void firstChanged(); | |
|
75 | void countChanged(); | |
|
76 | ||
|
77 | 62 | protected: |
|
78 | 63 | QXYModelMapperPrivate * const d_ptr; |
|
79 | 64 | Q_DECLARE_PRIVATE(QXYModelMapper) |
|
80 | 65 | }; |
|
81 | 66 | |
|
82 | 67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | 68 | |
|
84 | 69 | #endif // QXYMODELMAPPER_H |
@@ -1,529 +1,529 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtCore/QString> |
|
22 | 22 | #include <QtTest/QtTest> |
|
23 | 23 | |
|
24 | 24 | #include <qchart.h> |
|
25 | 25 | #include <qchartview.h> |
|
26 | 26 | #include <qxyseries.h> |
|
27 | 27 | #include <qlineseries.h> |
|
28 | 28 | #include <qvxymodelmapper.h> |
|
29 | 29 | #include <qhxymodelmapper.h> |
|
30 | 30 | #include <QStandardItemModel> |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | class tst_qxymodelmapper : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | |
|
38 | 38 | public: |
|
39 | 39 | tst_qxymodelmapper(); |
|
40 | 40 | void createVerticalMapper(); |
|
41 | 41 | void createHorizontalMapper(); |
|
42 | 42 | |
|
43 | 43 | private Q_SLOTS: |
|
44 | 44 | void initTestCase(); |
|
45 | 45 | void cleanupTestCase(); |
|
46 | 46 | void init(); |
|
47 | 47 | void cleanup(); |
|
48 | 48 | void verticalMapper_data(); |
|
49 | 49 | void verticalMapper(); |
|
50 | 50 | void verticalMapperCustomMapping_data(); |
|
51 | 51 | void verticalMapperCustomMapping(); |
|
52 | 52 | void horizontalMapper_data(); |
|
53 | 53 | void horizontalMapper(); |
|
54 | 54 | void horizontalMapperCustomMapping_data(); |
|
55 | 55 | void horizontalMapperCustomMapping(); |
|
56 | 56 | void seriesUpdated(); |
|
57 | 57 | void verticalModelInsertRows(); |
|
58 | 58 | void verticalModelRemoveRows(); |
|
59 | 59 | void verticalModelInsertColumns(); |
|
60 | 60 | void verticalModelRemoveColumns(); |
|
61 | 61 | void horizontalModelInsertRows(); |
|
62 | 62 | void horizontalModelRemoveRows(); |
|
63 | 63 | void horizontalModelInsertColumns(); |
|
64 | 64 | void horizontalModelRemoveColumns(); |
|
65 | 65 | void modelUpdateCell(); |
|
66 | 66 | |
|
67 | 67 | private: |
|
68 | 68 | QStandardItemModel *m_model; |
|
69 | 69 | int m_modelRowCount; |
|
70 | 70 | int m_modelColumnCount; |
|
71 | 71 | |
|
72 | 72 | QHXYModelMapper *m_hMapper; |
|
73 | 73 | QVXYModelMapper *m_vMapper; |
|
74 | 74 | |
|
75 | 75 | QXYSeries *m_series; |
|
76 | 76 | QChart *m_chart; |
|
77 | 77 | }; |
|
78 | 78 | |
|
79 | 79 | tst_qxymodelmapper::tst_qxymodelmapper(): |
|
80 | 80 | m_model(0), |
|
81 | 81 | m_modelRowCount(10), |
|
82 | 82 | m_modelColumnCount(8), |
|
83 | 83 | m_hMapper(0), |
|
84 | 84 | m_vMapper(0), |
|
85 | 85 | m_series(0), |
|
86 | 86 | m_chart(0) |
|
87 | 87 | { |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void tst_qxymodelmapper::createVerticalMapper() |
|
91 | 91 | { |
|
92 | 92 | m_vMapper = new QVXYModelMapper; |
|
93 | 93 | QVERIFY(m_vMapper->model() == 0); |
|
94 | 94 | m_vMapper->setXColumn(0); |
|
95 | 95 | m_vMapper->setYColumn(1); |
|
96 | 96 | m_vMapper->setModel(m_model); |
|
97 | 97 | m_vMapper->setSeries(m_series); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | void tst_qxymodelmapper::createHorizontalMapper() |
|
101 | 101 | { |
|
102 | 102 | m_hMapper = new QHXYModelMapper; |
|
103 | 103 | QVERIFY(m_hMapper->model() == 0); |
|
104 | 104 | m_hMapper->setXRow(0); |
|
105 | 105 | m_hMapper->setYRow(1); |
|
106 | 106 | m_hMapper->setModel(m_model); |
|
107 | 107 | m_hMapper->setSeries(m_series); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void tst_qxymodelmapper::init() |
|
111 | 111 | { |
|
112 | 112 | m_series = new QLineSeries; |
|
113 | 113 | m_chart->addSeries(m_series); |
|
114 | 114 | |
|
115 | 115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
116 | 116 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
117 | 117 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
118 | 118 | m_model->setData(m_model->index(row, column), row * column); |
|
119 | 119 | } |
|
120 | 120 | } |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void tst_qxymodelmapper::cleanup() |
|
124 | 124 | { |
|
125 | 125 | m_chart->removeSeries(m_series); |
|
126 | 126 | m_series->deleteLater(); |
|
127 | 127 | m_series = 0; |
|
128 | 128 | |
|
129 | 129 | m_model->clear(); |
|
130 | 130 | m_model->deleteLater(); |
|
131 | 131 | m_model = 0; |
|
132 | 132 | |
|
133 | 133 | if (m_vMapper) { |
|
134 | 134 | m_vMapper->deleteLater(); |
|
135 | 135 | m_vMapper = 0; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | if (m_hMapper) { |
|
139 | 139 | m_hMapper->deleteLater(); |
|
140 | 140 | m_hMapper = 0; |
|
141 | 141 | } |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | void tst_qxymodelmapper::initTestCase() |
|
145 | 145 | { |
|
146 | 146 | m_chart = new QChart; |
|
147 | 147 | QChartView *chartView = new QChartView(m_chart); |
|
148 | 148 | chartView->show(); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void tst_qxymodelmapper::cleanupTestCase() |
|
152 | 152 | { |
|
153 | 153 | // |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void tst_qxymodelmapper::verticalMapper_data() |
|
157 | 157 | { |
|
158 | 158 | QTest::addColumn<int>("xColumn"); |
|
159 | 159 | QTest::addColumn<int>("yColumn"); |
|
160 | 160 | QTest::addColumn<int>("expectedCount"); |
|
161 | 161 | QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount; |
|
162 | 162 | QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount; |
|
163 | 163 | QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0; |
|
164 | 164 | QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0; |
|
165 | 165 | QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0; |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void tst_qxymodelmapper::verticalMapper() |
|
169 | 169 | { |
|
170 | 170 | QFETCH(int, xColumn); |
|
171 | 171 | QFETCH(int, yColumn); |
|
172 | 172 | QFETCH(int, expectedCount); |
|
173 | 173 | |
|
174 | 174 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
175 | 175 | QVERIFY(mapper->model() == 0); |
|
176 | 176 | |
|
177 | 177 | mapper->setXColumn(xColumn); |
|
178 | 178 | mapper->setYColumn(yColumn); |
|
179 | 179 | mapper->setModel(m_model); |
|
180 | 180 | mapper->setSeries(m_series); |
|
181 | 181 | |
|
182 | 182 | QCOMPARE(m_series->count(), expectedCount); |
|
183 | 183 | QCOMPARE(mapper->xColumn(), qMax(-1, xColumn)); |
|
184 | 184 | QCOMPARE(mapper->yColumn(), qMax(-1, yColumn)); |
|
185 | 185 | |
|
186 | 186 | delete mapper; |
|
187 | 187 | mapper = 0; |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | void tst_qxymodelmapper::verticalMapperCustomMapping_data() |
|
191 | 191 | { |
|
192 | 192 | QTest::addColumn<int>("first"); |
|
193 | 193 | QTest::addColumn<int>("countLimit"); |
|
194 | 194 | QTest::addColumn<int>("expectedCount"); |
|
195 | 195 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; |
|
196 | 196 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; |
|
197 | 197 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); |
|
198 | 198 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); |
|
199 | 199 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; |
|
200 | 200 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; |
|
201 | 201 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; |
|
202 | 202 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; |
|
203 | 203 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; |
|
204 | 204 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; |
|
205 | 205 | |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void tst_qxymodelmapper::verticalMapperCustomMapping() |
|
209 | 209 | { |
|
210 | 210 | QFETCH(int, first); |
|
211 | 211 | QFETCH(int, countLimit); |
|
212 | 212 | QFETCH(int, expectedCount); |
|
213 | 213 | |
|
214 | 214 | QCOMPARE(m_series->count(), 0); |
|
215 | 215 | |
|
216 | 216 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
217 | 217 | mapper->setXColumn(0); |
|
218 | 218 | mapper->setYColumn(1); |
|
219 | 219 | mapper->setModel(m_model); |
|
220 | 220 | mapper->setSeries(m_series); |
|
221 | mapper->setFirst(first); | |
|
222 | mapper->setCount(countLimit); | |
|
221 | mapper->setFirstRow(first); | |
|
222 | mapper->setRowCount(countLimit); | |
|
223 | 223 | |
|
224 | 224 | QCOMPARE(m_series->count(), expectedCount); |
|
225 | 225 | |
|
226 | 226 | // change values column mapping to invalid |
|
227 | 227 | mapper->setXColumn(-1); |
|
228 | 228 | mapper->setYColumn(1); |
|
229 | 229 | |
|
230 | 230 | QCOMPARE(m_series->count(), 0); |
|
231 | 231 | |
|
232 | 232 | delete mapper; |
|
233 | 233 | mapper = 0; |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void tst_qxymodelmapper::horizontalMapper_data() |
|
237 | 237 | { |
|
238 | 238 | QTest::addColumn<int>("xRow"); |
|
239 | 239 | QTest::addColumn<int>("yRow"); |
|
240 | 240 | QTest::addColumn<int>("expectedCount"); |
|
241 | 241 | QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount; |
|
242 | 242 | QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount; |
|
243 | 243 | QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0; |
|
244 | 244 | QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0; |
|
245 | 245 | QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0; |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | void tst_qxymodelmapper::horizontalMapper() |
|
249 | 249 | { |
|
250 | 250 | QFETCH(int, xRow); |
|
251 | 251 | QFETCH(int, yRow); |
|
252 | 252 | QFETCH(int, expectedCount); |
|
253 | 253 | |
|
254 | 254 | QHXYModelMapper *mapper = new QHXYModelMapper; |
|
255 | 255 | mapper->setXRow(xRow); |
|
256 | 256 | mapper->setYRow(yRow); |
|
257 | 257 | mapper->setModel(m_model); |
|
258 | 258 | mapper->setSeries(m_series); |
|
259 | 259 | |
|
260 | 260 | QCOMPARE(m_series->count(), expectedCount); |
|
261 | 261 | QCOMPARE(mapper->xRow(), qMax(-1, xRow)); |
|
262 | 262 | QCOMPARE(mapper->yRow(), qMax(-1, yRow)); |
|
263 | 263 | |
|
264 | 264 | delete mapper; |
|
265 | 265 | mapper = 0; |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | void tst_qxymodelmapper::horizontalMapperCustomMapping_data() |
|
269 | 269 | { |
|
270 | 270 | QTest::addColumn<int>("first"); |
|
271 | 271 | QTest::addColumn<int>("countLimit"); |
|
272 | 272 | QTest::addColumn<int>("expectedCount"); |
|
273 | 273 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; |
|
274 | 274 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; |
|
275 | 275 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); |
|
276 | 276 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); |
|
277 | 277 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; |
|
278 | 278 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; |
|
279 | 279 | QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; |
|
280 | 280 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; |
|
281 | 281 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; |
|
282 | 282 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | void tst_qxymodelmapper::horizontalMapperCustomMapping() |
|
286 | 286 | { |
|
287 | 287 | QFETCH(int, first); |
|
288 | 288 | QFETCH(int, countLimit); |
|
289 | 289 | QFETCH(int, expectedCount); |
|
290 | 290 | |
|
291 | 291 | QCOMPARE(m_series->count(), 0); |
|
292 | 292 | |
|
293 | 293 | QHXYModelMapper *mapper = new QHXYModelMapper; |
|
294 | 294 | mapper->setXRow(0); |
|
295 | 295 | mapper->setYRow(1); |
|
296 | 296 | mapper->setModel(m_model); |
|
297 | 297 | mapper->setSeries(m_series); |
|
298 | mapper->setFirst(first); | |
|
299 | mapper->setCount(countLimit); | |
|
298 | mapper->setFirstColumn(first); | |
|
299 | mapper->setColumnCount(countLimit); | |
|
300 | 300 | |
|
301 | 301 | QCOMPARE(m_series->count(), expectedCount); |
|
302 | 302 | |
|
303 | 303 | // change values row mapping to invalid |
|
304 | 304 | mapper->setXRow(-1); |
|
305 | 305 | mapper->setYRow(1); |
|
306 | 306 | |
|
307 | 307 | QCOMPARE(m_series->count(), 0); |
|
308 | 308 | |
|
309 | 309 | delete mapper; |
|
310 | 310 | mapper = 0; |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | void tst_qxymodelmapper::seriesUpdated() |
|
314 | 314 | { |
|
315 | 315 | // setup the mapper |
|
316 | 316 | createVerticalMapper(); |
|
317 | 317 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
318 |
QCOMPARE(m_vMapper-> |
|
|
318 | QCOMPARE(m_vMapper->rowCount(), -1); | |
|
319 | 319 | |
|
320 | 320 | m_series->append(QPointF(100, 100)); |
|
321 | 321 | QCOMPARE(m_series->count(), m_modelRowCount + 1); |
|
322 |
QCOMPARE(m_vMapper-> |
|
|
322 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
|
323 | 323 | |
|
324 | 324 | m_series->remove(m_series->points().last()); |
|
325 | 325 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
326 |
QCOMPARE(m_vMapper-> |
|
|
326 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
|
327 | 327 | |
|
328 | 328 | m_series->replace(m_series->points().first(), QPointF(25.0, 75.0)); |
|
329 | 329 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); |
|
330 | 330 | QCOMPARE(m_model->data(m_model->index(0, 1)).toReal(), 75.0); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | void tst_qxymodelmapper::verticalModelInsertRows() |
|
334 | 334 | { |
|
335 | 335 | // setup the mapper |
|
336 | 336 | createVerticalMapper(); |
|
337 | 337 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
338 | 338 | QVERIFY(m_vMapper->model() != 0); |
|
339 | 339 | |
|
340 | 340 | int insertCount = 4; |
|
341 | 341 | m_model->insertRows(3, insertCount); |
|
342 | 342 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount); |
|
343 | 343 | |
|
344 | 344 | int first = 3; |
|
345 | m_vMapper->setFirst(3); | |
|
345 | m_vMapper->setFirstRow(3); | |
|
346 | 346 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); |
|
347 | 347 | |
|
348 | 348 | m_model->insertRows(3, insertCount); |
|
349 | 349 | QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); |
|
350 | 350 | |
|
351 | 351 | int countLimit = 6; |
|
352 | m_vMapper->setCount(countLimit); | |
|
352 | m_vMapper->setRowCount(countLimit); | |
|
353 | 353 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
354 | 354 | |
|
355 | 355 | m_model->insertRows(3, insertCount); |
|
356 | 356 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
357 | 357 | |
|
358 | m_vMapper->setFirst(0); | |
|
358 | m_vMapper->setFirstRow(0); | |
|
359 | 359 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
360 | 360 | |
|
361 | m_vMapper->setCount(-1); | |
|
361 | m_vMapper->setRowCount(-1); | |
|
362 | 362 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | void tst_qxymodelmapper::verticalModelRemoveRows() |
|
366 | 366 | { |
|
367 | 367 | // setup the mapper |
|
368 | 368 | createVerticalMapper(); |
|
369 | 369 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
370 | 370 | QVERIFY(m_vMapper->model() != 0); |
|
371 | 371 | |
|
372 | 372 | int removeCount = 2; |
|
373 | 373 | m_model->removeRows(1, removeCount); |
|
374 | 374 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount); |
|
375 | 375 | |
|
376 | 376 | int first = 1; |
|
377 | m_vMapper->setFirst(first); | |
|
377 | m_vMapper->setFirstRow(first); | |
|
378 | 378 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); |
|
379 | 379 | |
|
380 | 380 | m_model->removeRows(1, removeCount); |
|
381 | 381 | QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); |
|
382 | 382 | |
|
383 | 383 | int countLimit = 3; |
|
384 | m_vMapper->setCount(countLimit); | |
|
384 | m_vMapper->setRowCount(countLimit); | |
|
385 | 385 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
386 | 386 | |
|
387 | 387 | m_model->removeRows(1, removeCount); |
|
388 | 388 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
389 | 389 | |
|
390 | m_vMapper->setFirst(0); | |
|
390 | m_vMapper->setFirstRow(0); | |
|
391 | 391 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
392 | 392 | |
|
393 | m_vMapper->setCount(-1); | |
|
393 | m_vMapper->setRowCount(-1); | |
|
394 | 394 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); |
|
395 | 395 | } |
|
396 | 396 | |
|
397 | 397 | void tst_qxymodelmapper::verticalModelInsertColumns() |
|
398 | 398 | { |
|
399 | 399 | // setup the mapper |
|
400 | 400 | createVerticalMapper(); |
|
401 | 401 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
402 | 402 | QVERIFY(m_vMapper->model() != 0); |
|
403 | 403 | |
|
404 | 404 | int insertCount = 4; |
|
405 | 405 | m_model->insertColumns(3, insertCount); |
|
406 | 406 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | void tst_qxymodelmapper::verticalModelRemoveColumns() |
|
410 | 410 | { |
|
411 | 411 | // setup the mapper |
|
412 | 412 | createVerticalMapper(); |
|
413 | 413 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
414 | 414 | QVERIFY(m_vMapper->model() != 0); |
|
415 | 415 | |
|
416 | 416 | int removeCount = m_modelColumnCount - 2; |
|
417 | 417 | m_model->removeColumns(0, removeCount); |
|
418 | 418 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
419 | 419 | |
|
420 | 420 | // leave only one column |
|
421 | 421 | m_model->removeColumns(0, m_modelColumnCount - removeCount - 1); |
|
422 | 422 | QCOMPARE(m_series->count(), 0); |
|
423 | 423 | } |
|
424 | 424 | |
|
425 | 425 | void tst_qxymodelmapper::horizontalModelInsertRows() |
|
426 | 426 | { |
|
427 | 427 | // setup the mapper |
|
428 | 428 | createHorizontalMapper(); |
|
429 | 429 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
430 | 430 | QVERIFY(m_hMapper->model() != 0); |
|
431 | 431 | |
|
432 | 432 | int insertCount = 4; |
|
433 | 433 | m_model->insertRows(3, insertCount); |
|
434 | 434 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
435 | 435 | } |
|
436 | 436 | |
|
437 | 437 | void tst_qxymodelmapper::horizontalModelRemoveRows() |
|
438 | 438 | { |
|
439 | 439 | // setup the mapper |
|
440 | 440 | createHorizontalMapper(); |
|
441 | 441 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
442 | 442 | QVERIFY(m_hMapper->model() != 0); |
|
443 | 443 | |
|
444 | 444 | int removeCount = m_modelRowCount - 2; |
|
445 | 445 | m_model->removeRows(0, removeCount); |
|
446 | 446 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
447 | 447 | |
|
448 | 448 | // leave only one column |
|
449 | 449 | m_model->removeRows(0, m_modelRowCount - removeCount - 1); |
|
450 | 450 | QCOMPARE(m_series->count(), 0); |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | void tst_qxymodelmapper::horizontalModelInsertColumns() |
|
454 | 454 | { |
|
455 | 455 | // setup the mapper |
|
456 | 456 | createHorizontalMapper(); |
|
457 | 457 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
458 | 458 | QVERIFY(m_hMapper->model() != 0); |
|
459 | 459 | |
|
460 | 460 | int insertCount = 4; |
|
461 | 461 | m_model->insertColumns(3, insertCount); |
|
462 | 462 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); |
|
463 | 463 | |
|
464 | 464 | int first = 3; |
|
465 | m_hMapper->setFirst(3); | |
|
465 | m_hMapper->setFirstColumn(3); | |
|
466 | 466 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); |
|
467 | 467 | |
|
468 | 468 | m_model->insertColumns(3, insertCount); |
|
469 | 469 | QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); |
|
470 | 470 | |
|
471 | 471 | int countLimit = 6; |
|
472 | m_hMapper->setCount(countLimit); | |
|
472 | m_hMapper->setColumnCount(countLimit); | |
|
473 | 473 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
474 | 474 | |
|
475 | 475 | m_model->insertColumns(3, insertCount); |
|
476 | 476 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
477 | 477 | |
|
478 | m_hMapper->setFirst(0); | |
|
478 | m_hMapper->setFirstColumn(0); | |
|
479 | 479 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
480 | 480 | |
|
481 | m_hMapper->setCount(-1); | |
|
481 | m_hMapper->setColumnCount(-1); | |
|
482 | 482 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); |
|
483 | 483 | } |
|
484 | 484 | |
|
485 | 485 | void tst_qxymodelmapper::horizontalModelRemoveColumns() |
|
486 | 486 | { |
|
487 | 487 | // setup the mapper |
|
488 | 488 | createHorizontalMapper(); |
|
489 | 489 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
490 | 490 | QVERIFY(m_hMapper->model() != 0); |
|
491 | 491 | |
|
492 | 492 | int removeCount = 2; |
|
493 | 493 | m_model->removeColumns(1, removeCount); |
|
494 | 494 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); |
|
495 | 495 | |
|
496 | 496 | int first = 1; |
|
497 | m_hMapper->setFirst(first); | |
|
497 | m_hMapper->setFirstColumn(first); | |
|
498 | 498 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); |
|
499 | 499 | |
|
500 | 500 | m_model->removeColumns(1, removeCount); |
|
501 | 501 | QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); |
|
502 | 502 | |
|
503 | 503 | int countLimit = 3; |
|
504 | m_hMapper->setCount(countLimit); | |
|
504 | m_hMapper->setColumnCount(countLimit); | |
|
505 | 505 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
506 | 506 | |
|
507 | 507 | m_model->removeColumns(1, removeCount); |
|
508 | 508 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
509 | 509 | |
|
510 | m_hMapper->setFirst(0); | |
|
510 | m_hMapper->setFirstColumn(0); | |
|
511 | 511 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
512 | 512 | |
|
513 | m_hMapper->setCount(-1); | |
|
513 | m_hMapper->setColumnCount(-1); | |
|
514 | 514 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); |
|
515 | 515 | } |
|
516 | 516 | |
|
517 | 517 | void tst_qxymodelmapper::modelUpdateCell() |
|
518 | 518 | { |
|
519 | 519 | // setup the mapper |
|
520 | 520 | createVerticalMapper(); |
|
521 | 521 | |
|
522 | 522 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
523 | 523 | QCOMPARE(m_series->points().at(1).x(), 44.0); |
|
524 | 524 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
525 | 525 | } |
|
526 | 526 | |
|
527 | 527 | QTEST_MAIN(tst_qxymodelmapper) |
|
528 | 528 | |
|
529 | 529 | #include "tst_qxymodelmapper.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now