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