From ecf1d49ffcb6b436753c5901f35dd376307b95fc 2012-04-10 14:29:53 From: sauimone Date: 2012-04-10 14:29:53 Subject: [PATCH] fixed barchart signals with pimpl. drilldown works now --- diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index 6d2e699..8f2c9ae 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -25,9 +25,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -Bar::Bar(QString category, QGraphicsItem *parent) - : QGraphicsRectItem(parent), - m_category(category) +Bar::Bar(QBarSet *barset, QString category, QGraphicsItem *parent) : QGraphicsRectItem(parent), + m_category(category), + m_barset(barset) { setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); setAcceptHoverEvents(true); @@ -36,6 +36,7 @@ Bar::Bar(QString category, QGraphicsItem *parent) void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) { emit clicked(m_category, event->button()); + emit clicked(m_barset, m_category, event->button()); } void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) diff --git a/src/barchart/bar_p.h b/src/barchart/bar_p.h index c7c6a46..7d1543c 100644 --- a/src/barchart/bar_p.h +++ b/src/barchart/bar_p.h @@ -26,12 +26,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QBarSet; + // Single visual bar item of chart class Bar : public QObject, public QGraphicsRectItem { Q_OBJECT public: - Bar(QString category, QGraphicsItem *parent = 0); + Bar(QBarSet *barset, QString category, QGraphicsItem *parent = 0); public: void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -40,11 +42,13 @@ public: Q_SIGNALS: void clicked(QString category, Qt::MouseButtons button); + void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); void hoverEntered(QPoint pos); void hoverLeaved(); private: QString m_category; + QBarSet *m_barset; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index e5fb50b..f19e0f6 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -82,9 +82,10 @@ void BarChartItem::dataChanged() QString category = m_series->d_func()->categoryName(c); for (int s = 0; s < m_series->barsetCount(); s++) { QBarSet *set = m_series->d_func()->barsetAt(s); - Bar *bar = new Bar(category,this); + Bar *bar = new Bar(set,category,this); m_bars.append(bar); connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); + connect(bar, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), m_series, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons))); connect(bar, SIGNAL(hoverEntered(QPoint)), set->d_ptr.data(), SLOT(barHoverEnterEvent(QPoint))); connect(bar, SIGNAL(hoverLeaved()), set->d_ptr.data(), SLOT(barHoverLeaveEvent())); m_layout.append(QRectF(0, 0, 0, 0)); @@ -97,7 +98,7 @@ void BarChartItem::dataChanged() QBarSet *set = m_series->d_func()->barsetAt(s); BarLabel *value = new BarLabel(*set, this); m_labels.append(value); - connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); + connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); } } } diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 1160d48..7697b5a 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -87,7 +87,6 @@ void QBarSeries::appendBarSet(QBarSet *set) { Q_D(QBarSeries); d->m_internalModel->appendBarSet(set); - QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged())); emit d->restructuredBars(); } @@ -100,7 +99,6 @@ void QBarSeries::appendBarSet(QBarSet *set) void QBarSeries::removeBarSet(QBarSet *set) { Q_D(QBarSeries); - QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); d->m_internalModel->removeBarSet(set); emit d->restructuredBars(); } @@ -115,7 +113,6 @@ void QBarSeries::appendBarSets(QList sets) Q_D(QBarSeries); foreach (QBarSet* barset, sets) { d->m_internalModel->appendBarSet(barset); - QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); } emit d->restructuredBars(); @@ -132,7 +129,6 @@ void QBarSeries::removeBarSets(QList sets) Q_D(QBarSeries); foreach (QBarSet* barset, sets) { - QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); d->m_internalModel->removeBarSet(barset); } emit d->restructuredBars(); @@ -285,21 +281,16 @@ void QBarSeriesPrivate::setToolTipEnabled(bool enabled) if (enabled) { for (int i=0; ibarsetCount(); i++) { QBarSet *set = m_internalModel->barsetAt(i); - connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); + connect(set->d_ptr.data(), SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); } } else { for (int i=0; ibarsetCount(); i++) { QBarSet *set = m_internalModel->barsetAt(i); - disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); + disconnect(set->d_ptr.data(), SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); } } } -void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) -{ - emit clicked(qobject_cast(sender()), category, button); -} - qreal QBarSeriesPrivate::min() { return m_internalModel->min(); diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index a7223f4..1a75b73 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -36,7 +36,7 @@ public: BarChartModel& modelInternal(); Q_SIGNALS: - void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals + void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); void selected(); void updatedBars(); void restructuredBars(); @@ -44,7 +44,6 @@ Q_SIGNALS: public Q_SLOTS: void setToolTipEnabled(bool enabled = true); // enables tooltips - void barsetClicked(QString category, Qt::MouseButtons button); private Q_SLOTS: // slots for updating bars when data in model changes diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index d96bc7b..2a3f662 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -67,8 +67,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QBarSet::QBarSet(QString name, QObject *parent) : QObject(parent) ,d_ptr(new QBarSetPrivate(name,this)) -// ,m_name(name) -// ,m_labelsVisible(false) { } diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index d10100c..1552046 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -74,6 +74,7 @@ private: friend class QBarSeries; friend class BarLegendMarker; friend class BarChartItem; + friend class QBarSeriesPrivate; }; QTCOMMERCIALCHART_END_NAMESPACE