diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp index d6250fa..d2d2d07 100644 --- a/src/chartsqml2/declarativechart.cpp +++ b/src/chartsqml2/declarativechart.cpp @@ -250,6 +250,17 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \qmlmethod point ChartView::mapToValue(point position, AbstractSeries series) + Returns the value in the \a series domain that corresponds to the \a position relative to the + chart. +*/ + +/*! + \qmlmethod point ChartView::mapToPosition(point value, AbstractSeries series) + Returns the position on the chart that corresponds to the \a value in the \a series domain. +*/ + +/*! \qmlsignal ChartView::seriesAdded(AbstractSeries series) The \a series has been added to the chart. */ @@ -1037,6 +1048,16 @@ void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes axes->setAxisY(defaultAxis(Qt::Vertical, series)); } +QPointF DeclarativeChart::mapToValue(const QPointF &position, QAbstractSeries *series) +{ + return m_chart->mapToValue(position, series); +} + +QPointF DeclarativeChart::mapToPosition(const QPointF &value, QAbstractSeries *series) +{ + return m_chart->mapToPosition(value, series); +} + #include "moc_declarativechart.cpp" QT_CHARTS_END_NAMESPACE diff --git a/src/chartsqml2/declarativechart.h b/src/chartsqml2/declarativechart.h index 2105a27..3856cdc 100644 --- a/src/chartsqml2/declarativechart.h +++ b/src/chartsqml2/declarativechart.h @@ -167,6 +167,11 @@ public: Q_INVOKABLE void scrollRight(qreal pixels); Q_INVOKABLE void scrollUp(qreal pixels); Q_INVOKABLE void scrollDown(qreal pixels); + Q_REVISION(5) Q_INVOKABLE QPointF mapToValue(const QPointF &position, + QAbstractSeries *series = 0); + Q_REVISION(5) Q_INVOKABLE QPointF mapToPosition(const QPointF &value, + QAbstractSeries *series = 0); + Q_SIGNALS: void axisLabelsChanged(); diff --git a/src/chartsqml2/plugins.qmltypes b/src/chartsqml2/plugins.qmltypes index 9ca0e61..e822d44 100644 --- a/src/chartsqml2/plugins.qmltypes +++ b/src/chartsqml2/plugins.qmltypes @@ -1114,6 +1114,32 @@ Module { name: "scrollDown" Parameter { name: "pixels"; type: "double" } } + Method { + name: "mapToValue" + revision: 5 + type: "QPointF" + Parameter { name: "position"; type: "QPointF" } + Parameter { name: "series"; type: "QAbstractSeries"; isPointer: true } + } + Method { + name: "mapToValue" + revision: 5 + type: "QPointF" + Parameter { name: "position"; type: "QPointF" } + } + Method { + name: "mapToPosition" + revision: 5 + type: "QPointF" + Parameter { name: "value"; type: "QPointF" } + Parameter { name: "series"; type: "QAbstractSeries"; isPointer: true } + } + Method { + name: "mapToPosition" + revision: 5 + type: "QPointF" + Parameter { name: "value"; type: "QPointF" } + } } Component { name: "QtCharts::DeclarativeHorizontalBarSeries" diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml index e15b137..d813e1c 100644 --- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -111,4 +111,22 @@ ChartView { NumberAnimation { duration: 800 } } } + + MouseArea { + id: zoomArea + anchors.fill: parent + acceptedButtons: Qt.LeftButton + property point mousePoint; + property point valuePoint; + + onPressed: { + mousePoint.x = mouse.x + mousePoint.y = mouse.y + valuePoint = chart.mapToValue(mousePoint, series("line")); + // Mouse point and position should be the same! + console.log("mouse point: " + mouse.x + ", " + mouse.y); + console.log("value point: " + valuePoint); + console.log("position: " + chart.mapToPosition(valuePoint, series("line"))); + } + } }