@@ -21,7 +21,7 | |||||
21 | #include "chart.h" |
|
21 | #include "chart.h" | |
22 | #include <QValueAxis> |
|
22 | #include <QValueAxis> | |
23 | #include <QAbstractAxis> |
|
23 | #include <QAbstractAxis> | |
24 |
#include < |
|
24 | #include <qmath.h> | |
25 |
|
25 | |||
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) |
|
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) | |
27 | : QChart(QChart::ChartTypeCartesian, parent, wFlags), m_series(series) |
|
27 | : QChart(QChart::ChartTypeCartesian, parent, wFlags), m_series(series) | |
@@ -48,7 +48,7 void Chart::clickPoint(const QPointF &point) | |||||
48 |
|
48 | |||
49 | qreal Chart::distance(const QPointF &p1, const QPointF &p2) |
|
49 | qreal Chart::distance(const QPointF &p1, const QPointF &p2) | |
50 | { |
|
50 | { | |
51 |
return |
|
51 | return qSqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) | |
52 | + (p1.y() - p2.y()) * (p1.y() - p2.y())); |
|
52 | + (p1.y() - p2.y()) * (p1.y() - p2.y())); | |
53 | } |
|
53 | } | |
54 |
|
54 |
@@ -23,7 +23,7 | |||||
23 | #include <QAreaSeries> |
|
23 | #include <QAreaSeries> | |
24 | #include <QDeclarativeView> |
|
24 | #include <QDeclarativeView> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
#include < |
|
26 | #include <qmath.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
@@ -69,7 +69,7 void DataSource::generateData(int type, int rowCount, int colCount) | |||||
69 | switch (type) { |
|
69 | switch (type) { | |
70 | case 0: |
|
70 | case 0: | |
71 | // data with sin + random component |
|
71 | // data with sin + random component | |
72 |
y = |
|
72 | y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; | |
73 | x = j; |
|
73 | x = j; | |
74 | break; |
|
74 | break; | |
75 | case 1: |
|
75 | case 1: |
@@ -24,7 +24,7 | |||||
24 | #include <QtQuick/QQuickView> |
|
24 | #include <QtQuick/QQuickView> | |
25 | #include <QtQuick/QQuickItem> |
|
25 | #include <QtQuick/QQuickItem> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
#include < |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
@@ -70,7 +70,7 void DataSource::generateData(int type, int rowCount, int colCount) | |||||
70 | switch (type) { |
|
70 | switch (type) { | |
71 | case 0: |
|
71 | case 0: | |
72 | // data with sin + random component |
|
72 | // data with sin + random component | |
73 |
y = |
|
73 | y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; | |
74 | x = j; |
|
74 | x = j; | |
75 | break; |
|
75 | break; | |
76 | case 1: |
|
76 | case 1: |
@@ -19,7 +19,7 | |||||
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartview.h" |
|
21 | #include "chartview.h" | |
22 | #include <math.h> |
|
22 | #include <qmath.h> | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
@@ -63,8 +63,10 void ChartView::handleClickedPoint(const QPointF &point) | |||||
63 | QPointF closest(INT_MAX, INT_MAX); |
|
63 | QPointF closest(INT_MAX, INT_MAX); | |
64 | qreal distance(INT_MAX); |
|
64 | qreal distance(INT_MAX); | |
65 | foreach (QPointF currentPoint, m_scatter->points()) { |
|
65 | foreach (QPointF currentPoint, m_scatter->points()) { | |
66 |
qreal currentDistance = |
|
66 | qreal currentDistance = qSqrt((currentPoint.x() - clickedPoint.x()) | |
67 |
|
|
67 | * (currentPoint.x() - clickedPoint.x()) | |
|
68 | + (currentPoint.y() - clickedPoint.y()) | |||
|
69 | * (currentPoint.y() - clickedPoint.y())); | |||
68 | if (currentDistance < distance) { |
|
70 | if (currentDistance < distance) { | |
69 | distance = currentDistance; |
|
71 | distance = currentDistance; | |
70 | closest = currentPoint; |
|
72 | closest = currentPoint; |
General Comments 0
You need to be logged in to leave comments.
Login now