@@ -1,186 +1,204 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <private/xydomain_p.h> |
|
21 | #include <private/xydomain_p.h> | |
22 | #include <private/qabstractaxis_p.h> |
|
22 | #include <private/qabstractaxis_p.h> | |
23 | #include <QtCore/QtMath> |
|
23 | #include <QtCore/QtMath> | |
24 |
|
24 | |||
25 | QT_CHARTS_BEGIN_NAMESPACE |
|
25 | QT_CHARTS_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | XYDomain::XYDomain(QObject *parent) |
|
27 | XYDomain::XYDomain(QObject *parent) | |
28 | : AbstractDomain(parent) |
|
28 | : AbstractDomain(parent) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | XYDomain::~XYDomain() |
|
32 | XYDomain::~XYDomain() | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void XYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
36 | void XYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
37 | { |
|
37 | { | |
38 | bool axisXChanged = false; |
|
38 | bool axisXChanged = false; | |
39 | bool axisYChanged = false; |
|
39 | bool axisYChanged = false; | |
40 |
|
40 | |||
41 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
41 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { | |
42 | m_minX = minX; |
|
42 | m_minX = minX; | |
43 | m_maxX = maxX; |
|
43 | m_maxX = maxX; | |
44 | axisXChanged = true; |
|
44 | axisXChanged = true; | |
45 | if(!m_signalsBlocked) |
|
45 | if(!m_signalsBlocked) | |
46 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
46 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) { |
|
49 | if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) { | |
50 | m_minY = minY; |
|
50 | m_minY = minY; | |
51 | m_maxY = maxY; |
|
51 | m_maxY = maxY; | |
52 | axisYChanged = true; |
|
52 | axisYChanged = true; | |
53 | if(!m_signalsBlocked) |
|
53 | if(!m_signalsBlocked) | |
54 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
54 | emit rangeVerticalChanged(m_minY, m_maxY); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | if (axisXChanged || axisYChanged) |
|
57 | if (axisXChanged || axisYChanged) | |
58 | emit updated(); |
|
58 | emit updated(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | void XYDomain::zoomIn(const QRectF &rect) |
|
62 | void XYDomain::zoomIn(const QRectF &rect) | |
63 | { |
|
63 | { | |
64 | storeZoomReset(); |
|
64 | storeZoomReset(); | |
65 | qreal dx = spanX() / m_size.width(); |
|
65 | qreal dx = spanX() / m_size.width(); | |
66 | qreal dy = spanY() / m_size.height(); |
|
66 | qreal dy = spanY() / m_size.height(); | |
67 |
|
67 | |||
68 | qreal maxX = m_maxX; |
|
68 | qreal maxX = m_maxX; | |
69 | qreal minX = m_minX; |
|
69 | qreal minX = m_minX; | |
70 | qreal minY = m_minY; |
|
70 | qreal minY = m_minY; | |
71 | qreal maxY = m_maxY; |
|
71 | qreal maxY = m_maxY; | |
72 |
|
72 | |||
73 | maxX = minX + dx * rect.right(); |
|
73 | maxX = minX + dx * rect.right(); | |
74 | minX = minX + dx * rect.left(); |
|
74 | minX = minX + dx * rect.left(); | |
75 | minY = maxY - dy * rect.bottom(); |
|
75 | minY = maxY - dy * rect.bottom(); | |
76 | maxY = maxY - dy * rect.top(); |
|
76 | maxY = maxY - dy * rect.top(); | |
77 |
|
77 | |||
|
78 | if ((maxX - minX) == spanX()) { | |||
|
79 | minX = m_minX; | |||
|
80 | maxX = m_maxX; | |||
|
81 | } | |||
|
82 | if ((maxY - minY) == spanY()) { | |||
|
83 | minY = m_minY; | |||
|
84 | maxY = m_maxY; | |||
|
85 | } | |||
|
86 | ||||
78 | setRange(minX, maxX, minY, maxY); |
|
87 | setRange(minX, maxX, minY, maxY); | |
79 | } |
|
88 | } | |
80 |
|
89 | |||
81 | void XYDomain::zoomOut(const QRectF &rect) |
|
90 | void XYDomain::zoomOut(const QRectF &rect) | |
82 | { |
|
91 | { | |
83 | storeZoomReset(); |
|
92 | storeZoomReset(); | |
84 | qreal dx = spanX() / rect.width(); |
|
93 | qreal dx = spanX() / rect.width(); | |
85 | qreal dy = spanY() / rect.height(); |
|
94 | qreal dy = spanY() / rect.height(); | |
86 |
|
95 | |||
87 | qreal maxX = m_maxX; |
|
96 | qreal maxX = m_maxX; | |
88 | qreal minX = m_minX; |
|
97 | qreal minX = m_minX; | |
89 | qreal minY = m_minY; |
|
98 | qreal minY = m_minY; | |
90 | qreal maxY = m_maxY; |
|
99 | qreal maxY = m_maxY; | |
91 |
|
100 | |||
92 | minX = maxX - dx * rect.right(); |
|
101 | minX = maxX - dx * rect.right(); | |
93 | maxX = minX + dx * m_size.width(); |
|
102 | maxX = minX + dx * m_size.width(); | |
94 | maxY = minY + dy * rect.bottom(); |
|
103 | maxY = minY + dy * rect.bottom(); | |
95 | minY = maxY - dy * m_size.height(); |
|
104 | minY = maxY - dy * m_size.height(); | |
96 |
|
105 | |||
|
106 | if ((maxX - minX) == spanX()) { | |||
|
107 | minX = m_minX; | |||
|
108 | maxX = m_maxX; | |||
|
109 | } | |||
|
110 | if ((maxY - minY) == spanY()) { | |||
|
111 | minY = m_minY; | |||
|
112 | maxY = m_maxY; | |||
|
113 | } | |||
|
114 | ||||
97 | setRange(minX, maxX, minY, maxY); |
|
115 | setRange(minX, maxX, minY, maxY); | |
98 | } |
|
116 | } | |
99 |
|
117 | |||
100 | void XYDomain::move(qreal dx, qreal dy) |
|
118 | void XYDomain::move(qreal dx, qreal dy) | |
101 | { |
|
119 | { | |
102 | qreal x = spanX() / m_size.width(); |
|
120 | qreal x = spanX() / m_size.width(); | |
103 | qreal y = spanY() / m_size.height(); |
|
121 | qreal y = spanY() / m_size.height(); | |
104 |
|
122 | |||
105 | qreal maxX = m_maxX; |
|
123 | qreal maxX = m_maxX; | |
106 | qreal minX = m_minX; |
|
124 | qreal minX = m_minX; | |
107 | qreal minY = m_minY; |
|
125 | qreal minY = m_minY; | |
108 | qreal maxY = m_maxY; |
|
126 | qreal maxY = m_maxY; | |
109 |
|
127 | |||
110 | if (dx != 0) { |
|
128 | if (dx != 0) { | |
111 | minX = minX + x * dx; |
|
129 | minX = minX + x * dx; | |
112 | maxX = maxX + x * dx; |
|
130 | maxX = maxX + x * dx; | |
113 | } |
|
131 | } | |
114 | if (dy != 0) { |
|
132 | if (dy != 0) { | |
115 | minY = minY + y * dy; |
|
133 | minY = minY + y * dy; | |
116 | maxY = maxY + y * dy; |
|
134 | maxY = maxY + y * dy; | |
117 | } |
|
135 | } | |
118 | setRange(minX, maxX, minY, maxY); |
|
136 | setRange(minX, maxX, minY, maxY); | |
119 | } |
|
137 | } | |
120 |
|
138 | |||
121 | QPointF XYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
|
139 | QPointF XYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const | |
122 | { |
|
140 | { | |
123 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
141 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
124 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
142 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
125 | qreal x = (point.x() - m_minX) * deltaX; |
|
143 | qreal x = (point.x() - m_minX) * deltaX; | |
126 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); |
|
144 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); | |
127 | ok = true; |
|
145 | ok = true; | |
128 | return QPointF(x, y); |
|
146 | return QPointF(x, y); | |
129 | } |
|
147 | } | |
130 |
|
148 | |||
131 | QVector<QPointF> XYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const |
|
149 | QVector<QPointF> XYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const | |
132 | { |
|
150 | { | |
133 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
151 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
134 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
152 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
135 |
|
153 | |||
136 | QVector<QPointF> result; |
|
154 | QVector<QPointF> result; | |
137 | result.resize(vector.count()); |
|
155 | result.resize(vector.count()); | |
138 |
|
156 | |||
139 | for (int i = 0; i < vector.count(); ++i) { |
|
157 | for (int i = 0; i < vector.count(); ++i) { | |
140 | qreal x = (vector[i].x() - m_minX) * deltaX; |
|
158 | qreal x = (vector[i].x() - m_minX) * deltaX; | |
141 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); |
|
159 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); | |
142 | result[i].setX(x); |
|
160 | result[i].setX(x); | |
143 | result[i].setY(y); |
|
161 | result[i].setY(y); | |
144 | } |
|
162 | } | |
145 | return result; |
|
163 | return result; | |
146 | } |
|
164 | } | |
147 |
|
165 | |||
148 | QPointF XYDomain::calculateDomainPoint(const QPointF &point) const |
|
166 | QPointF XYDomain::calculateDomainPoint(const QPointF &point) const | |
149 | { |
|
167 | { | |
150 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
168 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
151 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
169 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
152 | qreal x = point.x() / deltaX + m_minX; |
|
170 | qreal x = point.x() / deltaX + m_minX; | |
153 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
171 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; | |
154 | return QPointF(x, y); |
|
172 | return QPointF(x, y); | |
155 | } |
|
173 | } | |
156 |
|
174 | |||
157 | // operators |
|
175 | // operators | |
158 |
|
176 | |||
159 | bool QT_CHARTS_AUTOTEST_EXPORT operator== (const XYDomain &domain1, const XYDomain &domain2) |
|
177 | bool QT_CHARTS_AUTOTEST_EXPORT operator== (const XYDomain &domain1, const XYDomain &domain2) | |
160 | { |
|
178 | { | |
161 | return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) |
|
179 | return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) | |
162 | && qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) |
|
180 | && qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) | |
163 | && qFuzzyCompare(domain1.m_minX, domain2.m_minX) |
|
181 | && qFuzzyCompare(domain1.m_minX, domain2.m_minX) | |
164 | && qFuzzyCompare(domain1.m_minY, domain2.m_minY)); |
|
182 | && qFuzzyCompare(domain1.m_minY, domain2.m_minY)); | |
165 | } |
|
183 | } | |
166 |
|
184 | |||
167 |
|
185 | |||
168 | bool QT_CHARTS_AUTOTEST_EXPORT operator!= (const XYDomain &domain1, const XYDomain &domain2) |
|
186 | bool QT_CHARTS_AUTOTEST_EXPORT operator!= (const XYDomain &domain1, const XYDomain &domain2) | |
169 | { |
|
187 | { | |
170 | return !(domain1 == domain2); |
|
188 | return !(domain1 == domain2); | |
171 | } |
|
189 | } | |
172 |
|
190 | |||
173 |
|
191 | |||
174 | QDebug QT_CHARTS_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &domain) |
|
192 | QDebug QT_CHARTS_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &domain) | |
175 | { |
|
193 | { | |
176 | #ifdef QT_NO_TEXTSTREAM |
|
194 | #ifdef QT_NO_TEXTSTREAM | |
177 | Q_UNUSED(domain) |
|
195 | Q_UNUSED(domain) | |
178 | #else |
|
196 | #else | |
179 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
197 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; | |
180 | #endif |
|
198 | #endif | |
181 | return dbg.maybeSpace(); |
|
199 | return dbg.maybeSpace(); | |
182 | } |
|
200 | } | |
183 |
|
201 | |||
184 | #include "moc_xydomain_p.cpp" |
|
202 | #include "moc_xydomain_p.cpp" | |
185 |
|
203 | |||
186 | QT_CHARTS_END_NAMESPACE |
|
204 | QT_CHARTS_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now