##// END OF EJS Templates
bugfix signals not reconnected when domain changed
Michal Klocek -
r2292:29ed1b505c34
parent child
Show More
@@ -1,481 +1,486
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdataset_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qchart.h"
24 24 #include "qchart_p.h"
25 25 #include "qvalueaxis.h"
26 26 #include "qbarcategoryaxis.h"
27 27 #include "qvalueaxis_p.h"
28 28 #include "qcategoryaxis.h"
29 29 #include "qabstractseries_p.h"
30 30 #include "qabstractbarseries.h"
31 31 #include "qstackedbarseries.h"
32 32 #include "qpercentbarseries.h"
33 33 #include "qpieseries.h"
34 34 #include "chartitem_p.h"
35 35 #include "xydomain_p.h"
36 36 #include "xlogydomain_p.h"
37 37 #include "logxydomain_p.h"
38 38 #include "logxlogydomain_p.h"
39 39
40 40 #ifndef QT_ON_ARM
41 41 #include "qdatetimeaxis.h"
42 42 #endif
43 43
44 44 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45 45
46 46 ChartDataSet::ChartDataSet(QChart *chart)
47 47 : QObject(chart),
48 48 m_chart(chart)
49 49 {
50 50
51 51 }
52 52
53 53 ChartDataSet::~ChartDataSet()
54 54 {
55 55 deleteAllSeries();
56 56 deleteAllAxes();
57 57 }
58 58
59 59 /*
60 60 * This method adds series to chartdataset, series ownership is taken from caller.
61 61 */
62 62 void ChartDataSet::addSeries(QAbstractSeries *series)
63 63 {
64 64 if (m_seriesList.contains(series)) {
65 65 qWarning() << QObject::tr("Can not add series. Series already on the chart.");
66 66 return;
67 67 }
68 68
69 69 series->d_ptr->initializeDomain();
70 70 m_seriesList.append(series);
71 71
72 72 series->setParent(this); // take ownership
73 73 series->d_ptr->m_chart = m_chart;
74 74
75 75 emit seriesAdded(series);
76 76 }
77 77
78 78 /*
79 79 * This method adds axis to chartdataset, axis ownership is taken from caller.
80 80 */
81 81 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
82 82 {
83 83 if (m_axisList.contains(axis)) {
84 84 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
85 85 return;
86 86 }
87 87
88 88 axis->d_ptr->setAlignment(aligment);
89 89
90 90 if(!axis->alignment()) {
91 91 qWarning()<< QObject::tr("No alignment specified !");
92 92 return;
93 93 };
94 94
95 95 QSharedPointer<AbstractDomain> domain(new XYDomain());
96 96 axis->d_ptr->initializeDomain(domain.data());
97 97
98 98 axis->setParent(this);
99 99 axis->d_ptr->m_chart = m_chart;
100 100 m_axisList.append(axis);
101 101
102 102 emit axisAdded(axis);
103 103 }
104 104
105 105 /*
106 106 * This method removes series form chartdataset, series ownership is passed back to caller.
107 107 */
108 108 void ChartDataSet::removeSeries(QAbstractSeries *series)
109 109 {
110 110
111 111 if (! m_seriesList.contains(series)) {
112 112 qWarning() << QObject::tr("Can not remove series. Series not found on the chart.");
113 113 return;
114 114 }
115 115
116 116 emit seriesRemoved(series);
117 117 m_seriesList.removeAll(series);
118 118
119 119 series->setParent(0);
120 120 series->d_ptr->m_chart = 0;
121 121 series->d_ptr->m_domain.reset(0);
122 122
123 123 QList<QAbstractAxis*> axes = series->d_ptr->m_axes;
124 124
125 125 foreach(QAbstractAxis* axis, axes) {
126 126 axis->d_ptr->m_series.removeAll(series);
127 127 series->d_ptr->m_axes.removeAll(axis);
128 128 }
129 129
130 130 }
131 131
132 132 /*
133 133 * This method removes axis form chartdataset, series ownership is passed back to caller.
134 134 */
135 135 void ChartDataSet::removeAxis(QAbstractAxis *axis)
136 136 {
137 137 if (! m_axisList.contains(axis)) {
138 138 qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart.");
139 139 return;
140 140 }
141 141
142 142 emit axisRemoved(axis);
143 143 m_axisList.removeAll(axis);
144 144
145 145 axis->setParent(0);
146 146 axis->d_ptr->m_chart = 0;
147 147
148 148 QList<QAbstractSeries*> series = axis->d_ptr->m_series;
149 149
150 150 foreach(QAbstractSeries* s, series) {
151 151 s->d_ptr->m_axes.removeAll(axis);
152 152 axis->d_ptr->m_series.removeAll(s);
153 153 }
154 154 }
155 155
156 156 /*
157 157 * This method attaches axis to series, return true if success.
158 158 */
159 159 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
160 160 {
161 161 Q_ASSERT(series);
162 162 Q_ASSERT(axis);
163 163
164 164 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
165 165 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
166 166
167 167 if (!m_seriesList.contains(series)) {
168 168 qWarning() << QObject::tr("Can not find series on the chart.");
169 169 return false;
170 170 }
171 171
172 172 if (axis && !m_axisList.contains(axis)) {
173 173 qWarning() << QObject::tr("Can not find axis on the chart.");
174 174 return false;
175 175 }
176 176
177 177 if (attachedAxisList.contains(axis)) {
178 178 qWarning() << QObject::tr("Axis already attached to series.");
179 179 return false;
180 180 }
181 181
182 182 if (attachedSeriesList.contains(series)) {
183 183 qWarning() << QObject::tr("Axis already attached to series.");
184 184 return false;
185 185 }
186 186
187 187 AbstractDomain* domain = series->d_ptr->domain();
188 188 AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis);
189 189
190 190 if(type == AbstractDomain::UndefinedDomain) return false;
191 191
192 192 if(domain->type()!=type){
193 193 domain = createDomain(type);
194 194 }
195 195
196 196 if(!domain) return false;
197 197
198 198 if(!domain->attachAxis(axis)) return false;
199 199
200 series->d_ptr->m_axes<<axis;
201 axis->d_ptr->m_series<<series;
202
203 200 if(domain!=series->d_ptr->domain()){
201 foreach(QAbstractAxis* axis,series->d_ptr->m_axes){
202 series->d_ptr->domain()->detachAxis(axis);
203 domain->attachAxis(axis);
204 }
204 205 series->d_ptr->setDomain(domain);
205 206 series->d_ptr->initializeDomain();
206 207 }
208
209 series->d_ptr->m_axes<<axis;
210 axis->d_ptr->m_series<<series;
211
207 212 series->d_ptr->initializeAxes();
208 213 axis->d_ptr->initializeDomain(domain);
209 214
210 215 return true;
211 216 }
212 217
213 218 /*
214 219 * This method detaches axis to series, return true if success.
215 220 */
216 221 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
217 222 {
218 223 Q_ASSERT(series);
219 224 Q_ASSERT(axis);
220 225
221 226 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
222 227 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
223 228 AbstractDomain* domain = series->d_ptr->domain();
224 229
225 230 if (!m_seriesList.contains(series)) {
226 231 qWarning() << QObject::tr("Can not find series on the chart.");
227 232 return false;
228 233 }
229 234
230 235 if (axis && !m_axisList.contains(axis)) {
231 236 qWarning() << QObject::tr("Can not find axis on the chart.");
232 237 return false;
233 238 }
234 239
235 240 if (!attachedAxisList.contains(axis)) {
236 241 qWarning() << QObject::tr("Axis not attached to series.");
237 242 return false;
238 243 }
239 244
240 245 Q_ASSERT(axis->d_ptr->m_series.contains(series));
241 246
242 247 domain->detachAxis(axis);
243 248 series->d_ptr->m_axes.removeAll(axis);
244 249 axis->d_ptr->m_series.removeAll(series);
245 250
246 251 return true;
247 252 }
248 253
249 254 void ChartDataSet::createDefaultAxes()
250 255 {
251 256 if (m_seriesList.isEmpty())
252 257 return;
253 258
254 259 QAbstractAxis::AxisTypes typeX(0);
255 260 QAbstractAxis::AxisTypes typeY(0);
256 261
257 262 // Remove possibly existing axes
258 263 deleteAllAxes();
259 264
260 265 Q_ASSERT(m_axisList.isEmpty());
261 266
262 267 // Select the required axis x and axis y types based on the types of the current series
263 268 foreach(QAbstractSeries* s, m_seriesList) {
264 269 typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal);
265 270 typeY |= s->d_ptr->defaultAxisType(Qt::Vertical);
266 271 }
267 272
268 273 // Create the axes of the types selected
269 274 createAxes(typeX, Qt::Horizontal);
270 275 createAxes(typeY, Qt::Vertical);
271 276
272 277 }
273 278
274 279 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation)
275 280 {
276 281 QAbstractAxis *axis = 0;
277 282 //decide what axis should be created
278 283
279 284 switch (type) {
280 285 case QAbstractAxis::AxisTypeValue:
281 286 axis = new QValueAxis(this);
282 287 break;
283 288 case QAbstractAxis::AxisTypeBarCategory:
284 289 axis = new QBarCategoryAxis(this);
285 290 break;
286 291 case QAbstractAxis::AxisTypeCategory:
287 292 axis = new QCategoryAxis(this);
288 293 break;
289 294 #ifndef Q_WS_QWS
290 295 case QAbstractAxis::AxisTypeDateTime:
291 296 axis = new QDateTimeAxis(this);
292 297 break;
293 298 #endif
294 299 default:
295 300 axis = 0;
296 301 break;
297 302 }
298 303
299 304 if (axis) {
300 305 //create one axis for all
301 306
302 307 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
303 308
304 309 foreach(QAbstractSeries *s, m_seriesList) {
305 310 attachAxis(s,axis);
306 311 }
307 312
308 313 }
309 314 else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
310 315 //create separate axis
311 316 foreach(QAbstractSeries *s, m_seriesList) {
312 317 QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation);
313 318 if(axis) {
314 319 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
315 320 attachAxis(s,axis);
316 321 }
317 322 }
318 323 }
319 324 }
320 325
321 326 void ChartDataSet::deleteAllSeries()
322 327 {
323 328 foreach (QAbstractSeries *s , m_seriesList){
324 329 removeSeries(s);
325 330 delete s;
326 331 }
327 332 Q_ASSERT(m_seriesList.count() == 0);
328 333 }
329 334
330 335 void ChartDataSet::deleteAllAxes()
331 336 {
332 337 foreach (QAbstractAxis *a , m_axisList){
333 338 removeAxis(a);
334 339 delete a;
335 340 }
336 341 Q_ASSERT(m_axisList.count() == 0);
337 342 }
338 343
339 344 void ChartDataSet::zoomInDomain(const QRectF &rect)
340 345 {
341 346 QList<AbstractDomain*> domains;
342 347 foreach(QAbstractSeries *s, m_seriesList) {
343 348 AbstractDomain* domain = s->d_ptr->domain();
344 349 s->d_ptr->m_domain->blockRangeSignals(true);
345 350 domains<<domain;
346 351 }
347 352
348 353 foreach(AbstractDomain *domain, domains)
349 354 domain->zoomIn(rect);
350 355
351 356 foreach(AbstractDomain *domain, domains)
352 357 domain->blockRangeSignals(false);
353 358 }
354 359
355 360 void ChartDataSet::zoomOutDomain(const QRectF &rect)
356 361 {
357 362 QList<AbstractDomain*> domains;
358 363 foreach(QAbstractSeries *s, m_seriesList) {
359 364 AbstractDomain* domain = s->d_ptr->domain();
360 365 s->d_ptr->m_domain->blockRangeSignals(true);
361 366 domains<<domain;
362 367 }
363 368
364 369 foreach(AbstractDomain *domain, domains)
365 370 domain->zoomOut(rect);
366 371
367 372 foreach(AbstractDomain *domain, domains)
368 373 domain->blockRangeSignals(false);
369 374 }
370 375
371 376 void ChartDataSet::scrollDomain(qreal dx, qreal dy)
372 377 {
373 378 QList<AbstractDomain*> domains;
374 379 foreach(QAbstractSeries *s, m_seriesList) {
375 380 AbstractDomain* domain = s->d_ptr->domain();
376 381 s->d_ptr->m_domain->blockRangeSignals(true);
377 382 domains<<domain;
378 383 }
379 384
380 385 foreach(AbstractDomain *domain, domains)
381 386 domain->move(dx, dy);
382 387
383 388 foreach(AbstractDomain *domain, domains)
384 389 domain->blockRangeSignals(false);
385 390 }
386 391
387 392 QList<QAbstractAxis*> ChartDataSet::axes() const
388 393 {
389 394 return m_axisList;
390 395 }
391 396
392 397 QList<QAbstractSeries *> ChartDataSet::series() const
393 398 {
394 399 return m_seriesList;
395 400 }
396 401
397 402 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes)
398 403 {
399 404 enum Type {
400 405 Undefined = 0,
401 406 LogType = 0x1,
402 407 ValueType = 0x2
403 408 };
404 409
405 410 int horizontal(Undefined);
406 411 int vertical(Undefined);
407 412
408 413 foreach(QAbstractAxis* axis, axes)
409 414 {
410 415 switch(axis->type()) {
411 416 case QAbstractAxis::AxisTypeLogValue:
412 417
413 418 if(axis->orientation()==Qt::Horizontal) {
414 419 horizontal|=LogType;
415 420 }
416 421 if(axis->orientation()==Qt::Vertical) {
417 422 vertical|=LogType;
418 423 }
419 424
420 425 break;
421 426 case QAbstractAxis::AxisTypeValue:
422 427 case QAbstractAxis::AxisTypeBarCategory:
423 428 case QAbstractAxis::AxisTypeCategory:
424 429 case QAbstractAxis::AxisTypeDateTime:
425 430 if(axis->orientation()==Qt::Horizontal) {
426 431 horizontal|=ValueType;
427 432 }
428 433 if(axis->orientation()==Qt::Vertical) {
429 434 vertical|=ValueType;
430 435 }
431 436 break;
432 437 default:
433 438 qWarning()<<"Undefined type";
434 439 break;
435 440 }
436 441 }
437 442
438 443 if(vertical==Undefined) vertical=ValueType;
439 444 if(horizontal==Undefined) horizontal=ValueType;
440 445
441 446 if(vertical==ValueType && horizontal== ValueType) {
442 447 return AbstractDomain::XYDomain;
443 448 }
444 449
445 450 if(vertical==LogType && horizontal== ValueType) {
446 451 return AbstractDomain::XLogYDomain;
447 452 }
448 453
449 454 if(vertical==ValueType && horizontal== LogType) {
450 455 return AbstractDomain::LogXYDomain;
451 456 }
452 457
453 458 if(vertical==LogType && horizontal== LogType) {
454 459 return AbstractDomain::LogXLogYDomain;
455 460 }
456 461
457 462 return AbstractDomain::UndefinedDomain;
458 463 }
459 464
460 465
461 466 //refactor create factory
462 467 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
463 468 {
464 469 switch(type)
465 470 {
466 471 case AbstractDomain::LogXLogYDomain:
467 472 return new LogXLogYDomain();
468 473 case AbstractDomain::XYDomain:
469 474 return new XYDomain();
470 475 case AbstractDomain::XLogYDomain:
471 476 return new XLogYDomain();
472 477 case AbstractDomain::LogXYDomain:
473 478 return new LogXYDomain();
474 479 default:
475 480 return 0;
476 481 }
477 482 }
478 483
479 484 #include "moc_chartdataset_p.cpp"
480 485
481 486 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,211 +1,209
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "xlogydomain_p.h"
22 22 #include "qabstractaxis_p.h"
23 23 #include "qlogvalueaxis.h"
24 24 #include <qmath.h>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 XLogYDomain::XLogYDomain(QObject *parent)
29 29 : AbstractDomain(parent),
30 30 m_logMinY(0),
31 31 m_logMaxY(1),
32 32 m_logBaseY(10)
33 33 {
34 34 }
35 35
36 36 XLogYDomain::~XLogYDomain()
37 37 {
38 38 }
39 39
40 40 void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
41 41 {
42 42 bool axisXChanged = false;
43 43 bool axisYChanged = false;
44 44
45 45 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
46 46 m_minX = minX;
47 47 m_maxX = maxX;
48 48 axisXChanged = true;
49 49 if(!m_signalsBlocked)
50 50 emit rangeHorizontalChanged(m_minX, m_maxX);
51 51 }
52 52
53 53 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
54 54 m_minY = minY;
55 55 m_maxY = maxY;
56 56 axisYChanged = true;
57 57 m_logMinY = log10(m_minY) / log10(m_logBaseY);
58 58 m_logMaxY = log10(m_maxY) / log10(m_logBaseY);
59 59 if(!m_signalsBlocked)
60 60 emit rangeVerticalChanged(m_minY, m_maxY);
61 61 }
62 62
63 63 if (axisXChanged || axisYChanged)
64 64 emit updated();
65 65 }
66 66
67 67 void XLogYDomain::zoomIn(const QRectF &rect)
68 68 {
69 69 qreal dx = spanX() / m_size.width();
70 70 qreal maxX = m_maxX;
71 71 qreal minX = m_minX;
72 72
73 73 maxX = minX + dx * rect.right();
74 74 minX = minX + dx * rect.left();
75 75
76 76 qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height();
77 77 qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height();
78 78 qreal minY = qPow(m_logBaseY, newLogMinY);
79 79 qreal maxY = qPow(m_logBaseY, newLogMaxY);
80 80
81 81 setRange(minX, maxX, minY, maxY);
82 82 }
83 83
84 84 void XLogYDomain::zoomOut(const QRectF &rect)
85 85 {
86 86 qreal dx = spanX() / rect.width();
87 87 qreal maxX = m_maxX;
88 88 qreal minX = m_minX;
89 89
90 90 minX = maxX - dx * rect.right();
91 91 maxX = minX + dx * m_size.width();
92 92
93 93 qreal ratioY = m_size.height()/rect.height();
94 94 qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY;
95 95 qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY;
96 96 qreal minY = qPow(m_logBaseY, newLogMinY);
97 97 qreal maxY = qPow(m_logBaseY, newLogMaxY);
98 98
99 99 setRange(minX, maxX, minY, maxY);
100 100 }
101 101
102 102 void XLogYDomain::move(qreal dx, qreal dy)
103 103 {
104 104 qreal x = spanX() / m_size.width();
105 105 qreal maxX = m_maxX;
106 106 qreal minX = m_minX;
107 107
108 108 if (dx != 0) {
109 109 minX = minX + x * dx;
110 110 maxX = maxX + x * dx;
111 111 }
112 112
113 113 qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height();
114 114 qreal minY = qPow(m_logBaseY, m_logMinY + stepY);
115 115 qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY);
116 116
117 117 setRange(minX, maxX, minY, maxY);
118 118 }
119 119
120 120 QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point) const
121 121 {
122 122 const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
123 123 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
124 124 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
125 125
126 126 qreal x = (point.x() - m_minX) * deltaX;
127 127 qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height();
128 128 return QPointF(x, y);
129 129 }
130 130
131 131 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
132 132 {
133 133 const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
134 134 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
135 135 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
136 136
137 137 QVector<QPointF> result;
138 138 result.resize(vector.count());
139 139
140 140 for (int i = 0; i < vector.count(); ++i) {
141 141 qreal x = (vector[i].x() - m_minX) * deltaX;
142 142 qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height();
143 143 result[i].setX(x);
144 144 result[i].setY(y);
145 145 }
146 146 return result;
147 147 }
148 148
149 149 QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const
150 150 {
151 151 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
152 152 const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY;
153 153 const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY);
154 154 qreal x = point.x() / deltaX + m_minX;
155 155 qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY);
156 156 return QPointF(x, y);
157 157 }
158 158
159 159 bool XLogYDomain::attachAxis(QAbstractAxis* axis)
160 160 {
161 AbstractDomain::attachAxis(axis);
162 161 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
163 162
164 163 if(logAxis && logAxis->orientation()==Qt::Vertical)
165 164 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
166 165
167 return true;
166 return AbstractDomain::attachAxis(axis);
168 167 }
169 168
170 169 bool XLogYDomain::detachAxis(QAbstractAxis* axis)
171 170 {
172 AbstractDomain::detachAxis(axis);
173 171 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
174 172
175 173 if(logAxis && logAxis->orientation()==Qt::Vertical)
176 174 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
177 175
178 return true;
176 return AbstractDomain::detachAxis(axis);
179 177 }
180 178
181 179 void XLogYDomain::handleVerticalAxisBaseChanged(qreal baseY)
182 180 {
183 181 m_logBaseY = baseY;
184 182 }
185 183
186 184 // operators
187 185
188 186 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2)
189 187 {
190 188 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
191 189 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
192 190 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
193 191 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
194 192 }
195 193
196 194
197 195 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2)
198 196 {
199 197 return !(domain1 == domain2);
200 198 }
201 199
202 200
203 201 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain)
204 202 {
205 203 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
206 204 return dbg.maybeSpace();
207 205 }
208 206
209 207 #include "moc_xlogydomain_p.cpp"
210 208
211 209 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now