@@ -38,9 +38,10 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |||
|
38 | 38 | { |
|
39 | 39 | setFlag(ItemClipsChildrenToShape); |
|
40 | 40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
41 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool))); | |
|
41 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
|
42 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
|
42 | 43 | setZValue(ChartPresenter::BarSeriesZValue); |
|
43 | dataChanged(); | |
|
44 | handleDataStructureChanged(); | |
|
44 | 45 | } |
|
45 | 46 | |
|
46 | 47 | BarChartItem::~BarChartItem() |
@@ -59,7 +60,7 QRectF BarChartItem::boundingRect() const | |||
|
59 | 60 | return m_rect; |
|
60 | 61 | } |
|
61 | 62 | |
|
62 | void BarChartItem::dataChanged() | |
|
63 | void BarChartItem::handleDataStructureChanged() | |
|
63 | 64 | { |
|
64 | 65 | foreach(QGraphicsItem *item, childItems()) { |
|
65 | 66 | delete item; |
@@ -92,6 +93,7 void BarChartItem::dataChanged() | |||
|
92 | 93 | |
|
93 | 94 | // TODO: Is this the right place to call it? |
|
94 | 95 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
96 | handleLayoutChanged(); | |
|
95 | 97 | } |
|
96 | 98 | |
|
97 | 99 | QVector<QRectF> BarChartItem::calculateLayout() |
@@ -150,18 +152,20 QVector<QRectF> BarChartItem::calculateLayout() | |||
|
150 | 152 | |
|
151 | 153 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
152 | 154 | { |
|
153 | if (animator()) | |
|
155 | if (animator()) { | |
|
154 | 156 | animator()->updateLayout(this, m_layout, layout); |
|
155 | else | |
|
157 | } else { | |
|
156 | 158 | setLayout(layout); |
|
159 | } | |
|
157 | 160 | } |
|
158 | 161 | |
|
159 | 162 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
160 | 163 | { |
|
161 | 164 | m_layout = layout; |
|
162 | 165 | |
|
163 | for (int i=0; i < m_bars.count(); i++) | |
|
166 | for (int i=0; i < m_bars.count(); i++) { | |
|
164 | 167 | m_bars.at(i)->setRect(layout.at(i)); |
|
168 | } | |
|
165 | 169 | |
|
166 | 170 | update(); |
|
167 | 171 | } |
@@ -194,7 +198,7 void BarChartItem::handleLayoutChanged() | |||
|
194 | 198 | update(); |
|
195 | 199 | } |
|
196 | 200 | |
|
197 | void BarChartItem::labelsVisibleChanged(bool visible) | |
|
201 | void BarChartItem::handleLabelsVisibleChanged(bool visible) | |
|
198 | 202 | { |
|
199 | 203 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
200 | 204 | label->setVisible(visible); |
@@ -53,8 +53,6 public: | |||
|
53 | 53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
54 | 54 | QRectF boundingRect() const; |
|
55 | 55 | |
|
56 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
|
57 | ||
|
58 | 56 | virtual QVector<QRectF> calculateLayout(); |
|
59 | 57 | void applyLayout(const QVector<QRectF> &layout); |
|
60 | 58 | void setLayout(const QVector<QRectF> &layout); |
@@ -66,7 +64,8 public Q_SLOTS: | |||
|
66 | 64 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
67 | 65 | void handleGeometryChanged(const QRectF &size); |
|
68 | 66 | void handleLayoutChanged(); |
|
69 | void labelsVisibleChanged(bool visible); | |
|
67 | void handleLabelsVisibleChanged(bool visible); | |
|
68 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items | |
|
70 | 69 | |
|
71 | 70 | protected: |
|
72 | 71 |
@@ -428,11 +428,6 qreal QBarSeriesPrivate::maxCategorySum() | |||
|
428 | 428 | return max; |
|
429 | 429 | } |
|
430 | 430 | |
|
431 | void QBarSeriesPrivate::barsetChanged() | |
|
432 | { | |
|
433 | emit updatedBars(); | |
|
434 | } | |
|
435 | ||
|
436 | 431 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
437 | 432 | { |
|
438 | 433 | qreal minX(domain.minX()); |
@@ -486,7 +481,8 bool QBarSeriesPrivate::append(QBarSet *set) | |||
|
486 | 481 | return false; |
|
487 | 482 | } |
|
488 | 483 | m_barSets.append(set); |
|
489 |
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SL |
|
|
484 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
|
485 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
|
490 | 486 | if (m_dataset) { |
|
491 | 487 | m_dataset->updateSeries(q); // this notifies legend |
|
492 | 488 | } |
@@ -502,7 +498,8 bool QBarSeriesPrivate::remove(QBarSet *set) | |||
|
502 | 498 | return false; |
|
503 | 499 | } |
|
504 | 500 | m_barSets.removeOne(set); |
|
505 |
QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SL |
|
|
501 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
|
502 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
|
506 | 503 | if (m_dataset) { |
|
507 | 504 | m_dataset->updateSeries(q); // this notifies legend |
|
508 | 505 | } |
@@ -526,7 +523,8 bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |||
|
526 | 523 | |
|
527 | 524 | foreach (QBarSet* set, sets) { |
|
528 | 525 | m_barSets.append(set); |
|
529 |
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SL |
|
|
526 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
|
527 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
|
530 | 528 | } |
|
531 | 529 | if (m_dataset) { |
|
532 | 530 | m_dataset->updateSeries(q); // this notifies legend |
@@ -542,7 +540,8 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |||
|
542 | 540 | foreach (QBarSet* set, sets) { |
|
543 | 541 | if (m_barSets.contains(set)) { |
|
544 | 542 | m_barSets.removeOne(set); |
|
545 |
QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SL |
|
|
543 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
|
544 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
|
546 | 545 | setsRemoved = true; |
|
547 | 546 | } |
|
548 | 547 | } |
@@ -83,9 +83,6 Q_SIGNALS: | |||
|
83 | 83 | void categoriesUpdated(); |
|
84 | 84 | void labelsVisibleChanged(bool visible); |
|
85 | 85 | |
|
86 | private Q_SLOTS: | |
|
87 | void barsetChanged(); | |
|
88 | ||
|
89 | 86 | protected: |
|
90 | 87 | QList<QBarSet *> m_barSets; |
|
91 | 88 | QStringList m_categories; |
@@ -349,7 +349,8 void tst_QBarSet::customize() | |||
|
349 | 349 | |
|
350 | 350 | // Append set1 to series |
|
351 | 351 | QGroupedBarSeries *series = new QGroupedBarSeries(); |
|
352 | series->append(set1); | |
|
352 | bool success = series->append(set1); | |
|
353 | QVERIFY(success); | |
|
353 | 354 | |
|
354 | 355 | // Add series to the chart |
|
355 | 356 | QChartView view(new QChart()); |
General Comments 0
You need to be logged in to leave comments.
Login now