##// END OF EJS Templates
Added attach/dettach axis domain implementations
Marek Rosa -
r2290:f089818f996f
parent child
Show More
@@ -1,318 +1,318
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 "qlogvalueaxis.h"
22 22 #include "qlogvalueaxis_p.h"
23 23 #include "chartlogvalueaxisx_p.h"
24 24 #include "chartlogvalueaxisy_p.h"
25 25 #include "abstractdomain_p.h"
26 26 #include <float.h>
27 27 #include <cmath>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 /*!
31 31 \class QLogValueAxis
32 32 \brief The QLogValueAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34 */
35 35
36 36 /*!
37 37 \qmlclass DateTimeAxis QLogValueAxis
38 38 \brief The DateTimeAxis element is used for manipulating chart's axes
39 39 \inherits AbstractAxis
40 40 */
41 41
42 42 /*!
43 43 \property QLogValueAxis::min
44 44 Defines the minimum value on the axis.
45 45 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
46 46 */
47 47 /*!
48 48 \qmlproperty real ValuesAxis::min
49 49 Defines the minimum value on the axis.
50 50 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
51 51 */
52 52
53 53 /*!
54 54 \property QLogValueAxis::max
55 55 Defines the maximum value on the axis.
56 56 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
57 57 */
58 58 /*!
59 59 \qmlproperty real ValuesAxis::max
60 60 Defines the maximum value on the axis.
61 61 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
62 62 */
63 63
64 64 /*!
65 65 \fn void QLogValueAxis::minChanged(qreal min)
66 66 Axis emits signal when \a min of axis has changed.
67 67 */
68 68 /*!
69 69 \qmlsignal ValuesAxis::onMinChanged(qreal min)
70 70 Axis emits signal when \a min of axis has changed.
71 71 */
72 72
73 73 /*!
74 74 \fn void QLogValueAxis::maxChanged(qreal max)
75 75 Axis emits signal when \a max of axis has changed.
76 76 */
77 77 /*!
78 78 \qmlsignal ValuesAxis::onMaxChanged(qreal max)
79 79 Axis emits signal when \a max of axis has changed.
80 80 */
81 81
82 82 /*!
83 83 \fn void QLogValueAxis::rangeChanged(qreal min, qreal max)
84 84 Axis emits signal when \a min or \a max of axis has changed.
85 85 */
86 86
87 87 /*!
88 88 Constructs an axis object which is a child of \a parent.
89 89 */
90 90 QLogValueAxis::QLogValueAxis(QObject *parent) :
91 91 QAbstractAxis(*new QLogValueAxisPrivate(this), parent)
92 92 {
93 93
94 94 }
95 95
96 96 /*!
97 97 \internal
98 98 */
99 99 QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
100 100 {
101 101
102 102 }
103 103
104 104 /*!
105 105 Destroys the object
106 106 */
107 107 QLogValueAxis::~QLogValueAxis()
108 108 {
109 109
110 110 }
111 111
112 112 void QLogValueAxis::setMin(qreal min)
113 113 {
114 114 Q_D(QLogValueAxis);
115 115 setRange(min, qMax(d->m_max, min));
116 116 }
117 117
118 118 qreal QLogValueAxis::min() const
119 119 {
120 120 Q_D(const QLogValueAxis);
121 121 return d->m_min;
122 122 }
123 123
124 124 void QLogValueAxis::setMax(qreal max)
125 125 {
126 126 Q_D(QLogValueAxis);
127 127 setRange(qMin(d->m_min, max), max);
128 128 }
129 129
130 130 qreal QLogValueAxis::max() const
131 131 {
132 132 Q_D(const QLogValueAxis);
133 133 return d->m_max;
134 134 }
135 135
136 136 /*!
137 137 Sets range from \a min to \a max on the axis.
138 138 If min is greater than max then this function returns without making any changes.
139 139 */
140 140 void QLogValueAxis::setRange(qreal min, qreal max)
141 141 {
142 142 Q_D(QLogValueAxis);
143 143 bool changed = false;
144 144
145 145 if (min > max)
146 146 return;
147 147
148 148 if (min > 0) {
149 149 if (!qFuzzyCompare(d->m_min, min)) {
150 150 d->m_min = min;
151 151 changed = true;
152 152 emit minChanged(min);
153 153 }
154 154
155 155 if (!qFuzzyCompare(d->m_max, max)) {
156 156 d->m_max = max;
157 157 changed = true;
158 158 emit maxChanged(max);
159 159 }
160 160
161 161 if (changed) {
162 162 emit rangeChanged(min, max);
163 163 emit d->rangeChanged(min,max);
164 164 }
165 165 }
166 166 }
167 167
168 168 void QLogValueAxis::setLabelFormat(const QString &format)
169 169 {
170 170 Q_D(QLogValueAxis);
171 171 d->m_format = format;
172 172 }
173 173
174 174 QString QLogValueAxis::labelFormat() const
175 175 {
176 176 Q_D(const QLogValueAxis);
177 177 return d->m_format;
178 178 }
179 179
180 180 void QLogValueAxis::setBase(qreal base)
181 181 {
182 182 // check if base is correct
183 183 if (qFuzzyCompare(base, 1))
184 184 return;
185 185
186 186 if (base > 0) {
187 187 Q_D(QLogValueAxis);
188 188 d->m_base = base;
189 emit d->baseChanged(base);
189 emit baseChanged(base);
190 190 }
191 191 }
192 192
193 193 qreal QLogValueAxis::base() const
194 194 {
195 195 Q_D(const QLogValueAxis);
196 196 return d->m_base;
197 197 }
198 198
199 199 /*!
200 200 Returns the type of the axis
201 201 */
202 202 QAbstractAxis::AxisType QLogValueAxis::type() const
203 203 {
204 204 return AxisTypeLogValue;
205 205 }
206 206
207 207 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
208 208
209 209 QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q)
210 210 : QAbstractAxisPrivate(q),
211 211 m_min(1),
212 212 m_max(10),
213 213 m_base(10),
214 214 m_format(QString::null)
215 215 {
216 216 }
217 217
218 218 QLogValueAxisPrivate::~QLogValueAxisPrivate()
219 219 {
220 220
221 221 }
222 222
223 223 void QLogValueAxisPrivate::setMin(const QVariant &min)
224 224 {
225 225 Q_Q(QLogValueAxis);
226 226 bool ok;
227 227 qreal value = min.toReal(&ok);
228 228 if (ok)
229 229 q->setMin(value);
230 230 }
231 231
232 232 void QLogValueAxisPrivate::setMax(const QVariant &max)
233 233 {
234 234
235 235 Q_Q(QLogValueAxis);
236 236 bool ok;
237 237 qreal value = max.toReal(&ok);
238 238 if (ok)
239 239 q->setMax(value);
240 240 }
241 241
242 242 void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
243 243 {
244 244 Q_Q(QLogValueAxis);
245 245 bool ok1;
246 246 bool ok2;
247 247 qreal value1 = min.toReal(&ok1);
248 248 qreal value2 = max.toReal(&ok2);
249 249 if (ok1 && ok2)
250 250 q->setRange(value1, value2);
251 251 }
252 252
253 253 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
254 254 {
255 255 Q_Q(QLogValueAxis);
256 256 bool changed = false;
257 257
258 258 if (min > max)
259 259 return;
260 260
261 261 if (min > 0) {
262 262 if (!qFuzzyCompare(m_min, min)) {
263 263 m_min = min;
264 264 changed = true;
265 265 emit q->minChanged(min);
266 266 }
267 267
268 268 if (!qFuzzyCompare(m_max, max)) {
269 269 m_max = max;
270 270 changed = true;
271 271 emit q->maxChanged(max);
272 272 }
273 273
274 274 if (changed) {
275 275 emit q->rangeChanged(min, max);
276 276 emit rangeChanged(min,max);
277 277 }
278 278 }
279 279 }
280 280
281 281 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
282 282 {
283 283 Q_Q(QLogValueAxis);
284 284 ChartAxis* axis(0);
285 285 if (orientation() == Qt::Vertical)
286 286 axis = new ChartLogValueAxisY(q,parent);
287 287 if (orientation() == Qt::Horizontal)
288 288 axis = new ChartLogValueAxisX(q,parent);
289 289
290 290 m_item.reset(axis);
291 291 QAbstractAxisPrivate::initializeGraphics(parent);
292 292 }
293 293
294 294
295 295 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
296 296 {
297 297 if (orientation() == Qt::Vertical) {
298 298 if(!qFuzzyCompare(m_max, m_min)) {
299 299 domain->setRangeY(m_min, m_max);
300 300 }
301 301 else {
302 302 setRange(domain->minY() + 1, domain->maxY());
303 303 }
304 304 }
305 305 if (orientation() == Qt::Horizontal) {
306 306 if(!qFuzzyCompare(m_max, m_min)) {
307 307 domain->setRangeX(m_min, m_max);
308 308 }
309 309 else {
310 310 setRange(domain->minX() + 1, domain->maxX());
311 311 }
312 312 }
313 313 }
314 314
315 315 #include "moc_qlogvalueaxis.cpp"
316 316 #include "moc_qlogvalueaxis_p.cpp"
317 317
318 318 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,75
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 #ifndef QLOGVALUEAXIS_H
22 22 #define QLOGVALUEAXIS_H
23 23
24 24 #include "qabstractaxis.h"
25 25
26 26 class QDateTime;
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QLogValueAxisPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QLogValueAxis : public QAbstractAxis
33 33 {
34 34 Q_OBJECT
35 35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37 37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat)
38 38
39 39 public:
40 40 explicit QLogValueAxis(QObject *parent = 0);
41 41 ~QLogValueAxis();
42 42
43 43 protected:
44 44 QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = 0);
45 45
46 46 public:
47 47 AxisType type() const;
48 48
49 49 //range handling
50 50 void setMin(qreal min);
51 51 qreal min() const;
52 52 void setMax(qreal max);
53 53 qreal max() const;
54 54 void setRange(qreal min, qreal max);
55 55
56 56 void setLabelFormat(const QString &format);
57 57 QString labelFormat() const;
58 58
59 59 void setBase(qreal base);
60 60 qreal base() const;
61 61
62 62 Q_SIGNALS:
63 63 void minChanged(qreal min);
64 64 void maxChanged(qreal max);
65 65 void rangeChanged(qreal min, qreal max);
66 void baseChanged(qreal base);
66 67
67 68 private:
68 69 Q_DECLARE_PRIVATE(QLogValueAxis)
69 70 Q_DISABLE_COPY(QLogValueAxis)
70 71 };
71 72
72 73 QTCOMMERCIALCHART_END_NAMESPACE
73 74
74 75 #endif // QLOGVALUEAXIS_H
@@ -1,72 +1,69
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QLOGVALUEAXIS_P_H
31 31 #define QLOGVALUEAXIS_P_H
32 32
33 33 #include "qlogvalueaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QLogValueAxisPrivate : public QAbstractAxisPrivate
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 QLogValueAxisPrivate(QLogValueAxis *q);
43 43 ~QLogValueAxisPrivate();
44 44
45 45 public:
46 46 void initializeGraphics(QGraphicsItem* parent);
47 47 void initializeDomain(AbstractDomain *domain);
48 48
49 49 qreal min() { return m_min; }
50 50 qreal max() { return m_max; }
51 51 void setRange(qreal min,qreal max);
52 52
53 53 protected:
54 54 void setMin(const QVariant &min);
55 55 void setMax(const QVariant &max);
56 56 void setRange(const QVariant &min, const QVariant &max);
57 57 int tickCount() const;
58 58
59 Q_SIGNALS:
60 void baseChanged(qreal base);
61
62 59 protected:
63 60 qreal m_min;
64 61 qreal m_max;
65 62 qreal m_base;
66 63 QString m_format;
67 64 Q_DECLARE_PUBLIC(QLogValueAxis)
68 65 };
69 66
70 67 QTCOMMERCIALCHART_END_NAMESPACE
71 68
72 69 #endif // QLOGVALUEAXIS_P_H
@@ -1,182 +1,221
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 "logxlogydomain_p.h"
22 22 #include "qabstractaxis_p.h"
23 #include "qlogvalueaxis.h"
23 24 #include <qmath.h>
24 25
25 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 27
27 28 LogXLogYDomain::LogXLogYDomain(QObject *parent)
28 29 : AbstractDomain(parent),
29 30 m_logMinX(0),
30 31 m_logMaxX(1),
31 32 m_logBaseX(10),
32 33 m_logMinY(0),
33 34 m_logMaxY(1),
34 35 m_logBaseY(10)
35 36 {
36 37 }
37 38
38 39 LogXLogYDomain::~LogXLogYDomain()
39 40 {
40 41 }
41 42
42 43 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
43 44 {
44 45 bool axisXChanged = false;
45 46 bool axisYChanged = false;
46 47
47 48 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
48 49 m_minX = minX;
49 50 m_maxX = maxX;
50 51 axisXChanged = true;
51 52 m_logMinX = log10(m_minX) / log10(m_logBaseX);
52 53 m_logMaxX = log10(m_maxX) / log10(m_logBaseX);
53 54 if(!m_signalsBlocked)
54 55 emit rangeHorizontalChanged(m_minX, m_maxX);
55 56 }
56 57
57 58 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
58 59 m_minY = minY;
59 60 m_maxY = maxY;
60 61 axisYChanged = true;
61 62 m_logMinY = log10(m_minY) / log10(m_logBaseY);
62 63 m_logMaxY = log10(m_maxY) / log10(m_logBaseY);
63 64 if(!m_signalsBlocked)
64 65 emit rangeVerticalChanged(m_minY, m_maxY);
65 66 }
66 67
67 68 if (axisXChanged || axisYChanged)
68 69 emit updated();
69 70 }
70 71
71 72 void LogXLogYDomain::zoomIn(const QRectF &rect)
72 73 {
73 74 qreal newLogMinX = rect.left() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX;
74 75 qreal newLogMaxX = rect.right() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX;
75 76 qreal minX = qPow(m_logBaseX, newLogMinX);
76 77 qreal maxX = qPow(m_logBaseX, newLogMaxX);
77 78
78 79 qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height();
79 80 qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height();
80 81 qreal minY = qPow(m_logBaseY, newLogMinY);
81 82 qreal maxY = qPow(m_logBaseY, newLogMaxY);
82 83
83 84 setRange(minX, maxX, minY, maxY);
84 85 }
85 86
86 87 void LogXLogYDomain::zoomOut(const QRectF &rect)
87 88 {
88 89 qreal ratioX = m_size.width()/rect.width();
89 90 qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX;
90 91 qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX;
91 92 qreal minX = qPow(m_logBaseX, newLogMinX);
92 93 qreal maxX = qPow(m_logBaseX, newLogMaxX);
93 94
94 95 qreal ratioY = m_size.height()/rect.height();
95 96 qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY;
96 97 qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY;
97 98 qreal minY = qPow(m_logBaseY, newLogMinY);
98 99 qreal maxY = qPow(m_logBaseY, newLogMaxY);
99 100
100 101 setRange(minX, maxX, minY, maxY);
101 102 }
102 103
103 104 void LogXLogYDomain::move(qreal dx, qreal dy)
104 105 {
105 106 qreal stepX = dx * qAbs(m_logMaxX - m_logMinX) / m_size.width();
106 107 qreal minX = qPow(m_logBaseX, m_logMinX + stepX);
107 108 qreal maxX = qPow(m_logBaseX, m_logMaxX + stepX);
108 109
109 110 qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height();
110 111 qreal minY = qPow(m_logBaseY, m_logMinY + stepY);
111 112 qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY);
112 113
113 114 setRange(minX, maxX, minY, maxY);
114 115 }
115 116
116 117 QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point) const
117 118 {
118 119 const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX;
119 120 const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
120 121 const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX);
121 122 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
122 123 qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX;
123 124 qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height();
124 125 return QPointF(x, y);
125 126 }
126 127
127 128 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
128 129 {
129 130 const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX;
130 131 const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
131 132 const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX);
132 133 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
133 134
134 135 QVector<QPointF> result;
135 136 result.resize(vector.count());
136 137
137 138 for (int i = 0; i < vector.count(); ++i) {
138 139 qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX;
139 140 qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height();
140 141 result[i].setX(x);
141 142 result[i].setY(y);
142 143 }
143 144 return result;
144 145 }
145 146
146 147 QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const
147 148 {
148 149 const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX;
149 150 const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
150 151 const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX);
151 152 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
152 153 qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX);
153 154 qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY);
154 155 return QPointF(x, y);
155 156 }
156 157
158 bool LogXLogYDomain::attachAxis(QAbstractAxis* axis)
159 {
160 AbstractDomain::attachAxis(axis);
161 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
162
163 if(logAxis && logAxis->orientation()==Qt::Vertical)
164 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
165
166 if(logAxis && logAxis->orientation()==Qt::Horizontal)
167 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
168
169 return true;
170 }
171
172 bool LogXLogYDomain::detachAxis(QAbstractAxis* axis)
173 {
174 AbstractDomain::detachAxis(axis);
175 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
176
177 if(logAxis && logAxis->orientation()==Qt::Vertical)
178 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
179
180 if(logAxis && logAxis->orientation()==Qt::Horizontal)
181 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
182
183 return true;
184 }
185
186 void LogXLogYDomain::handleVerticalAxisBaseChanged(qreal baseY)
187 {
188 m_logBaseY = baseY;
189 }
190
191 void LogXLogYDomain::handleHorizontalAxisBaseChanged(qreal baseX)
192 {
193 m_logBaseX = baseX;
194 }
195
157 196 // operators
158 197
159 198 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2)
160 199 {
161 200 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
162 201 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
163 202 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
164 203 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
165 204 }
166 205
167 206
168 207 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2)
169 208 {
170 209 return !(domain1 == domain2);
171 210 }
172 211
173 212
174 213 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain)
175 214 {
176 215 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
177 216 return dbg.maybeSpace();
178 217 }
179 218
180 219 #include "moc_logxlogydomain_p.cpp"
181 220
182 221 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,79
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef LOGXLOGYDOMAIN_H
31 31 #define LOGXLOGYDOMAIN_H
32 32 #include "abstractdomain_p.h"
33 33 #include <QRectF>
34 34 #include <QSizeF>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT LogXLogYDomain: public AbstractDomain
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 explicit LogXLogYDomain(QObject *object = 0);
43 43 virtual ~LogXLogYDomain();
44 44
45 45 DomainType type(){ return AbstractDomain::LogXLogYDomain;}
46 46
47 47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48 48
49 49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2);
50 50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2);
51 51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain);
52 52
53 53 void zoomIn(const QRectF &rect);
54 54 void zoomOut(const QRectF &rect);
55 55 void move(qreal dx, qreal dy);
56 56
57 57 QPointF calculateGeometryPoint(const QPointF &point) const;
58 58 QPointF calculateDomainPoint(const QPointF &point) const;
59 59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
60 60
61 bool attachAxis(QAbstractAxis* axis);
62 bool detachAxis(QAbstractAxis* axis);
63
64 public Q_SLOTS:
65 void handleVerticalAxisBaseChanged(qreal baseY);
66 void handleHorizontalAxisBaseChanged(qreal baseX);
67
61 68 private:
62 69 qreal m_logMinX;
63 70 qreal m_logMaxX;
64 71 qreal m_logBaseX;
65 72 qreal m_logMinY;
66 73 qreal m_logMaxY;
67 74 qreal m_logBaseY;
68 75 };
69 76
70 77 QTCOMMERCIALCHART_END_NAMESPACE
71 78
72 79 #endif // LOGXLOGYDOMAIN_H
@@ -1,182 +1,210
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 "logxydomain_p.h"
22 22 #include "qabstractaxis_p.h"
23 #include "qlogvalueaxis.h"
23 24 #include <qmath.h>
24 25
25 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 27
27 28 LogXYDomain::LogXYDomain(QObject *parent)
28 29 : AbstractDomain(parent),
29 30 m_logMinX(0),
30 31 m_logMaxX(1),
31 32 m_logBaseX(10)
32 33 {
33 34 }
34 35
35 36 LogXYDomain::~LogXYDomain()
36 37 {
37 38 }
38 39
39 40 void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
40 41 {
41 42 bool axisXChanged = false;
42 43 bool axisYChanged = false;
43 44
44 45 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
45 46 m_minX = minX;
46 47 m_maxX = maxX;
47 48 axisXChanged = true;
48 49 m_logMinX = log10(m_minX) / log10(m_logBaseX);
49 50 m_logMaxX = log10(m_maxX) / log10(m_logBaseX);
50 51 if(!m_signalsBlocked)
51 52 emit rangeHorizontalChanged(m_minX, m_maxX);
52 53 }
53 54
54 55 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
55 56 m_minY = minY;
56 57 m_maxY = maxY;
57 58 axisYChanged = true;
58 59 if(!m_signalsBlocked)
59 60 emit rangeVerticalChanged(m_minY, m_maxY);
60 61 }
61 62
62 63 if (axisXChanged || axisYChanged)
63 64 emit updated();
64 65 }
65 66
66 67 void LogXYDomain::zoomIn(const QRectF &rect)
67 68 {
68 69 qreal newLogMinX = rect.left() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX;
69 70 qreal newLogMaxX = rect.right() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX;
70 71 qreal minX = qPow(m_logBaseX, newLogMinX);
71 72 qreal maxX = qPow(m_logBaseX, newLogMaxX);
72 73
73 74 qreal dy = spanY() / m_size.height();
74 75 qreal minY = m_minY;
75 76 qreal maxY = m_maxY;
76 77
77 78 minY = maxY - dy * rect.bottom();
78 79 maxY = maxY - dy * rect.top();
79 80
80 81 setRange(minX, maxX, minY, maxY);
81 82 }
82 83
83 84 void LogXYDomain::zoomOut(const QRectF &rect)
84 85 {
85 86 qreal ratioX = m_size.width()/rect.width();
86 87 qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX;
87 88 qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX;
88 89 qreal minX = qPow(m_logBaseX, newLogMinX);
89 90 qreal maxX = qPow(m_logBaseX, newLogMaxX);
90 91
91 92 qreal dy = spanY() / rect.height();
92 93 qreal minY = m_minY;
93 94 qreal maxY = m_maxY;
94 95
95 96 maxY = minY + dy * rect.bottom();
96 97 minY = maxY - dy * m_size.height();
97 98
98 99 setRange(minX, maxX, minY, maxY);
99 100 }
100 101
101 102 void LogXYDomain::move(qreal dx, qreal dy)
102 103 {
103 104 qreal stepX = dx * qAbs(m_logMaxX - m_logMinX) / m_size.width();
104 105 qreal minX = qPow(m_logBaseX, m_logMinX + stepX);
105 106 qreal maxX = qPow(m_logBaseX, m_logMaxX + stepX);
106 107
107 108 qreal y = spanY() / m_size.height();
108 109 qreal minY = m_minY;
109 110 qreal maxY = m_maxY;
110 111
111 112 if (dy != 0) {
112 113 minY = minY + y * dy;
113 114 maxY = maxY + y * dy;
114 115 }
115 116 setRange(minX, maxX, minY, maxY);
116 117 }
117 118
118 119 QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point) const
119 120 {
120 121 const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX;
121 122 const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX);
122 123 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
123 124
124 125 qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdge * deltaX;
125 126 qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
126 127 return QPointF(x, y);
127 128 }
128 129
129 130 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
130 131 {
131 132 const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX;
132 133 const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX);
133 134 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
134 135
135 136 QVector<QPointF> result;
136 137 result.resize(vector.count());
137 138
138 139 for (int i = 0; i < vector.count(); ++i) {
139 140 qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - leftEdge * deltaX;
140 141 qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height();
141 142 result[i].setX(x);
142 143 result[i].setY(y);
143 144 }
144 145 return result;
145 146 }
146 147
147 148 QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const
148 149 {
149 150 const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX;
150 151 const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX);
151 152 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
152 153 qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX);
153 154 qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
154 155 return QPointF(x, y);
155 156 }
156 157
158 bool LogXYDomain::attachAxis(QAbstractAxis* axis)
159 {
160 AbstractDomain::attachAxis(axis);
161 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
162
163 if(logAxis && logAxis->orientation()==Qt::Horizontal)
164 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
165
166 return true;
167 }
168
169 bool LogXYDomain::detachAxis(QAbstractAxis* axis)
170 {
171 AbstractDomain::detachAxis(axis);
172 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
173
174 if(logAxis && logAxis->orientation()==Qt::Horizontal)
175 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
176
177 return true;
178 }
179
180 void LogXYDomain::handleHorizontalAxisBaseChanged(qreal baseX)
181 {
182 m_logBaseX = baseX;
183 }
184
157 185 // operators
158 186
159 187 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2)
160 188 {
161 189 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
162 190 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
163 191 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
164 192 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
165 193 }
166 194
167 195
168 196 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXYDomain &domain1, const LogXYDomain &domain2)
169 197 {
170 198 return !(domain1 == domain2);
171 199 }
172 200
173 201
174 202 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYDomain &domain)
175 203 {
176 204 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
177 205 return dbg.maybeSpace();
178 206 }
179 207
180 208 #include "moc_logxydomain_p.cpp"
181 209
182 210 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,75
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef LOGXYDOMAIN_H
31 31 #define LOGXYDOMAIN_H
32 32 #include "abstractdomain_p.h"
33 33 #include <QRectF>
34 34 #include <QSizeF>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT LogXYDomain: public AbstractDomain
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 explicit LogXYDomain(QObject *object = 0);
43 43 virtual ~LogXYDomain();
44 44
45 45 DomainType type(){ return AbstractDomain::LogXYDomain;}
46 46
47 47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48 48
49 49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2);
50 50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXYDomain &domain1, const LogXYDomain &domain2);
51 51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYDomain &domain);
52 52
53 53 void zoomIn(const QRectF &rect);
54 54 void zoomOut(const QRectF &rect);
55 55 void move(qreal dx, qreal dy);
56 56
57 57 QPointF calculateGeometryPoint(const QPointF &point) const;
58 58 QPointF calculateDomainPoint(const QPointF &point) const;
59 59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
60 60
61 bool attachAxis(QAbstractAxis* axis);
62 bool detachAxis(QAbstractAxis* axis);
63
64 public Q_SLOTS:
65 void handleHorizontalAxisBaseChanged(qreal baseX);
66
61 67 private:
62 68 qreal m_logMinX;
63 69 qreal m_logMaxX;
64 70 qreal m_logBaseX;
65 71 };
66 72
67 73 QTCOMMERCIALCHART_END_NAMESPACE
68 74
69 75 #endif // LOGXYDOMAIN_H
@@ -1,183 +1,211
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 "xlogydomain_p.h"
22 22 #include "qabstractaxis_p.h"
23 #include "qlogvalueaxis.h"
23 24 #include <qmath.h>
24 25
25 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 27
27 28 XLogYDomain::XLogYDomain(QObject *parent)
28 29 : AbstractDomain(parent),
29 30 m_logMinY(0),
30 31 m_logMaxY(1),
31 32 m_logBaseY(10)
32 33 {
33 34 }
34 35
35 36 XLogYDomain::~XLogYDomain()
36 37 {
37 38 }
38 39
39 40 void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
40 41 {
41 42 bool axisXChanged = false;
42 43 bool axisYChanged = false;
43 44
44 45 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
45 46 m_minX = minX;
46 47 m_maxX = maxX;
47 48 axisXChanged = true;
48 49 if(!m_signalsBlocked)
49 50 emit rangeHorizontalChanged(m_minX, m_maxX);
50 51 }
51 52
52 53 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
53 54 m_minY = minY;
54 55 m_maxY = maxY;
55 56 axisYChanged = true;
56 57 m_logMinY = log10(m_minY) / log10(m_logBaseY);
57 58 m_logMaxY = log10(m_maxY) / log10(m_logBaseY);
58 59 if(!m_signalsBlocked)
59 60 emit rangeVerticalChanged(m_minY, m_maxY);
60 61 }
61 62
62 63 if (axisXChanged || axisYChanged)
63 64 emit updated();
64 65 }
65 66
66 67 void XLogYDomain::zoomIn(const QRectF &rect)
67 68 {
68 69 qreal dx = spanX() / m_size.width();
69 70 qreal maxX = m_maxX;
70 71 qreal minX = m_minX;
71 72
72 73 maxX = minX + dx * rect.right();
73 74 minX = minX + dx * rect.left();
74 75
75 76 qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height();
76 77 qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height();
77 78 qreal minY = qPow(m_logBaseY, newLogMinY);
78 79 qreal maxY = qPow(m_logBaseY, newLogMaxY);
79 80
80 81 setRange(minX, maxX, minY, maxY);
81 82 }
82 83
83 84 void XLogYDomain::zoomOut(const QRectF &rect)
84 85 {
85 86 qreal dx = spanX() / rect.width();
86 87 qreal maxX = m_maxX;
87 88 qreal minX = m_minX;
88 89
89 90 minX = maxX - dx * rect.right();
90 91 maxX = minX + dx * m_size.width();
91 92
92 93 qreal ratioY = m_size.height()/rect.height();
93 94 qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY;
94 95 qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY;
95 96 qreal minY = qPow(m_logBaseY, newLogMinY);
96 97 qreal maxY = qPow(m_logBaseY, newLogMaxY);
97 98
98 99 setRange(minX, maxX, minY, maxY);
99 100 }
100 101
101 102 void XLogYDomain::move(qreal dx, qreal dy)
102 103 {
103 104 qreal x = spanX() / m_size.width();
104 105 qreal maxX = m_maxX;
105 106 qreal minX = m_minX;
106 107
107 108 if (dx != 0) {
108 109 minX = minX + x * dx;
109 110 maxX = maxX + x * dx;
110 111 }
111 112
112 113 qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height();
113 114 qreal minY = qPow(m_logBaseY, m_logMinY + stepY);
114 115 qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY);
115 116
116 117 setRange(minX, maxX, minY, maxY);
117 118 }
118 119
119 120 QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point) const
120 121 {
121 122 const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
122 123 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
123 124 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
124 125
125 126 qreal x = (point.x() - m_minX) * deltaX;
126 127 qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height();
127 128 return QPointF(x, y);
128 129 }
129 130
130 131 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
131 132 {
132 133 const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
133 134 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
134 135 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
135 136
136 137 QVector<QPointF> result;
137 138 result.resize(vector.count());
138 139
139 140 for (int i = 0; i < vector.count(); ++i) {
140 141 qreal x = (vector[i].x() - m_minX) * deltaX;
141 142 qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height();
142 143 result[i].setX(x);
143 144 result[i].setY(y);
144 145 }
145 146 return result;
146 147 }
147 148
148 149 QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const
149 150 {
150 151 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
151 152 const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
152 153 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
153 154 qreal x = point.x() / deltaX + m_minX;
154 155 qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY);
155 156 return QPointF(x, y);
156 157 }
157 158
159 bool XLogYDomain::attachAxis(QAbstractAxis* axis)
160 {
161 AbstractDomain::attachAxis(axis);
162 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
163
164 if(logAxis && logAxis->orientation()==Qt::Vertical)
165 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
166
167 return true;
168 }
169
170 bool XLogYDomain::detachAxis(QAbstractAxis* axis)
171 {
172 AbstractDomain::detachAxis(axis);
173 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
174
175 if(logAxis && logAxis->orientation()==Qt::Vertical)
176 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
177
178 return true;
179 }
180
181 void XLogYDomain::handleVerticalAxisBaseChanged(qreal baseY)
182 {
183 m_logBaseY = baseY;
184 }
185
158 186 // operators
159 187
160 188 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2)
161 189 {
162 190 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
163 191 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
164 192 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
165 193 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
166 194 }
167 195
168 196
169 197 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2)
170 198 {
171 199 return !(domain1 == domain2);
172 200 }
173 201
174 202
175 203 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain)
176 204 {
177 205 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
178 206 return dbg.maybeSpace();
179 207 }
180 208
181 209 #include "moc_xlogydomain_p.cpp"
182 210
183 211 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,75
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 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 Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial 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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef XLOGYDOMAIN_H
31 31 #define XLOGYDOMAIN_H
32 32 #include "abstractdomain_p.h"
33 33 #include <QRectF>
34 34 #include <QSizeF>
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XLogYDomain: public AbstractDomain
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 explicit XLogYDomain(QObject *object = 0);
43 43 virtual ~XLogYDomain();
44 44
45 45 DomainType type(){ return AbstractDomain::XLogYDomain;};
46 46
47 47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48 48
49 49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2);
50 50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2);
51 51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain);
52 52
53 53 void zoomIn(const QRectF &rect);
54 54 void zoomOut(const QRectF &rect);
55 55 void move(qreal dx, qreal dy);
56 56
57 57 QPointF calculateGeometryPoint(const QPointF &point) const;
58 58 QPointF calculateDomainPoint(const QPointF &point) const;
59 59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
60 60
61 bool attachAxis(QAbstractAxis* axis);
62 bool detachAxis(QAbstractAxis* axis);
63
64 public Q_SLOTS:
65 void handleVerticalAxisBaseChanged(qreal baseY);
66
61 67 private:
62 68 qreal m_logMinY;
63 69 qreal m_logMaxY;
64 70 qreal m_logBaseY;
65 71 };
66 72
67 73 QTCOMMERCIALCHART_END_NAMESPACE
68 74
69 75 #endif // XLOGYDOMAIN_H
General Comments 0
You need to be logged in to leave comments. Login now