##// END OF EJS Templates
barchart: removed mousebuttons from clicked signal. removed selected signal. unified internal signal naming in barset and barseries private
sauimone -
r1008:e02fb893688e
parent child
Show More
@@ -40,7 +40,7 void DrilldownChart::changeSeries(QAbstractSeries *series)
40 axisY()->setNiceNumbersEnabled(true);
40 axisY()->setNiceNumbersEnabled(true);
41 }
41 }
42
42
43 void DrilldownChart::handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button)
43 void DrilldownChart::handleClicked(QBarSet *barset, QString category)
44 {
44 {
45 Q_UNUSED(barset)
45 Q_UNUSED(barset)
46 Q_UNUSED(button)
46 Q_UNUSED(button)
@@ -36,7 +36,7 public:
36 void changeSeries(QAbstractSeries *series);
36 void changeSeries(QAbstractSeries *series);
37
37
38 public Q_SLOTS:
38 public Q_SLOTS:
39 void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button);
39 void handleClicked(QBarSet *barset, QString category);
40
40
41 private:
41 private:
42 QAbstractSeries* m_currentSeries;
42 QAbstractSeries* m_currentSeries;
@@ -70,11 +70,11 int main(int argc, char *argv[])
70 }
70 }
71
71
72 // Use right click signal to implement drilldown
72 // Use right click signal to implement drilldown
73 QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
73 QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString)), drilldownChart, SLOT(handleClicked(QBarSet*,QString)));
74 }
74 }
75
75
76 // Enable drilldown from season series using right click.
76 // Enable drilldown from season series using right click.
77 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
77 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString)), drilldownChart, SLOT(handleClicked(QBarSet*,QString)));
78 //! [4]
78 //! [4]
79
79
80 //! [5]
80 //! [5]
@@ -35,8 +35,8 Bar::Bar(QBarSet *barset, QString category, QGraphicsItem *parent) : QGraphicsRe
35
35
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);
39 emit clicked(m_barset, m_category, event->button());
39 emit clicked(m_barset, m_category);
40 }
40 }
41
41
42 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
42 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -41,8 +41,8 public:
41 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
41 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
42
42
43 Q_SIGNALS:
43 Q_SIGNALS:
44 void clicked(QString category, Qt::MouseButtons button);
44 void clicked(QString category);
45 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
45 void clicked(QBarSet *barset, QString category);
46 void hovered(bool status);
46 void hovered(bool status);
47 void hovered(QBarSet *barset, bool status);
47 void hovered(QBarSet *barset, bool status);
48
48
@@ -80,8 +80,8 void BarChartItem::dataChanged()
80 QBarSet *set = m_series->d_func()->barsetAt(s);
80 QBarSet *set = m_series->d_func()->barsetAt(s);
81 Bar *bar = new Bar(set,category,this);
81 Bar *bar = new Bar(set,category,this);
82 m_bars.append(bar);
82 m_bars.append(bar);
83 connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons)));
83 connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString)));
84 connect(bar, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), m_series, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)));
84 connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString)));
85 connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool)));
85 connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool)));
86 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
86 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
87 m_layout.append(QRectF(0, 0, 0, 0));
87 m_layout.append(QRectF(0, 0, 0, 0));
@@ -49,20 +49,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
49 */
49 */
50
50
51 /*!
51 /*!
52 \fn void QBarSeries::clicked(QBarSet *barset, QString category, Qt::MouseButtons button)
52 \fn void QBarSeries::clicked(QBarSet *barset, QString category)
53
53
54 The signal is emitted if the user clicks with a mouse \a button on top of QBarSet \a barset of category \a category
54 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category
55 contained by the series.
55 contained by the series.
56 */
56 */
57
57
58 /*!
58 /*!
59 \fn void QBarSeries::selected()
60
61 The signal is emitted if the user selects/deselects the series. The logic for storing selections should be
62 implemented by the user of QBarSeries API.
63 */
64
65 /*!
66 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
59 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
67
60
68 The signal is emitted if mouse is hovered on top of series.
61 The signal is emitted if mouse is hovered on top of series.
@@ -105,58 +98,52 QAbstractSeries::QSeriesType QBarSeries::type() const
105
98
106 /*!
99 /*!
107 Adds a set of bars to series. Takes ownership of \a set.
100 Adds a set of bars to series. Takes ownership of \a set.
108 Connects the clicked(QString, Qt::MouseButtons) signal
109 of \a set to this series
110 */
101 */
111 void QBarSeries::appendBarSet(QBarSet *set)
102 void QBarSeries::appendBarSet(QBarSet *set)
112 {
103 {
113 Q_D(QBarSeries);
104 Q_D(QBarSeries);
114 d->m_barSets.append(set);
105 d->m_barSets.append(set);
115 QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
106 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
116 emit d->restructuredBars();
107 emit d->restructuredBars();
117 }
108 }
118
109
119 /*!
110 /*!
120 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
111 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
121 Disconnects the clicked(QString, Qt::MouseButtons) signal
122 of \a set from this series
123 */
112 */
124 void QBarSeries::removeBarSet(QBarSet *set)
113 void QBarSeries::removeBarSet(QBarSet *set)
125 {
114 {
126 Q_D(QBarSeries);
115 Q_D(QBarSeries);
127 if (d->m_barSets.contains(set)) {
116 if (d->m_barSets.contains(set)) {
128 d->m_barSets.removeOne(set);
117 d->m_barSets.removeOne(set);
118 QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
129 emit d->restructuredBars();
119 emit d->restructuredBars();
130 }
120 }
131 }
121 }
132
122
133 /*!
123 /*!
134 Adds a list of barsets to series. Takes ownership of \a sets.
124 Adds a list of barsets to series. Takes ownership of \a sets.
135 Connects the clicked(QString, Qt::MouseButtons) signals
136 of \a sets to this series
137 */
125 */
138 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
126 void QBarSeries::appendBarSets(QList<QBarSet* > sets)
139 {
127 {
140 Q_D(QBarSeries);
128 Q_D(QBarSeries);
141 foreach (QBarSet* barset, sets) {
129 foreach (QBarSet* set, sets) {
142 d->m_barSets.append(barset);
130 d->m_barSets.append(set);
143 QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
131 QObject::connect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
144 }
132 }
145 emit d->restructuredBars();
133 emit d->restructuredBars();
146 }
134 }
147
135
148 /*!
136 /*!
149 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
137 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
150 Disconnects the clicked(QString, Qt::MouseButtons) signal
151 of \a sets from this series
152 */
138 */
153 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
139 void QBarSeries::removeBarSets(QList<QBarSet* > sets)
154 {
140 {
155 Q_D(QBarSeries);
141 Q_D(QBarSeries);
156
142
157 foreach (QBarSet* barset, sets) {
143 foreach (QBarSet* set, sets) {
158 if (d->m_barSets.contains(barset)) {
144 if (d->m_barSets.contains(set)) {
159 d->m_barSets.removeOne(barset);
145 d->m_barSets.removeOne(set);
146 QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
160 }
147 }
161 }
148 }
162 emit d->restructuredBars();
149 emit d->restructuredBars();
@@ -62,8 +62,7 protected:
62 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
62 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
63
63
64 Q_SIGNALS:
64 Q_SIGNALS:
65 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
65 void clicked(QBarSet *barset, QString category);
66 void selected();
67 void hovered(QBarSet* barset, bool status);
66 void hovered(QBarSet* barset, bool status);
68
67
69 protected:
68 protected:
@@ -35,8 +35,7 public:
35 qreal maxCategorySum();
35 qreal maxCategorySum();
36
36
37 Q_SIGNALS:
37 Q_SIGNALS:
38 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button);
38 void clicked(QBarSet *barset, QString category);
39 void selected();
40 void updatedBars();
39 void updatedBars();
41 void restructuredBars();
40 void restructuredBars();
42
41
@@ -38,15 +38,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 */
38 */
39
39
40 /*!
40 /*!
41 \fn void QBarSet::clicked(QString category, Qt::MouseButtons button)
41 \fn void QBarSet::clicked(QString category)
42 \brief signals that set has been clicked
42 \brief signals that set has been clicked
43 Parameter \a category describes on which category was clicked
43 Parameter \a category describes on which category was clicked
44 Parameter \a button mouse button
45 */
46
47 /*!
48 \fn void QBarSet::selected()
49 \brief signals that set has been selected
50 */
44 */
51
45
52 /*!
46 /*!
@@ -96,7 +90,7 QString QBarSet::name() const
96 void QBarSet::append(const qreal value)
90 void QBarSet::append(const qreal value)
97 {
91 {
98 d_ptr->m_values.append(value);
92 d_ptr->m_values.append(value);
99 emit d_ptr->structureChanged();
93 emit d_ptr->restructuredBars();
100 }
94 }
101
95
102 /*!
96 /*!
@@ -116,6 +110,7 QBarSet& QBarSet::operator << (const qreal &value)
116 void QBarSet::insert(const int index, const qreal value)
110 void QBarSet::insert(const int index, const qreal value)
117 {
111 {
118 d_ptr->m_values.insert(index, value);
112 d_ptr->m_values.insert(index, value);
113 emit d_ptr->updatedBars();
119 }
114 }
120
115
121 /*!
116 /*!
@@ -125,6 +120,7 void QBarSet::insert(const int index, const qreal value)
125 void QBarSet::remove(const int index)
120 void QBarSet::remove(const int index)
126 {
121 {
127 d_ptr->m_values.removeAt(index);
122 d_ptr->m_values.removeAt(index);
123 emit d_ptr->updatedBars();
128 }
124 }
129
125
130 /*!
126 /*!
@@ -133,7 +129,7 void QBarSet::remove(const int index)
133 void QBarSet::replace(const int index, const qreal value)
129 void QBarSet::replace(const int index, const qreal value)
134 {
130 {
135 d_ptr->m_values.replace(index,value);
131 d_ptr->m_values.replace(index,value);
136 emit d_ptr->valueChanged();
132 emit d_ptr->updatedBars();
137 }
133 }
138
134
139 /*!
135 /*!
@@ -179,7 +175,7 void QBarSet::setPen(const QPen &pen)
179 {
175 {
180 if(d_ptr->m_pen!=pen){
176 if(d_ptr->m_pen!=pen){
181 d_ptr->m_pen = pen;
177 d_ptr->m_pen = pen;
182 emit d_ptr->valueChanged();
178 emit d_ptr->updatedBars();
183 }
179 }
184 }
180 }
185
181
@@ -198,7 +194,7 void QBarSet::setBrush(const QBrush &brush)
198 {
194 {
199 if(d_ptr->m_brush!=brush){
195 if(d_ptr->m_brush!=brush){
200 d_ptr->m_brush = brush;
196 d_ptr->m_brush = brush;
201 emit d_ptr->valueChanged();
197 emit d_ptr->updatedBars();
202 }
198 }
203 }
199 }
204
200
@@ -217,7 +213,7 void QBarSet::setLabelPen(const QPen &pen)
217 {
213 {
218 if(d_ptr->m_labelPen!=pen){
214 if(d_ptr->m_labelPen!=pen){
219 d_ptr->m_labelPen = pen;
215 d_ptr->m_labelPen = pen;
220 emit d_ptr->valueChanged();
216 emit d_ptr->updatedBars();
221 }
217 }
222 }
218 }
223
219
@@ -236,7 +232,7 void QBarSet::setLabelBrush(const QBrush &brush)
236 {
232 {
237 if(d_ptr->m_labelBrush!=brush){
233 if(d_ptr->m_labelBrush!=brush){
238 d_ptr->m_labelBrush = brush;
234 d_ptr->m_labelBrush = brush;
239 emit d_ptr->valueChanged();
235 emit d_ptr->updatedBars();
240 }
236 }
241 }
237 }
242
238
@@ -255,7 +251,7 void QBarSet::setLabelFont(const QFont &font)
255 {
251 {
256 if(d_ptr->m_labelFont!=font) {
252 if(d_ptr->m_labelFont!=font) {
257 d_ptr->m_labelFont = font;
253 d_ptr->m_labelFont = font;
258 emit d_ptr->valueChanged();
254 emit d_ptr->updatedBars();
259 }
255 }
260
256
261 }
257 }
@@ -68,8 +68,7 public:
68 bool labelsVisible() const;
68 bool labelsVisible() const;
69
69
70 Q_SIGNALS:
70 Q_SIGNALS:
71 void clicked(QString category, Qt::MouseButtons button);
71 void clicked(QString category);
72 void selected();
73 void hovered(bool status);
72 void hovered(bool status);
74
73
75 private:
74 private:
@@ -15,9 +15,9 public:
15 ~QBarSetPrivate();
15 ~QBarSetPrivate();
16
16
17 Q_SIGNALS:
17 Q_SIGNALS:
18 void clicked(QString category, Qt::MouseButtons button);
18 void clicked(QString category);
19 void structureChanged();
19 void restructuredBars();
20 void valueChanged();
20 void updatedBars();
21 void labelsVisibleChanged(bool visible);
21 void labelsVisibleChanged(bool visible);
22
22
23 public:
23 public:
@@ -139,7 +139,7 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend
139 m_barset(barset)
139 m_barset(barset)
140 {
140 {
141 QObject::connect(this, SIGNAL(selected()),barseries, SIGNAL(selected()));
141 QObject::connect(this, SIGNAL(selected()),barseries, SIGNAL(selected()));
142 QObject::connect(barset->d_ptr.data(), SIGNAL(valueChanged()), this, SLOT(updated()));
142 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
143 updated();
143 updated();
144 }
144 }
145
145
General Comments 0
You need to be logged in to leave comments. Login now