##// END OF EJS Templates
Updated spline chart example documentation and added some more docs to barseries
Marek Rosa -
r901:087f347c6433
parent child
Show More
@@ -1,42 +1,33
1 1 /*!
2 2 \example examples/splinechart
3 3 \title SplineChart Example
4 4 \subtitle
5 5
6 6 The example shows how to create simple spline chart.
7 7
8 8 \image splinechart_example
9 9
10 10 To create spline chart we need to put our data into QSplineSeries. QSplineSeries automatically calculates spline segment control points that are needed to properly draw the spline.
11 11
12 \snippet ../examples/splinechart/splinewidget.cpp 1
12 \snippet ../examples/splinechart/main.cpp 1
13 13
14 14 Customize the look of the spline, by setting its pen's color and pen's width
15 15
16 \snippet ../examples/splinechart/splinewidget.cpp 2
16 \snippet ../examples/splinechart/main.cpp 2
17 17
18 18 Now lets add some data points to the series.
19 19
20 \snippet ../examples/splinechart/splinewidget.cpp add points to series
20 \snippet ../examples/splinechart/main.cpp 3
21 21
22 The data series has been populated. To display it on a chart we create QChartView object and add the data series to it. We also set the ranges on both axises, so that our chart is fully visible and there is some excess of space for adding more data points.
22 The data series has been populated. To display it on a chart we create QChart object and add the data series to it. We also set the title and the values range on y axis, so that our chart is better visible.
23 23
24 \snippet ../examples/splinechart/splinewidget.cpp 3
24 \snippet ../examples/splinechart/main.cpp 4
25 25
26 Then we add two buttons for adding and removing data points. Buttons clicked() signals are connected to handler functions.
26 Then we created a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
27 27
28 \snippet ../examples/splinechart/splinewidget.cpp 4
28 \snippet ../examples/splinechart/main.cpp 5
29 29
30 In the end we add the chart and the buttons to the widget's layout.
31
32 \snippet ../examples/splinechart/splinewidget.cpp 5
33
34 Here is the handler function for add new data point button:
35
36 \snippet ../examples/splinechart/splinewidget.cpp add point
37
38 And here is one for remove the last data point in the series:
39
40 \snippet ../examples/splinechart/splinewidget.cpp remove point
30 In the end we set the QChartView as the windows's central widget.
41 31
32 \snippet ../examples/splinechart/main.cpp 6
42 33 */
@@ -1,68 +1,71
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QSplineSeries>
25 25
26 26 QTCOMMERCIALCHART_USE_NAMESPACE
27 27
28 28 int main(int argc, char *argv[])
29 29 {
30 30 QApplication a(argc, argv);
31 31
32 //![1]
32 //![1]
33 33 QSplineSeries* series = new QSplineSeries();
34 //![1]
35
36 //![2]
34 37 QPen red(Qt::red);
35 38 red.setWidth(3);
36 39 series->setPen(red);
37 //![1]
40 //![2]
38 41
39 //![2]
42 //![3]
40 43 series->append(0, 6);
41 44 series->append(2, 4);
42 45 series->append(3, 8);
43 46 series->append(7, 4);
44 47 series->append(10, 5);
45 48 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
46 //![2]
49 //![3]
47 50
48 //![3]
51 //![4]
49 52 QChart* chart = new QChart();
50 53 chart->addSeries(series);
51 54 chart->setTitle("Simple spline chart example");
52 55 chart->axisY()->setRange(0, 10);
53 //![3]
56 //![4]
54 57
55 //![4]
58 //![5]
56 59 QChartView* chartView = new QChartView(chart);
57 60 chartView->setRenderHint(QPainter::Antialiasing);
58 //![4]
61 //![5]
59 62
60 //![5]
63 //![6]
61 64 QMainWindow window;
62 65 window.setCentralWidget(chartView);
63 66 window.resize(400, 300);
64 67 window.show();
65 //![5]
68 //![6]
66 69
67 70 return a.exec();
68 71 }
@@ -1,459 +1,472
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QDebug>
22 22 #include "qbarseries.h"
23 23 #include "qbarset.h"
24 24 #include "barchartmodel_p.h"
25 25 #include <QAbstractItemModel>
26 26 #include <QModelIndex>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 /*!
31 31 \class QBarSeries
32 32 \brief part of QtCommercial chart API.
33 33
34 34 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
35 35 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
36 36 by QStringList.
37 37
38 38 \mainclass
39 39
40 40 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
41 41 */
42 42
43 43 /*!
44 44 \fn virtual QSeriesType QBarSeries::type() const
45 45 \brief Returns type of series.
46 46 \sa QSeries, QSeriesType
47 47 */
48 48
49 49 /*!
50 50 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
51 51 \brief \internal \a pos \a tip
52 52 */
53 53
54 54 /*!
55 55 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
56 56 QBarSeries is QObject which is a child of a \a parent.
57 57 */
58 58 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent),
59 59 m_internalModel(new BarChartModel(categories, this))
60 60 {
61 61 m_model = 0;
62 62 m_mapCategories = -1;
63 63 m_mapBarBottom = -1;
64 64 m_mapBarTop = -1;
65 65 m_mapFirst = 0;
66 66 m_mapCount = 0;
67 67 m_mapOrientation = Qt::Vertical;
68 68 }
69 69
70 70 /*!
71 71 Adds a set of bars to series. Takes ownership of \a set.
72 72 Connects the clicked(QString, Qt::MouseButtons) signal
73 73 of \a set to this series
74 74 */
75 75 void QBarSeries::appendBarSet(QBarSet *set)
76 76 {
77 77 m_internalModel->appendBarSet(set);
78 78 connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
79 79 connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
80 80 emit restructuredBars();
81 81 }
82 82
83 83 /*!
84 84 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
85 85 Disconnects the clicked(QString, Qt::MouseButtons) signal
86 86 of \a set from this series
87 87 */
88 88 void QBarSeries::removeBarSet(QBarSet *set)
89 89 {
90 90 disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
91 91 m_internalModel->removeBarSet(set);
92 92 emit restructuredBars();
93 93 }
94 94
95 95 /*!
96 96 Adds a list of barsets to series. Takes ownership of \a sets.
97 97 Connects the clicked(QString, Qt::MouseButtons) signals
98 98 of \a sets to this series
99 99 */
100 100 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
101 101 {
102 102 foreach (QBarSet* barset, sets) {
103 103 m_internalModel->appendBarSet(barset);
104 104 connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
105 105 connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
106 106 }
107 107 emit restructuredBars();
108 108 }
109 109
110 110 /*!
111 Removes a list of barsets from series. Releases ownership of \a set. Doesnt delete \a sets.
111 Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets.
112 112 Disconnects the clicked(QString, Qt::MouseButtons) signal
113 113 of \a sets from this series
114 114 */
115 115 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
116 116 {
117 117 foreach (QBarSet* barset, sets) {
118 118 disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
119 119 m_internalModel->removeBarSet(barset);
120 120 }
121 121 emit restructuredBars();
122 122 }
123 123
124 /*!
125 Inserts new \a set on the \a i position.
126 The barset that is currently at this postion is moved to postion i + 1
127 */
124 128 void QBarSeries::insertBarSet(int i, QBarSet *set)
125 129 {
126 130 m_internalModel->insertBarSet(i, set);
127 131 // emit barsetChanged();
128 132 }
129 133
134 /*!
135 Inserts new \a category on the \a i position.
136 The category that is currently at this postion is moved to postion i + 1
137 \sa removeCategory()
138 */
130 139 void QBarSeries::insertCategory(int i, QString category)
131 140 {
132 141 m_internalModel->insertCategory(i, category);
133 142 }
134 143
144 /*!
145 Removes the category specified by \a i
146 \sa insertCategory()
147 */
135 148 void QBarSeries::removeCategory(int i)
136 149 {
137 150 m_internalModel->removeCategory(i);
138 151 }
139 152
140 153 /*!
141 154 Returns number of sets in series.
142 155 */
143 156 int QBarSeries::barsetCount() const
144 157 {
145 158 // if(m_model)
146 159 // return m_mapBarTop - m_mapBarBottom;
147 160 // else
148 161 return m_internalModel->barsetCount();
149 162 }
150 163
151 164 /*!
152 165 Returns number of categories in series
153 166 */
154 167 int QBarSeries::categoryCount() const
155 168 {
156 169 return m_internalModel->categoryCount();
157 170 }
158 171
159 172 /*!
160 173 Returns a list of sets in series. Keeps ownership of sets.
161 174 */
162 175 QList<QBarSet*> QBarSeries::barSets() const
163 176 {
164 177 return m_internalModel->barSets();
165 178 }
166 179
167 180 /*!
168 181 \internal \a index
169 182 */
170 183 QBarSet* QBarSeries::barsetAt(int index)
171 184 {
172 185 return m_internalModel->barsetAt(index);
173 186 }
174 187
175 188 /*!
176 189 \internal \a category
177 190 */
178 191 QString QBarSeries::categoryName(int category)
179 192 {
180 193 return m_internalModel->categoryName(category);
181 194 }
182 195
183 196 /*!
184 197 Enables or disables tooltip depending on parameter \a enabled.
185 198 Tooltip shows the name of set, when mouse is hovering on top of bar.
186 199 Calling without parameter \a enabled, enables the tooltip
187 200 */
188 201 void QBarSeries::setToolTipEnabled(bool enabled)
189 202 {
190 203 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
191 204 if (enabled) {
192 205 for (int i=0; i<m_internalModel->barsetCount(); i++) {
193 206 QBarSet *set = m_internalModel->barsetAt(i);
194 207 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
195 208 }
196 209 } else {
197 210 for (int i=0; i<m_internalModel->barsetCount(); i++) {
198 211 QBarSet *set = m_internalModel->barsetAt(i);
199 212 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
200 213 }
201 214 }
202 215 }
203 216
204 217
205 218 /*!
206 219 \internal \a category
207 220 */
208 221 void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button)
209 222 {
210 223 emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
211 224 }
212 225
213 226 /*!
214 227 \internal
215 228 */
216 229 qreal QBarSeries::min()
217 230 {
218 231 return m_internalModel->min();
219 232 }
220 233
221 234 /*!
222 235 \internal
223 236 */
224 237 qreal QBarSeries::max()
225 238 {
226 239 return m_internalModel->max();
227 240 }
228 241
229 242 /*!
230 243 \internal \a set \a category
231 244 */
232 245 qreal QBarSeries::valueAt(int set, int category)
233 246 {
234 247 return m_internalModel->valueAt(set, category);
235 248 }
236 249
237 250 /*!
238 251 \internal \a set \a category
239 252 */
240 253 qreal QBarSeries::percentageAt(int set, int category)
241 254 {
242 255 return m_internalModel->percentageAt(set, category);
243 256 }
244 257
245 258 /*!
246 259 \internal \a category
247 260 */
248 261 qreal QBarSeries::categorySum(int category)
249 262 {
250 263 return m_internalModel->categorySum(category);
251 264 }
252 265
253 266 /*!
254 267 \internal \a category
255 268 */
256 269 qreal QBarSeries::absoluteCategorySum(int category)
257 270 {
258 271 return m_internalModel->absoluteCategorySum(category);
259 272 }
260 273
261 274 /*!
262 275 \internal
263 276 */
264 277 qreal QBarSeries::maxCategorySum()
265 278 {
266 279 return m_internalModel->maxCategorySum();
267 280 }
268 281
269 282 /*!
270 283 \internal
271 284 */
272 285 BarChartModel& QBarSeries::modelInternal()
273 286 {
274 287 return *m_internalModel;
275 288 }
276 289
277 290 /*!
278 291 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
279 292 Sets the \a model to be used as a data source
280 293 */
281 294 bool QBarSeries::setModel(QAbstractItemModel *model)
282 295 {
283 296 // disconnect signals from old model
284 297 if(m_model)
285 298 {
286 299 disconnect(m_model, 0, this, 0);
287 300 m_mapCategories = -1;
288 301 m_mapBarBottom = -1;
289 302 m_mapBarTop = -1;
290 303 m_mapFirst = 0;
291 304 m_mapCount = 0;
292 305 m_mapOrientation = Qt::Vertical;
293 306 }
294 307
295 308 // set new model
296 309 if(model)
297 310 {
298 311 m_model = model;
299 312 return true;
300 313 }
301 314 else
302 315 {
303 316 m_model = 0;
304 317 return false;
305 318 }
306 319 }
307 320
308 321 /*!
309 322 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
310 323 Sets column/row specified by \a categories to be used as a list of bar series categories.
311 324 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
312 325 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
313 326 All the columns/rows inbetween those two values are also used as data for bar sets.
314 327 The \a orientation paramater specifies whether the data is in columns or in rows.
315 328 */
316 329 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
317 330 {
318 331 if (!m_model)
319 332 return;
320 333
321 334 m_mapCategories = categories;
322 335 m_mapBarBottom = bottomBoundry;
323 336 m_mapBarTop = topBoundry;
324 337 // m_mapFirst = 1;
325 338 m_mapOrientation = orientation;
326 339
327 340 // connect the signals
328 341 if (m_mapOrientation == Qt::Vertical) {
329 342 m_mapCount = m_model->rowCount() - m_mapFirst;
330 343 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
331 344 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
332 345 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
333 346 this, SLOT(modelDataAdded(QModelIndex,int,int)));
334 347 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
335 348 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
336 349 } else {
337 350 m_mapCount = m_model->columnCount() - m_mapFirst;
338 351 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
339 352 this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
340 353 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
341 354 this, SLOT(modelDataAdded(QModelIndex,int,int)));
342 355 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
343 356 this, SLOT(modelDataRemoved(QModelIndex,int,int)));
344 357 }
345 358
346 359 // create the initial bars
347 360 delete m_internalModel;
348 361 if (m_mapOrientation == Qt::Vertical) {
349 362 QStringList categories;
350 363 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
351 364 categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
352 365 m_internalModel = new BarChartModel(categories, this);
353 366
354 367 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
355 368 QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
356 369 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
357 370 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
358 371 appendBarSet(barSet);
359 372 }
360 373 } else {
361 374 QStringList categories;
362 375 for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
363 376 categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
364 377 m_internalModel = new BarChartModel(categories, this);
365 378
366 379 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
367 380 QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
368 381 for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
369 382 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
370 383 appendBarSet(barSet);
371 384 }
372 385 }
373 386 }
374 387
375 388 /*!
376 389 \internal
377 390 */
378 391 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
379 392 {
380 393 Q_UNUSED(bottomRight)
381 394
382 395 if (m_mapOrientation == Qt::Vertical)
383 396 {
384 397 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
385 398 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
386 399 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
387 400 }
388 401 else
389 402 {
390 403 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
391 404 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
392 405 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
393 406 }
394 407 }
395 408
396 409 /*!
397 410 \internal
398 411 */
399 412 void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
400 413 {
401 414 if (m_mapOrientation == Qt::Vertical) {
402 415 insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
403 416 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
404 417 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
405 418 }
406 419 } else {
407 420 insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
408 421 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
409 422 barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
410 423 }
411 424 }
412 425 emit restructuredBars();
413 426 }
414 427
415 428 /*!
416 429 \internal
417 430 */
418 431 void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end)
419 432 {
420 433 Q_UNUSED(parent)
421 434 Q_UNUSED(end)
422 435
423 436 removeCategory(start - m_mapFirst);
424 437 for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
425 438 {
426 439 barsetAt(i)->removeValue(start - m_mapFirst);
427 440 }
428 441 emit restructuredBars();
429 442 }
430 443
431 444 void QBarSeries::barsetChanged()
432 445 {
433 446 emit updatedBars();
434 447 }
435 448
436 449 QBarCategories QBarSeries::categories() const
437 450 {
438 451 QBarCategories categories;
439 452 int count = m_internalModel->categoryCount();
440 453 for (int i=1; i <= count; i++) {
441 454 categories.insert(i, m_internalModel->categoryName(i - 1));
442 455 }
443 456 return categories;
444 457 }
445 458
446 459 /*!
447 460 Sets the visibility of labels in series to \a visible
448 461 */
449 462 void QBarSeries::setLabelsVisible(bool visible)
450 463 {
451 464 foreach (QBarSet* s, barSets()) {
452 465 s->setLabelsVisible(visible);
453 466 }
454 467 }
455 468
456 469
457 470 #include "moc_qbarseries.cpp"
458 471
459 472 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,274 +1,283
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarset.h"
22 22 #include <QDebug>
23 23 #include <QToolTip>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 /*!
28 28 \class QBarSet
29 29 \brief part of QtCommercial chart API.
30 30
31 31 QBarSet represents one set of bars. Set of bars contains one data value for each category.
32 32 First value of set is assumed to belong to first category, second to second category and so on.
33 33 If set has fewer values than there are categories, then the missing values are assumed to be
34 34 at the end of set. For missing values in middle of a set, numerical value of zero is used.
35 35
36 36 \mainclass
37 37
38 38 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
39 39 */
40 40
41 41 /*!
42 42 \fn void QBarSet::clicked(QString category, Qt::MouseButtons button)
43 43 \brief signals that set has been clicked
44 44 Parameter \a category describes on which category was clicked
45 45 Parameter \a button mouse button
46 46 */
47 47
48 48 /*!
49 49 \fn void QBarSet::hoverEnter(QPoint pos)
50 50 \brief signals that mouse has entered over the set at position \a pos.
51 51 */
52 52
53 53 /*!
54 54 \fn void QBarSet::hoverLeave()
55 55 \brief signals that mouse has left from the set.
56 56 */
57 57
58 58 /*!
59 59 \fn void QBarSet::setLabelssVisible(bool visible = true)
60 60 \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
61 61 */
62 62
63 63 /*!
64 64 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
65 65 \brief \internal \a pos \a tip
66 66 */
67 67
68 68
69 69 /*!
70 70 Constructs QBarSet with a name of \a name and with parent of \a parent
71 71 */
72 72 QBarSet::QBarSet(QString name, QObject *parent)
73 73 : QObject(parent)
74 74 ,m_name(name)
75 75 ,m_labelsVisible(false)
76 76 {
77 77 }
78 78
79 79 /*!
80 80 Sets new \a name for set.
81 81 */
82 82 void QBarSet::setName(QString name)
83 83 {
84 84 m_name = name;
85 85 }
86 86
87 87 /*!
88 88 Returns name of the set.
89 89 */
90 90 QString QBarSet::name() const
91 91 {
92 92 return m_name;
93 93 }
94 94
95 95 /*!
96 96 Appends new value \a value to the end of set.
97 97 */
98 98 QBarSet& QBarSet::operator << (const qreal &value)
99 99 {
100 100 m_values.append(value);
101 101 emit structureChanged();
102 102 return *this;
103 103 }
104 104
105 /*!
106 Inserts new \a value on the \a i position.
107 The value that is currently at this postion is moved to postion i + 1
108 \sa removeValue()
109 */
105 110 void QBarSet::insertValue(int i, qreal value)
106 111 {
107 112 m_values.insert(i, value);
108 113 }
109 114
115 /*!
116 Removes the value specified by \a i
117 \sa insertValue()
118 */
110 119 void QBarSet::removeValue(int i)
111 120 {
112 121 m_values.removeAt(i);
113 122 }
114 123
115 124 /*!
116 125 Returns count of values in set.
117 126 */
118 127 int QBarSet::count() const
119 128 {
120 129 return m_values.count();
121 130 }
122 131
123 132 /*!
124 133 Returns value of set indexed by \a index
125 134 */
126 135 qreal QBarSet::valueAt(int index) const
127 136 {
128 137 return m_values.at(index);
129 138 }
130 139
131 140 /*!
132 141 Sets a new value \a value to set, indexed by \a index
133 142 */
134 143 void QBarSet::setValue(int index, qreal value)
135 144 {
136 145 m_values.replace(index,value);
137 146 emit valueChanged();
138 147 }
139 148
140 149 /*!
141 150 Returns total sum of all values in barset.
142 151 */
143 152 qreal QBarSet::total() const
144 153 {
145 154 qreal total(0);
146 155 for (int i=0; i < m_values.count(); i++) {
147 156 total += m_values.at(i);
148 157 }
149 158 return total;
150 159 }
151 160
152 161 /*!
153 162 Sets pen for set. Bars of this set are drawn using \a pen
154 163 */
155 164 void QBarSet::setPen(const QPen &pen)
156 165 {
157 166 m_pen = pen;
158 167 emit valueChanged();
159 168 }
160 169
161 170 /*!
162 171 Returns pen of the set.
163 172 */
164 173 QPen QBarSet::pen() const
165 174 {
166 175 return m_pen;
167 176 }
168 177
169 178 /*!
170 179 Sets brush for the set. Bars of this set are drawn using \a brush
171 180 */
172 181 void QBarSet::setBrush(const QBrush &brush)
173 182 {
174 183 m_brush = brush;
175 184 emit valueChanged();
176 185 }
177 186
178 187 /*!
179 188 Returns brush of the set.
180 189 */
181 190 QBrush QBarSet::brush() const
182 191 {
183 192 return m_brush;
184 193 }
185 194
186 195 /*!
187 196 Sets \a pen of the values that are drawn on top of this barset
188 197 */
189 198 void QBarSet::setLabelPen(const QPen &pen)
190 199 {
191 200 m_labelPen = pen;
192 201 emit valueChanged();
193 202 }
194 203
195 204 /*!
196 205 Returns pen of the values that are drawn on top of this barset
197 206 */
198 207 QPen QBarSet::labelPen() const
199 208 {
200 209 return m_labelPen;
201 210 }
202 211
203 212 /*!
204 213 Sets \a brush of the values that are drawn on top of this barset
205 214 */
206 215 void QBarSet::setLabelBrush(const QBrush &brush)
207 216 {
208 217 m_labelBrush = brush;
209 218 emit valueChanged();
210 219 }
211 220
212 221 /*!
213 222 Returns brush of the values that are drawn on top of this barset
214 223 */
215 224 QBrush QBarSet::labelBrush() const
216 225 {
217 226 return m_labelBrush;
218 227 }
219 228
220 229 /*!
221 230 Sets the \a font for values that are drawn on top of this barset
222 231 */
223 232 void QBarSet::setLabelFont(const QFont &font)
224 233 {
225 234 m_labelFont = font;
226 235 emit valueChanged();
227 236 }
228 237
229 238 /*!
230 239 Returns the pen for values that are drawn on top of this set
231 240 */
232 241 QFont QBarSet::labelFont() const
233 242 {
234 243 return m_labelFont;
235 244 }
236 245
237 246 /*!
238 247 Sets the visibility of barset values to \a visible
239 248 */
240 249 void QBarSet::setLabelsVisible(bool visible)
241 250 {
242 251 m_labelsVisible = visible;
243 252 emit labelsVisibleChanged(visible);
244 253 }
245 254
246 255 /*!
247 256 Returns the visibility of values
248 257 */
249 258 bool QBarSet::labelsVisible() const
250 259 {
251 260 return m_labelsVisible;
252 261 }
253 262
254 263 /*!
255 264 \internal \a pos
256 265 */
257 266 void QBarSet::barHoverEnterEvent(QPoint pos)
258 267 {
259 268 emit showToolTip(pos, m_name);
260 269 emit hoverEnter(pos);
261 270 }
262 271
263 272 /*!
264 273 \internal
265 274 */
266 275 void QBarSet::barHoverLeaveEvent()
267 276 {
268 277 // Emit signal to user of charts
269 278 emit hoverLeave();
270 279 }
271 280
272 281 #include "moc_qbarset.cpp"
273 282
274 283 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now