@@ -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 | first: 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 | first: 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 | first: 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 | first: 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 | first: 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 | first: 1 |
|
152 | firstRow: 1 | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } |
@@ -1,113 +1,171 | |||||
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 "qhpiemodelmapper.h" |
|
21 | #include "qhpiemodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHPieModelMapper |
|
26 | \class QHPieModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | 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 QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. |
|
31 | Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. | |
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync. |
|
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie 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. |
|
33 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \property QHPieModelMapper::valuesRow |
|
37 | \property QHPieModelMapper::valuesRow | |
38 | \brief Defines which row of the model is kept in sync with the values of the pie's slices |
|
38 | \brief Defines which row of the model is kept in sync with the values of the pie's slices | |
39 |
|
39 | |||
40 | Default value is: -1 (invalid mapping) |
|
40 | Default value is: -1 (invalid mapping) | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QHPieModelMapper::labelsRow |
|
44 | \property QHPieModelMapper::labelsRow | |
45 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices |
|
45 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices | |
46 |
|
46 | |||
47 | Default value is: -1 (invalid mapping) |
|
47 | Default value is: -1 (invalid mapping) | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
|
51 | \property QHPieModelMapper::firstColumn | |||
|
52 | \brief Defines which column of the model contains the first slice value. | |||
|
53 | Minimal and default value is: 0 | |||
|
54 | */ | |||
|
55 | /*! | |||
|
56 | \qmlproperty int QHPieModelMapper::firstColumn | |||
|
57 | Defines which column of the model contains the first slice value. | |||
|
58 | The default value is 0. | |||
|
59 | */ | |||
|
60 | ||||
|
61 | /*! | |||
|
62 | \property QHPieModelMapper::columnCount | |||
|
63 | \brief Defines the number of columns of the model that are mapped as the data for QPieSeries | |||
|
64 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |||
|
65 | */ | |||
|
66 | /*! | |||
|
67 | \qmlproperty int QHPieModelMapper::columnCount | |||
|
68 | Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is | |||
|
69 | -1 (count limited by the number of columns in the model) | |||
|
70 | */ | |||
|
71 | ||||
|
72 | /*! | |||
51 | \fn void QHPieModelMapper::valuesRowChanged() |
|
73 | \fn void QHPieModelMapper::valuesRowChanged() | |
52 |
|
74 | |||
53 | Emitted when the valuesRow has changed. |
|
75 | Emitted when the valuesRow has changed. | |
54 | */ |
|
76 | */ | |
55 |
|
77 | |||
56 | /*! |
|
78 | /*! | |
57 | \fn void QHPieModelMapper::labelsRowChanged() |
|
79 | \fn void QHPieModelMapper::labelsRowChanged() | |
58 |
|
80 | |||
59 | Emitted when the labelsRow has changed. |
|
81 | Emitted when the labelsRow has changed. | |
60 | */ |
|
82 | */ | |
61 |
|
83 | |||
62 | /*! |
|
84 | /*! | |
|
85 | \fn void QHPieModelMapper::firstColumnChanged() | |||
|
86 | Emitted when the firstColumn has changed. | |||
|
87 | */ | |||
|
88 | ||||
|
89 | /*! | |||
|
90 | \fn void QHPieModelMapper::columnCountChanged() | |||
|
91 | Emitted when the columnCount has changed. | |||
|
92 | */ | |||
|
93 | ||||
|
94 | /*! | |||
63 | Constructs a mapper object which is a child of \a parent. |
|
95 | Constructs a mapper object which is a child of \a parent. | |
64 | */ |
|
96 | */ | |
65 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : |
|
97 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : | |
66 | QPieModelMapper(parent) |
|
98 | QPieModelMapper(parent) | |
67 | { |
|
99 | { | |
68 |
|
|
100 | setOrientation(Qt::Horizontal); | |
69 | } |
|
101 | } | |
70 |
|
102 | |||
71 | /*! |
|
103 | /*! | |
72 | Returns which row of the model is kept in sync with the values of the pie's slices |
|
104 | Returns which row of the model is kept in sync with the values of the pie's slices | |
73 | */ |
|
105 | */ | |
74 | int QHPieModelMapper::valuesRow() const |
|
106 | int QHPieModelMapper::valuesRow() const | |
75 | { |
|
107 | { | |
76 |
return |
|
108 | return valuesSection(); | |
77 | } |
|
109 | } | |
78 |
|
110 | |||
79 | /*! |
|
111 | /*! | |
80 | Sets the model row that is kept in sync with the pie slices values. |
|
112 | Sets the model row that is kept in sync with the pie slices values. | |
81 | Parameter \a valuesRow specifies the row of the model. |
|
113 | Parameter \a valuesRow specifies the row of the model. | |
82 | */ |
|
114 | */ | |
83 | void QHPieModelMapper::setValuesRow(int valuesRow) |
|
115 | void QHPieModelMapper::setValuesRow(int valuesRow) | |
84 | { |
|
116 | { | |
85 | if (valuesRow != valuesSection()) { |
|
117 | if (valuesRow != valuesSection()) { | |
86 |
|
|
118 | setValuesSection(valuesRow); | |
87 | emit valuesRowChanged(); |
|
119 | emit valuesRowChanged(); | |
88 | } |
|
120 | } | |
89 | } |
|
121 | } | |
90 |
|
122 | |||
91 | /*! |
|
123 | /*! | |
92 | Returns which row of the model is kept in sync with the labels of the pie's slices |
|
124 | Returns which row of the model is kept in sync with the labels of the pie's slices | |
93 | */ |
|
125 | */ | |
94 | int QHPieModelMapper::labelsRow() const |
|
126 | int QHPieModelMapper::labelsRow() const | |
95 | { |
|
127 | { | |
96 |
return |
|
128 | return labelsSection(); | |
97 | } |
|
129 | } | |
98 |
|
130 | |||
99 | /*! |
|
131 | /*! | |
100 | Sets the model row that is kept in sync with the pie's slices labels. |
|
132 | Sets the model row that is kept in sync with the pie's slices labels. | |
101 | Parameter \a labelsRow specifies the row of the model. |
|
133 | Parameter \a labelsRow specifies the row of the model. | |
102 | */ |
|
134 | */ | |
103 | void QHPieModelMapper::setLabelsRow(int labelsRow) |
|
135 | void QHPieModelMapper::setLabelsRow(int labelsRow) | |
104 | { |
|
136 | { | |
105 | if (labelsRow != labelsSection()) { |
|
137 | if (labelsRow != labelsSection()) { | |
106 |
|
|
138 | setLabelsSection(labelsRow); | |
107 | emit labelsRowChanged(); |
|
139 | emit labelsRowChanged(); | |
108 | } |
|
140 | } | |
109 | } |
|
141 | } | |
110 |
|
142 | |||
|
143 | int QHPieModelMapper::firstColumn() const | |||
|
144 | { | |||
|
145 | return first(); | |||
|
146 | } | |||
|
147 | ||||
|
148 | void QHPieModelMapper::setFirstColumn(int firstColumn) | |||
|
149 | { | |||
|
150 | if (firstColumn != first()) { | |||
|
151 | setFirst(firstColumn); | |||
|
152 | emit firstColumnChanged(); | |||
|
153 | } | |||
|
154 | } | |||
|
155 | ||||
|
156 | int QHPieModelMapper::columnCount() const | |||
|
157 | { | |||
|
158 | return count(); | |||
|
159 | } | |||
|
160 | ||||
|
161 | void QHPieModelMapper::setColumnCount(int columnCount) | |||
|
162 | { | |||
|
163 | if (columnCount != count()) { | |||
|
164 | setCount(columnCount); | |||
|
165 | emit firstColumnChanged(); | |||
|
166 | } | |||
|
167 | } | |||
|
168 | ||||
111 | #include "moc_qhpiemodelmapper.cpp" |
|
169 | #include "moc_qhpiemodelmapper.cpp" | |
112 |
|
170 | |||
113 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,60 | |||||
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 QHPIEMODELMAPPER_H |
|
21 | #ifndef QHPIEMODELMAPPER_H | |
22 | #define QHPIEMODELMAPPER_H |
|
22 | #define QHPIEMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qpiemodelmapper.h" |
|
24 | #include "qpiemodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow NOTIFY valuesRowChanged) |
|
31 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow NOTIFY valuesRowChanged) | |
32 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow NOTIFY labelsRowChanged) |
|
32 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow NOTIFY labelsRowChanged) | |
|
33 | Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) | |||
|
34 | Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) | |||
33 |
|
35 | |||
34 | public: |
|
36 | public: | |
35 | explicit QHPieModelMapper(QObject *parent = 0); |
|
37 | explicit QHPieModelMapper(QObject *parent = 0); | |
36 |
|
38 | |||
37 | int valuesRow() const; |
|
39 | int valuesRow() const; | |
38 | void setValuesRow(int valuesRow); |
|
40 | void setValuesRow(int valuesRow); | |
39 |
|
41 | |||
40 | int labelsRow() const; |
|
42 | int labelsRow() const; | |
41 | void setLabelsRow(int labelsRow); |
|
43 | void setLabelsRow(int labelsRow); | |
42 |
|
44 | |||
|
45 | int firstColumn() const; | |||
|
46 | void setFirstColumn(int firstColumn); | |||
|
47 | ||||
|
48 | int columnCount() const; | |||
|
49 | void setColumnCount(int columnCount); | |||
|
50 | ||||
43 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
44 | void valuesRowChanged(); |
|
52 | void valuesRowChanged(); | |
45 | void labelsRowChanged(); |
|
53 | void labelsRowChanged(); | |
|
54 | void firstColumnChanged(); | |||
|
55 | void columnCountChanged(); | |||
46 | }; |
|
56 | }; | |
47 |
|
57 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
59 | |||
50 | #endif // QHPIEMODELMAPPER_H |
|
60 | #endif // QHPIEMODELMAPPER_H |
@@ -1,629 +1,611 | |||||
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 "qpiemodelmapper_p.h" |
|
21 | #include "qpiemodelmapper_p.h" | |
22 | #include "qpiemodelmapper.h" |
|
22 | #include "qpiemodelmapper.h" | |
23 | #include "qpieseries.h" |
|
23 | #include "qpieseries.h" | |
24 | #include "qpieslice.h" |
|
24 | #include "qpieslice.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QPieModelMapper |
|
30 | \class QPieModelMapper | |
31 | \brief part of QtCommercial chart API. |
|
31 | \brief part of QtCommercial chart API. | |
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
34 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
35 | The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object. |
|
35 | The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object. | |
36 | It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync. |
|
36 | It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync. | |
37 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
37 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \property QPieModelMapper::series |
|
41 | \property QPieModelMapper::series | |
42 | \brief Defines the QPieSeries object that is used by the mapper. |
|
42 | \brief Defines the QPieSeries object that is used by the mapper. | |
43 |
|
43 | |||
44 | All the data in the series is discarded when it is set to the mapper. |
|
44 | All the data in the series is discarded when it is set to the mapper. | |
45 | When new series is specified the old series is disconnected (it preserves its data) |
|
45 | When new series is specified the old series is disconnected (it preserves its data) | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \property QPieModelMapper::model |
|
49 | \property QPieModelMapper::model | |
50 | \brief Defines the model that is used by the mapper. |
|
50 | \brief Defines the model that is used by the mapper. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \property QPieModelMapper::first |
|
|||
55 | \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie |
|
|||
56 |
|
||||
57 | Minimal and default value is: 0 |
|
|||
58 | */ |
|
|||
59 |
|
||||
60 | /*! |
|
|||
61 | \property QPieModelMapper::count |
|
|||
62 | \brief Defines the number of rows/columns of the model that are mapped as the data for the pie. |
|
|||
63 |
|
||||
64 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
|||
65 | */ |
|
|||
66 |
|
||||
67 | /*! |
|
|||
68 | \fn void QPieModelMapper::seriesReplaced() |
|
54 | \fn void QPieModelMapper::seriesReplaced() | |
69 |
|
55 | |||
70 | Emitted when the series to which mapper is connected to has changed. |
|
56 | Emitted when the series to which mapper is connected to has changed. | |
71 | */ |
|
57 | */ | |
72 |
|
58 | |||
73 | /*! |
|
59 | /*! | |
74 | \fn void QPieModelMapper::modelReplaced() |
|
60 | \fn void QPieModelMapper::modelReplaced() | |
75 |
|
61 | |||
76 | Emitted when the model to which mapper is connected to has changed. |
|
62 | Emitted when the model to which mapper is connected to has changed. | |
77 | */ |
|
63 | */ | |
78 |
|
64 | |||
79 | /*! |
|
65 | /*! | |
80 | \fn void QPieModelMapper::firstChanged() |
|
|||
81 |
|
||||
82 | Emitted when the value for the first has changed. |
|
|||
83 | */ |
|
|||
84 |
|
||||
85 | /*! |
|
|||
86 | \fn void QPieModelMapper::countChanged() |
|
|||
87 |
|
||||
88 | Emitted when the value for the count has changed. |
|
|||
89 | */ |
|
|||
90 |
|
||||
91 | /*! |
|
|||
92 | Constructs a mapper object which is a child of \a parent. |
|
66 | Constructs a mapper object which is a child of \a parent. | |
93 | */ |
|
67 | */ | |
94 | QPieModelMapper::QPieModelMapper(QObject *parent) : |
|
68 | QPieModelMapper::QPieModelMapper(QObject *parent) : | |
95 | QObject(parent), |
|
69 | QObject(parent), | |
96 | d_ptr(new QPieModelMapperPrivate(this)) |
|
70 | d_ptr(new QPieModelMapperPrivate(this)) | |
97 | { |
|
71 | { | |
98 | } |
|
72 | } | |
99 |
|
73 | |||
100 | QAbstractItemModel* QPieModelMapper::model() const |
|
74 | QAbstractItemModel* QPieModelMapper::model() const | |
101 | { |
|
75 | { | |
102 | Q_D(const QPieModelMapper); |
|
76 | Q_D(const QPieModelMapper); | |
103 | return d->m_model; |
|
77 | return d->m_model; | |
104 | } |
|
78 | } | |
105 |
|
79 | |||
106 | void QPieModelMapper::setModel(QAbstractItemModel *model) |
|
80 | void QPieModelMapper::setModel(QAbstractItemModel *model) | |
107 | { |
|
81 | { | |
108 | if (model == 0) |
|
82 | if (model == 0) | |
109 | return; |
|
83 | return; | |
110 |
|
84 | |||
111 | Q_D(QPieModelMapper); |
|
85 | Q_D(QPieModelMapper); | |
112 | if (d->m_model) { |
|
86 | if (d->m_model) { | |
113 | disconnect(d->m_model, 0, d, 0); |
|
87 | disconnect(d->m_model, 0, d, 0); | |
114 | } |
|
88 | } | |
115 |
|
89 | |||
116 | d->m_model = model; |
|
90 | d->m_model = model; | |
117 | d->initializePieFromModel(); |
|
91 | d->initializePieFromModel(); | |
118 | // connect signals from the model |
|
92 | // connect signals from the model | |
119 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
93 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
120 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
94 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
121 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
95 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
122 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
96 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
123 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
97 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
124 |
|
98 | |||
125 | emit modelReplaced(); |
|
99 | emit modelReplaced(); | |
126 | } |
|
100 | } | |
127 |
|
101 | |||
128 | QPieSeries* QPieModelMapper::series() const |
|
102 | QPieSeries* QPieModelMapper::series() const | |
129 | { |
|
103 | { | |
130 | Q_D(const QPieModelMapper); |
|
104 | Q_D(const QPieModelMapper); | |
131 | return d->m_series; |
|
105 | return d->m_series; | |
132 | } |
|
106 | } | |
133 |
|
107 | |||
134 | void QPieModelMapper::setSeries(QPieSeries *series) |
|
108 | void QPieModelMapper::setSeries(QPieSeries *series) | |
135 | { |
|
109 | { | |
136 | Q_D(QPieModelMapper); |
|
110 | Q_D(QPieModelMapper); | |
137 | if (d->m_series) { |
|
111 | if (d->m_series) { | |
138 | disconnect(d->m_series, 0, d, 0); |
|
112 | disconnect(d->m_series, 0, d, 0); | |
139 | } |
|
113 | } | |
140 |
|
114 | |||
141 | if (series == 0) |
|
115 | if (series == 0) | |
142 | return; |
|
116 | return; | |
143 |
|
117 | |||
144 | d->m_series = series; |
|
118 | d->m_series = series; | |
145 | d->initializePieFromModel(); |
|
119 | d->initializePieFromModel(); | |
146 | // connect the signals from the series |
|
120 | // connect the signals from the series | |
147 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); |
|
121 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); | |
148 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); |
|
122 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); | |
149 |
|
123 | |||
150 | emit seriesReplaced(); |
|
124 | emit seriesReplaced(); | |
151 | } |
|
125 | } | |
152 |
|
126 | |||
|
127 | /*! | |||
|
128 | Defines which row/column of the model contains the first slice value. | |||
|
129 | Minimal and default value is: 0 | |||
|
130 | */ | |||
153 | int QPieModelMapper::first() const |
|
131 | int QPieModelMapper::first() const | |
154 | { |
|
132 | { | |
155 | Q_D(const QPieModelMapper); |
|
133 | Q_D(const QPieModelMapper); | |
156 | return d->m_first; |
|
134 | return d->m_first; | |
157 | } |
|
135 | } | |
158 |
|
136 | |||
|
137 | /*! | |||
|
138 | Sets which row/column of the model contains the \a first slice value. | |||
|
139 | Minimal and default value is: 0 | |||
|
140 | */ | |||
159 | void QPieModelMapper::setFirst(int first) |
|
141 | void QPieModelMapper::setFirst(int first) | |
160 | { |
|
142 | { | |
161 | Q_D(QPieModelMapper); |
|
143 | Q_D(QPieModelMapper); | |
162 | if (first != d->m_first) { |
|
|||
163 |
|
|
144 | d->m_first = qMax(first, 0); | |
164 |
|
|
145 | d->initializePieFromModel(); | |
165 |
|
||||
166 | emit firstChanged(); |
|
|||
167 | } |
|
|||
168 | } |
|
146 | } | |
169 |
|
147 | |||
|
148 | /*! | |||
|
149 | Defines the number of rows/columns of the model that are mapped as the data for QPieSeries | |||
|
150 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |||
|
151 | */ | |||
170 | int QPieModelMapper::count() const |
|
152 | int QPieModelMapper::count() const | |
171 | { |
|
153 | { | |
172 | Q_D(const QPieModelMapper); |
|
154 | Q_D(const QPieModelMapper); | |
173 | return d->m_count; |
|
155 | return d->m_count; | |
174 | } |
|
156 | } | |
175 |
|
157 | |||
|
158 | /*! | |||
|
159 | Defines the \a count of rows/columns of the model that are mapped as the data for QPieSeries | |||
|
160 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |||
|
161 | */ | |||
176 | void QPieModelMapper::setCount(int count) |
|
162 | void QPieModelMapper::setCount(int count) | |
177 | { |
|
163 | { | |
178 | Q_D(QPieModelMapper); |
|
164 | Q_D(QPieModelMapper); | |
179 | if (count != d->m_count) { |
|
|||
180 |
|
|
165 | d->m_count = qMax(count, -1); | |
181 |
|
|
166 | d->initializePieFromModel(); | |
182 |
|
||||
183 | emit countChanged(); |
|
|||
184 | } |
|
|||
185 | } |
|
167 | } | |
186 |
|
168 | |||
187 | /*! |
|
169 | /*! | |
188 | Returns the orientation that is used when QPieModelMapper accesses the model. |
|
170 | Returns the orientation that is used when QPieModelMapper accesses the model. | |
189 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
171 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) | |
190 | or from columns (Qt::Vertical) |
|
172 | or from columns (Qt::Vertical) | |
191 | */ |
|
173 | */ | |
192 | Qt::Orientation QPieModelMapper::orientation() const |
|
174 | Qt::Orientation QPieModelMapper::orientation() const | |
193 | { |
|
175 | { | |
194 | Q_D(const QPieModelMapper); |
|
176 | Q_D(const QPieModelMapper); | |
195 | return d->m_orientation; |
|
177 | return d->m_orientation; | |
196 | } |
|
178 | } | |
197 |
|
179 | |||
198 | /*! |
|
180 | /*! | |
199 | Returns the \a orientation that is used when QPieModelMapper accesses the model. |
|
181 | Returns the \a orientation that is used when QPieModelMapper accesses the model. | |
200 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
182 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) | |
201 | or from columns (Qt::Vertical) |
|
183 | or from columns (Qt::Vertical) | |
202 | */ |
|
184 | */ | |
203 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
185 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |
204 | { |
|
186 | { | |
205 | Q_D(QPieModelMapper); |
|
187 | Q_D(QPieModelMapper); | |
206 | d->m_orientation = orientation; |
|
188 | d->m_orientation = orientation; | |
207 | d->initializePieFromModel(); |
|
189 | d->initializePieFromModel(); | |
208 | } |
|
190 | } | |
209 |
|
191 | |||
210 | /*! |
|
192 | /*! | |
211 | Returns which section of the model is kept in sync with the values of the pie's slices |
|
193 | Returns which section of the model is kept in sync with the values of the pie's slices | |
212 | */ |
|
194 | */ | |
213 | int QPieModelMapper::valuesSection() const |
|
195 | int QPieModelMapper::valuesSection() const | |
214 | { |
|
196 | { | |
215 | Q_D(const QPieModelMapper); |
|
197 | Q_D(const QPieModelMapper); | |
216 | return d->m_valuesSection; |
|
198 | return d->m_valuesSection; | |
217 | } |
|
199 | } | |
218 |
|
200 | |||
219 | /*! |
|
201 | /*! | |
220 | Sets the model section that is kept in sync with the pie slices values. |
|
202 | Sets the model section that is kept in sync with the pie slices values. | |
221 | Parameter \a valuesSection specifies the section of the model. |
|
203 | Parameter \a valuesSection specifies the section of the model. | |
222 | */ |
|
204 | */ | |
223 | void QPieModelMapper::setValuesSection(int valuesSection) |
|
205 | void QPieModelMapper::setValuesSection(int valuesSection) | |
224 | { |
|
206 | { | |
225 | Q_D(QPieModelMapper); |
|
207 | Q_D(QPieModelMapper); | |
226 | d->m_valuesSection = qMax(-1, valuesSection); |
|
208 | d->m_valuesSection = qMax(-1, valuesSection); | |
227 | d->initializePieFromModel(); |
|
209 | d->initializePieFromModel(); | |
228 | } |
|
210 | } | |
229 |
|
211 | |||
230 | /*! |
|
212 | /*! | |
231 | Returns which section of the model is kept in sync with the labels of the pie's slices |
|
213 | Returns which section of the model is kept in sync with the labels of the pie's slices | |
232 | */ |
|
214 | */ | |
233 | int QPieModelMapper::labelsSection() const |
|
215 | int QPieModelMapper::labelsSection() const | |
234 | { |
|
216 | { | |
235 | Q_D(const QPieModelMapper); |
|
217 | Q_D(const QPieModelMapper); | |
236 | return d->m_labelsSection; |
|
218 | return d->m_labelsSection; | |
237 | } |
|
219 | } | |
238 |
|
220 | |||
239 | /*! |
|
221 | /*! | |
240 | Sets the model section that is kept in sync with the pie slices labels. |
|
222 | Sets the model section that is kept in sync with the pie slices labels. | |
241 | Parameter \a labelsSection specifies the section of the model. |
|
223 | Parameter \a labelsSection specifies the section of the model. | |
242 | */ |
|
224 | */ | |
243 | void QPieModelMapper::setLabelsSection(int labelsSection) |
|
225 | void QPieModelMapper::setLabelsSection(int labelsSection) | |
244 | { |
|
226 | { | |
245 | Q_D(QPieModelMapper); |
|
227 | Q_D(QPieModelMapper); | |
246 | d->m_labelsSection = qMax(-1, labelsSection); |
|
228 | d->m_labelsSection = qMax(-1, labelsSection); | |
247 | d->initializePieFromModel(); |
|
229 | d->initializePieFromModel(); | |
248 | } |
|
230 | } | |
249 |
|
231 | |||
250 | /*! |
|
232 | /*! | |
251 | Resets the QPieModelMapper to the default state. |
|
233 | Resets the QPieModelMapper to the default state. | |
252 | first: 0; count: -1; valuesSection: -1; labelsSection: -1; |
|
234 | first: 0; count: -1; valuesSection: -1; labelsSection: -1; | |
253 | */ |
|
235 | */ | |
254 | void QPieModelMapper::reset() |
|
236 | void QPieModelMapper::reset() | |
255 | { |
|
237 | { | |
256 | Q_D(QPieModelMapper); |
|
238 | Q_D(QPieModelMapper); | |
257 | d->m_first = 0; |
|
239 | d->m_first = 0; | |
258 | d->m_count = -1; |
|
240 | d->m_count = -1; | |
259 | d->m_valuesSection = -1; |
|
241 | d->m_valuesSection = -1; | |
260 | d->m_labelsSection = -1; |
|
242 | d->m_labelsSection = -1; | |
261 | } |
|
243 | } | |
262 |
|
244 | |||
263 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
245 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
264 |
|
246 | |||
265 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
247 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
266 | m_series(0), |
|
248 | m_series(0), | |
267 | m_model(0), |
|
249 | m_model(0), | |
268 | m_first(0), |
|
250 | m_first(0), | |
269 | m_count(-1), |
|
251 | m_count(-1), | |
270 | m_orientation(Qt::Vertical), |
|
252 | m_orientation(Qt::Vertical), | |
271 | m_valuesSection(-1), |
|
253 | m_valuesSection(-1), | |
272 | m_labelsSection(-1), |
|
254 | m_labelsSection(-1), | |
273 | m_seriesSignalsBlock(false), |
|
255 | m_seriesSignalsBlock(false), | |
274 | m_modelSignalsBlock(false), |
|
256 | m_modelSignalsBlock(false), | |
275 | q_ptr(q) |
|
257 | q_ptr(q) | |
276 | { |
|
258 | { | |
277 | } |
|
259 | } | |
278 |
|
260 | |||
279 | void QPieModelMapperPrivate::blockModelSignals(bool block) |
|
261 | void QPieModelMapperPrivate::blockModelSignals(bool block) | |
280 | { |
|
262 | { | |
281 | m_modelSignalsBlock = block; |
|
263 | m_modelSignalsBlock = block; | |
282 | } |
|
264 | } | |
283 |
|
265 | |||
284 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) |
|
266 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) | |
285 | { |
|
267 | { | |
286 | m_seriesSignalsBlock = block; |
|
268 | m_seriesSignalsBlock = block; | |
287 | } |
|
269 | } | |
288 |
|
270 | |||
289 |
|
271 | |||
290 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
272 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
291 | { |
|
273 | { | |
292 | if (!index.isValid()) |
|
274 | if (!index.isValid()) | |
293 | return 0; // index is invalid |
|
275 | return 0; // index is invalid | |
294 |
|
276 | |||
295 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { |
|
277 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { | |
296 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
278 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
297 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
279 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
298 | return m_series->slices().at(index.row() - m_first); |
|
280 | return m_series->slices().at(index.row() - m_first); | |
299 | else |
|
281 | else | |
300 | return 0; |
|
282 | return 0; | |
301 | } |
|
283 | } | |
302 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { |
|
284 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { | |
303 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { |
|
285 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { | |
304 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) |
|
286 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) | |
305 | return m_series->slices().at(index.column() - m_first); |
|
287 | return m_series->slices().at(index.column() - m_first); | |
306 | else |
|
288 | else | |
307 | return 0; |
|
289 | return 0; | |
308 | } |
|
290 | } | |
309 | } |
|
291 | } | |
310 | return 0; // This part of model has not been mapped to any slice |
|
292 | return 0; // This part of model has not been mapped to any slice | |
311 | } |
|
293 | } | |
312 |
|
294 | |||
313 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
295 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
314 | { |
|
296 | { | |
315 | if (m_count != -1 && slicePos >= m_count) |
|
297 | if (m_count != -1 && slicePos >= m_count) | |
316 | return QModelIndex(); // invalid |
|
298 | return QModelIndex(); // invalid | |
317 |
|
299 | |||
318 | if (m_orientation == Qt::Vertical) |
|
300 | if (m_orientation == Qt::Vertical) | |
319 | return m_model->index(slicePos + m_first, m_valuesSection); |
|
301 | return m_model->index(slicePos + m_first, m_valuesSection); | |
320 | else |
|
302 | else | |
321 | return m_model->index(m_valuesSection, slicePos + m_first); |
|
303 | return m_model->index(m_valuesSection, slicePos + m_first); | |
322 | } |
|
304 | } | |
323 |
|
305 | |||
324 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
306 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
325 | { |
|
307 | { | |
326 | if (m_count != -1 && slicePos >= m_count) |
|
308 | if (m_count != -1 && slicePos >= m_count) | |
327 | return QModelIndex(); // invalid |
|
309 | return QModelIndex(); // invalid | |
328 |
|
310 | |||
329 | if (m_orientation == Qt::Vertical) |
|
311 | if (m_orientation == Qt::Vertical) | |
330 | return m_model->index(slicePos + m_first, m_labelsSection); |
|
312 | return m_model->index(slicePos + m_first, m_labelsSection); | |
331 | else |
|
313 | else | |
332 | return m_model->index(m_labelsSection, slicePos + m_first); |
|
314 | return m_model->index(m_labelsSection, slicePos + m_first); | |
333 | } |
|
315 | } | |
334 |
|
316 | |||
335 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const |
|
317 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const | |
336 | { |
|
318 | { | |
337 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) |
|
319 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) | |
338 | return true; |
|
320 | return true; | |
339 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) |
|
321 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) | |
340 | return true; |
|
322 | return true; | |
341 |
|
323 | |||
342 | return false; |
|
324 | return false; | |
343 | } |
|
325 | } | |
344 |
|
326 | |||
345 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const |
|
327 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const | |
346 | { |
|
328 | { | |
347 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) |
|
329 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) | |
348 | return true; |
|
330 | return true; | |
349 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) |
|
331 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) | |
350 | return true; |
|
332 | return true; | |
351 |
|
333 | |||
352 | return false; |
|
334 | return false; | |
353 | } |
|
335 | } | |
354 |
|
336 | |||
355 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) |
|
337 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) | |
356 | { |
|
338 | { | |
357 | if (m_seriesSignalsBlock) |
|
339 | if (m_seriesSignalsBlock) | |
358 | return; |
|
340 | return; | |
359 |
|
341 | |||
360 | if (slices.count() == 0) |
|
342 | if (slices.count() == 0) | |
361 | return; |
|
343 | return; | |
362 |
|
344 | |||
363 | int firstIndex = m_series->slices().indexOf(slices.at(0)); |
|
345 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |
364 | if (firstIndex == -1) |
|
346 | if (firstIndex == -1) | |
365 | return; |
|
347 | return; | |
366 |
|
348 | |||
367 | if (m_count != -1) |
|
349 | if (m_count != -1) | |
368 | m_count += slices.count(); |
|
350 | m_count += slices.count(); | |
369 |
|
351 | |||
370 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
352 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
371 | m_slices.insert(i, slices.at(i - firstIndex)); |
|
353 | m_slices.insert(i, slices.at(i - firstIndex)); | |
372 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
354 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
373 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
355 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
374 | } |
|
356 | } | |
375 |
|
357 | |||
376 | blockModelSignals(); |
|
358 | blockModelSignals(); | |
377 | if (m_orientation == Qt::Vertical) |
|
359 | if (m_orientation == Qt::Vertical) | |
378 | m_model->insertRows(firstIndex + m_first, slices.count()); |
|
360 | m_model->insertRows(firstIndex + m_first, slices.count()); | |
379 | else |
|
361 | else | |
380 | m_model->insertColumns(firstIndex + m_first, slices.count()); |
|
362 | m_model->insertColumns(firstIndex + m_first, slices.count()); | |
381 |
|
363 | |||
382 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
364 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
383 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); |
|
365 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); | |
384 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); |
|
366 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); | |
385 | } |
|
367 | } | |
386 | blockModelSignals(false); |
|
368 | blockModelSignals(false); | |
387 | } |
|
369 | } | |
388 |
|
370 | |||
389 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) |
|
371 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) | |
390 | { |
|
372 | { | |
391 | if (m_seriesSignalsBlock) |
|
373 | if (m_seriesSignalsBlock) | |
392 | return; |
|
374 | return; | |
393 |
|
375 | |||
394 | if (slices.count() == 0) |
|
376 | if (slices.count() == 0) | |
395 | return; |
|
377 | return; | |
396 |
|
378 | |||
397 | int firstIndex = m_slices.indexOf(slices.at(0)); |
|
379 | int firstIndex = m_slices.indexOf(slices.at(0)); | |
398 | if (firstIndex == -1) |
|
380 | if (firstIndex == -1) | |
399 | return; |
|
381 | return; | |
400 |
|
382 | |||
401 | if (m_count != -1) |
|
383 | if (m_count != -1) | |
402 | m_count -= slices.count(); |
|
384 | m_count -= slices.count(); | |
403 |
|
385 | |||
404 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) |
|
386 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) | |
405 | m_slices.removeAt(i); |
|
387 | m_slices.removeAt(i); | |
406 |
|
388 | |||
407 | blockModelSignals(); |
|
389 | blockModelSignals(); | |
408 | if (m_orientation == Qt::Vertical) |
|
390 | if (m_orientation == Qt::Vertical) | |
409 | m_model->removeRows(firstIndex + m_first, slices.count()); |
|
391 | m_model->removeRows(firstIndex + m_first, slices.count()); | |
410 | else |
|
392 | else | |
411 | m_model->removeColumns(firstIndex + m_first, slices.count()); |
|
393 | m_model->removeColumns(firstIndex + m_first, slices.count()); | |
412 | blockModelSignals(false); |
|
394 | blockModelSignals(false); | |
413 | } |
|
395 | } | |
414 |
|
396 | |||
415 | void QPieModelMapperPrivate::sliceLabelChanged() |
|
397 | void QPieModelMapperPrivate::sliceLabelChanged() | |
416 | { |
|
398 | { | |
417 | if (m_seriesSignalsBlock) |
|
399 | if (m_seriesSignalsBlock) | |
418 | return; |
|
400 | return; | |
419 |
|
401 | |||
420 | blockModelSignals(); |
|
402 | blockModelSignals(); | |
421 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
403 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
422 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); |
|
404 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); | |
423 | blockModelSignals(false); |
|
405 | blockModelSignals(false); | |
424 | } |
|
406 | } | |
425 |
|
407 | |||
426 | void QPieModelMapperPrivate::sliceValueChanged() |
|
408 | void QPieModelMapperPrivate::sliceValueChanged() | |
427 | { |
|
409 | { | |
428 | if (m_seriesSignalsBlock) |
|
410 | if (m_seriesSignalsBlock) | |
429 | return; |
|
411 | return; | |
430 |
|
412 | |||
431 | blockModelSignals(); |
|
413 | blockModelSignals(); | |
432 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
414 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
433 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); |
|
415 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); | |
434 | blockModelSignals(false); |
|
416 | blockModelSignals(false); | |
435 | } |
|
417 | } | |
436 |
|
418 | |||
437 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
419 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
438 | { |
|
420 | { | |
439 | if (m_model == 0 || m_series == 0) |
|
421 | if (m_model == 0 || m_series == 0) | |
440 | return; |
|
422 | return; | |
441 |
|
423 | |||
442 | if (m_modelSignalsBlock) |
|
424 | if (m_modelSignalsBlock) | |
443 | return; |
|
425 | return; | |
444 |
|
426 | |||
445 | blockSeriesSignals(); |
|
427 | blockSeriesSignals(); | |
446 | QModelIndex index; |
|
428 | QModelIndex index; | |
447 | QPieSlice *slice; |
|
429 | QPieSlice *slice; | |
448 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
430 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
449 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
431 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
450 | index = topLeft.sibling(row, column); |
|
432 | index = topLeft.sibling(row, column); | |
451 | slice = pieSlice(index); |
|
433 | slice = pieSlice(index); | |
452 | if (slice) { |
|
434 | if (slice) { | |
453 | if (isValueIndex(index)) |
|
435 | if (isValueIndex(index)) | |
454 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
436 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
455 | if (isLabelIndex(index)) |
|
437 | if (isLabelIndex(index)) | |
456 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); |
|
438 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |
457 | } |
|
439 | } | |
458 | } |
|
440 | } | |
459 | } |
|
441 | } | |
460 | blockSeriesSignals(false); |
|
442 | blockSeriesSignals(false); | |
461 | } |
|
443 | } | |
462 |
|
444 | |||
463 |
|
445 | |||
464 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
446 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
465 | { |
|
447 | { | |
466 | Q_UNUSED(parent); |
|
448 | Q_UNUSED(parent); | |
467 | if (m_modelSignalsBlock) |
|
449 | if (m_modelSignalsBlock) | |
468 | return; |
|
450 | return; | |
469 |
|
451 | |||
470 | blockSeriesSignals(); |
|
452 | blockSeriesSignals(); | |
471 | if (m_orientation == Qt::Vertical) |
|
453 | if (m_orientation == Qt::Vertical) | |
472 | insertData(start, end); |
|
454 | insertData(start, end); | |
473 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
455 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
474 | initializePieFromModel(); |
|
456 | initializePieFromModel(); | |
475 | blockSeriesSignals(false); |
|
457 | blockSeriesSignals(false); | |
476 | } |
|
458 | } | |
477 |
|
459 | |||
478 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
460 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
479 | { |
|
461 | { | |
480 | Q_UNUSED(parent); |
|
462 | Q_UNUSED(parent); | |
481 | if (m_modelSignalsBlock) |
|
463 | if (m_modelSignalsBlock) | |
482 | return; |
|
464 | return; | |
483 |
|
465 | |||
484 | blockSeriesSignals(); |
|
466 | blockSeriesSignals(); | |
485 | if (m_orientation == Qt::Vertical) |
|
467 | if (m_orientation == Qt::Vertical) | |
486 | removeData(start, end); |
|
468 | removeData(start, end); | |
487 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
469 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
488 | initializePieFromModel(); |
|
470 | initializePieFromModel(); | |
489 | blockSeriesSignals(false); |
|
471 | blockSeriesSignals(false); | |
490 | } |
|
472 | } | |
491 |
|
473 | |||
492 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
474 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
493 | { |
|
475 | { | |
494 | Q_UNUSED(parent); |
|
476 | Q_UNUSED(parent); | |
495 | if (m_modelSignalsBlock) |
|
477 | if (m_modelSignalsBlock) | |
496 | return; |
|
478 | return; | |
497 |
|
479 | |||
498 | blockSeriesSignals(); |
|
480 | blockSeriesSignals(); | |
499 | if (m_orientation == Qt::Horizontal) |
|
481 | if (m_orientation == Qt::Horizontal) | |
500 | insertData(start, end); |
|
482 | insertData(start, end); | |
501 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
483 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
502 | initializePieFromModel(); |
|
484 | initializePieFromModel(); | |
503 | blockSeriesSignals(false); |
|
485 | blockSeriesSignals(false); | |
504 | } |
|
486 | } | |
505 |
|
487 | |||
506 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
488 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
507 | { |
|
489 | { | |
508 | Q_UNUSED(parent); |
|
490 | Q_UNUSED(parent); | |
509 | if (m_modelSignalsBlock) |
|
491 | if (m_modelSignalsBlock) | |
510 | return; |
|
492 | return; | |
511 |
|
493 | |||
512 | blockSeriesSignals(); |
|
494 | blockSeriesSignals(); | |
513 | if (m_orientation == Qt::Horizontal) |
|
495 | if (m_orientation == Qt::Horizontal) | |
514 | removeData(start, end); |
|
496 | removeData(start, end); | |
515 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
497 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
516 | initializePieFromModel(); |
|
498 | initializePieFromModel(); | |
517 | blockSeriesSignals(false); |
|
499 | blockSeriesSignals(false); | |
518 | } |
|
500 | } | |
519 |
|
501 | |||
520 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
502 | void QPieModelMapperPrivate::insertData(int start, int end) | |
521 | { |
|
503 | { | |
522 | if (m_model == 0 || m_series == 0) |
|
504 | if (m_model == 0 || m_series == 0) | |
523 | return; |
|
505 | return; | |
524 |
|
506 | |||
525 | if (m_count != -1 && start >= m_first + m_count) { |
|
507 | if (m_count != -1 && start >= m_first + m_count) { | |
526 | return; |
|
508 | return; | |
527 | } else { |
|
509 | } else { | |
528 | int addedCount = end - start + 1; |
|
510 | int addedCount = end - start + 1; | |
529 | if (m_count != -1 && addedCount > m_count) |
|
511 | if (m_count != -1 && addedCount > m_count) | |
530 | addedCount = m_count; |
|
512 | addedCount = m_count; | |
531 | int first = qMax(start, m_first); |
|
513 | int first = qMax(start, m_first); | |
532 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
514 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
533 | for (int i = first; i <= last; i++) { |
|
515 | for (int i = first; i <= last; i++) { | |
534 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
516 | QModelIndex valueIndex = valueModelIndex(i - m_first); | |
535 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
517 | QModelIndex labelIndex = labelModelIndex(i - m_first); | |
536 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
518 | if (valueIndex.isValid() && labelIndex.isValid()) { | |
537 | QPieSlice *slice = new QPieSlice; |
|
519 | QPieSlice *slice = new QPieSlice; | |
538 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
520 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
539 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
521 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
540 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
522 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
541 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
523 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
542 | m_series->insert(i - m_first, slice); |
|
524 | m_series->insert(i - m_first, slice); | |
543 | m_slices.insert(i - m_first, slice); |
|
525 | m_slices.insert(i - m_first, slice); | |
544 | } |
|
526 | } | |
545 | } |
|
527 | } | |
546 |
|
528 | |||
547 | // remove excess of slices (abouve m_count) |
|
529 | // remove excess of slices (abouve m_count) | |
548 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
530 | if (m_count != -1 && m_series->slices().size() > m_count) | |
549 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { |
|
531 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { | |
550 | m_series->remove(m_series->slices().at(i)); |
|
532 | m_series->remove(m_series->slices().at(i)); | |
551 | m_slices.removeAt(i); |
|
533 | m_slices.removeAt(i); | |
552 | } |
|
534 | } | |
553 | } |
|
535 | } | |
554 | } |
|
536 | } | |
555 |
|
537 | |||
556 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
538 | void QPieModelMapperPrivate::removeData(int start, int end) | |
557 | { |
|
539 | { | |
558 | if (m_model == 0 || m_series == 0) |
|
540 | if (m_model == 0 || m_series == 0) | |
559 | return; |
|
541 | return; | |
560 |
|
542 | |||
561 | int removedCount = end - start + 1; |
|
543 | int removedCount = end - start + 1; | |
562 | if (m_count != -1 && start >= m_first + m_count) { |
|
544 | if (m_count != -1 && start >= m_first + m_count) { | |
563 | return; |
|
545 | return; | |
564 | } else { |
|
546 | } else { | |
565 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
547 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
566 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
548 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
567 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
549 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
568 | for (int i = last; i >= first; i--) { |
|
550 | for (int i = last; i >= first; i--) { | |
569 | m_series->remove(m_series->slices().at(i - m_first)); |
|
551 | m_series->remove(m_series->slices().at(i - m_first)); | |
570 | m_slices.removeAt(i - m_first); |
|
552 | m_slices.removeAt(i - m_first); | |
571 | } |
|
553 | } | |
572 |
|
554 | |||
573 | if (m_count != -1) { |
|
555 | if (m_count != -1) { | |
574 | int itemsAvailable; // check how many are available to be added |
|
556 | int itemsAvailable; // check how many are available to be added | |
575 | if (m_orientation == Qt::Vertical) |
|
557 | if (m_orientation == Qt::Vertical) | |
576 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
558 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
577 | else |
|
559 | else | |
578 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
560 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); | |
579 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
561 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
580 | int currentSize = m_series->slices().size(); |
|
562 | int currentSize = m_series->slices().size(); | |
581 | if (toBeAdded > 0) |
|
563 | if (toBeAdded > 0) | |
582 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
564 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
583 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
565 | QModelIndex valueIndex = valueModelIndex(i - m_first); | |
584 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
566 | QModelIndex labelIndex = labelModelIndex(i - m_first); | |
585 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
567 | if (valueIndex.isValid() && labelIndex.isValid()) { | |
586 | QPieSlice *slice = new QPieSlice; |
|
568 | QPieSlice *slice = new QPieSlice; | |
587 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
569 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
588 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
570 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
589 | m_series->insert(i, slice); |
|
571 | m_series->insert(i, slice); | |
590 | m_slices.insert(i, slice); |
|
572 | m_slices.insert(i, slice); | |
591 | } |
|
573 | } | |
592 | } |
|
574 | } | |
593 | } |
|
575 | } | |
594 | } |
|
576 | } | |
595 | } |
|
577 | } | |
596 |
|
578 | |||
597 | void QPieModelMapperPrivate::initializePieFromModel() |
|
579 | void QPieModelMapperPrivate::initializePieFromModel() | |
598 | { |
|
580 | { | |
599 | if (m_model == 0 || m_series == 0) |
|
581 | if (m_model == 0 || m_series == 0) | |
600 | return; |
|
582 | return; | |
601 |
|
583 | |||
602 | blockSeriesSignals(); |
|
584 | blockSeriesSignals(); | |
603 | // clear current content |
|
585 | // clear current content | |
604 | m_series->clear(); |
|
586 | m_series->clear(); | |
605 | m_slices.clear(); |
|
587 | m_slices.clear(); | |
606 |
|
588 | |||
607 | // create the initial slices set |
|
589 | // create the initial slices set | |
608 | int slicePos = 0; |
|
590 | int slicePos = 0; | |
609 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
591 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
610 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
592 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
611 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
593 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
612 | QPieSlice *slice = new QPieSlice; |
|
594 | QPieSlice *slice = new QPieSlice; | |
613 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
595 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
614 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
596 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
615 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
597 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
616 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
598 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
617 | m_series->append(slice); |
|
599 | m_series->append(slice); | |
618 | m_slices.append(slice); |
|
600 | m_slices.append(slice); | |
619 | slicePos++; |
|
601 | slicePos++; | |
620 | valueIndex = valueModelIndex(slicePos); |
|
602 | valueIndex = valueModelIndex(slicePos); | |
621 | labelIndex = labelModelIndex(slicePos); |
|
603 | labelIndex = labelModelIndex(slicePos); | |
622 | } |
|
604 | } | |
623 | blockSeriesSignals(false); |
|
605 | blockSeriesSignals(false); | |
624 | } |
|
606 | } | |
625 |
|
607 | |||
626 | #include "moc_qpiemodelmapper_p.cpp" |
|
608 | #include "moc_qpiemodelmapper_p.cpp" | |
627 | #include "moc_qpiemodelmapper.cpp" |
|
609 | #include "moc_qpiemodelmapper.cpp" | |
628 |
|
610 | |||
629 | QTCOMMERCIALCHART_END_NAMESPACE |
|
611 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,80 | |||||
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 QPIEMODELMAPPER_H |
|
21 | #ifndef QPIEMODELMAPPER_H | |
22 | #define QPIEMODELMAPPER_H |
|
22 | #define QPIEMODELMAPPER_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 QPieModelMapperPrivate; |
|
31 | class QPieModelMapperPrivate; | |
32 | class QPieSeries; |
|
32 | class QPieSeries; | |
33 |
|
33 | |||
34 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject |
|
34 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(QPieSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
37 | Q_PROPERTY(QPieSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
38 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
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) |
|
39 | Q_ENUMS(Qt::Orientation) | |
42 |
|
40 | |||
43 | protected: |
|
41 | protected: | |
44 | QPieModelMapper(QObject *parent = 0); |
|
42 | QPieModelMapper(QObject *parent = 0); | |
45 |
|
43 | |||
46 | public: |
|
44 | public: | |
47 | QAbstractItemModel* model() const; |
|
45 | QAbstractItemModel* model() const; | |
48 | void setModel(QAbstractItemModel *model); |
|
46 | void setModel(QAbstractItemModel *model); | |
49 |
|
47 | |||
50 | QPieSeries* series() const; |
|
48 | QPieSeries* series() const; | |
51 | void setSeries(QPieSeries *series); |
|
49 | void setSeries(QPieSeries *series); | |
52 |
|
50 | |||
|
51 | void reset(); | |||
|
52 | ||||
|
53 | protected: | |||
53 | int first() const; |
|
54 | int first() const; | |
54 | void setFirst(int first); |
|
55 | void setFirst(int first); | |
55 |
|
56 | |||
56 | int count() const; |
|
57 | int count() const; | |
57 | void setCount(int count); |
|
58 | void setCount(int count); | |
58 |
|
59 | |||
59 | void reset(); |
|
|||
60 |
|
||||
61 | protected: |
|
|||
62 | int valuesSection() const; |
|
60 | int valuesSection() const; | |
63 | void setValuesSection(int valuesSection); |
|
61 | void setValuesSection(int valuesSection); | |
64 |
|
62 | |||
65 | int labelsSection() const; |
|
63 | int labelsSection() const; | |
66 | void setLabelsSection(int labelsSection); |
|
64 | void setLabelsSection(int labelsSection); | |
67 |
|
65 | |||
68 | Qt::Orientation orientation() const; |
|
66 | Qt::Orientation orientation() const; | |
69 | void setOrientation(Qt::Orientation orientation); |
|
67 | void setOrientation(Qt::Orientation orientation); | |
70 |
|
68 | |||
71 | Q_SIGNALS: |
|
69 | Q_SIGNALS: | |
72 | void seriesReplaced(); |
|
70 | void seriesReplaced(); | |
73 | void modelReplaced(); |
|
71 | void modelReplaced(); | |
74 | void firstChanged(); |
|
|||
75 | void countChanged(); |
|
|||
76 |
|
72 | |||
77 | protected: |
|
73 | protected: | |
78 | QPieModelMapperPrivate * const d_ptr; |
|
74 | QPieModelMapperPrivate * const d_ptr; | |
79 | Q_DECLARE_PRIVATE(QPieModelMapper) |
|
75 | Q_DECLARE_PRIVATE(QPieModelMapper) | |
80 | }; |
|
76 | }; | |
81 |
|
77 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
79 | |||
84 | #endif // QPIEMODELMAPPER_H |
|
80 | #endif // QPIEMODELMAPPER_H |
@@ -1,113 +1,171 | |||||
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 "qvpiemodelmapper.h" |
|
21 | #include "qvpiemodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVPieModelMapper |
|
26 | \class QVPieModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | 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 QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. |
|
31 | Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. | |
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync. |
|
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie 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. |
|
33 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \property QVPieModelMapper::valuesColumn |
|
37 | \property QVPieModelMapper::valuesColumn | |
38 | \brief Defines which column of the model is kept in sync with the values of the pie's slices |
|
38 | \brief Defines which column of the model is kept in sync with the values of the pie's slices | |
39 |
|
39 | |||
40 | Default value is: -1 (invalid mapping) |
|
40 | Default value is: -1 (invalid mapping) | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QVPieModelMapper::labelsColumn |
|
44 | \property QVPieModelMapper::labelsColumn | |
45 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices |
|
45 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices | |
46 |
|
46 | |||
47 | Default value is: -1 (invalid mapping) |
|
47 | Default value is: -1 (invalid mapping) | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
|
51 | \property QVPieModelMapper::firstRow | |||
|
52 | \brief Defines which row of the model contains the first slice value. | |||
|
53 | Minimal and default value is: 0 | |||
|
54 | */ | |||
|
55 | /*! | |||
|
56 | \qmlproperty int QVPieModelMapper::firstRow | |||
|
57 | Defines which row of the model contains the first slice value. | |||
|
58 | The default value is 0. | |||
|
59 | */ | |||
|
60 | ||||
|
61 | /*! | |||
|
62 | \property QVPieModelMapper::rowCount | |||
|
63 | \brief Defines the number of rows of the model that are mapped as the data for QPieSeries | |||
|
64 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |||
|
65 | */ | |||
|
66 | /*! | |||
|
67 | \qmlproperty int QVPieModelMapper::columnCount | |||
|
68 | Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is | |||
|
69 | -1 (count limited by the number of rows in the model) | |||
|
70 | */ | |||
|
71 | ||||
|
72 | /*! | |||
51 | \fn void QVPieModelMapper::valuesColumnChanged() |
|
73 | \fn void QVPieModelMapper::valuesColumnChanged() | |
52 |
|
74 | |||
53 | Emitted when the valuesColumn has changed. |
|
75 | Emitted when the valuesColumn has changed. | |
54 | */ |
|
76 | */ | |
55 |
|
77 | |||
56 | /*! |
|
78 | /*! | |
57 | \fn void QVPieModelMapper::labelsColumnChanged() |
|
79 | \fn void QVPieModelMapper::labelsColumnChanged() | |
58 |
|
80 | |||
59 | Emitted when the labelsColumn has changed. |
|
81 | Emitted when the labelsColumn has changed. | |
60 | */ |
|
82 | */ | |
61 |
|
83 | |||
62 | /*! |
|
84 | /*! | |
|
85 | \fn void QVPieModelMapper::firstRowChanged() | |||
|
86 | Emitted when the firstRow has changed. | |||
|
87 | */ | |||
|
88 | ||||
|
89 | /*! | |||
|
90 | \fn void QVPieModelMapper::rowCountChanged() | |||
|
91 | Emitted when the rowCount has changed. | |||
|
92 | */ | |||
|
93 | ||||
|
94 | /*! | |||
63 | Constructs a mapper object which is a child of \a parent. |
|
95 | Constructs a mapper object which is a child of \a parent. | |
64 | */ |
|
96 | */ | |
65 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : |
|
97 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : | |
66 | QPieModelMapper(parent) |
|
98 | QPieModelMapper(parent) | |
67 | { |
|
99 | { | |
68 | QPieModelMapper::setOrientation(Qt::Vertical); |
|
100 | QPieModelMapper::setOrientation(Qt::Vertical); | |
69 | } |
|
101 | } | |
70 |
|
102 | |||
71 | /*! |
|
103 | /*! | |
72 | Returns which column of the model is kept in sync with the values of the pie's slices |
|
104 | Returns which column of the model is kept in sync with the values of the pie's slices | |
73 | */ |
|
105 | */ | |
74 | int QVPieModelMapper::valuesColumn() const |
|
106 | int QVPieModelMapper::valuesColumn() const | |
75 | { |
|
107 | { | |
76 | return QPieModelMapper::valuesSection(); |
|
108 | return QPieModelMapper::valuesSection(); | |
77 | } |
|
109 | } | |
78 |
|
110 | |||
79 | /*! |
|
111 | /*! | |
80 | Sets the model column that is kept in sync with the pie slices values. |
|
112 | Sets the model column that is kept in sync with the pie slices values. | |
81 | Parameter \a valuesColumn specifies the row of the model. |
|
113 | Parameter \a valuesColumn specifies the row of the model. | |
82 | */ |
|
114 | */ | |
83 | void QVPieModelMapper::setValuesColumn(int valuesColumn) |
|
115 | void QVPieModelMapper::setValuesColumn(int valuesColumn) | |
84 | { |
|
116 | { | |
85 | if (valuesColumn != valuesSection()) { |
|
117 | if (valuesColumn != valuesSection()) { | |
86 | QPieModelMapper::setValuesSection(valuesColumn); |
|
118 | QPieModelMapper::setValuesSection(valuesColumn); | |
87 | emit valuesColumnChanged(); |
|
119 | emit valuesColumnChanged(); | |
88 | } |
|
120 | } | |
89 | } |
|
121 | } | |
90 |
|
122 | |||
91 | /*! |
|
123 | /*! | |
92 | Returns which column of the model is kept in sync with the labels of the pie's slices |
|
124 | Returns which column of the model is kept in sync with the labels of the pie's slices | |
93 | */ |
|
125 | */ | |
94 | int QVPieModelMapper::labelsColumn() const |
|
126 | int QVPieModelMapper::labelsColumn() const | |
95 | { |
|
127 | { | |
96 | return QPieModelMapper::labelsSection(); |
|
128 | return QPieModelMapper::labelsSection(); | |
97 | } |
|
129 | } | |
98 |
|
130 | |||
99 | /*! |
|
131 | /*! | |
100 | Sets the model column that is kept in sync with the pie's slices labels. |
|
132 | Sets the model column that is kept in sync with the pie's slices labels. | |
101 | Parameter \a labelsColumn specifies the row of the model. |
|
133 | Parameter \a labelsColumn specifies the row of the model. | |
102 | */ |
|
134 | */ | |
103 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) |
|
135 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) | |
104 | { |
|
136 | { | |
105 | if (labelsColumn != labelsSection()) { |
|
137 | if (labelsColumn != labelsSection()) { | |
106 | QPieModelMapper::setLabelsSection(labelsColumn); |
|
138 | QPieModelMapper::setLabelsSection(labelsColumn); | |
107 | emit labelsColumnChanged(); |
|
139 | emit labelsColumnChanged(); | |
108 | } |
|
140 | } | |
109 | } |
|
141 | } | |
110 |
|
142 | |||
|
143 | int QVPieModelMapper::firstRow() const | |||
|
144 | { | |||
|
145 | return first(); | |||
|
146 | } | |||
|
147 | ||||
|
148 | void QVPieModelMapper::setFirstRow(int firstRow) | |||
|
149 | { | |||
|
150 | if (firstRow != first()) { | |||
|
151 | setFirst(firstRow); | |||
|
152 | emit firstRowChanged(); | |||
|
153 | } | |||
|
154 | } | |||
|
155 | ||||
|
156 | int QVPieModelMapper::rowCount() const | |||
|
157 | { | |||
|
158 | return count(); | |||
|
159 | } | |||
|
160 | ||||
|
161 | void QVPieModelMapper::setRowCount(int rowCount) | |||
|
162 | { | |||
|
163 | if (rowCount != count()) { | |||
|
164 | setCount(rowCount); | |||
|
165 | emit firstRowChanged(); | |||
|
166 | } | |||
|
167 | } | |||
|
168 | ||||
111 | #include "moc_qvpiemodelmapper.cpp" |
|
169 | #include "moc_qvpiemodelmapper.cpp" | |
112 |
|
170 | |||
113 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,60 | |||||
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 QVPIEMODELMAPPER_H |
|
21 | #ifndef QVPIEMODELMAPPER_H | |
22 | #define QVPIEMODELMAPPER_H |
|
22 | #define QVPIEMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qpiemodelmapper.h" |
|
24 | #include "qpiemodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn NOTIFY valuesColumnChanged) |
|
31 | Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn NOTIFY valuesColumnChanged) | |
32 | Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn NOTIFY labelsColumnChanged) |
|
32 | Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn NOTIFY labelsColumnChanged) | |
|
33 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) | |||
|
34 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) | |||
33 |
|
35 | |||
34 | public: |
|
36 | public: | |
35 | explicit QVPieModelMapper(QObject *parent = 0); |
|
37 | explicit QVPieModelMapper(QObject *parent = 0); | |
36 |
|
38 | |||
37 | int valuesColumn() const; |
|
39 | int valuesColumn() const; | |
38 | void setValuesColumn(int valuesColumn); |
|
40 | void setValuesColumn(int valuesColumn); | |
39 |
|
41 | |||
40 | int labelsColumn() const; |
|
42 | int labelsColumn() const; | |
41 | void setLabelsColumn(int labelsColumn); |
|
43 | void setLabelsColumn(int labelsColumn); | |
42 |
|
44 | |||
|
45 | int firstRow() const; | |||
|
46 | void setFirstRow(int firstRow); | |||
|
47 | ||||
|
48 | int rowCount() const; | |||
|
49 | void setRowCount(int rowCount); | |||
|
50 | ||||
43 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
44 | void valuesColumnChanged(); |
|
52 | void valuesColumnChanged(); | |
45 | void labelsColumnChanged(); |
|
53 | void labelsColumnChanged(); | |
|
54 | void firstRowChanged(); | |||
|
55 | void rowCountChanged(); | |||
46 | }; |
|
56 | }; | |
47 |
|
57 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
59 | |||
50 | #endif // QVPIEMODELMAPPER_H |
|
60 | #endif // QVPIEMODELMAPPER_H |
@@ -1,528 +1,528 | |||||
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 <qpieseries.h> |
|
26 | #include <qpieseries.h> | |
27 | #include <qpieslice.h> |
|
27 | #include <qpieslice.h> | |
28 | #include <qvpiemodelmapper.h> |
|
28 | #include <qvpiemodelmapper.h> | |
29 | #include <qhpiemodelmapper.h> |
|
29 | #include <qhpiemodelmapper.h> | |
30 | #include <QStandardItemModel> |
|
30 | #include <QStandardItemModel> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | class tst_qpiemodelmapper : public QObject |
|
34 | class tst_qpiemodelmapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | tst_qpiemodelmapper(); |
|
39 | tst_qpiemodelmapper(); | |
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 | QVPieModelMapper *m_vMapper; |
|
71 | QVPieModelMapper *m_vMapper; | |
72 | QHPieModelMapper *m_hMapper; |
|
72 | QHPieModelMapper *m_hMapper; | |
73 |
|
73 | |||
74 | QPieSeries *m_series; |
|
74 | QPieSeries *m_series; | |
75 | QChart *m_chart; |
|
75 | QChart *m_chart; | |
76 | }; |
|
76 | }; | |
77 |
|
77 | |||
78 | tst_qpiemodelmapper::tst_qpiemodelmapper(): |
|
78 | tst_qpiemodelmapper::tst_qpiemodelmapper(): | |
79 | m_model(0), |
|
79 | m_model(0), | |
80 | m_modelRowCount(10), |
|
80 | m_modelRowCount(10), | |
81 | m_modelColumnCount(8), |
|
81 | m_modelColumnCount(8), | |
82 | m_vMapper(0), |
|
82 | m_vMapper(0), | |
83 | m_hMapper(0), |
|
83 | m_hMapper(0), | |
84 | m_series(0), |
|
84 | m_series(0), | |
85 | m_chart(0) |
|
85 | m_chart(0) | |
86 | { |
|
86 | { | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void tst_qpiemodelmapper::createVerticalMapper() |
|
89 | void tst_qpiemodelmapper::createVerticalMapper() | |
90 | { |
|
90 | { | |
91 | m_vMapper = new QVPieModelMapper; |
|
91 | m_vMapper = new QVPieModelMapper; | |
92 | QVERIFY(m_vMapper->model() == 0); |
|
92 | QVERIFY(m_vMapper->model() == 0); | |
93 | m_vMapper->setValuesColumn(0); |
|
93 | m_vMapper->setValuesColumn(0); | |
94 | m_vMapper->setLabelsColumn(1); |
|
94 | m_vMapper->setLabelsColumn(1); | |
95 | m_vMapper->setModel(m_model); |
|
95 | m_vMapper->setModel(m_model); | |
96 | m_vMapper->setSeries(m_series); |
|
96 | m_vMapper->setSeries(m_series); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void tst_qpiemodelmapper::createHorizontalMapper() |
|
99 | void tst_qpiemodelmapper::createHorizontalMapper() | |
100 | { |
|
100 | { | |
101 | m_hMapper = new QHPieModelMapper; |
|
101 | m_hMapper = new QHPieModelMapper; | |
102 | QVERIFY(m_hMapper->model() == 0); |
|
102 | QVERIFY(m_hMapper->model() == 0); | |
103 | m_hMapper->setValuesRow(0); |
|
103 | m_hMapper->setValuesRow(0); | |
104 | m_hMapper->setLabelsRow(1); |
|
104 | m_hMapper->setLabelsRow(1); | |
105 | m_hMapper->setModel(m_model); |
|
105 | m_hMapper->setModel(m_model); | |
106 | m_hMapper->setSeries(m_series); |
|
106 | m_hMapper->setSeries(m_series); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void tst_qpiemodelmapper::init() |
|
109 | void tst_qpiemodelmapper::init() | |
110 | { |
|
110 | { | |
111 | m_series = new QPieSeries; |
|
111 | m_series = new QPieSeries; | |
112 | m_chart->addSeries(m_series); |
|
112 | m_chart->addSeries(m_series); | |
113 |
|
113 | |||
114 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
114 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); | |
115 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
115 | for (int row = 0; row < m_modelRowCount; ++row) { | |
116 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
116 | for (int column = 0; column < m_modelColumnCount; column++) { | |
117 | m_model->setData(m_model->index(row, column), row * column); |
|
117 | m_model->setData(m_model->index(row, column), row * column); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_qpiemodelmapper::cleanup() |
|
122 | void tst_qpiemodelmapper::cleanup() | |
123 | { |
|
123 | { | |
124 | m_chart->removeSeries(m_series); |
|
124 | m_chart->removeSeries(m_series); | |
125 | m_series->deleteLater(); |
|
125 | m_series->deleteLater(); | |
126 | m_series = 0; |
|
126 | m_series = 0; | |
127 |
|
127 | |||
128 | m_model->clear(); |
|
128 | m_model->clear(); | |
129 | m_model->deleteLater(); |
|
129 | m_model->deleteLater(); | |
130 | m_model = 0; |
|
130 | m_model = 0; | |
131 |
|
131 | |||
132 | if (m_vMapper) { |
|
132 | if (m_vMapper) { | |
133 | m_vMapper->deleteLater(); |
|
133 | m_vMapper->deleteLater(); | |
134 | m_vMapper = 0; |
|
134 | m_vMapper = 0; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | if (m_hMapper) { |
|
137 | if (m_hMapper) { | |
138 | m_hMapper->deleteLater(); |
|
138 | m_hMapper->deleteLater(); | |
139 | m_hMapper = 0; |
|
139 | m_hMapper = 0; | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void tst_qpiemodelmapper::initTestCase() |
|
143 | void tst_qpiemodelmapper::initTestCase() | |
144 | { |
|
144 | { | |
145 | m_chart = new QChart; |
|
145 | m_chart = new QChart; | |
146 | QChartView *chartView = new QChartView(m_chart); |
|
146 | QChartView *chartView = new QChartView(m_chart); | |
147 | chartView->show(); |
|
147 | chartView->show(); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void tst_qpiemodelmapper::cleanupTestCase() |
|
150 | void tst_qpiemodelmapper::cleanupTestCase() | |
151 | { |
|
151 | { | |
152 | // |
|
152 | // | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void tst_qpiemodelmapper::verticalMapper_data() |
|
155 | void tst_qpiemodelmapper::verticalMapper_data() | |
156 | { |
|
156 | { | |
157 | QTest::addColumn<int>("valuesColumn"); |
|
157 | QTest::addColumn<int>("valuesColumn"); | |
158 | QTest::addColumn<int>("labelsColumn"); |
|
158 | QTest::addColumn<int>("labelsColumn"); | |
159 | QTest::addColumn<int>("expectedCount"); |
|
159 | QTest::addColumn<int>("expectedCount"); | |
160 | QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; |
|
160 | QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; | |
161 | QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; |
|
161 | QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; | |
162 | QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; |
|
162 | QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; | |
163 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; |
|
163 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; | |
164 | QTest::newRow("values column beyond the size of model and invalid labels column") << m_modelColumnCount << -1 << 0; |
|
164 | QTest::newRow("values column beyond the size of model and invalid labels column") << m_modelColumnCount << -1 << 0; | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void tst_qpiemodelmapper::verticalMapper() |
|
167 | void tst_qpiemodelmapper::verticalMapper() | |
168 | { |
|
168 | { | |
169 | QFETCH(int, valuesColumn); |
|
169 | QFETCH(int, valuesColumn); | |
170 | QFETCH(int, labelsColumn); |
|
170 | QFETCH(int, labelsColumn); | |
171 | QFETCH(int, expectedCount); |
|
171 | QFETCH(int, expectedCount); | |
172 |
|
172 | |||
173 | QVPieModelMapper *mapper = new QVPieModelMapper; |
|
173 | QVPieModelMapper *mapper = new QVPieModelMapper; | |
174 | mapper->setValuesColumn(valuesColumn); |
|
174 | mapper->setValuesColumn(valuesColumn); | |
175 | mapper->setLabelsColumn(labelsColumn); |
|
175 | mapper->setLabelsColumn(labelsColumn); | |
176 | mapper->setModel(m_model); |
|
176 | mapper->setModel(m_model); | |
177 | mapper->setSeries(m_series); |
|
177 | mapper->setSeries(m_series); | |
178 |
|
178 | |||
179 | QCOMPARE(m_series->count(), expectedCount); |
|
179 | QCOMPARE(m_series->count(), expectedCount); | |
180 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); |
|
180 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); | |
181 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); |
|
181 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); | |
182 |
|
182 | |||
183 | delete mapper; |
|
183 | delete mapper; | |
184 | mapper = 0; |
|
184 | mapper = 0; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void tst_qpiemodelmapper::verticalMapperCustomMapping_data() |
|
187 | void tst_qpiemodelmapper::verticalMapperCustomMapping_data() | |
188 | { |
|
188 | { | |
189 | QTest::addColumn<int>("first"); |
|
189 | QTest::addColumn<int>("first"); | |
190 | QTest::addColumn<int>("countLimit"); |
|
190 | QTest::addColumn<int>("countLimit"); | |
191 | QTest::addColumn<int>("expectedCount"); |
|
191 | QTest::addColumn<int>("expectedCount"); | |
192 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; |
|
192 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; | |
193 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; |
|
193 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; | |
194 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); |
|
194 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); | |
195 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); |
|
195 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); | |
196 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; |
|
196 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; | |
197 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; |
|
197 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; | |
198 | 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; |
|
198 | 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; | |
199 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; |
|
199 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; | |
200 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; |
|
200 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; | |
201 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; |
|
201 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; | |
202 |
|
202 | |||
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void tst_qpiemodelmapper::verticalMapperCustomMapping() |
|
205 | void tst_qpiemodelmapper::verticalMapperCustomMapping() | |
206 | { |
|
206 | { | |
207 | QFETCH(int, first); |
|
207 | QFETCH(int, first); | |
208 | QFETCH(int, countLimit); |
|
208 | QFETCH(int, countLimit); | |
209 | QFETCH(int, expectedCount); |
|
209 | QFETCH(int, expectedCount); | |
210 |
|
210 | |||
211 | QCOMPARE(m_series->count(), 0); |
|
211 | QCOMPARE(m_series->count(), 0); | |
212 |
|
212 | |||
213 | QVPieModelMapper *mapper = new QVPieModelMapper; |
|
213 | QVPieModelMapper *mapper = new QVPieModelMapper; | |
214 | mapper->setValuesColumn(0); |
|
214 | mapper->setValuesColumn(0); | |
215 | mapper->setLabelsColumn(1); |
|
215 | mapper->setLabelsColumn(1); | |
216 | mapper->setModel(m_model); |
|
216 | mapper->setModel(m_model); | |
217 | mapper->setSeries(m_series); |
|
217 | mapper->setSeries(m_series); | |
218 | mapper->setFirst(first); |
|
218 | mapper->setFirstRow(first); | |
219 | mapper->setCount(countLimit); |
|
219 | mapper->setRowCount(countLimit); | |
220 |
|
220 | |||
221 | QCOMPARE(m_series->count(), expectedCount); |
|
221 | QCOMPARE(m_series->count(), expectedCount); | |
222 |
|
222 | |||
223 | // change values column mapping to invalid |
|
223 | // change values column mapping to invalid | |
224 | mapper->setValuesColumn(-1); |
|
224 | mapper->setValuesColumn(-1); | |
225 | mapper->setLabelsColumn(1); |
|
225 | mapper->setLabelsColumn(1); | |
226 |
|
226 | |||
227 | QCOMPARE(m_series->count(), 0); |
|
227 | QCOMPARE(m_series->count(), 0); | |
228 |
|
228 | |||
229 | delete mapper; |
|
229 | delete mapper; | |
230 | mapper = 0; |
|
230 | mapper = 0; | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void tst_qpiemodelmapper::horizontalMapper_data() |
|
233 | void tst_qpiemodelmapper::horizontalMapper_data() | |
234 | { |
|
234 | { | |
235 | QTest::addColumn<int>("valuesRow"); |
|
235 | QTest::addColumn<int>("valuesRow"); | |
236 | QTest::addColumn<int>("labelsRow"); |
|
236 | QTest::addColumn<int>("labelsRow"); | |
237 | QTest::addColumn<int>("expectedCount"); |
|
237 | QTest::addColumn<int>("expectedCount"); | |
238 | QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; |
|
238 | QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; | |
239 | QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; |
|
239 | QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; | |
240 | QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; |
|
240 | QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; | |
241 | QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; |
|
241 | QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; | |
242 | QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; |
|
242 | QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void tst_qpiemodelmapper::horizontalMapper() |
|
245 | void tst_qpiemodelmapper::horizontalMapper() | |
246 | { |
|
246 | { | |
247 | QFETCH(int, valuesRow); |
|
247 | QFETCH(int, valuesRow); | |
248 | QFETCH(int, labelsRow); |
|
248 | QFETCH(int, labelsRow); | |
249 | QFETCH(int, expectedCount); |
|
249 | QFETCH(int, expectedCount); | |
250 |
|
250 | |||
251 | QHPieModelMapper *mapper = new QHPieModelMapper; |
|
251 | QHPieModelMapper *mapper = new QHPieModelMapper; | |
252 | mapper->setValuesRow(valuesRow); |
|
252 | mapper->setValuesRow(valuesRow); | |
253 | mapper->setLabelsRow(labelsRow); |
|
253 | mapper->setLabelsRow(labelsRow); | |
254 | mapper->setModel(m_model); |
|
254 | mapper->setModel(m_model); | |
255 | mapper->setSeries(m_series); |
|
255 | mapper->setSeries(m_series); | |
256 |
|
256 | |||
257 | QCOMPARE(m_series->count(), expectedCount); |
|
257 | QCOMPARE(m_series->count(), expectedCount); | |
258 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); |
|
258 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); | |
259 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); |
|
259 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); | |
260 |
|
260 | |||
261 | delete mapper; |
|
261 | delete mapper; | |
262 | mapper = 0; |
|
262 | mapper = 0; | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void tst_qpiemodelmapper::horizontalMapperCustomMapping_data() |
|
265 | void tst_qpiemodelmapper::horizontalMapperCustomMapping_data() | |
266 | { |
|
266 | { | |
267 | QTest::addColumn<int>("first"); |
|
267 | QTest::addColumn<int>("first"); | |
268 | QTest::addColumn<int>("countLimit"); |
|
268 | QTest::addColumn<int>("countLimit"); | |
269 | QTest::addColumn<int>("expectedCount"); |
|
269 | QTest::addColumn<int>("expectedCount"); | |
270 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; |
|
270 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; | |
271 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; |
|
271 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; | |
272 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); |
|
272 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); | |
273 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); |
|
273 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); | |
274 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; |
|
274 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; | |
275 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; |
|
275 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; | |
276 | 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; |
|
276 | 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; | |
277 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; |
|
277 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; | |
278 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; |
|
278 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; | |
279 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; |
|
279 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void tst_qpiemodelmapper::horizontalMapperCustomMapping() |
|
282 | void tst_qpiemodelmapper::horizontalMapperCustomMapping() | |
283 | { |
|
283 | { | |
284 | QFETCH(int, first); |
|
284 | QFETCH(int, first); | |
285 | QFETCH(int, countLimit); |
|
285 | QFETCH(int, countLimit); | |
286 | QFETCH(int, expectedCount); |
|
286 | QFETCH(int, expectedCount); | |
287 |
|
287 | |||
288 | QCOMPARE(m_series->count(), 0); |
|
288 | QCOMPARE(m_series->count(), 0); | |
289 |
|
289 | |||
290 | QHPieModelMapper *mapper = new QHPieModelMapper; |
|
290 | QHPieModelMapper *mapper = new QHPieModelMapper; | |
291 | mapper->setValuesRow(0); |
|
291 | mapper->setValuesRow(0); | |
292 | mapper->setLabelsRow(1); |
|
292 | mapper->setLabelsRow(1); | |
293 | mapper->setModel(m_model); |
|
293 | mapper->setModel(m_model); | |
294 | mapper->setSeries(m_series); |
|
294 | mapper->setSeries(m_series); | |
295 | mapper->setFirst(first); |
|
295 | mapper->setFirstColumn(first); | |
296 | mapper->setCount(countLimit); |
|
296 | mapper->setColumnCount(countLimit); | |
297 |
|
297 | |||
298 | QCOMPARE(m_series->count(), expectedCount); |
|
298 | QCOMPARE(m_series->count(), expectedCount); | |
299 |
|
299 | |||
300 | // change values row mapping to invalid |
|
300 | // change values row mapping to invalid | |
301 | mapper->setValuesRow(-1); |
|
301 | mapper->setValuesRow(-1); | |
302 | mapper->setLabelsRow(1); |
|
302 | mapper->setLabelsRow(1); | |
303 |
|
303 | |||
304 | QCOMPARE(m_series->count(), 0); |
|
304 | QCOMPARE(m_series->count(), 0); | |
305 |
|
305 | |||
306 | delete mapper; |
|
306 | delete mapper; | |
307 | mapper = 0; |
|
307 | mapper = 0; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | void tst_qpiemodelmapper::seriesUpdated() |
|
310 | void tst_qpiemodelmapper::seriesUpdated() | |
311 | { |
|
311 | { | |
312 | // setup the mapper |
|
312 | // setup the mapper | |
313 | createVerticalMapper(); |
|
313 | createVerticalMapper(); | |
314 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
314 | QCOMPARE(m_series->count(), m_modelRowCount); | |
315 |
QCOMPARE(m_vMapper-> |
|
315 | QCOMPARE(m_vMapper->rowCount(), -1); | |
316 |
|
316 | |||
317 | m_series->append("1000", 1000); |
|
317 | m_series->append("1000", 1000); | |
318 | QCOMPARE(m_series->count(), m_modelRowCount + 1); |
|
318 | QCOMPARE(m_series->count(), m_modelRowCount + 1); | |
319 |
QCOMPARE(m_vMapper-> |
|
319 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
320 |
|
320 | |||
321 | m_series->remove(m_series->slices().last()); |
|
321 | m_series->remove(m_series->slices().last()); | |
322 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
322 | QCOMPARE(m_series->count(), m_modelRowCount); | |
323 |
QCOMPARE(m_vMapper-> |
|
323 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
324 |
|
324 | |||
325 | QPieSlice *slice = m_series->slices().first(); |
|
325 | QPieSlice *slice = m_series->slices().first(); | |
326 | slice->setValue(25.0); |
|
326 | slice->setValue(25.0); | |
327 | slice->setLabel(QString("25.0")); |
|
327 | slice->setLabel(QString("25.0")); | |
328 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); |
|
328 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); | |
329 | QCOMPARE(m_model->data(m_model->index(0, 1)).toString(), QString("25.0")); |
|
329 | QCOMPARE(m_model->data(m_model->index(0, 1)).toString(), QString("25.0")); | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void tst_qpiemodelmapper::verticalModelInsertRows() |
|
332 | void tst_qpiemodelmapper::verticalModelInsertRows() | |
333 | { |
|
333 | { | |
334 | // setup the mapper |
|
334 | // setup the mapper | |
335 | createVerticalMapper(); |
|
335 | createVerticalMapper(); | |
336 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
336 | QCOMPARE(m_series->count(), m_modelRowCount); | |
337 | QVERIFY(m_vMapper->model() != 0); |
|
337 | QVERIFY(m_vMapper->model() != 0); | |
338 |
|
338 | |||
339 | int insertCount = 4; |
|
339 | int insertCount = 4; | |
340 | m_model->insertRows(3, insertCount); |
|
340 | m_model->insertRows(3, insertCount); | |
341 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount); |
|
341 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount); | |
342 |
|
342 | |||
343 | int first = 3; |
|
343 | int first = 3; | |
344 | m_vMapper->setFirst(3); |
|
344 | m_vMapper->setFirstRow(3); | |
345 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); |
|
345 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); | |
346 |
|
346 | |||
347 | m_model->insertRows(3, insertCount); |
|
347 | m_model->insertRows(3, insertCount); | |
348 | QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); |
|
348 | QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); | |
349 |
|
349 | |||
350 | int countLimit = 6; |
|
350 | int countLimit = 6; | |
351 | m_vMapper->setCount(countLimit); |
|
351 | m_vMapper->setRowCount(countLimit); | |
352 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
352 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); | |
353 |
|
353 | |||
354 | m_model->insertRows(3, insertCount); |
|
354 | m_model->insertRows(3, insertCount); | |
355 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
355 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); | |
356 |
|
356 | |||
357 | m_vMapper->setFirst(0); |
|
357 | m_vMapper->setFirstRow(0); | |
358 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
358 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); | |
359 |
|
359 | |||
360 | m_vMapper->setCount(-1); |
|
360 | m_vMapper->setRowCount(-1); | |
361 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); |
|
361 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void tst_qpiemodelmapper::verticalModelRemoveRows() |
|
364 | void tst_qpiemodelmapper::verticalModelRemoveRows() | |
365 | { |
|
365 | { | |
366 | // setup the mapper |
|
366 | // setup the mapper | |
367 | createVerticalMapper(); |
|
367 | createVerticalMapper(); | |
368 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
368 | QCOMPARE(m_series->count(), m_modelRowCount); | |
369 | QVERIFY(m_vMapper->model() != 0); |
|
369 | QVERIFY(m_vMapper->model() != 0); | |
370 |
|
370 | |||
371 | int removeCount = 2; |
|
371 | int removeCount = 2; | |
372 | m_model->removeRows(1, removeCount); |
|
372 | m_model->removeRows(1, removeCount); | |
373 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount); |
|
373 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount); | |
374 |
|
374 | |||
375 | int first = 1; |
|
375 | int first = 1; | |
376 | m_vMapper->setFirst(first); |
|
376 | m_vMapper->setFirstRow(first); | |
377 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); |
|
377 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); | |
378 |
|
378 | |||
379 | m_model->removeRows(1, removeCount); |
|
379 | m_model->removeRows(1, removeCount); | |
380 | QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); |
|
380 | QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); | |
381 |
|
381 | |||
382 | int countLimit = 3; |
|
382 | int countLimit = 3; | |
383 | m_vMapper->setCount(countLimit); |
|
383 | m_vMapper->setRowCount(countLimit); | |
384 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
384 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); | |
385 |
|
385 | |||
386 | m_model->removeRows(1, removeCount); |
|
386 | m_model->removeRows(1, removeCount); | |
387 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
387 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); | |
388 |
|
388 | |||
389 | m_vMapper->setFirst(0); |
|
389 | m_vMapper->setFirstRow(0); | |
390 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
390 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); | |
391 |
|
391 | |||
392 | m_vMapper->setCount(-1); |
|
392 | m_vMapper->setRowCount(-1); | |
393 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); |
|
393 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | void tst_qpiemodelmapper::verticalModelInsertColumns() |
|
396 | void tst_qpiemodelmapper::verticalModelInsertColumns() | |
397 | { |
|
397 | { | |
398 | // setup the mapper |
|
398 | // setup the mapper | |
399 | createVerticalMapper(); |
|
399 | createVerticalMapper(); | |
400 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
400 | QCOMPARE(m_series->count(), m_modelRowCount); | |
401 | QVERIFY(m_vMapper->model() != 0); |
|
401 | QVERIFY(m_vMapper->model() != 0); | |
402 |
|
402 | |||
403 | int insertCount = 4; |
|
403 | int insertCount = 4; | |
404 | m_model->insertColumns(3, insertCount); |
|
404 | m_model->insertColumns(3, insertCount); | |
405 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
405 | QCOMPARE(m_series->count(), m_modelRowCount); | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void tst_qpiemodelmapper::verticalModelRemoveColumns() |
|
408 | void tst_qpiemodelmapper::verticalModelRemoveColumns() | |
409 | { |
|
409 | { | |
410 | // setup the mapper |
|
410 | // setup the mapper | |
411 | createVerticalMapper(); |
|
411 | createVerticalMapper(); | |
412 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
412 | QCOMPARE(m_series->count(), m_modelRowCount); | |
413 | QVERIFY(m_vMapper->model() != 0); |
|
413 | QVERIFY(m_vMapper->model() != 0); | |
414 |
|
414 | |||
415 | int removeCount = m_modelColumnCount - 2; |
|
415 | int removeCount = m_modelColumnCount - 2; | |
416 | m_model->removeColumns(0, removeCount); |
|
416 | m_model->removeColumns(0, removeCount); | |
417 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
417 | QCOMPARE(m_series->count(), m_modelRowCount); | |
418 |
|
418 | |||
419 | // leave only one column |
|
419 | // leave only one column | |
420 | m_model->removeColumns(0, m_modelColumnCount - removeCount - 1); |
|
420 | m_model->removeColumns(0, m_modelColumnCount - removeCount - 1); | |
421 | QCOMPARE(m_series->count(), 0); |
|
421 | QCOMPARE(m_series->count(), 0); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | void tst_qpiemodelmapper::horizontalModelInsertRows() |
|
424 | void tst_qpiemodelmapper::horizontalModelInsertRows() | |
425 | { |
|
425 | { | |
426 | // setup the mapper |
|
426 | // setup the mapper | |
427 | createHorizontalMapper(); |
|
427 | createHorizontalMapper(); | |
428 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
428 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
429 | QVERIFY(m_hMapper->model() != 0); |
|
429 | QVERIFY(m_hMapper->model() != 0); | |
430 |
|
430 | |||
431 | int insertCount = 4; |
|
431 | int insertCount = 4; | |
432 | m_model->insertRows(3, insertCount); |
|
432 | m_model->insertRows(3, insertCount); | |
433 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
433 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | void tst_qpiemodelmapper::horizontalModelRemoveRows() |
|
436 | void tst_qpiemodelmapper::horizontalModelRemoveRows() | |
437 | { |
|
437 | { | |
438 | // setup the mapper |
|
438 | // setup the mapper | |
439 | createHorizontalMapper(); |
|
439 | createHorizontalMapper(); | |
440 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
440 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
441 | QVERIFY(m_hMapper->model() != 0); |
|
441 | QVERIFY(m_hMapper->model() != 0); | |
442 |
|
442 | |||
443 | int removeCount = m_modelRowCount - 2; |
|
443 | int removeCount = m_modelRowCount - 2; | |
444 | m_model->removeRows(0, removeCount); |
|
444 | m_model->removeRows(0, removeCount); | |
445 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
445 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
446 |
|
446 | |||
447 | // leave only one column |
|
447 | // leave only one column | |
448 | m_model->removeRows(0, m_modelRowCount - removeCount - 1); |
|
448 | m_model->removeRows(0, m_modelRowCount - removeCount - 1); | |
449 | QCOMPARE(m_series->count(), 0); |
|
449 | QCOMPARE(m_series->count(), 0); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | void tst_qpiemodelmapper::horizontalModelInsertColumns() |
|
452 | void tst_qpiemodelmapper::horizontalModelInsertColumns() | |
453 | { |
|
453 | { | |
454 | // setup the mapper |
|
454 | // setup the mapper | |
455 | createHorizontalMapper(); |
|
455 | createHorizontalMapper(); | |
456 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
456 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
457 | QVERIFY(m_hMapper->model() != 0); |
|
457 | QVERIFY(m_hMapper->model() != 0); | |
458 |
|
458 | |||
459 | int insertCount = 4; |
|
459 | int insertCount = 4; | |
460 | m_model->insertColumns(3, insertCount); |
|
460 | m_model->insertColumns(3, insertCount); | |
461 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); |
|
461 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); | |
462 |
|
462 | |||
463 | int first = 3; |
|
463 | int first = 3; | |
464 | m_hMapper->setFirst(3); |
|
464 | m_hMapper->setFirstColumn(3); | |
465 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); |
|
465 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); | |
466 |
|
466 | |||
467 | m_model->insertColumns(3, insertCount); |
|
467 | m_model->insertColumns(3, insertCount); | |
468 | QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); |
|
468 | QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); | |
469 |
|
469 | |||
470 | int countLimit = 6; |
|
470 | int countLimit = 6; | |
471 | m_hMapper->setCount(countLimit); |
|
471 | m_hMapper->setColumnCount(countLimit); | |
472 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
472 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); | |
473 |
|
473 | |||
474 | m_model->insertColumns(3, insertCount); |
|
474 | m_model->insertColumns(3, insertCount); | |
475 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
475 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); | |
476 |
|
476 | |||
477 | m_hMapper->setFirst(0); |
|
477 | m_hMapper->setFirstColumn(0); | |
478 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
478 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); | |
479 |
|
479 | |||
480 | m_hMapper->setCount(-1); |
|
480 | m_hMapper->setColumnCount(-1); | |
481 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); |
|
481 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); | |
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | void tst_qpiemodelmapper::horizontalModelRemoveColumns() |
|
484 | void tst_qpiemodelmapper::horizontalModelRemoveColumns() | |
485 | { |
|
485 | { | |
486 | // setup the mapper |
|
486 | // setup the mapper | |
487 | createHorizontalMapper(); |
|
487 | createHorizontalMapper(); | |
488 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
488 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
489 | QVERIFY(m_hMapper->model() != 0); |
|
489 | QVERIFY(m_hMapper->model() != 0); | |
490 |
|
490 | |||
491 | int removeCount = 2; |
|
491 | int removeCount = 2; | |
492 | m_model->removeColumns(1, removeCount); |
|
492 | m_model->removeColumns(1, removeCount); | |
493 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); |
|
493 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); | |
494 |
|
494 | |||
495 | int first = 1; |
|
495 | int first = 1; | |
496 | m_hMapper->setFirst(first); |
|
496 | m_hMapper->setFirstColumn(first); | |
497 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); |
|
497 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); | |
498 |
|
498 | |||
499 | m_model->removeColumns(1, removeCount); |
|
499 | m_model->removeColumns(1, removeCount); | |
500 | QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); |
|
500 | QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); | |
501 |
|
501 | |||
502 | int countLimit = 3; |
|
502 | int countLimit = 3; | |
503 | m_hMapper->setCount(countLimit); |
|
503 | m_hMapper->setColumnCount(countLimit); | |
504 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
504 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); | |
505 |
|
505 | |||
506 | m_model->removeColumns(1, removeCount); |
|
506 | m_model->removeColumns(1, removeCount); | |
507 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
507 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); | |
508 |
|
508 | |||
509 | m_hMapper->setFirst(0); |
|
509 | m_hMapper->setFirstColumn(0); | |
510 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
510 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); | |
511 |
|
511 | |||
512 | m_hMapper->setCount(-1); |
|
512 | m_hMapper->setColumnCount(-1); | |
513 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); |
|
513 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
516 | void tst_qpiemodelmapper::modelUpdateCell() |
|
516 | void tst_qpiemodelmapper::modelUpdateCell() | |
517 | { |
|
517 | { | |
518 | // setup the mapper |
|
518 | // setup the mapper | |
519 | createVerticalMapper(); |
|
519 | createVerticalMapper(); | |
520 |
|
520 | |||
521 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
521 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); | |
522 | QCOMPARE(m_series->slices().at(1)->value(), 44.0); |
|
522 | QCOMPARE(m_series->slices().at(1)->value(), 44.0); | |
523 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
523 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | QTEST_MAIN(tst_qpiemodelmapper) |
|
526 | QTEST_MAIN(tst_qpiemodelmapper) | |
527 |
|
527 | |||
528 | #include "tst_qpiemodelmapper.moc" |
|
528 | #include "tst_qpiemodelmapper.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now