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