@@ -19,6 +19,8 | |||||
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartview.h" |
|
21 | #include "chartview.h" | |
|
22 | #include <math.h> | |||
|
23 | #include <QDebug> | |||
22 |
|
24 | |||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
26 | |||
@@ -55,6 +57,20 ChartView::~ChartView() | |||||
55 |
|
57 | |||
56 | void ChartView::handleClickedPoint(const QPointF& point) |
|
58 | void ChartView::handleClickedPoint(const QPointF& point) | |
57 | { |
|
59 | { | |
58 | m_scatter->remove(point); |
|
60 | QPointF clickedPoint = point; | |
59 | m_scatter2->append(point); |
|
61 | // Find the closest point from series 1 | |
|
62 | QPointF closest(INT64_MAX, INT64_MAX); | |||
|
63 | qreal distance(INT64_MAX); | |||
|
64 | foreach(QPointF currentPoint, m_scatter->points()) { | |||
|
65 | qreal currentDistance = sqrt((currentPoint.x() - clickedPoint.x()) * (currentPoint.x() - clickedPoint.x()) | |||
|
66 | + (currentPoint.y() - clickedPoint.y()) * (currentPoint.y() - clickedPoint.y())); | |||
|
67 | if (currentDistance < distance) { | |||
|
68 | distance = currentDistance; | |||
|
69 | closest = currentPoint; | |||
|
70 | } | |||
|
71 | } | |||
|
72 | ||||
|
73 | // Remove the closes point from series 1 and append it to series 2 | |||
|
74 | m_scatter->remove(closest); | |||
|
75 | m_scatter2->append(closest); | |||
60 | } |
|
76 | } |
@@ -102,7 +102,7 void ScatterChartItem::deletePoints(int count) | |||||
102 |
|
102 | |||
103 | void ScatterChartItem::markerSelected(Marker *marker) |
|
103 | void ScatterChartItem::markerSelected(Marker *marker) | |
104 | { |
|
104 | { | |
105 | emit XYChart::clicked(marker->point()); |
|
105 | emit XYChart::clicked(calculateDomainPoint(marker->point())); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void ScatterChartItem::updateGeometry() |
|
108 | void ScatterChartItem::updateGeometry() |
General Comments 0
You need to be logged in to leave comments.
Login now