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