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