@@ -1,91 +1,91 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "polardomain_p.h" |
|
22 | 22 | #include "qabstractaxis_p.h" |
|
23 | 23 | #include <qmath.h> |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | PolarDomain::PolarDomain(QObject *parent) |
|
28 | 28 | : AbstractDomain(parent) |
|
29 | 29 | { |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | PolarDomain::~PolarDomain() |
|
33 | 33 | { |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void PolarDomain::setSize(const QSizeF &size) |
|
37 | 37 | { |
|
38 | 38 | Q_ASSERT(size.width() == size.height()); |
|
39 | m_radius = size.height() / 2; | |
|
39 | m_radius = size.height() / 2.0; | |
|
40 | 40 | m_center = QPointF(m_radius, m_radius); |
|
41 | 41 | AbstractDomain::setSize(size); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | QPointF PolarDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
|
45 | 45 | { |
|
46 | qreal r; | |
|
46 | qreal r = 0.0; | |
|
47 | 47 | qreal a = toAngularCoordinate(point.x(), ok); |
|
48 | 48 | if (ok) |
|
49 | 49 | r = toRadialCoordinate(point.y(), ok); |
|
50 | 50 | if (ok) { |
|
51 | 51 | return m_center + polarCoordinateToPoint(a, r); |
|
52 | 52 | } else { |
|
53 | 53 | qWarning() << "Logarithm of negative value is undefined. Empty layout returned."; |
|
54 | 54 | return QPointF(); |
|
55 | 55 | } |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | QVector<QPointF> PolarDomain::calculateGeometryPoints(const QList<QPointF> &vector) const |
|
59 | 59 | { |
|
60 | 60 | QVector<QPointF> result; |
|
61 | 61 | result.resize(vector.count()); |
|
62 | 62 | bool ok; |
|
63 | qreal r; | |
|
64 | qreal a; | |
|
63 | qreal r = 0.0; | |
|
64 | qreal a = 0.0; | |
|
65 | 65 | |
|
66 | 66 | for (int i = 0; i < vector.count(); ++i) { |
|
67 | 67 | a = toAngularCoordinate(vector[i].x(), ok); |
|
68 | 68 | if (ok) |
|
69 | 69 | r = toRadialCoordinate(vector[i].y(), ok); |
|
70 | 70 | if (ok) { |
|
71 | 71 | result[i] = m_center + polarCoordinateToPoint(a, r); |
|
72 | 72 | } else { |
|
73 | 73 | qWarning() << "Logarithm of negative value is undefined. Empty layout returned."; |
|
74 | 74 | return QVector<QPointF>(); |
|
75 | 75 | } |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | return result; |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | QPointF PolarDomain::polarCoordinateToPoint(qreal angularCoordinate, qreal radialCoordinate) const |
|
82 | 82 | { |
|
83 | 83 | qreal dx = qSin(angularCoordinate * (M_PI / 180)) * radialCoordinate; |
|
84 | 84 | qreal dy = qCos(angularCoordinate * (M_PI / 180)) * radialCoordinate; |
|
85 | 85 | |
|
86 | 86 | return QPointF(dx, -dy); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | #include "moc_polardomain_p.cpp" |
|
90 | 90 | |
|
91 | 91 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now