##// END OF EJS Templates
Add mousebuttons to pie clicked signals
Jani Honkonen -
r707:0529e02041c3
parent child
Show More
@@ -298,7 +298,7 public:
298 *m_series << new CustomSlice(50.0, "Slice 5");
298 *m_series << new CustomSlice(50.0, "Slice 5");
299 m_chartView->addSeries(m_series);
299 m_chartView->addSeries(m_series);
300
300
301 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
301 connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons)));
302
302
303 // chart settings
303 // chart settings
304 m_themeComboBox = new QComboBox();
304 m_themeComboBox = new QComboBox();
@@ -483,8 +483,10 public Q_SLOTS:
483 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
483 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
484 }
484 }
485
485
486 void handleSliceClicked(QPieSlice* slice)
486 void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons)
487 {
487 {
488 Q_UNUSED(buttons);
489
488 m_slice = static_cast<CustomSlice*>(slice);
490 m_slice = static_cast<CustomSlice*>(slice);
489
491
490 // name
492 // name
@@ -95,12 +95,12 int main(int argc, char *argv[])
95 foreach (QString month, months)
95 foreach (QString month, months)
96 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
96 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
97
97
98 QObject::connect(series, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
98 QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
99
99
100 *yearSeries << new DrilldownSlice(series->total(), name, series);
100 *yearSeries << new DrilldownSlice(series->total(), name, series);
101 }
101 }
102
102
103 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
103 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
104
104
105 drilldownChart->changeSeries(yearSeries);
105 drilldownChart->changeSeries(yearSeries);
106
106
@@ -57,7 +57,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
57 PieSliceItem* item = new PieSliceItem(this);
57 PieSliceItem* item = new PieSliceItem(this);
58 m_slices.insert(s, item);
58 m_slices.insert(s, item);
59 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
59 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
60 connect(item, SIGNAL(clicked()), s, SIGNAL(clicked()));
60 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked(Qt::MouseButtons)));
61 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
61 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
62 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
62 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
63
63
@@ -24,7 +24,7 PieSliceItem::PieSliceItem(QGraphicsItem* parent)
24 :QGraphicsObject(parent)
24 :QGraphicsObject(parent)
25 {
25 {
26 setAcceptHoverEvents(true);
26 setAcceptHoverEvents(true);
27 setAcceptedMouseButtons(Qt::LeftButton);
27 setAcceptedMouseButtons(Qt::MouseButtonMask);
28 setZValue(ChartPresenter::PieSeriesZValue);
28 setZValue(ChartPresenter::PieSeriesZValue);
29 }
29 }
30
30
@@ -76,9 +76,9 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
76 emit hoverLeave();
76 emit hoverLeave();
77 }
77 }
78
78
79 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
79 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
80 {
80 {
81 emit clicked();
81 emit clicked(event->buttons());
82 }
82 }
83
83
84 void PieSliceItem::setSliceData(PieSliceData sliceData)
84 void PieSliceItem::setSliceData(PieSliceData sliceData)
@@ -34,7 +34,7 public: // from QGraphicsItem
34 void mousePressEvent(QGraphicsSceneMouseEvent *event);
34 void mousePressEvent(QGraphicsSceneMouseEvent *event);
35
35
36 Q_SIGNALS:
36 Q_SIGNALS:
37 void clicked();
37 void clicked(Qt::MouseButtons buttons);
38 void hoverEnter();
38 void hoverEnter();
39 void hoverLeave();
39 void hoverLeave();
40
40
@@ -80,12 +80,12 void QPieSeriesPrivate::sliceChanged()
80 updateDerivativeData();
80 updateDerivativeData();
81 }
81 }
82
82
83 void QPieSeriesPrivate::sliceClicked()
83 void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons)
84 {
84 {
85 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
85 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
86 Q_ASSERT(m_slices.contains(slice));
86 Q_ASSERT(m_slices.contains(slice));
87 Q_Q(QPieSeries);
87 Q_Q(QPieSeries);
88 emit q->clicked(slice);
88 emit q->clicked(slice, buttons);
89 }
89 }
90
90
91 void QPieSeriesPrivate::sliceHoverEnter()
91 void QPieSeriesPrivate::sliceHoverEnter()
@@ -240,7 +240,7 void QPieSeries::add(QList<QPieSlice*> slices)
240
240
241 foreach (QPieSlice* s, slices) {
241 foreach (QPieSlice* s, slices) {
242 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
242 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
243 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
243 connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
244 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
244 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
245 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
245 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
246 }
246 }
@@ -57,7 +57,7 public:
57 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
57 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
58
58
59 Q_SIGNALS:
59 Q_SIGNALS:
60 void clicked(QPieSlice* slice);
60 void clicked(QPieSlice* slice, Qt::MouseButtons buttons);
61 void hoverEnter(QPieSlice* slice);
61 void hoverEnter(QPieSlice* slice);
62 void hoverLeave(QPieSlice* slice);
62 void hoverLeave(QPieSlice* slice);
63 void added(QList<QPieSlice*> slices);
63 void added(QList<QPieSlice*> slices);
@@ -16,9 +16,9 public:
16
16
17 void updateDerivativeData();
17 void updateDerivativeData();
18
18
19 public Q_SLOTS: // TODO: should be private and not visible in the interface at all
19 public Q_SLOTS:
20 void sliceChanged();
20 void sliceChanged();
21 void sliceClicked();
21 void sliceClicked(Qt::MouseButtons buttons);
22 void sliceHoverEnter();
22 void sliceHoverEnter();
23 void sliceHoverLeave();
23 void sliceHoverLeave();
24 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
24 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
@@ -51,7 +51,7 public:
51 qreal explodeDistanceFactor() const;
51 qreal explodeDistanceFactor() const;
52
52
53 Q_SIGNALS:
53 Q_SIGNALS:
54 void clicked();
54 void clicked(Qt::MouseButtons buttons);
55 void hoverEnter();
55 void hoverEnter();
56 void hoverLeave();
56 void hoverLeave();
57 void changed();
57 void changed();
General Comments 0
You need to be logged in to leave comments. Login now