@@ -1,289 +1,285 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qareaseries.h" |
|
22 | 22 | #include "qareaseries_p.h" |
|
23 | 23 | #include "qlineseries.h" |
|
24 | 24 | #include "areachartitem_p.h" |
|
25 | 25 | #include "legendmarker_p.h" |
|
26 | 26 | #include "domain_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \class QAreaSeries |
|
35 | 35 | \brief The QAreaSeries class is used for making area charts. |
|
36 | 36 | |
|
37 | 37 | \mainclass |
|
38 | 38 | |
|
39 | 39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
40 | 40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
41 | 41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
42 | 42 | In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
43 | 43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
44 | 44 | |
|
45 | 45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
46 | 46 | \image examples_areachart.png |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | \fn virtual QSeriesType QAreaSeries::type() const | |
|
51 | \brief Returns type of series. | |
|
52 | \sa QAbstractSeries, QSeriesType | |
|
53 | */ | |
|
54 | ||
|
55 | /*! | |
|
56 | 50 | \fn QLineSeries* QAreaSeries::upperSeries() const |
|
57 | 51 | \brief Returns upperSeries used to define one of area boundaries. |
|
58 | 52 | */ |
|
59 | 53 | |
|
60 | 54 | /*! |
|
61 | 55 | \fn QLineSeries* QAreaSeries::lowerSeries() const |
|
62 | 56 | \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries |
|
63 | 57 | this function return Null pointer. |
|
64 | 58 | */ |
|
65 | 59 | |
|
66 | 60 | /*! |
|
67 | 61 | \fn QPen QAreaSeries::pen() const |
|
68 | 62 | \brief Returns the pen used to draw line for this series. |
|
69 | 63 | \sa setPen() |
|
70 | 64 | */ |
|
71 | 65 | |
|
72 | 66 | /*! |
|
73 | 67 | \fn QPen QAreaSeries::brush() const |
|
74 | 68 | \brief Returns the brush used to draw line for this series. |
|
75 | 69 | \sa setBrush() |
|
76 | 70 | */ |
|
77 | 71 | |
|
78 | 72 | /*! |
|
79 | 73 | \fn bool QAreaSeries::pointsVisible() const |
|
80 | 74 | \brief Returns if the points are drawn for this series. |
|
81 | 75 | \sa setPointsVisible() |
|
82 | 76 | */ |
|
83 | 77 | |
|
84 | 78 | /*! |
|
85 | 79 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
86 | 80 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
87 | 81 | */ |
|
88 | 82 | |
|
89 | 83 | /*! |
|
90 | 84 | \fn void QAreaSeries::selected() |
|
91 | 85 | |
|
92 | 86 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
93 | 87 | implemented by the user of QAreaSeries API. |
|
94 | 88 | */ |
|
95 | 89 | |
|
96 | 90 | /*! |
|
97 | 91 | \fn void QAreaSeriesPrivate::updated() |
|
98 | 92 | \brief \internal |
|
99 | 93 | */ |
|
100 | 94 | |
|
101 | 95 | /*! |
|
102 | 96 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
103 | 97 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
104 | 98 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
105 | 99 | */ |
|
106 | 100 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
107 | 101 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) |
|
108 | 102 | { |
|
109 | 103 | } |
|
110 | 104 | |
|
111 | 105 | /*! |
|
112 | 106 | Constructs area series object without upper or lower series. |
|
113 | 107 | */ |
|
114 | 108 | QAreaSeries::QAreaSeries(QObject *parent) |
|
115 | 109 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
116 | 110 | { |
|
117 | 111 | } |
|
118 | 112 | |
|
119 | 113 | /*! |
|
120 | 114 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
121 | 115 | and are deleted when mentioned object are destroyed. |
|
122 | 116 | */ |
|
123 | 117 | QAreaSeries::~QAreaSeries() |
|
124 | 118 | { |
|
125 | 119 | } |
|
126 | 120 | |
|
127 | ||
|
121 | /*! | |
|
122 | Returns QChartSeries::SeriesTypeArea. | |
|
123 | */ | |
|
128 | 124 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
129 | 125 | { |
|
130 | 126 | return QAbstractSeries::SeriesTypeArea; |
|
131 | 127 | } |
|
132 | 128 | |
|
133 | 129 | void QAreaSeries::setUpperSeries(QLineSeries* series) |
|
134 | 130 | { |
|
135 | 131 | Q_D(QAreaSeries); |
|
136 | 132 | d->m_upperSeries = series; |
|
137 | 133 | } |
|
138 | 134 | |
|
139 | 135 | QLineSeries* QAreaSeries::upperSeries() const |
|
140 | 136 | { |
|
141 | 137 | Q_D(const QAreaSeries); |
|
142 | 138 | return d->m_upperSeries; |
|
143 | 139 | } |
|
144 | 140 | |
|
145 | 141 | void QAreaSeries::setLowerSeries(QLineSeries* series) |
|
146 | 142 | { |
|
147 | 143 | Q_D(QAreaSeries); |
|
148 | 144 | d->m_lowerSeries = series; |
|
149 | 145 | } |
|
150 | 146 | |
|
151 | 147 | QLineSeries* QAreaSeries::lowerSeries() const |
|
152 | 148 | { |
|
153 | 149 | Q_D(const QAreaSeries); |
|
154 | 150 | return d->m_lowerSeries; |
|
155 | 151 | } |
|
156 | 152 | |
|
157 | 153 | /*! |
|
158 | 154 | Sets \a pen used for drawing area outline. |
|
159 | 155 | */ |
|
160 | 156 | void QAreaSeries::setPen(const QPen &pen) |
|
161 | 157 | { |
|
162 | 158 | Q_D(QAreaSeries); |
|
163 | 159 | if (d->m_pen != pen) { |
|
164 | 160 | d->m_pen = pen; |
|
165 | 161 | emit d->updated(); |
|
166 | 162 | } |
|
167 | 163 | } |
|
168 | 164 | |
|
169 | 165 | QPen QAreaSeries::pen() const |
|
170 | 166 | { |
|
171 | 167 | Q_D(const QAreaSeries); |
|
172 | 168 | return d->m_pen; |
|
173 | 169 | } |
|
174 | 170 | |
|
175 | 171 | /*! |
|
176 | 172 | Sets \a brush used for filling the area. |
|
177 | 173 | */ |
|
178 | 174 | void QAreaSeries::setBrush(const QBrush &brush) |
|
179 | 175 | { |
|
180 | 176 | Q_D(QAreaSeries); |
|
181 | 177 | if (d->m_brush != brush) { |
|
182 | 178 | d->m_brush = brush; |
|
183 | 179 | emit d->updated(); |
|
184 | 180 | } |
|
185 | 181 | } |
|
186 | 182 | |
|
187 | 183 | QBrush QAreaSeries::brush() const |
|
188 | 184 | { |
|
189 | 185 | Q_D(const QAreaSeries); |
|
190 | 186 | return d->m_brush; |
|
191 | 187 | } |
|
192 | 188 | /*! |
|
193 | 189 | Sets if data points are \a visible and should be drawn on line. |
|
194 | 190 | */ |
|
195 | 191 | void QAreaSeries::setPointsVisible(bool visible) |
|
196 | 192 | { |
|
197 | 193 | Q_D(QAreaSeries); |
|
198 | 194 | if (d->m_pointsVisible != visible) { |
|
199 | 195 | d->m_pointsVisible = visible; |
|
200 | 196 | emit d->updated(); |
|
201 | 197 | } |
|
202 | 198 | } |
|
203 | 199 | |
|
204 | 200 | bool QAreaSeries::pointsVisible() const |
|
205 | 201 | { |
|
206 | 202 | Q_D(const QAreaSeries); |
|
207 | 203 | return d->m_pointsVisible; |
|
208 | 204 | } |
|
209 | 205 | |
|
210 | 206 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
211 | 207 | |
|
212 | 208 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : |
|
213 | 209 | QAbstractSeriesPrivate(q), |
|
214 | 210 | m_upperSeries(upperSeries), |
|
215 | 211 | m_lowerSeries(lowerSeries), |
|
216 | 212 | m_pointsVisible(false) |
|
217 | 213 | { |
|
218 | 214 | } |
|
219 | 215 | |
|
220 | 216 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) |
|
221 | 217 | { |
|
222 | 218 | Q_Q(QAreaSeries); |
|
223 | 219 | |
|
224 | 220 | qreal minX(domain.minX()); |
|
225 | 221 | qreal minY(domain.minY()); |
|
226 | 222 | qreal maxX(domain.maxX()); |
|
227 | 223 | qreal maxY(domain.maxY()); |
|
228 | 224 | int tickXCount(domain.tickXCount()); |
|
229 | 225 | int tickYCount(domain.tickYCount()); |
|
230 | 226 | |
|
231 | 227 | QLineSeries* upperSeries = q->upperSeries(); |
|
232 | 228 | QLineSeries* lowerSeries = q->lowerSeries(); |
|
233 | 229 | |
|
234 | 230 | const QList<QPointF>& points = upperSeries->points(); |
|
235 | 231 | |
|
236 | 232 | for (int i = 0; i < points.count(); i++) |
|
237 | 233 | { |
|
238 | 234 | qreal x = points[i].x(); |
|
239 | 235 | qreal y = points[i].y(); |
|
240 | 236 | minX = qMin(minX, x); |
|
241 | 237 | minY = qMin(minY, y); |
|
242 | 238 | maxX = qMax(maxX, x); |
|
243 | 239 | maxY = qMax(maxY, y); |
|
244 | 240 | } |
|
245 | 241 | if(lowerSeries) { |
|
246 | 242 | |
|
247 | 243 | const QList<QPointF>& points = lowerSeries->points(); |
|
248 | 244 | |
|
249 | 245 | for (int i = 0; i < points.count(); i++) |
|
250 | 246 | { |
|
251 | 247 | qreal x = points[i].x(); |
|
252 | 248 | qreal y = points[i].y(); |
|
253 | 249 | minX = qMin(minX, x); |
|
254 | 250 | minY = qMin(minY, y); |
|
255 | 251 | maxX = qMax(maxX, x); |
|
256 | 252 | maxY = qMax(maxY, y); |
|
257 | 253 | }} |
|
258 | 254 | |
|
259 | 255 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
260 | 256 | } |
|
261 | 257 | |
|
262 | 258 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
263 | 259 | { |
|
264 | 260 | Q_Q(QAreaSeries); |
|
265 | 261 | |
|
266 | 262 | AreaChartItem* area = new AreaChartItem(q,presenter); |
|
267 | 263 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
268 | 264 | area->upperLineItem()->setAnimator(presenter->animator()); |
|
269 | 265 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
270 | 266 | if(q->lowerSeries()) { |
|
271 | 267 | area->lowerLineItem()->setAnimator(presenter->animator()); |
|
272 | 268 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
273 | 269 | } |
|
274 | 270 | } |
|
275 | 271 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
276 | 272 | return area; |
|
277 | 273 | } |
|
278 | 274 | |
|
279 | 275 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) |
|
280 | 276 | { |
|
281 | 277 | Q_Q(QAreaSeries); |
|
282 | 278 | QList<LegendMarker*> list; |
|
283 | 279 | return list << new AreaLegendMarker(q,legend); |
|
284 | 280 | } |
|
285 | 281 | |
|
286 | 282 | #include "moc_qareaseries.cpp" |
|
287 | 283 | #include "moc_qareaseries_p.cpp" |
|
288 | 284 | |
|
289 | 285 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,108 +1,105 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qgroupedbarseries.h" |
|
22 | 22 | #include "qgroupedbarseries_p.h" |
|
23 | 23 | #include "groupedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QGroupedBarSeries |
|
32 | 32 | \brief part of QtCommercial chart API. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | 36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
37 | 37 | from sets to categories, which are defined by a QStringList. |
|
38 | 38 | |
|
39 | 39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
40 | 40 | \image examples_groupedbarchart.png |
|
41 | 41 | |
|
42 | 42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | \fn virtual QSeriesType QGroupedBarSeries::type() const | |
|
47 | \brief Returns type of series. | |
|
48 | \sa QAbstractSeries, QSeriesType | |
|
49 | */ | |
|
50 | ||
|
51 | /*! | |
|
52 | 46 | Constructs empty QGroupedBarSeries. |
|
53 | 47 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
54 | 48 | */ |
|
55 | 49 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
56 | 50 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
57 | 51 | { |
|
58 | 52 | } |
|
59 | 53 | |
|
54 | /*! | |
|
55 | Returns QChartSeries::SeriesTypeGroupedBar. | |
|
56 | */ | |
|
60 | 57 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
61 | 58 | { |
|
62 | 59 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
63 | 60 | } |
|
64 | 61 | |
|
65 | 62 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 | 63 | |
|
67 | 64 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) |
|
68 | 65 | { |
|
69 | 66 | |
|
70 | 67 | } |
|
71 | 68 | |
|
72 | 69 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
73 | 70 | { |
|
74 | 71 | qreal minX(domain.minX()); |
|
75 | 72 | qreal minY(domain.minY()); |
|
76 | 73 | qreal maxX(domain.maxX()); |
|
77 | 74 | qreal maxY(domain.maxY()); |
|
78 | 75 | int tickXCount(domain.tickXCount()); |
|
79 | 76 | int tickYCount(domain.tickYCount()); |
|
80 | 77 | |
|
81 | 78 | qreal x = categoryCount(); |
|
82 | 79 | qreal y = max(); |
|
83 | 80 | minX = qMin(minX, x) - 0.5; |
|
84 | 81 | minY = qMin(minY, y); |
|
85 | 82 | maxX = qMax(maxX, x) - 0.5; |
|
86 | 83 | maxY = qMax(maxY, y); |
|
87 | 84 | tickXCount = x+1; |
|
88 | 85 | |
|
89 | 86 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
90 | 87 | } |
|
91 | 88 | |
|
92 | 89 | |
|
93 | 90 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
94 | 91 | { |
|
95 | 92 | Q_Q(QGroupedBarSeries); |
|
96 | 93 | |
|
97 | 94 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
98 | 95 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
99 | 96 | presenter->animator()->addAnimation(bar); |
|
100 | 97 | } |
|
101 | 98 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
102 | 99 | return bar; |
|
103 | 100 | } |
|
104 | 101 | |
|
105 | 102 | #include "moc_qgroupedbarseries.cpp" |
|
106 | 103 | |
|
107 | 104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | 105 |
@@ -1,107 +1,104 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpercentbarseries.h" |
|
22 | 22 | #include "qpercentbarseries_p.h" |
|
23 | 23 | #include "percentbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QPercentBarSeries |
|
32 | 32 | \brief part of QtCommercial chart API. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | 36 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
37 | 37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
38 | 38 | |
|
39 | 39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
40 | 40 | \image examples_percentbarchart.png |
|
41 | 41 | |
|
42 | 42 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | \fn virtual QSeriesType QPercentBarSeries::type() const | |
|
47 | \brief Returns type of series. | |
|
48 | \sa QAbstractSeries, QSeriesType | |
|
49 | */ | |
|
50 | ||
|
51 | /*! | |
|
52 | 46 | Constructs empty QPercentBarSeries. |
|
53 | 47 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
54 | 48 | */ |
|
55 | 49 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
56 | 50 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
57 | 51 | { |
|
58 | 52 | } |
|
59 | 53 | |
|
54 | /*! | |
|
55 | Returns QChartSeries::SeriesTypePercentBar. | |
|
56 | */ | |
|
60 | 57 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
61 | 58 | { |
|
62 | 59 | return QAbstractSeries::SeriesTypePercentBar; |
|
63 | 60 | } |
|
64 | 61 | |
|
65 | 62 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 | 63 | |
|
67 | 64 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) |
|
68 | 65 | { |
|
69 | 66 | |
|
70 | 67 | } |
|
71 | 68 | |
|
72 | 69 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
73 | 70 | { |
|
74 | 71 | qreal minX(domain.minX()); |
|
75 | 72 | qreal minY(domain.minY()); |
|
76 | 73 | qreal maxX(domain.maxX()); |
|
77 | 74 | qreal maxY(domain.maxY()); |
|
78 | 75 | int tickXCount(domain.tickXCount()); |
|
79 | 76 | int tickYCount(domain.tickYCount()); |
|
80 | 77 | |
|
81 | 78 | qreal x = categoryCount(); |
|
82 | 79 | minX = qMin(minX, x) - 0.5; |
|
83 | 80 | maxX = qMax(maxX, x) - 0.5; |
|
84 | 81 | minY = 0; |
|
85 | 82 | maxY = 100; |
|
86 | 83 | tickXCount = x+1; |
|
87 | 84 | |
|
88 | 85 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | 86 | } |
|
90 | 87 | |
|
91 | 88 | |
|
92 | 89 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | 90 | { |
|
94 | 91 | Q_Q(QPercentBarSeries); |
|
95 | 92 | |
|
96 | 93 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
97 | 94 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | 95 | presenter->animator()->addAnimation(bar); |
|
99 | 96 | } |
|
100 | 97 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | 98 | return bar; |
|
102 | 99 | } |
|
103 | 100 | |
|
104 | 101 | #include "moc_qpercentbarseries.cpp" |
|
105 | 102 | |
|
106 | 103 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | 104 |
@@ -1,108 +1,105 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qstackedbarseries.h" |
|
22 | 22 | #include "qstackedbarseries_p.h" |
|
23 | 23 | #include "stackedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QStackedBarSeries |
|
32 | 32 | \brief part of QtCommercial chart API. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | 36 | as stacks, where bars in same category are stacked on top of each other. |
|
37 | 37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
38 | 38 | |
|
39 | 39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
40 | 40 | \image examples_stackedbarchart.png |
|
41 | 41 | |
|
42 | 42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | \fn virtual QSeriesType QStackedBarSeries::type() const | |
|
47 | \brief Returns type of series. | |
|
48 | \sa QAbstractSeries, QSeriesType | |
|
49 | */ | |
|
50 | ||
|
51 | /*! | |
|
52 | 46 | Constructs empty QStackedBarSeries. |
|
53 | 47 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
54 | 48 | */ |
|
55 | 49 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
56 | 50 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
57 | 51 | { |
|
58 | 52 | } |
|
59 | 53 | |
|
54 | /*! | |
|
55 | Returns QChartSeries::SeriesTypeStackedBar. | |
|
56 | */ | |
|
60 | 57 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
61 | 58 | { |
|
62 | 59 | return QAbstractSeries::SeriesTypeStackedBar; |
|
63 | 60 | } |
|
64 | 61 | |
|
65 | 62 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 | 63 | |
|
67 | 64 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) |
|
68 | 65 | { |
|
69 | 66 | |
|
70 | 67 | } |
|
71 | 68 | |
|
72 | 69 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
73 | 70 | { |
|
74 | 71 | qreal minX(domain.minX()); |
|
75 | 72 | qreal minY(domain.minY()); |
|
76 | 73 | qreal maxX(domain.maxX()); |
|
77 | 74 | qreal maxY(domain.maxY()); |
|
78 | 75 | int tickXCount(domain.tickXCount()); |
|
79 | 76 | int tickYCount(domain.tickYCount()); |
|
80 | 77 | |
|
81 | 78 | qreal x = categoryCount(); |
|
82 | 79 | qreal y = maxCategorySum(); |
|
83 | 80 | minX = qMin(minX, x) - 0.5; |
|
84 | 81 | minY = qMin(minY, y); |
|
85 | 82 | maxX = qMax(maxX, x) - 0.5; |
|
86 | 83 | maxY = qMax(maxY, y); |
|
87 | 84 | tickXCount = x+1; |
|
88 | 85 | |
|
89 | 86 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
90 | 87 | } |
|
91 | 88 | |
|
92 | 89 | |
|
93 | 90 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
94 | 91 | { |
|
95 | 92 | Q_Q(QStackedBarSeries); |
|
96 | 93 | |
|
97 | 94 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
98 | 95 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
99 | 96 | presenter->animator()->addAnimation(bar); |
|
100 | 97 | } |
|
101 | 98 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
102 | 99 | return bar; |
|
103 | 100 | } |
|
104 | 101 | |
|
105 | 102 | #include "moc_qstackedbarseries.cpp" |
|
106 | 103 | |
|
107 | 104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | 105 |
General Comments 0
You need to be logged in to leave comments.
Login now