@@ -1,735 +1,735 | |||||
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 "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 | #include "qvaluesaxis.h" |
|
30 | #include "qvaluesaxis.h" | |
31 | #include "qcategoriesaxis.h" |
|
31 | #include "qcategoriesaxis.h" | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QAbstractBarSeries |
|
36 | \class QAbstractBarSeries | |
37 | \brief Series for creating a bar chart |
|
37 | \brief Series for creating a bar chart | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
43 | shows the x-values. |
|
43 | shows the x-values. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 | /*! |
|
50 | /*! | |
51 | \qmlclass BarSeries QAbstractBarSeries |
|
51 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
52 | \inherits QAbstractSeries |
|
52 | \inherits QAbstractSeries | |
53 |
|
53 | |||
54 | The following QML shows how to create a simple bar chart: |
|
54 | The following QML shows how to create a simple bar chart: | |
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
56 |
|
56 | |||
57 | \beginfloatleft |
|
57 | \beginfloatleft | |
58 | \image demos_qmlchart6.png |
|
58 | \image demos_qmlchart6.png | |
59 | \endfloat |
|
59 | \endfloat | |
60 | \clearfloat |
|
60 | \clearfloat | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QAbstractBarSeries::barWidth |
|
64 | \property QAbstractBarSeries::barWidth | |
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
69 | \sa QGroupedBarSeries |
|
69 | \sa QGroupedBarSeries | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty real BarSeries::barWidth |
|
72 | \qmlproperty real AbstractBarSeries::barWidth | |
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QAbstractBarSeries::count |
|
80 | \property QAbstractBarSeries::count | |
81 | Holds the number of sets in series. |
|
81 | Holds the number of sets in series. | |
82 | */ |
|
82 | */ | |
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty int BarSeries::count |
|
84 | \qmlproperty int AbstractBarSeries::count | |
85 | Holds the number of sets in series. |
|
85 | Holds the number of sets in series. | |
86 | */ |
|
86 | */ | |
87 |
|
87 | |||
88 | /*! |
|
88 | /*! | |
89 | \property QAbstractBarSeries::labelsVisible |
|
89 | \property QAbstractBarSeries::labelsVisible | |
90 | Defines the visibility of the labels in series |
|
90 | Defines the visibility of the labels in series | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty bool BarSeries::labelsVisible |
|
93 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
94 | Defines the visibility of the labels in series |
|
94 | Defines the visibility of the labels in series | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
100 | Clicked bar inside set is indexed by \a index |
|
100 | Clicked bar inside set is indexed by \a index | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) |
|
103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
105 | Clicked bar inside set is indexed by \a index |
|
105 | Clicked bar inside set is indexed by \a index | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
110 |
|
110 | |||
111 | The signal is emitted if mouse is hovered on top of series. |
|
111 | The signal is emitted if mouse is hovered on top of series. | |
112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | Parameter \a barset is the pointer of barset, where hover happened. | |
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) |
|
116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
117 |
|
117 | |||
118 | The signal is emitted if mouse is hovered on top of series. |
|
118 | The signal is emitted if mouse is hovered on top of series. | |
119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | Parameter \a barset is the pointer of barset, where hover happened. | |
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QAbstractBarSeries::countChanged() |
|
124 | \fn void QAbstractBarSeries::countChanged() | |
125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | This signal is emitted when barset count has been changed, for example by append or remove. | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlsignal BarSeries::onCountChanged() |
|
128 | \qmlsignal AbstractBarSeries::onCountChanged() | |
129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | This signal is emitted when barset count has been changed, for example by append or remove. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
134 | This signal is emitted when labels visibility have changed. |
|
134 | This signal is emitted when labels visibility have changed. | |
135 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | \sa isLabelsVisible(), setLabelsVisible() | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
140 | This signal is emitted when \a sets have been added to the series. |
|
140 | This signal is emitted when \a sets have been added to the series. | |
141 | \sa append(), insert() |
|
141 | \sa append(), insert() | |
142 | */ |
|
142 | */ | |
143 | /*! |
|
143 | /*! | |
144 | \qmlsignal BarSeries::onAdded(BarSet barset) |
|
144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
145 | Emitted when \a barset has been added to the series. |
|
145 | Emitted when \a barset has been added to the series. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
150 | This signal is emitted when \a sets have been removed from the series. |
|
150 | This signal is emitted when \a sets have been removed from the series. | |
151 | \sa remove() |
|
151 | \sa remove() | |
152 | */ |
|
152 | */ | |
153 | /*! |
|
153 | /*! | |
154 | \qmlsignal BarSeries::onRemoved(BarSet barset) |
|
154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
155 | Emitted when \a barset has been removed from the series. |
|
155 | Emitted when \a barset has been removed from the series. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \qmlmethod BarSet BarSeries::at(int index) |
|
159 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
160 | Returns bar set at \a index. Returns null if the index is not valid. | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) |
|
164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
166 | For example: |
|
166 | For example: | |
167 | \code |
|
167 | \code | |
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
170 | \endcode |
|
170 | \endcode | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) |
|
174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
177 | appended. |
|
177 | appended. | |
178 | \sa BarSeries::append() |
|
178 | \sa AbstractBarSeries::append() | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlmethod bool BarSeries::remove(BarSet barset) |
|
182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
183 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
184 | */ |
|
184 | */ | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \qmlmethod BarSeries::clear() |
|
187 | \qmlmethod AbstractBarSeries::clear() | |
188 | Removes all barsets from the series. |
|
188 | Removes all barsets from the series. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Constructs empty QAbstractBarSeries. |
|
192 | Constructs empty QAbstractBarSeries. | |
193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
193 | QAbstractBarSeries is QObject which is a child of a \a parent. | |
194 | */ |
|
194 | */ | |
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) | |
197 | { |
|
197 | { | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Destructs barseries and owned barsets. |
|
201 | Destructs abstractbarseries and owned barsets. | |
202 | */ |
|
202 | */ | |
203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
203 | QAbstractBarSeries::~QAbstractBarSeries() | |
204 | { |
|
204 | { | |
205 | Q_D(QAbstractBarSeries); |
|
205 | Q_D(QAbstractBarSeries); | |
206 | if(d->m_dataset){ |
|
206 | if(d->m_dataset){ | |
207 | d->m_dataset->removeSeries(this); |
|
207 | d->m_dataset->removeSeries(this); | |
208 | } |
|
208 | } | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | \internal |
|
212 | \internal | |
213 | */ |
|
213 | */ | |
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
215 | QAbstractSeries(d,parent) |
|
215 | QAbstractSeries(d,parent) | |
216 | { |
|
216 | { | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
224 | */ |
|
224 | */ | |
225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
225 | void QAbstractBarSeries::setBarWidth(qreal width) | |
226 | { |
|
226 | { | |
227 | Q_D(QAbstractBarSeries); |
|
227 | Q_D(QAbstractBarSeries); | |
228 | d->setBarWidth(width); |
|
228 | d->setBarWidth(width); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Returns the width of the bars of the series. |
|
232 | Returns the width of the bars of the series. | |
233 | \sa setBarWidth() |
|
233 | \sa setBarWidth() | |
234 | */ |
|
234 | */ | |
235 | qreal QAbstractBarSeries::barWidth() const |
|
235 | qreal QAbstractBarSeries::barWidth() const | |
236 | { |
|
236 | { | |
237 | Q_D(const QAbstractBarSeries); |
|
237 | Q_D(const QAbstractBarSeries); | |
238 | return d->barWidth(); |
|
238 | return d->barWidth(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
243 | Returns true, if appending succeeded. |
|
243 | Returns true, if appending succeeded. | |
244 | */ |
|
244 | */ | |
245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
245 | bool QAbstractBarSeries::append(QBarSet *set) | |
246 | { |
|
246 | { | |
247 | Q_D(QAbstractBarSeries); |
|
247 | Q_D(QAbstractBarSeries); | |
248 | bool success = d->append(set); |
|
248 | bool success = d->append(set); | |
249 | if (success) { |
|
249 | if (success) { | |
250 | QList<QBarSet*> sets; |
|
250 | QList<QBarSet*> sets; | |
251 | sets.append(set); |
|
251 | sets.append(set); | |
252 | emit barsetsAdded(sets); |
|
252 | emit barsetsAdded(sets); | |
253 | emit countChanged(); |
|
253 | emit countChanged(); | |
254 | } |
|
254 | } | |
255 | return success; |
|
255 | return success; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
260 | Returns true, if set was removed. |
|
260 | Returns true, if set was removed. | |
261 | */ |
|
261 | */ | |
262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
262 | bool QAbstractBarSeries::remove(QBarSet *set) | |
263 | { |
|
263 | { | |
264 | Q_D(QAbstractBarSeries); |
|
264 | Q_D(QAbstractBarSeries); | |
265 | bool success = d->remove(set); |
|
265 | bool success = d->remove(set); | |
266 | if (success) { |
|
266 | if (success) { | |
267 | QList<QBarSet*> sets; |
|
267 | QList<QBarSet*> sets; | |
268 | sets.append(set); |
|
268 | sets.append(set); | |
269 | emit barsetsRemoved(sets); |
|
269 | emit barsetsRemoved(sets); | |
270 | emit countChanged(); |
|
270 | emit countChanged(); | |
271 | } |
|
271 | } | |
272 | return success; |
|
272 | return success; | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
276 | Adds a list of barsets to series. Takes ownership of \a sets. | |
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
279 | and function returns false. |
|
279 | and function returns false. | |
280 | */ |
|
280 | */ | |
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
282 | { |
|
282 | { | |
283 | Q_D(QAbstractBarSeries); |
|
283 | Q_D(QAbstractBarSeries); | |
284 | bool success = d->append(sets); |
|
284 | bool success = d->append(sets); | |
285 | if (success) { |
|
285 | if (success) { | |
286 | emit barsetsAdded(sets); |
|
286 | emit barsetsAdded(sets); | |
287 | emit countChanged(); |
|
287 | emit countChanged(); | |
288 | } |
|
288 | } | |
289 | return success; |
|
289 | return success; | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
294 | Returns true, if inserting succeeded. |
|
294 | Returns true, if inserting succeeded. | |
295 |
|
295 | |||
296 | */ |
|
296 | */ | |
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
298 | { |
|
298 | { | |
299 | Q_D(QAbstractBarSeries); |
|
299 | Q_D(QAbstractBarSeries); | |
300 | bool success = d->insert(index, set); |
|
300 | bool success = d->insert(index, set); | |
301 | if (success) { |
|
301 | if (success) { | |
302 | QList<QBarSet*> sets; |
|
302 | QList<QBarSet*> sets; | |
303 | sets.append(set); |
|
303 | sets.append(set); | |
304 | emit barsetsAdded(sets); |
|
304 | emit barsetsAdded(sets); | |
305 | emit countChanged(); |
|
305 | emit countChanged(); | |
306 | } |
|
306 | } | |
307 | return success; |
|
307 | return success; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Removes all of the bar sets from the series |
|
311 | Removes all of the bar sets from the series | |
312 | */ |
|
312 | */ | |
313 | void QAbstractBarSeries::clear() |
|
313 | void QAbstractBarSeries::clear() | |
314 | { |
|
314 | { | |
315 | Q_D(QAbstractBarSeries); |
|
315 | Q_D(QAbstractBarSeries); | |
316 | QList<QBarSet *> sets = barSets(); |
|
316 | QList<QBarSet *> sets = barSets(); | |
317 | bool success = d->remove(sets); |
|
317 | bool success = d->remove(sets); | |
318 | if (success) { |
|
318 | if (success) { | |
319 | emit barsetsRemoved(sets); |
|
319 | emit barsetsRemoved(sets); | |
320 | emit countChanged(); |
|
320 | emit countChanged(); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | Returns number of sets in series. |
|
325 | Returns number of sets in series. | |
326 | */ |
|
326 | */ | |
327 | int QAbstractBarSeries::count() const |
|
327 | int QAbstractBarSeries::count() const | |
328 | { |
|
328 | { | |
329 | Q_D(const QAbstractBarSeries); |
|
329 | Q_D(const QAbstractBarSeries); | |
330 | return d->m_barSets.count(); |
|
330 | return d->m_barSets.count(); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | Returns a list of sets in series. Keeps ownership of sets. |
|
334 | Returns a list of sets in series. Keeps ownership of sets. | |
335 | */ |
|
335 | */ | |
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
337 | { |
|
337 | { | |
338 | Q_D(const QAbstractBarSeries); |
|
338 | Q_D(const QAbstractBarSeries); | |
339 | return d->m_barSets; |
|
339 | return d->m_barSets; | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | /*! |
|
342 | /*! | |
343 | Sets the visibility of labels in series to \a visible |
|
343 | Sets the visibility of labels in series to \a visible | |
344 | */ |
|
344 | */ | |
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | Q_D(QAbstractBarSeries); |
|
347 | Q_D(QAbstractBarSeries); | |
348 | if (d->m_labelsVisible != visible) { |
|
348 | if (d->m_labelsVisible != visible) { | |
349 | d->setLabelsVisible(visible); |
|
349 | d->setLabelsVisible(visible); | |
350 | emit labelsVisibleChanged(); |
|
350 | emit labelsVisibleChanged(); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns the visibility of labels |
|
355 | Returns the visibility of labels | |
356 | */ |
|
356 | */ | |
357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
357 | bool QAbstractBarSeries::isLabelsVisible() const | |
358 | { |
|
358 | { | |
359 | Q_D(const QAbstractBarSeries); |
|
359 | Q_D(const QAbstractBarSeries); | |
360 | return d->m_labelsVisible; |
|
360 | return d->m_labelsVisible; | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
364 |
|
364 | |||
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
366 | QAbstractSeriesPrivate(q), |
|
366 | QAbstractSeriesPrivate(q), | |
367 | m_barWidth(0.5), // Default value is 50% of category width |
|
367 | m_barWidth(0.5), // Default value is 50% of category width | |
368 | m_labelsVisible(false), |
|
368 | m_labelsVisible(false), | |
369 | m_visible(true) |
|
369 | m_visible(true) | |
370 | { |
|
370 | { | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
373 | int QAbstractBarSeriesPrivate::categoryCount() const | |
374 | { |
|
374 | { | |
375 | // No categories defined. return count of longest set. |
|
375 | // No categories defined. return count of longest set. | |
376 | int count = 0; |
|
376 | int count = 0; | |
377 | for (int i=0; i<m_barSets.count(); i++) { |
|
377 | for (int i=0; i<m_barSets.count(); i++) { | |
378 | if (m_barSets.at(i)->count() > count) { |
|
378 | if (m_barSets.at(i)->count() > count) { | |
379 | count = m_barSets.at(i)->count(); |
|
379 | count = m_barSets.at(i)->count(); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | return count; |
|
383 | return count; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
387 | { |
|
387 | { | |
388 | if (width < 0.0) { |
|
388 | if (width < 0.0) { | |
389 | width = 0.0; |
|
389 | width = 0.0; | |
390 | } |
|
390 | } | |
391 | m_barWidth = width; |
|
391 | m_barWidth = width; | |
392 | emit updatedBars(); |
|
392 | emit updatedBars(); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
395 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
396 | { |
|
396 | { | |
397 | return m_barWidth; |
|
397 | return m_barWidth; | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
401 | { |
|
401 | { | |
402 | return m_barSets.at(index); |
|
402 | return m_barSets.at(index); | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
406 | { |
|
406 | { | |
407 | m_visible = visible; |
|
407 | m_visible = visible; | |
408 | emit updatedBars(); |
|
408 | emit updatedBars(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
412 | { |
|
412 | { | |
413 | m_labelsVisible = visible; |
|
413 | m_labelsVisible = visible; | |
414 | emit labelsVisibleChanged(visible); |
|
414 | emit labelsVisibleChanged(visible); | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | qreal QAbstractBarSeriesPrivate::min() |
|
417 | qreal QAbstractBarSeriesPrivate::min() | |
418 | { |
|
418 | { | |
419 | if (m_barSets.count() <= 0) { |
|
419 | if (m_barSets.count() <= 0) { | |
420 | return 0; |
|
420 | return 0; | |
421 | } |
|
421 | } | |
422 | qreal min = INT_MAX; |
|
422 | qreal min = INT_MAX; | |
423 |
|
423 | |||
424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
424 | for (int i = 0; i < m_barSets.count(); i++) { | |
425 | int categoryCount = m_barSets.at(i)->count(); |
|
425 | int categoryCount = m_barSets.at(i)->count(); | |
426 | for (int j = 0; j < categoryCount; j++) { |
|
426 | for (int j = 0; j < categoryCount; j++) { | |
427 | qreal temp = m_barSets.at(i)->at(j); |
|
427 | qreal temp = m_barSets.at(i)->at(j); | |
428 | if (temp < min) |
|
428 | if (temp < min) | |
429 | min = temp; |
|
429 | min = temp; | |
430 | } |
|
430 | } | |
431 | } |
|
431 | } | |
432 | return min; |
|
432 | return min; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | qreal QAbstractBarSeriesPrivate::max() |
|
435 | qreal QAbstractBarSeriesPrivate::max() | |
436 | { |
|
436 | { | |
437 | if (m_barSets.count() <= 0) { |
|
437 | if (m_barSets.count() <= 0) { | |
438 | return 0; |
|
438 | return 0; | |
439 | } |
|
439 | } | |
440 | qreal max = INT_MIN; |
|
440 | qreal max = INT_MIN; | |
441 |
|
441 | |||
442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
442 | for (int i = 0; i < m_barSets.count(); i++) { | |
443 | int categoryCount = m_barSets.at(i)->count(); |
|
443 | int categoryCount = m_barSets.at(i)->count(); | |
444 | for (int j = 0; j < categoryCount; j++) { |
|
444 | for (int j = 0; j < categoryCount; j++) { | |
445 | qreal temp = m_barSets.at(i)->at(j); |
|
445 | qreal temp = m_barSets.at(i)->at(j); | |
446 | if (temp > max) |
|
446 | if (temp > max) | |
447 | max = temp; |
|
447 | max = temp; | |
448 | } |
|
448 | } | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | return max; |
|
451 | return max; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
455 | { |
|
455 | { | |
456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
456 | if ((set < 0) || (set >= m_barSets.count())) { | |
457 | // No set, no value. |
|
457 | // No set, no value. | |
458 | return 0; |
|
458 | return 0; | |
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
460 | // No category, no value. |
|
460 | // No category, no value. | |
461 | return 0; |
|
461 | return 0; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | return m_barSets.at(set)->at(category); |
|
464 | return m_barSets.at(set)->at(category); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
468 | { |
|
468 | { | |
469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
469 | if ((set < 0) || (set >= m_barSets.count())) { | |
470 | // No set, no value. |
|
470 | // No set, no value. | |
471 | return 0; |
|
471 | return 0; | |
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
473 | // No category, no value. |
|
473 | // No category, no value. | |
474 | return 0; |
|
474 | return 0; | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | qreal value = m_barSets.at(set)->at(category); |
|
477 | qreal value = m_barSets.at(set)->at(category); | |
478 | qreal sum = categorySum(category); |
|
478 | qreal sum = categorySum(category); | |
479 | if ( qFuzzyIsNull(sum) ) { |
|
479 | if ( qFuzzyIsNull(sum) ) { | |
480 | return 0; |
|
480 | return 0; | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | return value / sum; |
|
483 | return value / sum; | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
487 | { |
|
487 | { | |
488 | qreal sum(0); |
|
488 | qreal sum(0); | |
489 | int count = m_barSets.count(); // Count sets |
|
489 | int count = m_barSets.count(); // Count sets | |
490 | for (int set = 0; set < count; set++) { |
|
490 | for (int set = 0; set < count; set++) { | |
491 | if (category < m_barSets.at(set)->count()) |
|
491 | if (category < m_barSets.at(set)->count()) | |
492 | sum += m_barSets.at(set)->at(category); |
|
492 | sum += m_barSets.at(set)->at(category); | |
493 | } |
|
493 | } | |
494 | return sum; |
|
494 | return sum; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
498 | { |
|
498 | { | |
499 | qreal sum(0); |
|
499 | qreal sum(0); | |
500 | int count = m_barSets.count(); // Count sets |
|
500 | int count = m_barSets.count(); // Count sets | |
501 | for (int set = 0; set < count; set++) { |
|
501 | for (int set = 0; set < count; set++) { | |
502 | if (category < m_barSets.at(set)->count()) |
|
502 | if (category < m_barSets.at(set)->count()) | |
503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
503 | sum += qAbs(m_barSets.at(set)->at(category)); | |
504 | } |
|
504 | } | |
505 | return sum; |
|
505 | return sum; | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
509 | { |
|
509 | { | |
510 | qreal max = INT_MIN; |
|
510 | qreal max = INT_MIN; | |
511 | int count = categoryCount(); |
|
511 | int count = categoryCount(); | |
512 | for (int i = 0; i < count; i++) { |
|
512 | for (int i = 0; i < count; i++) { | |
513 | qreal sum = categorySum(i); |
|
513 | qreal sum = categorySum(i); | |
514 | if (sum > max) |
|
514 | if (sum > max) | |
515 | max = sum; |
|
515 | max = sum; | |
516 | } |
|
516 | } | |
517 | return max; |
|
517 | return max; | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | qreal QAbstractBarSeriesPrivate::minX() |
|
520 | qreal QAbstractBarSeriesPrivate::minX() | |
521 | { |
|
521 | { | |
522 | if (m_barSets.count() <= 0) { |
|
522 | if (m_barSets.count() <= 0) { | |
523 | return 0; |
|
523 | return 0; | |
524 | } |
|
524 | } | |
525 | qreal min = INT_MAX; |
|
525 | qreal min = INT_MAX; | |
526 |
|
526 | |||
527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
527 | for (int i = 0; i < m_barSets.count(); i++) { | |
528 | int categoryCount = m_barSets.at(i)->count(); |
|
528 | int categoryCount = m_barSets.at(i)->count(); | |
529 | for (int j = 0; j < categoryCount; j++) { |
|
529 | for (int j = 0; j < categoryCount; j++) { | |
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
531 | if (temp < min) |
|
531 | if (temp < min) | |
532 | min = temp; |
|
532 | min = temp; | |
533 | } |
|
533 | } | |
534 | } |
|
534 | } | |
535 | return min; |
|
535 | return min; | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
538 | qreal QAbstractBarSeriesPrivate::maxX() | |
539 | { |
|
539 | { | |
540 | if (m_barSets.count() <= 0) { |
|
540 | if (m_barSets.count() <= 0) { | |
541 | return 0; |
|
541 | return 0; | |
542 | } |
|
542 | } | |
543 | qreal max = INT_MIN; |
|
543 | qreal max = INT_MIN; | |
544 |
|
544 | |||
545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
545 | for (int i = 0; i < m_barSets.count(); i++) { | |
546 | int categoryCount = m_barSets.at(i)->count(); |
|
546 | int categoryCount = m_barSets.at(i)->count(); | |
547 | for (int j = 0; j < categoryCount; j++) { |
|
547 | for (int j = 0; j < categoryCount; j++) { | |
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
549 | if (temp > max) |
|
549 | if (temp > max) | |
550 | max = temp; |
|
550 | max = temp; | |
551 | } |
|
551 | } | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 | return max; |
|
554 | return max; | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 |
|
557 | |||
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
559 | { |
|
559 | { | |
560 | qreal minX(domain.minX()); |
|
560 | qreal minX(domain.minX()); | |
561 | qreal minY(domain.minY()); |
|
561 | qreal minY(domain.minY()); | |
562 | qreal maxX(domain.maxX()); |
|
562 | qreal maxX(domain.maxX()); | |
563 | qreal maxY(domain.maxY()); |
|
563 | qreal maxY(domain.maxY()); | |
564 | int tickXCount(domain.tickXCount()); |
|
564 | int tickXCount(domain.tickXCount()); | |
565 | int tickYCount(domain.tickYCount()); |
|
565 | int tickYCount(domain.tickYCount()); | |
566 |
|
566 | |||
567 | qreal seriesMinX = this->minX(); |
|
567 | qreal seriesMinX = this->minX(); | |
568 | qreal seriesMaxX = this->maxX(); |
|
568 | qreal seriesMaxX = this->maxX(); | |
569 | qreal y = max(); |
|
569 | qreal y = max(); | |
570 | minX = qMin(minX, seriesMinX - 0.5); |
|
570 | minX = qMin(minX, seriesMinX - 0.5); | |
571 | minY = qMin(minY, y); |
|
571 | minY = qMin(minY, y); | |
572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
572 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
573 | maxY = qMax(maxY, y); |
|
573 | maxY = qMax(maxY, y); | |
574 | tickXCount = categoryCount()+1; |
|
574 | tickXCount = categoryCount()+1; | |
575 |
|
575 | |||
576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
577 | } |
|
577 | } | |
578 |
|
578 | |||
579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
580 | { |
|
580 | { | |
581 | Q_Q(QAbstractBarSeries); |
|
581 | Q_Q(QAbstractBarSeries); | |
582 |
|
582 | |||
583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
583 | BarChartItem* bar = new BarChartItem(q,presenter); | |
584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
585 | presenter->animator()->addAnimation(bar); |
|
585 | presenter->animator()->addAnimation(bar); | |
586 | } |
|
586 | } | |
587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
588 | return bar; |
|
588 | return bar; | |
589 |
|
589 | |||
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
593 | { |
|
593 | { | |
594 | Q_Q(QAbstractBarSeries); |
|
594 | Q_Q(QAbstractBarSeries); | |
595 | QList<LegendMarker*> markers; |
|
595 | QList<LegendMarker*> markers; | |
596 | foreach(QBarSet* set, q->barSets()) { |
|
596 | foreach(QBarSet* set, q->barSets()) { | |
597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
598 | markers << marker; |
|
598 | markers << marker; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | return markers; |
|
601 | return markers; | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
605 | { |
|
605 | { | |
606 | Q_Q(QAbstractBarSeries); |
|
606 | Q_Q(QAbstractBarSeries); | |
607 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
607 | if ((m_barSets.contains(set)) || (set == 0)) { | |
608 | // Fail if set is already in list or set is null. |
|
608 | // Fail if set is already in list or set is null. | |
609 | return false; |
|
609 | return false; | |
610 | } |
|
610 | } | |
611 | m_barSets.append(set); |
|
611 | m_barSets.append(set); | |
612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
614 | emit restructuredBars(); // this notifies barchartitem |
|
614 | emit restructuredBars(); // this notifies barchartitem | |
615 | if (m_dataset) { |
|
615 | if (m_dataset) { | |
616 | m_dataset->updateSeries(q); // this notifies legend |
|
616 | m_dataset->updateSeries(q); // this notifies legend | |
617 | } |
|
617 | } | |
618 | return true; |
|
618 | return true; | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
622 | { |
|
622 | { | |
623 | Q_Q(QAbstractBarSeries); |
|
623 | Q_Q(QAbstractBarSeries); | |
624 | if (!m_barSets.contains(set)) { |
|
624 | if (!m_barSets.contains(set)) { | |
625 | // Fail if set is not in list |
|
625 | // Fail if set is not in list | |
626 | return false; |
|
626 | return false; | |
627 | } |
|
627 | } | |
628 | m_barSets.removeOne(set); |
|
628 | m_barSets.removeOne(set); | |
629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
631 | emit restructuredBars(); // this notifies barchartitem |
|
631 | emit restructuredBars(); // this notifies barchartitem | |
632 | if (m_dataset) { |
|
632 | if (m_dataset) { | |
633 | m_dataset->updateSeries(q); // this notifies legend |
|
633 | m_dataset->updateSeries(q); // this notifies legend | |
634 | } |
|
634 | } | |
635 | return true; |
|
635 | return true; | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
639 | { |
|
639 | { | |
640 | Q_Q(QAbstractBarSeries); |
|
640 | Q_Q(QAbstractBarSeries); | |
641 | foreach (QBarSet* set, sets) { |
|
641 | foreach (QBarSet* set, sets) { | |
642 | if ((set == 0) || (m_barSets.contains(set))) { |
|
642 | if ((set == 0) || (m_barSets.contains(set))) { | |
643 | // Fail if any of the sets is null or is already appended. |
|
643 | // Fail if any of the sets is null or is already appended. | |
644 | return false; |
|
644 | return false; | |
645 | } |
|
645 | } | |
646 | if (sets.count(set) != 1) { |
|
646 | if (sets.count(set) != 1) { | |
647 | // Also fail if same set is more than once in given list. |
|
647 | // Also fail if same set is more than once in given list. | |
648 | return false; |
|
648 | return false; | |
649 | } |
|
649 | } | |
650 | } |
|
650 | } | |
651 |
|
651 | |||
652 | foreach (QBarSet* set, sets) { |
|
652 | foreach (QBarSet* set, sets) { | |
653 | m_barSets.append(set); |
|
653 | m_barSets.append(set); | |
654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
656 | } |
|
656 | } | |
657 | emit restructuredBars(); // this notifies barchartitem |
|
657 | emit restructuredBars(); // this notifies barchartitem | |
658 | if (m_dataset) { |
|
658 | if (m_dataset) { | |
659 | m_dataset->updateSeries(q); // this notifies legend |
|
659 | m_dataset->updateSeries(q); // this notifies legend | |
660 | } |
|
660 | } | |
661 | return true; |
|
661 | return true; | |
662 | } |
|
662 | } | |
663 |
|
663 | |||
664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
665 | { |
|
665 | { | |
666 | Q_Q(QAbstractBarSeries); |
|
666 | Q_Q(QAbstractBarSeries); | |
667 | if (sets.count() == 0) { |
|
667 | if (sets.count() == 0) { | |
668 | return false; |
|
668 | return false; | |
669 | } |
|
669 | } | |
670 | foreach (QBarSet* set, sets) { |
|
670 | foreach (QBarSet* set, sets) { | |
671 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
671 | if ((set == 0) || (!m_barSets.contains(set))) { | |
672 | // Fail if any of the sets is null or is not in series |
|
672 | // Fail if any of the sets is null or is not in series | |
673 | return false; |
|
673 | return false; | |
674 | } |
|
674 | } | |
675 | if (sets.count(set) != 1) { |
|
675 | if (sets.count(set) != 1) { | |
676 | // Also fail if same set is more than once in given list. |
|
676 | // Also fail if same set is more than once in given list. | |
677 | return false; |
|
677 | return false; | |
678 | } |
|
678 | } | |
679 | } |
|
679 | } | |
680 |
|
680 | |||
681 | foreach (QBarSet* set, sets) { |
|
681 | foreach (QBarSet* set, sets) { | |
682 | m_barSets.removeOne(set); |
|
682 | m_barSets.removeOne(set); | |
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
685 | } |
|
685 | } | |
686 |
|
686 | |||
687 | emit restructuredBars(); // this notifies barchartitem |
|
687 | emit restructuredBars(); // this notifies barchartitem | |
688 | if (m_dataset) { |
|
688 | if (m_dataset) { | |
689 | m_dataset->updateSeries(q); // this notifies legend |
|
689 | m_dataset->updateSeries(q); // this notifies legend | |
690 | } |
|
690 | } | |
691 | return true; |
|
691 | return true; | |
692 | } |
|
692 | } | |
693 |
|
693 | |||
694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
695 | { |
|
695 | { | |
696 | Q_Q(QAbstractBarSeries); |
|
696 | Q_Q(QAbstractBarSeries); | |
697 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
697 | if ((m_barSets.contains(set)) || (set == 0)) { | |
698 | // Fail if set is already in list or set is null. |
|
698 | // Fail if set is already in list or set is null. | |
699 | return false; |
|
699 | return false; | |
700 | } |
|
700 | } | |
701 | m_barSets.insert(index, set); |
|
701 | m_barSets.insert(index, set); | |
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
704 | emit restructuredBars(); // this notifies barchartitem |
|
704 | emit restructuredBars(); // this notifies barchartitem | |
705 | if (m_dataset) { |
|
705 | if (m_dataset) { | |
706 | m_dataset->updateSeries(q); // this notifies legend |
|
706 | m_dataset->updateSeries(q); // this notifies legend | |
707 | } |
|
707 | } | |
708 | return true; |
|
708 | return true; | |
709 | } |
|
709 | } | |
710 |
|
710 | |||
711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) |
|
711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
712 | { |
|
712 | { | |
713 | Q_UNUSED(axis); |
|
713 | Q_UNUSED(axis); | |
714 | } |
|
714 | } | |
715 |
|
715 | |||
716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) |
|
716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
717 | { |
|
717 | { | |
718 | Q_UNUSED(axis) |
|
718 | Q_UNUSED(axis) | |
719 | } |
|
719 | } | |
720 |
|
720 | |||
721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const |
|
721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const | |
722 | { |
|
722 | { | |
723 | return QAbstractAxis::AxisTypeCategories; |
|
723 | return QAbstractAxis::AxisTypeCategories; | |
724 | } |
|
724 | } | |
725 |
|
725 | |||
726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const |
|
726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const | |
727 | { |
|
727 | { | |
728 | return QAbstractAxis::AxisTypeValues; |
|
728 | return QAbstractAxis::AxisTypeValues; | |
729 | } |
|
729 | } | |
730 |
|
730 | |||
731 | #include "moc_qabstractbarseries.cpp" |
|
731 | #include "moc_qabstractbarseries.cpp" | |
732 | #include "moc_qabstractbarseries_p.cpp" |
|
732 | #include "moc_qabstractbarseries_p.cpp" | |
733 |
|
733 | |||
734 |
|
734 | |||
735 | QTCOMMERCIALCHART_END_NAMESPACE |
|
735 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,84 | |||||
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 BARSERIES_H |
|
21 | #ifndef ABSTRACTBARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define ABSTRACTBARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QBarSet; |
|
29 | class QBarSet; | |
30 | class QAbstractBarSeriesPrivate; |
|
30 | class QAbstractBarSeriesPrivate; | |
31 |
|
31 | |||
32 | // Container for series |
|
32 | // Container for series | |
33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) | |
37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
37 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
39 |
|
39 | |||
40 | protected: |
|
40 | protected: | |
41 | explicit QAbstractBarSeries(QObject *parent = 0); |
|
41 | explicit QAbstractBarSeries(QObject *parent = 0); | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | virtual ~QAbstractBarSeries(); |
|
44 | virtual ~QAbstractBarSeries(); | |
45 |
|
45 | |||
46 | virtual QAbstractSeries::SeriesType type() const = 0; |
|
46 | virtual QAbstractSeries::SeriesType type() const = 0; | |
47 |
|
47 | |||
48 | void setBarWidth(qreal width); |
|
48 | void setBarWidth(qreal width); | |
49 | qreal barWidth() const; |
|
49 | qreal barWidth() const; | |
50 |
|
50 | |||
51 | bool append(QBarSet *set); |
|
51 | bool append(QBarSet *set); | |
52 | bool remove(QBarSet *set); |
|
52 | bool remove(QBarSet *set); | |
53 | bool append(QList<QBarSet* > sets); |
|
53 | bool append(QList<QBarSet* > sets); | |
54 | bool insert(int index, QBarSet *set); |
|
54 | bool insert(int index, QBarSet *set); | |
55 | int count() const; |
|
55 | int count() const; | |
56 | QList<QBarSet*> barSets() const; |
|
56 | QList<QBarSet*> barSets() const; | |
57 | void clear(); |
|
57 | void clear(); | |
58 |
|
58 | |||
59 | void setLabelsVisible(bool visible = true); |
|
59 | void setLabelsVisible(bool visible = true); | |
60 | bool isLabelsVisible() const; |
|
60 | bool isLabelsVisible() const; | |
61 |
|
61 | |||
62 | protected: |
|
62 | protected: | |
63 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); |
|
63 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); | |
64 |
|
64 | |||
65 | Q_SIGNALS: |
|
65 | Q_SIGNALS: | |
66 | void clicked(int index, QBarSet *barset); |
|
66 | void clicked(int index, QBarSet *barset); | |
67 | void hovered(bool status, QBarSet *barset); |
|
67 | void hovered(bool status, QBarSet *barset); | |
68 | void countChanged(); |
|
68 | void countChanged(); | |
69 | void labelsVisibleChanged(); |
|
69 | void labelsVisibleChanged(); | |
70 |
|
70 | |||
71 | void barsetsAdded(QList<QBarSet*> sets); |
|
71 | void barsetsAdded(QList<QBarSet*> sets); | |
72 | void barsetsRemoved(QList<QBarSet*> sets); |
|
72 | void barsetsRemoved(QList<QBarSet*> sets); | |
73 |
|
73 | |||
74 | protected: |
|
74 | protected: | |
75 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
75 | Q_DECLARE_PRIVATE(QAbstractBarSeries) | |
76 | friend class BarChartItem; |
|
76 | friend class BarChartItem; | |
77 | friend class PercentBarChartItem; |
|
77 | friend class PercentBarChartItem; | |
78 | friend class StackedBarChartItem; |
|
78 | friend class StackedBarChartItem; | |
79 | friend class GroupedBarChartItem; |
|
79 | friend class GroupedBarChartItem; | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
83 | |||
84 | #endif // BARSERIES_H |
|
84 | #endif // ABSTRACTBARSERIES_H |
@@ -1,616 +1,616 | |||||
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 "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief Building block for different bar charts |
|
28 | \brief Building block for different bar charts | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QAbstractBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QAbstractBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries |
|
46 | \sa AbstractBarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty Font BarSet::labelFont |
|
79 | \qmlproperty Font BarSet::labelFont | |
80 | Defines the font used by the barSet's label. |
|
80 | Defines the font used by the barSet's label. | |
81 |
|
81 | |||
82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSet::color |
|
86 | \property QBarSet::color | |
87 | The fill (brush) color of the bar set. |
|
87 | The fill (brush) color of the bar set. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty color BarSet::color |
|
90 | \qmlproperty color BarSet::color | |
91 | The fill (brush) color of the bar set. |
|
91 | The fill (brush) color of the bar set. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarSet::borderColor |
|
95 | \property QBarSet::borderColor | |
96 | The line (pen) color of the bar set. |
|
96 | The line (pen) color of the bar set. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty color BarSet::borderColor |
|
99 | \qmlproperty color BarSet::borderColor | |
100 | The line (pen) color of the bar set. |
|
100 | The line (pen) color of the bar set. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QBarSet::labelColor |
|
104 | \property QBarSet::labelColor | |
105 | The text (label) color of the bar set. |
|
105 | The text (label) color of the bar set. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty color BarSet::labelColor |
|
108 | \qmlproperty color BarSet::labelColor | |
109 | The text (label) color of the bar set. |
|
109 | The text (label) color of the bar set. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarSet::clicked(int index) |
|
113 | \fn void QBarSet::clicked(int index) | |
114 |
|
114 | |||
115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
115 | The signal is emitted if the user clicks with a mouse on top of barset. | |
116 | Clicked bar inside set is indexed by \a index |
|
116 | Clicked bar inside set is indexed by \a index | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QBarSet::hovered(bool status) |
|
120 | \fn void QBarSet::hovered(bool status) | |
121 |
|
121 | |||
122 | The signal is emitted if mouse is hovered on top of barset. |
|
122 | The signal is emitted if mouse is hovered on top of barset. | |
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QBarSet::labelChanged() |
|
128 | \fn void QBarSet::labelChanged() | |
129 | This signal is emitted when the label of the barSet has changed. |
|
129 | This signal is emitted when the label of the barSet has changed. | |
130 | \sa label |
|
130 | \sa label | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlsignal BarSet::onLabelChanged() |
|
133 | \qmlsignal BarSet::onLabelChanged() | |
134 | This signal is emitted when the label of the barSet has changed. |
|
134 | This signal is emitted when the label of the barSet has changed. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QBarSet::penChanged() |
|
138 | \fn void QBarSet::penChanged() | |
139 | This signal is emitted when the pen of the barSet has changed. |
|
139 | This signal is emitted when the pen of the barSet has changed. | |
140 | \sa pen |
|
140 | \sa pen | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QBarSet::brushChanged() |
|
144 | \fn void QBarSet::brushChanged() | |
145 | This signal is emitted when the brush of the barSet has changed. |
|
145 | This signal is emitted when the brush of the barSet has changed. | |
146 | \sa brush |
|
146 | \sa brush | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QBarSet::labelBrushChanged() |
|
150 | \fn void QBarSet::labelBrushChanged() | |
151 | This signal is emitted when the brush of the barSet's label has changed. |
|
151 | This signal is emitted when the brush of the barSet's label has changed. | |
152 | \sa labelBrush |
|
152 | \sa labelBrush | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QBarSet::labelFontChanged() |
|
156 | \fn void QBarSet::labelFontChanged() | |
157 | This signal is emitted when the font of the barSet's label has changed. |
|
157 | This signal is emitted when the font of the barSet's label has changed. | |
158 | \sa labelBrush |
|
158 | \sa labelBrush | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QBarSet::colorChanged(QColor) |
|
162 | \fn void QBarSet::colorChanged(QColor) | |
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 | /*! |
|
165 | /*! | |
166 | \qmlsignal BarSet::onColorChanged(color color) |
|
166 | \qmlsignal BarSet::onColorChanged(color color) | |
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \fn void QBarSet::borderColorChanged(QColor) |
|
171 | \fn void QBarSet::borderColorChanged(QColor) | |
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
173 | */ |
|
173 | */ | |
174 | /*! |
|
174 | /*! | |
175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
175 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \fn void QBarSet::labelColorChanged(QColor) |
|
180 | \fn void QBarSet::labelColorChanged(QColor) | |
181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
181 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
182 | */ |
|
182 | */ | |
183 | /*! |
|
183 | /*! | |
184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
184 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
185 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
186 | */ |
|
186 | */ | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
189 | \fn void QBarSet::valuesAdded(int index, int count) | |
190 | This signal is emitted when new values have been added to the set. |
|
190 | This signal is emitted when new values have been added to the set. | |
191 | Parameter \a index indicates the position of the first inserted value. |
|
191 | Parameter \a index indicates the position of the first inserted value. | |
192 | Parameter \a count is the number of iserted values. |
|
192 | Parameter \a count is the number of iserted values. | |
193 | \sa append(), insert() |
|
193 | \sa append(), insert() | |
194 | */ |
|
194 | */ | |
195 | /*! |
|
195 | /*! | |
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
197 | This signal is emitted when new values have been added to the set. |
|
197 | This signal is emitted when new values have been added to the set. | |
198 | Parameter \a index indicates the position of the first inserted value. |
|
198 | Parameter \a index indicates the position of the first inserted value. | |
199 | Parameter \a count is the number of iserted values. |
|
199 | Parameter \a count is the number of iserted values. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
203 | \fn void QBarSet::valuesRemoved(int index, int count) | |
204 | This signal is emitted values have been removed from the set. |
|
204 | This signal is emitted values have been removed from the set. | |
205 | Parameter \a index indicates the position of the first removed value. |
|
205 | Parameter \a index indicates the position of the first removed value. | |
206 | Parameter \a count is the number of removed values. |
|
206 | Parameter \a count is the number of removed values. | |
207 | \sa remove() |
|
207 | \sa remove() | |
208 | */ |
|
208 | */ | |
209 | /*! |
|
209 | /*! | |
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
211 | This signal is emitted values have been removed from the set. |
|
211 | This signal is emitted values have been removed from the set. | |
212 | Parameter \a index indicates the position of the first removed value. |
|
212 | Parameter \a index indicates the position of the first removed value. | |
213 | Parameter \a count is the number of removed values. |
|
213 | Parameter \a count is the number of removed values. | |
214 | */ |
|
214 | */ | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | \fn void QBarSet::valueChanged(int index) |
|
217 | \fn void QBarSet::valueChanged(int index) | |
218 | This signal is emitted values the value in the set has been modified. |
|
218 | This signal is emitted values the value in the set has been modified. | |
219 | Parameter \a index indicates the position of the modified value. |
|
219 | Parameter \a index indicates the position of the modified value. | |
220 | \sa at() |
|
220 | \sa at() | |
221 | */ |
|
221 | */ | |
222 | /*! |
|
222 | /*! | |
223 | \qmlsignal BarSet::onValueChanged(int index) |
|
223 | \qmlsignal BarSet::onValueChanged(int index) | |
224 | This signal is emitted values the value in the set has been modified. |
|
224 | This signal is emitted values the value in the set has been modified. | |
225 | Parameter \a index indicates the position of the modified value. |
|
225 | Parameter \a index indicates the position of the modified value. | |
226 | */ |
|
226 | */ | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | \qmlproperty int BarSet::count |
|
229 | \qmlproperty int BarSet::count | |
230 | The count of values on the barset |
|
230 | The count of values on the barset | |
231 | */ |
|
231 | */ | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | \qmlproperty QVariantList BarSet::values |
|
234 | \qmlproperty QVariantList BarSet::values | |
235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of | |
236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
236 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
237 | x-coordinate. For example: |
|
237 | x-coordinate. For example: | |
238 | \code |
|
238 | \code | |
239 | myBarSet1.values = [0, 5, 1, 5]; |
|
239 | myBarSet1.values = [0, 5, 1, 5]; | |
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
241 | \endcode |
|
241 | \endcode | |
242 | */ |
|
242 | */ | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
245 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
246 | */ |
|
246 | */ | |
247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
247 | QBarSet::QBarSet(const QString label, QObject *parent) | |
248 | : QObject(parent) |
|
248 | : QObject(parent) | |
249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
249 | ,d_ptr(new QBarSetPrivate(label,this)) | |
250 | { |
|
250 | { | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Destroys the barset |
|
254 | Destroys the barset | |
255 | */ |
|
255 | */ | |
256 | QBarSet::~QBarSet() |
|
256 | QBarSet::~QBarSet() | |
257 | { |
|
257 | { | |
258 | // NOTE: d_ptr destroyed by QObject |
|
258 | // NOTE: d_ptr destroyed by QObject | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Sets new \a label for set. |
|
262 | Sets new \a label for set. | |
263 | */ |
|
263 | */ | |
264 | void QBarSet::setLabel(const QString label) |
|
264 | void QBarSet::setLabel(const QString label) | |
265 | { |
|
265 | { | |
266 | d_ptr->m_label = label; |
|
266 | d_ptr->m_label = label; | |
267 | emit labelChanged(); |
|
267 | emit labelChanged(); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Returns label of the set. |
|
271 | Returns label of the set. | |
272 | */ |
|
272 | */ | |
273 | QString QBarSet::label() const |
|
273 | QString QBarSet::label() const | |
274 | { |
|
274 | { | |
275 | return d_ptr->m_label; |
|
275 | return d_ptr->m_label; | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Appends new value \a value to the end of set. |
|
279 | Appends new value \a value to the end of set. | |
280 | */ |
|
280 | */ | |
281 | void QBarSet::append(const qreal value) |
|
281 | void QBarSet::append(const qreal value) | |
282 | { |
|
282 | { | |
283 | // Convert to QPointF |
|
283 | // Convert to QPointF | |
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
288 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
289 | are appended to end of barset |
|
289 | are appended to end of barset | |
290 | \sa append() |
|
290 | \sa append() | |
291 | */ |
|
291 | */ | |
292 | void QBarSet::append(const QList<qreal> &values) |
|
292 | void QBarSet::append(const QList<qreal> &values) | |
293 | { |
|
293 | { | |
294 | int index = d_ptr->m_values.count(); |
|
294 | int index = d_ptr->m_values.count(); | |
295 | d_ptr->append(values); |
|
295 | d_ptr->append(values); | |
296 | emit valuesAdded(index, values.count()); |
|
296 | emit valuesAdded(index, values.count()); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Convinience operator. Same as append, with real \a value. |
|
300 | Convinience operator. Same as append, with real \a value. | |
301 | \sa append() |
|
301 | \sa append() | |
302 | */ |
|
302 | */ | |
303 | QBarSet& QBarSet::operator << (const qreal &value) |
|
303 | QBarSet& QBarSet::operator << (const qreal &value) | |
304 | { |
|
304 | { | |
305 | // append(value); |
|
305 | // append(value); | |
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
307 | return *this; |
|
307 | return *this; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Inserts new \a value on the \a index position. |
|
311 | Inserts new \a value on the \a index position. | |
312 | The value that is currently at this postion is moved to postion index + 1 |
|
312 | The value that is currently at this postion is moved to postion index + 1 | |
313 | \sa remove() |
|
313 | \sa remove() | |
314 | */ |
|
314 | */ | |
315 | void QBarSet::insert(const int index, const qreal value) |
|
315 | void QBarSet::insert(const int index, const qreal value) | |
316 | { |
|
316 | { | |
317 | d_ptr->insert(index, value); |
|
317 | d_ptr->insert(index, value); | |
318 | emit valuesAdded(index,1); |
|
318 | emit valuesAdded(index,1); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | /*! |
|
321 | /*! | |
322 | Removes \a count number of values from the set starting at \a index. |
|
322 | Removes \a count number of values from the set starting at \a index. | |
323 | \sa insert() |
|
323 | \sa insert() | |
324 | */ |
|
324 | */ | |
325 | void QBarSet::remove(const int index, const int count) |
|
325 | void QBarSet::remove(const int index, const int count) | |
326 | { |
|
326 | { | |
327 | int removedCount = d_ptr->remove(index,count); |
|
327 | int removedCount = d_ptr->remove(index,count); | |
328 | if (removedCount > 0) { |
|
328 | if (removedCount > 0) { | |
329 | emit valuesRemoved(index,removedCount); |
|
329 | emit valuesRemoved(index,removedCount); | |
330 | } |
|
330 | } | |
331 | return; |
|
331 | return; | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | Sets a new value \a value to set, indexed by \a index |
|
335 | Sets a new value \a value to set, indexed by \a index | |
336 | */ |
|
336 | */ | |
337 | void QBarSet::replace(const int index, const qreal value) |
|
337 | void QBarSet::replace(const int index, const qreal value) | |
338 | { |
|
338 | { | |
339 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
339 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
340 | d_ptr->replace(index,value); |
|
340 | d_ptr->replace(index,value); | |
341 | emit valueChanged(index); |
|
341 | emit valueChanged(index); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 |
|
345 | |||
346 | /*! |
|
346 | /*! | |
347 | Returns value of set indexed by \a index. |
|
347 | Returns value of set indexed by \a index. | |
348 | If the index is out of bounds 0.0 is returned. |
|
348 | If the index is out of bounds 0.0 is returned. | |
349 | */ |
|
349 | */ | |
350 | qreal QBarSet::at(const int index) const |
|
350 | qreal QBarSet::at(const int index) const | |
351 | { |
|
351 | { | |
352 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
352 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
353 | return 0; |
|
353 | return 0; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | return d_ptr->m_values.at(index).y(); |
|
356 | return d_ptr->m_values.at(index).y(); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Returns value of set indexed by \a index. |
|
360 | Returns value of set indexed by \a index. | |
361 | If the index is out of bounds 0.0 is returned. |
|
361 | If the index is out of bounds 0.0 is returned. | |
362 | */ |
|
362 | */ | |
363 | qreal QBarSet::operator [](const int index) const |
|
363 | qreal QBarSet::operator [](const int index) const | |
364 | { |
|
364 | { | |
365 | return at(index); |
|
365 | return at(index); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | /*! |
|
368 | /*! | |
369 | Returns count of values in set. |
|
369 | Returns count of values in set. | |
370 | */ |
|
370 | */ | |
371 | int QBarSet::count() const |
|
371 | int QBarSet::count() const | |
372 | { |
|
372 | { | |
373 | return d_ptr->m_values.count(); |
|
373 | return d_ptr->m_values.count(); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | /*! |
|
376 | /*! | |
377 | Returns sum of all values in barset. |
|
377 | Returns sum of all values in barset. | |
378 | */ |
|
378 | */ | |
379 | qreal QBarSet::sum() const |
|
379 | qreal QBarSet::sum() const | |
380 | { |
|
380 | { | |
381 | qreal total(0); |
|
381 | qreal total(0); | |
382 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
382 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
383 | total += d_ptr->m_values.at(i).y(); |
|
383 | total += d_ptr->m_values.at(i).y(); | |
384 | } |
|
384 | } | |
385 | return total; |
|
385 | return total; | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | /*! |
|
388 | /*! | |
389 | Sets pen for set. Bars of this set are drawn using \a pen |
|
389 | Sets pen for set. Bars of this set are drawn using \a pen | |
390 | */ |
|
390 | */ | |
391 | void QBarSet::setPen(const QPen &pen) |
|
391 | void QBarSet::setPen(const QPen &pen) | |
392 | { |
|
392 | { | |
393 | if(d_ptr->m_pen!=pen){ |
|
393 | if(d_ptr->m_pen!=pen){ | |
394 | d_ptr->m_pen = pen; |
|
394 | d_ptr->m_pen = pen; | |
395 | emit d_ptr->updatedBars(); |
|
395 | emit d_ptr->updatedBars(); | |
396 | emit penChanged(); |
|
396 | emit penChanged(); | |
397 | } |
|
397 | } | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | /*! |
|
400 | /*! | |
401 | Returns pen of the set. |
|
401 | Returns pen of the set. | |
402 | */ |
|
402 | */ | |
403 | QPen QBarSet::pen() const |
|
403 | QPen QBarSet::pen() const | |
404 | { |
|
404 | { | |
405 | return d_ptr->m_pen; |
|
405 | return d_ptr->m_pen; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
409 | Sets brush for the set. Bars of this set are drawn using \a brush | |
410 | */ |
|
410 | */ | |
411 | void QBarSet::setBrush(const QBrush &brush) |
|
411 | void QBarSet::setBrush(const QBrush &brush) | |
412 | { |
|
412 | { | |
413 | if(d_ptr->m_brush!=brush){ |
|
413 | if(d_ptr->m_brush!=brush){ | |
414 | d_ptr->m_brush = brush; |
|
414 | d_ptr->m_brush = brush; | |
415 | emit d_ptr->updatedBars(); |
|
415 | emit d_ptr->updatedBars(); | |
416 | emit brushChanged(); |
|
416 | emit brushChanged(); | |
417 | } |
|
417 | } | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | /*! |
|
420 | /*! | |
421 | Returns brush of the set. |
|
421 | Returns brush of the set. | |
422 | */ |
|
422 | */ | |
423 | QBrush QBarSet::brush() const |
|
423 | QBrush QBarSet::brush() const | |
424 | { |
|
424 | { | |
425 | return d_ptr->m_brush; |
|
425 | return d_ptr->m_brush; | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | /*! |
|
428 | /*! | |
429 | Sets \a brush of the values that are drawn on top of this barset |
|
429 | Sets \a brush of the values that are drawn on top of this barset | |
430 | */ |
|
430 | */ | |
431 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
431 | void QBarSet::setLabelBrush(const QBrush &brush) | |
432 | { |
|
432 | { | |
433 | if(d_ptr->m_labelBrush!=brush){ |
|
433 | if(d_ptr->m_labelBrush!=brush){ | |
434 | d_ptr->m_labelBrush = brush; |
|
434 | d_ptr->m_labelBrush = brush; | |
435 | emit d_ptr->updatedBars(); |
|
435 | emit d_ptr->updatedBars(); | |
436 | emit labelBrushChanged(); |
|
436 | emit labelBrushChanged(); | |
437 | } |
|
437 | } | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | /*! |
|
440 | /*! | |
441 | Returns brush of the values that are drawn on top of this barset |
|
441 | Returns brush of the values that are drawn on top of this barset | |
442 | */ |
|
442 | */ | |
443 | QBrush QBarSet::labelBrush() const |
|
443 | QBrush QBarSet::labelBrush() const | |
444 | { |
|
444 | { | |
445 | return d_ptr->m_labelBrush; |
|
445 | return d_ptr->m_labelBrush; | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | /*! |
|
448 | /*! | |
449 | Sets the \a font for values that are drawn on top of this barset |
|
449 | Sets the \a font for values that are drawn on top of this barset | |
450 | */ |
|
450 | */ | |
451 | void QBarSet::setLabelFont(const QFont &font) |
|
451 | void QBarSet::setLabelFont(const QFont &font) | |
452 | { |
|
452 | { | |
453 | if(d_ptr->m_labelFont!=font) { |
|
453 | if(d_ptr->m_labelFont!=font) { | |
454 | d_ptr->m_labelFont = font; |
|
454 | d_ptr->m_labelFont = font; | |
455 | emit d_ptr->updatedBars(); |
|
455 | emit d_ptr->updatedBars(); | |
456 | emit labelFontChanged(); |
|
456 | emit labelFontChanged(); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | /*! |
|
461 | /*! | |
462 | Returns the pen for values that are drawn on top of this barset |
|
462 | Returns the pen for values that are drawn on top of this barset | |
463 | */ |
|
463 | */ | |
464 | QFont QBarSet::labelFont() const |
|
464 | QFont QBarSet::labelFont() const | |
465 | { |
|
465 | { | |
466 | return d_ptr->m_labelFont; |
|
466 | return d_ptr->m_labelFont; | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | /*! |
|
469 | /*! | |
470 | Returns the color of the brush of barset. |
|
470 | Returns the color of the brush of barset. | |
471 | */ |
|
471 | */ | |
472 | QColor QBarSet::color() |
|
472 | QColor QBarSet::color() | |
473 | { |
|
473 | { | |
474 | return brush().color(); |
|
474 | return brush().color(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets the \a color of brush for this barset |
|
478 | Sets the \a color of brush for this barset | |
479 | */ |
|
479 | */ | |
480 | void QBarSet::setColor(QColor color) |
|
480 | void QBarSet::setColor(QColor color) | |
481 | { |
|
481 | { | |
482 | QBrush b = brush(); |
|
482 | QBrush b = brush(); | |
483 | if (b.color() != color) { |
|
483 | if (b.color() != color) { | |
484 | b.setColor(color); |
|
484 | b.setColor(color); | |
485 | setBrush(b); |
|
485 | setBrush(b); | |
486 | emit colorChanged(color); |
|
486 | emit colorChanged(color); | |
487 | } |
|
487 | } | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | /*! |
|
490 | /*! | |
491 | Returns the color of pen of this barset |
|
491 | Returns the color of pen of this barset | |
492 | */ |
|
492 | */ | |
493 | QColor QBarSet::borderColor() |
|
493 | QColor QBarSet::borderColor() | |
494 | { |
|
494 | { | |
495 | return pen().color(); |
|
495 | return pen().color(); | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | /*! |
|
498 | /*! | |
499 | Sets the color of pen for this barset |
|
499 | Sets the color of pen for this barset | |
500 | */ |
|
500 | */ | |
501 | void QBarSet::setBorderColor(QColor color) |
|
501 | void QBarSet::setBorderColor(QColor color) | |
502 | { |
|
502 | { | |
503 | QPen p = pen(); |
|
503 | QPen p = pen(); | |
504 | if (p.color() != color) { |
|
504 | if (p.color() != color) { | |
505 | p.setColor(color); |
|
505 | p.setColor(color); | |
506 | setPen(p); |
|
506 | setPen(p); | |
507 | emit borderColorChanged(color); |
|
507 | emit borderColorChanged(color); | |
508 | } |
|
508 | } | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | /*! |
|
511 | /*! | |
512 | Returns the color of labels of this barset |
|
512 | Returns the color of labels of this barset | |
513 | */ |
|
513 | */ | |
514 | QColor QBarSet::labelColor() |
|
514 | QColor QBarSet::labelColor() | |
515 | { |
|
515 | { | |
516 | return labelBrush().color(); |
|
516 | return labelBrush().color(); | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | /*! |
|
519 | /*! | |
520 | Sets the color of labels for this barset |
|
520 | Sets the color of labels for this barset | |
521 | */ |
|
521 | */ | |
522 | void QBarSet::setLabelColor(QColor color) |
|
522 | void QBarSet::setLabelColor(QColor color) | |
523 | { |
|
523 | { | |
524 | QBrush b = labelBrush(); |
|
524 | QBrush b = labelBrush(); | |
525 | if (b.color() != color) { |
|
525 | if (b.color() != color) { | |
526 | b.setColor(color); |
|
526 | b.setColor(color); | |
527 | setLabelBrush(b); |
|
527 | setLabelBrush(b); | |
528 | emit labelColorChanged(color); |
|
528 | emit labelColorChanged(color); | |
529 | } |
|
529 | } | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
533 |
|
533 | |||
534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
535 | q_ptr(parent), |
|
535 | q_ptr(parent), | |
536 | m_label(label) |
|
536 | m_label(label) | |
537 | { |
|
537 | { | |
538 | } |
|
538 | } | |
539 |
|
539 | |||
540 | QBarSetPrivate::~QBarSetPrivate() |
|
540 | QBarSetPrivate::~QBarSetPrivate() | |
541 | { |
|
541 | { | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | void QBarSetPrivate::append(QPointF value) |
|
544 | void QBarSetPrivate::append(QPointF value) | |
545 | { |
|
545 | { | |
546 | m_values.append(value); |
|
546 | m_values.append(value); | |
547 | emit restructuredBars(); |
|
547 | emit restructuredBars(); | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | void QBarSetPrivate::append(QList<QPointF> values) |
|
550 | void QBarSetPrivate::append(QList<QPointF> values) | |
551 | { |
|
551 | { | |
552 | for (int i=0; i<values.count(); i++) { |
|
552 | for (int i=0; i<values.count(); i++) { | |
553 | m_values.append(values.at(i)); |
|
553 | m_values.append(values.at(i)); | |
554 | } |
|
554 | } | |
555 | emit restructuredBars(); |
|
555 | emit restructuredBars(); | |
556 | } |
|
556 | } | |
557 |
|
557 | |||
558 | void QBarSetPrivate::append(QList<qreal> values) |
|
558 | void QBarSetPrivate::append(QList<qreal> values) | |
559 | { |
|
559 | { | |
560 | int index = m_values.count(); |
|
560 | int index = m_values.count(); | |
561 | for (int i=0; i<values.count(); i++) { |
|
561 | for (int i=0; i<values.count(); i++) { | |
562 | m_values.append(QPointF(index,values.at(i))); |
|
562 | m_values.append(QPointF(index,values.at(i))); | |
563 | index++; |
|
563 | index++; | |
564 | } |
|
564 | } | |
565 | emit restructuredBars(); |
|
565 | emit restructuredBars(); | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
568 | void QBarSetPrivate::insert(const int index, const qreal value) | |
569 | { |
|
569 | { | |
570 | m_values.insert(index, QPointF(index, value)); |
|
570 | m_values.insert(index, QPointF(index, value)); | |
571 | emit restructuredBars(); |
|
571 | emit restructuredBars(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
574 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
575 | { |
|
575 | { | |
576 | m_values.insert(index, value); |
|
576 | m_values.insert(index, value); | |
577 | emit restructuredBars(); |
|
577 | emit restructuredBars(); | |
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | int QBarSetPrivate::remove(const int index, const int count) |
|
580 | int QBarSetPrivate::remove(const int index, const int count) | |
581 | { |
|
581 | { | |
582 | int removeCount = count; |
|
582 | int removeCount = count; | |
583 |
|
583 | |||
584 | if ((index <0) || (m_values.count() == 0)) { |
|
584 | if ((index <0) || (m_values.count() == 0)) { | |
585 | // Invalid index or not values in list, remove nothing. |
|
585 | // Invalid index or not values in list, remove nothing. | |
586 | return 0; |
|
586 | return 0; | |
587 | } else if ((index + count) > m_values.count()) { |
|
587 | } else if ((index + count) > m_values.count()) { | |
588 | // Trying to remove more items than list has. Limit amount to be removed. |
|
588 | // Trying to remove more items than list has. Limit amount to be removed. | |
589 | removeCount = m_values.count() - index; |
|
589 | removeCount = m_values.count() - index; | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | int c = 0; |
|
592 | int c = 0; | |
593 | while (c < removeCount) { |
|
593 | while (c < removeCount) { | |
594 | m_values.removeAt(index); |
|
594 | m_values.removeAt(index); | |
595 | c++; |
|
595 | c++; | |
596 | } |
|
596 | } | |
597 | emit restructuredBars(); |
|
597 | emit restructuredBars(); | |
598 | return removeCount; |
|
598 | return removeCount; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
601 | void QBarSetPrivate::replace(const int index, const qreal value) | |
602 | { |
|
602 | { | |
603 | m_values.replace(index,QPointF(index,value)); |
|
603 | m_values.replace(index,QPointF(index,value)); | |
604 | emit updatedBars(); |
|
604 | emit updatedBars(); | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
607 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
608 | { |
|
608 | { | |
609 | m_values.replace(index,value); |
|
609 | m_values.replace(index,value); | |
610 | emit updatedBars(); |
|
610 | emit updatedBars(); | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | #include "moc_qbarset.cpp" |
|
613 | #include "moc_qbarset.cpp" | |
614 | #include "moc_qbarset_p.cpp" |
|
614 | #include "moc_qbarset_p.cpp" | |
615 |
|
615 | |||
616 | QTCOMMERCIALCHART_END_NAMESPACE |
|
616 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,119 +1,119 | |||||
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 "qgroupedbarseries.h" |
|
21 | #include "qgroupedbarseries.h" | |
22 | #include "qgroupedbarseries_p.h" |
|
22 | #include "qgroupedbarseries_p.h" | |
23 | #include "groupedbarchartitem_p.h" |
|
23 | #include "groupedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include "qcategoriesaxis.h" |
|
27 | #include "qcategoriesaxis.h" | |
28 | #include "qvaluesaxis.h" |
|
28 | #include "qvaluesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QGroupedBarSeries |
|
33 | \class QGroupedBarSeries | |
34 | \brief Series for creating grouped bar chart |
|
34 | \brief Series for creating grouped bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data | |
39 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
42 | \image examples_groupedbarchart.png |
|
42 | \image examples_groupedbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass GroupedBarSeries QGroupedBarSeries |
|
47 | \qmlclass GroupedBarSeries QGroupedBarSeries | |
48 | \inherits BarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple grouped bar chart: |
|
50 | The following QML shows how to create a simple grouped bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart7.png |
|
53 | \image demos_qmlchart7.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QGroupedBarSeries. |
|
59 | Constructs empty QGroupedBarSeries. | |
60 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
60 | QGroupedBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
62 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
68 | Returns QChartSeries::SeriesTypeGroupedBar. | |
69 | */ |
|
69 | */ | |
70 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |
71 | { |
|
71 | { | |
72 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
72 | return QAbstractSeries::SeriesTypeGroupedBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
76 |
|
76 | |||
77 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
77 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
78 | { |
|
78 | { | |
79 |
|
79 | |||
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
82 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |
83 | { |
|
83 | { | |
84 | qreal minX(domain.minX()); |
|
84 | qreal minX(domain.minX()); | |
85 | qreal minY(domain.minY()); |
|
85 | qreal minY(domain.minY()); | |
86 | qreal maxX(domain.maxX()); |
|
86 | qreal maxX(domain.maxX()); | |
87 | qreal maxY(domain.maxY()); |
|
87 | qreal maxY(domain.maxY()); | |
88 | int tickXCount(domain.tickXCount()); |
|
88 | int tickXCount(domain.tickXCount()); | |
89 | int tickYCount(domain.tickYCount()); |
|
89 | int tickYCount(domain.tickYCount()); | |
90 |
|
90 | |||
91 | qreal x = categoryCount(); |
|
91 | qreal x = categoryCount(); | |
92 | qreal y = max(); |
|
92 | qreal y = max(); | |
93 | minX = qMin(minX, -0.5); |
|
93 | minX = qMin(minX, -0.5); | |
94 | minY = qMin(minY, y); |
|
94 | minY = qMin(minY, y); | |
95 | maxX = qMax(maxX, x - 0.5); |
|
95 | maxX = qMax(maxX, x - 0.5); | |
96 | maxY = qMax(maxY, y); |
|
96 | maxY = qMax(maxY, y); | |
97 | tickXCount = x+1; |
|
97 | tickXCount = x+1; | |
98 |
|
98 | |||
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
103 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
104 | { |
|
104 | { | |
105 | Q_Q(QGroupedBarSeries); |
|
105 | Q_Q(QGroupedBarSeries); | |
106 |
|
106 | |||
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
109 | presenter->animator()->addAnimation(bar); |
|
109 | presenter->animator()->addAnimation(bar); | |
110 | } |
|
110 | } | |
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
112 | return bar; |
|
112 | return bar; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | #include "moc_qgroupedbarseries.cpp" |
|
116 | #include "moc_qgroupedbarseries.cpp" | |
117 |
|
117 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
118 | QTCOMMERCIALCHART_END_NAMESPACE | |
119 |
|
119 |
@@ -1,249 +1,249 | |||||
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 "qhbarmodelmapper.h" |
|
21 | #include "qhbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHBarModelMapper |
|
26 | \class QHBarModelMapper | |
27 | \brief Horizontal model mapper for bar series |
|
27 | \brief Horizontal model mapper for bar series | |
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 QAbstractBarSeries and QAbstractItemModel derived model object. |
|
31 | Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass HBarModelMapper QHBarModelMapper |
|
37 | \qmlclass HBarModelMapper QHBarModelMapper | |
38 |
|
38 | |||
39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
41 | HBarModelMapper keeps the series and the model in sync. |
|
41 | HBarModelMapper keeps the series and the model in sync. | |
42 |
|
42 | |||
43 | The following QML example would create a bar series with three bar sets (assuming the model has |
|
43 | The following QML example would create a bar series with three bar sets (assuming the model has | |
44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by |
|
44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by | |
45 | the vertical header (of the row). |
|
45 | the vertical header (of the row). | |
46 | \code |
|
46 | \code | |
47 | BarSeries { |
|
47 | BarSeries { | |
48 | HBarModelMapper { |
|
48 | HBarModelMapper { | |
49 | model: myCustomModel // QAbstractItemModel derived implementation |
|
49 | model: myCustomModel // QAbstractItemModel derived implementation | |
50 | firstBarSetRow: 1 |
|
50 | firstBarSetRow: 1 | |
51 | lastBarSetRow: 3 |
|
51 | lastBarSetRow: 3 | |
52 | firstColumn: 1 |
|
52 | firstColumn: 1 | |
53 | } |
|
53 | } | |
54 | } |
|
54 | } | |
55 | \endcode |
|
55 | \endcode | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QHBarModelMapper::series |
|
59 | \property QHBarModelMapper::series | |
60 | \brief Defines the QPieSeries object that is used by the mapper. |
|
60 | \brief Defines the QPieSeries object that is used by the mapper. | |
61 |
|
61 | |||
62 | All the data in the series is discarded when it is set to the mapper. |
|
62 | All the data in the series is discarded when it is set to the mapper. | |
63 | When new series is specified the old series is disconnected (it preserves its data) |
|
63 | When new series is specified the old series is disconnected (it preserves its data) | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty BarSeries HBarModelMapper::series |
|
66 | \qmlproperty AbstractBarSeries HBarModelMapper::series | |
67 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
67 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QHBarModelMapper::model |
|
72 | \property QHBarModelMapper::model | |
73 | \brief Defines the model that is used by the mapper. |
|
73 | \brief Defines the model that is used by the mapper. | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlproperty SomeModel HBarModelMapper::model |
|
76 | \qmlproperty SomeModel HBarModelMapper::model | |
77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
78 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
78 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
79 | and modifying the data of the cells. |
|
79 | and modifying the data of the cells. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \property QHBarModelMapper::firstBarSetRow |
|
83 | \property QHBarModelMapper::firstBarSetRow | |
84 | \brief Defines which column of the model is used as the data source for the first bar set |
|
84 | \brief Defines which column of the model is used as the data source for the first bar set | |
85 | Default value is: -1 (invalid mapping) |
|
85 | Default value is: -1 (invalid mapping) | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty int HBarModelMapper::firstBarSetRow |
|
88 | \qmlproperty int HBarModelMapper::firstBarSetRow | |
89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 |
|
89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 | |
90 | (invalid mapping). |
|
90 | (invalid mapping). | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QHBarModelMapper::lastBarSetRow |
|
94 | \property QHBarModelMapper::lastBarSetRow | |
95 | \brief Defines which column of the model is used as the data source for the last bar set |
|
95 | \brief Defines which column of the model is used as the data source for the last bar set | |
96 | Default value is: -1 (invalid mapping) |
|
96 | Default value is: -1 (invalid mapping) | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty int HBarModelMapper::lastBarSetRow |
|
99 | \qmlproperty int HBarModelMapper::lastBarSetRow | |
100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 |
|
100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 | |
101 | (invalid mapping). |
|
101 | (invalid mapping). | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QHBarModelMapper::firstColumn |
|
105 | \property QHBarModelMapper::firstColumn | |
106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. | |
107 | Minimal and default value is: 0 |
|
107 | Minimal and default value is: 0 | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty int HBarModelMapper::firstColumn |
|
110 | \qmlproperty int HBarModelMapper::firstColumn | |
111 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
111 | Defines which column of the model contains the first values of the QBarSets in the series. | |
112 | The default value is 0. |
|
112 | The default value is 0. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \property QHBarModelMapper::columnCount |
|
116 | \property QHBarModelMapper::columnCount | |
117 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries |
|
117 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries | |
118 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
118 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlproperty int HBarModelMapper::columnCount |
|
121 | \qmlproperty int HBarModelMapper::columnCount | |
122 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
122 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
123 | -1 (count limited by the number of columns in the model) |
|
123 | -1 (count limited by the number of columns in the model) | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QHBarModelMapper::seriesReplaced() |
|
127 | \fn void QHBarModelMapper::seriesReplaced() | |
128 |
|
128 | |||
129 | Emitted when the series to which mapper is connected to has changed. |
|
129 | Emitted when the series to which mapper is connected to has changed. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QHBarModelMapper::modelReplaced() |
|
133 | \fn void QHBarModelMapper::modelReplaced() | |
134 |
|
134 | |||
135 | Emitted when the model to which mapper is connected to has changed. |
|
135 | Emitted when the model to which mapper is connected to has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
139 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
140 |
|
140 | |||
141 | Emitted when the firstBarSetRow has changed. |
|
141 | Emitted when the firstBarSetRow has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
145 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
146 |
|
146 | |||
147 | Emitted when the lastBarSetRow has changed. |
|
147 | Emitted when the lastBarSetRow has changed. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QHBarModelMapper::firstColumnChanged() |
|
151 | \fn void QHBarModelMapper::firstColumnChanged() | |
152 | Emitted when the firstColumn has changed. |
|
152 | Emitted when the firstColumn has changed. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QHBarModelMapper::columnCountChanged() |
|
156 | \fn void QHBarModelMapper::columnCountChanged() | |
157 | Emitted when the columnCount has changed. |
|
157 | Emitted when the columnCount has changed. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Constructs a mapper object which is a child of \a parent. |
|
161 | Constructs a mapper object which is a child of \a parent. | |
162 | */ |
|
162 | */ | |
163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
164 | QBarModelMapper(parent) |
|
164 | QBarModelMapper(parent) | |
165 | { |
|
165 | { | |
166 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
166 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | QAbstractItemModel* QHBarModelMapper::model() const |
|
169 | QAbstractItemModel* QHBarModelMapper::model() const | |
170 | { |
|
170 | { | |
171 | return QBarModelMapper::model(); |
|
171 | return QBarModelMapper::model(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) |
|
174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) | |
175 | { |
|
175 | { | |
176 | if (model != QBarModelMapper::model()) { |
|
176 | if (model != QBarModelMapper::model()) { | |
177 | QBarModelMapper::setModel(model); |
|
177 | QBarModelMapper::setModel(model); | |
178 | emit modelReplaced(); |
|
178 | emit modelReplaced(); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | QAbstractBarSeries* QHBarModelMapper::series() const |
|
182 | QAbstractBarSeries* QHBarModelMapper::series() const | |
183 | { |
|
183 | { | |
184 | return QBarModelMapper::series(); |
|
184 | return QBarModelMapper::series(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) | |
188 | { |
|
188 | { | |
189 | if (series != QBarModelMapper::series()) { |
|
189 | if (series != QBarModelMapper::series()) { | |
190 | QBarModelMapper::setSeries(series); |
|
190 | QBarModelMapper::setSeries(series); | |
191 | emit seriesReplaced(); |
|
191 | emit seriesReplaced(); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | int QHBarModelMapper::firstBarSetRow() const |
|
195 | int QHBarModelMapper::firstBarSetRow() const | |
196 | { |
|
196 | { | |
197 | return QBarModelMapper::firstBarSetSection(); |
|
197 | return QBarModelMapper::firstBarSetSection(); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
201 | { |
|
201 | { | |
202 | if (firstBarSetRow != firstBarSetSection()) { |
|
202 | if (firstBarSetRow != firstBarSetSection()) { | |
203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
204 | emit firstBarSetRowChanged(); |
|
204 | emit firstBarSetRowChanged(); | |
205 | } |
|
205 | } | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | int QHBarModelMapper::lastBarSetRow() const |
|
208 | int QHBarModelMapper::lastBarSetRow() const | |
209 | { |
|
209 | { | |
210 | return QBarModelMapper::lastBarSetSection(); |
|
210 | return QBarModelMapper::lastBarSetSection(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
214 | { |
|
214 | { | |
215 | if (lastBarSetRow != lastBarSetSection()) { |
|
215 | if (lastBarSetRow != lastBarSetSection()) { | |
216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
217 | emit lastBarSetRowChanged(); |
|
217 | emit lastBarSetRowChanged(); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | int QHBarModelMapper::firstColumn() const |
|
221 | int QHBarModelMapper::firstColumn() const | |
222 | { |
|
222 | { | |
223 | return QBarModelMapper::first(); |
|
223 | return QBarModelMapper::first(); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
226 | void QHBarModelMapper::setFirstColumn(int firstColumn) | |
227 | { |
|
227 | { | |
228 | if (firstColumn != first()) { |
|
228 | if (firstColumn != first()) { | |
229 | QBarModelMapper::setFirst(firstColumn); |
|
229 | QBarModelMapper::setFirst(firstColumn); | |
230 | emit firstColumnChanged(); |
|
230 | emit firstColumnChanged(); | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | int QHBarModelMapper::columnCount() const |
|
234 | int QHBarModelMapper::columnCount() const | |
235 | { |
|
235 | { | |
236 | return QBarModelMapper::count(); |
|
236 | return QBarModelMapper::count(); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
239 | void QHBarModelMapper::setColumnCount(int columnCount) | |
240 | { |
|
240 | { | |
241 | if (columnCount != count()) { |
|
241 | if (columnCount != count()) { | |
242 | QBarModelMapper::setCount(columnCount); |
|
242 | QBarModelMapper::setCount(columnCount); | |
243 | emit firstColumnChanged(); |
|
243 | emit firstColumnChanged(); | |
244 | } |
|
244 | } | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | #include "moc_qhbarmodelmapper.cpp" |
|
247 | #include "moc_qhbarmodelmapper.cpp" | |
248 |
|
248 | |||
249 | QTCOMMERCIALCHART_END_NAMESPACE |
|
249 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,120 | |||||
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 "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include "qcategoriesaxis.h" |
|
27 | #include "qcategoriesaxis.h" | |
28 | #include "qvaluesaxis.h" |
|
28 | #include "qvaluesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QStackedBarSeries |
|
33 | \class QStackedBarSeries | |
34 | \brief Series for creating stacked bar chart |
|
34 | \brief Series for creating stacked bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as stacks, where bars in same category are stacked on top of each other. |
|
38 | as stacks, where bars in same category are stacked on top of each other. | |
39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
40 |
|
40 | |||
41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
42 | \image examples_stackedbarchart.png |
|
42 | \image examples_stackedbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \qmlclass StackedBarSeries QStackedBarSeries |
|
48 | \qmlclass StackedBarSeries QStackedBarSeries | |
49 | \inherits BarSeries |
|
49 | \inherits AbstractBarSeries | |
50 |
|
50 | |||
51 | The following QML shows how to create a simple stacked bar chart: |
|
51 | The following QML shows how to create a simple stacked bar chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image demos_qmlchart8.png |
|
54 | \image demos_qmlchart8.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | Constructs empty QStackedBarSeries. |
|
60 | Constructs empty QStackedBarSeries. | |
61 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
61 | QStackedBarSeries is QObject which is a child of a \a parent. | |
62 | */ |
|
62 | */ | |
63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
64 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
64 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Returns QChartSeries::SeriesTypeStackedBar. |
|
69 | Returns QChartSeries::SeriesTypeStackedBar. | |
70 | */ |
|
70 | */ | |
71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
72 | { |
|
72 | { | |
73 | return QAbstractSeries::SeriesTypeStackedBar; |
|
73 | return QAbstractSeries::SeriesTypeStackedBar; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
77 |
|
77 | |||
78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
84 | { |
|
84 | { | |
85 | qreal minX(domain.minX()); |
|
85 | qreal minX(domain.minX()); | |
86 | qreal minY(domain.minY()); |
|
86 | qreal minY(domain.minY()); | |
87 | qreal maxX(domain.maxX()); |
|
87 | qreal maxX(domain.maxX()); | |
88 | qreal maxY(domain.maxY()); |
|
88 | qreal maxY(domain.maxY()); | |
89 | int tickXCount(domain.tickXCount()); |
|
89 | int tickXCount(domain.tickXCount()); | |
90 | int tickYCount(domain.tickYCount()); |
|
90 | int tickYCount(domain.tickYCount()); | |
91 |
|
91 | |||
92 | qreal x = categoryCount(); |
|
92 | qreal x = categoryCount(); | |
93 | qreal y = maxCategorySum(); |
|
93 | qreal y = maxCategorySum(); | |
94 | minX = qMin(minX, -0.5); |
|
94 | minX = qMin(minX, -0.5); | |
95 | minY = qMin(minY, y); |
|
95 | minY = qMin(minY, y); | |
96 | maxX = qMax(maxX, x - 0.5); |
|
96 | maxX = qMax(maxX, x - 0.5); | |
97 | maxY = qMax(maxY, y); |
|
97 | maxY = qMax(maxY, y); | |
98 | tickXCount = x+1; |
|
98 | tickXCount = x+1; | |
99 |
|
99 | |||
100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 |
|
103 | |||
104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
105 | { |
|
105 | { | |
106 | Q_Q(QStackedBarSeries); |
|
106 | Q_Q(QStackedBarSeries); | |
107 |
|
107 | |||
108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
110 | presenter->animator()->addAnimation(bar); |
|
110 | presenter->animator()->addAnimation(bar); | |
111 | } |
|
111 | } | |
112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
113 | return bar; |
|
113 | return bar; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 |
|
116 | |||
117 | #include "moc_qstackedbarseries.cpp" |
|
117 | #include "moc_qstackedbarseries.cpp" | |
118 |
|
118 | |||
119 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE | |
120 |
|
120 |
@@ -1,248 +1,248 | |||||
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 "qvbarmodelmapper.h" |
|
21 | #include "qvbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVBarModelMapper |
|
26 | \class QVBarModelMapper | |
27 | \brief Vertical model mapper for bar series |
|
27 | \brief Vertical model mapper for bar series | |
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 QAbstractBarSeries and QAbstractItemModel derived model object. |
|
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass VBarModelMapper |
|
37 | \qmlclass VBarModelMapper | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
42 | VBarModelMapper keeps the series and the model in sync. |
|
42 | VBarModelMapper keeps the series and the model in sync. | |
43 |
|
43 | |||
44 | The following QML example would create a bar series with three bar sets (assuming the |
|
44 | The following QML example would create a bar series with three bar sets (assuming the | |
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be | |
46 | defined by the horizontal header (of the column). |
|
46 | defined by the horizontal header (of the column). | |
47 | \code |
|
47 | \code | |
48 | GroupedBarSeries { |
|
48 | GroupedBarSeries { | |
49 | VBarModelMapper { |
|
49 | VBarModelMapper { | |
50 | model: myCustomModel // QAbstractItemModel derived implementation |
|
50 | model: myCustomModel // QAbstractItemModel derived implementation | |
51 | firstBarSetColumn: 1 |
|
51 | firstBarSetColumn: 1 | |
52 | lastBarSetColumn: 3 |
|
52 | lastBarSetColumn: 3 | |
53 | firstRow: 1 |
|
53 | firstRow: 1 | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QVBarModelMapper::series |
|
60 | \property QVBarModelMapper::series | |
61 | \brief Defines the QPieSeries object that is used by the mapper. |
|
61 | \brief Defines the QPieSeries object that is used by the mapper. | |
62 |
|
62 | |||
63 | All the data in the series is discarded when it is set to the mapper. |
|
63 | All the data in the series is discarded when it is set to the mapper. | |
64 | When new series is specified the old series is disconnected (it preserves its data) |
|
64 | When new series is specified the old series is disconnected (it preserves its data) | |
65 | */ |
|
65 | */ | |
66 | /*! |
|
66 | /*! | |
67 | \qmlproperty BarSeries VBarModelMapper::series |
|
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series | |
68 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QVBarModelMapper::model |
|
73 | \property QVBarModelMapper::model | |
74 | \brief Defines the model that is used by the mapper. |
|
74 | \brief Defines the model that is used by the mapper. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty SomeModel VBarModelMapper::model |
|
77 | \qmlproperty SomeModel VBarModelMapper::model | |
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
80 | and modifying the data of the cells. |
|
80 | and modifying the data of the cells. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QVBarModelMapper::firstBarSetColumn |
|
84 | \property QVBarModelMapper::firstBarSetColumn | |
85 | \brief Defines which column of the model is used as the data source for the first bar set |
|
85 | \brief Defines which column of the model is used as the data source for the first bar set | |
86 | Default value is: -1 (invalid mapping) |
|
86 | Default value is: -1 (invalid mapping) | |
87 | */ |
|
87 | */ | |
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
90 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
90 | Defines which column of the model is used as the data source for the first bar set. Default value | |
91 | is: -1 (invalid mapping). |
|
91 | is: -1 (invalid mapping). | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QVBarModelMapper::lastBarSetColumn |
|
95 | \property QVBarModelMapper::lastBarSetColumn | |
96 | \brief Defines which column of the model is used as the data source for the last bar set |
|
96 | \brief Defines which column of the model is used as the data source for the last bar set | |
97 | Default value is: -1 (invalid mapping) |
|
97 | Default value is: -1 (invalid mapping) | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
101 | Defines which column of the model is used as the data source for the last bar set. Default |
|
101 | Defines which column of the model is used as the data source for the last bar set. Default | |
102 | value is: -1 (invalid mapping). |
|
102 | value is: -1 (invalid mapping). | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QVBarModelMapper::firstRow |
|
106 | \property QVBarModelMapper::firstRow | |
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |
108 | Minimal and default value is: 0 |
|
108 | Minimal and default value is: 0 | |
109 | */ |
|
109 | */ | |
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty int VBarModelMapper::firstRow |
|
111 | \qmlproperty int VBarModelMapper::firstRow | |
112 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
112 | Defines which row of the model contains the first values of the QBarSets in the series. | |
113 | The default value is 0. |
|
113 | The default value is 0. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \property QVBarModelMapper::rowCount |
|
117 | \property QVBarModelMapper::rowCount | |
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries |
|
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries | |
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty int VBarModelMapper::rowCount |
|
122 | \qmlproperty int VBarModelMapper::rowCount | |
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
124 | -1 (count limited by the number of rows in the model) |
|
124 | -1 (count limited by the number of rows in the model) | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QVBarModelMapper::seriesReplaced() |
|
128 | \fn void QVBarModelMapper::seriesReplaced() | |
129 |
|
129 | |||
130 | Emitted when the series to which mapper is connected to has changed. |
|
130 | Emitted when the series to which mapper is connected to has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QVBarModelMapper::modelReplaced() |
|
134 | \fn void QVBarModelMapper::modelReplaced() | |
135 |
|
135 | |||
136 | Emitted when the model to which mapper is connected to has changed. |
|
136 | Emitted when the model to which mapper is connected to has changed. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
141 | Emitted when the firstBarSetColumn has changed. |
|
141 | Emitted when the firstBarSetColumn has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
146 | Emitted when the lastBarSetColumn has changed. |
|
146 | Emitted when the lastBarSetColumn has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QVBarModelMapper::firstRowChanged() |
|
150 | \fn void QVBarModelMapper::firstRowChanged() | |
151 | Emitted when the firstRow has changed. |
|
151 | Emitted when the firstRow has changed. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QVBarModelMapper::rowCountChanged() |
|
155 | \fn void QVBarModelMapper::rowCountChanged() | |
156 | Emitted when the rowCount has changed. |
|
156 | Emitted when the rowCount has changed. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Constructs a mapper object which is a child of \a parent. |
|
160 | Constructs a mapper object which is a child of \a parent. | |
161 | */ |
|
161 | */ | |
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
163 | QBarModelMapper(parent) |
|
163 | QBarModelMapper(parent) | |
164 | { |
|
164 | { | |
165 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
165 | QBarModelMapper::setOrientation(Qt::Vertical); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QAbstractItemModel* QVBarModelMapper::model() const |
|
168 | QAbstractItemModel* QVBarModelMapper::model() const | |
169 | { |
|
169 | { | |
170 | return QBarModelMapper::model(); |
|
170 | return QBarModelMapper::model(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) | |
174 | { |
|
174 | { | |
175 | if (model != QBarModelMapper::model()) { |
|
175 | if (model != QBarModelMapper::model()) { | |
176 | QBarModelMapper::setModel(model); |
|
176 | QBarModelMapper::setModel(model); | |
177 | emit modelReplaced(); |
|
177 | emit modelReplaced(); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | QAbstractBarSeries* QVBarModelMapper::series() const |
|
181 | QAbstractBarSeries* QVBarModelMapper::series() const | |
182 | { |
|
182 | { | |
183 | return QBarModelMapper::series(); |
|
183 | return QBarModelMapper::series(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) | |
187 | { |
|
187 | { | |
188 | if (series != QBarModelMapper::series()) { |
|
188 | if (series != QBarModelMapper::series()) { | |
189 | QBarModelMapper::setSeries(series); |
|
189 | QBarModelMapper::setSeries(series); | |
190 | emit seriesReplaced(); |
|
190 | emit seriesReplaced(); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | int QVBarModelMapper::firstBarSetColumn() const |
|
194 | int QVBarModelMapper::firstBarSetColumn() const | |
195 | { |
|
195 | { | |
196 | return QBarModelMapper::firstBarSetSection(); |
|
196 | return QBarModelMapper::firstBarSetSection(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
200 | { |
|
200 | { | |
201 | if (firstBarSetColumn != firstBarSetSection()) { |
|
201 | if (firstBarSetColumn != firstBarSetSection()) { | |
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
203 | emit firstBarSetColumnChanged(); |
|
203 | emit firstBarSetColumnChanged(); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | int QVBarModelMapper::lastBarSetColumn() const |
|
207 | int QVBarModelMapper::lastBarSetColumn() const | |
208 | { |
|
208 | { | |
209 | return QBarModelMapper::lastBarSetSection(); |
|
209 | return QBarModelMapper::lastBarSetSection(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
213 | { |
|
213 | { | |
214 | if (lastBarSetColumn != lastBarSetSection()) { |
|
214 | if (lastBarSetColumn != lastBarSetSection()) { | |
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
216 | emit lastBarSetColumnChanged(); |
|
216 | emit lastBarSetColumnChanged(); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | int QVBarModelMapper::firstRow() const |
|
220 | int QVBarModelMapper::firstRow() const | |
221 | { |
|
221 | { | |
222 | return QBarModelMapper::first(); |
|
222 | return QBarModelMapper::first(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
225 | void QVBarModelMapper::setFirstRow(int firstRow) | |
226 | { |
|
226 | { | |
227 | if (firstRow != first()) { |
|
227 | if (firstRow != first()) { | |
228 | QBarModelMapper::setFirst(firstRow); |
|
228 | QBarModelMapper::setFirst(firstRow); | |
229 | emit firstRowChanged(); |
|
229 | emit firstRowChanged(); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | int QVBarModelMapper::rowCount() const |
|
233 | int QVBarModelMapper::rowCount() const | |
234 | { |
|
234 | { | |
235 | return QBarModelMapper::count(); |
|
235 | return QBarModelMapper::count(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | void QVBarModelMapper::setRowCount(int rowCount) |
|
238 | void QVBarModelMapper::setRowCount(int rowCount) | |
239 | { |
|
239 | { | |
240 | if (rowCount != count()) { |
|
240 | if (rowCount != count()) { | |
241 | QBarModelMapper::setCount(rowCount); |
|
241 | QBarModelMapper::setCount(rowCount); | |
242 | emit firstRowChanged(); |
|
242 | emit firstRowChanged(); | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | #include "moc_qvbarmodelmapper.cpp" |
|
246 | #include "moc_qvbarmodelmapper.cpp" | |
247 |
|
247 | |||
248 | QTCOMMERCIALCHART_END_NAMESPACE |
|
248 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now