##// END OF EJS Templates
Refactors Domain and Axis...
Michal Klocek -
r1698:da7242791c36
parent child
Show More
@@ -0,0 +1,15
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
3
4 SOURCES += \
5 $$PWD/chartcategoriesaxisx.cpp \
6 $$PWD/chartcategoriesaxisy.cpp \
7 $$PWD/qbarcategoriesaxis.cpp
8
9 PRIVATE_HEADERS += \
10 $$PWD/chartcategoriesaxisx_p.h \
11 $$PWD/chartcategoriesaxisy_p.h \
12 $$PWD/qbarcategoriesaxis_p.h
13
14 PUBLIC_HEADERS += \
15 $$PWD/qbarcategoriesaxis.h No newline at end of file
@@ -0,0 +1,12
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
3
4 SOURCES += \
5 $$PWD/qintervalsaxis.cpp
6
7
8 PRIVATE_HEADERS += \
9 $$PWD/qintervalaxis_p.h
10
11 PUBLIC_HEADERS += \
12 $$PWD/qintervalaxis.h
@@ -0,0 +1,15
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
3
4 SOURCES += \
5 $$PWD/chartvaluesaxisx.cpp \
6 $$PWD/chartvaluesaxisy.cpp \
7 $$PWD/qvaluesaxis.cpp \
8
9 PRIVATE_HEADERS += \
10 $$PWD/chartvaluesaxisx_p.h \
11 $$PWD/chartvaluesaxisy_p.h \
12 $$PWD/qvaluesaxis_p.h
13
14 PUBLIC_HEADERS += \
15 $$PWD/qvaluesaxis.h No newline at end of file
@@ -23,6 +23,7
23 #include "qareaseries_p.h"
23 #include "qareaseries_p.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25 #include "chartpresenter_p.h"
25 #include "chartpresenter_p.h"
26 #include "domain_p.h"
26 #include <QPainter>
27 #include <QPainter>
27 #include <QGraphicsSceneMouseEvent>
28 #include <QGraphicsSceneMouseEvent>
28 #include <QDebug>
29 #include <QDebug>
@@ -41,8 +42,9 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter)
41 {
42 {
42 setZValue(ChartPresenter::LineChartZValue);
43 setZValue(ChartPresenter::LineChartZValue);
43 m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter);
44 m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter);
44 if (m_series->lowerSeries())
45 if (m_series->lowerSeries()){
45 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
46 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
47 }
46
48
47 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
49 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
48 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
50 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
@@ -100,11 +102,14 void AreaChartItem::handleUpdated()
100 update();
102 update();
101 }
103 }
102
104
103 void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
105 void AreaChartItem::handleDomainUpdated()
104 {
106 {
105 m_upper->handleDomainChanged(minX,maxX,minY,maxY);
107 m_upper->setDomain(domain());
106 if (m_lower)
108 m_upper->handleDomainUpdated();
107 m_lower->handleDomainChanged(minX,maxX,minY,maxY);
109 if (m_lower){
110 m_lower->setDomain(domain());
111 m_lower->handleDomainUpdated();
112 }
108 }
113 }
109
114
110 void AreaChartItem::handleGeometryChanged(const QRectF &rect)
115 void AreaChartItem::handleGeometryChanged(const QRectF &rect)
@@ -64,7 +64,7 Q_SIGNALS:
64
64
65 public Q_SLOTS:
65 public Q_SLOTS:
66 void handleUpdated();
66 void handleUpdated();
67 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
67 void handleDomainUpdated();
68 void handleGeometryChanged(const QRectF &size);
68 void handleGeometryChanged(const QRectF &size);
69
69
70 private:
70 private:
@@ -321,8 +321,6 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
321 qreal minY(domain.minY());
321 qreal minY(domain.minY());
322 qreal maxX(domain.maxX());
322 qreal maxX(domain.maxX());
323 qreal maxY(domain.maxY());
323 qreal maxY(domain.maxY());
324 int tickXCount(domain.tickXCount());
325 int tickYCount(domain.tickYCount());
326
324
327 QLineSeries* upperSeries = q->upperSeries();
325 QLineSeries* upperSeries = q->upperSeries();
328 QLineSeries* lowerSeries = q->lowerSeries();
326 QLineSeries* lowerSeries = q->lowerSeries();
@@ -352,7 +350,7 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
352 maxY = qMax(maxY, y);
350 maxY = qMax(maxY, y);
353 }}
351 }}
354
352
355 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
353 domain.setRange(minX,maxX,minY,maxY);
356 }
354 }
357
355
358 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
356 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
@@ -1,30 +1,16
1 include(valuesaxis/valuesaxis.pri)
2 include(categoriesaxis/categoriesaxis.pri)
3
1 INCLUDEPATH += $$PWD
4 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
5 DEPENDPATH += $$PWD
3
6
4 SOURCES += \
7 SOURCES += \
5 $$PWD/chartaxis.cpp \
8 $$PWD/chartaxis.cpp \
6 $$PWD/chartvaluesaxisx.cpp \
7 $$PWD/chartvaluesaxisy.cpp \
8 $$PWD/chartcategoriesaxisx.cpp \
9 $$PWD/chartcategoriesaxisy.cpp \
10 $$PWD/qbarcategoriesaxis.cpp \
11 # $$PWD/qintervalaxis.cpp \
12 $$PWD/qvaluesaxis.cpp \
13 $$PWD/qabstractaxis.cpp
9 $$PWD/qabstractaxis.cpp
14
10
15 PRIVATE_HEADERS += \
11 PRIVATE_HEADERS += \
16 $$PWD/chartaxis_p.h \
12 $$PWD/chartaxis_p.h \
17 $$PWD/chartvaluesaxisx_p.h \
18 $$PWD/chartvaluesaxisy_p.h \
19 $$PWD/chartcategoriesaxisx_p.h \
20 $$PWD/chartcategoriesaxisy_p.h \
21 $$PWD/qbarcategoriesaxis_p.h \
22 # $$PWD/qintervalaxis_p.h \
23 $$PWD/qvaluesaxis_p.h \
24 $$PWD/qabstractaxis_p.h
13 $$PWD/qabstractaxis_p.h
25
14
26 PUBLIC_HEADERS += \
15 PUBLIC_HEADERS += \
27 $$PWD/qbarcategoriesaxis.h \
28 # $$PWD/qintervalaxis.h \
29 $$PWD/qvaluesaxis.h \
30 $$PWD/qabstractaxis.h
16 $$PWD/qabstractaxis.h
@@ -41,14 +41,14 ChartCategoriesAxisX::~ChartCategoriesAxisX()
41
41
42 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
42 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
43 {
43 {
44 Q_ASSERT(m_ticksCount>=2);
44 Q_ASSERT(m_categoriesAxis->categories().count()>=2);
45
45
46 QVector<qreal> points;
46 QVector<qreal> points;
47 points.resize(m_ticksCount);
47 points.resize(m_categoriesAxis->categories().count());
48
48
49 // TODO: shift logic
49 // TODO: shift logic
50 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
50 const qreal deltaX = m_rect.width()/(m_categoriesAxis->categories().count()-1);
51 for (int i = 0; i < m_ticksCount; ++i) {
51 for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) {
52 int x = i * deltaX + m_rect.left();
52 int x = i * deltaX + m_rect.left();
53 points[i] = x;
53 points[i] = x;
54 }
54 }
1 NO CONTENT: file renamed from src/axis/chartcategoriesaxisx_p.h to src/axis/categoriesaxis/chartcategoriesaxisx_p.h
NO CONTENT: file renamed from src/axis/chartcategoriesaxisx_p.h to src/axis/categoriesaxis/chartcategoriesaxisx_p.h
@@ -41,13 +41,13 ChartCategoriesAxisY::~ChartCategoriesAxisY()
41
41
42 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
42 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
43 {
43 {
44 Q_ASSERT(m_ticksCount>=2);
44 Q_ASSERT(m_categoriesAxis->categories().count()>=2);
45
45
46 QVector<qreal> points;
46 QVector<qreal> points;
47 points.resize(m_ticksCount);
47 points.resize(m_categoriesAxis->categories().count());
48
48
49 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 const qreal deltaY = m_rect.height()/(m_categoriesAxis->categories().count()-1);
50 for (int i = 0; i < m_ticksCount; ++i) {
50 for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) {
51 int y = i * -deltaY + m_rect.bottom();
51 int y = i * -deltaY + m_rect.bottom();
52 points[i] = y;
52 points[i] = y;
53 }
53 }
1 NO CONTENT: file renamed from src/axis/chartcategoriesaxisy_p.h to src/axis/categoriesaxis/chartcategoriesaxisy_p.h
NO CONTENT: file renamed from src/axis/chartcategoriesaxisy_p.h to src/axis/categoriesaxis/chartcategoriesaxisy_p.h
@@ -251,7 +251,12 QString QBarCategoriesAxis::at(int index) const
251 void QBarCategoriesAxis::setMin(const QString& min)
251 void QBarCategoriesAxis::setMin(const QString& min)
252 {
252 {
253 Q_D(QBarCategoriesAxis);
253 Q_D(QBarCategoriesAxis);
254 setRange(min,d->m_maxCategory);
254 if (d->m_minCategory!=min && d->m_categories.contains(min)) {
255 d->m_minCategory = min;
256 d->emitUpdated();
257 emit minChanged(min);
258 }
259
255 }
260 }
256
261
257 /*!
262 /*!
@@ -269,7 +274,12 QString QBarCategoriesAxis::min() const
269 void QBarCategoriesAxis::setMax(const QString& max)
274 void QBarCategoriesAxis::setMax(const QString& max)
270 {
275 {
271 Q_D(QBarCategoriesAxis);
276 Q_D(QBarCategoriesAxis);
272 setRange(d->m_minCategory,max);
277 if (d->m_maxCategory!=max && d->m_categories.contains(max)) {
278 d->m_maxCategory = max;
279 d->emitUpdated();
280 emit maxChanged(max);
281 }
282
273 }
283 }
274
284
275 /*!
285 /*!
@@ -286,40 +296,8 QString QBarCategoriesAxis::max() const
286 */
296 */
287 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
297 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
288 {
298 {
289 Q_D(QBarCategoriesAxis);
299 setMin(minCategory);
290
300 setMax(maxCategory);
291 int minIndex = d->m_categories.indexOf(minCategory);
292 if (minIndex == -1) {
293 return;
294 }
295 int maxIndex = d->m_categories.indexOf(maxCategory);
296 if (maxIndex == -1) {
297 return;
298 }
299
300 if (maxIndex <= minIndex) {
301 // max must be greater than min
302 return;
303 }
304
305 bool changed = false;
306 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
307 d->m_minCategory = minCategory;
308 d->m_min = minIndex;
309 emit minChanged(minCategory);
310 changed = true;
311 }
312
313 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
314 d->m_max = maxIndex;
315 d->m_maxCategory = maxCategory;
316 emit maxChanged(maxCategory);
317 changed = true;
318 }
319
320 if (changed) {
321 d->emitRange();
322 }
323 }
301 }
324
302
325 /*!
303 /*!
@@ -361,17 +339,22 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &ma
361 q->setRange(value1,value2);
339 q->setRange(value1,value2);
362 }
340 }
363
341
364 int QBarCategoriesAxisPrivate::ticksCount() const
342 qreal QBarCategoriesAxisPrivate::min()
343 {
344 //TODO:: cache it
345 return m_categories.indexOf(m_minCategory) + 0.5;
346 }
347
348 qreal QBarCategoriesAxisPrivate::max()
365 {
349 {
366 return m_categories.count()+1;
350 //TODO:: cache it
351 return m_categories.indexOf(m_maxCategory) + 0.5;
367 }
352 }
368
353
369 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
354 void QBarCategoriesAxisPrivate::handleDomainUpdated()
370 {
355 {
371 // Q_Q(QBarCategoriesAxis);
356 // Q_Q(QBarCategoriesAxis);
372 m_min = min;
357
373 m_max = max;
374 m_ticksCount = count;
375 // TODO: causes crash in some situations. added to known issues
358 // TODO: causes crash in some situations. added to known issues
376 /*
359 /*
377 int minIndex = qFloor(min);
360 int minIndex = qFloor(min);
@@ -416,10 +399,12 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
416 }
399 }
417 }
400 }
418
401
402 /*
419 void QBarCategoriesAxisPrivate::emitRange()
403 void QBarCategoriesAxisPrivate::emitRange()
420 {
404 {
421 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
405 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
422 }
406 }
407 */
423
408
424 void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain)
409 void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain)
425 {
410 {
1 NO CONTENT: file renamed from src/axis/qbarcategoriesaxis.h to src/axis/categoriesaxis/qbarcategoriesaxis.h
NO CONTENT: file renamed from src/axis/qbarcategoriesaxis.h to src/axis/categoriesaxis/qbarcategoriesaxis.h
@@ -48,20 +48,15 public:
48 public:
48 public:
49 ChartAxis* createGraphics(ChartPresenter* presenter);
49 ChartAxis* createGraphics(ChartPresenter* presenter);
50 void intializeDomain(Domain* domain);
50 void intializeDomain(Domain* domain);
51 void emitRange();
51 void handleDomainUpdated();
52 qreal min();
53 qreal max();
52
54
53 private:
55 private:
54 //range handling
56 //range handling
55 void setMin(const QVariant &min);
57 void setMin(const QVariant &min);
56 void setMax(const QVariant &max);
58 void setMax(const QVariant &max);
57 void setRange(const QVariant &min, const QVariant &max);
59 void setRange(const QVariant &min, const QVariant &max);
58 int ticksCount() const;
59
60 Q_SIGNALS:
61 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
62
63 public Q_SLOTS:
64 void handleAxisRangeChanged(qreal min, qreal max,int count);
65
60
66 private:
61 private:
67 QStringList m_categories;
62 QStringList m_categories;
@@ -23,6 +23,7
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include "domain_p.h"
26 #include <QPainter>
27 #include <QPainter>
27 #include <QDebug>
28 #include <QDebug>
28 #include <qmath.h>
29 #include <qmath.h>
@@ -38,7 +39,6 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres
38 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
39 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
39 m_min(0),
40 m_min(0),
40 m_max(0),
41 m_max(0),
41 m_ticksCount(0),
42 m_animation(0),
42 m_animation(0),
43 m_minWidth(0),
43 m_minWidth(0),
44 m_minHeight(0)
44 m_minHeight(0)
@@ -54,8 +54,6 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres
54
54
55 QGraphicsSimpleTextItem item;
55 QGraphicsSimpleTextItem item;
56 m_font = item.font();
56 m_font = item.font();
57
58 handleAxisUpdated();
59 }
57 }
60
58
61 ChartAxis::~ChartAxis()
59 ChartAxis::~ChartAxis()
@@ -110,7 +108,7 void ChartAxis::updateLayout(QVector<qreal> &layout)
110 createItems(-diff);
108 createItems(-diff);
111 }
109 }
112
110
113 if( diff!=0) handleAxisUpdated();
111 if(diff<0) handleAxisUpdated();
114
112
115 if (m_animation) {
113 if (m_animation) {
116 switch(presenter()->state()){
114 switch(presenter()->state()){
@@ -244,21 +242,40 void ChartAxis::setGridPen(const QPen &pen)
244
242
245 bool ChartAxis::isEmpty()
243 bool ChartAxis::isEmpty()
246 {
244 {
247 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
245 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max);
248 }
246 }
249
247
250 //handlers
248 void ChartAxis::handleDomainUpdated()
251
252 void ChartAxis::handleAxisCategoriesUpdated()
253 {
249 {
254 if (isEmpty()) return;
250 Domain* domain = qobject_cast<Domain*>(sender());
255 updateLayout(m_layoutVector);
251 qreal min(0);
252 qreal max(0);
253
254 if(m_chartAxis->orientation()==Qt::Horizontal) {
255 min = domain->minX();
256 max = domain->maxX();
257 }
258 else if (m_chartAxis->orientation()==Qt::Vertical)
259 {
260 min = domain->minY();
261 max = domain->maxY();
262 }
263
264 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max))
265 {
266 m_min = min;
267 m_max = max;
268
269 if (!isEmpty()) {
270 QVector<qreal> layout = calculateLayout();
271 updateLayout(layout);
272 }
273 }
256 }
274 }
257
275
258 void ChartAxis::handleAxisUpdated()
276 void ChartAxis::handleAxisUpdated()
259 {
277 {
260
278 if(isEmpty()) return;
261 if (isEmpty()) return;
262
279
263 if (!m_chartAxis->isVisible()) {
280 if (!m_chartAxis->isVisible()) {
264 setAxisOpacity(0);
281 setAxisOpacity(0);
@@ -296,6 +313,7 void ChartAxis::handleAxisUpdated()
296 setShadesOpacity(0);
313 setShadesOpacity(0);
297 }
314 }
298 }
315 }
316
299 setLabelsAngle(m_chartAxis->labelsAngle());
317 setLabelsAngle(m_chartAxis->labelsAngle());
300 setAxisPen(m_chartAxis->axisPen());
318 setAxisPen(m_chartAxis->axisPen());
301 setLabelsPen(m_chartAxis->labelsPen());
319 setLabelsPen(m_chartAxis->labelsPen());
@@ -307,20 +325,6 void ChartAxis::handleAxisUpdated()
307
325
308 }
326 }
309
327
310 void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount)
311 {
312 if (qFuzzyIsNull(min - max) || tickCount < 2)
313 return;
314
315 m_min = min;
316 m_max = max;
317 m_ticksCount= tickCount;
318
319 if (isEmpty()) return;
320 QVector<qreal> layout = calculateLayout();
321 updateLayout(layout);
322 }
323
324 void ChartAxis::handleGeometryChanged(const QRectF &rect)
328 void ChartAxis::handleGeometryChanged(const QRectF &rect)
325 {
329 {
326 if(m_rect != rect)
330 if(m_rect != rect)
@@ -374,7 +378,7 void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,co
374 int count = 0;
378 int count = 0;
375
379
376 // Try to find category for x coordinate
380 // Try to find category for x coordinate
377 while (count < m_ticksCount) {
381 while (count < categories.count()) {
378 if ((x < categories.count()) && (x >= 0)) {
382 if ((x < categories.count()) && (x >= 0)) {
379 labels << categories.at(x);
383 labels << categories.at(x);
380 } else {
384 } else {
@@ -96,8 +96,7 protected:
96
96
97 public Q_SLOTS:
97 public Q_SLOTS:
98 virtual void handleAxisUpdated();
98 virtual void handleAxisUpdated();
99 void handleAxisCategoriesUpdated();
99 virtual void handleDomainUpdated();
100 void handleRangeChanged(qreal min , qreal max,int tickCount);
101 void handleGeometryChanged(const QRectF &size);
100 void handleGeometryChanged(const QRectF &size);
102
101
103 private:
102 private:
@@ -118,7 +117,6 protected:
118 QVector<qreal> m_layoutVector;
117 QVector<qreal> m_layoutVector;
119 qreal m_min;
118 qreal m_min;
120 qreal m_max;
119 qreal m_max;
121 int m_ticksCount;
122 AxisAnimation *m_animation;
120 AxisAnimation *m_animation;
123 qreal m_minWidth;
121 qreal m_minWidth;
124 qreal m_minHeight;
122 qreal m_minHeight;
1 NO CONTENT: file renamed from src/axis/qintervalaxis.cpp to src/axis/intervalsaxis/qintervalaxis.cpp
NO CONTENT: file renamed from src/axis/qintervalaxis.cpp to src/axis/intervalsaxis/qintervalaxis.cpp
1 NO CONTENT: file renamed from src/axis/qintervalaxis.h to src/axis/intervalsaxis/qintervalaxis.h
NO CONTENT: file renamed from src/axis/qintervalaxis.h to src/axis/intervalsaxis/qintervalaxis.h
1 NO CONTENT: file renamed from src/axis/qintervalaxis_p.h to src/axis/intervalsaxis/qintervalaxis_p.h
NO CONTENT: file renamed from src/axis/qintervalaxis_p.h to src/axis/intervalsaxis/qintervalaxis_p.h
@@ -279,7 +279,7 void QAbstractAxis::setAxisPen(const QPen &pen)
279 {
279 {
280 if (d_ptr->m_axisPen!=pen) {
280 if (d_ptr->m_axisPen!=pen) {
281 d_ptr->m_axisPen = pen;
281 d_ptr->m_axisPen = pen;
282 emit d_ptr->updated();
282 d_ptr->emitUpdated();
283 }
283 }
284 }
284 }
285
285
@@ -313,7 +313,7 void QAbstractAxis::setArrowVisible(bool visible)
313 {
313 {
314 if (d_ptr->m_arrowVisible != visible) {
314 if (d_ptr->m_arrowVisible != visible) {
315 d_ptr->m_arrowVisible = visible;
315 d_ptr->m_arrowVisible = visible;
316 emit d_ptr->updated();
316 d_ptr->emitUpdated();
317 emit arrowVisibleChanged(visible);
317 emit arrowVisibleChanged(visible);
318 }
318 }
319 }
319 }
@@ -327,7 +327,7 void QAbstractAxis::setGridLineVisible(bool visible)
327 {
327 {
328 if (d_ptr->m_gridLineVisible != visible) {
328 if (d_ptr->m_gridLineVisible != visible) {
329 d_ptr->m_gridLineVisible = visible;
329 d_ptr->m_gridLineVisible = visible;
330 emit d_ptr->updated();
330 d_ptr->emitUpdated();
331 emit gridVisibleChanged(visible);
331 emit gridVisibleChanged(visible);
332 }
332 }
333 }
333 }
@@ -344,7 +344,7 void QAbstractAxis::setGridLinePen(const QPen &pen)
344 {
344 {
345 if (d_ptr->m_gridLinePen != pen) {
345 if (d_ptr->m_gridLinePen != pen) {
346 d_ptr->m_gridLinePen = pen;
346 d_ptr->m_gridLinePen = pen;
347 emit d_ptr->updated();
347 d_ptr->emitUpdated();
348 }
348 }
349 }
349 }
350
350
@@ -360,7 +360,7 void QAbstractAxis::setLabelsVisible(bool visible)
360 {
360 {
361 if (d_ptr->m_labelsVisible != visible) {
361 if (d_ptr->m_labelsVisible != visible) {
362 d_ptr->m_labelsVisible = visible;
362 d_ptr->m_labelsVisible = visible;
363 emit d_ptr->updated();
363 d_ptr->emitUpdated();
364 emit labelsVisibleChanged(visible);
364 emit labelsVisibleChanged(visible);
365 }
365 }
366 }
366 }
@@ -377,7 +377,7 void QAbstractAxis::setLabelsPen(const QPen &pen)
377 {
377 {
378 if (d_ptr->m_labelsPen != pen) {
378 if (d_ptr->m_labelsPen != pen) {
379 d_ptr->m_labelsPen = pen;
379 d_ptr->m_labelsPen = pen;
380 emit d_ptr->updated();
380 d_ptr->emitUpdated();
381 }
381 }
382 }
382 }
383
383
@@ -396,7 +396,7 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
396 {
396 {
397 if (d_ptr->m_labelsBrush != brush) {
397 if (d_ptr->m_labelsBrush != brush) {
398 d_ptr->m_labelsBrush = brush;
398 d_ptr->m_labelsBrush = brush;
399 emit d_ptr->updated();
399 d_ptr->emitUpdated();
400 }
400 }
401 }
401 }
402
402
@@ -415,7 +415,7 void QAbstractAxis::setLabelsFont(const QFont &font)
415 {
415 {
416 if (d_ptr->m_labelsFont != font) {
416 if (d_ptr->m_labelsFont != font) {
417 d_ptr->m_labelsFont = font;
417 d_ptr->m_labelsFont = font;
418 emit d_ptr->updated();
418 d_ptr->emitUpdated();
419 }
419 }
420 }
420 }
421
421
@@ -431,7 +431,7 void QAbstractAxis::setLabelsAngle(int angle)
431 {
431 {
432 if (d_ptr->m_labelsAngle != angle) {
432 if (d_ptr->m_labelsAngle != angle) {
433 d_ptr->m_labelsAngle = angle;
433 d_ptr->m_labelsAngle = angle;
434 emit d_ptr->updated();
434 d_ptr->emitUpdated();
435 }
435 }
436 }
436 }
437
437
@@ -459,7 +459,7 void QAbstractAxis::setShadesVisible(bool visible)
459 {
459 {
460 if (d_ptr->m_shadesVisible != visible) {
460 if (d_ptr->m_shadesVisible != visible) {
461 d_ptr->m_shadesVisible = visible;
461 d_ptr->m_shadesVisible = visible;
462 emit d_ptr->updated();
462 d_ptr->emitUpdated();
463 emit shadesVisibleChanged(visible);
463 emit shadesVisibleChanged(visible);
464 }
464 }
465 }
465 }
@@ -476,7 +476,7 void QAbstractAxis::setShadesPen(const QPen &pen)
476 {
476 {
477 if (d_ptr->m_shadesPen != pen) {
477 if (d_ptr->m_shadesPen != pen) {
478 d_ptr->m_shadesPen = pen;
478 d_ptr->m_shadesPen = pen;
479 emit d_ptr->updated();
479 d_ptr->emitUpdated();
480 }
480 }
481 }
481 }
482
482
@@ -495,7 +495,7 void QAbstractAxis::setShadesBrush(const QBrush &brush)
495 {
495 {
496 if (d_ptr->m_shadesBrush != brush) {
496 if (d_ptr->m_shadesBrush != brush) {
497 d_ptr->m_shadesBrush = brush;
497 d_ptr->m_shadesBrush = brush;
498 emit d_ptr->updated();
498 d_ptr->emitUpdated();
499 emit shadesColorChanged(brush.color());
499 emit shadesColorChanged(brush.color());
500 }
500 }
501 }
501 }
@@ -545,8 +545,8 void QAbstractAxis::setVisible(bool visible)
545 {
545 {
546 if(d_ptr->m_visible!=visible){
546 if(d_ptr->m_visible!=visible){
547 d_ptr->m_visible=visible;
547 d_ptr->m_visible=visible;
548 d_ptr->emitUpdated();
548 emit visibleChanged(visible);
549 emit visibleChanged(visible);
549 emit d_ptr->updated();
550 }
550 }
551 }
551 }
552
552
@@ -607,6 +607,7 Qt::Orientation QAbstractAxis::orientation()
607
607
608 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
608 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
609 q_ptr(q),
609 q_ptr(q),
610 m_orientation(Qt::Orientation(0)),
610 m_visible(false),
611 m_visible(false),
611 m_arrowVisible(true),
612 m_arrowVisible(true),
612 m_gridLineVisible(true),
613 m_gridLineVisible(true),
@@ -615,10 +616,7 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
615 m_shadesVisible(false),
616 m_shadesVisible(false),
616 m_shadesBrush(Qt::SolidPattern),
617 m_shadesBrush(Qt::SolidPattern),
617 m_shadesOpacity(1.0),
618 m_shadesOpacity(1.0),
618 m_orientation(Qt::Orientation(0)),
619 m_dirty(false)
619 m_min(0),
620 m_max(0),
621 m_ticksCount(5)
622 {
620 {
623
621
624 }
622 }
@@ -628,6 +626,25 QAbstractAxisPrivate::~QAbstractAxisPrivate()
628
626
629 }
627 }
630
628
629 void QAbstractAxisPrivate::emitUpdated()
630 {
631 if(!m_dirty){
632 m_dirty=true;
633 emit updated();
634 }
635 }
636
637 void QAbstractAxisPrivate::setDirty(bool dirty)
638 {
639 m_dirty=dirty;
640 }
641
642 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
643 {
644 m_orientation=orientation;
645 }
646
647
631 #include "moc_qabstractaxis.cpp"
648 #include "moc_qabstractaxis.cpp"
632 #include "moc_qabstractaxis_p.cpp"
649 #include "moc_qabstractaxis_p.cpp"
633
650
@@ -38,29 +38,43 class ChartPresenter;
38 class ChartAxis;
38 class ChartAxis;
39 class Domain;
39 class Domain;
40
40
41 class QAbstractAxisPrivate : public QObject
41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 QAbstractAxisPrivate(QAbstractAxis *q);
45 QAbstractAxisPrivate(QAbstractAxis *q);
46 ~QAbstractAxisPrivate();
46 ~QAbstractAxisPrivate();
47
47
48 Q_SIGNALS:
49 void updated();
50
51 public:
48 public:
49
52 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
50 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
53 virtual void emitRange() = 0;
54 virtual void intializeDomain(Domain* domain) = 0;
51 virtual void intializeDomain(Domain* domain) = 0;
55
52
56 protected:
53 void emitUpdated();
54 void setDirty(bool dirty);
55 bool isDirty(){ return m_dirty; };
56 void setOrientation(Qt::Orientation orientation);
57 Qt::Orientation orientation() const { return m_orientation; }
58
57 virtual void setMin(const QVariant &min) = 0;
59 virtual void setMin(const QVariant &min) = 0;
60 virtual qreal min() = 0;
61
58 virtual void setMax(const QVariant &max) = 0;
62 virtual void setMax(const QVariant &max) = 0;
63 virtual qreal max() = 0;
64
59 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
65 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
60 virtual int ticksCount() const = 0;
61
66
62 public:
67 public Q_SLOTS:
68 virtual void handleDomainUpdated() = 0;
69
70 Q_SIGNALS:
71 void updated();
72
73 protected:
63 QAbstractAxis *q_ptr;
74 QAbstractAxis *q_ptr;
75 Qt::Orientation m_orientation;
76
77 private:
64 bool m_visible;
78 bool m_visible;
65
79
66 bool m_arrowVisible;
80 bool m_arrowVisible;
@@ -81,12 +95,7 public:
81 QBrush m_shadesBrush;
95 QBrush m_shadesBrush;
82 qreal m_shadesOpacity;
96 qreal m_shadesOpacity;
83
97
84 Qt::Orientation m_orientation;
98 bool m_dirty;
85
86 // range
87 qreal m_min;
88 qreal m_max;
89 int m_ticksCount;
90
99
91 friend class QAbstractAxis;
100 friend class QAbstractAxis;
92 };
101 };
@@ -22,6 +22,7
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include "qvaluesaxis.h"
25 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
26 #include <QDebug>
27 #include <QDebug>
27 #include <QFontMetrics>
28 #include <QFontMetrics>
@@ -31,7 +32,8 static int label_padding = 5;
31
32
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
34
34 ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
35 ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
36 m_tickCount(0)
35 {
37 {
36 }
38 }
37
39
@@ -41,13 +43,13 ChartValuesAxisX::~ChartValuesAxisX()
41
43
42 QVector<qreal> ChartValuesAxisX::calculateLayout() const
44 QVector<qreal> ChartValuesAxisX::calculateLayout() const
43 {
45 {
44 Q_ASSERT(m_ticksCount>=2);
46 Q_ASSERT(m_tickCount>=2);
45
47
46 QVector<qreal> points;
48 QVector<qreal> points;
47 points.resize(m_ticksCount);
49 points.resize(m_tickCount);
48
50
49 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
51 const qreal deltaX = m_rect.width()/(m_tickCount-1);
50 for (int i = 0; i < m_ticksCount; ++i) {
52 for (int i = 0; i < m_tickCount; ++i) {
51 int x = i * deltaX + m_rect.left();
53 int x = i * deltaX + m_rect.left();
52 points[i] = x;
54 points[i] = x;
53 }
55 }
@@ -109,4 +111,12 void ChartValuesAxisX::updateGeometry()
109 }
111 }
110 }
112 }
111
113
114 void ChartValuesAxisX::handleAxisUpdated()
115 {
116 //TODO:: fix this
117 QValuesAxis* axis = qobject_cast<QValuesAxis*>(m_chartAxis);
118 m_tickCount = axis->ticksCount();
119 ChartAxis::handleAxisUpdated();
120 }
121
112 QTCOMMERCIALCHART_END_NAMESPACE
122 QTCOMMERCIALCHART_END_NAMESPACE
@@ -46,11 +46,12 public:
46 AxisType axisType() const { return X_AXIS;}
46 AxisType axisType() const { return X_AXIS;}
47
47
48 protected:
48 protected:
49 void handleAxisUpdated();
49 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
51 void updateGeometry();
51
52
52 private:
53 private:
53 void createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
54 int m_tickCount;
54
55
55 };
56 };
56
57
@@ -22,6 +22,7
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include "qvaluesaxis.h"
25 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
26 #include <QDebug>
27 #include <QDebug>
27 #include <QFontMetrics>
28 #include <QFontMetrics>
@@ -31,7 +32,8 static int label_padding = 5;
31
32
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
34
34 ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
35 ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
36 m_tickCount(0)
35 {
37 {
36 }
38 }
37
39
@@ -41,13 +43,13 ChartValuesAxisY::~ChartValuesAxisY()
41
43
42 QVector<qreal> ChartValuesAxisY::calculateLayout() const
44 QVector<qreal> ChartValuesAxisY::calculateLayout() const
43 {
45 {
44 Q_ASSERT(m_ticksCount>=2);
46 Q_ASSERT(m_tickCount>=2);
45
47
46 QVector<qreal> points;
48 QVector<qreal> points;
47 points.resize(m_ticksCount);
49 points.resize(m_tickCount);
48
50
49 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
51 const qreal deltaY = m_rect.height()/(m_tickCount-1);
50 for (int i = 0; i < m_ticksCount; ++i) {
52 for (int i = 0; i < m_tickCount; ++i) {
51 int y = i * -deltaY + m_rect.bottom();
53 int y = i * -deltaY + m_rect.bottom();
52 points[i] = y;
54 points[i] = y;
53 }
55 }
@@ -114,4 +116,13 void ChartValuesAxisY::updateGeometry()
114 }
116 }
115 }
117 }
116
118
119 void ChartValuesAxisY::handleAxisUpdated()
120 {
121 //TODO:: fix this
122 QValuesAxis* axis = qobject_cast<QValuesAxis*>(m_chartAxis);
123 m_tickCount = axis->ticksCount();
124 ChartAxis::handleAxisUpdated();
125 }
126
127
117 QTCOMMERCIALCHART_END_NAMESPACE
128 QTCOMMERCIALCHART_END_NAMESPACE
@@ -48,6 +48,9 public:
48 protected:
48 protected:
49 QVector<qreal> calculateLayout() const;
49 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
50 void updateGeometry();
51 void handleAxisUpdated();
52 private:
53 int m_tickCount;
51 };
54 };
52
55
53 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
@@ -23,6 +23,7
23 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include <cmath>
26 #include <QDebug>
27 #include <QDebug>
27
28
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -172,6 +173,7 void QValuesAxis::setRange(qreal min, qreal max)
172 {
173 {
173 Q_D(QValuesAxis);
174 Q_D(QValuesAxis);
174 bool changed = false;
175 bool changed = false;
176
175 if (!qFuzzyIsNull(d->m_min - min)) {
177 if (!qFuzzyIsNull(d->m_min - min)) {
176 d->m_min = min;
178 d->m_min = min;
177 changed = true;
179 changed = true;
@@ -184,9 +186,11 void QValuesAxis::setRange(qreal min, qreal max)
184 emit maxChanged(max);
186 emit maxChanged(max);
185 }
187 }
186
188
189 if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount);
190
187 if (changed) {
191 if (changed) {
188 d->emitRange();
189 emit rangeChanged(d->m_min,d->m_max);
192 emit rangeChanged(d->m_min,d->m_max);
193 d->emitUpdated();
190 }
194 }
191 }
195 }
192
196
@@ -196,9 +200,9 void QValuesAxis::setRange(qreal min, qreal max)
196 void QValuesAxis::setTicksCount(int count)
200 void QValuesAxis::setTicksCount(int count)
197 {
201 {
198 Q_D(QValuesAxis);
202 Q_D(QValuesAxis);
199 if (d->m_ticksCount != count) {
203 if (d->m_tickCount != count) {
200 d->m_ticksCount = count;
204 d->m_tickCount = count;
201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
205 d->emitUpdated();
202 }
206 }
203 }
207 }
204
208
@@ -209,7 +213,7 void QValuesAxis::setTicksCount(int count)
209 int QValuesAxis::ticksCount() const
213 int QValuesAxis::ticksCount() const
210 {
214 {
211 Q_D(const QValuesAxis);
215 Q_D(const QValuesAxis);
212 return d->m_ticksCount;
216 return d->m_tickCount;
213 }
217 }
214
218
215 void QValuesAxis::setNiceNumbersEnabled(bool enable)
219 void QValuesAxis::setNiceNumbersEnabled(bool enable)
@@ -217,7 +221,7 void QValuesAxis::setNiceNumbersEnabled(bool enable)
217 Q_D(QValuesAxis);
221 Q_D(QValuesAxis);
218 if (d->m_niceNumbers != enable){
222 if (d->m_niceNumbers != enable){
219 d->m_niceNumbers = enable;
223 d->m_niceNumbers = enable;
220 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
224 if(enable) setRange(d->min(),d->max());
221 }
225 }
222 }
226 }
223
227
@@ -239,6 +243,9 QAbstractAxis::AxisType QValuesAxis::type() const
239
243
240 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
244 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
241 QAbstractAxisPrivate(q),
245 QAbstractAxisPrivate(q),
246 m_min(0),
247 m_max(0),
248 m_tickCount(5),
242 m_niceNumbers(false)
249 m_niceNumbers(false)
243 {
250 {
244
251
@@ -249,11 +256,17 QValuesAxisPrivate::~QValuesAxisPrivate()
249
256
250 }
257 }
251
258
252 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
259 void QValuesAxisPrivate::handleDomainUpdated()
253 {
260 {
254 Q_Q(QValuesAxis);
261 Q_Q(QValuesAxis);
255 q->setRange(min,max);
262 Domain* domain = qobject_cast<Domain*>(sender());
256 q->setTicksCount(count);
263 Q_ASSERT(domain);
264
265 if(orientation()==Qt::Horizontal){
266 q->setRange(domain->minX(),domain->maxX());
267 }else if(orientation()==Qt::Vertical){
268 q->setRange(domain->minY(),domain->maxY());
269 }
257 }
270 }
258
271
259
272
@@ -284,11 +297,6 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
284 if(ok1&&ok2) q->setRange(value1,value2);
297 if(ok1&&ok2) q->setRange(value1,value2);
285 }
298 }
286
299
287 int QValuesAxisPrivate::ticksCount() const
288 {
289 return m_ticksCount;
290 }
291
292 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
300 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
293 {
301 {
294 Q_Q(QValuesAxis);
302 Q_Q(QValuesAxis);
@@ -300,26 +308,54 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
300
308
301 }
309 }
302
310
303 void QValuesAxisPrivate::emitRange()
304 {
305 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
306 }
307
308 void QValuesAxisPrivate::intializeDomain(Domain* domain)
311 void QValuesAxisPrivate::intializeDomain(Domain* domain)
309 {
312 {
310 if(qFuzzyCompare(m_max,m_min)) {
313 if(qFuzzyCompare(m_max,m_min)) {
311 if(m_orientation==Qt::Vertical){
314 if(m_orientation==Qt::Vertical){
312 m_min = domain->minY();
315 m_min = domain->minY();
313 m_max = domain->maxY();
316 m_max = domain->maxY();
314 m_ticksCount = domain->tickYCount();
315 }else{
317 }else{
316 m_min = domain->minX();
318 m_min = domain->minX();
317 m_max = domain->maxX();
319 m_max = domain->maxX();
318 m_ticksCount = domain->tickXCount();
319 }
320 }
320 }
321 }
321 }
322 }
322
323
324 //algorithm defined by Paul S.Heckbert GraphicalGems I
325
326 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
327 {
328 qreal range = niceNumber(max-min,true); //range with ceiling
329 qreal step = niceNumber(range/(ticksCount-1),false);
330 min = floor(min/step);
331 max = ceil(max/step);
332 ticksCount = int(max-min) +1;
333 min*=step;
334 max*=step;
335 }
336
337 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
338
339 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
340 {
341 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
342 qreal q = x/z;//q<10 && q>=1;
343
344 if(ceiling) {
345 if(q <= 1.0) q=1;
346 else if(q <= 2.0) q=2;
347 else if(q <= 5.0) q=5;
348 else q=10;
349 }
350 else {
351 if(q < 1.5) q=1;
352 else if(q < 3.0) q=2;
353 else if(q < 7.0) q=5;
354 else q=10;
355 }
356 return q*z;
357 }
358
323 #include "moc_qvaluesaxis.cpp"
359 #include "moc_qvaluesaxis.cpp"
324 #include "moc_qvaluesaxis_p.cpp"
360 #include "moc_qvaluesaxis_p.cpp"
325
361
1 NO CONTENT: file renamed from src/axis/qvaluesaxis.h to src/axis/valuesaxis/qvaluesaxis.h
NO CONTENT: file renamed from src/axis/qvaluesaxis.h to src/axis/valuesaxis/qvaluesaxis.h
@@ -42,16 +42,12 public:
42 QValuesAxisPrivate(QValuesAxis *q);
42 QValuesAxisPrivate(QValuesAxis *q);
43 ~QValuesAxisPrivate();
43 ~QValuesAxisPrivate();
44
44
45 Q_SIGNALS:
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
47
48 public Q_SLOTS:
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
50
51 public:
45 public:
52 ChartAxis* createGraphics(ChartPresenter* presenter);
46 ChartAxis* createGraphics(ChartPresenter* presenter);
53 void intializeDomain(Domain* domain);
47 void intializeDomain(Domain* domain);
54 void emitRange();
48 void handleDomainUpdated();
49 qreal min(){ return m_min; };
50 qreal max(){ return m_max; };
55
51
56 protected:
52 protected:
57 void setMin(const QVariant &min);
53 void setMin(const QVariant &min);
@@ -60,6 +56,13 protected:
60 int ticksCount() const;
56 int ticksCount() const;
61
57
62 private:
58 private:
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
61
62 private:
63 qreal m_min;
64 qreal m_max;
65 int m_tickCount;
63 bool m_niceNumbers;
66 bool m_niceNumbers;
64 Q_DECLARE_PUBLIC(QValuesAxis)
67 Q_DECLARE_PUBLIC(QValuesAxis)
65 };
68 };
@@ -85,7 +85,7 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
85 if (layout.count() != m_bars.count())
85 if (layout.count() != m_bars.count())
86 return;
86 return;
87
87
88 m_layout = layout;
88 m_layout = layout;
89
89
90 for (int i=0; i < m_bars.count(); i++) {
90 for (int i=0; i < m_bars.count(); i++) {
91 m_bars.at(i)->setRect(layout.at(i));
91 m_bars.at(i)->setRect(layout.at(i));
@@ -93,12 +93,12 void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
93 }
93 }
94 //handlers
94 //handlers
95
95
96 void AbstractBarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
96 void AbstractBarChartItem::handleDomainUpdated()
97 {
97 {
98 m_domainMinX = minX;
98 m_domainMinX = domain()->minX();
99 m_domainMaxX = maxX;
99 m_domainMaxX = domain()->maxX();
100 m_domainMinY = minY;
100 m_domainMinY = domain()->minY();
101 m_domainMaxY = maxY;
101 m_domainMaxY = domain()->maxY();
102 handleLayoutChanged();
102 handleLayoutChanged();
103 }
103 }
104
104
@@ -59,12 +59,10 public:
59 virtual void setAnimation(AbstractBarAnimation* animation);
59 virtual void setAnimation(AbstractBarAnimation* animation);
60 void setLayout(const QVector<QRectF> &layout);
60 void setLayout(const QVector<QRectF> &layout);
61 void updateLayout(const QVector<QRectF> &layout);
61 void updateLayout(const QVector<QRectF> &layout);
62
63
64 QRectF geometry() const { return m_rect;}
62 QRectF geometry() const { return m_rect;}
65
63
66 public Q_SLOTS:
64 public Q_SLOTS:
67 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
65 void handleDomainUpdated();
68 void handleGeometryChanged(const QRectF &size);
66 void handleGeometryChanged(const QRectF &size);
69 void handleLayoutChanged();
67 void handleLayoutChanged();
70 void handleLabelsVisibleChanged(bool visible);
68 void handleLabelsVisibleChanged(bool visible);
@@ -561,8 +561,6 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
561 qreal minY(domain.minY());
561 qreal minY(domain.minY());
562 qreal maxX(domain.maxX());
562 qreal maxX(domain.maxX());
563 qreal maxY(domain.maxY());
563 qreal maxY(domain.maxY());
564 int tickXCount(domain.tickXCount());
565 int tickYCount(domain.tickYCount());
566
564
567 qreal seriesMinX = this->minX();
565 qreal seriesMinX = this->minX();
568 qreal seriesMaxX = this->maxX();
566 qreal seriesMaxX = this->maxX();
@@ -571,9 +569,8 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
571 minY = qMin(minY, y);
569 minY = qMin(minY, y);
572 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
570 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
573 maxY = qMax(maxY, y);
571 maxY = qMax(maxY, y);
574 tickXCount = categoryCount()+1;
575
572
576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
573 domain.setRange(minX,maxX,minY,maxY);
577 }
574 }
578
575
579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
576 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
@@ -85,8 +85,6 void QBarSeriesPrivate::scaleDomain(Domain& domain)
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
90
88
91 qreal x = categoryCount();
89 qreal x = categoryCount();
92 qreal y = max();
90 qreal y = max();
@@ -94,9 +92,8 void QBarSeriesPrivate::scaleDomain(Domain& domain)
94 minY = qMin(minY, y);
92 minY = qMin(minY, y);
95 maxX = qMax(maxX, x - (qreal)0.5);
93 maxX = qMax(maxX, x - (qreal)0.5);
96 maxY = qMax(maxY, y);
94 maxY = qMax(maxY, y);
97 tickXCount = x+1;
98
95
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
96 domain.setRange(minX,maxX,minY,maxY);
100 }
97 }
101
98
102
99
@@ -35,8 +35,6 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
35 qreal minY(domain.minY());
35 qreal minY(domain.minY());
36 qreal maxX(domain.maxX());
36 qreal maxX(domain.maxX());
37 qreal maxY(domain.maxY());
37 qreal maxY(domain.maxY());
38 int tickXCount(domain.tickXCount());
39 int tickYCount(domain.tickYCount());
40
38
41 qreal y = categoryCount();
39 qreal y = categoryCount();
42 qreal x = max();
40 qreal x = max();
@@ -44,9 +42,8 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
44 minY = qMin(minY, - (qreal)0.5);
42 minY = qMin(minY, - (qreal)0.5);
45 maxX = qMax(maxX, x);
43 maxX = qMax(maxX, x);
46 maxY = qMax(maxY, y - (qreal)0.5);
44 maxY = qMax(maxY, y - (qreal)0.5);
47 tickYCount = y+1;
48
45
49 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
46 domain.setRange(minX,maxX,minY,maxY);
50 }
47 }
51
48
52
49
@@ -33,17 +33,14 void QHorizontalPercentBarSeriesPrivate::scaleDomain(Domain& domain)
33 qreal minY(domain.minY());
33 qreal minY(domain.minY());
34 qreal maxX(domain.maxX());
34 qreal maxX(domain.maxX());
35 qreal maxY(domain.maxY());
35 qreal maxY(domain.maxY());
36 int tickXCount(domain.tickXCount());
37 int tickYCount(domain.tickYCount());
38
36
39 qreal y = categoryCount();
37 qreal y = categoryCount();
40 minX = 0;
38 minX = 0;
41 maxX = 100;
39 maxX = 100;
42 minY = qMin(minY, - (qreal)0.5);
40 minY = qMin(minY, - (qreal)0.5);
43 maxY = qMax(maxY, y - (qreal)0.5);
41 maxY = qMax(maxY, y - (qreal)0.5);
44 tickYCount = y+1;
45
42
46 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
43 domain.setRange(minX,maxX,minY,maxY);
47 }
44 }
48
45
49 Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
46 Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
@@ -33,8 +33,6 void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain& domain)
33 qreal minY(domain.minY());
33 qreal minY(domain.minY());
34 qreal maxX(domain.maxX());
34 qreal maxX(domain.maxX());
35 qreal maxY(domain.maxY());
35 qreal maxY(domain.maxY());
36 int tickXCount(domain.tickXCount());
37 int tickYCount(domain.tickYCount());
38
36
39 qreal y = categoryCount();
37 qreal y = categoryCount();
40 qreal x = maxCategorySum();
38 qreal x = maxCategorySum();
@@ -42,9 +40,8 void QHorizontalStackedBarSeriesPrivate::scaleDomain(Domain& domain)
42 minY = qMin(minY, - (qreal)0.5);
40 minY = qMin(minY, - (qreal)0.5);
43 maxX = qMax(maxX, x);
41 maxX = qMax(maxX, x);
44 maxY = qMax(maxY, y - (qreal)0.5);
42 maxY = qMax(maxY, y - (qreal)0.5);
45 tickYCount = y+1;
46
43
47 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
44 domain.setRange(minX,maxX,minY,maxY);
48 }
45 }
49
46
50 Chart* QHorizontalStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
47 Chart* QHorizontalStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
@@ -85,17 +85,14 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
90
88
91 qreal x = categoryCount();
89 qreal x = categoryCount();
92 minX = qMin(minX, - (qreal)0.5);
90 minX = qMin(minX, - (qreal)0.5);
93 maxX = qMax(maxX, x - (qreal)0.5);
91 maxX = qMax(maxX, x - (qreal)0.5);
94 minY = 0;
92 minY = 0;
95 maxY = 100;
93 maxY = 100;
96 tickXCount = x+1;
97
94
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
95 domain.setRange(minX,maxX,minY,maxY);
99 }
96 }
100
97
101
98
@@ -86,8 +86,6 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
86 qreal minY(domain.minY());
86 qreal minY(domain.minY());
87 qreal maxX(domain.maxX());
87 qreal maxX(domain.maxX());
88 qreal maxY(domain.maxY());
88 qreal maxY(domain.maxY());
89 int tickXCount(domain.tickXCount());
90 int tickYCount(domain.tickYCount());
91
89
92 qreal x = categoryCount();
90 qreal x = categoryCount();
93 qreal y = maxCategorySum();
91 qreal y = maxCategorySum();
@@ -95,9 +93,8 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
95 minY = qMin(minY, y);
93 minY = qMin(minY, y);
96 maxX = qMax(maxX, x - (qreal)0.5);
94 maxX = qMax(maxX, x - (qreal)0.5);
97 maxY = qMax(maxY, y);
95 maxY = qMax(maxY, y);
98 tickXCount = x+1;
99
96
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
97 domain.setRange(minX,maxX,minY,maxY);
101 }
98 }
102
99
103
100
@@ -77,6 +77,12 void Chart::handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY)
77 qWarning()<<"Slot not implemented";
77 qWarning()<<"Slot not implemented";
78 }
78 }
79
79
80 void Chart::handleDomainUpdated()
81 {
82 qWarning()<<"Slot not implemented";
83 }
84
85
80 #include "moc_chart_p.cpp"
86 #include "moc_chart_p.cpp"
81
87
82 QTCOMMERCIALCHART_END_NAMESPACE
88 QTCOMMERCIALCHART_END_NAMESPACE
@@ -50,6 +50,7 public:
50 public Q_SLOTS:
50 public Q_SLOTS:
51 virtual void handleGeometryChanged(const QRectF& rect);
51 virtual void handleGeometryChanged(const QRectF& rect);
52 virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY);
52 virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY);
53 virtual void handleDomainUpdated();
53
54
54 void setAnimator(ChartAnimator* animator);
55 void setAnimator(ChartAnimator* animator);
55 ChartAnimator* animator() const;
56 ChartAnimator* animator() const;
@@ -186,7 +186,7 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orienta
186 }
186 }
187
187
188 if(axis)
188 if(axis)
189 axis->d_ptr->m_orientation=orientation;
189 axis->d_ptr->setOrientation(orientation);
190
190
191 return axis;
191 return axis;
192 }
192 }
@@ -197,16 +197,16 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
197 axis->d_ptr->intializeDomain(domain);
197 axis->d_ptr->intializeDomain(domain);
198 series->d_ptr->initializeAxis(axis);
198 series->d_ptr->initializeAxis(axis);
199 if(axis->orientation()==Qt::Horizontal) {
199 if(axis->orientation()==Qt::Horizontal) {
200 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
200 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
201 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
201 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
202 m_seriesAxisXMap.insert(series,axis);
202 m_seriesAxisXMap.insert(series,axis);
203 }
203 }
204 else {
204 else {
205 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
205 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
206 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
206 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
207 m_seriesAxisYMap.insert(series,axis);
207 m_seriesAxisYMap.insert(series,axis);
208 }
208 }
209 axis->d_ptr->emitRange();
209 axis->d_ptr->emitUpdated();
210 }
210 }
211
211
212 void ChartDataSet::removeAxes(QAbstractSeries* series)
212 void ChartDataSet::removeAxes(QAbstractSeries* series)
@@ -369,7 +369,7 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori
369 return;
369 return;
370 }
370 }
371
371
372 axis->d_ptr->m_orientation=orientation;
372 axis->d_ptr->setOrientation(orientation);
373
373
374 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
374 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
375
375
@@ -78,28 +78,19 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain)
78 item->setAnimation(new AxisAnimation(item));
78 item->setAnimation(new AxisAnimation(item));
79 }
79 }
80
80
81 if(item->axisType()==ChartAxis::X_AXIS){
82 m_chartTheme->decorate(axis,true);
83 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
84 //initialize
85 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
86
87 }
88 else{
89 m_chartTheme->decorate(axis,false);
90 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
91 //initialize
92 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
93 }
94
95 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
81 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
82 QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated()));
96 QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool)));
83 QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool)));
84
97 //initialize
85 //initialize
86 domain->emitUpdated();
87 m_chartTheme->decorate(axis);
88 axis->d_ptr->setDirty(false);
89 axis->d_ptr->emitUpdated();
98 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
90 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
99 //reload visiblity
91
100 m_axisItems.insert(axis, item);
92 m_axisItems.insert(axis, item);
101 selectVisibleAxis();
93 selectVisibleAxis();
102
103 }
94 }
104
95
105 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
96 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
@@ -119,9 +110,10 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
119 item->setDomain(domain);
110 item->setDomain(domain);
120
111
121 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
112 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
122 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
113 QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated()));
123 //initialize
114 //initialize
124 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
115 item->handleDomainUpdated();
116
125 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
117 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
126 m_chartItems.insert(series,item);
118 m_chartItems.insert(series,item);
127 }
119 }
@@ -159,11 +151,11 void ChartPresenter::selectVisibleAxis()
159
151
160 while (i.hasNext()) {
152 while (i.hasNext()) {
161 i.next();
153 i.next();
162 if(i.key()->d_ptr->m_orientation==Qt::Vertical && !axisY) {
154 if(i.key()->orientation()==Qt::Vertical && !axisY) {
163 axisY=true;
155 axisY=true;
164 i.key()->show();
156 i.key()->show();
165 }
157 }
166 if(i.key()->d_ptr->m_orientation==Qt::Horizontal && !axisX) {
158 if(i.key()->orientation()==Qt::Horizontal && !axisX) {
167 axisX=true;
159 axisX=true;
168 i.key()->show();
160 i.key()->show();
169 }
161 }
@@ -185,7 +177,7 void ChartPresenter::handleAxisVisibleChanged(bool visible)
185 if(i.key()==axis) {
177 if(i.key()==axis) {
186 continue;
178 continue;
187 }
179 }
188 if(i.key()->d_ptr->m_orientation==axis->d_ptr->m_orientation) {
180 if(i.key()->orientation()==axis->orientation()) {
189 i.key()->setVisible(false);
181 i.key()->setVisible(false);
190 }
182 }
191 }
183 }
@@ -256,12 +256,14 void ChartTheme::decorate(QSplineSeries *series, int index)
256 }
256 }
257 }
257 }
258
258
259 void ChartTheme::decorate(QAbstractAxis *axis,bool axisX)
259 void ChartTheme::decorate(QAbstractAxis *axis)
260 {
260 {
261 QPen pen;
261 QPen pen;
262 QBrush brush;
262 QBrush brush;
263 QFont font;
263 QFont font;
264
264
265 bool axisX = axis->orientation()== Qt::Horizontal;
266
265 if (axis->isArrowVisible()) {
267 if (axis->isArrowVisible()) {
266
268
267 if(brush == axis->labelsBrush() || m_force){
269 if(brush == axis->labelsBrush() || m_force){
@@ -78,7 +78,7 public:
78 void decorate(QScatterSeries *series, int index);
78 void decorate(QScatterSeries *series, int index);
79 void decorate(QPieSeries *series, int index);
79 void decorate(QPieSeries *series, int index);
80 void decorate(QSplineSeries *series, int index);
80 void decorate(QSplineSeries *series, int index);
81 void decorate(QAbstractAxis *axis, bool axisX);
81 void decorate(QAbstractAxis *axis);
82 void setForced(bool enabled);
82 void setForced(bool enabled);
83 bool isForced() { return m_force; }
83 bool isForced() { return m_force; }
84
84
@@ -19,7 +19,7
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "domain_p.h"
21 #include "domain_p.h"
22 #include <cmath>
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
@@ -27,11 +27,7 Domain::Domain(QObject* parent) : QObject(parent),
27 m_minX(0),
27 m_minX(0),
28 m_maxX(0),
28 m_maxX(0),
29 m_minY(0),
29 m_minY(0),
30 m_maxY(0),
30 m_maxY(0)
31 m_tickXCount(5),
32 m_tickYCount(5),
33 m_niceXNumbers(false),
34 m_niceYNumbers(false)
35 {
31 {
36 }
32 }
37
33
@@ -41,48 +37,25 Domain::~Domain()
41
37
42 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
38 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
43 {
39 {
44 setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount);
45 }
46
47 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount)
48 {
49 bool axisXChanged = false;
40 bool axisXChanged = false;
50 bool axisYChanged = false;
41 bool axisYChanged = false;
51
42
52 if(m_tickXCount!=tickXCount) {
53 m_tickXCount=tickXCount;
54 axisXChanged=true;
55 }
56
57 if(m_tickYCount!=tickYCount) {
58 m_tickYCount=tickYCount;
59 axisYChanged=true;
60 }
61
62 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
43 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
63 if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
64 m_minX=minX;
44 m_minX=minX;
65 m_maxX=maxX;
45 m_maxX=maxX;
66 axisXChanged=true;
46 axisXChanged=true;
47 emit rangeXChanged(m_minX,m_maxX);
67 }
48 }
68
49
69 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
50 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
70 if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
71 m_minY=minY;
51 m_minY=minY;
72 m_maxY=maxY;
52 m_maxY=maxY;
73 axisYChanged=true;
53 axisYChanged=true;
54 emit rangeYChanged(m_minY,m_maxY);
74 }
55 }
75
56
76 if(axisXChanged || axisYChanged) {
57 if(axisXChanged || axisYChanged) {
77 emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY);
58 emit updated();
78 }
79
80 if(axisXChanged) {
81 emit rangeXChanged(minX,maxX, m_tickXCount);
82 }
83
84 if(axisYChanged) {
85 emit rangeYChanged(minY,maxY, m_tickYCount);
86 }
59 }
87 }
60 }
88
61
@@ -91,21 +64,11 void Domain::setRangeX(qreal min, qreal max)
91 setRange(min,max,m_minY, m_maxY);
64 setRange(min,max,m_minY, m_maxY);
92 }
65 }
93
66
94 void Domain::setRangeX(qreal min, qreal max, int tickCount)
95 {
96 setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount);
97 }
98
99 void Domain::setRangeY(qreal min, qreal max)
67 void Domain::setRangeY(qreal min, qreal max)
100 {
68 {
101 setRange(m_minX, m_maxX, min, max);
69 setRange(m_minX, m_maxX, min, max);
102 }
70 }
103
71
104 void Domain::setRangeY(qreal min, qreal max,int tickCount)
105 {
106 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount);
107 }
108
109 void Domain::setMinX(qreal min)
72 void Domain::setMinX(qreal min)
110 {
73 {
111 setRange(min, m_maxX, m_minY, m_maxY);
74 setRange(min, m_maxX, m_minY, m_maxY);
@@ -158,16 +121,7 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
158 minY = maxY - dy * rect.bottom();
121 minY = maxY - dy * rect.bottom();
159 maxY = maxY - dy * rect.top();
122 maxY = maxY - dy * rect.top();
160
123
161 int tickXCount = m_tickXCount;
124 setRange(minX,maxX,minY,maxY);
162 int tickYCount = m_tickYCount;
163
164 if(m_niceXNumbers) {
165 looseNiceNumbers(minX, maxX, tickXCount);
166 }
167 if(m_niceYNumbers) {
168 looseNiceNumbers(minY, maxY, tickYCount);
169 }
170 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
171 }
125 }
172
126
173 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
127 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
@@ -185,16 +139,7 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
185 maxY = minY + dy * rect.bottom();
139 maxY = minY + dy * rect.bottom();
186 minY = maxY - dy * size.height();
140 minY = maxY - dy * size.height();
187
141
188 int tickXCount = m_tickXCount;
142 setRange(minX,maxX,minY,maxY);
189 int tickYCount = m_tickYCount;
190
191 if(m_niceXNumbers) {
192 looseNiceNumbers(minX, maxX, tickXCount);
193 }
194 if(m_niceYNumbers) {
195 looseNiceNumbers(minY, maxY, tickYCount);
196 }
197 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
198 }
143 }
199
144
200 void Domain::move(qreal dx,qreal dy,const QSizeF& size)
145 void Domain::move(qreal dx,qreal dy,const QSizeF& size)
@@ -218,64 +163,24 void Domain::move(qreal dx,qreal dy,const QSizeF& size)
218 setRange(minX,maxX,minY,maxY);
163 setRange(minX,maxX,minY,maxY);
219 }
164 }
220
165
221 void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers)
166 void Domain::emitUpdated()
222 {
167 {
223 if (m_niceXNumbers != niceNumbers) {
168 emit updated();
224 m_niceXNumbers = niceNumbers;
225 //force recalculation
226 m_minX = 0;
227 m_maxX = 0;
228 }
229 setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount);
230 }
169 }
231
170
232 void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers)
171 void Domain::handleAxisUpdated()
233 {
172 {
234 if (m_niceYNumbers != niceNumbers) {
173 QAbstractAxisPrivate* axis = qobject_cast<QAbstractAxisPrivate*>(sender());
235 m_niceYNumbers = niceNumbers;
174 Q_ASSERT(axis);
236 //force recalculation
175 axis->setDirty(false);
237 m_minY = 0;
176 if(axis->orientation()==Qt::Horizontal){
238 m_maxY = 0;
177 setRangeX(axis->min(),axis->max());
178 }else if(axis->orientation()==Qt::Vertical){
179 setRangeY(axis->min(),axis->max());
239 }
180 }
240 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount);
241 }
242
181
243 //algorithm defined by Paul S.Heckbert GraphicalGems I
244
245 void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
246 {
247 qreal range = niceNumber(max-min,true); //range with ceiling
248 qreal step = niceNumber(range/(ticksCount-1),false);
249 min = floor(min/step);
250 max = ceil(max/step);
251 ticksCount = int(max-min) +1;
252 min*=step;
253 max*=step;
254 }
182 }
255
183
256 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
257
258 qreal Domain::niceNumber(qreal x,bool ceiling) const
259 {
260 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
261 qreal q = x/z;//q<10 && q>=1;
262
263 if(ceiling) {
264 if(q <= 1.0) q=1;
265 else if(q <= 2.0) q=2;
266 else if(q <= 5.0) q=5;
267 else q=10;
268 }
269 else {
270 if(q < 1.5) q=1;
271 else if(q < 3.0) q=2;
272 else if(q < 7.0) q=5;
273 else q=10;
274 }
275 return q*z;
276 }
277
278
279 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
184 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
280 {
185 {
281 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
186 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
@@ -293,7 +198,7 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const
293
198
294 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
199 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
295 {
200 {
296 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ;
201 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')';
297 return dbg.maybeSpace();
202 return dbg.maybeSpace();
298 }
203 }
299
204
@@ -43,11 +43,8 public:
43 virtual ~Domain();
43 virtual ~Domain();
44
44
45 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
45 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
46 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount);
47 void setRangeX(qreal min, qreal max);
46 void setRangeX(qreal min, qreal max);
48 void setRangeX(qreal min, qreal max, int tickCount);
49 void setRangeY(qreal min, qreal max);
47 void setRangeY(qreal min, qreal max);
50 void setRangeY(qreal min, qreal max, int tickCount);
51 void setMinX(qreal min);
48 void setMinX(qreal min);
52 void setMaxX(qreal max);
49 void setMaxX(qreal max);
53 void setMinY(qreal min);
50 void setMinY(qreal min);
@@ -62,9 +59,6 public:
62 qreal spanY() const;
59 qreal spanY() const;
63 bool isEmpty() const;
60 bool isEmpty() const;
64
61
65 int tickXCount() const {return m_tickXCount;}
66 int tickYCount() const {return m_tickYCount;}
67
68 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2);
62 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2);
69 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2);
63 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2);
70 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain);
64 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain);
@@ -72,29 +66,21 public:
72 void zoomIn(const QRectF& rect, const QSizeF& size);
66 void zoomIn(const QRectF& rect, const QSizeF& size);
73 void zoomOut(const QRectF& rect, const QSizeF& size);
67 void zoomOut(const QRectF& rect, const QSizeF& size);
74 void move(qreal dx,qreal dy,const QSizeF& size);
68 void move(qreal dx,qreal dy,const QSizeF& size);
69 void emitUpdated();
75
70
76 Q_SIGNALS:
71 Q_SIGNALS:
77 void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
72 void updated();
78 void rangeXChanged(qreal min, qreal max, int tickXCount);
73 void rangeXChanged(qreal min, qreal max);
79 void rangeYChanged(qreal min, qreal max, int tickYCount);
74 void rangeYChanged(qreal min, qreal max);
80
75
81 public Q_SLOTS:
76 public Q_SLOTS:
82 void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,bool niceNumbers = false);
77 void handleAxisUpdated();
83 void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,bool niceNumbers = false);
84
85 private:
86 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
87 qreal niceNumber(qreal x,bool celing) const;
88
78
89 private:
79 private:
90 qreal m_minX;
80 qreal m_minX;
91 qreal m_maxX;
81 qreal m_maxX;
92 qreal m_minY;
82 qreal m_minY;
93 qreal m_maxY;
83 qreal m_maxY;
94 int m_tickXCount;
95 int m_tickYCount;
96 bool m_niceXNumbers;
97 bool m_niceYNumbers;
98 };
84 };
99
85
100 QTCOMMERCIALCHART_END_NAMESPACE
86 QTCOMMERCIALCHART_END_NAMESPACE
@@ -401,8 +401,6 void QXYSeriesPrivate::scaleDomain(Domain& domain)
401 qreal minY(domain.minY());
401 qreal minY(domain.minY());
402 qreal maxX(domain.maxX());
402 qreal maxX(domain.maxX());
403 qreal maxY(domain.maxY());
403 qreal maxY(domain.maxY());
404 int tickXCount(domain.tickXCount());
405 int tickYCount(domain.tickYCount());
406
404
407 Q_Q(QXYSeries);
405 Q_Q(QXYSeries);
408
406
@@ -425,7 +423,7 void QXYSeriesPrivate::scaleDomain(Domain& domain)
425 maxY = qMax(maxY, y);
423 maxY = qMax(maxY, y);
426 }
424 }
427
425
428 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
426 domain.setRange(minX,maxX,minY,maxY);
429 }
427 }
430
428
431 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
429 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
@@ -23,6 +23,7
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include "domain_p.h"
26 #include <QPainter>
27 #include <QPainter>
27 #include <QAbstractItemModel>
28 #include <QAbstractItemModel>
28 #include "qxymodelmapper.h"
29 #include "qxymodelmapper.h"
@@ -185,12 +186,12 void XYChart::handlePointReplaced(int index)
185 updateChart(m_points,points,index);
186 updateChart(m_points,points,index);
186 }
187 }
187
188
188 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
189 void XYChart::handleDomainUpdated()
189 {
190 {
190 m_minX=minX;
191 m_minX=domain()->minX();
191 m_maxX=maxX;
192 m_maxX=domain()->maxX();
192 m_minY=minY;
193 m_minY=domain()->minY();
193 m_maxY=maxY;
194 m_maxY=domain()->maxY();
194 if (isEmpty()) return;
195 if (isEmpty()) return;
195
196
196 QVector<QPointF> points = calculateGeometryPoints();
197 QVector<QPointF> points = calculateGeometryPoints();
@@ -68,7 +68,7 public Q_SLOTS:
68 void handlePointAdded(int index);
68 void handlePointAdded(int index);
69 void handlePointRemoved(int index);
69 void handlePointRemoved(int index);
70 void handlePointReplaced(int index);
70 void handlePointReplaced(int index);
71 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
71 void handleDomainUpdated();
72 void handleGeometryChanged(const QRectF &size);
72 void handleGeometryChanged(const QRectF &size);
73
73
74 Q_SIGNALS:
74 Q_SIGNALS:
@@ -538,7 +538,7 void tst_ChartDataSet::zoomInDomain()
538 QList<QSignalSpy*> spyList;
538 QList<QSignalSpy*> spyList;
539
539
540 foreach(QAbstractSeries* series, seriesList) {
540 foreach(QAbstractSeries* series, seriesList) {
541 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
541 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
542 }
542 }
543
543
544 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
544 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
@@ -572,7 +572,7 void tst_ChartDataSet::zoomOutDomain()
572 QList<QSignalSpy*> spyList;
572 QList<QSignalSpy*> spyList;
573
573
574 foreach(QAbstractSeries* series, seriesList) {
574 foreach(QAbstractSeries* series, seriesList) {
575 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
575 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
576 }
576 }
577
577
578 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
578 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
@@ -606,7 +606,7 void tst_ChartDataSet::scrollDomain()
606 foreach(QAbstractSeries* series, seriesList) {
606 foreach(QAbstractSeries* series, seriesList) {
607 spyList
607 spyList
608 << new QSignalSpy(m_dataset->domain(series),
608 << new QSignalSpy(m_dataset->domain(series),
609 SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
609 SIGNAL(updated()));
610 }
610 }
611
611
612 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
612 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
@@ -20,6 +20,7
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <private/domain_p.h>
22 #include <private/domain_p.h>
23 #include <private/qabstractaxis_p.h>
23 #include <tst_definitions.h>
24 #include <tst_definitions.h>
24
25
25 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -27,6 +28,26 QTCOMMERCIALCHART_USE_NAMESPACE
27 Q_DECLARE_METATYPE(Domain*)
28 Q_DECLARE_METATYPE(Domain*)
28 Q_DECLARE_METATYPE(QSizeF)
29 Q_DECLARE_METATYPE(QSizeF)
29
30
31
32 class AxisMock: public QAbstractAxisPrivate
33 {
34 Q_OBJECT
35 public:
36 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
37 ChartAxis* createGraphics(ChartPresenter* presenter){};
38 void intializeDomain(Domain* domain){};
39 void setMin(const QVariant &min){}
40 qreal min() { return m_min;}
41 void setMax(const QVariant &max){}
42 qreal max() { return m_max; }
43 void setRange(const QVariant &min, const QVariant &max){};
44
45 void handleDomainUpdated(){};
46 public:
47 qreal m_min;
48 qreal m_max;
49 };
50
30 class tst_Domain: public QObject
51 class tst_Domain: public QObject
31 {
52 {
32 Q_OBJECT
53 Q_OBJECT
@@ -39,10 +60,10 public Q_SLOTS:
39
60
40 private Q_SLOTS:
61 private Q_SLOTS:
41 void domain();
62 void domain();
42 void handleAxisRangeXChanged_data();
63 void handleAxisUpdatedX_data();
43 void handleAxisRangeXChanged();
64 void handleAxisUpdatedX();
44 void handleAxisRangeYChanged_data();
65 void handleAxisUpdatedY_data();
45 void handleAxisRangeYChanged();
66 void handleAxisUpdatedY();
46 void isEmpty_data();
67 void isEmpty_data();
47 void isEmpty();
68 void isEmpty();
48 void maxX_data();
69 void maxX_data();
@@ -69,10 +90,6 private Q_SLOTS:
69 void zoom();
90 void zoom();
70 void move_data();
91 void move_data();
71 void move();
92 void move();
72 void handleAxisXChanged_data();
73 void handleAxisXChanged();
74 void handleAxisYChanged_data();
75 void handleAxisYChanged();
76 };
93 };
77
94
78 void tst_Domain::initTestCase()
95 void tst_Domain::initTestCase()
@@ -102,7 +119,7 void tst_Domain::domain()
102 QCOMPARE(domain.minY(), 0.0);
119 QCOMPARE(domain.minY(), 0.0);
103 }
120 }
104
121
105 void tst_Domain::handleAxisRangeXChanged_data()
122 void tst_Domain::handleAxisUpdatedX_data()
106 {
123 {
107 QTest::addColumn<qreal>("min");
124 QTest::addColumn<qreal>("min");
108 QTest::addColumn<qreal>("max");
125 QTest::addColumn<qreal>("max");
@@ -111,22 +128,25 void tst_Domain::handleAxisRangeXChanged_data()
111 QTest::newRow("-1 0") << -1.0 << 0.0;
128 QTest::newRow("-1 0") << -1.0 << 0.0;
112 }
129 }
113
130
114 void tst_Domain::handleAxisRangeXChanged()
131 void tst_Domain::handleAxisUpdatedX()
115 {
132 {
116 QFETCH(qreal, min);
133 QFETCH(qreal, min);
117 QFETCH(qreal, max);
134 QFETCH(qreal, max);
118
135
119 Domain domain;
136 Domain domain;
120
137
121 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
138 QSignalSpy spy0(&domain, SIGNAL(updated()));
122 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
139 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
123 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
140 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
124
141
125 domain.handleAxisXChanged(min, max);
142 AxisMock axis(Qt::Horizontal);
143 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
144 axis.m_min=min;
145 axis.m_max=max;
146 axis.emitUpdated();
126
147
127 QList<QVariant> arg0 = spy0.first();
148 QVERIFY(qFuzzyIsNull(domain.minX() - min));
128 QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min));
149 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
129 QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max));
130
150
131 QList<QVariant> arg1 = spy1.first();
151 QList<QVariant> arg1 = spy1.first();
132 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
152 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
@@ -138,7 +158,7 void tst_Domain::handleAxisRangeXChanged()
138
158
139 }
159 }
140
160
141 void tst_Domain::handleAxisRangeYChanged_data()
161 void tst_Domain::handleAxisUpdatedY_data()
142 {
162 {
143 QTest::addColumn<qreal>("min");
163 QTest::addColumn<qreal>("min");
144 QTest::addColumn<qreal>("max");
164 QTest::addColumn<qreal>("max");
@@ -147,22 +167,25 void tst_Domain::handleAxisRangeYChanged_data()
147 QTest::newRow("-1 0") << -1.0 << 0.0;
167 QTest::newRow("-1 0") << -1.0 << 0.0;
148 }
168 }
149
169
150 void tst_Domain::handleAxisRangeYChanged()
170 void tst_Domain::handleAxisUpdatedY()
151 {
171 {
152 QFETCH(qreal, min);
172 QFETCH(qreal, min);
153 QFETCH(qreal, max);
173 QFETCH(qreal, max);
154
174
155 Domain domain;
175 Domain domain;
156
176
157 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
177 QSignalSpy spy0(&domain, SIGNAL(updated()));
158 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
178 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
159 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
179 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
160
180
161 domain.handleAxisYChanged(min, max, 5);
181 AxisMock axis(Qt::Vertical);
182 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
183 axis.m_min = min;
184 axis.m_max = max;
185 axis.emitUpdated();
162
186
163 QList<QVariant> arg0 = spy0.first();
187 QVERIFY(qFuzzyIsNull(domain.minY() - min));
164 QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min));
188 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
165 QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max));
166
189
167 QList<QVariant> arg1 = spy2.first();
190 QList<QVariant> arg1 = spy2.first();
168 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
191 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
@@ -217,9 +240,9 void tst_Domain::maxX()
217
240
218 Domain domain;
241 Domain domain;
219
242
220 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
243 QSignalSpy spy0(&domain, SIGNAL(updated()));
221 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
244 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
222 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
245 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
223
246
224 domain.setMaxX(maxX1);
247 domain.setMaxX(maxX1);
225 QCOMPARE(domain.maxX(), maxX1);
248 QCOMPARE(domain.maxX(), maxX1);
@@ -250,9 +273,9 void tst_Domain::maxY()
250
273
251 Domain domain;
274 Domain domain;
252
275
253 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
276 QSignalSpy spy0(&domain, SIGNAL(updated()));
254 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
277 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
255 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
278 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
256
279
257 domain.setMaxY(maxY1);
280 domain.setMaxY(maxY1);
258 QCOMPARE(domain.maxY(), maxY1);
281 QCOMPARE(domain.maxY(), maxY1);
@@ -282,9 +305,9 void tst_Domain::minX()
282
305
283 Domain domain;
306 Domain domain;
284
307
285 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
308 QSignalSpy spy0(&domain, SIGNAL(updated()));
286 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
309 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
287 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
310 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
288
311
289 domain.setMinX(minX1);
312 domain.setMinX(minX1);
290 QCOMPARE(domain.minX(), minX1);
313 QCOMPARE(domain.minX(), minX1);
@@ -314,9 +337,9 void tst_Domain::minY()
314
337
315 Domain domain;
338 Domain domain;
316
339
317 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
340 QSignalSpy spy0(&domain, SIGNAL(updated()));
318 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
341 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
319 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
342 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
320
343
321 domain.setMinY(minY1);
344 domain.setMinY(minY1);
322 QCOMPARE(domain.minY(), minY1);
345 QCOMPARE(domain.minY(), minY1);
@@ -364,9 +387,9 void tst_Domain::operatorEquals()
364
387
365 Domain domain;
388 Domain domain;
366
389
367 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
390 QSignalSpy spy0(&domain, SIGNAL(updated()));
368 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
391 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
369 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
392 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
370
393
371 QCOMPARE(*domain1==*domain2, equals);
394 QCOMPARE(*domain1==*domain2, equals);
372 QCOMPARE(*domain1!=*domain2, notEquals);
395 QCOMPARE(*domain1!=*domain2, notEquals);
@@ -396,9 +419,9 void tst_Domain::setRange()
396
419
397 Domain domain;
420 Domain domain;
398
421
399 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
422 QSignalSpy spy0(&domain, SIGNAL(updated()));
400 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
423 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
401 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
424 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
402
425
403 domain.setRange(minX, maxX, minY, maxY);
426 domain.setRange(minX, maxX, minY, maxY);
404
427
@@ -429,15 +452,14 void tst_Domain::setRangeX()
429
452
430 Domain domain;
453 Domain domain;
431
454
432 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
455 QSignalSpy spy0(&domain, SIGNAL(updated()));
433 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
456 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
434 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
457 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
435
458
436 domain.setRangeX(min, max);
459 domain.setRangeX(min, max);
437
460
438 QList<QVariant> arg0 = spy0.first();
461 QVERIFY(qFuzzyIsNull(domain.minX() - min));
439 QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min));
462 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
440 QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max));
441
463
442 QList<QVariant> arg1 = spy1.first();
464 QList<QVariant> arg1 = spy1.first();
443 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
465 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
@@ -464,15 +486,14 void tst_Domain::setRangeY()
464
486
465 Domain domain;
487 Domain domain;
466
488
467 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
489 QSignalSpy spy0(&domain, SIGNAL(updated()));
468 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
490 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
469 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
491 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
470
492
471 domain.setRangeY(min, max);
493 domain.setRangeY(min, max);
472
494
473 QList<QVariant> arg0 = spy0.first();
495 QVERIFY(qFuzzyIsNull(domain.minY() - min));
474 QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min));
496 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
475 QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max));
476
497
477 QList<QVariant> arg1 = spy2.first();
498 QList<QVariant> arg1 = spy2.first();
478 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
499 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
@@ -502,9 +523,9 void tst_Domain::spanX()
502
523
503 domain.setRangeX(minX, maxX);
524 domain.setRangeX(minX, maxX);
504
525
505 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
526 QSignalSpy spy0(&domain, SIGNAL(updated()));
506 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
527 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
507 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
528 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
508
529
509 QCOMPARE(domain.spanX(), spanX);
530 QCOMPARE(domain.spanX(), spanX);
510
531
@@ -532,9 +553,9 void tst_Domain::spanY()
532
553
533 domain.setRangeY(minY, maxY);
554 domain.setRangeY(minY, maxY);
534
555
535 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
556 QSignalSpy spy0(&domain, SIGNAL(updated()));
536 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
557 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
537 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
558 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
538
559
539 QCOMPARE(domain.spanY(), spanY);
560 QCOMPARE(domain.spanY(), spanY);
540
561
@@ -574,9 +595,9 void tst_Domain::zoom()
574
595
575 domain.setRange(0, 1000, 0, 1000);
596 domain.setRange(0, 1000, 0, 1000);
576
597
577 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
598 QSignalSpy spy0(&domain, SIGNAL(updated()));
578 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
599 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
579 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
600 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
580
601
581 Domain domain0;
602 Domain domain0;
582 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
603 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
@@ -620,9 +641,9 void tst_Domain::move()
620
641
621 domain.setRange(0, size.width(), 0, size.height());
642 domain.setRange(0, size.width(), 0, size.height());
622
643
623 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
644 QSignalSpy spy0(&domain, SIGNAL(updated()));
624 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
645 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
625 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
646 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
626
647
627 domain.move(dx, dy, size);
648 domain.move(dx, dy, size);
628
649
@@ -635,6 +656,7 void tst_Domain::move()
635 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
656 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
636 }
657 }
637
658
659 /*
638 void tst_Domain::handleAxisXChanged_data()
660 void tst_Domain::handleAxisXChanged_data()
639 {
661 {
640 QTest::addColumn<qreal>("min");
662 QTest::addColumn<qreal>("min");
@@ -661,15 +683,15 void tst_Domain::handleAxisXChanged()
661 QFETCH(int, resultTickCount);
683 QFETCH(int, resultTickCount);
662
684
663 Domain domain;
685 Domain domain;
664 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
686 QSignalSpy spy0(&domain, SIGNAL(updated()));
665 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
687 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
666 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
688 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
667
689
668 domain.handleAxisXChanged(min, max, tickCount, niceNumbers);
690 // domain.handleAxisXChanged(min, max, tickCount, niceNumbers);
669
691
670 QCOMPARE(resultMin, domain.minX());
692 QCOMPARE(resultMin, domain.minX());
671 QCOMPARE(resultMax, domain.maxX());
693 QCOMPARE(resultMax, domain.maxX());
672 QCOMPARE(resultTickCount, domain.tickXCount());
694 // QCOMPARE(resultTickCount, domain.tickXCount());
673 TRY_COMPARE(spy0.count(), 1);
695 TRY_COMPARE(spy0.count(), 1);
674 TRY_COMPARE(spy1.count(), 1);
696 TRY_COMPARE(spy1.count(), 1);
675 TRY_COMPARE(spy2.count(), 0);
697 TRY_COMPARE(spy2.count(), 0);
@@ -692,20 +714,20 void tst_Domain::handleAxisYChanged()
692 QFETCH(int, resultTickCount);
714 QFETCH(int, resultTickCount);
693
715
694 Domain domain;
716 Domain domain;
695 QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
717 QSignalSpy spy0(&domain, SIGNAL(updated()));
696 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int)));
718 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
697 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int)));
719 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
698
720
699 domain.handleAxisYChanged(min, max, tickCount, niceNumbers);
721 // domain.handleAxisYChanged(min, max, tickCount, niceNumbers);
700
722
701 QCOMPARE(resultMin, domain.minY());
723 QCOMPARE(resultMin, domain.minY());
702 QCOMPARE(resultMax, domain.maxY());
724 QCOMPARE(resultMax, domain.maxY());
703 QCOMPARE(resultTickCount, domain.tickYCount());
725 // QCOMPARE(resultTickCount, domain.tickYCount());
704 TRY_COMPARE(spy0.count(), 1);
726 TRY_COMPARE(spy0.count(), 1);
705 TRY_COMPARE(spy1.count(), 0);
727 TRY_COMPARE(spy1.count(), 0);
706 TRY_COMPARE(spy2.count(), 1);
728 TRY_COMPARE(spy2.count(), 1);
707 }
729 }
708
730 */
709 QTEST_MAIN(tst_Domain)
731 QTEST_MAIN(tst_Domain)
710 #include "tst_domain.moc"
732 #include "tst_domain.moc"
711
733
General Comments 0
You need to be logged in to leave comments. Login now