##// END OF EJS Templates
fixed barchart signals with pimpl. drilldown works now
sauimone -
r968:ecf1d49ffcb6
parent child
Show More
@@ -25,9 +25,9
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 Bar::Bar(QString category, QGraphicsItem *parent)
29 : QGraphicsRectItem(parent),
30 m_category(category)
28 Bar::Bar(QBarSet *barset, QString category, QGraphicsItem *parent) : QGraphicsRectItem(parent),
29 m_category(category),
30 m_barset(barset)
31 31 {
32 32 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
33 33 setAcceptHoverEvents(true);
@@ -36,6 +36,7 Bar::Bar(QString category, QGraphicsItem *parent)
36 36 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
37 37 {
38 38 emit clicked(m_category, event->button());
39 emit clicked(m_barset, m_category, event->button());
39 40 }
40 41
41 42 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -26,12 +26,14
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 class QBarSet;
30
29 31 // Single visual bar item of chart
30 32 class Bar : public QObject, public QGraphicsRectItem
31 33 {
32 34 Q_OBJECT
33 35 public:
34 Bar(QString category, QGraphicsItem *parent = 0);
36 Bar(QBarSet *barset, QString category, QGraphicsItem *parent = 0);
35 37
36 38 public:
37 39 void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -40,11 +42,13 public:
40 42
41 43 Q_SIGNALS:
42 44 void clicked(QString category, Qt::MouseButtons button);
45 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
43 46 void hoverEntered(QPoint pos);
44 47 void hoverLeaved();
45 48
46 49 private:
47 50 QString m_category;
51 QBarSet *m_barset;
48 52 };
49 53
50 54 QTCOMMERCIALCHART_END_NAMESPACE
@@ -82,9 +82,10 void BarChartItem::dataChanged()
82 82 QString category = m_series->d_func()->categoryName(c);
83 83 for (int s = 0; s < m_series->barsetCount(); s++) {
84 84 QBarSet *set = m_series->d_func()->barsetAt(s);
85 Bar *bar = new Bar(category,this);
85 Bar *bar = new Bar(set,category,this);
86 86 m_bars.append(bar);
87 87 connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons)));
88 connect(bar, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), m_series, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)));
88 89 connect(bar, SIGNAL(hoverEntered(QPoint)), set->d_ptr.data(), SLOT(barHoverEnterEvent(QPoint)));
89 90 connect(bar, SIGNAL(hoverLeaved()), set->d_ptr.data(), SLOT(barHoverLeaveEvent()));
90 91 m_layout.append(QRectF(0, 0, 0, 0));
@@ -97,7 +98,7 void BarChartItem::dataChanged()
97 98 QBarSet *set = m_series->d_func()->barsetAt(s);
98 99 BarLabel *value = new BarLabel(*set, this);
99 100 m_labels.append(value);
100 connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
101 connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
101 102 }
102 103 }
103 104 }
@@ -87,7 +87,6 void QBarSeries::appendBarSet(QBarSet *set)
87 87 {
88 88 Q_D(QBarSeries);
89 89 d->m_internalModel->appendBarSet(set);
90 QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
91 90 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
92 91 emit d->restructuredBars();
93 92 }
@@ -100,7 +99,6 void QBarSeries::appendBarSet(QBarSet *set)
100 99 void QBarSeries::removeBarSet(QBarSet *set)
101 100 {
102 101 Q_D(QBarSeries);
103 QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
104 102 d->m_internalModel->removeBarSet(set);
105 103 emit d->restructuredBars();
106 104 }
@@ -115,7 +113,6 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
115 113 Q_D(QBarSeries);
116 114 foreach (QBarSet* barset, sets) {
117 115 d->m_internalModel->appendBarSet(barset);
118 QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
119 116 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
120 117 }
121 118 emit d->restructuredBars();
@@ -132,7 +129,6 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
132 129 Q_D(QBarSeries);
133 130
134 131 foreach (QBarSet* barset, sets) {
135 QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
136 132 d->m_internalModel->removeBarSet(barset);
137 133 }
138 134 emit d->restructuredBars();
@@ -285,21 +281,16 void QBarSeriesPrivate::setToolTipEnabled(bool enabled)
285 281 if (enabled) {
286 282 for (int i=0; i<m_internalModel->barsetCount(); i++) {
287 283 QBarSet *set = m_internalModel->barsetAt(i);
288 connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
284 connect(set->d_ptr.data(), SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
289 285 }
290 286 } else {
291 287 for (int i=0; i<m_internalModel->barsetCount(); i++) {
292 288 QBarSet *set = m_internalModel->barsetAt(i);
293 disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
289 disconnect(set->d_ptr.data(), SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
294 290 }
295 291 }
296 292 }
297 293
298 void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button)
299 {
300 emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
301 }
302
303 294 qreal QBarSeriesPrivate::min()
304 295 {
305 296 return m_internalModel->min();
@@ -36,7 +36,7 public:
36 36 BarChartModel& modelInternal();
37 37
38 38 Q_SIGNALS:
39 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals
39 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
40 40 void selected();
41 41 void updatedBars();
42 42 void restructuredBars();
@@ -44,7 +44,6 Q_SIGNALS:
44 44
45 45 public Q_SLOTS:
46 46 void setToolTipEnabled(bool enabled = true); // enables tooltips
47 void barsetClicked(QString category, Qt::MouseButtons button);
48 47
49 48 private Q_SLOTS:
50 49 // slots for updating bars when data in model changes
@@ -67,8 +67,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
67 67 QBarSet::QBarSet(QString name, QObject *parent)
68 68 : QObject(parent)
69 69 ,d_ptr(new QBarSetPrivate(name,this))
70 // ,m_name(name)
71 // ,m_labelsVisible(false)
72 70 {
73 71 }
74 72
@@ -74,6 +74,7 private:
74 74 friend class QBarSeries;
75 75 friend class BarLegendMarker;
76 76 friend class BarChartItem;
77 friend class QBarSeriesPrivate;
77 78 };
78 79
79 80 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now