##// END OF EJS Templates
Added insert method to QBarSeries
Marek Rosa -
r1362:978d41b59ab7
parent child
Show More
@@ -1,94 +1,94
1 /*!
1 /*!
2 \page classes.html
2 \page classes.html
3 \title QtCommercial Charts API
3 \title QtCommercial Charts API
4 \keyword All Classes
4 \keyword All Classes
5
5
6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
8 The API supports following chart types:
8 The API supports following chart types:
9
9
10 \list
10 \list
11 \o area
11 \o area
12 \o line
12 \o line
13 \o bar
13 \o bar
14 \o percent bar
14 \o percent bar
15 \o pie
15 \o pie
16 \o scatter
16 \o scatter
17 \o spline
17 \o spline
18 \o stacked bar
18 \o stacked bar
19 \endlist
19 \endlist
20
20
21
21
22 Each chart type is represented by QSeries derived class. To create given chart type users have to use instace of releted sereis class and add it to QChart/QChartView instance.
22 Each chart type is represented by QSeries derived class. To create given chart type users have to use instace of releted sereis class and add it to QChart/QChartView instance.
23 \code
23 \code
24 QLineSeries* series = new QLineSeries();
24 QLineSeries* series = new QLineSeries();
25 series->add(0, 6);
25 series->add(0, 6);
26 series->add(2, 4);
26 series->add(2, 4);
27 ...
27 ...
28 chartView->addSeries(series);
28 chart->addSeries(series);
29 \endcode
29 \endcode
30
30
31 \raw HTML
31 \raw HTML
32 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
32 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
33 <tr>
33 <tr>
34 <th class="titleheader" width="33%">
34 <th class="titleheader" width="33%">
35 List of classes
35 List of classes
36 </th>
36 </th>
37 </tr>
37 </tr>
38 <tr>
38 <tr>
39 <td valign="top">
39 <td valign="top">
40 <ul>
40 <ul>
41 <li><a href="qareaseries.html">QAreaSeries</a></li>
41 <li><a href="qareaseries.html">QAreaSeries</a></li>
42 <li><a href="qbarseries.html">QBarSeries</a></li>
42 <li><a href="qbarseries.html">QBarSeries</a></li>
43 <li><a href="qbarset.html">QBarSet</a></li>
43 <li><a href="qbarset.html">QBarSet</a></li>
44 <li><a href="qchart.html">QChart</a></li>
44 <li><a href="qchart.html">QChart</a></li>
45 <li><a href="qaxis.html">QAxis</a></li>
45 <li><a href="qaxis.html">QAxis</a></li>
46 <li><a href="qchartview.html">QChartView</a></li>
46 <li><a href="qchartview.html">QChartView</a></li>
47 <li><a href="qlineseries.html">QLineSeries</a></li>
47 <li><a href="qlineseries.html">QLineSeries</a></li>
48 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
48 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
49 <li><a href="qpieseries.html">QPieSeries</a></li>
49 <li><a href="qpieseries.html">QPieSeries</a></li>
50 <li><a href="qpieslice.html">QPieSlice</a></li>
50 <li><a href="qpieslice.html">QPieSlice</a></li>
51 <li><a href="qscatterseries.html">QScatterSeries</a></li>
51 <li><a href="qscatterseries.html">QScatterSeries</a></li>
52 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
52 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
53 <li><a href="qsplineseries.html">QSplineSeries</a></li>
53 <li><a href="qsplineseries.html">QSplineSeries</a></li>
54 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
54 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
55 <li><a href="qxyseries.html">QXYSeries</a></li>
55 <li><a href="qxyseries.html">QXYSeries</a></li>
56 <li><a href="qlegend.html">QLegend</a></li>
56 <li><a href="qlegend.html">QLegend</a></li>
57 <li><a href="qpiemodelmapper.html">QPieModelMapper</a></li>
57 <li><a href="qpiemodelmapper.html">QPieModelMapper</a></li>
58 <ul>
58 <ul>
59 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
59 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
60 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
60 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
61 </ul>
61 </ul>
62 <li><a href="qbarmodelmapper.html">QBarModelMapper</a></li>
62 <li><a href="qbarmodelmapper.html">QBarModelMapper</a></li>
63 <ul>
63 <ul>
64 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
64 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
65 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
65 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
66 </ul>
66 </ul>
67 <li><a href="qxymodelmapper.html">QXYModelMapper</a></li>
67 <li><a href="qxymodelmapper.html">QXYModelMapper</a></li>
68 <ul>
68 <ul>
69 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
69 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
70 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
70 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
71 </ul>
71 </ul>
72 </ul>
72 </ul>
73 </td>
73 </td>
74 </tr>
74 </tr>
75 </table>
75 </table>
76
76
77 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
77 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
78 <tr>
78 <tr>
79 <th class="titleheader" width="33%">
79 <th class="titleheader" width="33%">
80 Other files:
80 Other files:
81 </th>
81 </th>
82 </tr>
82 </tr>
83 <tr>
83 <tr>
84 <td valign="top">
84 <td valign="top">
85 <ul>
85 <ul>
86 <li><a href="qchartglobal.html">QChartGlobal</a></li>
86 <li><a href="qchartglobal.html">QChartGlobal</a></li>
87 </ul>
87 </ul>
88 </td>
88 </td>
89 </tr>
89 </tr>
90 </table>
90 </table>
91
91
92 \endraw
92 \endraw
93
93
94 */
94 */
@@ -1,616 +1,650
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 "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_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
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QBarSeries
34 \class QBarSeries
35 \brief part of QtCommercial chart API.
35 \brief part of QtCommercial chart API.
36 \mainclass
36 \mainclass
37
37
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 shows the x-values.
41 shows the x-values.
42
42
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 \image examples_barchart.png
44 \image examples_barchart.png
45
45
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 */
47 */
48
48
49 /*!
49 /*!
50 \property QBarSeries::barMargin
50 \property QBarSeries::barMargin
51 \brief Defines the margin around bars.
51 \brief Defines the margin around bars.
52
52
53 Value is from 0 to 1 and represents
53 Value is from 0 to 1 and represents
54 percentage of margin compared to bars
54 percentage of margin compared to bars
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QBarSeries::count
58 \property QBarSeries::count
59 \brief Holds the number of sets in series.
59 \brief Holds the number of sets in series.
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QBarSeries::labelsVisible
63 \property QBarSeries::labelsVisible
64 \brief Defines the visibility of the labels in series
64 \brief Defines the visibility of the labels in series
65 */
65 */
66
66
67 /*!
67 /*!
68 \fn void QBarSeries::clicked(QBarSet *barset, int index)
68 \fn void QBarSeries::clicked(QBarSet *barset, int index)
69
69
70 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
70 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
71 Clicked bar inside set is indexed by \a index
71 Clicked bar inside set is indexed by \a index
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
75 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
76
76
77 The signal is emitted if mouse is hovered on top of series.
77 The signal is emitted if mouse is hovered on top of series.
78 Parameter \a barset is the pointer of barset, where hover happened.
78 Parameter \a barset is the pointer of barset, where hover happened.
79 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
79 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
80 */
80 */
81
81
82 /*!
82 /*!
83 \fn void QBarSeries::visibleChanged()
83 \fn void QBarSeries::visibleChanged()
84 */
84 */
85
85
86 /*!
86 /*!
87 \fn void QBarSeries::labelsVisibleChanged()
87 \fn void QBarSeries::labelsVisibleChanged()
88
88
89 This signal is emitted when labels visibility have changed.
89 This signal is emitted when labels visibility have changed.
90
90
91 \sa labelsVisible(), setLabelsVisible()
91 \sa isLabelsVisible(), setLabelsVisible()
92 */
92 */
93
93
94 /*!
94 /*!
95 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
95 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
96
96
97 This signal is emitted when \a sets have been added to the series.
97 This signal is emitted when \a sets have been added to the series.
98
98
99 \sa append(), insert()
99 \sa append(), insert()
100 */
100 */
101
101
102 /*!
102 /*!
103 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
103 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
104
104
105 This signal is emitted when \a sets have been removed from the series.
105 This signal is emitted when \a sets have been removed from the series.
106
106
107 \sa remove()
107 \sa remove()
108 */
108 */
109
109
110 /*!
110 /*!
111 Constructs empty QBarSeries.
111 Constructs empty QBarSeries.
112 QBarSeries is QObject which is a child of a \a parent.
112 QBarSeries is QObject which is a child of a \a parent.
113 */
113 */
114 QBarSeries::QBarSeries(QObject *parent) :
114 QBarSeries::QBarSeries(QObject *parent) :
115 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
115 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
116 {
116 {
117 }
117 }
118
118
119 /*!
119 /*!
120 Destructs barseries and owned barsets.
120 Destructs barseries and owned barsets.
121 */
121 */
122 QBarSeries::~QBarSeries()
122 QBarSeries::~QBarSeries()
123 {
123 {
124 Q_D(QBarSeries);
124 Q_D(QBarSeries);
125 if(d->m_dataset){
125 if(d->m_dataset){
126 d->m_dataset->removeSeries(this);
126 d->m_dataset->removeSeries(this);
127 }
127 }
128 }
128 }
129
129
130 /*!
130 /*!
131 \internal
131 \internal
132 */
132 */
133 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
133 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
134 QAbstractSeries(d,parent)
134 QAbstractSeries(d,parent)
135 {
135 {
136 }
136 }
137
137
138 /*!
138 /*!
139 Returns the type of series. Derived classes override this.
139 Returns the type of series. Derived classes override this.
140 */
140 */
141 QAbstractSeries::SeriesType QBarSeries::type() const
141 QAbstractSeries::SeriesType QBarSeries::type() const
142 {
142 {
143 return QAbstractSeries::SeriesTypeBar;
143 return QAbstractSeries::SeriesTypeBar;
144 }
144 }
145
145
146 /*!
146 /*!
147 Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents
147 Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents
148 percentage of margin compared to bars
148 percentage of margin compared to bars
149 */
149 */
150 void QBarSeries::setBarMargin(qreal margin)
150 void QBarSeries::setBarMargin(qreal margin)
151 {
151 {
152 Q_D(QBarSeries);
152 Q_D(QBarSeries);
153 d->setBarMargin(margin);
153 d->setBarMargin(margin);
154 }
154 }
155
155
156 /*!
156 /*!
157 Returns the margin around bars
157 Returns the margin around bars
158 */
158 */
159 qreal QBarSeries::barMargin() const
159 qreal QBarSeries::barMargin() const
160 {
160 {
161 Q_D(const QBarSeries);
161 Q_D(const QBarSeries);
162 return d->barMargin();
162 return d->barMargin();
163 }
163 }
164
164
165 /*!
165 /*!
166 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.
166 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.
167 Returns true, if appending succeeded.
167 Returns true, if appending succeeded.
168
168
169 */
169 */
170 bool QBarSeries::append(QBarSet *set)
170 bool QBarSeries::append(QBarSet *set)
171 {
171 {
172 Q_D(QBarSeries);
172 Q_D(QBarSeries);
173 bool success = d->append(set);
173 bool success = d->append(set);
174 if (success) {
174 if (success) {
175 QList<QBarSet*> sets;
175 QList<QBarSet*> sets;
176 sets.append(set);
176 sets.append(set);
177 emit barsetsAdded(sets);
177 emit barsetsAdded(sets);
178 }
178 }
179 return success;
179 return success;
180 }
180 }
181
181
182 /*!
182 /*!
183 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
183 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
184 Returns true, if set was removed.
184 Returns true, if set was removed.
185 */
185 */
186 bool QBarSeries::remove(QBarSet *set)
186 bool QBarSeries::remove(QBarSet *set)
187 {
187 {
188 Q_D(QBarSeries);
188 Q_D(QBarSeries);
189 bool success = d->remove(set);
189 bool success = d->remove(set);
190 if (success) {
190 if (success) {
191 QList<QBarSet*> sets;
191 QList<QBarSet*> sets;
192 sets.append(set);
192 sets.append(set);
193 emit barsetsRemoved(sets);
193 emit barsetsRemoved(sets);
194 }
194 }
195 return success;
195 return success;
196 }
196 }
197
197
198 /*!
198 /*!
199 Adds a list of barsets to series. Takes ownership of \a sets.
199 Adds a list of barsets to series. Takes ownership of \a sets.
200 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
200 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
201 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
201 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
202 and function returns false.
202 and function returns false.
203 */
203 */
204 bool QBarSeries::append(QList<QBarSet* > sets)
204 bool QBarSeries::append(QList<QBarSet* > sets)
205 {
205 {
206 Q_D(QBarSeries);
206 Q_D(QBarSeries);
207 bool success = d->append(sets);
207 bool success = d->append(sets);
208 if (success) {
208 if (success) {
209 emit barsetsAdded(sets);
209 emit barsetsAdded(sets);
210 }
210 }
211 return success;
211 return success;
212 }
212 }
213
213
214 /*!
214 /*!
215 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
215 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
216 */
216 */
217 bool QBarSeries::remove(QList<QBarSet* > sets)
217 bool QBarSeries::remove(QList<QBarSet* > sets)
218 {
218 {
219 Q_D(QBarSeries);
219 Q_D(QBarSeries);
220 bool success = d->remove(sets);
220 bool success = d->remove(sets);
221 if (success) {
221 if (success) {
222 emit barsetsRemoved(sets);
222 emit barsetsRemoved(sets);
223 }
223 }
224 return success;
224 return success;
225 }
225 }
226
226
227 /*!
227 /*!
228 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.
229 Returns true, if inserting succeeded.
230
231 */
232 bool QBarSeries::insert(int index, QBarSet *set)
233 {
234 Q_D(QBarSeries);
235 bool success = d->insert(index, set);
236 if (success) {
237 QList<QBarSet*> sets;
238 sets.append(set);
239 emit barsetsAdded(sets);
240 }
241 return success;
242 }
243
244 /*!
228 Removes all of the bar sets from the series
245 Removes all of the bar sets from the series
229 */
246 */
230 void QBarSeries::clear()
247 void QBarSeries::clear()
231 {
248 {
232 Q_D(QBarSeries);
249 Q_D(QBarSeries);
233 d->remove(barSets());
250 d->remove(barSets());
234 }
251 }
235
252
236 /*!
253 /*!
237 Returns number of sets in series.
254 Returns number of sets in series.
238 */
255 */
239 int QBarSeries::barsetCount() const
256 int QBarSeries::barsetCount() const
240 {
257 {
241 Q_D(const QBarSeries);
258 Q_D(const QBarSeries);
242 return d->m_barSets.count();
259 return d->m_barSets.count();
243 }
260 }
244
261
245 /*!
262 /*!
246 Returns a list of sets in series. Keeps ownership of sets.
263 Returns a list of sets in series. Keeps ownership of sets.
247 */
264 */
248 QList<QBarSet*> QBarSeries::barSets() const
265 QList<QBarSet*> QBarSeries::barSets() const
249 {
266 {
250 Q_D(const QBarSeries);
267 Q_D(const QBarSeries);
251 return d->m_barSets;
268 return d->m_barSets;
252 }
269 }
253
270
254 /*!
271 /*!
255 Sets the visibility of labels in series to \a visible
272 Sets the visibility of labels in series to \a visible
256 */
273 */
257 void QBarSeries::setLabelsVisible(bool visible)
274 void QBarSeries::setLabelsVisible(bool visible)
258 {
275 {
259 Q_D(QBarSeries);
276 Q_D(QBarSeries);
260 if (d->m_labelsVisible != visible) {
277 if (d->m_labelsVisible != visible) {
261 d->setLabelsVisible(visible);
278 d->setLabelsVisible(visible);
262 emit labelsVisibleChanged();
279 emit labelsVisibleChanged();
263 }
280 }
264 }
281 }
265
282
266 /*!
283 /*!
267 Returns the visibility of labels
284 Returns the visibility of labels
268 */
285 */
269 bool QBarSeries::labelsVisible() const
286 bool QBarSeries::isLabelsVisible() const
270 {
287 {
271 Q_D(const QBarSeries);
288 Q_D(const QBarSeries);
272 return d->m_labelsVisible;
289 return d->m_labelsVisible;
273 }
290 }
274
291
275 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
292 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
276
293
277 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
294 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
278 QAbstractSeriesPrivate(q),
295 QAbstractSeriesPrivate(q),
279 m_barMargin(0.5), // Default value is 50% of category width
296 m_barMargin(0.5), // Default value is 50% of category width
280 m_labelsVisible(false),
297 m_labelsVisible(false),
281 m_visible(true)
298 m_visible(true)
282 {
299 {
283 }
300 }
284
301
285 void QBarSeriesPrivate::setCategories(QStringList categories)
302 void QBarSeriesPrivate::setCategories(QStringList categories)
286 {
303 {
287 m_categories = categories;
304 m_categories = categories;
288 }
305 }
289
306
290 void QBarSeriesPrivate::insertCategory(int index, const QString category)
307 void QBarSeriesPrivate::insertCategory(int index, const QString category)
291 {
308 {
292 m_categories.insert(index, category);
309 m_categories.insert(index, category);
293 emit categoriesUpdated();
310 emit categoriesUpdated();
294 }
311 }
295
312
296 void QBarSeriesPrivate::removeCategory(int index)
313 void QBarSeriesPrivate::removeCategory(int index)
297 {
314 {
298 m_categories.removeAt(index);
315 m_categories.removeAt(index);
299 emit categoriesUpdated();
316 emit categoriesUpdated();
300 }
317 }
301
318
302 int QBarSeriesPrivate::categoryCount() const
319 int QBarSeriesPrivate::categoryCount() const
303 {
320 {
304 if (m_categories.count() > 0) {
321 if (m_categories.count() > 0) {
305 return m_categories.count();
322 return m_categories.count();
306 }
323 }
307
324
308 // No categories defined. return count of longest set.
325 // No categories defined. return count of longest set.
309 int count = 0;
326 int count = 0;
310 for (int i=0; i<m_barSets.count(); i++) {
327 for (int i=0; i<m_barSets.count(); i++) {
311 if (m_barSets.at(i)->count() > count) {
328 if (m_barSets.at(i)->count() > count) {
312 count = m_barSets.at(i)->count();
329 count = m_barSets.at(i)->count();
313 }
330 }
314 }
331 }
315
332
316 return count;
333 return count;
317 }
334 }
318
335
319 QStringList QBarSeriesPrivate::categories() const
336 QStringList QBarSeriesPrivate::categories() const
320 {
337 {
321 if (m_categories.count() > 0) {
338 if (m_categories.count() > 0) {
322 return m_categories;
339 return m_categories;
323 }
340 }
324
341
325 // No categories defined. retun list of indices.
342 // No categories defined. retun list of indices.
326 QStringList categories;
343 QStringList categories;
327
344
328 int count = categoryCount();
345 int count = categoryCount();
329 for (int i = 0; i < count; i++) {
346 for (int i = 0; i < count; i++) {
330 categories.append(QString::number(i));
347 categories.append(QString::number(i));
331 }
348 }
332 return categories;
349 return categories;
333 }
350 }
334
351
335 void QBarSeriesPrivate::setBarMargin(qreal margin)
352 void QBarSeriesPrivate::setBarMargin(qreal margin)
336 {
353 {
337 if (margin > 1.0) {
354 if (margin > 1.0) {
338 margin = 1.0;
355 margin = 1.0;
339 } else if (margin < 0.0) {
356 } else if (margin < 0.0) {
340 margin = 0.0;
357 margin = 0.0;
341 }
358 }
342
359
343 m_barMargin = margin;
360 m_barMargin = margin;
344 emit updatedBars();
361 emit updatedBars();
345 }
362 }
346
363
347 qreal QBarSeriesPrivate::barMargin() const
364 qreal QBarSeriesPrivate::barMargin() const
348 {
365 {
349 return m_barMargin;
366 return m_barMargin;
350 }
367 }
351
368
352 QBarSet* QBarSeriesPrivate::barsetAt(int index)
369 QBarSet* QBarSeriesPrivate::barsetAt(int index)
353 {
370 {
354 return m_barSets.at(index);
371 return m_barSets.at(index);
355 }
372 }
356
373
357 void QBarSeriesPrivate::setVisible(bool visible)
374 void QBarSeriesPrivate::setVisible(bool visible)
358 {
375 {
359 m_visible = visible;
376 m_visible = visible;
360 emit updatedBars();
377 emit updatedBars();
361 }
378 }
362
379
363 void QBarSeriesPrivate::setLabelsVisible(bool visible)
380 void QBarSeriesPrivate::setLabelsVisible(bool visible)
364 {
381 {
365 m_labelsVisible = visible;
382 m_labelsVisible = visible;
366 emit labelsVisibleChanged(visible);
383 emit labelsVisibleChanged(visible);
367 }
384 }
368
385
369 QString QBarSeriesPrivate::categoryName(int category)
386 QString QBarSeriesPrivate::categoryName(int category)
370 {
387 {
371 if ((category >= 0) && (category < m_categories.count())) {
388 if ((category >= 0) && (category < m_categories.count())) {
372 return m_categories.at(category);
389 return m_categories.at(category);
373 }
390 }
374
391
375 return QString::number(category);
392 return QString::number(category);
376 }
393 }
377
394
378 qreal QBarSeriesPrivate::min()
395 qreal QBarSeriesPrivate::min()
379 {
396 {
380 if (m_barSets.count() <= 0) {
397 if (m_barSets.count() <= 0) {
381 return 0;
398 return 0;
382 }
399 }
383 qreal min = INT_MAX;
400 qreal min = INT_MAX;
384
401
385 for (int i = 0; i < m_barSets.count(); i++) {
402 for (int i = 0; i < m_barSets.count(); i++) {
386 int categoryCount = m_barSets.at(i)->count();
403 int categoryCount = m_barSets.at(i)->count();
387 for (int j = 0; j < categoryCount; j++) {
404 for (int j = 0; j < categoryCount; j++) {
388 qreal temp = m_barSets.at(i)->at(j).y();
405 qreal temp = m_barSets.at(i)->at(j).y();
389 if (temp < min)
406 if (temp < min)
390 min = temp;
407 min = temp;
391 }
408 }
392 }
409 }
393 return min;
410 return min;
394 }
411 }
395
412
396 qreal QBarSeriesPrivate::max()
413 qreal QBarSeriesPrivate::max()
397 {
414 {
398 if (m_barSets.count() <= 0) {
415 if (m_barSets.count() <= 0) {
399 return 0;
416 return 0;
400 }
417 }
401 qreal max = INT_MIN;
418 qreal max = INT_MIN;
402
419
403 for (int i = 0; i < m_barSets.count(); i++) {
420 for (int i = 0; i < m_barSets.count(); i++) {
404 int categoryCount = m_barSets.at(i)->count();
421 int categoryCount = m_barSets.at(i)->count();
405 for (int j = 0; j < categoryCount; j++) {
422 for (int j = 0; j < categoryCount; j++) {
406 qreal temp = m_barSets.at(i)->at(j).y();
423 qreal temp = m_barSets.at(i)->at(j).y();
407 if (temp > max)
424 if (temp > max)
408 max = temp;
425 max = temp;
409 }
426 }
410 }
427 }
411
428
412 return max;
429 return max;
413 }
430 }
414
431
415 qreal QBarSeriesPrivate::valueAt(int set, int category)
432 qreal QBarSeriesPrivate::valueAt(int set, int category)
416 {
433 {
417 if ((set < 0) || (set >= m_barSets.count())) {
434 if ((set < 0) || (set >= m_barSets.count())) {
418 // No set, no value.
435 // No set, no value.
419 return 0;
436 return 0;
420 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
437 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
421 // No category, no value.
438 // No category, no value.
422 return 0;
439 return 0;
423 }
440 }
424
441
425 return m_barSets.at(set)->at(category).y();
442 return m_barSets.at(set)->at(category).y();
426 }
443 }
427
444
428 qreal QBarSeriesPrivate::percentageAt(int set, int category)
445 qreal QBarSeriesPrivate::percentageAt(int set, int category)
429 {
446 {
430 if ((set < 0) || (set >= m_barSets.count())) {
447 if ((set < 0) || (set >= m_barSets.count())) {
431 // No set, no value.
448 // No set, no value.
432 return 0;
449 return 0;
433 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
450 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
434 // No category, no value.
451 // No category, no value.
435 return 0;
452 return 0;
436 }
453 }
437
454
438 qreal value = m_barSets.at(set)->at(category).y();
455 qreal value = m_barSets.at(set)->at(category).y();
439 qreal sum = categorySum(category);
456 qreal sum = categorySum(category);
440 if ( qFuzzyIsNull(sum) ) {
457 if ( qFuzzyIsNull(sum) ) {
441 return 0;
458 return 0;
442 }
459 }
443
460
444 return value / sum;
461 return value / sum;
445 }
462 }
446
463
447 qreal QBarSeriesPrivate::categorySum(int category)
464 qreal QBarSeriesPrivate::categorySum(int category)
448 {
465 {
449 qreal sum(0);
466 qreal sum(0);
450 int count = m_barSets.count(); // Count sets
467 int count = m_barSets.count(); // Count sets
451 for (int set = 0; set < count; set++) {
468 for (int set = 0; set < count; set++) {
452 if (category < m_barSets.at(set)->count())
469 if (category < m_barSets.at(set)->count())
453 sum += m_barSets.at(set)->at(category).y();
470 sum += m_barSets.at(set)->at(category).y();
454 }
471 }
455 return sum;
472 return sum;
456 }
473 }
457
474
458 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
475 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
459 {
476 {
460 qreal sum(0);
477 qreal sum(0);
461 int count = m_barSets.count(); // Count sets
478 int count = m_barSets.count(); // Count sets
462 for (int set = 0; set < count; set++) {
479 for (int set = 0; set < count; set++) {
463 if (category < m_barSets.at(set)->count())
480 if (category < m_barSets.at(set)->count())
464 sum += qAbs(m_barSets.at(set)->at(category).y());
481 sum += qAbs(m_barSets.at(set)->at(category).y());
465 }
482 }
466 return sum;
483 return sum;
467 }
484 }
468
485
469 qreal QBarSeriesPrivate::maxCategorySum()
486 qreal QBarSeriesPrivate::maxCategorySum()
470 {
487 {
471 qreal max = INT_MIN;
488 qreal max = INT_MIN;
472 int count = categoryCount();
489 int count = categoryCount();
473 for (int i = 0; i < count; i++) {
490 for (int i = 0; i < count; i++) {
474 qreal sum = categorySum(i);
491 qreal sum = categorySum(i);
475 if (sum > max)
492 if (sum > max)
476 max = sum;
493 max = sum;
477 }
494 }
478 return max;
495 return max;
479 }
496 }
480
497
481 void QBarSeriesPrivate::scaleDomain(Domain& domain)
498 void QBarSeriesPrivate::scaleDomain(Domain& domain)
482 {
499 {
483 qreal minX(domain.minX());
500 qreal minX(domain.minX());
484 qreal minY(domain.minY());
501 qreal minY(domain.minY());
485 qreal maxX(domain.maxX());
502 qreal maxX(domain.maxX());
486 qreal maxY(domain.maxY());
503 qreal maxY(domain.maxY());
487 int tickXCount(domain.tickXCount());
504 int tickXCount(domain.tickXCount());
488 int tickYCount(domain.tickYCount());
505 int tickYCount(domain.tickYCount());
489
506
490 qreal x = categoryCount();
507 qreal x = categoryCount();
491 qreal y = max();
508 qreal y = max();
492 minX = qMin(minX, x) - 0.5;
509 minX = qMin(minX, x) - 0.5;
493 minY = qMin(minY, y);
510 minY = qMin(minY, y);
494 maxX = qMax(maxX, x) - 0.5;
511 maxX = qMax(maxX, x) - 0.5;
495 maxY = qMax(maxY, y);
512 maxY = qMax(maxY, y);
496 tickXCount = x+1;
513 tickXCount = x+1;
497
514
498 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
515 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
499 }
516 }
500
517
501 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
518 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
502 {
519 {
503 Q_Q(QBarSeries);
520 Q_Q(QBarSeries);
504
521
505 BarChartItem* bar = new BarChartItem(q,presenter);
522 BarChartItem* bar = new BarChartItem(q,presenter);
506 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
523 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
507 presenter->animator()->addAnimation(bar);
524 presenter->animator()->addAnimation(bar);
508 }
525 }
509 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
526 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
510 return bar;
527 return bar;
511
528
512 }
529 }
513
530
514 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
531 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
515 {
532 {
516 Q_Q(QBarSeries);
533 Q_Q(QBarSeries);
517 QList<LegendMarker*> markers;
534 QList<LegendMarker*> markers;
518 foreach(QBarSet* set, q->barSets()) {
535 foreach(QBarSet* set, q->barSets()) {
519 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
536 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
520 markers << marker;
537 markers << marker;
521 }
538 }
522
539
523 return markers;
540 return markers;
524 }
541 }
525
542
526 bool QBarSeriesPrivate::append(QBarSet *set)
543 bool QBarSeriesPrivate::append(QBarSet *set)
527 {
544 {
528 Q_Q(QBarSeries);
545 Q_Q(QBarSeries);
529 if ((m_barSets.contains(set)) || (set == 0)) {
546 if ((m_barSets.contains(set)) || (set == 0)) {
530 // Fail if set is already in list or set is null.
547 // Fail if set is already in list or set is null.
531 return false;
548 return false;
532 }
549 }
533 m_barSets.append(set);
550 m_barSets.append(set);
534 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
551 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
535 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
552 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
536 if (m_dataset) {
553 if (m_dataset) {
537 m_dataset->updateSeries(q); // this notifies legend
554 m_dataset->updateSeries(q); // this notifies legend
538 }
555 }
539 emit restructuredBars(); // this notifies barchartitem
556 emit restructuredBars(); // this notifies barchartitem
540 return true;
557 return true;
541 }
558 }
542
559
543 bool QBarSeriesPrivate::remove(QBarSet *set)
560 bool QBarSeriesPrivate::remove(QBarSet *set)
544 {
561 {
545 Q_Q(QBarSeries);
562 Q_Q(QBarSeries);
546 if (!m_barSets.contains(set)) {
563 if (!m_barSets.contains(set)) {
547 // Fail if set is not in list
564 // Fail if set is not in list
548 return false;
565 return false;
549 }
566 }
550 m_barSets.removeOne(set);
567 m_barSets.removeOne(set);
551 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
568 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
552 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
569 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
553 if (m_dataset) {
570 if (m_dataset) {
554 m_dataset->updateSeries(q); // this notifies legend
571 m_dataset->updateSeries(q); // this notifies legend
555 }
572 }
556 emit restructuredBars(); // this notifies barchartitem
573 emit restructuredBars(); // this notifies barchartitem
557 return true;
574 return true;
558 }
575 }
559
576
560 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
577 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
561 {
578 {
562 Q_Q(QBarSeries);
579 Q_Q(QBarSeries);
563 foreach (QBarSet* set, sets) {
580 foreach (QBarSet* set, sets) {
564 if ((set == 0) || (m_barSets.contains(set))) {
581 if ((set == 0) || (m_barSets.contains(set))) {
565 // Fail if any of the sets is null or is already appended.
582 // Fail if any of the sets is null or is already appended.
566 return false;
583 return false;
567 }
584 }
568 if (sets.count(set) != 1) {
585 if (sets.count(set) != 1) {
569 // Also fail if same set is more than once in given list.
586 // Also fail if same set is more than once in given list.
570 return false;
587 return false;
571 }
588 }
572 }
589 }
573
590
574 foreach (QBarSet* set, sets) {
591 foreach (QBarSet* set, sets) {
575 m_barSets.append(set);
592 m_barSets.append(set);
576 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
593 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
577 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
594 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
578 }
595 }
579 if (m_dataset) {
596 if (m_dataset) {
580 m_dataset->updateSeries(q); // this notifies legend
597 m_dataset->updateSeries(q); // this notifies legend
581 }
598 }
582 emit restructuredBars(); // this notifies barchartitem
599 emit restructuredBars(); // this notifies barchartitem
583 return true;
600 return true;
584 }
601 }
585
602
586 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
603 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
587 {
604 {
588 Q_Q(QBarSeries);
605 Q_Q(QBarSeries);
589 foreach (QBarSet* set, sets) {
606 foreach (QBarSet* set, sets) {
590 if ((set == 0) || (!m_barSets.contains(set))) {
607 if ((set == 0) || (!m_barSets.contains(set))) {
591 // Fail if any of the sets is null or is not in series
608 // Fail if any of the sets is null or is not in series
592 return false;
609 return false;
593 }
610 }
594 if (sets.count(set) != 1) {
611 if (sets.count(set) != 1) {
595 // Also fail if same set is more than once in given list.
612 // Also fail if same set is more than once in given list.
596 return false;
613 return false;
597 }
614 }
598 }
615 }
599
616
600 foreach (QBarSet* set, sets) {
617 foreach (QBarSet* set, sets) {
601 m_barSets.removeOne(set);
618 m_barSets.removeOne(set);
602 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
619 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
603 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
620 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
604 }
621 }
605
622
606 if (m_dataset) {
623 if (m_dataset) {
607 m_dataset->updateSeries(q); // this notifies legend
624 m_dataset->updateSeries(q); // this notifies legend
608 }
625 }
609 emit restructuredBars(); // this notifies barchartitem
626 emit restructuredBars(); // this notifies barchartitem
610 return true;
627 return true;
611 }
628 }
612
629
630 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
631 {
632 Q_Q(QBarSeries);
633 if ((m_barSets.contains(set)) || (set == 0)) {
634 // Fail if set is already in list or set is null.
635 return false;
636 }
637 m_barSets.insert(index, set);
638 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
639 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
640 if (m_dataset) {
641 m_dataset->updateSeries(q); // this notifies legend
642 }
643 emit restructuredBars(); // this notifies barchartitem
644 return true;
645 }
646
613 #include "moc_qbarseries.cpp"
647 #include "moc_qbarseries.cpp"
614 #include "moc_qbarseries_p.cpp"
648 #include "moc_qbarseries_p.cpp"
615
649
616 QTCOMMERCIALCHART_END_NAMESPACE
650 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,83
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 BARSERIES_H
22 #define BARSERIES_H
22 #define BARSERIES_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 QBarSeriesPrivate;
30 class QBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin)
36 Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin)
37 Q_PROPERTY(int count READ barsetCount)
37 Q_PROPERTY(int count READ barsetCount)
38 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible)
39
39
40 public:
40 public:
41 explicit QBarSeries(QObject *parent = 0);
41 explicit QBarSeries(QObject *parent = 0);
42 virtual ~QBarSeries();
42 virtual ~QBarSeries();
43
43
44 QAbstractSeries::SeriesType type() const;
44 QAbstractSeries::SeriesType type() const;
45
45
46 void setBarMargin(qreal margin);
46 void setBarMargin(qreal margin);
47 qreal barMargin() const;
47 qreal barMargin() const;
48
48
49 bool append(QBarSet *set);
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
50 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
51 bool append(QList<QBarSet* > sets);
52 bool remove(QList<QBarSet* > sets);
52 bool remove(QList<QBarSet* > sets);
53 bool insert(int index, QBarSet *set);
53 int barsetCount() const;
54 int barsetCount() const;
54 QList<QBarSet*> barSets() const;
55 QList<QBarSet*> barSets() const;
55 void clear();
56 void clear();
56
57
57 void setLabelsVisible(bool visible = true);
58 void setLabelsVisible(bool visible = true);
58 bool labelsVisible() const;
59 bool isLabelsVisible() const;
59
60
60 protected:
61 protected:
61 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
62 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
62
63
63 Q_SIGNALS:
64 Q_SIGNALS:
64 void clicked(QBarSet *barset, int index);
65 void clicked(QBarSet *barset, int index);
65 void hovered(QBarSet* barset, bool status);
66 void hovered(QBarSet* barset, bool status);
66 void visibleChanged();
67 void visibleChanged();
67 void labelsVisibleChanged();
68 void labelsVisibleChanged();
68
69
69 void barsetsAdded(QList<QBarSet*> sets);
70 void barsetsAdded(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
71 void barsetsRemoved(QList<QBarSet*> sets);
71
72
72 protected:
73 protected:
73 Q_DECLARE_PRIVATE(QBarSeries)
74 Q_DECLARE_PRIVATE(QBarSeries)
74 friend class BarChartItem;
75 friend class BarChartItem;
75 friend class PercentBarChartItem;
76 friend class PercentBarChartItem;
76 friend class StackedBarChartItem;
77 friend class StackedBarChartItem;
77 friend class GroupedBarChartItem;
78 friend class GroupedBarChartItem;
78 };
79 };
79
80
80 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
81
82
82 #endif // BARSERIES_H
83 #endif // BARSERIES_H
@@ -1,99 +1,100
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARSERIES_P_H
30 #ifndef QBARSERIES_P_H
31 #define QBARSERIES_P_H
31 #define QBARSERIES_P_H
32
32
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
35 #include <QStringList>
35 #include <QStringList>
36 #include <QAbstractSeries>
36 #include <QAbstractSeries>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QBarModelMapper;
40 class QBarModelMapper;
41
41
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 QBarSeriesPrivate(QBarSeries *parent);
46 QBarSeriesPrivate(QBarSeries *parent);
47 // TODO: refactor/remove private category stuff
47 // TODO: refactor/remove private category stuff
48 void setCategories(QStringList categories);
48 void setCategories(QStringList categories);
49 void insertCategory(int index, const QString category);
49 void insertCategory(int index, const QString category);
50 void removeCategory(int index);
50 void removeCategory(int index);
51 int categoryCount() const;
51 int categoryCount() const;
52 QStringList categories() const;
52 QStringList categories() const;
53
53
54 void setBarMargin(qreal margin);
54 void setBarMargin(qreal margin);
55 qreal barMargin() const;
55 qreal barMargin() const;
56
56
57 void setVisible(bool visible);
57 void setVisible(bool visible);
58 void setLabelsVisible(bool visible);
58 void setLabelsVisible(bool visible);
59
59
60 void scaleDomain(Domain& domain);
60 void scaleDomain(Domain& domain);
61 Chart* createGraphics(ChartPresenter* presenter);
61 Chart* createGraphics(ChartPresenter* presenter);
62 QList<LegendMarker*> createLegendMarker(QLegend* legend);
62 QList<LegendMarker*> createLegendMarker(QLegend* legend);
63
63
64 bool append(QBarSet *set);
64 bool append(QBarSet *set);
65 bool remove(QBarSet *set);
65 bool remove(QBarSet *set);
66 bool append(QList<QBarSet* > sets);
66 bool append(QList<QBarSet* > sets);
67 bool remove(QList<QBarSet* > sets);
67 bool remove(QList<QBarSet* > sets);
68 bool insert(int index, QBarSet *set);
68
69
69 QBarSet* barsetAt(int index);
70 QBarSet* barsetAt(int index);
70 QString categoryName(int category);
71 QString categoryName(int category);
71 qreal min();
72 qreal min();
72 qreal max();
73 qreal max();
73 qreal valueAt(int set, int category);
74 qreal valueAt(int set, int category);
74 qreal percentageAt(int set, int category);
75 qreal percentageAt(int set, int category);
75 qreal categorySum(int category);
76 qreal categorySum(int category);
76 qreal absoluteCategorySum(int category);
77 qreal absoluteCategorySum(int category);
77 qreal maxCategorySum();
78 qreal maxCategorySum();
78
79
79 Q_SIGNALS:
80 Q_SIGNALS:
80 void clicked(QBarSet *barset, int index);
81 void clicked(QBarSet *barset, int index);
81 void updatedBars();
82 void updatedBars();
82 void restructuredBars();
83 void restructuredBars();
83 void categoriesUpdated();
84 void categoriesUpdated();
84 void labelsVisibleChanged(bool visible);
85 void labelsVisibleChanged(bool visible);
85
86
86 protected:
87 protected:
87 QList<QBarSet *> m_barSets;
88 QList<QBarSet *> m_barSets;
88 QStringList m_categories;
89 QStringList m_categories;
89 qreal m_barMargin;
90 qreal m_barMargin;
90 bool m_labelsVisible;
91 bool m_labelsVisible;
91 bool m_visible;
92 bool m_visible;
92
93
93 private:
94 private:
94 Q_DECLARE_PUBLIC(QBarSeries)
95 Q_DECLARE_PUBLIC(QBarSeries)
95 };
96 };
96
97
97 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
98
99
99 #endif // QBARSERIESPRIVATE_P_H
100 #endif // QBARSERIESPRIVATE_P_H
General Comments 0
You need to be logged in to leave comments. Login now