##// END OF EJS Templates
Fixed problem with PieModelMapper
Marek Rosa -
r1320:42dbf474caea
parent child
Show More
@@ -1,127 +1,134
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 width: parent.width
26 width: parent.width
27 height: parent.height
27 height: parent.height
28
28
29 ChartView {
29 ChartView {
30 id: chart
30 id: chart
31 title: "Custom model example"
31 title: "Custom model example"
32 anchors.fill: parent
32 anchors.fill: parent
33 theme: ChartView.ChartThemeLight
33 theme: ChartView.ChartThemeLight
34 axisX.max: 10
34 axisX.max: 10
35 axisX.min: 0
35 axisX.min: 0
36 axisY.max: 20
36 axisY.max: 20
37 axisY.min: 0
37 axisY.min: 0
38
38
39 // For dynamic data we use a custom data model derived from QAbstractiItemModel
39 // For dynamic data we use a custom data model derived from QAbstractiItemModel
40 CustomModel {
40 CustomModel {
41 id: customModel
41 id: customModel
42 CustomModelElement { values: [0, "Manufacturer", 1, 2] }
42 CustomModelElement { values: [0, "Manufacturer", 1, 2] }
43 CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] }
43 CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] }
44 CustomModelElement { values: [2, "Toyota", 10.9, 9.9] }
44 CustomModelElement { values: [2, "Toyota", 10.9, 9.9] }
45 CustomModelElement { values: [3, "Ford", 8.6, 7.6] }
45 CustomModelElement { values: [3, "Ford", 8.6, 7.6] }
46 CustomModelElement { values: [4, "Skoda", 8.2, 7.2] }
46 CustomModelElement { values: [4, "Skoda", 8.2, 7.2] }
47 CustomModelElement { values: [5, "Volvo", 6.8, 5.8] }
47 CustomModelElement { values: [5, "Volvo", 6.8, 5.8] }
48 }
48 }
49
49
50 LineSeries {
50 LineSeries {
51 name: "Volkswagen"
51 name: "Volkswagen"
52 HXYModelMapper {
52 HXYModelMapper {
53 model: customModel
53 model: customModel
54 xRow: 0
54 xRow: 0
55 yRow: 1
55 yRow: 1
56 first: 2
56 first: 2
57 }
57 }
58 }
58 }
59
59
60 LineSeries {
60 LineSeries {
61 name: "Toyota"
61 name: "Toyota"
62 HXYModelMapper {
62 HXYModelMapper {
63 model: customModel
63 model: customModel
64 xRow: 0
64 xRow: 0
65 yRow: 2
65 yRow: 2
66 first: 2
66 first: 2
67 }
67 }
68 }
68 }
69
69
70 PieSeries {
70 PieSeries {
71 id: pieSeries
71 id: pieSeries
72 size: 0.4
72 size: 0.4
73 horizontalPosition: 0.7
73 horizontalPosition: 0.7
74 verticalPosition: 0.3
74 verticalPosition: 0.3
75 }
75 }
76
76
77 VPieModelMapper {
77 // VPieModelMapper {
78 // series: pieSeries
79 // model: customModel
80 // labelsColumn: 1
81 // valuesColumn: 2
82 // first: 1
83 // }
84 HPieModelMapper {
78 series: pieSeries
85 series: pieSeries
79 model: customModel
86 model: customModel
80 labelsColumn: 1
87 labelsRow: 1
81 valuesColumn: 2
88 valuesRow: 2
82 first: 1
89 first: 2
83 }
90 }
84
91
85 AreaSeries {
92 AreaSeries {
86 name: "Ford"
93 name: "Ford"
87 upperSeries: LineSeries {
94 upperSeries: LineSeries {
88 HXYModelMapper {
95 HXYModelMapper {
89 model: customModel
96 model: customModel
90 xRow: 0
97 xRow: 0
91 yRow: 3
98 yRow: 3
92 first: 2
99 first: 2
93 }
100 }
94 }
101 }
95 }
102 }
96
103
97 GroupedBarSeries {
104 GroupedBarSeries {
98 name: "Skoda and Volvo"
105 name: "Skoda and Volvo"
99 HBarModelMapper {
106 HBarModelMapper {
100 model: customModel
107 model: customModel
101 firstBarSetRow: 4
108 firstBarSetRow: 4
102 lastBarSetRow: 5
109 lastBarSetRow: 5
103 first: 2
110 first: 2
104 }
111 }
105 }
112 }
106 }
113 }
107
114
108
115
109 // TODO: you could also implement appending to your model, for example:
116 // TODO: you could also implement appending to your model, for example:
110 // pieSeries.model.append(["Others", 52.0]);
117 // pieSeries.model.append(["Others", 52.0]);
111
118
112 // TODO: show how to use data from a list model in a chart view
119 // TODO: show how to use data from a list model in a chart view
113 // i.e. copy the data into a custom model
120 // i.e. copy the data into a custom model
114 // ListModel {
121 // ListModel {
115 // id: listModel
122 // id: listModel
116 // ListElement {
123 // ListElement {
117 // label: "Volkswagen"
124 // label: "Volkswagen"
118 // value: 13.5
125 // value: 13.5
119 // }
126 // }
120 // ListElement {
127 // ListElement {
121 // label: "Toyota"
128 // label: "Toyota"
122 // value: 10.9
129 // value: 10.9
123 // }
130 // }
124 // // and so on...
131 // // and so on...
125 // }
132 // }
126
133
127 }
134 }
@@ -1,53 +1,53
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 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
25 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
26 QPieModelMapper(parent)
26 QPieModelMapper(parent)
27 {
27 {
28 QPieModelMapper::setOrientation(Qt::Horizontal);
28 QPieModelMapper::setOrientation(Qt::Horizontal);
29 }
29 }
30
30
31 int QHPieModelMapper::valuesRow() const
31 int QHPieModelMapper::valuesRow() const
32 {
32 {
33 return QPieModelMapper::valuesIndex();
33 return QPieModelMapper::valuesSection();
34 }
34 }
35
35
36 void QHPieModelMapper::setValuesRow(int valuesRow)
36 void QHPieModelMapper::setValuesRow(int valuesRow)
37 {
37 {
38 QPieModelMapper::setValuesIndex(valuesRow);
38 QPieModelMapper::setValuesSection(valuesRow);
39 }
39 }
40
40
41 int QHPieModelMapper::labelsRow() const
41 int QHPieModelMapper::labelsRow() const
42 {
42 {
43 return QPieModelMapper::labelsIndex();
43 return QPieModelMapper::labelsSection();
44 }
44 }
45
45
46 void QHPieModelMapper::setLabelsRow(int labelsRow)
46 void QHPieModelMapper::setLabelsRow(int labelsRow)
47 {
47 {
48 QPieModelMapper::setLabelsIndex(labelsRow);
48 QPieModelMapper::setLabelsSection(labelsRow);
49 }
49 }
50
50
51 #include "moc_qhpiemodelmapper.cpp"
51 #include "moc_qhpiemodelmapper.cpp"
52
52
53 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,521 +1,535
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 QPieModelMapper::QPieModelMapper(QObject *parent) :
29 QPieModelMapper::QPieModelMapper(QObject *parent) :
30 QObject(parent),
30 QObject(parent),
31 d_ptr(new QPieModelMapperPrivate(this))
31 d_ptr(new QPieModelMapperPrivate(this))
32 {
32 {
33 }
33 }
34
34
35 QPieModelMapper::~QPieModelMapper()
35 QPieModelMapper::~QPieModelMapper()
36 {
36 {
37 // Q_D(QPieModelMapper);
37 // Q_D(QPieModelMapper);
38 // disconnect(d->m_model, 0, d, 0);
38 // disconnect(d->m_model, 0, d, 0);
39 }
39 }
40
40
41 QAbstractItemModel* QPieModelMapper::model() const
41 QAbstractItemModel* QPieModelMapper::model() const
42 {
42 {
43 Q_D(const QPieModelMapper);
43 Q_D(const QPieModelMapper);
44 return d->m_model;
44 return d->m_model;
45 }
45 }
46
46
47 void QPieModelMapper::setModel(QAbstractItemModel *model)
47 void QPieModelMapper::setModel(QAbstractItemModel *model)
48 {
48 {
49 if (model == 0)
49 if (model == 0)
50 return;
50 return;
51
51
52 Q_D(QPieModelMapper);
52 Q_D(QPieModelMapper);
53 if (d->m_model) {
53 if (d->m_model) {
54 disconnect(d->m_model, 0, d, 0);
54 disconnect(d->m_model, 0, d, 0);
55 }
55 }
56
56
57 d->m_model = model;
57 d->m_model = model;
58 d->initializePieFromModel();
58 d->initializePieFromModel();
59 // connect signals from the model
59 // connect signals from the model
60 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
60 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
61 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
61 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
62 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
62 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
63 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
63 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
64 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
64 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
65 }
65 }
66
66
67 QPieSeries* QPieModelMapper::series() const
67 QPieSeries* QPieModelMapper::series() const
68 {
68 {
69 Q_D(const QPieModelMapper);
69 Q_D(const QPieModelMapper);
70 return d->m_series;
70 return d->m_series;
71 }
71 }
72
72
73 void QPieModelMapper::setSeries(QPieSeries *series)
73 void QPieModelMapper::setSeries(QPieSeries *series)
74 {
74 {
75 Q_D(QPieModelMapper);
75 Q_D(QPieModelMapper);
76 if (d->m_series) {
76 if (d->m_series) {
77 disconnect(d->m_series, 0, d, 0);
77 disconnect(d->m_series, 0, d, 0);
78 }
78 }
79
79
80 if (series == 0)
80 if (series == 0)
81 return;
81 return;
82
82
83 d->m_series = series;
83 d->m_series = series;
84 d->initializePieFromModel();
84 d->initializePieFromModel();
85 // connect the signals from the series
85 // connect the signals from the series
86 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
86 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
87 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
87 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
88 }
88 }
89
89
90 int QPieModelMapper::first() const
90 int QPieModelMapper::first() const
91 {
91 {
92 Q_D(const QPieModelMapper);
92 Q_D(const QPieModelMapper);
93 return d->m_first;
93 return d->m_first;
94 }
94 }
95
95
96 void QPieModelMapper::setFirst(int first)
96 void QPieModelMapper::setFirst(int first)
97 {
97 {
98 Q_D(QPieModelMapper);
98 Q_D(QPieModelMapper);
99 d->m_first = qMax(first, 0);
99 d->m_first = qMax(first, 0);
100 d->initializePieFromModel();
100 d->initializePieFromModel();
101 }
101 }
102
102
103 int QPieModelMapper::count() const
103 int QPieModelMapper::count() const
104 {
104 {
105 Q_D(const QPieModelMapper);
105 Q_D(const QPieModelMapper);
106 return d->m_count;
106 return d->m_count;
107 }
107 }
108
108
109 void QPieModelMapper::setCount(int count)
109 void QPieModelMapper::setCount(int count)
110 {
110 {
111 Q_D(QPieModelMapper);
111 Q_D(QPieModelMapper);
112 d->m_count = qMax(count, -1);
112 d->m_count = qMax(count, -1);
113 d->initializePieFromModel();
113 d->initializePieFromModel();
114 }
114 }
115
115
116 Qt::Orientation QPieModelMapper::orientation() const
116 Qt::Orientation QPieModelMapper::orientation() const
117 {
117 {
118 Q_D(const QPieModelMapper);
118 Q_D(const QPieModelMapper);
119 return d->m_orientation;
119 return d->m_orientation;
120 }
120 }
121
121
122 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
122 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
123 {
123 {
124 Q_D(QPieModelMapper);
124 Q_D(QPieModelMapper);
125 d->m_orientation = orientation;
125 d->m_orientation = orientation;
126 d->initializePieFromModel();
126 d->initializePieFromModel();
127 }
127 }
128
128
129 int QPieModelMapper::valuesIndex() const
129 int QPieModelMapper::valuesSection() const
130 {
130 {
131 Q_D(const QPieModelMapper);
131 Q_D(const QPieModelMapper);
132 return d->m_valuesIndex;
132 return d->m_valuesSection;
133 }
133 }
134
134
135 void QPieModelMapper::setValuesIndex(int valuesIndex)
135 void QPieModelMapper::setValuesSection(int valuesSection)
136 {
136 {
137 Q_D(QPieModelMapper);
137 Q_D(QPieModelMapper);
138 d->m_valuesIndex = qMax(-1, valuesIndex);
138 d->m_valuesSection = qMax(-1, valuesSection);
139 d->initializePieFromModel();
139 d->initializePieFromModel();
140 }
140 }
141
141
142 int QPieModelMapper::labelsIndex() const
142 int QPieModelMapper::labelsSection() const
143 {
143 {
144 Q_D(const QPieModelMapper);
144 Q_D(const QPieModelMapper);
145 return d->m_labelsIndex;
145 return d->m_labelsSection;
146 }
146 }
147
147
148 void QPieModelMapper::setLabelsIndex(int labelsIndex)
148 void QPieModelMapper::setLabelsSection(int labelsSection)
149 {
149 {
150 Q_D(QPieModelMapper);
150 Q_D(QPieModelMapper);
151 d->m_labelsIndex = qMax(-1, labelsIndex);
151 d->m_labelsSection = qMax(-1, labelsSection);
152 d->initializePieFromModel();
152 d->initializePieFromModel();
153 }
153 }
154
154
155 void QPieModelMapper::reset()
155 void QPieModelMapper::reset()
156 {
156 {
157 Q_D(QPieModelMapper);
157 Q_D(QPieModelMapper);
158 d->m_first = 0;
158 d->m_first = 0;
159 d->m_count = -1;
159 d->m_count = -1;
160 d->m_orientation = Qt::Vertical;
160 d->m_orientation = Qt::Vertical;
161 d->m_valuesIndex = -1;
161 d->m_valuesSection = -1;
162 d->m_labelsIndex = -1;
162 d->m_labelsSection = -1;
163 }
163 }
164
164
165 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
165 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
166
166
167 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
167 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
168 m_series(0),
168 m_series(0),
169 m_model(0),
169 m_model(0),
170 m_first(0),
170 m_first(0),
171 m_count(-1),
171 m_count(-1),
172 m_orientation(Qt::Vertical),
172 m_orientation(Qt::Vertical),
173 m_valuesIndex(-1),
173 m_valuesSection(-1),
174 m_labelsIndex(-1),
174 m_labelsSection(-1),
175 m_seriesSignalsBlock(false),
175 m_seriesSignalsBlock(false),
176 m_modelSignalsBlock(false),
176 m_modelSignalsBlock(false),
177 q_ptr(q)
177 q_ptr(q)
178 {
178 {
179 }
179 }
180
180
181 void QPieModelMapperPrivate::blockModelSignals(bool block)
181 void QPieModelMapperPrivate::blockModelSignals(bool block)
182 {
182 {
183 m_modelSignalsBlock = block;
183 m_modelSignalsBlock = block;
184 }
184 }
185
185
186 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
186 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
187 {
187 {
188 m_seriesSignalsBlock = block;
188 m_seriesSignalsBlock = block;
189 }
189 }
190
190
191
191
192 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
192 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
193 {
193 {
194 if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) {
194 if (!index.isValid())
195 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
195 return 0; // index is invalid
196 return m_series->slices().at(index.row() - m_first);
196
197 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) {
197 if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
198 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
198 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
199 return m_series->slices().at(index.column() - m_first);
199 if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
200 return m_series->slices().at(index.row() - m_first);
201 else
202 return 0;
203 }
204 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
205 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
206 if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
207 return m_series->slices().at(index.column() - m_first);
208 else
209 return 0;
210 }
200 }
211 }
201 return 0; // This part of model has not been mapped to any slice
212 return 0; // This part of model has not been mapped to any slice
202 }
213 }
203
214
204 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
215 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
205 {
216 {
206 if (m_count != -1 && slicePos >= m_count)
217 if (m_count != -1 && slicePos >= m_count)
207 return QModelIndex(); // invalid
218 return QModelIndex(); // invalid
208
219
209 if (m_orientation == Qt::Vertical)
220 if (m_orientation == Qt::Vertical)
210 return m_model->index(slicePos + m_first, m_valuesIndex);
221 return m_model->index(slicePos + m_first, m_valuesSection);
211 else
222 else
212 return m_model->index(m_valuesIndex, slicePos + m_first);
223 return m_model->index(m_valuesSection, slicePos + m_first);
213 }
224 }
214
225
215 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
226 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
216 {
227 {
217 if (m_count != -1 && slicePos >= m_count)
228 if (m_count != -1 && slicePos >= m_count)
218 return QModelIndex(); // invalid
229 return QModelIndex(); // invalid
219
230
220 if (m_orientation == Qt::Vertical)
231 if (m_orientation == Qt::Vertical)
221 return m_model->index(slicePos + m_first, m_labelsIndex);
232 return m_model->index(slicePos + m_first, m_labelsSection);
222 else
233 else
223 return m_model->index(m_labelsIndex, slicePos + m_first);
234 return m_model->index(m_labelsSection, slicePos + m_first);
224 }
235 }
225
236
226 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
237 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
227 {
238 {
228 if (m_orientation == Qt::Vertical && index.column() == m_labelsIndex)
239 if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
229 return true;
240 return true;
230 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsIndex)
241 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
231 return true;
242 return true;
232
243
233 return false;
244 return false;
234 }
245 }
235
246
236 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
247 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
237 {
248 {
238 if (m_orientation == Qt::Vertical && index.column() == m_valuesIndex)
249 if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
239 return true;
250 return true;
240 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesIndex)
251 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
241 return true;
252 return true;
242
253
243 return false;
254 return false;
244 }
255 }
245
256
246 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
257 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
247 {
258 {
248 if (m_seriesSignalsBlock)
259 if (m_seriesSignalsBlock)
249 return;
260 return;
250
261
251 if (slices.count() == 0)
262 if (slices.count() == 0)
252 return;
263 return;
253
264
254 int firstIndex = m_series->slices().indexOf(slices.at(0));
265 int firstIndex = m_series->slices().indexOf(slices.at(0));
255 if (firstIndex == -1)
266 if (firstIndex == -1)
256 return;
267 return;
257
268
258 if (m_count != -1)
269 if (m_count != -1)
259 m_count += slices.count();
270 m_count += slices.count();
260
271
261 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
272 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
262 m_slices.insert(i, slices.at(i - firstIndex));
273 m_slices.insert(i, slices.at(i - firstIndex));
263 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
274 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
264 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
275 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
265 }
276 }
266
277
267 blockModelSignals();
278 blockModelSignals();
268 if (m_orientation == Qt::Vertical)
279 if (m_orientation == Qt::Vertical)
269 m_model->insertRows(firstIndex + m_first, slices.count());
280 m_model->insertRows(firstIndex + m_first, slices.count());
270 else
281 else
271 m_model->insertColumns(firstIndex + m_first, slices.count());
282 m_model->insertColumns(firstIndex + m_first, slices.count());
272
283
273 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
284 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
274 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
285 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
275 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
286 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
276 }
287 }
277 blockModelSignals(false);
288 blockModelSignals(false);
278 }
289 }
279
290
280 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
291 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
281 {
292 {
282 if (m_seriesSignalsBlock)
293 if (m_seriesSignalsBlock)
283 return;
294 return;
284
295
285 if (slices.count() == 0)
296 if (slices.count() == 0)
286 return;
297 return;
287
298
288 int firstIndex = m_slices.indexOf(slices.at(0));
299 int firstIndex = m_slices.indexOf(slices.at(0));
289 if (firstIndex == -1)
300 if (firstIndex == -1)
290 return;
301 return;
291
302
292 if (m_count != -1)
303 if (m_count != -1)
293 m_count -= slices.count();
304 m_count -= slices.count();
294
305
295 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
306 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
296 m_slices.removeAt(i);
307 m_slices.removeAt(i);
297
308
298 blockModelSignals();
309 blockModelSignals();
299 if (m_orientation == Qt::Vertical)
310 if (m_orientation == Qt::Vertical)
300 m_model->removeRows(firstIndex + m_first, slices.count());
311 m_model->removeRows(firstIndex + m_first, slices.count());
301 else
312 else
302 m_model->removeColumns(firstIndex + m_first, slices.count());
313 m_model->removeColumns(firstIndex + m_first, slices.count());
303 blockModelSignals(false);
314 blockModelSignals(false);
304 }
315 }
305
316
306 void QPieModelMapperPrivate::sliceLabelChanged()
317 void QPieModelMapperPrivate::sliceLabelChanged()
307 {
318 {
308 if (m_seriesSignalsBlock)
319 if (m_seriesSignalsBlock)
309 return;
320 return;
310
321
311 blockModelSignals();
322 blockModelSignals();
312 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
323 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
313 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
324 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
314 blockModelSignals(false);
325 blockModelSignals(false);
315 }
326 }
316
327
317 void QPieModelMapperPrivate::sliceValueChanged()
328 void QPieModelMapperPrivate::sliceValueChanged()
318 {
329 {
319 if (m_seriesSignalsBlock)
330 if (m_seriesSignalsBlock)
320 return;
331 return;
321
332
322 blockModelSignals();
333 blockModelSignals();
323 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
334 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
324 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
335 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
325 blockModelSignals(false);
336 blockModelSignals(false);
326 }
337 }
327
338
328 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
339 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
329 {
340 {
330 if (m_model == 0 || m_series == 0)
341 if (m_model == 0 || m_series == 0)
331 return;
342 return;
332
343
333 if (m_modelSignalsBlock)
344 if (m_modelSignalsBlock)
334 return;
345 return;
335
346
336 blockSeriesSignals();
347 blockSeriesSignals();
337 QModelIndex index;
348 QModelIndex index;
338 QPieSlice *slice;
349 QPieSlice *slice;
339 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
350 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
340 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
351 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
341 index = topLeft.sibling(row, column);
352 index = topLeft.sibling(row, column);
342 slice = pieSlice(index);
353 slice = pieSlice(index);
343 if (slice) {
354 if (slice) {
344 if (isValueIndex(index))
355 if (isValueIndex(index))
345 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
356 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
346 if (isLabelIndex(index))
357 if (isLabelIndex(index))
347 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
358 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
348 }
359 }
349 }
360 }
350 }
361 }
351 blockSeriesSignals(false);
362 blockSeriesSignals(false);
352 }
363 }
353
364
354
365
355 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
366 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
356 {
367 {
357 Q_UNUSED(parent);
368 Q_UNUSED(parent);
358 if (m_modelSignalsBlock)
369 if (m_modelSignalsBlock)
359 return;
370 return;
360
371
361 blockSeriesSignals();
372 blockSeriesSignals();
362 if (m_orientation == Qt::Vertical)
373 if (m_orientation == Qt::Vertical)
363 insertData(start, end);
374 insertData(start, end);
364 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
375 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
365 initializePieFromModel();
376 initializePieFromModel();
366 blockSeriesSignals(false);
377 blockSeriesSignals(false);
367 }
378 }
368
379
369 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
380 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
370 {
381 {
371 Q_UNUSED(parent);
382 Q_UNUSED(parent);
372 if (m_modelSignalsBlock)
383 if (m_modelSignalsBlock)
373 return;
384 return;
374
385
375 blockSeriesSignals();
386 blockSeriesSignals();
376 if (m_orientation == Qt::Vertical)
387 if (m_orientation == Qt::Vertical)
377 removeData(start, end);
388 removeData(start, end);
378 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
389 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
379 initializePieFromModel();
390 initializePieFromModel();
380 blockSeriesSignals(false);
391 blockSeriesSignals(false);
381 }
392 }
382
393
383 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
394 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
384 {
395 {
385 Q_UNUSED(parent);
396 Q_UNUSED(parent);
386 if (m_modelSignalsBlock)
397 if (m_modelSignalsBlock)
387 return;
398 return;
388
399
389 blockSeriesSignals();
400 blockSeriesSignals();
390 if (m_orientation == Qt::Horizontal)
401 if (m_orientation == Qt::Horizontal)
391 insertData(start, end);
402 insertData(start, end);
392 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
403 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
393 initializePieFromModel();
404 initializePieFromModel();
394 blockSeriesSignals(false);
405 blockSeriesSignals(false);
395 }
406 }
396
407
397 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
408 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
398 {
409 {
399 Q_UNUSED(parent);
410 Q_UNUSED(parent);
400 if (m_modelSignalsBlock)
411 if (m_modelSignalsBlock)
401 return;
412 return;
402
413
403 blockSeriesSignals();
414 blockSeriesSignals();
404 if (m_orientation == Qt::Horizontal)
415 if (m_orientation == Qt::Horizontal)
405 removeData(start, end);
416 removeData(start, end);
406 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
417 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
407 initializePieFromModel();
418 initializePieFromModel();
408 blockSeriesSignals(false);
419 blockSeriesSignals(false);
409 }
420 }
410
421
411 void QPieModelMapperPrivate::insertData(int start, int end)
422 void QPieModelMapperPrivate::insertData(int start, int end)
412 {
423 {
413 if (m_model == 0 || m_series == 0)
424 if (m_model == 0 || m_series == 0)
414 return;
425 return;
415
426
416 if (m_count != -1 && start >= m_first + m_count) {
427 if (m_count != -1 && start >= m_first + m_count) {
417 return;
428 return;
418 } else {
429 } else {
419 int addedCount = end - start + 1;
430 int addedCount = end - start + 1;
420 if (m_count != -1 && addedCount > m_count)
431 if (m_count != -1 && addedCount > m_count)
421 addedCount = m_count;
432 addedCount = m_count;
422 int first = qMax(start, m_first);
433 int first = qMax(start, m_first);
423 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
434 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
424 for (int i = first; i <= last; i++) {
435 for (int i = first; i <= last; i++) {
425 QPieSlice *slice = new QPieSlice;
436 QModelIndex valueIndex = valueModelIndex(i - m_first);
426 slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble());
437 QModelIndex labelIndex = labelModelIndex(i - m_first);
427 slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString());
438 if (valueIndex.isValid() && labelIndex.isValid()) {
428 slice->setLabelVisible();
439 QPieSlice *slice = new QPieSlice;
429 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
440 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
430 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
441 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
431 m_series->insert(i - m_first, slice);
442 slice->setLabelVisible();
432 m_slices.insert(i - m_first, slice);
443 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
444 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
445 m_series->insert(i - m_first, slice);
446 m_slices.insert(i - m_first, slice);
447 }
433 }
448 }
434
449
435 // remove excess of slices (abouve m_count)
450 // remove excess of slices (abouve m_count)
436 if (m_count != -1 && m_series->slices().size() > m_count)
451 if (m_count != -1 && m_series->slices().size() > m_count)
437 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
452 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
438 m_series->remove(m_series->slices().at(i));
453 m_series->remove(m_series->slices().at(i));
439 m_slices.removeAt(i);
454 m_slices.removeAt(i);
440 }
455 }
441 }
456 }
442 }
457 }
443
458
444 void QPieModelMapperPrivate::removeData(int start, int end)
459 void QPieModelMapperPrivate::removeData(int start, int end)
445 {
460 {
446 if (m_model == 0 || m_series == 0)
461 if (m_model == 0 || m_series == 0)
447 return;
462 return;
448
463
449 int removedCount = end - start + 1;
464 int removedCount = end - start + 1;
450 if (m_count != -1 && start >= m_first + m_count) {
465 if (m_count != -1 && start >= m_first + m_count) {
451 return;
466 return;
452 } else {
467 } else {
453 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
468 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
454 int first = qMax(start, m_first); // get the index of the first item that will be removed.
469 int first = qMax(start, m_first); // get the index of the first item that will be removed.
455 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
470 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
456 for (int i = last; i >= first; i--) {
471 for (int i = last; i >= first; i--) {
457 m_series->remove(m_series->slices().at(i - m_first));
472 m_series->remove(m_series->slices().at(i - m_first));
458 m_slices.removeAt(i - m_first);
473 m_slices.removeAt(i - m_first);
459 }
474 }
460
475
461 if (m_count != -1) {
476 if (m_count != -1) {
462 int itemsAvailable; // check how many are available to be added
477 int itemsAvailable; // check how many are available to be added
463 if (m_orientation == Qt::Vertical)
478 if (m_orientation == Qt::Vertical)
464 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
479 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
465 else
480 else
466 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
481 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
467 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
482 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
468 int currentSize = m_series->slices().size();
483 int currentSize = m_series->slices().size();
469 if (toBeAdded > 0)
484 if (toBeAdded > 0)
470 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
485 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
471 QPieSlice *slice = new QPieSlice;
486 QModelIndex valueIndex = valueModelIndex(i - m_first);
472 if (m_orientation == Qt::Vertical) {
487 QModelIndex labelIndex = labelModelIndex(i - m_first);
473 slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble());
488 if (valueIndex.isValid() && labelIndex.isValid()) {
474 slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString());
489 QPieSlice *slice = new QPieSlice;
475 } else {
490 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
476 slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble());
491 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
477 slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString());
492 slice->setLabelVisible();
493 m_series->insert(i, slice);
494 m_slices.insert(i, slice);
478 }
495 }
479 slice->setLabelVisible();
480 m_series->insert(i, slice);
481 m_slices.insert(i, slice);
482 }
496 }
483 }
497 }
484 }
498 }
485 }
499 }
486
500
487 void QPieModelMapperPrivate::initializePieFromModel()
501 void QPieModelMapperPrivate::initializePieFromModel()
488 {
502 {
489 if (m_model == 0 || m_series == 0)
503 if (m_model == 0 || m_series == 0)
490 return;
504 return;
491
505
492 blockSeriesSignals();
506 blockSeriesSignals();
493 // clear current content
507 // clear current content
494 m_series->clear();
508 m_series->clear();
495 m_slices.clear();
509 m_slices.clear();
496
510
497 // create the initial slices set
511 // create the initial slices set
498 int slicePos = 0;
512 int slicePos = 0;
499 QModelIndex valueIndex = valueModelIndex(slicePos);
513 QModelIndex valueIndex = valueModelIndex(slicePos);
500 QModelIndex labelIndex = labelModelIndex(slicePos);
514 QModelIndex labelIndex = labelModelIndex(slicePos);
501 while (valueIndex.isValid() && labelIndex.isValid()) {
515 while (valueIndex.isValid() && labelIndex.isValid()) {
502 QPieSlice *slice = new QPieSlice;
516 QPieSlice *slice = new QPieSlice;
503 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
517 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
504 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
518 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
505 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
519 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
506 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
520 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
507 m_series->append(slice);
521 m_series->append(slice);
508 m_slices.append(slice);
522 m_slices.append(slice);
509 // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble());
523 // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble());
510 slicePos++;
524 slicePos++;
511 valueIndex = valueModelIndex(slicePos);
525 valueIndex = valueModelIndex(slicePos);
512 labelIndex = labelModelIndex(slicePos);
526 labelIndex = labelModelIndex(slicePos);
513 }
527 }
514 m_series->setLabelsVisible(true);
528 m_series->setLabelsVisible(true);
515 blockSeriesSignals(false);
529 blockSeriesSignals(false);
516 }
530 }
517
531
518 #include "moc_qpiemodelmapper_p.cpp"
532 #include "moc_qpiemodelmapper_p.cpp"
519 #include "moc_qpiemodelmapper.cpp"
533 #include "moc_qpiemodelmapper.cpp"
520
534
521 QTCOMMERCIALCHART_END_NAMESPACE
535 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,79 +1,79
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)
37 Q_PROPERTY(QPieSeries *series READ series WRITE setSeries)
38 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
38 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
39 Q_PROPERTY(int first READ first WRITE setFirst)
39 Q_PROPERTY(int first READ first WRITE setFirst)
40 Q_PROPERTY(int count READ count WRITE setCount)
40 Q_PROPERTY(int count READ count WRITE setCount)
41 Q_ENUMS(Qt::Orientation)
41 Q_ENUMS(Qt::Orientation)
42
42
43 protected:
43 protected:
44 QPieModelMapper(QObject *parent = 0);
44 QPieModelMapper(QObject *parent = 0);
45 ~QPieModelMapper();
45 ~QPieModelMapper();
46
46
47 public:
47 public:
48 QAbstractItemModel* model() const;
48 QAbstractItemModel* model() const;
49 void setModel(QAbstractItemModel *model);
49 void setModel(QAbstractItemModel *model);
50
50
51 QPieSeries* series() const;
51 QPieSeries* series() const;
52 void setSeries(QPieSeries *series);
52 void setSeries(QPieSeries *series);
53
53
54 int first() const;
54 int first() const;
55 void setFirst(int first);
55 void setFirst(int first);
56
56
57 int count() const;
57 int count() const;
58 void setCount(int count);
58 void setCount(int count);
59
59
60 void reset();
60 void reset();
61
61
62 protected:
62 protected:
63 int valuesIndex() const;
63 int valuesSection() const;
64 void setValuesIndex(int valuesIndex);
64 void setValuesSection(int valuesSection);
65
65
66 int labelsIndex() const;
66 int labelsSection() const;
67 void setLabelsIndex(int labelsIndex);
67 void setLabelsSection(int labelsSection);
68
68
69 Qt::Orientation orientation() const;
69 Qt::Orientation orientation() const;
70 void setOrientation(Qt::Orientation orientation);
70 void setOrientation(Qt::Orientation orientation);
71
71
72 protected:
72 protected:
73 QPieModelMapperPrivate * const d_ptr;
73 QPieModelMapperPrivate * const d_ptr;
74 Q_DECLARE_PRIVATE(QPieModelMapper)
74 Q_DECLARE_PRIVATE(QPieModelMapper)
75 };
75 };
76
76
77 QTCOMMERCIALCHART_END_NAMESPACE
77 QTCOMMERCIALCHART_END_NAMESPACE
78
78
79 #endif // QPIEMODELMAPPER_H
79 #endif // QPIEMODELMAPPER_H
@@ -1,101 +1,101
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPIEMODELMAPPER_P_H
30 #ifndef QPIEMODELMAPPER_P_H
31 #define QPIEMODELMAPPER_P_H
31 #define QPIEMODELMAPPER_P_H
32
32
33 #include "qpiemodelmapper.h"
33 #include "qpiemodelmapper.h"
34 #include <QObject>
34 #include <QObject>
35
35
36 class QModelIndex;
36 class QModelIndex;
37 class QAbstractItemModel;
37 class QAbstractItemModel;
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QPieModelMapper;
41 class QPieModelMapper;
42 class QPieSeries;
42 class QPieSeries;
43 class QPieSlice;
43 class QPieSlice;
44
44
45 class QPieModelMapperPrivate : public QObject
45 class QPieModelMapperPrivate : public QObject
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48
48
49 public:
49 public:
50 QPieModelMapperPrivate(QPieModelMapper *q);
50 QPieModelMapperPrivate(QPieModelMapper *q);
51
51
52 public Q_SLOTS:
52 public Q_SLOTS:
53 // for the model
53 // for the model
54 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
54 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
55 void modelRowsAdded(QModelIndex parent, int start, int end);
55 void modelRowsAdded(QModelIndex parent, int start, int end);
56 void modelRowsRemoved(QModelIndex parent, int start, int end);
56 void modelRowsRemoved(QModelIndex parent, int start, int end);
57 void modelColumnsAdded(QModelIndex parent, int start, int end);
57 void modelColumnsAdded(QModelIndex parent, int start, int end);
58 void modelColumnsRemoved(QModelIndex parent, int start, int end);
58 void modelColumnsRemoved(QModelIndex parent, int start, int end);
59
59
60 // for the series
60 // for the series
61 void slicesAdded(QList<QPieSlice*> slices);
61 void slicesAdded(QList<QPieSlice*> slices);
62 void slicesRemoved(QList<QPieSlice*> slices);
62 void slicesRemoved(QList<QPieSlice*> slices);
63 void sliceLabelChanged();
63 void sliceLabelChanged();
64 void sliceValueChanged();
64 void sliceValueChanged();
65
65
66 void initializePieFromModel();
66 void initializePieFromModel();
67
67
68 private:
68 private:
69 QPieSlice* pieSlice(QModelIndex index) const;
69 QPieSlice* pieSlice(QModelIndex index) const;
70 bool isLabelIndex(QModelIndex index) const;
70 bool isLabelIndex(QModelIndex index) const;
71 bool isValueIndex(QModelIndex index) const;
71 bool isValueIndex(QModelIndex index) const;
72 QModelIndex valueModelIndex(int slicePos);
72 QModelIndex valueModelIndex(int slicePos);
73 QModelIndex labelModelIndex(int slicePos);
73 QModelIndex labelModelIndex(int slicePos);
74 void insertData(int start, int end);
74 void insertData(int start, int end);
75 void removeData(int start, int end);
75 void removeData(int start, int end);
76
76
77 void blockModelSignals(bool block = true);
77 void blockModelSignals(bool block = true);
78 void blockSeriesSignals(bool block = true);
78 void blockSeriesSignals(bool block = true);
79
79
80 private:
80 private:
81 QPieSeries *m_series;
81 QPieSeries *m_series;
82 QList<QPieSlice*> m_slices;
82 QList<QPieSlice*> m_slices;
83 QAbstractItemModel *m_model;
83 QAbstractItemModel *m_model;
84 int m_first;
84 int m_first;
85 int m_count;
85 int m_count;
86 Qt::Orientation m_orientation;
86 Qt::Orientation m_orientation;
87 int m_valuesIndex;
87 int m_valuesSection;
88 int m_labelsIndex;
88 int m_labelsSection;
89 bool m_seriesSignalsBlock;
89 bool m_seriesSignalsBlock;
90 bool m_modelSignalsBlock;
90 bool m_modelSignalsBlock;
91
91
92 private:
92 private:
93
93
94 QPieModelMapper *q_ptr;
94 QPieModelMapper *q_ptr;
95 Q_DECLARE_PUBLIC(QPieModelMapper)
95 Q_DECLARE_PUBLIC(QPieModelMapper)
96 friend class QPieSeriesPrivate;
96 friend class QPieSeriesPrivate;
97 };
97 };
98
98
99 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
100
100
101 #endif // QPIEMODELMAPPER_P_H
101 #endif // QPIEMODELMAPPER_P_H
@@ -1,54 +1,54
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 "qvpiemodelmapper.h"
22 #include "qvpiemodelmapper.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
26 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
27 QPieModelMapper(parent)
27 QPieModelMapper(parent)
28 {
28 {
29 QPieModelMapper::setOrientation(Qt::Vertical);
29 QPieModelMapper::setOrientation(Qt::Vertical);
30 }
30 }
31
31
32 int QVPieModelMapper::valuesColumn() const
32 int QVPieModelMapper::valuesColumn() const
33 {
33 {
34 return QPieModelMapper::valuesIndex();
34 return QPieModelMapper::valuesSection();
35 }
35 }
36
36
37 void QVPieModelMapper::setValuesColumn(int valuesColumn)
37 void QVPieModelMapper::setValuesColumn(int valuesColumn)
38 {
38 {
39 QPieModelMapper::setValuesIndex(valuesColumn);
39 QPieModelMapper::setValuesSection(valuesColumn);
40 }
40 }
41
41
42 int QVPieModelMapper::labelsColumn() const
42 int QVPieModelMapper::labelsColumn() const
43 {
43 {
44 return QPieModelMapper::labelsIndex();
44 return QPieModelMapper::labelsSection();
45 }
45 }
46
46
47 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
47 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
48 {
48 {
49 QPieModelMapper::setLabelsIndex(labelsColumn);
49 QPieModelMapper::setLabelsSection(labelsColumn);
50 }
50 }
51
51
52 #include "moc_qvpiemodelmapper.cpp"
52 #include "moc_qvpiemodelmapper.cpp"
53
53
54 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now