@@ -0,0 +1,5 | |||||
|
1 | !include( ../auto.pri ) { | |||
|
2 | error( "Couldn't find the auto.pri file!" ) | |||
|
3 | } | |||
|
4 | HEADERS += ../qabstractaxis/tst_qabstractaxis.h | |||
|
5 | SOURCES += tst_qlogvalueaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp |
@@ -0,0 +1,378 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "../qabstractaxis/tst_qabstractaxis.h" | |||
|
22 | #include "qlogvalueaxis.h" | |||
|
23 | #include <qlineseries.h> | |||
|
24 | #include <QDebug> | |||
|
25 | ||||
|
26 | class tst_QLogValueAxis: public tst_QAbstractAxis | |||
|
27 | { | |||
|
28 | Q_OBJECT | |||
|
29 | ||||
|
30 | public slots: | |||
|
31 | void initTestCase(); | |||
|
32 | void cleanupTestCase(); | |||
|
33 | void init(); | |||
|
34 | void cleanup(); | |||
|
35 | ||||
|
36 | private slots: | |||
|
37 | // void qlogvalueaxis_data(); | |||
|
38 | // void qlogvalueaxis(); | |||
|
39 | // void max_raw_data(); | |||
|
40 | // void max_raw(); | |||
|
41 | // void max_data(); | |||
|
42 | // void max(); | |||
|
43 | // void max_animation_data(); | |||
|
44 | // void max_animation(); | |||
|
45 | void min_raw_data(); | |||
|
46 | void min_raw(); | |||
|
47 | void min_data(); | |||
|
48 | void min(); | |||
|
49 | void min_animation_data(); | |||
|
50 | void min_animation(); | |||
|
51 | // void range_raw_data(); | |||
|
52 | // void range_raw(); | |||
|
53 | // void range_data(); | |||
|
54 | // void range(); | |||
|
55 | // void range_animation_data(); | |||
|
56 | // void range_animation(); | |||
|
57 | // void noautoscale_data(); | |||
|
58 | // void noautoscale(); | |||
|
59 | // void autoscale_data(); | |||
|
60 | // void autoscale(); | |||
|
61 | void zoomIn(); | |||
|
62 | // void zoomOut(); | |||
|
63 | ||||
|
64 | private: | |||
|
65 | QLogValueAxis* m_logvaluesaxis; | |||
|
66 | QLineSeries* m_series; | |||
|
67 | }; | |||
|
68 | ||||
|
69 | void tst_QLogValueAxis::initTestCase() | |||
|
70 | { | |||
|
71 | } | |||
|
72 | ||||
|
73 | void tst_QLogValueAxis::cleanupTestCase() | |||
|
74 | { | |||
|
75 | } | |||
|
76 | ||||
|
77 | void tst_QLogValueAxis::init() | |||
|
78 | { | |||
|
79 | m_logvaluesaxis = new QLogValueAxis(); | |||
|
80 | m_series = new QLineSeries(); | |||
|
81 | *m_series << QPointF(1, 1) << QPointF(100, 100); | |||
|
82 | tst_QAbstractAxis::init(m_logvaluesaxis,m_series); | |||
|
83 | m_chart->addSeries(m_series); | |||
|
84 | m_chart->createDefaultAxes(); | |||
|
85 | } | |||
|
86 | ||||
|
87 | void tst_QLogValueAxis::cleanup() | |||
|
88 | { | |||
|
89 | delete m_series; | |||
|
90 | delete m_logvaluesaxis; | |||
|
91 | m_series = 0; | |||
|
92 | m_logvaluesaxis = 0; | |||
|
93 | tst_QAbstractAxis::cleanup(); | |||
|
94 | } | |||
|
95 | ||||
|
96 | //void tst_QLogValueAxis::qlogvalueaxis_data() | |||
|
97 | //{ | |||
|
98 | //} | |||
|
99 | ||||
|
100 | //void tst_QLogValueAxis::qlogvalueaxis() | |||
|
101 | //{ | |||
|
102 | // qabstractaxis(); | |||
|
103 | ||||
|
104 | // QVERIFY(qFuzzyCompare(m_logvaluesaxis->max(), 1)); | |||
|
105 | // QVERIFY(qFuzzyCompare(m_logvaluesaxis->min(), 1)); | |||
|
106 | // QCOMPARE(m_logvaluesaxis->type(), QAbstractAxis::AxisTypeLogValue); | |||
|
107 | ||||
|
108 | // m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
109 | // m_view->show(); | |||
|
110 | // QTest::qWaitForWindowShown(m_view); | |||
|
111 | ||||
|
112 | // QVERIFY(!qFuzzyCompare(m_logvaluesaxis->max(), 100)); | |||
|
113 | // QVERIFY(!qFuzzyCompare(m_logvaluesaxis->min(), 0.1)); | |||
|
114 | //} | |||
|
115 | ||||
|
116 | //void tst_QLogValueAxis::max_raw_data() | |||
|
117 | //{ | |||
|
118 | // QTest::addColumn<qreal>("max"); | |||
|
119 | // QTest::addColumn<qreal>("expected"); | |||
|
120 | // QTest::addColumn<bool>("minChanged"); | |||
|
121 | // QTest::addColumn<bool>("maxChanged"); | |||
|
122 | // QTest::newRow("-1.0") << (qreal)-1.0 << (qreal)1.0 << false << false; | |||
|
123 | // QTest::newRow("0.0") << (qreal)0.0 << (qreal)1.0 << false << false; | |||
|
124 | // QTest::newRow("0.5") << (qreal)0.5 << (qreal)0.5 << true << true; | |||
|
125 | // QTest::newRow("101.0") << (qreal)101.0 << (qreal)101.0 << false << true; | |||
|
126 | //} | |||
|
127 | ||||
|
128 | //void tst_QLogValueAxis::max_raw() | |||
|
129 | //{ | |||
|
130 | // QFETCH(qreal, max); | |||
|
131 | // QFETCH(qreal, expected); | |||
|
132 | // QFETCH(bool, minChanged); | |||
|
133 | // QFETCH(bool, maxChanged); | |||
|
134 | ||||
|
135 | // QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal))); | |||
|
136 | // QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal))); | |||
|
137 | // QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal))); | |||
|
138 | ||||
|
139 | // m_logvaluesaxis->setMax(max); | |||
|
140 | // QCOMPARE(m_logvaluesaxis->max(), expected); | |||
|
141 | ||||
|
142 | // QCOMPARE(spy0.count(), (int)maxChanged); | |||
|
143 | // QCOMPARE(spy1.count(), (int)minChanged); | |||
|
144 | // QCOMPARE(spy2.count(), (int)maxChanged); | |||
|
145 | ||||
|
146 | //} | |||
|
147 | ||||
|
148 | //void tst_QLogValueAxis::max_data() | |||
|
149 | //{ | |||
|
150 | // max_raw_data(); | |||
|
151 | //} | |||
|
152 | ||||
|
153 | //void tst_QLogValueAxis::max() | |||
|
154 | //{ | |||
|
155 | // m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
156 | // m_view->show(); | |||
|
157 | // QTest::qWaitForWindowShown(m_view); | |||
|
158 | // max_raw(); | |||
|
159 | //} | |||
|
160 | ||||
|
161 | //void tst_QLogValueAxis::max_animation_data() | |||
|
162 | //{ | |||
|
163 | // max_data(); | |||
|
164 | //} | |||
|
165 | ||||
|
166 | //void tst_QLogValueAxis::max_animation() | |||
|
167 | //{ | |||
|
168 | // m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |||
|
169 | // max(); | |||
|
170 | //} | |||
|
171 | ||||
|
172 | void tst_QLogValueAxis::min_raw_data() | |||
|
173 | { | |||
|
174 | QTest::addColumn<qreal>("min"); | |||
|
175 | QTest::addColumn<qreal>("expected"); | |||
|
176 | QTest::addColumn<bool>("minChanged"); | |||
|
177 | QTest::addColumn<bool>("maxChanged"); | |||
|
178 | QTest::newRow("-1.0") << (qreal)-1.0 << (qreal)1.0 << false << false; | |||
|
179 | QTest::newRow("0.0") << (qreal)0.0 << (qreal)1.0 << false << false; | |||
|
180 | QTest::newRow("0.5") << (qreal)0.5 << (qreal)0.5 << true << false; | |||
|
181 | QTest::newRow("101.0") << (qreal)101.0 << (qreal)101.0 << true << true; | |||
|
182 | } | |||
|
183 | ||||
|
184 | void tst_QLogValueAxis::min_raw() | |||
|
185 | { | |||
|
186 | QFETCH(qreal, min); | |||
|
187 | QFETCH(qreal, expected); | |||
|
188 | QFETCH(bool, minChanged); | |||
|
189 | QFETCH(bool, maxChanged); | |||
|
190 | ||||
|
191 | QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal))); | |||
|
192 | QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal))); | |||
|
193 | QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal))); | |||
|
194 | ||||
|
195 | m_logvaluesaxis->setMin(min); | |||
|
196 | QCOMPARE(m_logvaluesaxis->min(), expected); | |||
|
197 | ||||
|
198 | QCOMPARE(spy0.count(), (int)maxChanged); | |||
|
199 | QCOMPARE(spy1.count(), (int)minChanged); | |||
|
200 | QCOMPARE(spy2.count(), (int)minChanged); | |||
|
201 | } | |||
|
202 | ||||
|
203 | void tst_QLogValueAxis::min_data() | |||
|
204 | { | |||
|
205 | min_raw_data(); | |||
|
206 | } | |||
|
207 | ||||
|
208 | void tst_QLogValueAxis::min() | |||
|
209 | { | |||
|
210 | m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
211 | m_view->show(); | |||
|
212 | QTest::qWaitForWindowShown(m_view); | |||
|
213 | min_raw(); | |||
|
214 | } | |||
|
215 | ||||
|
216 | void tst_QLogValueAxis::min_animation_data() | |||
|
217 | { | |||
|
218 | min_data(); | |||
|
219 | } | |||
|
220 | ||||
|
221 | void tst_QLogValueAxis::min_animation() | |||
|
222 | { | |||
|
223 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |||
|
224 | min(); | |||
|
225 | } | |||
|
226 | ||||
|
227 | //void tst_QLogValueAxis::range_raw_data() | |||
|
228 | //{ | |||
|
229 | // QTest::addColumn<qreal>("min"); | |||
|
230 | // QTest::addColumn<qreal>("max"); | |||
|
231 | // QTest::newRow("1.0 - 101.0") << (qreal)1.0 << (qreal)101.0; | |||
|
232 | // QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0; | |||
|
233 | // QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0; | |||
|
234 | //} | |||
|
235 | ||||
|
236 | //void tst_QLogValueAxis::range_raw() | |||
|
237 | //{ | |||
|
238 | // QFETCH(qreal, min); | |||
|
239 | // QFETCH(qreal, max); | |||
|
240 | ||||
|
241 | // QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal))); | |||
|
242 | // QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal))); | |||
|
243 | // QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal))); | |||
|
244 | ||||
|
245 | // m_logvaluesaxis->setRange(min, max); | |||
|
246 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->min(), min), "Min not equal"); | |||
|
247 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->max(), max), "Max not equal"); | |||
|
248 | ||||
|
249 | // QCOMPARE(spy0.count(), 1); | |||
|
250 | // QCOMPARE(spy1.count(), 1); | |||
|
251 | // QCOMPARE(spy2.count(), 1); | |||
|
252 | //} | |||
|
253 | ||||
|
254 | //void tst_QLogValueAxis::range_data() | |||
|
255 | //{ | |||
|
256 | // range_raw_data(); | |||
|
257 | //} | |||
|
258 | ||||
|
259 | //void tst_QLogValueAxis::range() | |||
|
260 | //{ | |||
|
261 | // m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
262 | // m_view->show(); | |||
|
263 | // QTest::qWaitForWindowShown(m_view); | |||
|
264 | // range_raw(); | |||
|
265 | //} | |||
|
266 | ||||
|
267 | //void tst_QLogValueAxis::range_animation_data() | |||
|
268 | //{ | |||
|
269 | // range_data(); | |||
|
270 | //} | |||
|
271 | ||||
|
272 | //void tst_QLogValueAxis::range_animation() | |||
|
273 | //{ | |||
|
274 | // m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |||
|
275 | // range(); | |||
|
276 | //} | |||
|
277 | ||||
|
278 | //void tst_QLogValueAxis::noautoscale_data() | |||
|
279 | //{ | |||
|
280 | // QTest::addColumn<qreal>("min"); | |||
|
281 | // QTest::addColumn<qreal>("max"); | |||
|
282 | // QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0; | |||
|
283 | // QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0; | |||
|
284 | // QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0; | |||
|
285 | //} | |||
|
286 | ||||
|
287 | //void tst_QLogValueAxis::noautoscale() | |||
|
288 | //{ | |||
|
289 | // QFETCH(qreal, min); | |||
|
290 | // QFETCH(qreal, max); | |||
|
291 | ||||
|
292 | // QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal))); | |||
|
293 | // QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal))); | |||
|
294 | // QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal))); | |||
|
295 | ||||
|
296 | // m_logvaluesaxis->setRange(min, max); | |||
|
297 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->min(), min), "Min not equal"); | |||
|
298 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->max(), max), "Max not equal"); | |||
|
299 | ||||
|
300 | // QCOMPARE(spy0.count(), 1); | |||
|
301 | // QCOMPARE(spy1.count(), 1); | |||
|
302 | // QCOMPARE(spy2.count(), 1); | |||
|
303 | ||||
|
304 | // m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
305 | // m_view->show(); | |||
|
306 | // QTest::qWaitForWindowShown(m_view); | |||
|
307 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->min(), min), "Min not equal"); | |||
|
308 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->max(), max), "Max not equal"); | |||
|
309 | //} | |||
|
310 | ||||
|
311 | //void tst_QLogValueAxis::autoscale_data() | |||
|
312 | //{ | |||
|
313 | ||||
|
314 | //} | |||
|
315 | ||||
|
316 | //void tst_QLogValueAxis::autoscale() | |||
|
317 | //{ | |||
|
318 | // QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal))); | |||
|
319 | // QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal))); | |||
|
320 | // QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal))); | |||
|
321 | ||||
|
322 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->min(), 0), "Min not equal"); | |||
|
323 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->max(), 0), "Max not equal"); | |||
|
324 | // m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
325 | ||||
|
326 | // QCOMPARE(spy0.count(), 1); | |||
|
327 | // QCOMPARE(spy1.count(), 1); | |||
|
328 | // QCOMPARE(spy2.count(), 1); | |||
|
329 | ||||
|
330 | // m_view->show(); | |||
|
331 | // QTest::qWaitForWindowShown(m_view); | |||
|
332 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->min(), -100), "Min not equal"); | |||
|
333 | // QVERIFY2(qFuzzyCompare(m_logvaluesaxis->max(), 100), "Max not equal"); | |||
|
334 | //} | |||
|
335 | ||||
|
336 | void tst_QLogValueAxis::zoomIn() | |||
|
337 | { | |||
|
338 | m_chart->setAxisX(m_logvaluesaxis, m_series); | |||
|
339 | m_view->show(); | |||
|
340 | QTest::qWaitForWindowShown(m_view); | |||
|
341 | m_logvaluesaxis->setBase(2); | |||
|
342 | m_logvaluesaxis->setRange(0.5, 2); | |||
|
343 | ||||
|
344 | QCOMPARE(m_logvaluesaxis->min(), (qreal)0.5); | |||
|
345 | QCOMPARE(m_logvaluesaxis->max(), (qreal)2.0); | |||
|
346 | ||||
|
347 | m_chart->zoomOut(); | |||
|
348 | ||||
|
349 | QCOMPARE(m_logvaluesaxis->min(), (qreal)0.25); | |||
|
350 | QCOMPARE(m_logvaluesaxis->max(), (qreal)4.0); | |||
|
351 | ||||
|
352 | m_chart->zoomIn(); | |||
|
353 | ||||
|
354 | QCOMPARE(m_logvaluesaxis->min(), (qreal)0.5); | |||
|
355 | QCOMPARE(m_logvaluesaxis->max(), (qreal)2.0); | |||
|
356 | ||||
|
357 | m_logvaluesaxis->setRange(0.5, 1024); | |||
|
358 | m_chart->zoom(11.0); | |||
|
359 | ||||
|
360 | QCOMPARE(m_logvaluesaxis->min(), (qreal)16.0); | |||
|
361 | QCOMPARE(m_logvaluesaxis->max(), (qreal)32.0); | |||
|
362 | ||||
|
363 | m_logvaluesaxis->setRange(16, 64); | |||
|
364 | m_chart->zoom(1/3.0); | |||
|
365 | ||||
|
366 | QCOMPARE(m_logvaluesaxis->min(), (qreal)4); | |||
|
367 | QCOMPARE(m_logvaluesaxis->max(), (qreal)256.0); | |||
|
368 | ||||
|
369 | } | |||
|
370 | ||||
|
371 | //void tst_QLogValueAxis::zoomOut() | |||
|
372 | //{ | |||
|
373 | ||||
|
374 | //} | |||
|
375 | ||||
|
376 | QTEST_MAIN(tst_QLogValueAxis) | |||
|
377 | #include "tst_qlogvalueaxis.moc" | |||
|
378 |
@@ -41,7 +41,7 View::View(QWidget *parent) | |||||
41 |
|
41 | |||
42 | // chart |
|
42 | // chart | |
43 | m_chart = new QChart; |
|
43 | m_chart = new QChart; | |
44 |
m_chart->setMinimumSize( |
|
44 | m_chart->setMinimumSize(640, 480); | |
45 | m_chart->setTitle("Hover the line to show callout. Click the line to make it stay"); |
|
45 | m_chart->setTitle("Hover the line to show callout. Click the line to make it stay"); | |
46 | m_chart->legend()->hide(); |
|
46 | m_chart->legend()->hide(); | |
47 | QLineSeries *series = new QLineSeries; |
|
47 | QLineSeries *series = new QLineSeries; | |
@@ -84,8 +84,12 View::View(QWidget *parent) | |||||
84 |
|
84 | |||
85 | void View::resizeEvent(QResizeEvent *event) |
|
85 | void View::resizeEvent(QResizeEvent *event) | |
86 | { |
|
86 | { | |
87 | if (scene()) |
|
87 | if (scene()) { | |
88 | scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); |
|
88 | scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); | |
|
89 | m_chart->resize(event->size()); | |||
|
90 | m_coordX->setPos(m_chart->size().width()/2 - 50, m_chart->size().height() - 20); | |||
|
91 | m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height() - 20); | |||
|
92 | } | |||
89 | QGraphicsView::resizeEvent(event); |
|
93 | QGraphicsView::resizeEvent(event); | |
90 | } |
|
94 | } | |
91 |
|
95 |
@@ -391,8 +391,11 QPointF ChartDataSet::mapToValue(const QPointF &position, QAbstractSeries *serie | |||||
391 | if (series == 0 && !m_seriesList.isEmpty()) |
|
391 | if (series == 0 && !m_seriesList.isEmpty()) | |
392 | series = m_seriesList.first(); |
|
392 | series = m_seriesList.first(); | |
393 |
|
393 | |||
|
394 | if (series && series->type() == QAbstractSeries::SeriesTypePie) | |||
|
395 | return point; | |||
|
396 | ||||
394 | if (series && m_seriesList.contains(series)) |
|
397 | if (series && m_seriesList.contains(series)) | |
395 | point = series->d_ptr->m_domain->calculateDomainPoint(position); |
|
398 | point = series->d_ptr->m_domain->calculateDomainPoint(position - m_chart->plotArea().topLeft()); | |
396 | return point; |
|
399 | return point; | |
397 | } |
|
400 | } | |
398 |
|
401 | |||
@@ -402,6 +405,9 QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *serie | |||||
402 | if (series == 0 && !m_seriesList.isEmpty()) |
|
405 | if (series == 0 && !m_seriesList.isEmpty()) | |
403 | series = m_seriesList.first(); |
|
406 | series = m_seriesList.first(); | |
404 |
|
407 | |||
|
408 | if (series && series->type() == QAbstractSeries::SeriesTypePie) | |||
|
409 | return QPoint(0, 0); | |||
|
410 | ||||
405 | if (series && m_seriesList.contains(series)) |
|
411 | if (series && m_seriesList.contains(series)) | |
406 | point += series->d_ptr->m_domain->calculateGeometryPoint(value); |
|
412 | point += series->d_ptr->m_domain->calculateGeometryPoint(value); | |
407 | return point; |
|
413 | return point; |
@@ -27,11 +27,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
27 |
|
27 | |||
28 | LogXLogYDomain::LogXLogYDomain(QObject *parent) |
|
28 | LogXLogYDomain::LogXLogYDomain(QObject *parent) | |
29 | : AbstractDomain(parent), |
|
29 | : AbstractDomain(parent), | |
30 |
m_log |
|
30 | m_logLeftX(0), | |
31 |
m_log |
|
31 | m_logRightX(1), | |
32 | m_logBaseX(10), |
|
32 | m_logBaseX(10), | |
33 |
m_log |
|
33 | m_logLeftY(0), | |
34 |
m_log |
|
34 | m_logRightY(1), | |
35 | m_logBaseY(10) |
|
35 | m_logBaseY(10) | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
@@ -49,8 +49,10 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
49 | m_minX = minX; |
|
49 | m_minX = minX; | |
50 | m_maxX = maxX; |
|
50 | m_maxX = maxX; | |
51 | axisXChanged = true; |
|
51 | axisXChanged = true; | |
52 |
|
|
52 | qreal logMinX = log10(m_minX) / log10(m_logBaseX); | |
53 |
|
|
53 | qreal logMaxX = log10(m_maxX) / log10(m_logBaseX); | |
|
54 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; | |||
|
55 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; | |||
54 | if(!m_signalsBlocked) |
|
56 | if(!m_signalsBlocked) | |
55 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
57 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
56 | } |
|
58 | } | |
@@ -59,8 +61,10 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
59 | m_minY = minY; |
|
61 | m_minY = minY; | |
60 | m_maxY = maxY; |
|
62 | m_maxY = maxY; | |
61 | axisYChanged = true; |
|
63 | axisYChanged = true; | |
62 |
|
|
64 | qreal logMinY = log10(m_minY) / log10(m_logBaseY); | |
63 |
|
|
65 | qreal logMaxY = log10(m_maxY) / log10(m_logBaseY); | |
|
66 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; | |||
|
67 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; | |||
64 | if(!m_signalsBlocked) |
|
68 | if(!m_signalsBlocked) | |
65 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
69 | emit rangeVerticalChanged(m_minY, m_maxY); | |
66 | } |
|
70 | } | |
@@ -71,73 +75,82 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
71 |
|
75 | |||
72 | void LogXLogYDomain::zoomIn(const QRectF &rect) |
|
76 | void LogXLogYDomain::zoomIn(const QRectF &rect) | |
73 | { |
|
77 | { | |
74 |
qreal |
|
78 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; | |
75 |
qreal |
|
79 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; | |
76 |
qreal |
|
80 | qreal leftX = qPow(m_logBaseX, logLeftX); | |
77 |
qreal |
|
81 | qreal rightX = qPow(m_logBaseX, logRightX); | |
|
82 | qreal minX = leftX < rightX ? leftX : rightX; | |||
|
83 | qreal maxX = leftX > rightX ? leftX : rightX; | |||
78 |
|
84 | |||
79 |
qreal |
|
85 | qreal logLeftY = m_logRightY - rect.bottom() * (m_logRightY - m_logLeftY) / m_size.height(); | |
80 |
qreal |
|
86 | qreal logRightY = m_logRightY - rect.top() * (m_logRightY - m_logLeftY) / m_size.height(); | |
81 |
qreal |
|
87 | qreal leftY = qPow(m_logBaseY, logLeftY); | |
82 |
qreal |
|
88 | qreal rightY = qPow(m_logBaseY, logRightY); | |
|
89 | qreal minY = leftY < rightY ? leftY : rightY; | |||
|
90 | qreal maxY = leftY > rightY ? leftY : rightY; | |||
83 |
|
91 | |||
84 | setRange(minX, maxX, minY, maxY); |
|
92 | setRange(minX, maxX, minY, maxY); | |
85 | } |
|
93 | } | |
86 |
|
94 | |||
87 | void LogXLogYDomain::zoomOut(const QRectF &rect) |
|
95 | void LogXLogYDomain::zoomOut(const QRectF &rect) | |
88 | { |
|
96 | { | |
89 |
qreal |
|
97 | const qreal factorX = m_size.width() / rect.width(); | |
90 | qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX; |
|
98 | const qreal factorY = m_size.height() / rect.height(); | |
91 | qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX; |
|
|||
92 | qreal minX = qPow(m_logBaseX, newLogMinX); |
|
|||
93 | qreal maxX = qPow(m_logBaseX, newLogMaxX); |
|
|||
94 |
|
99 | |||
95 | qreal ratioY = m_size.height()/rect.height(); |
|
100 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); | |
96 | qreal newLogMinY = m_logMinY - (m_logMaxY - m_logMinY) / ratioY; |
|
101 | qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); | |
97 | qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY; |
|
102 | qreal leftX = qPow(m_logBaseX, logLeftX); | |
98 |
qreal |
|
103 | qreal rightX = qPow(m_logBaseX, logRIghtX); | |
99 | qreal maxY = qPow(m_logBaseY, newLogMaxY); |
|
104 | qreal minX = leftX < rightX ? leftX : rightX; | |
|
105 | qreal maxX = leftX > rightX ? leftX : rightX; | |||
|
106 | ||||
|
107 | qreal newLogMinY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 - factorY); | |||
|
108 | qreal newLogMaxY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 + factorY); | |||
|
109 | qreal leftY = qPow(m_logBaseY, newLogMinY); | |||
|
110 | qreal rightY = qPow(m_logBaseY, newLogMaxY); | |||
|
111 | qreal minY = leftY < rightY ? leftY : rightY; | |||
|
112 | qreal maxY = leftY > rightY ? leftY : rightY; | |||
100 |
|
113 | |||
101 | setRange(minX, maxX, minY, maxY); |
|
114 | setRange(minX, maxX, minY, maxY); | |
102 | } |
|
115 | } | |
103 |
|
116 | |||
104 | void LogXLogYDomain::move(qreal dx, qreal dy) |
|
117 | void LogXLogYDomain::move(qreal dx, qreal dy) | |
105 | { |
|
118 | { | |
106 |
qreal stepX = dx * qAbs(m_log |
|
119 | qreal stepX = dx * qAbs(m_logRightX - m_logLeftX) / m_size.width(); | |
107 |
qreal |
|
120 | qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX); | |
108 |
qreal |
|
121 | qreal rightX = qPow(m_logBaseX, m_logRightX + stepX); | |
|
122 | qreal minX = leftX < rightX ? leftX : rightX; | |||
|
123 | qreal maxX = leftX > rightX ? leftX : rightX; | |||
109 |
|
124 | |||
110 |
qreal stepY = dy * |
|
125 | qreal stepY = dy * (m_logRightY - m_logLeftY) / m_size.height(); | |
111 |
qreal |
|
126 | qreal leftY = qPow(m_logBaseY, m_logLeftY + stepY); | |
112 |
qreal |
|
127 | qreal rightY = qPow(m_logBaseY, m_logRightY + stepY); | |
|
128 | qreal minY = leftY < rightY ? leftY : rightY; | |||
|
129 | qreal maxY = leftY > rightY ? leftY : rightY; | |||
113 |
|
130 | |||
114 | setRange(minX, maxX, minY, maxY); |
|
131 | setRange(minX, maxX, minY, maxY); | |
115 | } |
|
132 | } | |
116 |
|
133 | |||
117 | QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point) const |
|
134 | QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point) const | |
118 | { |
|
135 | { | |
119 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
136 | const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX); | |
120 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
137 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); | |
121 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
138 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; | |
122 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
139 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); | |
123 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX; |
|
|||
124 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height(); |
|
|||
125 | return QPointF(x, y); |
|
140 | return QPointF(x, y); | |
126 | } |
|
141 | } | |
127 |
|
142 | |||
128 | QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const |
|
143 | QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
129 | { |
|
144 | { | |
130 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
145 | const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX); | |
131 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
146 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); | |
132 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
|||
133 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
|||
134 |
|
147 | |||
135 | QVector<QPointF> result; |
|
148 | QVector<QPointF> result; | |
136 | result.resize(vector.count()); |
|
149 | result.resize(vector.count()); | |
137 |
|
150 | |||
138 | for (int i = 0; i < vector.count(); ++i) { |
|
151 | for (int i = 0; i < vector.count(); ++i) { | |
139 |
qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - left |
|
152 | qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; | |
140 |
qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - left |
|
153 | qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); | |
141 | result[i].setX(x); |
|
154 | result[i].setX(x); | |
142 | result[i].setY(y); |
|
155 | result[i].setY(y); | |
143 | } |
|
156 | } | |
@@ -146,12 +159,10 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& v | |||||
146 |
|
159 | |||
147 | QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const |
|
160 | QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const | |
148 | { |
|
161 | { | |
149 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
162 | const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX); | |
150 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
163 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); | |
151 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
164 | qreal x = qPow(m_logBaseX, m_logLeftX + point.x() / deltaX); | |
152 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
165 | qreal y = qPow(m_logBaseY, m_logLeftY + (m_size.height() - point.y()) / deltaY); | |
153 | qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX); |
|
|||
154 | qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY); |
|
|||
155 | return QPointF(x, y); |
|
166 | return QPointF(x, y); | |
156 | } |
|
167 | } | |
157 |
|
168 | |||
@@ -190,16 +201,20 bool LogXLogYDomain::detachAxis(QAbstractAxis* axis) | |||||
190 | void LogXLogYDomain::handleVerticalAxisBaseChanged(qreal baseY) |
|
201 | void LogXLogYDomain::handleVerticalAxisBaseChanged(qreal baseY) | |
191 | { |
|
202 | { | |
192 | m_logBaseY = baseY; |
|
203 | m_logBaseY = baseY; | |
193 |
|
|
204 | qreal logMinY = log10(m_minY) / log10(m_logBaseY); | |
194 |
|
|
205 | qreal logMaxY = log10(m_maxY) / log10(m_logBaseY); | |
|
206 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; | |||
|
207 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; | |||
195 | emit updated(); |
|
208 | emit updated(); | |
196 | } |
|
209 | } | |
197 |
|
210 | |||
198 | void LogXLogYDomain::handleHorizontalAxisBaseChanged(qreal baseX) |
|
211 | void LogXLogYDomain::handleHorizontalAxisBaseChanged(qreal baseX) | |
199 | { |
|
212 | { | |
200 | m_logBaseX = baseX; |
|
213 | m_logBaseX = baseX; | |
201 |
|
|
214 | qreal logMinX = log10(m_minX) / log10(m_logBaseX); | |
202 |
|
|
215 | qreal logMaxX = log10(m_maxX) / log10(m_logBaseX); | |
|
216 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; | |||
|
217 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; | |||
203 | emit updated(); |
|
218 | emit updated(); | |
204 | } |
|
219 | } | |
205 |
|
220 |
@@ -66,11 +66,11 public Q_SLOTS: | |||||
66 | void handleHorizontalAxisBaseChanged(qreal baseX); |
|
66 | void handleHorizontalAxisBaseChanged(qreal baseX); | |
67 |
|
67 | |||
68 | private: |
|
68 | private: | |
69 |
qreal m_log |
|
69 | qreal m_logLeftX; | |
70 |
qreal m_log |
|
70 | qreal m_logRightX; | |
71 | qreal m_logBaseX; |
|
71 | qreal m_logBaseX; | |
72 |
qreal m_log |
|
72 | qreal m_logLeftY; | |
73 |
qreal m_log |
|
73 | qreal m_logRightY; | |
74 | qreal m_logBaseY; |
|
74 | qreal m_logBaseY; | |
75 | }; |
|
75 | }; | |
76 |
|
76 |
@@ -27,8 +27,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
27 |
|
27 | |||
28 | LogXYDomain::LogXYDomain(QObject *parent) |
|
28 | LogXYDomain::LogXYDomain(QObject *parent) | |
29 | : AbstractDomain(parent), |
|
29 | : AbstractDomain(parent), | |
30 |
m_log |
|
30 | m_logLeftX(0), | |
31 |
m_log |
|
31 | m_logRightX(1), | |
32 | m_logBaseX(10) |
|
32 | m_logBaseX(10) | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
@@ -46,8 +46,10 void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
46 | m_minX = minX; |
|
46 | m_minX = minX; | |
47 | m_maxX = maxX; |
|
47 | m_maxX = maxX; | |
48 | axisXChanged = true; |
|
48 | axisXChanged = true; | |
49 |
|
|
49 | qreal logMinX = log10(m_minX) / log10(m_logBaseX); | |
50 |
|
|
50 | qreal logMaxX = log10(m_maxX) / log10(m_logBaseX); | |
|
51 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; | |||
|
52 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; | |||
51 | if(!m_signalsBlocked) |
|
53 | if(!m_signalsBlocked) | |
52 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
54 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
53 | } |
|
55 | } | |
@@ -66,10 +68,12 void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
66 |
|
68 | |||
67 | void LogXYDomain::zoomIn(const QRectF &rect) |
|
69 | void LogXYDomain::zoomIn(const QRectF &rect) | |
68 | { |
|
70 | { | |
69 |
qreal |
|
71 | qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; | |
70 |
qreal |
|
72 | qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX; | |
71 |
qreal |
|
73 | qreal leftX = qPow(m_logBaseX, logLeftX); | |
72 |
qreal |
|
74 | qreal rightX = qPow(m_logBaseX, logRightX); | |
|
75 | qreal minX = leftX < rightX ? leftX : rightX; | |||
|
76 | qreal maxX = leftX > rightX ? leftX : rightX; | |||
73 |
|
77 | |||
74 | qreal dy = spanY() / m_size.height(); |
|
78 | qreal dy = spanY() / m_size.height(); | |
75 | qreal minY = m_minY; |
|
79 | qreal minY = m_minY; | |
@@ -83,11 +87,14 void LogXYDomain::zoomIn(const QRectF &rect) | |||||
83 |
|
87 | |||
84 | void LogXYDomain::zoomOut(const QRectF &rect) |
|
88 | void LogXYDomain::zoomOut(const QRectF &rect) | |
85 | { |
|
89 | { | |
86 |
qreal |
|
90 | const qreal factorX = m_size.width() / rect.width(); | |
87 | qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX; |
|
91 | ||
88 |
qreal |
|
92 | qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 - factorX); | |
89 | qreal minX = qPow(m_logBaseX, newLogMinX); |
|
93 | qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2 * (1 + factorX); | |
90 |
qreal |
|
94 | qreal leftX = qPow(m_logBaseX, logLeftX); | |
|
95 | qreal rightX = qPow(m_logBaseX, logRIghtX); | |||
|
96 | qreal minX = leftX < rightX ? leftX : rightX; | |||
|
97 | qreal maxX = leftX > rightX ? leftX : rightX; | |||
91 |
|
98 | |||
92 | qreal dy = spanY() / rect.height(); |
|
99 | qreal dy = spanY() / rect.height(); | |
93 | qreal minY = m_minY; |
|
100 | qreal minY = m_minY; | |
@@ -101,9 +108,11 void LogXYDomain::zoomOut(const QRectF &rect) | |||||
101 |
|
108 | |||
102 | void LogXYDomain::move(qreal dx, qreal dy) |
|
109 | void LogXYDomain::move(qreal dx, qreal dy) | |
103 | { |
|
110 | { | |
104 |
qreal stepX = dx * |
|
111 | qreal stepX = dx * (m_logRightX - m_logLeftX) / m_size.width(); | |
105 |
qreal |
|
112 | qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX); | |
106 |
qreal |
|
113 | qreal rightX = qPow(m_logBaseX, m_logRightX + stepX); | |
|
114 | qreal minX = leftX < rightX ? leftX : rightX; | |||
|
115 | qreal maxX = leftX > rightX ? leftX : rightX; | |||
107 |
|
116 | |||
108 | qreal y = spanY() / m_size.height(); |
|
117 | qreal y = spanY() / m_size.height(); | |
109 | qreal minY = m_minY; |
|
118 | qreal minY = m_minY; | |
@@ -118,26 +127,24 void LogXYDomain::move(qreal dx, qreal dy) | |||||
118 |
|
127 | |||
119 | QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point) const |
|
128 | QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point) const | |
120 | { |
|
129 | { | |
121 | const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
130 | const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX); | |
122 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
|||
123 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
131 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
124 |
|
132 | |||
125 |
qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - |
|
133 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; | |
126 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); |
|
134 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); | |
127 | return QPointF(x, y); |
|
135 | return QPointF(x, y); | |
128 | } |
|
136 | } | |
129 |
|
137 | |||
130 | QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const |
|
138 | QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
131 | { |
|
139 | { | |
132 | const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
140 | const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX); | |
133 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
|||
134 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
141 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
135 |
|
142 | |||
136 | QVector<QPointF> result; |
|
143 | QVector<QPointF> result; | |
137 | result.resize(vector.count()); |
|
144 | result.resize(vector.count()); | |
138 |
|
145 | |||
139 | for (int i = 0; i < vector.count(); ++i) { |
|
146 | for (int i = 0; i < vector.count(); ++i) { | |
140 |
qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - |
|
147 | qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX; | |
141 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); |
|
148 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); | |
142 | result[i].setX(x); |
|
149 | result[i].setX(x); | |
143 | result[i].setY(y); |
|
150 | result[i].setY(y); | |
@@ -147,10 +154,9 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vect | |||||
147 |
|
154 | |||
148 | QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const |
|
155 | QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const | |
149 | { |
|
156 | { | |
150 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
157 | const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX); | |
151 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
|||
152 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
158 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
153 |
qreal x = qPow(m_logBaseX, left |
|
159 | qreal x = qPow(m_logBaseX, m_logLeftX + point.x() / deltaX); | |
154 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
160 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; | |
155 | return QPointF(x, y); |
|
161 | return QPointF(x, y); | |
156 | } |
|
162 | } | |
@@ -182,8 +188,10 bool LogXYDomain::detachAxis(QAbstractAxis* axis) | |||||
182 | void LogXYDomain::handleHorizontalAxisBaseChanged(qreal baseX) |
|
188 | void LogXYDomain::handleHorizontalAxisBaseChanged(qreal baseX) | |
183 | { |
|
189 | { | |
184 | m_logBaseX = baseX; |
|
190 | m_logBaseX = baseX; | |
185 |
|
|
191 | qreal logMinX = log10(m_minX) / log10(m_logBaseX); | |
186 |
|
|
192 | qreal logMaxX = log10(m_maxX) / log10(m_logBaseX); | |
|
193 | m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX; | |||
|
194 | m_logRightX = logMinX > logMaxX ? logMinX : logMaxX; | |||
187 | emit updated(); |
|
195 | emit updated(); | |
188 | } |
|
196 | } | |
189 |
|
197 |
@@ -65,8 +65,8 public Q_SLOTS: | |||||
65 | void handleHorizontalAxisBaseChanged(qreal baseX); |
|
65 | void handleHorizontalAxisBaseChanged(qreal baseX); | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 |
qreal m_log |
|
68 | qreal m_logLeftX; | |
69 |
qreal m_log |
|
69 | qreal m_logRightX; | |
70 | qreal m_logBaseX; |
|
70 | qreal m_logBaseX; | |
71 | }; |
|
71 | }; | |
72 |
|
72 |
@@ -27,8 +27,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
27 |
|
27 | |||
28 | XLogYDomain::XLogYDomain(QObject *parent) |
|
28 | XLogYDomain::XLogYDomain(QObject *parent) | |
29 | : AbstractDomain(parent), |
|
29 | : AbstractDomain(parent), | |
30 |
m_log |
|
30 | m_logLeftY(0), | |
31 |
m_log |
|
31 | m_logRightY(1), | |
32 | m_logBaseY(10) |
|
32 | m_logBaseY(10) | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
@@ -54,8 +54,10 void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||||
54 | m_minY = minY; |
|
54 | m_minY = minY; | |
55 | m_maxY = maxY; |
|
55 | m_maxY = maxY; | |
56 | axisYChanged = true; |
|
56 | axisYChanged = true; | |
57 |
|
|
57 | qreal logMinY = log10(m_minY) / log10(m_logBaseY); | |
58 |
|
|
58 | qreal logMaxY = log10(m_maxY) / log10(m_logBaseY); | |
|
59 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; | |||
|
60 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; | |||
59 | if(!m_signalsBlocked) |
|
61 | if(!m_signalsBlocked) | |
60 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
62 | emit rangeVerticalChanged(m_minY, m_maxY); | |
61 | } |
|
63 | } | |
@@ -73,10 +75,12 void XLogYDomain::zoomIn(const QRectF &rect) | |||||
73 | maxX = minX + dx * rect.right(); |
|
75 | maxX = minX + dx * rect.right(); | |
74 | minX = minX + dx * rect.left(); |
|
76 | minX = minX + dx * rect.left(); | |
75 |
|
77 | |||
76 |
qreal |
|
78 | qreal logLeftY = m_logRightY - rect.bottom() * (m_logRightY - m_logLeftY) / m_size.height(); | |
77 |
qreal |
|
79 | qreal logRightY = m_logRightY - rect.top() * (m_logRightY - m_logLeftY) / m_size.height(); | |
78 |
qreal |
|
80 | qreal leftY = qPow(m_logBaseY, logLeftY); | |
79 |
qreal |
|
81 | qreal rightY = qPow(m_logBaseY, logRightY); | |
|
82 | qreal minY = leftY < rightY ? leftY : rightY; | |||
|
83 | qreal maxY = leftY > rightY ? leftY : rightY; | |||
80 |
|
84 | |||
81 | setRange(minX, maxX, minY, maxY); |
|
85 | setRange(minX, maxX, minY, maxY); | |
82 | } |
|
86 | } | |
@@ -90,11 +94,13 void XLogYDomain::zoomOut(const QRectF &rect) | |||||
90 | minX = maxX - dx * rect.right(); |
|
94 | minX = maxX - dx * rect.right(); | |
91 | maxX = minX + dx * m_size.width(); |
|
95 | maxX = minX + dx * m_size.width(); | |
92 |
|
96 | |||
93 |
qreal |
|
97 | const qreal factorY = m_size.height() / rect.height(); | |
94 |
qreal newLogMinY = m_log |
|
98 | qreal newLogMinY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 - factorY); | |
95 |
qreal newLogMaxY = m_log |
|
99 | qreal newLogMaxY = m_logLeftY + (m_logRightY - m_logLeftY) / 2 * (1 + factorY); | |
96 |
qreal |
|
100 | qreal leftY = qPow(m_logBaseY, newLogMinY); | |
97 |
qreal |
|
101 | qreal rightY = qPow(m_logBaseY, newLogMaxY); | |
|
102 | qreal minY = leftY < rightY ? leftY : rightY; | |||
|
103 | qreal maxY = leftY > rightY ? leftY : rightY; | |||
98 |
|
104 | |||
99 | setRange(minX, maxX, minY, maxY); |
|
105 | setRange(minX, maxX, minY, maxY); | |
100 | } |
|
106 | } | |
@@ -110,36 +116,36 void XLogYDomain::move(qreal dx, qreal dy) | |||||
110 | maxX = maxX + x * dx; |
|
116 | maxX = maxX + x * dx; | |
111 | } |
|
117 | } | |
112 |
|
118 | |||
113 |
qreal stepY = dy * |
|
119 | qreal stepY = dy * (m_logRightY - m_logLeftY) / m_size.height(); | |
114 |
qreal |
|
120 | qreal leftY = qPow(m_logBaseY, m_logLeftY + stepY); | |
115 |
qreal |
|
121 | qreal rightY = qPow(m_logBaseY, m_logRightY + stepY); | |
|
122 | qreal minY = leftY < rightY ? leftY : rightY; | |||
|
123 | qreal maxY = leftY > rightY ? leftY : rightY; | |||
116 |
|
124 | |||
117 | setRange(minX, maxX, minY, maxY); |
|
125 | setRange(minX, maxX, minY, maxY); | |
118 | } |
|
126 | } | |
119 |
|
127 | |||
120 | QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point) const |
|
128 | QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point) const | |
121 | { |
|
129 | { | |
122 | const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
|||
123 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
130 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
124 |
const qreal deltaY = m_size.height() / qAbs(m_log |
|
131 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); | |
125 |
|
132 | |||
126 | qreal x = (point.x() - m_minX) * deltaX; |
|
133 | qreal x = (point.x() - m_minX) * deltaX; | |
127 |
qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - |
|
134 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); | |
128 | return QPointF(x, y); |
|
135 | return QPointF(x, y); | |
129 | } |
|
136 | } | |
130 |
|
137 | |||
131 | QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const |
|
138 | QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
132 | { |
|
139 | { | |
133 | const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
|||
134 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
140 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
135 |
const qreal deltaY = m_size.height() / qAbs(m_log |
|
141 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); | |
136 |
|
142 | |||
137 | QVector<QPointF> result; |
|
143 | QVector<QPointF> result; | |
138 | result.resize(vector.count()); |
|
144 | result.resize(vector.count()); | |
139 |
|
145 | |||
140 | for (int i = 0; i < vector.count(); ++i) { |
|
146 | for (int i = 0; i < vector.count(); ++i) { | |
141 | qreal x = (vector[i].x() - m_minX) * deltaX; |
|
147 | qreal x = (vector[i].x() - m_minX) * deltaX; | |
142 |
qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - |
|
148 | qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height(); | |
143 | result[i].setX(x); |
|
149 | result[i].setX(x); | |
144 | result[i].setY(y); |
|
150 | result[i].setY(y); | |
145 | } |
|
151 | } | |
@@ -149,10 +155,9 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vect | |||||
149 | QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const |
|
155 | QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const | |
150 | { |
|
156 | { | |
151 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
157 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
152 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
158 | const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY); | |
153 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
|||
154 | qreal x = point.x() / deltaX + m_minX; |
|
159 | qreal x = point.x() / deltaX + m_minX; | |
155 |
qreal y = qPow(m_logBaseY, left |
|
160 | qreal y = qPow(m_logBaseY, m_logLeftY + (m_size.height() - point.y()) / deltaY); | |
156 | return QPointF(x, y); |
|
161 | return QPointF(x, y); | |
157 | } |
|
162 | } | |
158 |
|
163 | |||
@@ -180,8 +185,10 bool XLogYDomain::detachAxis(QAbstractAxis* axis) | |||||
180 | void XLogYDomain::handleVerticalAxisBaseChanged(qreal baseY) |
|
185 | void XLogYDomain::handleVerticalAxisBaseChanged(qreal baseY) | |
181 | { |
|
186 | { | |
182 | m_logBaseY = baseY; |
|
187 | m_logBaseY = baseY; | |
183 |
|
|
188 | qreal logMinY = log10(m_minY) / log10(m_logBaseY); | |
184 |
|
|
189 | qreal logMaxY = log10(m_maxY) / log10(m_logBaseY); | |
|
190 | m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY; | |||
|
191 | m_logRightY = logMinY > logMaxY ? logMinY : logMaxY; | |||
185 | emit updated(); |
|
192 | emit updated(); | |
186 | } |
|
193 | } | |
187 |
|
194 |
@@ -65,8 +65,8 public Q_SLOTS: | |||||
65 | void handleVerticalAxisBaseChanged(qreal baseY); |
|
65 | void handleVerticalAxisBaseChanged(qreal baseY); | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 |
qreal m_log |
|
68 | qreal m_logLeftY; | |
69 |
qreal m_log |
|
69 | qreal m_logRightY; | |
70 | qreal m_logBaseY; |
|
70 | qreal m_logBaseY; | |
71 | }; |
|
71 | }; | |
72 |
|
72 |
@@ -21,6 +21,7 SUBDIRS += \ | |||||
21 | qhorizontalstackedbarseries \ |
|
21 | qhorizontalstackedbarseries \ | |
22 | qhorizontalpercentbarseries \ |
|
22 | qhorizontalpercentbarseries \ | |
23 | qvalueaxis \ |
|
23 | qvalueaxis \ | |
|
24 | qlogvalueaxis \ | |||
24 | qcategoryaxis \ |
|
25 | qcategoryaxis \ | |
25 | qbarcategoryaxis \ |
|
26 | qbarcategoryaxis \ | |
26 | domain \ |
|
27 | domain \ |
General Comments 0
You need to be logged in to leave comments.
Login now