@@ -22,7 +22,9 | |||
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "barlabel_p.h" |
|
24 | 24 | #include "qbarset.h" |
|
25 | #include "qbarset_p.h" | |
|
25 | 26 | #include "qbarseries.h" |
|
27 | #include "qbarseries_p.h" | |
|
26 | 28 | #include "qchart.h" |
|
27 | 29 | #include "qchartaxis.h" |
|
28 | 30 | #include "qchartaxiscategories.h" |
@@ -40,9 +42,9 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |||
|
40 | 42 | m_series(series) |
|
41 | 43 | { |
|
42 | 44 | setFlag(ItemClipsChildrenToShape); |
|
43 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); | |
|
44 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
|
45 | connect(series, SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
|
45 | connect(series->d_func(), SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); | |
|
46 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
|
47 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
|
46 | 48 | setZValue(ChartPresenter::BarSeriesZValue); |
|
47 | 49 | dataChanged(); |
|
48 | 50 | } |
@@ -77,14 +79,14 void BarChartItem::dataChanged() | |||
|
77 | 79 | |
|
78 | 80 | // Create new graphic items for bars |
|
79 | 81 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
80 | QString category = m_series->categoryName(c); | |
|
82 | QString category = m_series->d_func()->categoryName(c); | |
|
81 | 83 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
82 | QBarSet *set = m_series->barsetAt(s); | |
|
84 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
|
83 | 85 | Bar *bar = new Bar(category,this); |
|
84 | 86 | m_bars.append(bar); |
|
85 | 87 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); |
|
86 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
|
87 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
|
88 | connect(bar, SIGNAL(hoverEntered(QPoint)), set->d_ptr.data(), SLOT(barHoverEnterEvent(QPoint))); | |
|
89 | connect(bar, SIGNAL(hoverLeaved()), set->d_ptr.data(), SLOT(barHoverLeaveEvent())); | |
|
88 | 90 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
89 | 91 | } |
|
90 | 92 | } |
@@ -92,7 +94,7 void BarChartItem::dataChanged() | |||
|
92 | 94 | // Create labels |
|
93 | 95 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
94 | 96 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
95 | QBarSet *set = m_series->barsetAt(s); | |
|
97 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
|
96 | 98 | BarLabel *value = new BarLabel(*set, this); |
|
97 | 99 | m_labels.append(value); |
|
98 | 100 | connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); |
@@ -121,7 +123,7 QVector<QRectF> BarChartItem::calculateLayout() | |||
|
121 | 123 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
122 | 124 | qreal yPos = height + scale * m_domainMinY; |
|
123 | 125 | for (int set = 0; set < setCount; set++) { |
|
124 | QBarSet* barSet = m_series->barsetAt(set); | |
|
126 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
125 | 127 | |
|
126 | 128 | qreal barHeight = barSet->valueAt(category) * scale; |
|
127 | 129 | Bar* bar = m_bars.at(itemIndex); |
@@ -21,6 +21,7 | |||
|
21 | 21 | #include "percentbarchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "barlabel_p.h" |
|
24 | #include "qbarseries_p.h" | |
|
24 | 25 | #include "qbarset.h" |
|
25 | 26 | #include <QDebug> |
|
26 | 27 | |
@@ -49,11 +50,11 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
49 | 50 | |
|
50 | 51 | int itemIndex(0); |
|
51 | 52 | for (int category = 0; category < categoryCount; category++) { |
|
52 | qreal colSum = m_series->categorySum(category); | |
|
53 | qreal colSum = m_series->d_func()->categorySum(category); | |
|
53 | 54 | qreal percentage = (100 / colSum); |
|
54 | 55 | qreal yPos = height + domainScale * m_domainMinY; |
|
55 | 56 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
56 | QBarSet* barSet = m_series->barsetAt(set); | |
|
57 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
57 | 58 | qreal barHeight = barSet->valueAt(category) * percentage * domainScale; |
|
58 | 59 | Bar* bar = m_bars.at(itemIndex); |
|
59 | 60 | bar->setPen(barSet->pen()); |
@@ -63,8 +64,8 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
63 | 64 | |
|
64 | 65 | BarLabel* label = m_labels.at(itemIndex); |
|
65 | 66 | |
|
66 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
|
67 | int p = m_series->percentageAt(set,category) * 100; | |
|
67 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { | |
|
68 | int p = m_series->d_func()->percentageAt(set,category) * 100; | |
|
68 | 69 | QString vString(QString::number(p)); |
|
69 | 70 | vString.truncate(3); |
|
70 | 71 | vString.append("%"); |
@@ -176,12 +176,6 void QBarSeries::removeCategory(int i) | |||
|
176 | 176 | int QBarSeries::barsetCount() const |
|
177 | 177 | { |
|
178 | 178 | Q_D(const QBarSeries); |
|
179 | /* | |
|
180 | // if(m_model) | |
|
181 | // return m_mapBarTop - m_mapBarBottom; | |
|
182 | // else | |
|
183 | ||
|
184 | */ | |
|
185 | 179 | return d->m_internalModel->barsetCount(); |
|
186 | 180 | } |
|
187 | 181 | |
@@ -204,26 +198,6 QList<QBarSet*> QBarSeries::barSets() const | |||
|
204 | 198 | } |
|
205 | 199 | |
|
206 | 200 | /*! |
|
207 | \internal \a index | |
|
208 | */ | |
|
209 | QBarSet* QBarSeries::barsetAt(int index) | |
|
210 | { | |
|
211 | Q_D(QBarSeries); | |
|
212 | return d->barsetAt(index); | |
|
213 | // return m_internalModel->barsetAt(index); | |
|
214 | } | |
|
215 | ||
|
216 | /*! | |
|
217 | \internal \a category | |
|
218 | */ | |
|
219 | QString QBarSeries::categoryName(int category) | |
|
220 | { | |
|
221 | Q_D(QBarSeries); | |
|
222 | return d->categoryName(category); | |
|
223 | // return m_internalModel->categoryName(category); | |
|
224 | } | |
|
225 | ||
|
226 | /*! | |
|
227 | 201 | Enables or disables tooltip depending on parameter \a enabled. |
|
228 | 202 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
229 | 203 | Calling without parameter \a enabled, enables the tooltip |
@@ -232,111 +206,6 void QBarSeries::setToolTipEnabled(bool enabled) | |||
|
232 | 206 | { |
|
233 | 207 | Q_D(QBarSeries); |
|
234 | 208 | d->setToolTipEnabled(enabled); |
|
235 | /* | |
|
236 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
|
237 | if (enabled) { | |
|
238 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
239 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
240 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
241 | } | |
|
242 | } else { | |
|
243 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
244 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
245 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
246 | } | |
|
247 | } | |
|
248 | */ | |
|
249 | } | |
|
250 | ||
|
251 | ||
|
252 | /*! | |
|
253 | \internal \a category | |
|
254 | */ | |
|
255 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
|
256 | { | |
|
257 | Q_D(QBarSeries); | |
|
258 | d->barsetClicked(category,button); | |
|
259 | // emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
|
260 | } | |
|
261 | ||
|
262 | /*! | |
|
263 | \internal | |
|
264 | */ | |
|
265 | qreal QBarSeries::min() | |
|
266 | { | |
|
267 | Q_D(QBarSeries); | |
|
268 | return d->min(); | |
|
269 | //return m_internalModel->min(); | |
|
270 | } | |
|
271 | ||
|
272 | /*! | |
|
273 | \internal | |
|
274 | */ | |
|
275 | qreal QBarSeries::max() | |
|
276 | { | |
|
277 | Q_D(QBarSeries); | |
|
278 | return d->max(); | |
|
279 | // return m_internalModel->max(); | |
|
280 | } | |
|
281 | ||
|
282 | /*! | |
|
283 | \internal \a set \a category | |
|
284 | */ | |
|
285 | qreal QBarSeries::valueAt(int set, int category) | |
|
286 | { | |
|
287 | Q_D(QBarSeries); | |
|
288 | return d->valueAt(set,category); | |
|
289 | // return m_internalModel->valueAt(set, category); | |
|
290 | } | |
|
291 | ||
|
292 | /*! | |
|
293 | \internal \a set \a category | |
|
294 | */ | |
|
295 | qreal QBarSeries::percentageAt(int set, int category) | |
|
296 | { | |
|
297 | Q_D(QBarSeries); | |
|
298 | return d->percentageAt(set,category); | |
|
299 | // return m_internalModel->percentageAt(set, category); | |
|
300 | } | |
|
301 | ||
|
302 | /*! | |
|
303 | \internal \a category | |
|
304 | */ | |
|
305 | qreal QBarSeries::categorySum(int category) | |
|
306 | { | |
|
307 | Q_D(QBarSeries); | |
|
308 | return d->categorySum(category); | |
|
309 | // return m_internalModel->categorySum(category); | |
|
310 | } | |
|
311 | ||
|
312 | /*! | |
|
313 | \internal \a category | |
|
314 | */ | |
|
315 | qreal QBarSeries::absoluteCategorySum(int category) | |
|
316 | { | |
|
317 | Q_D(QBarSeries); | |
|
318 | return d->absoluteCategorySum(category); | |
|
319 | // return m_internalModel->absoluteCategorySum(category); | |
|
320 | } | |
|
321 | ||
|
322 | /*! | |
|
323 | \internal | |
|
324 | */ | |
|
325 | qreal QBarSeries::maxCategorySum() | |
|
326 | { | |
|
327 | Q_D(QBarSeries); | |
|
328 | return d->maxCategorySum(); | |
|
329 | // return m_internalModel->maxCategorySum(); | |
|
330 | } | |
|
331 | ||
|
332 | /*! | |
|
333 | \internal | |
|
334 | */ | |
|
335 | BarChartModel& QBarSeries::modelInternal() | |
|
336 | { | |
|
337 | Q_D(QBarSeries); | |
|
338 | return d->modelInternal(); | |
|
339 | // return *m_internalModel; | |
|
340 | 209 | } |
|
341 | 210 | |
|
342 | 211 | /*! |
@@ -347,31 +216,6 bool QBarSeries::setModel(QAbstractItemModel *model) | |||
|
347 | 216 | { |
|
348 | 217 | Q_D(QBarSeries); |
|
349 | 218 | return d->setModel(model); |
|
350 | /* | |
|
351 | // disconnect signals from old model | |
|
352 | if(m_model) | |
|
353 | { | |
|
354 | disconnect(m_model, 0, this, 0); | |
|
355 | m_mapCategories = -1; | |
|
356 | m_mapBarBottom = -1; | |
|
357 | m_mapBarTop = -1; | |
|
358 | m_mapFirst = 0; | |
|
359 | m_mapCount = 0; | |
|
360 | m_mapOrientation = Qt::Vertical; | |
|
361 | } | |
|
362 | ||
|
363 | // set new model | |
|
364 | if(model) | |
|
365 | { | |
|
366 | m_model = model; | |
|
367 | return true; | |
|
368 | } | |
|
369 | else | |
|
370 | { | |
|
371 | m_model = 0; | |
|
372 | return false; | |
|
373 | } | |
|
374 | */ | |
|
375 | 219 | } |
|
376 | 220 | |
|
377 | 221 | /*! |
@@ -386,138 +230,6 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoun | |||
|
386 | 230 | { |
|
387 | 231 | Q_D(QBarSeries); |
|
388 | 232 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
389 | /* | |
|
390 | if (!m_model) | |
|
391 | return; | |
|
392 | ||
|
393 | m_mapCategories = categories; | |
|
394 | m_mapBarBottom = bottomBoundry; | |
|
395 | m_mapBarTop = topBoundry; | |
|
396 | // m_mapFirst = 1; | |
|
397 | m_mapOrientation = orientation; | |
|
398 | ||
|
399 | // connect the signals | |
|
400 | if (m_mapOrientation == Qt::Vertical) { | |
|
401 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
|
402 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
403 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
404 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
|
405 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
406 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
|
407 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
408 | } else { | |
|
409 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
|
410 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
411 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
412 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
|
413 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
414 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
|
415 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
416 | } | |
|
417 | ||
|
418 | // create the initial bars | |
|
419 | delete m_internalModel; | |
|
420 | if (m_mapOrientation == Qt::Vertical) { | |
|
421 | QStringList categories; | |
|
422 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
423 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
|
424 | m_internalModel = new BarChartModel(categories, this); | |
|
425 | ||
|
426 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
427 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
|
428 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
429 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
|
430 | appendBarSet(barSet); | |
|
431 | } | |
|
432 | } else { | |
|
433 | QStringList categories; | |
|
434 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
435 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
|
436 | m_internalModel = new BarChartModel(categories, this); | |
|
437 | ||
|
438 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
439 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
|
440 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
441 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
|
442 | appendBarSet(barSet); | |
|
443 | } | |
|
444 | } | |
|
445 | */ | |
|
446 | } | |
|
447 | ||
|
448 | /*! | |
|
449 | \internal | |
|
450 | */ | |
|
451 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
452 | { | |
|
453 | Q_D(QBarSeries); | |
|
454 | d->modelUpdated(topLeft,bottomRight); | |
|
455 | /* | |
|
456 | Q_UNUSED(bottomRight) | |
|
457 | ||
|
458 | if (m_mapOrientation == Qt::Vertical) | |
|
459 | { | |
|
460 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
461 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
|
462 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
463 | } | |
|
464 | else | |
|
465 | { | |
|
466 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
467 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
|
468 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
469 | } | |
|
470 | */ | |
|
471 | } | |
|
472 | ||
|
473 | /*! | |
|
474 | \internal | |
|
475 | */ | |
|
476 | void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
|
477 | { | |
|
478 | Q_D(QBarSeries); | |
|
479 | d->modelDataAdded(parent,start,end); | |
|
480 | /* | |
|
481 | if (m_mapOrientation == Qt::Vertical) { | |
|
482 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
|
483 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
484 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
|
485 | } | |
|
486 | } else { | |
|
487 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
|
488 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
489 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
|
490 | } | |
|
491 | } | |
|
492 | emit restructuredBars(); | |
|
493 | */ | |
|
494 | } | |
|
495 | ||
|
496 | /*! | |
|
497 | \internal | |
|
498 | */ | |
|
499 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
500 | { | |
|
501 | Q_D(QBarSeries); | |
|
502 | d->modelDataRemoved(parent,start,end); | |
|
503 | /* | |
|
504 | Q_UNUSED(parent) | |
|
505 | Q_UNUSED(end) | |
|
506 | ||
|
507 | removeCategory(start - m_mapFirst); | |
|
508 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
509 | { | |
|
510 | barsetAt(i)->removeValue(start - m_mapFirst); | |
|
511 | } | |
|
512 | emit restructuredBars(); | |
|
513 | */ | |
|
514 | } | |
|
515 | ||
|
516 | void QBarSeries::barsetChanged() | |
|
517 | { | |
|
518 | Q_D(QBarSeries); | |
|
519 | d->barsetChanged(); | |
|
520 | // emit updatedBars(); | |
|
521 | 233 | } |
|
522 | 234 | |
|
523 | 235 | QBarCategories QBarSeries::categories() const |
@@ -773,7 +485,6 void QBarSeriesPrivate::barsetChanged() | |||
|
773 | 485 | |
|
774 | 486 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
775 | 487 | { |
|
776 | Q_Q(QBarSeries); | |
|
777 | 488 | qreal minX(domain.minX()); |
|
778 | 489 | qreal minY(domain.minY()); |
|
779 | 490 | qreal maxX(domain.maxX()); |
@@ -781,8 +492,8 void QBarSeriesPrivate::scaleDomain(Domain& domain) | |||
|
781 | 492 | int tickXCount(domain.tickXCount()); |
|
782 | 493 | int tickYCount(domain.tickYCount()); |
|
783 | 494 | |
|
784 |
qreal x = |
|
|
785 |
qreal y = |
|
|
495 | qreal x = m_internalModel->categoryCount(); | |
|
496 | qreal y = max(); | |
|
786 | 497 | minX = qMin(minX, x); |
|
787 | 498 | minY = qMin(minY, y); |
|
788 | 499 | maxX = qMax(maxX, x); |
@@ -61,65 +61,21 public: | |||
|
61 | 61 | bool setModel(QAbstractItemModel *model); |
|
62 | 62 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
63 | 63 | |
|
64 | public: | |
|
65 | // TODO: Functions below this are not part of api and will be moved | |
|
66 | // to private implementation, when we start using it | |
|
67 | // TODO: TO PIMPL ---> | |
|
68 | QBarSet* barsetAt(int index); | |
|
69 | QString categoryName(int category); | |
|
70 | qreal min(); | |
|
71 | qreal max(); | |
|
72 | qreal valueAt(int set, int category); | |
|
73 | qreal percentageAt(int set, int category); | |
|
74 | qreal categorySum(int category); | |
|
75 | qreal absoluteCategorySum(int category); | |
|
76 | qreal maxCategorySum(); | |
|
77 | BarChartModel& modelInternal(); | |
|
78 | // <--- TO PIMPL | |
|
79 | ||
|
80 | 64 | protected: |
|
81 | 65 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
82 | 66 | |
|
83 | 67 | Q_SIGNALS: |
|
84 |
void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); |
|
|
68 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); | |
|
85 | 69 | void selected(); |
|
86 | // | |
|
87 | void updatedBars(); | |
|
88 | void restructuredBars(); | |
|
89 | ||
|
90 | // TODO: internal signals, these to private implementation. | |
|
91 | // TODO: TO PIMPL ---> | |
|
92 | // void showToolTip(QPoint pos, QString tip); | |
|
93 | // <--- TO PIMPL | |
|
94 | 70 | |
|
95 | 71 | public Q_SLOTS: |
|
96 | 72 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
97 | 73 | |
|
98 | // TODO: TO PIMPL ---> | |
|
99 | void barsetClicked(QString category, Qt::MouseButtons button); | |
|
100 | // <--- TO PIMPL | |
|
101 | ||
|
102 | private Q_SLOTS: | |
|
103 | // slots for updating bars when data in model changes | |
|
104 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
105 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
106 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
|
107 | void barsetChanged(); | |
|
108 | ||
|
109 | 74 | protected: |
|
110 | 75 | Q_DECLARE_PRIVATE(QBarSeries) |
|
111 | ||
|
112 | /* | |
|
113 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
|
114 | ||
|
115 | // QAbstractItemModel* m_model; | |
|
116 | int m_mapCategories; | |
|
117 | int m_mapBarBottom; | |
|
118 | int m_mapBarTop; | |
|
119 | int m_mapFirst; | |
|
120 | int m_mapCount; | |
|
121 | Qt::Orientation m_mapOrientation; | |
|
122 | */ | |
|
76 | friend class BarChartItem; | |
|
77 | friend class PercentBarChartItem; | |
|
78 | friend class StackedBarChartItem; | |
|
123 | 79 | }; |
|
124 | 80 | |
|
125 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -73,6 +73,7 private: | |||
|
73 | 73 | Q_DISABLE_COPY(QBarSet) |
|
74 | 74 | friend class QBarSeries; |
|
75 | 75 | friend class BarLegendMarker; |
|
76 | friend class BarChartItem; | |
|
76 | 77 | }; |
|
77 | 78 | |
|
78 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -21,6 +21,7 | |||
|
21 | 21 | #include "qstackedbarseries.h" |
|
22 | 22 | #include "qstackedbarseries_p.h" |
|
23 | 23 | #include "stackedbarchartitem_p.h" |
|
24 | #include "barchartmodel_p.h" | |
|
24 | 25 | #include "chartdataset_p.h" |
|
25 | 26 | #include "charttheme_p.h" |
|
26 | 27 | #include "chartanimator_p.h" |
@@ -69,7 +70,6 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QBarCategories categories, QS | |||
|
69 | 70 | |
|
70 | 71 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
71 | 72 | { |
|
72 | Q_Q(QStackedBarSeries); | |
|
73 | 73 | qreal minX(domain.minX()); |
|
74 | 74 | qreal minY(domain.minY()); |
|
75 | 75 | qreal maxX(domain.maxX()); |
@@ -77,8 +77,8 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |||
|
77 | 77 | int tickXCount(domain.tickXCount()); |
|
78 | 78 | int tickYCount(domain.tickYCount()); |
|
79 | 79 | |
|
80 |
qreal x = |
|
|
81 |
qreal y = |
|
|
80 | qreal x = m_internalModel->categoryCount(); | |
|
81 | qreal y = maxCategorySum(); | |
|
82 | 82 | minX = qMin(minX, x); |
|
83 | 83 | minY = qMin(minY, y); |
|
84 | 84 | maxX = qMax(maxX, x); |
@@ -21,6 +21,8 | |||
|
21 | 21 | #include "stackedbarchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "barlabel_p.h" |
|
24 | #include "qbarset_p.h" | |
|
25 | #include "qbarseries_p.h" | |
|
24 | 26 | #include "qbarset.h" |
|
25 | 27 | |
|
26 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -49,7 +51,7 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||
|
49 | 51 | for (int category = 0; category < categotyCount; category++) { |
|
50 | 52 | qreal yPos = height + scale * m_domainMinY; |
|
51 | 53 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
52 | QBarSet* barSet = m_series->barsetAt(set); | |
|
54 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
|
53 | 55 | |
|
54 | 56 | qreal barHeight = barSet->valueAt(category) * scale; |
|
55 | 57 | Bar* bar = m_bars.at(itemIndex); |
@@ -314,8 +314,9 void TableWidget::updateChartType(bool toggle) | |||
|
314 | 314 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
315 | 315 | barSeries->setToolTipEnabled(true); |
|
316 | 316 | m_chart->addSeries(barSeries); |
|
317 |
|
|
|
318 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
317 | QList<QBarSet*> barsets = barSeries->barSets(); | |
|
318 | for (int i = 0; i < barsets.count(); i++) { | |
|
319 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
319 | 320 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
320 | 321 | } |
|
321 | 322 | } |
General Comments 0
You need to be logged in to leave comments.
Login now