##// END OF EJS Templates
Fix clicked, released and doubleClicked signal points...
Titta Heikkala -
r2746:4909289ecbd7
parent child
Show More
@@ -265,16 +265,16 void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
265 265
266 266 void AreaChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
267 267 {
268 emit released(m_upper->domain()->calculateDomainPoint(event->pos()));
269 if (m_lastMousePos == event->pos() && m_mousePressed)
270 emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
268 emit released(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
269 if (m_mousePressed)
270 emit clicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
271 271 m_mousePressed = false;
272 272 ChartItem::mouseReleaseEvent(event);
273 273 }
274 274
275 275 void AreaChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
276 276 {
277 emit doubleClicked(m_upper->domain()->calculateDomainPoint(event->pos()));
277 emit doubleClicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
278 278 ChartItem::mouseDoubleClickEvent(event);
279 279 }
280 280
@@ -145,11 +145,15 QT_CHARTS_BEGIN_NAMESPACE
145 145
146 146 /*!
147 147 \fn void QAreaSeries::clicked(const QPointF& point)
148 \brief Signal is emitted when user clicks the \a point on area chart.
148 \brief Signal is emitted when user clicks the \a point on area chart. The \a point is the point
149 where the press was triggered.
150 \sa pressed, released, doubleClicked
149 151 */
150 152 /*!
151 153 \qmlsignal AreaSeries::onClicked(QPointF point)
152 Signal is emitted when user clicks the \a point on area chart.
154 Signal is emitted when user clicks the \a point on area chart. The \a point is the point where
155 the press was triggered.
156 \sa onPressed, onReleased, onDoubleClicked
153 157 */
154 158
155 159 /*!
@@ -168,28 +172,37 QT_CHARTS_BEGIN_NAMESPACE
168 172 /*!
169 173 \fn void QAreaSeries::pressed(const QPointF& point)
170 174 \brief Signal is emitted when user presses the \a point on area chart.
175 \sa clicked, released, doubleClicked
171 176 */
172 177 /*!
173 178 \qmlsignal AreaSeries::onPressed(QPointF point)
174 179 Signal is emitted when user presses the \a point on area chart.
180 \sa onClicked, onReleased, onDoubleClicked
175 181 */
176 182
177 183 /*!
178 184 \fn void QAreaSeries::released(const QPointF& point)
179 \brief Signal is emitted when user releases the \a point on area chart.
185 \brief Signal is emitted when user releases a press that was triggered on a \a point on area
186 chart.
187 \sa pressed, clicked, doubleClicked
180 188 */
181 189 /*!
182 190 \qmlsignal AreaSeries::onReleased(QPointF point)
183 Signal is emitted when user releases the \a point on area chart.
191 Signal is emitted when user releases a press that was triggered on a \a point on area chart.
192 \sa onPressed, onClicked, onDoubleClicked
184 193 */
185 194
186 195 /*!
187 196 \fn void QAreaSeries::doubleClicked(const QPointF& point)
188 \brief Signal is emitted when user doubleclicks the \a point on area chart.
197 \brief Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the
198 point where the first press was triggered.
199 \sa pressed, released, clicked
189 200 */
190 201 /*!
191 202 \qmlsignal AreaSeries::onDoubleClicked(QPointF point)
192 Signal is emitted when user doubleclicks the \a point on area chart.
203 Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the point
204 where the first press was triggered.
205 \sa onPressed, onReleased, onClicked
193 206 */
194 207
195 208 /*!
@@ -45,7 +45,6 Bar::~Bar()
45 45 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
46 46 {
47 47 emit pressed(m_index, m_barset);
48 m_lastMousePos = event->pos();
49 48 m_mousePressed = true;
50 49 QGraphicsItem::mousePressEvent(event);
51 50 }
@@ -68,7 +67,7 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
68 67 void Bar::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
69 68 {
70 69 emit released(m_index, m_barset);
71 if (m_lastMousePos == event->pos() && m_mousePressed)
70 if (m_mousePressed)
72 71 emit clicked(m_index, m_barset);
73 72 m_mousePressed = false;
74 73 QGraphicsItem::mouseReleaseEvent(event);
@@ -64,7 +64,6 private:
64 64 QBarSet *m_barset;
65 65 bool m_hovering;
66 66
67 QPointF m_lastMousePos;
68 67 bool m_mousePressed;
69 68 };
70 69
@@ -40,8 +40,8 BoxWhiskers::~BoxWhiskers()
40 40
41 41 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
42 42 {
43 Q_UNUSED(event)
43 44 emit pressed(m_boxSet);
44 m_lastMousePos = event->pos();
45 45 m_mousePressed = true;
46 46 }
47 47
@@ -59,8 +59,9 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
59 59
60 60 void BoxWhiskers::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
61 61 {
62 Q_UNUSED(event)
62 63 emit released(m_boxSet);
63 if (m_lastMousePos == event->pos() && m_mousePressed)
64 if (m_mousePressed)
64 65 emit clicked(m_boxSet);
65 66 }
66 67
@@ -99,7 +99,6 private:
99 99 qreal m_geometryLeft;
100 100 qreal m_geometryRight;
101 101
102 QPointF m_lastMousePos;
103 102 bool m_mousePressed;
104 103 };
105 104
@@ -404,16 +404,16 void LineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
404 404
405 405 void LineChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
406 406 {
407 emit XYChart::released(domain()->calculateDomainPoint(event->pos()));
408 if (m_lastMousePos == event->pos() && m_mousePressed)
409 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
407 emit XYChart::released(domain()->calculateDomainPoint(m_lastMousePos));
408 if (m_mousePressed)
409 emit XYChart::clicked(domain()->calculateDomainPoint(m_lastMousePos));
410 410 m_mousePressed = false;
411 411 QGraphicsItem::mouseReleaseEvent(event);
412 412 }
413 413
414 414 void LineChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
415 415 {
416 emit XYChart::doubleClicked(domain()->calculateDomainPoint(event->pos()));
416 emit XYChart::doubleClicked(domain()->calculateDomainPoint(m_lastMousePos));
417 417 QGraphicsItem::mouseDoubleClickEvent(event);
418 418 }
419 419
@@ -109,14 +109,13 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
109 109 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
110 110 {
111 111 emit pressed(event->buttons());
112 m_lastMousePos = event->pos();
113 112 m_mousePressed = true;
114 113 }
115 114
116 115 void PieSliceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
117 116 {
118 117 emit released(event->buttons());
119 if (m_lastMousePos == event->pos() && m_mousePressed)
118 if (m_mousePressed)
120 119 emit clicked(event->buttons());
121 120 }
122 121
@@ -86,7 +86,6 private:
86 86 bool m_hovered;
87 87 QGraphicsTextItem *m_labelItem;
88 88
89 QPointF m_lastMousePos;
90 89 bool m_mousePressed;
91 90
92 91 friend class PieSliceAnimation;
@@ -304,7 +304,7 QT_CHARTS_BEGIN_NAMESPACE
304 304 */
305 305
306 306 /*!
307 \fn void QPieSeries::clicked(QPieSlice* slice)
307 \fn void QPieSeries::clicked(QPieSlice *slice)
308 308 This signal is emitted when a \a slice has been clicked.
309 309 \sa QPieSlice::clicked()
310 310 */
@@ -314,7 +314,7 QT_CHARTS_BEGIN_NAMESPACE
314 314 */
315 315
316 316 /*!
317 \fn void QPieSeries::pressed(QPieSlice* slice)
317 \fn void QPieSeries::pressed(QPieSlice *slice)
318 318 This signal is emitted when a \a slice has been pressed.
319 319 \sa QPieSlice::pressed()
320 320 */
@@ -324,7 +324,7 QT_CHARTS_BEGIN_NAMESPACE
324 324 */
325 325
326 326 /*!
327 \fn void QPieSeries::released(QPieSlice* slice)
327 \fn void QPieSeries::released(QPieSlice *slice)
328 328 This signal is emitted when a \a slice has been released.
329 329 \sa QPieSlice::released()
330 330 */
@@ -334,7 +334,7 QT_CHARTS_BEGIN_NAMESPACE
334 334 */
335 335
336 336 /*!
337 \fn void QPieSeries::doubleClicked(QPieSlice* slice)
337 \fn void QPieSeries::doubleClicked(QPieSlice *slice)
338 338 This signal is emitted when a \a slice has been doubleClicked.
339 339 \sa QPieSlice::doubleClicked()
340 340 */
@@ -59,8 +59,6 public:
59 59 void markerReleased(QGraphicsItem *item);
60 60 void markerDoubleClicked(QGraphicsItem *item);
61 61
62 void setLastMousePosition(const QPointF pos) {m_lastMousePos = pos;}
63 QPointF lastMousePosition() const {return m_lastMousePos;}
64 62 void setMousePressed(bool pressed = true) {m_mousePressed = pressed;}
65 63 bool mousePressed() {return m_mousePressed;}
66 64
@@ -89,7 +87,6 private:
89 87 QFont m_pointLabelsFont;
90 88 QColor m_pointLabelsColor;
91 89
92 QPointF m_lastMousePos;
93 90 bool m_mousePressed;
94 91 };
95 92
@@ -110,7 +107,6 protected:
110 107 {
111 108 QGraphicsEllipseItem::mousePressEvent(event);
112 109 m_parent->markerPressed(this);
113 m_parent->setLastMousePosition(event->pos());
114 110 m_parent->setMousePressed();
115 111 }
116 112 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -127,7 +123,7 protected:
127 123 {
128 124 QGraphicsEllipseItem::mouseReleaseEvent(event);
129 125 m_parent->markerReleased(this);
130 if (m_parent->lastMousePosition() == event->pos() && m_parent->mousePressed())
126 if (m_parent->mousePressed())
131 127 m_parent->markerSelected(this);
132 128 m_parent->setMousePressed(false);
133 129 }
@@ -158,7 +154,6 protected:
158 154 {
159 155 QGraphicsRectItem::mousePressEvent(event);
160 156 m_parent->markerPressed(this);
161 m_parent->setLastMousePosition(event->pos());
162 157 m_parent->setMousePressed();
163 158 }
164 159 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -175,7 +170,7 protected:
175 170 {
176 171 QGraphicsRectItem::mouseReleaseEvent(event);
177 172 m_parent->markerReleased(this);
178 if (m_parent->lastMousePosition() == event->pos() && m_parent->mousePressed())
173 if (m_parent->mousePressed())
179 174 m_parent->markerSelected(this);
180 175 m_parent->setMousePressed(false);
181 176 }
@@ -484,16 +484,16 void SplineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
484 484
485 485 void SplineChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
486 486 {
487 emit XYChart::released(domain()->calculateDomainPoint(event->pos()));
488 if (m_lastMousePos == event->pos() && m_mousePressed)
489 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
487 emit XYChart::released(domain()->calculateDomainPoint(m_lastMousePos));
488 if (m_mousePressed)
489 emit XYChart::clicked(domain()->calculateDomainPoint(m_lastMousePos));
490 490 m_mousePressed = false;
491 491 QGraphicsItem::mouseReleaseEvent(event);
492 492 }
493 493
494 494 void SplineChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
495 495 {
496 emit XYChart::doubleClicked(domain()->calculateDomainPoint(event->pos()));
496 emit XYChart::doubleClicked(domain()->calculateDomainPoint(m_lastMousePos));
497 497 QGraphicsItem::mouseDoubleClickEvent(event);
498 498 }
499 499
@@ -225,11 +225,14 QT_CHARTS_BEGIN_NAMESPACE
225 225
226 226 /*!
227 227 \fn void QXYSeries::clicked(const QPointF& point)
228 \brief Signal is emitted when user clicks the \a point on chart.
228 \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point
229 where the press was triggered.
230 \sa pressed, released, doubleClicked
229 231 */
230 232 /*!
231 233 \qmlsignal XYSeries::onClicked(QPointF point)
232 Signal is emitted when user clicks the \a point on chart. For example:
234 Signal is emitted when user clicks the \a point on chart. The \a point is the point where the
235 press was triggered. For example:
233 236 \code
234 237 LineSeries {
235 238 XYPoint { x: 0; y: 0 }
@@ -237,6 +240,7 QT_CHARTS_BEGIN_NAMESPACE
237 240 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
238 241 }
239 242 \endcode
243 \sa onPressed, onReleased, onDoubleClicked
240 244 */
241 245
242 246 /*!
@@ -255,6 +259,7 QT_CHARTS_BEGIN_NAMESPACE
255 259 /*!
256 260 \fn void QXYSeries::pressed(const QPointF& point)
257 261 \brief Signal is emitted when user presses the \a point on chart.
262 \sa clicked, released, doubleClicked
258 263 */
259 264 /*!
260 265 \qmlsignal XYSeries::onPressed(QPointF point)
@@ -266,15 +271,18 QT_CHARTS_BEGIN_NAMESPACE
266 271 onPressed: console.log("onPressed: " + point.x + ", " + point.y);
267 272 }
268 273 \endcode
274 \sa onClicked, onReleased, onDoubleClicked
269 275 */
270 276
271 277 /*!
272 278 \fn void QXYSeries::released(const QPointF& point)
273 \brief Signal is emitted when user releases the \a point on chart.
279 \brief Signal is emitted when user releases a press that was triggered on a \a point on chart.
280 \sa pressed, clicked, doubleClicked
274 281 */
275 282 /*!
276 283 \qmlsignal XYSeries::onReleased(QPointF point)
277 Signal is emitted when user releases the \a point on chart. For example:
284 Signal is emitted when user releases a press that was triggered on a \a point on chart.
285 For example:
278 286 \code
279 287 LineSeries {
280 288 XYPoint { x: 0; y: 0 }
@@ -282,15 +290,19 QT_CHARTS_BEGIN_NAMESPACE
282 290 onReleased: console.log("onReleased: " + point.x + ", " + point.y);
283 291 }
284 292 \endcode
293 \sa onPressed, onClicked, onDoubleClicked
285 294 */
286 295
287 296 /*!
288 297 \fn void QXYSeries::doubleClicked(const QPointF& point)
289 \brief Signal is emitted when user doubleclicks the \a point on chart.
298 \brief Signal is emitted when user doubleclicks the \a point on chart. The \a point is the
299 point where the first press was triggered.
300 \sa pressed, released, clicked
290 301 */
291 302 /*!
292 303 \qmlsignal XYSeries::onDoubleClicked(QPointF point)
293 Signal is emitted when user doubleclicks the \a point on chart. For example:
304 Signal is emitted when user doubleclicks the \a point on chart. The \a point is the point where
305 the first press was triggered. For example:
294 306 \code
295 307 LineSeries {
296 308 XYPoint { x: 0; y: 0 }
@@ -298,6 +310,7 QT_CHARTS_BEGIN_NAMESPACE
298 310 onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y);
299 311 }
300 312 \endcode
313 \sa onPressed, onReleased, onClicked
301 314 */
302 315
303 316 /*!
@@ -184,6 +184,8 void tst_QLineSeries::doubleClickedSignal()
184 184 QSignalSpy seriesSpy(lineSeries, SIGNAL(doubleClicked(QPointF)));
185 185
186 186 QPointF checkPoint = view.chart()->mapToPosition(linePoint);
187 // mouseClick needed first to save the position
188 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
187 189 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
188 190 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
189 191
@@ -177,6 +177,8 void tst_QSplineSeries::doubleClickedSignal()
177 177 QSignalSpy seriesSpy(splineSeries, SIGNAL(doubleClicked(QPointF)));
178 178
179 179 QPointF checkPoint = view.chart()->mapToPosition(splinePoint);
180 // mouseClick needed first to save the position
181 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
180 182 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
181 183 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
182 184
@@ -49,13 +49,13 ChartView {
49 49 onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor);
50 50 onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth);
51 51 onCountChanged: console.log("scatterSeries.onCountChanged: " + count);
52 onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
52 onPointLabelsVisibilityChanged: console.log("scatterSeries.onPointLabelsVisibilityChanged: "
53 53 + visible);
54 onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
54 onPointLabelsFormatChanged: console.log("scatterSeries.onPointLabelsFormatChanged: "
55 55 + format);
56 onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: "
56 onPointLabelsFontChanged: console.log("scatterSeries.onPointLabelsFontChanged: "
57 57 + font.family);
58 onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
58 onPointLabelsColorChanged: console.log("scatterSeries.onPointLabelsColorChanged: "
59 59 + color);
60 60 onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
61 61 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
@@ -76,4 +76,5 ChartView {
76 76 onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
77 77 onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
78 78 }
79
79 80 }
General Comments 0
You need to be logged in to leave comments. Login now