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