summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@theqtcompany.com>2014-11-13 14:51:00 +0200
committerTitta Heikkala <titta.heikkala@theqtcompany.com>2014-11-13 15:39:13 +0200
commit4909289ecbd79024e5cdbe3974292935979aded8 (patch)
tree97f0a6f6e1e10e90be8003b0ca7a1c3229c51a53
parent704036e35c0a6515014cdc4fa5c983c9059d9011 (diff)
Fix clicked, released and doubleClicked signal points
The clicked, released and doubleClicked signals for line, spline and area series return the point where the press was triggered. Change-Id: I075bb213657a7cadabdec3a72fde7cf5f412e982 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>
-rw-r--r--src/charts/areachart/areachartitem.cpp8
-rw-r--r--src/charts/areachart/qareaseries.cpp25
-rw-r--r--src/charts/barchart/bar.cpp3
-rw-r--r--src/charts/barchart/bar_p.h1
-rw-r--r--src/charts/boxplotchart/boxwhiskers.cpp5
-rw-r--r--src/charts/boxplotchart/boxwhiskers_p.h1
-rw-r--r--src/charts/linechart/linechartitem.cpp8
-rw-r--r--src/charts/piechart/piesliceitem.cpp3
-rw-r--r--src/charts/piechart/piesliceitem_p.h1
-rw-r--r--src/charts/piechart/qpieseries.cpp8
-rw-r--r--src/charts/scatterchart/scatterchartitem_p.h9
-rw-r--r--src/charts/splinechart/splinechartitem.cpp8
-rw-r--r--src/charts/xychart/qxyseries.cpp25
-rw-r--r--tests/auto/qlineseries/tst_qlineseries.cpp2
-rw-r--r--tests/auto/qsplineseries/tst_qsplineseries.cpp2
-rw-r--r--tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml9
16 files changed, 70 insertions, 48 deletions
diff --git a/src/charts/areachart/areachartitem.cpp b/src/charts/areachart/areachartitem.cpp
index 54a80d56..557ea01e 100644
--- a/src/charts/areachart/areachartitem.cpp
+++ b/src/charts/areachart/areachartitem.cpp
@@ -265,16 +265,16 @@ void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void AreaChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- emit released(m_upper->domain()->calculateDomainPoint(event->pos()));
- if (m_lastMousePos == event->pos() && m_mousePressed)
- emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
+ emit released(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
+ if (m_mousePressed)
+ emit clicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
m_mousePressed = false;
ChartItem::mouseReleaseEvent(event);
}
void AreaChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
- emit doubleClicked(m_upper->domain()->calculateDomainPoint(event->pos()));
+ emit doubleClicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
ChartItem::mouseDoubleClickEvent(event);
}
diff --git a/src/charts/areachart/qareaseries.cpp b/src/charts/areachart/qareaseries.cpp
index eabaa703..535a9935 100644
--- a/src/charts/areachart/qareaseries.cpp
+++ b/src/charts/areachart/qareaseries.cpp
@@ -145,11 +145,15 @@ QT_CHARTS_BEGIN_NAMESPACE
/*!
\fn void QAreaSeries::clicked(const QPointF& point)
- \brief Signal is emitted when user clicks the \a point on area chart.
+ \brief Signal is emitted when user clicks the \a point on area chart. The \a point is the point
+ where the press was triggered.
+ \sa pressed, released, doubleClicked
*/
/*!
\qmlsignal AreaSeries::onClicked(QPointF point)
- Signal is emitted when user clicks the \a point on area chart.
+ Signal is emitted when user clicks the \a point on area chart. The \a point is the point where
+ the press was triggered.
+ \sa onPressed, onReleased, onDoubleClicked
*/
/*!
@@ -168,28 +172,37 @@ QT_CHARTS_BEGIN_NAMESPACE
/*!
\fn void QAreaSeries::pressed(const QPointF& point)
\brief Signal is emitted when user presses the \a point on area chart.
+ \sa clicked, released, doubleClicked
*/
/*!
\qmlsignal AreaSeries::onPressed(QPointF point)
Signal is emitted when user presses the \a point on area chart.
+ \sa onClicked, onReleased, onDoubleClicked
*/
/*!
\fn void QAreaSeries::released(const QPointF& point)
- \brief Signal is emitted when user releases the \a point on area chart.
+ \brief Signal is emitted when user releases a press that was triggered on a \a point on area
+ chart.
+ \sa pressed, clicked, doubleClicked
*/
/*!
\qmlsignal AreaSeries::onReleased(QPointF point)
- Signal is emitted when user releases the \a point on area chart.
+ Signal is emitted when user releases a press that was triggered on a \a point on area chart.
+ \sa onPressed, onClicked, onDoubleClicked
*/
/*!
\fn void QAreaSeries::doubleClicked(const QPointF& point)
- \brief Signal is emitted when user doubleclicks the \a point on area chart.
+ \brief Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the
+ point where the first press was triggered.
+ \sa pressed, released, clicked
*/
/*!
\qmlsignal AreaSeries::onDoubleClicked(QPointF point)
- Signal is emitted when user doubleclicks the \a point on area chart.
+ Signal is emitted when user doubleclicks the \a point on area chart. The \a point is the point
+ where the first press was triggered.
+ \sa onPressed, onReleased, onClicked
*/
/*!
diff --git a/src/charts/barchart/bar.cpp b/src/charts/barchart/bar.cpp
index 2ca4fc92..9cba5005 100644
--- a/src/charts/barchart/bar.cpp
+++ b/src/charts/barchart/bar.cpp
@@ -45,7 +45,6 @@ Bar::~Bar()
void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit pressed(m_index, m_barset);
- m_lastMousePos = event->pos();
m_mousePressed = true;
QGraphicsItem::mousePressEvent(event);
}
@@ -68,7 +67,7 @@ void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void Bar::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
emit released(m_index, m_barset);
- if (m_lastMousePos == event->pos() && m_mousePressed)
+ if (m_mousePressed)
emit clicked(m_index, m_barset);
m_mousePressed = false;
QGraphicsItem::mouseReleaseEvent(event);
diff --git a/src/charts/barchart/bar_p.h b/src/charts/barchart/bar_p.h
index e1232b3f..c03a61ff 100644
--- a/src/charts/barchart/bar_p.h
+++ b/src/charts/barchart/bar_p.h
@@ -64,7 +64,6 @@ private:
QBarSet *m_barset;
bool m_hovering;
- QPointF m_lastMousePos;
bool m_mousePressed;
};
diff --git a/src/charts/boxplotchart/boxwhiskers.cpp b/src/charts/boxplotchart/boxwhiskers.cpp
index d8c93d67..1234d1b6 100644
--- a/src/charts/boxplotchart/boxwhiskers.cpp
+++ b/src/charts/boxplotchart/boxwhiskers.cpp
@@ -40,8 +40,8 @@ BoxWhiskers::~BoxWhiskers()
void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
+ Q_UNUSED(event)
emit pressed(m_boxSet);
- m_lastMousePos = event->pos();
m_mousePressed = true;
}
@@ -59,8 +59,9 @@ void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void BoxWhiskers::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
+ Q_UNUSED(event)
emit released(m_boxSet);
- if (m_lastMousePos == event->pos() && m_mousePressed)
+ if (m_mousePressed)
emit clicked(m_boxSet);
}
diff --git a/src/charts/boxplotchart/boxwhiskers_p.h b/src/charts/boxplotchart/boxwhiskers_p.h
index 0ec36e68..22b8205c 100644
--- a/src/charts/boxplotchart/boxwhiskers_p.h
+++ b/src/charts/boxplotchart/boxwhiskers_p.h
@@ -99,7 +99,6 @@ private:
qreal m_geometryLeft;
qreal m_geometryRight;
- QPointF m_lastMousePos;
bool m_mousePressed;
};
diff --git a/src/charts/linechart/linechartitem.cpp b/src/charts/linechart/linechartitem.cpp
index e48a9678..91175b73 100644
--- a/src/charts/linechart/linechartitem.cpp
+++ b/src/charts/linechart/linechartitem.cpp
@@ -404,16 +404,16 @@ void LineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void LineChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- emit XYChart::released(domain()->calculateDomainPoint(event->pos()));
- if (m_lastMousePos == event->pos() && m_mousePressed)
- emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
+ emit XYChart::released(domain()->calculateDomainPoint(m_lastMousePos));
+ if (m_mousePressed)
+ emit XYChart::clicked(domain()->calculateDomainPoint(m_lastMousePos));
m_mousePressed = false;
QGraphicsItem::mouseReleaseEvent(event);
}
void LineChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
- emit XYChart::doubleClicked(domain()->calculateDomainPoint(event->pos()));
+ emit XYChart::doubleClicked(domain()->calculateDomainPoint(m_lastMousePos));
QGraphicsItem::mouseDoubleClickEvent(event);
}
diff --git a/src/charts/piechart/piesliceitem.cpp b/src/charts/piechart/piesliceitem.cpp
index bd822b0e..43d076ca 100644
--- a/src/charts/piechart/piesliceitem.cpp
+++ b/src/charts/piechart/piesliceitem.cpp
@@ -109,14 +109,13 @@ void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit pressed(event->buttons());
- m_lastMousePos = event->pos();
m_mousePressed = true;
}
void PieSliceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
emit released(event->buttons());
- if (m_lastMousePos == event->pos() && m_mousePressed)
+ if (m_mousePressed)
emit clicked(event->buttons());
}
diff --git a/src/charts/piechart/piesliceitem_p.h b/src/charts/piechart/piesliceitem_p.h
index 8a0d71f2..405dc85b 100644
--- a/src/charts/piechart/piesliceitem_p.h
+++ b/src/charts/piechart/piesliceitem_p.h
@@ -86,7 +86,6 @@ private:
bool m_hovered;
QGraphicsTextItem *m_labelItem;
- QPointF m_lastMousePos;
bool m_mousePressed;
friend class PieSliceAnimation;
diff --git a/src/charts/piechart/qpieseries.cpp b/src/charts/piechart/qpieseries.cpp
index 5442e2fe..2b4c8788 100644
--- a/src/charts/piechart/qpieseries.cpp
+++ b/src/charts/piechart/qpieseries.cpp
@@ -304,7 +304,7 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
- \fn void QPieSeries::clicked(QPieSlice* slice)
+ \fn void QPieSeries::clicked(QPieSlice *slice)
This signal is emitted when a \a slice has been clicked.
\sa QPieSlice::clicked()
*/
@@ -314,7 +314,7 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
- \fn void QPieSeries::pressed(QPieSlice* slice)
+ \fn void QPieSeries::pressed(QPieSlice *slice)
This signal is emitted when a \a slice has been pressed.
\sa QPieSlice::pressed()
*/
@@ -324,7 +324,7 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
- \fn void QPieSeries::released(QPieSlice* slice)
+ \fn void QPieSeries::released(QPieSlice *slice)
This signal is emitted when a \a slice has been released.
\sa QPieSlice::released()
*/
@@ -334,7 +334,7 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
- \fn void QPieSeries::doubleClicked(QPieSlice* slice)
+ \fn void QPieSeries::doubleClicked(QPieSlice *slice)
This signal is emitted when a \a slice has been doubleClicked.
\sa QPieSlice::doubleClicked()
*/
diff --git a/src/charts/scatterchart/scatterchartitem_p.h b/src/charts/scatterchart/scatterchartitem_p.h
index 64e84796..b2cbcb20 100644
--- a/src/charts/scatterchart/scatterchartitem_p.h
+++ b/src/charts/scatterchart/scatterchartitem_p.h
@@ -59,8 +59,6 @@ public:
void markerReleased(QGraphicsItem *item);
void markerDoubleClicked(QGraphicsItem *item);
- void setLastMousePosition(const QPointF pos) {m_lastMousePos = pos;}
- QPointF lastMousePosition() const {return m_lastMousePos;}
void setMousePressed(bool pressed = true) {m_mousePressed = pressed;}
bool mousePressed() {return m_mousePressed;}
@@ -89,7 +87,6 @@ private:
QFont m_pointLabelsFont;
QColor m_pointLabelsColor;
- QPointF m_lastMousePos;
bool m_mousePressed;
};
@@ -110,7 +107,6 @@ protected:
{
QGraphicsEllipseItem::mousePressEvent(event);
m_parent->markerPressed(this);
- m_parent->setLastMousePosition(event->pos());
m_parent->setMousePressed();
}
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -127,7 +123,7 @@ protected:
{
QGraphicsEllipseItem::mouseReleaseEvent(event);
m_parent->markerReleased(this);
- if (m_parent->lastMousePosition() == event->pos() && m_parent->mousePressed())
+ if (m_parent->mousePressed())
m_parent->markerSelected(this);
m_parent->setMousePressed(false);
}
@@ -158,7 +154,6 @@ protected:
{
QGraphicsRectItem::mousePressEvent(event);
m_parent->markerPressed(this);
- m_parent->setLastMousePosition(event->pos());
m_parent->setMousePressed();
}
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -175,7 +170,7 @@ protected:
{
QGraphicsRectItem::mouseReleaseEvent(event);
m_parent->markerReleased(this);
- if (m_parent->lastMousePosition() == event->pos() && m_parent->mousePressed())
+ if (m_parent->mousePressed())
m_parent->markerSelected(this);
m_parent->setMousePressed(false);
}
diff --git a/src/charts/splinechart/splinechartitem.cpp b/src/charts/splinechart/splinechartitem.cpp
index 9d55ad7e..d34b53d7 100644
--- a/src/charts/splinechart/splinechartitem.cpp
+++ b/src/charts/splinechart/splinechartitem.cpp
@@ -484,16 +484,16 @@ void SplineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void SplineChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- emit XYChart::released(domain()->calculateDomainPoint(event->pos()));
- if (m_lastMousePos == event->pos() && m_mousePressed)
- emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
+ emit XYChart::released(domain()->calculateDomainPoint(m_lastMousePos));
+ if (m_mousePressed)
+ emit XYChart::clicked(domain()->calculateDomainPoint(m_lastMousePos));
m_mousePressed = false;
QGraphicsItem::mouseReleaseEvent(event);
}
void SplineChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
- emit XYChart::doubleClicked(domain()->calculateDomainPoint(event->pos()));
+ emit XYChart::doubleClicked(domain()->calculateDomainPoint(m_lastMousePos));
QGraphicsItem::mouseDoubleClickEvent(event);
}
diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp
index 3c3b9fdf..df527174 100644
--- a/src/charts/xychart/qxyseries.cpp
+++ b/src/charts/xychart/qxyseries.cpp
@@ -225,11 +225,14 @@ QT_CHARTS_BEGIN_NAMESPACE
/*!
\fn void QXYSeries::clicked(const QPointF& point)
- \brief Signal is emitted when user clicks the \a point on chart.
+ \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point
+ where the press was triggered.
+ \sa pressed, released, doubleClicked
*/
/*!
\qmlsignal XYSeries::onClicked(QPointF point)
- Signal is emitted when user clicks the \a point on chart. For example:
+ Signal is emitted when user clicks the \a point on chart. The \a point is the point where the
+ press was triggered. For example:
\code
LineSeries {
XYPoint { x: 0; y: 0 }
@@ -237,6 +240,7 @@ QT_CHARTS_BEGIN_NAMESPACE
onClicked: console.log("onClicked: " + point.x + ", " + point.y);
}
\endcode
+ \sa onPressed, onReleased, onDoubleClicked
*/
/*!
@@ -255,6 +259,7 @@ QT_CHARTS_BEGIN_NAMESPACE
/*!
\fn void QXYSeries::pressed(const QPointF& point)
\brief Signal is emitted when user presses the \a point on chart.
+ \sa clicked, released, doubleClicked
*/
/*!
\qmlsignal XYSeries::onPressed(QPointF point)
@@ -266,15 +271,18 @@ QT_CHARTS_BEGIN_NAMESPACE
onPressed: console.log("onPressed: " + point.x + ", " + point.y);
}
\endcode
+ \sa onClicked, onReleased, onDoubleClicked
*/
/*!
\fn void QXYSeries::released(const QPointF& point)
- \brief Signal is emitted when user releases the \a point on chart.
+ \brief Signal is emitted when user releases a press that was triggered on a \a point on chart.
+ \sa pressed, clicked, doubleClicked
*/
/*!
\qmlsignal XYSeries::onReleased(QPointF point)
- Signal is emitted when user releases the \a point on chart. For example:
+ Signal is emitted when user releases a press that was triggered on a \a point on chart.
+ For example:
\code
LineSeries {
XYPoint { x: 0; y: 0 }
@@ -282,15 +290,19 @@ QT_CHARTS_BEGIN_NAMESPACE
onReleased: console.log("onReleased: " + point.x + ", " + point.y);
}
\endcode
+ \sa onPressed, onClicked, onDoubleClicked
*/
/*!
\fn void QXYSeries::doubleClicked(const QPointF& point)
- \brief Signal is emitted when user doubleclicks the \a point on chart.
+ \brief Signal is emitted when user doubleclicks the \a point on chart. The \a point is the
+ point where the first press was triggered.
+ \sa pressed, released, clicked
*/
/*!
\qmlsignal XYSeries::onDoubleClicked(QPointF point)
- Signal is emitted when user doubleclicks the \a point on chart. For example:
+ Signal is emitted when user doubleclicks the \a point on chart. The \a point is the point where
+ the first press was triggered. For example:
\code
LineSeries {
XYPoint { x: 0; y: 0 }
@@ -298,6 +310,7 @@ QT_CHARTS_BEGIN_NAMESPACE
onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y);
}
\endcode
+ \sa onPressed, onReleased, onClicked
*/
/*!
diff --git a/tests/auto/qlineseries/tst_qlineseries.cpp b/tests/auto/qlineseries/tst_qlineseries.cpp
index ffceea95..b4a557be 100644
--- a/tests/auto/qlineseries/tst_qlineseries.cpp
+++ b/tests/auto/qlineseries/tst_qlineseries.cpp
@@ -184,6 +184,8 @@ void tst_QLineSeries::doubleClickedSignal()
QSignalSpy seriesSpy(lineSeries, SIGNAL(doubleClicked(QPointF)));
QPointF checkPoint = view.chart()->mapToPosition(linePoint);
+ // mouseClick needed first to save the position
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
diff --git a/tests/auto/qsplineseries/tst_qsplineseries.cpp b/tests/auto/qsplineseries/tst_qsplineseries.cpp
index 3b9a23be..52b97d23 100644
--- a/tests/auto/qsplineseries/tst_qsplineseries.cpp
+++ b/tests/auto/qsplineseries/tst_qsplineseries.cpp
@@ -177,6 +177,8 @@ void tst_QSplineSeries::doubleClickedSignal()
QSignalSpy seriesSpy(splineSeries, SIGNAL(doubleClicked(QPointF)));
QPointF checkPoint = view.chart()->mapToPosition(splinePoint);
+ // mouseClick needed first to save the position
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml
index 9c38d350..a7543934 100644
--- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml
+++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml
@@ -49,13 +49,13 @@ ChartView {
onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor);
onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth);
onCountChanged: console.log("scatterSeries.onCountChanged: " + count);
- onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
+ onPointLabelsVisibilityChanged: console.log("scatterSeries.onPointLabelsVisibilityChanged: "
+ visible);
- onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
+ onPointLabelsFormatChanged: console.log("scatterSeries.onPointLabelsFormatChanged: "
+ format);
- onPointLabelsFontChanged: console.log("lineSeries.onPointLabelsFontChanged: "
+ onPointLabelsFontChanged: console.log("scatterSeries.onPointLabelsFontChanged: "
+ font.family);
- onPointLabelsColorChanged: console.log("lineSeries.onPointLabelsColorChanged: "
+ onPointLabelsColorChanged: console.log("scatterSeries.onPointLabelsColorChanged: "
+ color);
onPressed: console.log(name + ".onPressed: " + point.x + ", " + point.y);
onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
@@ -76,4 +76,5 @@ ChartView {
onReleased: console.log(name + ".onReleased: " + point.x + ", " + point.y);
onDoubleClicked: console.log(name + ".onDoubleClicked: " + point.x + ", " + point.y);
}
+
}