##// END OF EJS Templates
barchart: doc update for hover signals
sauimone -
r980:29373936de0b
parent child
Show More
@@ -1,513 +1,532
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 "barchartmodel_p.h"
25 #include "barchartmodel_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include "legendmarker_p.h"
27 #include "legendmarker_p.h"
28 #include "chartdataset_p.h"
28 #include "chartdataset_p.h"
29 #include "charttheme_p.h"
29 #include "charttheme_p.h"
30 #include "chartanimator_p.h"
30 #include "chartanimator_p.h"
31
31
32 #include <QAbstractItemModel>
32 #include <QAbstractItemModel>
33 #include <QModelIndex>
33 #include <QModelIndex>
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 /*!
37 /*!
38 \class QBarSeries
38 \class QBarSeries
39 \brief part of QtCommercial chart API.
39 \brief part of QtCommercial chart API.
40
40
41 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple
41 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple
42 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
42 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
43 by QStringList.
43 by QStringList.
44
44
45 \mainclass
45 \mainclass
46
46
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
48 */
49
49
50 /*!
50 /*!
51 \fn virtual QSeriesType QBarSeries::type() const
51 \fn virtual QSeriesType QBarSeries::type() const
52 \brief Returns type of series.
52 \brief Returns type of series.
53 \sa QSeries, QSeriesType
53 \sa QSeries, QSeriesType
54 */
54 */
55
55
56 /*!
56 /*!
57 \fn void QBarSeries::clicked(QBarSet *barset, QString category, Qt::MouseButtons button)
57 \fn void QBarSeries::clicked(QBarSet *barset, QString category, Qt::MouseButtons button)
58
58
59 The signal is emitted if the user clicks with a mouse \a button on top of QBarSet \a barset of category \a category
59 The signal is emitted if the user clicks with a mouse \a button on top of QBarSet \a barset of category \a category
60 contained by the series.
60 contained by the series.
61 */
61 */
62
62
63 /*!
63 /*!
64 \fn void QBarSeries::selected()
64 \fn void QBarSeries::selected()
65
65
66 The signal is emitted if the user selects/deselects the series. The logic for storing selections should be
66 The signal is emitted if the user selects/deselects the series. The logic for storing selections should be
67 implemented by the user of QBarSeries API.
67 implemented by the user of QBarSeries API.
68 */
68 */
69
69
70 /*!
70 /*!
71 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
72
73 The signal is emitted if mouse is hovered on top of series.
74 Parameter \a barset is the pointer of barset, where hover happened.
75 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
76 */
77
78 /*!
71 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
79 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
72 QBarSeries is QObject which is a child of a \a parent.
80 QBarSeries is QObject which is a child of a \a parent.
73 */
81 */
74 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) :
82 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) :
75 QSeries(*new QBarSeriesPrivate(categories, this),parent)
83 QSeries(*new QBarSeriesPrivate(categories, this),parent)
76 {
84 {
77 }
85 }
78
86
79 /*!
87 /*!
88 Destructs barseries and owned barsets.
89 */
90 QBarSeries::~QBarSeries()
91 {
92 // NOTE: d_ptr destroyed by QObject
93 }
94
95 /*!
80 \internal
96 \internal
81 */
97 */
82 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
98 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
83 QSeries(d,parent)
99 QSeries(d,parent)
84 {
100 {
85 }
101 }
86
102
103 /*!
104 Returns the type of series. Derived classes override this.
105 */
87 QSeries::QSeriesType QBarSeries::type() const
106 QSeries::QSeriesType QBarSeries::type() const
88 {
107 {
89 return QSeries::SeriesTypeBar;
108 return QSeries::SeriesTypeBar;
90 }
109 }
91
110
92 /*!
111 /*!
93 Adds a set of bars to series. Takes ownership of \a set.
112 Adds a set of bars to series. Takes ownership of \a set.
94 Connects the clicked(QString, Qt::MouseButtons) signal
113 Connects the clicked(QString, Qt::MouseButtons) signal
95 of \a set to this series
114 of \a set to this series
96 */
115 */
97 void QBarSeries::appendBarSet(QBarSet *set)
116 void QBarSeries::appendBarSet(QBarSet *set)
98 {
117 {
99 Q_D(QBarSeries);
118 Q_D(QBarSeries);
100 d->m_internalModel->appendBarSet(set);
119 d->m_internalModel->appendBarSet(set);
101 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
120 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
102 emit d->restructuredBars();
121 emit d->restructuredBars();
103 }
122 }
104
123
105 /*!
124 /*!
106 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
125 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
107 Disconnects the clicked(QString, Qt::MouseButtons) signal
126 Disconnects the clicked(QString, Qt::MouseButtons) signal
108 of \a set from this series
127 of \a set from this series
109 */
128 */
110 void QBarSeries::removeBarSet(QBarSet *set)
129 void QBarSeries::removeBarSet(QBarSet *set)
111 {
130 {
112 Q_D(QBarSeries);
131 Q_D(QBarSeries);
113 d->m_internalModel->removeBarSet(set);
132 d->m_internalModel->removeBarSet(set);
114 emit d->restructuredBars();
133 emit d->restructuredBars();
115 }
134 }
116
135
117 /*!
136 /*!
118 Adds a list of barsets to series. Takes ownership of \a sets.
137 Adds a list of barsets to series. Takes ownership of \a sets.
119 Connects the clicked(QString, Qt::MouseButtons) signals
138 Connects the clicked(QString, Qt::MouseButtons) signals
120 of \a sets to this series
139 of \a sets to this series
121 */
140 */
122 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
141 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
123 {
142 {
124 Q_D(QBarSeries);
143 Q_D(QBarSeries);
125 foreach (QBarSet* barset, sets) {
144 foreach (QBarSet* barset, sets) {
126 d->m_internalModel->appendBarSet(barset);
145 d->m_internalModel->appendBarSet(barset);
127 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
146 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
128 }
147 }
129 emit d->restructuredBars();
148 emit d->restructuredBars();
130
149
131 }
150 }
132
151
133 /*!
152 /*!
134 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
153 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
135 Disconnects the clicked(QString, Qt::MouseButtons) signal
154 Disconnects the clicked(QString, Qt::MouseButtons) signal
136 of \a sets from this series
155 of \a sets from this series
137 */
156 */
138 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
157 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
139 {
158 {
140 Q_D(QBarSeries);
159 Q_D(QBarSeries);
141
160
142 foreach (QBarSet* barset, sets) {
161 foreach (QBarSet* barset, sets) {
143 d->m_internalModel->removeBarSet(barset);
162 d->m_internalModel->removeBarSet(barset);
144 }
163 }
145 emit d->restructuredBars();
164 emit d->restructuredBars();
146 }
165 }
147
166
148 /*!
167 /*!
149 Inserts new \a set on the \a i position.
168 Inserts new \a set on the \a i position.
150 The barset that is currently at this postion is moved to postion i + 1
169 The barset that is currently at this postion is moved to postion i + 1
151 */
170 */
152 void QBarSeries::insertBarSet(int i, QBarSet *set)
171 void QBarSeries::insertBarSet(int i, QBarSet *set)
153 {
172 {
154 Q_D(QBarSeries);
173 Q_D(QBarSeries);
155 d->m_internalModel->insertBarSet(i, set);
174 d->m_internalModel->insertBarSet(i, set);
156 emit d->barsetChanged();
175 emit d->barsetChanged();
157 }
176 }
158
177
159 /*!
178 /*!
160 Inserts new \a category on the \a i position.
179 Inserts new \a category on the \a i position.
161 The category that is currently at this postion is moved to postion i + 1
180 The category that is currently at this postion is moved to postion i + 1
162 \sa removeCategory()
181 \sa removeCategory()
163 */
182 */
164 void QBarSeries::insertCategory(int i, QString category)
183 void QBarSeries::insertCategory(int i, QString category)
165 {
184 {
166 Q_D(QBarSeries);
185 Q_D(QBarSeries);
167 d->m_internalModel->insertCategory(i, category);
186 d->m_internalModel->insertCategory(i, category);
168 }
187 }
169
188
170 /*!
189 /*!
171 Removes the category specified by \a i
190 Removes the category specified by \a i
172 \sa insertCategory()
191 \sa insertCategory()
173 */
192 */
174 void QBarSeries::removeCategory(int i)
193 void QBarSeries::removeCategory(int i)
175 {
194 {
176 Q_D(QBarSeries);
195 Q_D(QBarSeries);
177 d->m_internalModel->removeCategory(i);
196 d->m_internalModel->removeCategory(i);
178 }
197 }
179
198
180 /*!
199 /*!
181 Returns number of sets in series.
200 Returns number of sets in series.
182 */
201 */
183 int QBarSeries::barsetCount() const
202 int QBarSeries::barsetCount() const
184 {
203 {
185 Q_D(const QBarSeries);
204 Q_D(const QBarSeries);
186 return d->m_internalModel->barsetCount();
205 return d->m_internalModel->barsetCount();
187 }
206 }
188
207
189 /*!
208 /*!
190 Returns number of categories in series
209 Returns number of categories in series
191 */
210 */
192 int QBarSeries::categoryCount() const
211 int QBarSeries::categoryCount() const
193 {
212 {
194 Q_D(const QBarSeries);
213 Q_D(const QBarSeries);
195 return d->m_internalModel->categoryCount();
214 return d->m_internalModel->categoryCount();
196 }
215 }
197
216
198 /*!
217 /*!
199 Returns a list of sets in series. Keeps ownership of sets.
218 Returns a list of sets in series. Keeps ownership of sets.
200 */
219 */
201 QList<QBarSet*> QBarSeries::barSets() const
220 QList<QBarSet*> QBarSeries::barSets() const
202 {
221 {
203 Q_D(const QBarSeries);
222 Q_D(const QBarSeries);
204 return d->m_internalModel->barSets();
223 return d->m_internalModel->barSets();
205 }
224 }
206
225
207 /*!
226 /*!
208 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
227 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
209 Sets the \a model to be used as a data source
228 Sets the \a model to be used as a data source
210 */
229 */
211 bool QBarSeries::setModel(QAbstractItemModel *model)
230 bool QBarSeries::setModel(QAbstractItemModel *model)
212 {
231 {
213 Q_D(QBarSeries);
232 Q_D(QBarSeries);
214 return d->setModel(model);
233 return d->setModel(model);
215 }
234 }
216
235
217 /*!
236 /*!
218 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
237 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
219 Sets column/row specified by \a categories to be used as a list of bar series categories.
238 Sets column/row specified by \a categories to be used as a list of bar series categories.
220 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
239 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
221 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
240 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
222 All the columns/rows inbetween those two values are also used as data for bar sets.
241 All the columns/rows inbetween those two values are also used as data for bar sets.
223 The \a orientation parameter specifies whether the data is in columns or in rows.
242 The \a orientation parameter specifies whether the data is in columns or in rows.
224 */
243 */
225 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
244 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
226 {
245 {
227 Q_D(QBarSeries);
246 Q_D(QBarSeries);
228 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
247 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
229 }
248 }
230
249
231 /*!
250 /*!
232 Returns the bar categories of the series.
251 Returns the bar categories of the series.
233 */
252 */
234 QBarCategories QBarSeries::categories() const
253 QBarCategories QBarSeries::categories() const
235 {
254 {
236 Q_D(const QBarSeries);
255 Q_D(const QBarSeries);
237
256
238 QBarCategories categories;
257 QBarCategories categories;
239 int count = d->m_internalModel->categoryCount();
258 int count = d->m_internalModel->categoryCount();
240 for (int i=1; i <= count; i++) {
259 for (int i=1; i <= count; i++) {
241 categories.insert(i, d->m_internalModel->categoryName(i - 1));
260 categories.insert(i, d->m_internalModel->categoryName(i - 1));
242 }
261 }
243 return categories;
262 return categories;
244
263
245 }
264 }
246
265
247 /*!
266 /*!
248 Sets the visibility of labels in series to \a visible
267 Sets the visibility of labels in series to \a visible
249 */
268 */
250 void QBarSeries::setLabelsVisible(bool visible)
269 void QBarSeries::setLabelsVisible(bool visible)
251 {
270 {
252 foreach (QBarSet* s, barSets()) {
271 foreach (QBarSet* s, barSets()) {
253 s->setLabelsVisible(visible);
272 s->setLabelsVisible(visible);
254 }
273 }
255 }
274 }
256
275
257 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
276 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
258
277
259 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
278 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
260 m_internalModel(new BarChartModel(categories,this)),
279 m_internalModel(new BarChartModel(categories,this)),
261 m_model(0),
280 m_model(0),
262 m_mapCategories(-1),
281 m_mapCategories(-1),
263 m_mapBarBottom(-1),
282 m_mapBarBottom(-1),
264 m_mapBarTop(-1),
283 m_mapBarTop(-1),
265 m_mapFirst(0),
284 m_mapFirst(0),
266 m_mapCount(0),
285 m_mapCount(0),
267 m_mapOrientation(Qt::Vertical)
286 m_mapOrientation(Qt::Vertical)
268 {
287 {
269 }
288 }
270
289
271 QBarSet* QBarSeriesPrivate::barsetAt(int index)
290 QBarSet* QBarSeriesPrivate::barsetAt(int index)
272 {
291 {
273 return m_internalModel->barsetAt(index);
292 return m_internalModel->barsetAt(index);
274 }
293 }
275
294
276 QString QBarSeriesPrivate::categoryName(int category)
295 QString QBarSeriesPrivate::categoryName(int category)
277 {
296 {
278 return m_internalModel->categoryName(category);
297 return m_internalModel->categoryName(category);
279 }
298 }
280
299
281 qreal QBarSeriesPrivate::min()
300 qreal QBarSeriesPrivate::min()
282 {
301 {
283 return m_internalModel->min();
302 return m_internalModel->min();
284 }
303 }
285
304
286 qreal QBarSeriesPrivate::max()
305 qreal QBarSeriesPrivate::max()
287 {
306 {
288 return m_internalModel->max();
307 return m_internalModel->max();
289 }
308 }
290
309
291 qreal QBarSeriesPrivate::valueAt(int set, int category)
310 qreal QBarSeriesPrivate::valueAt(int set, int category)
292 {
311 {
293 return m_internalModel->valueAt(set, category);
312 return m_internalModel->valueAt(set, category);
294 }
313 }
295
314
296 qreal QBarSeriesPrivate::percentageAt(int set, int category)
315 qreal QBarSeriesPrivate::percentageAt(int set, int category)
297 {
316 {
298 return m_internalModel->percentageAt(set, category);
317 return m_internalModel->percentageAt(set, category);
299 }
318 }
300
319
301 qreal QBarSeriesPrivate::categorySum(int category)
320 qreal QBarSeriesPrivate::categorySum(int category)
302 {
321 {
303 return m_internalModel->categorySum(category);
322 return m_internalModel->categorySum(category);
304 }
323 }
305
324
306 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
325 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
307 {
326 {
308 return m_internalModel->absoluteCategorySum(category);
327 return m_internalModel->absoluteCategorySum(category);
309 }
328 }
310
329
311 qreal QBarSeriesPrivate::maxCategorySum()
330 qreal QBarSeriesPrivate::maxCategorySum()
312 {
331 {
313 return m_internalModel->maxCategorySum();
332 return m_internalModel->maxCategorySum();
314 }
333 }
315
334
316 BarChartModel& QBarSeriesPrivate::modelInternal()
335 BarChartModel& QBarSeriesPrivate::modelInternal()
317 {
336 {
318 return *m_internalModel;
337 return *m_internalModel;
319 }
338 }
320
339
321 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
340 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
322 {
341 {
323 // disconnect signals from old model
342 // disconnect signals from old model
324 if(m_model)
343 if(m_model)
325 {
344 {
326 disconnect(m_model, 0, this, 0);
345 disconnect(m_model, 0, this, 0);
327 m_mapCategories = -1;
346 m_mapCategories = -1;
328 m_mapBarBottom = -1;
347 m_mapBarBottom = -1;
329 m_mapBarTop = -1;
348 m_mapBarTop = -1;
330 m_mapFirst = 0;
349 m_mapFirst = 0;
331 m_mapCount = 0;
350 m_mapCount = 0;
332 m_mapOrientation = Qt::Vertical;
351 m_mapOrientation = Qt::Vertical;
333 }
352 }
334
353
335 // set new model
354 // set new model
336 if(model)
355 if(model)
337 {
356 {
338 m_model = model;
357 m_model = model;
339 return true;
358 return true;
340 }
359 }
341 else
360 else
342 {
361 {
343 m_model = 0;
362 m_model = 0;
344 return false;
363 return false;
345 }
364 }
346 }
365 }
347
366
348 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
367 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
349 {
368 {
350 Q_Q(QBarSeries);
369 Q_Q(QBarSeries);
351
370
352 if (m_model == 0)
371 if (m_model == 0)
353 return;
372 return;
354
373
355 m_mapCategories = categories;
374 m_mapCategories = categories;
356 m_mapBarBottom = bottomBoundry;
375 m_mapBarBottom = bottomBoundry;
357 m_mapBarTop = topBoundry;
376 m_mapBarTop = topBoundry;
358 // m_mapFirst = 1;
377 // m_mapFirst = 1;
359 m_mapOrientation = orientation;
378 m_mapOrientation = orientation;
360
379
361 // connect the signals
380 // connect the signals
362 if (m_mapOrientation == Qt::Vertical) {
381 if (m_mapOrientation == Qt::Vertical) {
363 m_mapCount = m_model->rowCount() - m_mapFirst;
382 m_mapCount = m_model->rowCount() - m_mapFirst;
364 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
383 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
365 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
384 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
366 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)),
385 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)),
367 this, SLOT(modelDataAdded(QModelIndex,int,int)));
386 this, SLOT(modelDataAdded(QModelIndex,int,int)));
368 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
387 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
369 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
388 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
370 } else {
389 } else {
371 m_mapCount = m_model->columnCount() - m_mapFirst;
390 m_mapCount = m_model->columnCount() - m_mapFirst;
372 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
391 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
373 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
392 this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
374 connect(m_model,SIGNAL(columnsInserted(QModelIndex,int,int)),
393 connect(m_model,SIGNAL(columnsInserted(QModelIndex,int,int)),
375 this, SLOT(modelDataAdded(QModelIndex,int,int)));
394 this, SLOT(modelDataAdded(QModelIndex,int,int)));
376 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
395 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
377 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
396 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
378 }
397 }
379
398
380 // create the initial bars
399 // create the initial bars
381 delete m_internalModel;
400 delete m_internalModel;
382 if (m_mapOrientation == Qt::Vertical) {
401 if (m_mapOrientation == Qt::Vertical) {
383 QStringList categories;
402 QStringList categories;
384 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
403 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
385 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
404 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
386 m_internalModel = new BarChartModel(categories, this);
405 m_internalModel = new BarChartModel(categories, this);
387
406
388 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
407 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
389 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
408 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
390 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
409 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
391 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
410 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
392 q->appendBarSet(barSet);
411 q->appendBarSet(barSet);
393 }
412 }
394 } else {
413 } else {
395 QStringList categories;
414 QStringList categories;
396 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
415 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
397 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
416 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
398 m_internalModel = new BarChartModel(categories, this);
417 m_internalModel = new BarChartModel(categories, this);
399
418
400 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
419 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
401 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
420 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
402 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
421 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
403 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
422 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
404 q->appendBarSet(barSet);
423 q->appendBarSet(barSet);
405 }
424 }
406 }
425 }
407 }
426 }
408
427
409 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
428 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
410 {
429 {
411 Q_UNUSED(bottomRight)
430 Q_UNUSED(bottomRight)
412
431
413 if (m_mapOrientation == Qt::Vertical)
432 if (m_mapOrientation == Qt::Vertical)
414 {
433 {
415 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
434 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
416 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
435 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
417 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
436 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
418 }
437 }
419 else
438 else
420 {
439 {
421 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
440 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
422 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
441 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
423 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
442 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
424 }
443 }
425 }
444 }
426
445
427 void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
446 void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
428 {
447 {
429 Q_Q(QBarSeries);
448 Q_Q(QBarSeries);
430
449
431 if (m_mapOrientation == Qt::Vertical) {
450 if (m_mapOrientation == Qt::Vertical) {
432 q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
451 q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
433 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
452 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
434 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
453 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
435 }
454 }
436 } else {
455 } else {
437 q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
456 q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
438 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
457 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
439 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
458 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
440 }
459 }
441 }
460 }
442 emit restructuredBars();
461 emit restructuredBars();
443 }
462 }
444
463
445 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
464 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
446 {
465 {
447 Q_Q(QBarSeries);
466 Q_Q(QBarSeries);
448 Q_UNUSED(parent)
467 Q_UNUSED(parent)
449 Q_UNUSED(end)
468 Q_UNUSED(end)
450
469
451 q->removeCategory(start - m_mapFirst);
470 q->removeCategory(start - m_mapFirst);
452 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
471 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
453 {
472 {
454 barsetAt(i)->removeValue(start - m_mapFirst);
473 barsetAt(i)->removeValue(start - m_mapFirst);
455 }
474 }
456 emit restructuredBars();
475 emit restructuredBars();
457 }
476 }
458
477
459 void QBarSeriesPrivate::barsetChanged()
478 void QBarSeriesPrivate::barsetChanged()
460 {
479 {
461 emit updatedBars();
480 emit updatedBars();
462 }
481 }
463
482
464 void QBarSeriesPrivate::scaleDomain(Domain& domain)
483 void QBarSeriesPrivate::scaleDomain(Domain& domain)
465 {
484 {
466 qreal minX(domain.minX());
485 qreal minX(domain.minX());
467 qreal minY(domain.minY());
486 qreal minY(domain.minY());
468 qreal maxX(domain.maxX());
487 qreal maxX(domain.maxX());
469 qreal maxY(domain.maxY());
488 qreal maxY(domain.maxY());
470 int tickXCount(domain.tickXCount());
489 int tickXCount(domain.tickXCount());
471 int tickYCount(domain.tickYCount());
490 int tickYCount(domain.tickYCount());
472
491
473 qreal x = m_internalModel->categoryCount();
492 qreal x = m_internalModel->categoryCount();
474 qreal y = max();
493 qreal y = max();
475 minX = qMin(minX, x);
494 minX = qMin(minX, x);
476 minY = qMin(minY, y);
495 minY = qMin(minY, y);
477 maxX = qMax(maxX, x);
496 maxX = qMax(maxX, x);
478 maxY = qMax(maxY, y);
497 maxY = qMax(maxY, y);
479 tickXCount = x+1;
498 tickXCount = x+1;
480
499
481 domain.setRangeX(minX,maxX,tickXCount);
500 domain.setRangeX(minX,maxX,tickXCount);
482 domain.setRangeY(minY,maxY,tickYCount);
501 domain.setRangeY(minY,maxY,tickYCount);
483 }
502 }
484
503
485 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
504 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
486 {
505 {
487 Q_Q(QBarSeries);
506 Q_Q(QBarSeries);
488
507
489 BarChartItem* bar = new BarChartItem(q,presenter);
508 BarChartItem* bar = new BarChartItem(q,presenter);
490 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
509 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
491 presenter->animator()->addAnimation(bar);
510 presenter->animator()->addAnimation(bar);
492 }
511 }
493 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
512 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
494 return bar;
513 return bar;
495
514
496 }
515 }
497
516
498 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
517 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
499 {
518 {
500 Q_Q(QBarSeries);
519 Q_Q(QBarSeries);
501 QList<LegendMarker*> markers;
520 QList<LegendMarker*> markers;
502 foreach(QBarSet* set, q->barSets()) {
521 foreach(QBarSet* set, q->barSets()) {
503 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
522 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
504 markers << marker;
523 markers << marker;
505 }
524 }
506
525
507 return markers;
526 return markers;
508 }
527 }
509
528
510 #include "moc_qbarseries.cpp"
529 #include "moc_qbarseries.cpp"
511 #include "moc_qbarseries_p.cpp"
530 #include "moc_qbarseries_p.cpp"
512
531
513 QTCOMMERCIALCHART_END_NAMESPACE
532 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,81 +1,82
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 <qseries.h>
24 #include <qseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 class QModelIndex;
27 class QModelIndex;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 typedef QStringList QBarCategories;
31 typedef QStringList QBarCategories;
32
32
33 class QBarSet;
33 class QBarSet;
34 class BarChartModel;
34 class BarChartModel;
35 class BarCategory;
35 class BarCategory;
36 class QBarSeriesPrivate;
36 class QBarSeriesPrivate;
37
37
38 // Container for series
38 // Container for series
39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
40 {
40 {
41 Q_OBJECT
41 Q_OBJECT
42 public:
42 public:
43 explicit QBarSeries(QBarCategories categories, QObject *parent = 0);
43 explicit QBarSeries(QBarCategories categories, QObject *parent = 0);
44 virtual ~QBarSeries();
44
45
45 QSeries::QSeriesType type() const;
46 QSeries::QSeriesType type() const;
46
47
47 void appendBarSet(QBarSet *set); // Takes ownership of set
48 void appendBarSet(QBarSet *set); // Takes ownership of set
48 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
49 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
49 void appendBarSets(QList<QBarSet* > sets);
50 void appendBarSets(QList<QBarSet* > sets);
50 void removeBarSets(QList<QBarSet* > sets);
51 void removeBarSets(QList<QBarSet* > sets);
51 void insertBarSet(int i, QBarSet *set);
52 void insertBarSet(int i, QBarSet *set);
52 void insertCategory(int i, QString category);
53 void insertCategory(int i, QString category);
53 void removeCategory(int i);
54 void removeCategory(int i);
54 int barsetCount() const;
55 int barsetCount() const;
55 int categoryCount() const;
56 int categoryCount() const;
56 QList<QBarSet*> barSets() const;
57 QList<QBarSet*> barSets() const;
57 QBarCategories categories() const;
58 QBarCategories categories() const;
58
59
59 void setLabelsVisible(bool visible = true);
60 void setLabelsVisible(bool visible = true);
60
61
61 bool setModel(QAbstractItemModel *model);
62 bool setModel(QAbstractItemModel *model);
62 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
63 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
63
64
64 protected:
65 protected:
65 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
66 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
66
67
67 Q_SIGNALS:
68 Q_SIGNALS:
68 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
69 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
69 void selected();
70 void selected();
70 void hovered(QBarSet* barset, bool status);
71 void hovered(QBarSet* barset, bool status);
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 };
78 };
78
79
79 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
80
81
81 #endif // BARSERIES_H
82 #endif // BARSERIES_H
@@ -1,281 +1,292
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 part of QtCommercial chart API.
28 \brief part of QtCommercial chart API.
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 QBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39
39
40 /*!
40 /*!
41 \fn void QBarSet::clicked(QString category, Qt::MouseButtons button)
41 \fn void QBarSet::clicked(QString category, Qt::MouseButtons button)
42 \brief signals that set has been clicked
42 \brief signals that set has been clicked
43 Parameter \a category describes on which category was clicked
43 Parameter \a category describes on which category was clicked
44 Parameter \a button mouse button
44 Parameter \a button mouse button
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn void QBarSet::selected()
49 \brief signals that set has been selected
50 */
51
52 /*!
48 \fn void QBarSet::hovered(bool status)
53 \fn void QBarSet::hovered(bool status)
49 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
54 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
55
56 The signal is emitted if mouse is hovered on top of set
57 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
50 */
58 */
51
59
52 /*!
60 /*!
53 Constructs QBarSet with a name of \a name and with parent of \a parent
61 Constructs QBarSet with a name of \a name and with parent of \a parent
54 */
62 */
55 QBarSet::QBarSet(QString name, QObject *parent)
63 QBarSet::QBarSet(QString name, QObject *parent)
56 : QObject(parent)
64 : QObject(parent)
57 ,d_ptr(new QBarSetPrivate(name,this))
65 ,d_ptr(new QBarSetPrivate(name,this))
58 {
66 {
59 }
67 }
60
68
69 /*!
70 Destroys the barset
71 */
61 QBarSet::~QBarSet()
72 QBarSet::~QBarSet()
62 {
73 {
63
74 // NOTE: d_ptr destroyed by QObject
64 }
75 }
65
76
66 /*!
77 /*!
67 Sets new \a name for set.
78 Sets new \a name for set.
68 */
79 */
69 void QBarSet::setName(QString name)
80 void QBarSet::setName(QString name)
70 {
81 {
71 d_ptr->m_name = name;
82 d_ptr->m_name = name;
72 }
83 }
73
84
74 /*!
85 /*!
75 Returns name of the set.
86 Returns name of the set.
76 */
87 */
77 QString QBarSet::name() const
88 QString QBarSet::name() const
78 {
89 {
79 return d_ptr->m_name;
90 return d_ptr->m_name;
80 }
91 }
81
92
82 /*!
93 /*!
83 Appends new value \a value to the end of set.
94 Appends new value \a value to the end of set.
84 */
95 */
85 QBarSet& QBarSet::operator << (const qreal &value)
96 QBarSet& QBarSet::operator << (const qreal &value)
86 {
97 {
87 d_ptr->m_values.append(value);
98 d_ptr->m_values.append(value);
88 emit d_ptr->structureChanged();
99 emit d_ptr->structureChanged();
89 return *this;
100 return *this;
90 }
101 }
91
102
92 /*!
103 /*!
93 Inserts new \a value on the \a i position.
104 Inserts new \a value on the \a i position.
94 The value that is currently at this postion is moved to postion i + 1
105 The value that is currently at this postion is moved to postion i + 1
95 \sa removeValue()
106 \sa removeValue()
96 */
107 */
97 void QBarSet::insertValue(int i, qreal value)
108 void QBarSet::insertValue(int i, qreal value)
98 {
109 {
99 d_ptr->m_values.insert(i, value);
110 d_ptr->m_values.insert(i, value);
100 }
111 }
101
112
102 /*!
113 /*!
103 Removes the value specified by \a i
114 Removes the value specified by \a i
104 \sa insertValue()
115 \sa insertValue()
105 */
116 */
106 void QBarSet::removeValue(int i)
117 void QBarSet::removeValue(int i)
107 {
118 {
108 d_ptr->m_values.removeAt(i);
119 d_ptr->m_values.removeAt(i);
109 }
120 }
110
121
111 /*!
122 /*!
112 Returns count of values in set.
123 Returns count of values in set.
113 */
124 */
114 int QBarSet::count() const
125 int QBarSet::count() const
115 {
126 {
116 return d_ptr->m_values.count();
127 return d_ptr->m_values.count();
117 }
128 }
118
129
119 /*!
130 /*!
120 Returns value of set indexed by \a index
131 Returns value of set indexed by \a index
121 */
132 */
122 qreal QBarSet::valueAt(int index) const
133 qreal QBarSet::valueAt(int index) const
123 {
134 {
124 return d_ptr->m_values.at(index);
135 return d_ptr->m_values.at(index);
125 }
136 }
126
137
127 /*!
138 /*!
128 Sets a new value \a value to set, indexed by \a index
139 Sets a new value \a value to set, indexed by \a index
129 */
140 */
130 void QBarSet::setValue(int index, qreal value)
141 void QBarSet::setValue(int index, qreal value)
131 {
142 {
132 d_ptr->m_values.replace(index,value);
143 d_ptr->m_values.replace(index,value);
133 emit d_ptr->valueChanged();
144 emit d_ptr->valueChanged();
134 }
145 }
135
146
136 /*!
147 /*!
137 Returns sum of all values in barset.
148 Returns sum of all values in barset.
138 */
149 */
139 qreal QBarSet::sum() const
150 qreal QBarSet::sum() const
140 {
151 {
141 qreal total(0);
152 qreal total(0);
142 for (int i=0; i < d_ptr->m_values.count(); i++) {
153 for (int i=0; i < d_ptr->m_values.count(); i++) {
143 total += d_ptr->m_values.at(i);
154 total += d_ptr->m_values.at(i);
144 }
155 }
145 return total;
156 return total;
146 }
157 }
147
158
148 /*!
159 /*!
149 Sets pen for set. Bars of this set are drawn using \a pen
160 Sets pen for set. Bars of this set are drawn using \a pen
150 */
161 */
151 void QBarSet::setPen(const QPen &pen)
162 void QBarSet::setPen(const QPen &pen)
152 {
163 {
153 if(d_ptr->m_pen!=pen){
164 if(d_ptr->m_pen!=pen){
154 d_ptr->m_pen = pen;
165 d_ptr->m_pen = pen;
155 emit d_ptr->valueChanged();
166 emit d_ptr->valueChanged();
156 }
167 }
157 }
168 }
158
169
159 /*!
170 /*!
160 Returns pen of the set.
171 Returns pen of the set.
161 */
172 */
162 QPen QBarSet::pen() const
173 QPen QBarSet::pen() const
163 {
174 {
164 return d_ptr->m_pen;
175 return d_ptr->m_pen;
165 }
176 }
166
177
167 /*!
178 /*!
168 Sets brush for the set. Bars of this set are drawn using \a brush
179 Sets brush for the set. Bars of this set are drawn using \a brush
169 */
180 */
170 void QBarSet::setBrush(const QBrush &brush)
181 void QBarSet::setBrush(const QBrush &brush)
171 {
182 {
172 if(d_ptr->m_brush!=brush){
183 if(d_ptr->m_brush!=brush){
173 d_ptr->m_brush = brush;
184 d_ptr->m_brush = brush;
174 emit d_ptr->valueChanged();
185 emit d_ptr->valueChanged();
175 }
186 }
176 }
187 }
177
188
178 /*!
189 /*!
179 Returns brush of the set.
190 Returns brush of the set.
180 */
191 */
181 QBrush QBarSet::brush() const
192 QBrush QBarSet::brush() const
182 {
193 {
183 return d_ptr->m_brush;
194 return d_ptr->m_brush;
184 }
195 }
185
196
186 /*!
197 /*!
187 Sets \a pen of the values that are drawn on top of this barset
198 Sets \a pen of the values that are drawn on top of this barset
188 */
199 */
189 void QBarSet::setLabelPen(const QPen &pen)
200 void QBarSet::setLabelPen(const QPen &pen)
190 {
201 {
191 if(d_ptr->m_labelPen!=pen){
202 if(d_ptr->m_labelPen!=pen){
192 d_ptr->m_labelPen = pen;
203 d_ptr->m_labelPen = pen;
193 emit d_ptr->valueChanged();
204 emit d_ptr->valueChanged();
194 }
205 }
195 }
206 }
196
207
197 /*!
208 /*!
198 Returns pen of the values that are drawn on top of this barset
209 Returns pen of the values that are drawn on top of this barset
199 */
210 */
200 QPen QBarSet::labelPen() const
211 QPen QBarSet::labelPen() const
201 {
212 {
202 return d_ptr->m_labelPen;
213 return d_ptr->m_labelPen;
203 }
214 }
204
215
205 /*!
216 /*!
206 Sets \a brush of the values that are drawn on top of this barset
217 Sets \a brush of the values that are drawn on top of this barset
207 */
218 */
208 void QBarSet::setLabelBrush(const QBrush &brush)
219 void QBarSet::setLabelBrush(const QBrush &brush)
209 {
220 {
210 if(d_ptr->m_labelBrush!=brush){
221 if(d_ptr->m_labelBrush!=brush){
211 d_ptr->m_labelBrush = brush;
222 d_ptr->m_labelBrush = brush;
212 emit d_ptr->valueChanged();
223 emit d_ptr->valueChanged();
213 }
224 }
214 }
225 }
215
226
216 /*!
227 /*!
217 Returns brush of the values that are drawn on top of this barset
228 Returns brush of the values that are drawn on top of this barset
218 */
229 */
219 QBrush QBarSet::labelBrush() const
230 QBrush QBarSet::labelBrush() const
220 {
231 {
221 return d_ptr->m_labelBrush;
232 return d_ptr->m_labelBrush;
222 }
233 }
223
234
224 /*!
235 /*!
225 Sets the \a font for values that are drawn on top of this barset
236 Sets the \a font for values that are drawn on top of this barset
226 */
237 */
227 void QBarSet::setLabelFont(const QFont &font)
238 void QBarSet::setLabelFont(const QFont &font)
228 {
239 {
229 if(d_ptr->m_labelFont!=font) {
240 if(d_ptr->m_labelFont!=font) {
230 d_ptr->m_labelFont = font;
241 d_ptr->m_labelFont = font;
231 emit d_ptr->valueChanged();
242 emit d_ptr->valueChanged();
232 }
243 }
233
244
234 }
245 }
235
246
236 /*!
247 /*!
237 Returns the pen for values that are drawn on top of this set
248 Returns the pen for values that are drawn on top of this set
238 */
249 */
239 QFont QBarSet::labelFont() const
250 QFont QBarSet::labelFont() const
240 {
251 {
241 return d_ptr->m_labelFont;
252 return d_ptr->m_labelFont;
242 }
253 }
243
254
244 /*!
255 /*!
245 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
256 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
246 */
257 */
247
258
248 void QBarSet::setLabelsVisible(bool visible)
259 void QBarSet::setLabelsVisible(bool visible)
249 {
260 {
250 if(d_ptr->m_labelsVisible!=visible) {
261 if(d_ptr->m_labelsVisible!=visible) {
251 d_ptr->m_labelsVisible = visible;
262 d_ptr->m_labelsVisible = visible;
252 emit d_ptr->labelsVisibleChanged(visible);
263 emit d_ptr->labelsVisibleChanged(visible);
253 }
264 }
254 }
265 }
255
266
256 /*!
267 /*!
257 Returns the visibility of values
268 Returns the visibility of values
258 */
269 */
259 bool QBarSet::labelsVisible() const
270 bool QBarSet::labelsVisible() const
260 {
271 {
261 return d_ptr->m_labelsVisible;
272 return d_ptr->m_labelsVisible;
262 }
273 }
263
274
264 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
275 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
265
276
266 QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent),
277 QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent),
267 q_ptr(parent),
278 q_ptr(parent),
268 m_name(name),
279 m_name(name),
269 m_labelsVisible(false)
280 m_labelsVisible(false)
270 {
281 {
271
282
272 }
283 }
273
284
274 QBarSetPrivate::~QBarSetPrivate()
285 QBarSetPrivate::~QBarSetPrivate()
275 {
286 {
276
287
277 }
288 }
278 #include "moc_qbarset.cpp"
289 #include "moc_qbarset.cpp"
279 #include "moc_qbarset_p.cpp"
290 #include "moc_qbarset_p.cpp"
280
291
281 QTCOMMERCIALCHART_END_NAMESPACE
292 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 QBARSET_H
21 #ifndef QBARSET_H
22 #define QBARSET_H
22 #define QBARSET_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QBrush>
26 #include <QBrush>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QBarSetPrivate;
30 class QBarSetPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35
35
36 public:
36 public:
37 explicit QBarSet(QString name, QObject *parent = 0);
37 explicit QBarSet(QString name, QObject *parent = 0);
38 ~QBarSet();
38 virtual ~QBarSet();
39
39
40 void setName(QString name);
40 void setName(QString name);
41 QString name() const;
41 QString name() const;
42 QBarSet& operator << (const qreal &value); // appends new value to set
42 QBarSet& operator << (const qreal &value); // appends new value to set
43 void insertValue(int i, qreal value);
43 void insertValue(int i, qreal value);
44 void removeValue(int i);
44 void removeValue(int i);
45 int count() const; // count of values in set
45 int count() const; // count of values in set
46 qreal valueAt(int index) const; // for modifying individual values
46 qreal valueAt(int index) const; // for modifying individual values
47 void setValue(int index, qreal value); // setter for individual value
47 void setValue(int index, qreal value); // setter for individual value
48 qreal sum() const; // sum of all values in the set
48 qreal sum() const; // sum of all values in the set
49
49
50 void setPen(const QPen &pen);
50 void setPen(const QPen &pen);
51 QPen pen() const;
51 QPen pen() const;
52
52
53 void setBrush(const QBrush &brush);
53 void setBrush(const QBrush &brush);
54 QBrush brush() const;
54 QBrush brush() const;
55
55
56 void setLabelPen(const QPen &pen);
56 void setLabelPen(const QPen &pen);
57 QPen labelPen() const;
57 QPen labelPen() const;
58
58
59 void setLabelBrush(const QBrush &brush);
59 void setLabelBrush(const QBrush &brush);
60 QBrush labelBrush() const;
60 QBrush labelBrush() const;
61
61
62 void setLabelFont(const QFont &font);
62 void setLabelFont(const QFont &font);
63 QFont labelFont() const;
63 QFont labelFont() const;
64
64
65 void setLabelsVisible(bool visible = true);
65 void setLabelsVisible(bool visible = true);
66 bool labelsVisible() const;
66 bool labelsVisible() const;
67
67
68 Q_SIGNALS:
68 Q_SIGNALS:
69 void clicked(QString category, Qt::MouseButtons button);
69 void clicked(QString category, Qt::MouseButtons button);
70 void selected();
70 void selected();
71 void hovered(bool status);
71 void hovered(bool status);
72
72
73 private:
73 private:
74 QScopedPointer<QBarSetPrivate> d_ptr;
74 QScopedPointer<QBarSetPrivate> d_ptr;
75 Q_DISABLE_COPY(QBarSet)
75 Q_DISABLE_COPY(QBarSet)
76 friend class QBarSeries;
76 friend class QBarSeries;
77 friend class BarLegendMarker;
77 friend class BarLegendMarker;
78 friend class BarChartItem;
78 friend class BarChartItem;
79 friend class QBarSeriesPrivate;
79 friend class QBarSeriesPrivate;
80 };
80 };
81
81
82 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
83
83
84 #endif // QBARSET_H
84 #endif // QBARSET_H
General Comments 0
You need to be logged in to leave comments. Login now