##// END OF EJS Templates
QValueAxis ticksCount to tickCount
Marek Rosa -
r1807:d572c33906e7
parent child
Show More
@@ -1,71 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chart.h"
21 #include "chart.h"
22 #include <QAbstractAxis>
22 #include <QAbstractAxis>
23 #include <QSplineSeries>
23 #include <QSplineSeries>
24 #include <QValueAxis>
24 #include <QValueAxis>
25 #include <QTime>
25 #include <QTime>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
29 QChart(parent, wFlags),
29 QChart(parent, wFlags),
30 m_series(0),
30 m_series(0),
31 m_axis(new QValueAxis),
31 m_axis(new QValueAxis),
32 m_step(0),
32 m_step(0),
33 m_x(5),
33 m_x(5),
34 m_y(1)
34 m_y(1)
35 {
35 {
36 qsrand((uint) QTime::currentTime().msec());
36 qsrand((uint) QTime::currentTime().msec());
37
37
38 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
38 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
39 m_timer.setInterval(1000);
39 m_timer.setInterval(1000);
40
40
41 m_series = new QSplineSeries(this);
41 m_series = new QSplineSeries(this);
42 QPen green(Qt::red);
42 QPen green(Qt::red);
43 green.setWidth(3);
43 green.setWidth(3);
44 m_series->setPen(green);
44 m_series->setPen(green);
45 m_series->append(m_x, m_y);
45 m_series->append(m_x, m_y);
46
46
47 addSeries(m_series);
47 addSeries(m_series);
48 createDefaultAxes();
48 createDefaultAxes();
49 setAxisX(m_axis,m_series);
49 setAxisX(m_axis,m_series);
50 m_axis->setTicksCount(5);
50 m_axis->setTickCount(5);
51 axisX()->setRange(0, 10);
51 axisX()->setRange(0, 10);
52 axisY()->setRange(-5, 10);
52 axisY()->setRange(-5, 10);
53
53
54 m_timer.start();
54 m_timer.start();
55 }
55 }
56
56
57 Chart::~Chart()
57 Chart::~Chart()
58 {
58 {
59
59
60 }
60 }
61
61
62 void Chart::handleTimeout()
62 void Chart::handleTimeout()
63 {
63 {
64 qreal x = plotArea().width()/m_axis->ticksCount();
64 qreal x = plotArea().width()/m_axis->tickCount();
65 qreal y =(m_axis->max() - m_axis->min())/m_axis->ticksCount();
65 qreal y =(m_axis->max() - m_axis->min())/m_axis->tickCount();
66 m_x += y;
66 m_x += y;
67 m_y = qrand() % 5 - 2.5;
67 m_y = qrand() % 5 - 2.5;
68 m_series->append(m_x, m_y);
68 m_series->append(m_x, m_y);
69 scroll(x,0);
69 scroll(x,0);
70 if(m_x==100) m_timer.stop();
70 if(m_x==100) m_timer.stop();
71 }
71 }
@@ -1,120 +1,120
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartvalueaxisx_p.h"
21 #include "chartvalueaxisx_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 static int label_padding = 5;
29 static int label_padding = 5;
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
33 ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 m_tickCount(0)
34 m_tickCount(0)
35 {
35 {
36 }
36 }
37
37
38 ChartValueAxisX::~ChartValueAxisX()
38 ChartValueAxisX::~ChartValueAxisX()
39 {
39 {
40 }
40 }
41
41
42 QVector<qreal> ChartValueAxisX::calculateLayout() const
42 QVector<qreal> ChartValueAxisX::calculateLayout() const
43 {
43 {
44 Q_ASSERT(m_tickCount>=2);
44 Q_ASSERT(m_tickCount>=2);
45
45
46 QVector<qreal> points;
46 QVector<qreal> points;
47 points.resize(m_tickCount);
47 points.resize(m_tickCount);
48
48
49 const qreal deltaX = m_rect.width()/(m_tickCount-1);
49 const qreal deltaX = m_rect.width()/(m_tickCount-1);
50 for (int i = 0; i < m_tickCount; ++i) {
50 for (int i = 0; i < m_tickCount; ++i) {
51 int x = i * deltaX + m_rect.left();
51 int x = i * deltaX + m_rect.left();
52 points[i] = x;
52 points[i] = x;
53 }
53 }
54 return points;
54 return points;
55 }
55 }
56
56
57 void ChartValueAxisX::updateGeometry()
57 void ChartValueAxisX::updateGeometry()
58 {
58 {
59 const QVector<qreal>& layout = ChartAxis::layout();
59 const QVector<qreal>& layout = ChartAxis::layout();
60
60
61 m_minWidth = 0;
61 m_minWidth = 0;
62 m_minHeight = 0;
62 m_minHeight = 0;
63
63
64 if(layout.isEmpty()) return;
64 if(layout.isEmpty()) return;
65
65
66 QStringList ticksList;
66 QStringList ticksList;
67
67
68 createNumberLabels(ticksList,m_min,m_max,layout.size());
68 createNumberLabels(ticksList,m_min,m_max,layout.size());
69
69
70 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> lines = m_grid->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
72 QList<QGraphicsItem *> shades = m_shades->childItems();
72 QList<QGraphicsItem *> shades = m_shades->childItems();
73 QList<QGraphicsItem *> axis = m_arrow->childItems();
73 QList<QGraphicsItem *> axis = m_arrow->childItems();
74
74
75 Q_ASSERT(labels.size() == ticksList.size());
75 Q_ASSERT(labels.size() == ticksList.size());
76 Q_ASSERT(layout.size() == ticksList.size());
76 Q_ASSERT(layout.size() == ticksList.size());
77
77
78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
79 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
79 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
80
80
81 qreal width = 0;
81 qreal width = 0;
82 for (int i = 0; i < layout.size(); ++i) {
82 for (int i = 0; i < layout.size(); ++i) {
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 labelItem->setText(ticksList.at(i));
86 labelItem->setText(ticksList.at(i));
87 const QRectF& rect = labelItem->boundingRect();
87 const QRectF& rect = labelItem->boundingRect();
88 QPointF center = rect.center();
88 QPointF center = rect.center();
89 labelItem->setTransformOriginPoint(center.x(), center.y());
89 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
91
91
92 if(labelItem->pos().x()<=width){
92 if(labelItem->pos().x()<=width){
93 labelItem->setVisible(false);
93 labelItem->setVisible(false);
94 lineItem->setVisible(false);
94 lineItem->setVisible(false);
95 }else{
95 }else{
96 labelItem->setVisible(true);
96 labelItem->setVisible(true);
97 lineItem->setVisible(true);
97 lineItem->setVisible(true);
98 width=rect.width()+labelItem->pos().x();
98 width=rect.width()+labelItem->pos().x();
99 }
99 }
100 m_minWidth+=rect.width();
100 m_minWidth+=rect.width();
101 m_minHeight=qMax(rect.height(),m_minHeight);
101 m_minHeight=qMax(rect.height(),m_minHeight);
102
102
103 if ((i+1)%2 && i>1) {
103 if ((i+1)%2 && i>1) {
104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
105 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
105 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
106 }
106 }
107 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
107 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
108 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
108 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
109 }
109 }
110 }
110 }
111
111
112 void ChartValueAxisX::handleAxisUpdated()
112 void ChartValueAxisX::handleAxisUpdated()
113 {
113 {
114 //TODO:: fix this
114 //TODO:: fix this
115 QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis);
115 QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis);
116 m_tickCount = axis->ticksCount();
116 m_tickCount = axis->tickCount();
117 ChartAxis::handleAxisUpdated();
117 ChartAxis::handleAxisUpdated();
118 }
118 }
119
119
120 QTCOMMERCIALCHART_END_NAMESPACE
120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,126 +1,126
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartvalueaxisy_p.h"
21 #include "chartvalueaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 static int label_padding = 5;
29 static int label_padding = 5;
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
33 ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 m_tickCount(0)
34 m_tickCount(0)
35 {
35 {
36 }
36 }
37
37
38 ChartValueAxisY::~ChartValueAxisY()
38 ChartValueAxisY::~ChartValueAxisY()
39 {
39 {
40 }
40 }
41
41
42 QVector<qreal> ChartValueAxisY::calculateLayout() const
42 QVector<qreal> ChartValueAxisY::calculateLayout() const
43 {
43 {
44 Q_ASSERT(m_tickCount>=2);
44 Q_ASSERT(m_tickCount>=2);
45
45
46 QVector<qreal> points;
46 QVector<qreal> points;
47 points.resize(m_tickCount);
47 points.resize(m_tickCount);
48
48
49 const qreal deltaY = m_rect.height()/(m_tickCount-1);
49 const qreal deltaY = m_rect.height()/(m_tickCount-1);
50 for (int i = 0; i < m_tickCount; ++i) {
50 for (int i = 0; i < m_tickCount; ++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 }
54
54
55 return points;
55 return points;
56 }
56 }
57
57
58 void ChartValueAxisY::updateGeometry()
58 void ChartValueAxisY::updateGeometry()
59 {
59 {
60 const QVector<qreal> &layout = ChartAxis::layout();
60 const QVector<qreal> &layout = ChartAxis::layout();
61 m_minWidth = 0;
61 m_minWidth = 0;
62 m_minHeight = 0;
62 m_minHeight = 0;
63
63
64 if(layout.isEmpty()) return;
64 if(layout.isEmpty()) return;
65
65
66 QStringList ticksList;
66 QStringList ticksList;
67
67
68 createNumberLabels(ticksList,m_min,m_max,layout.size());
68 createNumberLabels(ticksList,m_min,m_max,layout.size());
69
69
70 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> lines = m_grid->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
72 QList<QGraphicsItem *> shades = m_shades->childItems();
72 QList<QGraphicsItem *> shades = m_shades->childItems();
73 QList<QGraphicsItem *> axis = m_arrow->childItems();
73 QList<QGraphicsItem *> axis = m_arrow->childItems();
74
74
75 Q_ASSERT(labels.size() == ticksList.size());
75 Q_ASSERT(labels.size() == ticksList.size());
76 Q_ASSERT(layout.size() == ticksList.size());
76 Q_ASSERT(layout.size() == ticksList.size());
77
77
78 qreal height = 2*m_rect.bottom();
78 qreal height = 2*m_rect.bottom();
79
79
80 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
80 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
81 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
81 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
82
82
83 for (int i = 0; i < layout.size(); ++i) {
83 for (int i = 0; i < layout.size(); ++i) {
84 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
84 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
85 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
85 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
86 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
87
87
88 labelItem->setText(ticksList.at(i));
88 labelItem->setText(ticksList.at(i));
89 const QRectF& rect = labelItem->boundingRect();
89 const QRectF& rect = labelItem->boundingRect();
90
90
91 QPointF center = rect.center();
91 QPointF center = rect.center();
92 labelItem->setTransformOriginPoint(center.x(), center.y());
92 labelItem->setTransformOriginPoint(center.x(), center.y());
93 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
93 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
94
94
95 if(labelItem->pos().y()+rect.height()>height) {
95 if(labelItem->pos().y()+rect.height()>height) {
96 labelItem->setVisible(false);
96 labelItem->setVisible(false);
97 lineItem->setVisible(false);
97 lineItem->setVisible(false);
98 }
98 }
99 else {
99 else {
100 labelItem->setVisible(true);
100 labelItem->setVisible(true);
101 lineItem->setVisible(true);
101 lineItem->setVisible(true);
102 height=labelItem->pos().y();
102 height=labelItem->pos().y();
103 }
103 }
104
104
105 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
105 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
106 m_minHeight+=rect.height();
106 m_minHeight+=rect.height();
107
107
108 if ((i+1)%2 && i>1) {
108 if ((i+1)%2 && i>1) {
109 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
109 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
110 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
110 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
111 }
111 }
112 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
112 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
113 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
113 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
114 }
114 }
115 }
115 }
116
116
117 void ChartValueAxisY::handleAxisUpdated()
117 void ChartValueAxisY::handleAxisUpdated()
118 {
118 {
119 //TODO:: fix this
119 //TODO:: fix this
120 QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis);
120 QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis);
121 m_tickCount = axis->ticksCount();
121 m_tickCount = axis->tickCount();
122 ChartAxis::handleAxisUpdated();
122 ChartAxis::handleAxisUpdated();
123 }
123 }
124
124
125
125
126 QTCOMMERCIALCHART_END_NAMESPACE
126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,384 +1,384
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvalueaxis.h"
21 #include "qvalueaxis.h"
22 #include "qvalueaxis_p.h"
22 #include "qvalueaxis_p.h"
23 #include "chartvalueaxisx_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
24 #include "chartvalueaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 /*!
31 /*!
32 \class QValueAxis
32 \class QValueAxis
33 \brief The QValueAxis class is used for manipulating chart's axis.
33 \brief The QValueAxis class is used for manipulating chart's axis.
34 \mainclass
34 \mainclass
35
35
36 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
37 Values of axis are drawn to position of ticks
37 Values of axis are drawn to position of ticks
38 */
38 */
39
39
40 /*!
40 /*!
41 \qmlclass ValuesAxis QValueAxis
41 \qmlclass ValuesAxis QValueAxis
42 \brief The ValuesAxis element is used for manipulating chart's axes
42 \brief The ValuesAxis element is used for manipulating chart's axes
43
43
44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
45 Values of axis are drawn to position of ticks
45 Values of axis are drawn to position of ticks
46
46
47 To access Axes you can use ChartView API. For example:
47 To access Axes you can use ChartView API. For example:
48 \code
48 \code
49 ChartView {
49 ChartView {
50 ValuesAxis {
50 ValuesAxis {
51 id: xAxis
51 id: xAxis
52 min: 0
52 min: 0
53 max: 10
53 max: 10
54 }
54 }
55 // Add a few series...
55 // Add a few series...
56 }
56 }
57 \endcode
57 \endcode
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QValueAxis::min
61 \property QValueAxis::min
62 Defines the minimum value on the axis.
62 Defines the minimum value on the axis.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
64 */
64 */
65 /*!
65 /*!
66 \qmlproperty real ValuesAxis::min
66 \qmlproperty real ValuesAxis::min
67 Defines the minimum value on the axis.
67 Defines the minimum value on the axis.
68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QValueAxis::max
72 \property QValueAxis::max
73 Defines the maximum value on the axis.
73 Defines the maximum value on the axis.
74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty real ValuesAxis::max
77 \qmlproperty real ValuesAxis::max
78 Defines the maximum value on the axis.
78 Defines the maximum value on the axis.
79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
80 */
80 */
81
81
82 /*!
82 /*!
83 \fn void QValueAxis::minChanged(qreal min)
83 \fn void QValueAxis::minChanged(qreal min)
84 Axis emits signal when \a min of axis has changed.
84 Axis emits signal when \a min of axis has changed.
85 */
85 */
86 /*!
86 /*!
87 \qmlsignal ValuesAxis::onMinChanged(real min)
87 \qmlsignal ValuesAxis::onMinChanged(real min)
88 Axis emits signal when \a min of axis has changed.
88 Axis emits signal when \a min of axis has changed.
89 */
89 */
90
90
91 /*!
91 /*!
92 \fn void QValueAxis::maxChanged(qreal max)
92 \fn void QValueAxis::maxChanged(qreal max)
93 Axis emits signal when \a max of axis has changed.
93 Axis emits signal when \a max of axis has changed.
94 */
94 */
95 /*!
95 /*!
96 \qmlsignal ValuesAxis::onMaxChanged(real max)
96 \qmlsignal ValuesAxis::onMaxChanged(real max)
97 Axis emits signal when \a max of axis has changed.
97 Axis emits signal when \a max of axis has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
101 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
102 Axis emits signal when \a min or \a max of axis has changed.
102 Axis emits signal when \a min or \a max of axis has changed.
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QValueAxis::ticksCount
106 \property QValueAxis::ticksCount
107 The number of tick marks for the axis.
107 The number of tick marks for the axis.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty int ValuesAxis::ticksCount
111 \qmlproperty int ValuesAxis::ticksCount
112 The number of tick marks for the axis.
112 The number of tick marks for the axis.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QValueAxis::niceNumbersEnabled
116 \property QValueAxis::niceNumbersEnabled
117 Whether the nice numbers algorithm is enabled or not for the axis.
117 Whether the nice numbers algorithm is enabled or not for the axis.
118 */
118 */
119
119
120 /*!
120 /*!
121 \qmlproperty bool ValuesAxis::niceNumbersEnabled
121 \qmlproperty bool ValuesAxis::niceNumbersEnabled
122 Whether the nice numbers algorithm is enabled or not for the axis.
122 Whether the nice numbers algorithm is enabled or not for the axis.
123 */
123 */
124
124
125 /*!
125 /*!
126 Constructs an axis object which is a child of \a parent.
126 Constructs an axis object which is a child of \a parent.
127 */
127 */
128 QValueAxis::QValueAxis(QObject *parent) :
128 QValueAxis::QValueAxis(QObject *parent) :
129 QAbstractAxis(*new QValueAxisPrivate(this),parent)
129 QAbstractAxis(*new QValueAxisPrivate(this),parent)
130 {
130 {
131
131
132 }
132 }
133
133
134 /*!
134 /*!
135 \internal
135 \internal
136 */
136 */
137 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
137 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
138 {
138 {
139
139
140 }
140 }
141
141
142 /*!
142 /*!
143 Destroys the object
143 Destroys the object
144 */
144 */
145 QValueAxis::~QValueAxis()
145 QValueAxis::~QValueAxis()
146 {
146 {
147 Q_D(QValueAxis);
147 Q_D(QValueAxis);
148 if(d->m_dataset) {
148 if(d->m_dataset) {
149 d->m_dataset->removeAxis(this);
149 d->m_dataset->removeAxis(this);
150 }
150 }
151 }
151 }
152
152
153 void QValueAxis::setMin(qreal min)
153 void QValueAxis::setMin(qreal min)
154 {
154 {
155 Q_D(QValueAxis);
155 Q_D(QValueAxis);
156 setRange(min, qMax(d->m_max, min));
156 setRange(min, qMax(d->m_max, min));
157 }
157 }
158
158
159 qreal QValueAxis::min() const
159 qreal QValueAxis::min() const
160 {
160 {
161 Q_D(const QValueAxis);
161 Q_D(const QValueAxis);
162 return d->m_min;
162 return d->m_min;
163 }
163 }
164
164
165 void QValueAxis::setMax(qreal max)
165 void QValueAxis::setMax(qreal max)
166 {
166 {
167 Q_D(QValueAxis);
167 Q_D(QValueAxis);
168 setRange(qMin(d->m_min, max), max);
168 setRange(qMin(d->m_min, max), max);
169 }
169 }
170
170
171 qreal QValueAxis::max() const
171 qreal QValueAxis::max() const
172 {
172 {
173 Q_D(const QValueAxis);
173 Q_D(const QValueAxis);
174 return d->m_max;
174 return d->m_max;
175 }
175 }
176
176
177 /*!
177 /*!
178 Sets range from \a min to \a max on the axis.
178 Sets range from \a min to \a max on the axis.
179 If min is greater than max then this function returns without making any changes.
179 If min is greater than max then this function returns without making any changes.
180 */
180 */
181 void QValueAxis::setRange(qreal min, qreal max)
181 void QValueAxis::setRange(qreal min, qreal max)
182 {
182 {
183 Q_D(QValueAxis);
183 Q_D(QValueAxis);
184 bool changed = false;
184 bool changed = false;
185
185
186 if (min > max) return;
186 if (min > max) return;
187
187
188 if(d->m_niceNumbers) {
188 if(d->m_niceNumbers) {
189 int ticks = d->m_tickCount;
189 int ticks = d->m_tickCount;
190 d->looseNiceNumbers(min, max, ticks);
190 d->looseNiceNumbers(min, max, ticks);
191 if(ticks!=d->m_tickCount) setTicksCount(ticks);
191 if(ticks!=d->m_tickCount) setTickCount(ticks);
192 }
192 }
193
193
194 if (!qFuzzyIsNull(d->m_min - min)) {
194 if (!qFuzzyIsNull(d->m_min - min)) {
195 d->m_min = min;
195 d->m_min = min;
196 changed = true;
196 changed = true;
197 emit minChanged(min);
197 emit minChanged(min);
198 }
198 }
199
199
200 if (!qFuzzyIsNull(d->m_max - max)) {
200 if (!qFuzzyIsNull(d->m_max - max)) {
201 d->m_max = max;
201 d->m_max = max;
202 changed = true;
202 changed = true;
203 emit maxChanged(max);
203 emit maxChanged(max);
204 }
204 }
205
205
206 if (changed) {
206 if (changed) {
207 emit rangeChanged(min,max);
207 emit rangeChanged(min,max);
208 d->emitUpdated();
208 d->emitUpdated();
209 }
209 }
210 }
210 }
211
211
212 /*!
212 /*!
213 Sets \a count for ticks on the axis.
213 Sets \a count for ticks on the axis.
214 */
214 */
215 void QValueAxis::setTicksCount(int count)
215 void QValueAxis::setTickCount(int count)
216 {
216 {
217 Q_D(QValueAxis);
217 Q_D(QValueAxis);
218 if (d->m_tickCount != count && count >=2) {
218 if (d->m_tickCount != count && count >=2) {
219 d->m_tickCount = count;
219 d->m_tickCount = count;
220 d->emitUpdated();
220 d->emitUpdated();
221 }
221 }
222 }
222 }
223
223
224 /*!
224 /*!
225 \fn int QValueAxis::ticksCount() const
225 \fn int QValueAxis::ticksCount() const
226 Return number of ticks on the axis
226 Return number of ticks on the axis
227 */
227 */
228 int QValueAxis::ticksCount() const
228 int QValueAxis::tickCount() const
229 {
229 {
230 Q_D(const QValueAxis);
230 Q_D(const QValueAxis);
231 return d->m_tickCount;
231 return d->m_tickCount;
232 }
232 }
233
233
234 void QValueAxis::setNiceNumbersEnabled(bool enable)
234 void QValueAxis::setNiceNumbersEnabled(bool enable)
235 {
235 {
236 Q_D(QValueAxis);
236 Q_D(QValueAxis);
237 if (d->m_niceNumbers != enable){
237 if (d->m_niceNumbers != enable){
238 d->m_niceNumbers = enable;
238 d->m_niceNumbers = enable;
239 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
239 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
240 setRange(d->m_min,d->m_max);
240 setRange(d->m_min,d->m_max);
241 }
241 }
242 }
242 }
243 }
243 }
244
244
245 bool QValueAxis::niceNumbersEnabled() const
245 bool QValueAxis::niceNumbersEnabled() const
246 {
246 {
247 Q_D(const QValueAxis);
247 Q_D(const QValueAxis);
248 return d->m_niceNumbers;
248 return d->m_niceNumbers;
249 }
249 }
250
250
251 /*!
251 /*!
252 Returns the type of the axis
252 Returns the type of the axis
253 */
253 */
254 QAbstractAxis::AxisType QValueAxis::type() const
254 QAbstractAxis::AxisType QValueAxis::type() const
255 {
255 {
256 return AxisTypeValues;
256 return AxisTypeValues;
257 }
257 }
258
258
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
260
260
261 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
261 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
262 QAbstractAxisPrivate(q),
262 QAbstractAxisPrivate(q),
263 m_min(0),
263 m_min(0),
264 m_max(0),
264 m_max(0),
265 m_tickCount(5),
265 m_tickCount(5),
266 m_niceNumbers(false)
266 m_niceNumbers(false)
267 {
267 {
268
268
269 }
269 }
270
270
271 QValueAxisPrivate::~QValueAxisPrivate()
271 QValueAxisPrivate::~QValueAxisPrivate()
272 {
272 {
273
273
274 }
274 }
275
275
276 void QValueAxisPrivate::handleDomainUpdated()
276 void QValueAxisPrivate::handleDomainUpdated()
277 {
277 {
278 Q_Q(QValueAxis);
278 Q_Q(QValueAxis);
279 Domain* domain = qobject_cast<Domain*>(sender());
279 Domain* domain = qobject_cast<Domain*>(sender());
280 Q_ASSERT(domain);
280 Q_ASSERT(domain);
281
281
282 if(orientation()==Qt::Horizontal){
282 if(orientation()==Qt::Horizontal){
283 q->setRange(domain->minX(),domain->maxX());
283 q->setRange(domain->minX(),domain->maxX());
284 }else if(orientation()==Qt::Vertical){
284 }else if(orientation()==Qt::Vertical){
285 q->setRange(domain->minY(),domain->maxY());
285 q->setRange(domain->minY(),domain->maxY());
286 }
286 }
287 }
287 }
288
288
289
289
290 void QValueAxisPrivate::setMin(const QVariant &min)
290 void QValueAxisPrivate::setMin(const QVariant &min)
291 {
291 {
292 Q_Q(QValueAxis);
292 Q_Q(QValueAxis);
293 bool ok;
293 bool ok;
294 qreal value = min.toReal(&ok);
294 qreal value = min.toReal(&ok);
295 if(ok) q->setMin(value);
295 if(ok) q->setMin(value);
296 }
296 }
297
297
298 void QValueAxisPrivate::setMax(const QVariant &max)
298 void QValueAxisPrivate::setMax(const QVariant &max)
299 {
299 {
300
300
301 Q_Q(QValueAxis);
301 Q_Q(QValueAxis);
302 bool ok;
302 bool ok;
303 qreal value = max.toReal(&ok);
303 qreal value = max.toReal(&ok);
304 if(ok) q->setMax(value);
304 if(ok) q->setMax(value);
305 }
305 }
306
306
307 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
307 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
308 {
308 {
309 Q_Q(QValueAxis);
309 Q_Q(QValueAxis);
310 bool ok1;
310 bool ok1;
311 bool ok2;
311 bool ok2;
312 qreal value1 = min.toReal(&ok1);
312 qreal value1 = min.toReal(&ok1);
313 qreal value2 = max.toReal(&ok2);
313 qreal value2 = max.toReal(&ok2);
314 if(ok1&&ok2) q->setRange(value1,value2);
314 if(ok1&&ok2) q->setRange(value1,value2);
315 }
315 }
316
316
317 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
317 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
318 {
318 {
319 Q_Q(QValueAxis);
319 Q_Q(QValueAxis);
320 if(m_orientation == Qt::Vertical){
320 if(m_orientation == Qt::Vertical){
321 return new ChartValueAxisY(q,presenter);
321 return new ChartValueAxisY(q,presenter);
322 }else{
322 }else{
323 return new ChartValueAxisX(q,presenter);
323 return new ChartValueAxisX(q,presenter);
324 }
324 }
325
325
326 }
326 }
327
327
328 void QValueAxisPrivate::intializeDomain(Domain* domain)
328 void QValueAxisPrivate::intializeDomain(Domain* domain)
329 {
329 {
330 Q_Q(QValueAxis);
330 Q_Q(QValueAxis);
331 if(qFuzzyCompare(m_max,m_min)) {
331 if(qFuzzyCompare(m_max,m_min)) {
332 if(m_orientation==Qt::Vertical){
332 if(m_orientation==Qt::Vertical){
333 q->setRange(domain->minY(),domain->maxY());
333 q->setRange(domain->minY(),domain->maxY());
334 }else{
334 }else{
335 q->setRange(domain->minX(), domain->maxX());
335 q->setRange(domain->minX(), domain->maxX());
336 }
336 }
337 } else {
337 } else {
338 if(m_orientation==Qt::Vertical){
338 if(m_orientation==Qt::Vertical){
339 domain->setRangeY(m_min, m_max);
339 domain->setRangeY(m_min, m_max);
340 }else{
340 }else{
341 domain->setRangeX(m_min, m_max);
341 domain->setRangeX(m_min, m_max);
342 }
342 }
343 }
343 }
344 }
344 }
345
345
346 //algorithm defined by Paul S.Heckbert GraphicalGems I
346 //algorithm defined by Paul S.Heckbert GraphicalGems I
347
347
348 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
348 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
349 {
349 {
350 qreal range = niceNumber(max-min,true); //range with ceiling
350 qreal range = niceNumber(max-min,true); //range with ceiling
351 qreal step = niceNumber(range/(ticksCount-1),false);
351 qreal step = niceNumber(range/(ticksCount-1),false);
352 min = qFloor(min/step);
352 min = qFloor(min/step);
353 max = qCeil(max/step);
353 max = qCeil(max/step);
354 ticksCount = int(max-min) +1;
354 ticksCount = int(max-min) +1;
355 min*=step;
355 min*=step;
356 max*=step;
356 max*=step;
357 }
357 }
358
358
359 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
359 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
360
360
361 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
361 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
362 {
362 {
363 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
363 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
364 qreal q = x/z;//q<10 && q>=1;
364 qreal q = x/z;//q<10 && q>=1;
365
365
366 if(ceiling) {
366 if(ceiling) {
367 if(q <= 1.0) q=1;
367 if(q <= 1.0) q=1;
368 else if(q <= 2.0) q=2;
368 else if(q <= 2.0) q=2;
369 else if(q <= 5.0) q=5;
369 else if(q <= 5.0) q=5;
370 else q=10;
370 else q=10;
371 }
371 }
372 else {
372 else {
373 if(q < 1.5) q=1;
373 if(q < 1.5) q=1;
374 else if(q < 3.0) q=2;
374 else if(q < 3.0) q=2;
375 else if(q < 7.0) q=5;
375 else if(q < 7.0) q=5;
376 else q=10;
376 else q=10;
377 }
377 }
378 return q*z;
378 return q*z;
379 }
379 }
380
380
381 #include "moc_qvalueaxis.cpp"
381 #include "moc_qvalueaxis.cpp"
382 #include "moc_qvalueaxis_p.cpp"
382 #include "moc_qvalueaxis_p.cpp"
383
383
384 QTCOMMERCIALCHART_END_NAMESPACE
384 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,74
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QVALUESAXIS_H
21 #ifndef QVALUESAXIS_H
22 #define QVALUESAXIS_H
22 #define QVALUESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QValueAxisPrivate;
28 class QValueAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(int ticksCount READ ticksCount WRITE setTicksCount)
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37
37
38 public:
38 public:
39 explicit QValueAxis(QObject *parent = 0);
39 explicit QValueAxis(QObject *parent = 0);
40 ~QValueAxis();
40 ~QValueAxis();
41
41
42 protected:
42 protected:
43 QValueAxis(QValueAxisPrivate &d,QObject *parent = 0);
43 QValueAxis(QValueAxisPrivate &d,QObject *parent = 0);
44
44
45 public:
45 public:
46 AxisType type() const;
46 AxisType type() const;
47
47
48 //range handling
48 //range handling
49 void setMin(qreal min);
49 void setMin(qreal min);
50 qreal min() const;
50 qreal min() const;
51 void setMax(qreal max);
51 void setMax(qreal max);
52 qreal max() const;
52 qreal max() const;
53 void setRange(qreal min, qreal max);
53 void setRange(qreal min, qreal max);
54
54
55 //ticks handling
55 //ticks handling
56 void setTicksCount(int count);
56 void setTickCount(int count);
57 int ticksCount() const;
57 int tickCount() const;
58
58
59 void setNiceNumbersEnabled(bool enable = true);
59 void setNiceNumbersEnabled(bool enable = true);
60 bool niceNumbersEnabled() const;
60 bool niceNumbersEnabled() const;
61
61
62 Q_SIGNALS:
62 Q_SIGNALS:
63 void minChanged(qreal min);
63 void minChanged(qreal min);
64 void maxChanged(qreal max);
64 void maxChanged(qreal max);
65 void rangeChanged(qreal min, qreal max);
65 void rangeChanged(qreal min, qreal max);
66
66
67 private:
67 private:
68 Q_DECLARE_PRIVATE(QValueAxis)
68 Q_DECLARE_PRIVATE(QValueAxis)
69 Q_DISABLE_COPY(QValueAxis)
69 Q_DISABLE_COPY(QValueAxis)
70 };
70 };
71
71
72 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
73
73
74 #endif // QVALUESAXIS_H
74 #endif // QVALUESAXIS_H
@@ -1,415 +1,415
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "../qabstractaxis/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qvalueaxis.h"
22 #include "qvalueaxis.h"
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24
24
25 class tst_QValueAxis: public tst_QAbstractAxis
25 class tst_QValueAxis: public tst_QAbstractAxis
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28
28
29 public slots:
29 public slots:
30 void initTestCase();
30 void initTestCase();
31 void cleanupTestCase();
31 void cleanupTestCase();
32 void init();
32 void init();
33 void cleanup();
33 void cleanup();
34
34
35 private slots:
35 private slots:
36 void qvalueaxis_data();
36 void qvalueaxis_data();
37 void qvalueaxis();
37 void qvalueaxis();
38 void max_raw_data();
38 void max_raw_data();
39 void max_raw();
39 void max_raw();
40 void max_data();
40 void max_data();
41 void max();
41 void max();
42 void max_animation_data();
42 void max_animation_data();
43 void max_animation();
43 void max_animation();
44 void min_raw_data();
44 void min_raw_data();
45 void min_raw();
45 void min_raw();
46 void min_data();
46 void min_data();
47 void min();
47 void min();
48 void min_animation_data();
48 void min_animation_data();
49 void min_animation();
49 void min_animation();
50 void niceNumbersEnabled_data();
50 void niceNumbersEnabled_data();
51 void niceNumbersEnabled();
51 void niceNumbersEnabled();
52 void range_raw_data();
52 void range_raw_data();
53 void range_raw();
53 void range_raw();
54 void range_data();
54 void range_data();
55 void range();
55 void range();
56 void range_animation_data();
56 void range_animation_data();
57 void range_animation();
57 void range_animation();
58 void ticksCount_data();
58 void ticksCount_data();
59 void ticksCount();
59 void ticksCount();
60 void noautoscale_data();
60 void noautoscale_data();
61 void noautoscale();
61 void noautoscale();
62 void autoscale_data();
62 void autoscale_data();
63 void autoscale();
63 void autoscale();
64
64
65 private:
65 private:
66 QValueAxis* m_valuesaxis;
66 QValueAxis* m_valuesaxis;
67 QLineSeries* m_series;
67 QLineSeries* m_series;
68 };
68 };
69
69
70 void tst_QValueAxis::initTestCase()
70 void tst_QValueAxis::initTestCase()
71 {
71 {
72 }
72 }
73
73
74 void tst_QValueAxis::cleanupTestCase()
74 void tst_QValueAxis::cleanupTestCase()
75 {
75 {
76 }
76 }
77
77
78 void tst_QValueAxis::init()
78 void tst_QValueAxis::init()
79 {
79 {
80 m_valuesaxis = new QValueAxis();
80 m_valuesaxis = new QValueAxis();
81 m_series = new QLineSeries();
81 m_series = new QLineSeries();
82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
84 m_chart->addSeries(m_series);
84 m_chart->addSeries(m_series);
85 m_chart->createDefaultAxes();
85 m_chart->createDefaultAxes();
86 }
86 }
87
87
88 void tst_QValueAxis::cleanup()
88 void tst_QValueAxis::cleanup()
89 {
89 {
90 delete m_series;
90 delete m_series;
91 delete m_valuesaxis;
91 delete m_valuesaxis;
92 m_series = 0;
92 m_series = 0;
93 m_valuesaxis = 0;
93 m_valuesaxis = 0;
94 tst_QAbstractAxis::cleanup();
94 tst_QAbstractAxis::cleanup();
95 }
95 }
96
96
97 void tst_QValueAxis::qvalueaxis_data()
97 void tst_QValueAxis::qvalueaxis_data()
98 {
98 {
99 }
99 }
100
100
101 void tst_QValueAxis::qvalueaxis()
101 void tst_QValueAxis::qvalueaxis()
102 {
102 {
103 qabstractaxis();
103 qabstractaxis();
104
104
105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
108 QCOMPARE(m_valuesaxis->ticksCount(), 5);
108 QCOMPARE(m_valuesaxis->tickCount(), 5);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
110
110
111 m_chart->setAxisX(m_valuesaxis, m_series);
111 m_chart->setAxisX(m_valuesaxis, m_series);
112 m_view->show();
112 m_view->show();
113 QTest::qWaitForWindowShown(m_view);
113 QTest::qWaitForWindowShown(m_view);
114
114
115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
118 QCOMPARE(m_valuesaxis->ticksCount(), 5);
118 QCOMPARE(m_valuesaxis->tickCount(), 5);
119 }
119 }
120
120
121 void tst_QValueAxis::max_raw_data()
121 void tst_QValueAxis::max_raw_data()
122 {
122 {
123 QTest::addColumn<qreal>("max");
123 QTest::addColumn<qreal>("max");
124 QTest::newRow("1.0") << 1.0;
124 QTest::newRow("1.0") << 1.0;
125 QTest::newRow("50.0") << 50.0;
125 QTest::newRow("50.0") << 50.0;
126 QTest::newRow("101.0") << 101.0;
126 QTest::newRow("101.0") << 101.0;
127 }
127 }
128
128
129 void tst_QValueAxis::max_raw()
129 void tst_QValueAxis::max_raw()
130 {
130 {
131 QFETCH(qreal, max);
131 QFETCH(qreal, max);
132
132
133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
136
136
137 m_valuesaxis->setMax(max);
137 m_valuesaxis->setMax(max);
138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
139
139
140 QCOMPARE(spy0.count(), 1);
140 QCOMPARE(spy0.count(), 1);
141 QCOMPARE(spy1.count(), 0);
141 QCOMPARE(spy1.count(), 0);
142 QCOMPARE(spy2.count(), 1);
142 QCOMPARE(spy2.count(), 1);
143
143
144 }
144 }
145
145
146 void tst_QValueAxis::max_data()
146 void tst_QValueAxis::max_data()
147 {
147 {
148 max_raw_data();
148 max_raw_data();
149 }
149 }
150
150
151 void tst_QValueAxis::max()
151 void tst_QValueAxis::max()
152 {
152 {
153 m_chart->setAxisX(m_valuesaxis, m_series);
153 m_chart->setAxisX(m_valuesaxis, m_series);
154 m_view->show();
154 m_view->show();
155 QTest::qWaitForWindowShown(m_view);
155 QTest::qWaitForWindowShown(m_view);
156 max_raw();
156 max_raw();
157 }
157 }
158
158
159 void tst_QValueAxis::max_animation_data()
159 void tst_QValueAxis::max_animation_data()
160 {
160 {
161 max_data();
161 max_data();
162 }
162 }
163
163
164 void tst_QValueAxis::max_animation()
164 void tst_QValueAxis::max_animation()
165 {
165 {
166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
167 max();
167 max();
168 }
168 }
169
169
170 void tst_QValueAxis::min_raw_data()
170 void tst_QValueAxis::min_raw_data()
171 {
171 {
172 QTest::addColumn<qreal>("min");
172 QTest::addColumn<qreal>("min");
173 QTest::newRow("-1.0") << -1.0;
173 QTest::newRow("-1.0") << -1.0;
174 QTest::newRow("-50.0") << -50.0;
174 QTest::newRow("-50.0") << -50.0;
175 QTest::newRow("-101.0") << -101.0;
175 QTest::newRow("-101.0") << -101.0;
176 }
176 }
177
177
178 void tst_QValueAxis::min_raw()
178 void tst_QValueAxis::min_raw()
179 {
179 {
180 QFETCH(qreal, min);
180 QFETCH(qreal, min);
181
181
182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
185
185
186 m_valuesaxis->setMin(min);
186 m_valuesaxis->setMin(min);
187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
188
188
189 QCOMPARE(spy0.count(), 0);
189 QCOMPARE(spy0.count(), 0);
190 QCOMPARE(spy1.count(), 1);
190 QCOMPARE(spy1.count(), 1);
191 QCOMPARE(spy2.count(), 1);
191 QCOMPARE(spy2.count(), 1);
192 }
192 }
193
193
194 void tst_QValueAxis::min_data()
194 void tst_QValueAxis::min_data()
195 {
195 {
196 min_raw_data();
196 min_raw_data();
197 }
197 }
198
198
199 void tst_QValueAxis::min()
199 void tst_QValueAxis::min()
200 {
200 {
201 m_chart->setAxisX(m_valuesaxis, m_series);
201 m_chart->setAxisX(m_valuesaxis, m_series);
202 m_view->show();
202 m_view->show();
203 QTest::qWaitForWindowShown(m_view);
203 QTest::qWaitForWindowShown(m_view);
204 min_raw();
204 min_raw();
205 }
205 }
206
206
207 void tst_QValueAxis::min_animation_data()
207 void tst_QValueAxis::min_animation_data()
208 {
208 {
209 min_data();
209 min_data();
210 }
210 }
211
211
212 void tst_QValueAxis::min_animation()
212 void tst_QValueAxis::min_animation()
213 {
213 {
214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
215 min();
215 min();
216 }
216 }
217
217
218 void tst_QValueAxis::niceNumbersEnabled_data()
218 void tst_QValueAxis::niceNumbersEnabled_data()
219 {
219 {
220 QTest::addColumn<bool>("niceNumbersEnabled");
220 QTest::addColumn<bool>("niceNumbersEnabled");
221 QTest::addColumn<qreal>("min");
221 QTest::addColumn<qreal>("min");
222 QTest::addColumn<qreal>("max");
222 QTest::addColumn<qreal>("max");
223 QTest::addColumn<int>("ticks");
223 QTest::addColumn<int>("ticks");
224 QTest::addColumn<qreal>("expectedMin");
224 QTest::addColumn<qreal>("expectedMin");
225 QTest::addColumn<qreal>("expectedMax");
225 QTest::addColumn<qreal>("expectedMax");
226 QTest::addColumn<int>("expectedTicks");
226 QTest::addColumn<int>("expectedTicks");
227 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
227 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
228 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
228 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
229 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
229 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
230 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
230 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
231 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
231 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
232 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
232 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
233 }
233 }
234
234
235 void tst_QValueAxis::niceNumbersEnabled()
235 void tst_QValueAxis::niceNumbersEnabled()
236 {
236 {
237 QFETCH(bool, niceNumbersEnabled);
237 QFETCH(bool, niceNumbersEnabled);
238 QFETCH(qreal, min);
238 QFETCH(qreal, min);
239 QFETCH(qreal, max);
239 QFETCH(qreal, max);
240 QFETCH(int, ticks);
240 QFETCH(int, ticks);
241 QFETCH(qreal, expectedMin);
241 QFETCH(qreal, expectedMin);
242 QFETCH(qreal, expectedMax);
242 QFETCH(qreal, expectedMax);
243 QFETCH(int, expectedTicks);
243 QFETCH(int, expectedTicks);
244
244
245 m_valuesaxis->setRange(min, max);
245 m_valuesaxis->setRange(min, max);
246 m_valuesaxis->setTicksCount(ticks);
246 m_valuesaxis->setTickCount(ticks);
247
247
248 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
248 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
249 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
249 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
250
250
251 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
251 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
252 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
252 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
253 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
253 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
254
254
255 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
255 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
256 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
256 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
257
257
258 if(!qFuzzyIsNull(expectedMin - min))
258 if(!qFuzzyIsNull(expectedMin - min))
259 QCOMPARE(spy1.count(), 1);
259 QCOMPARE(spy1.count(), 1);
260 if(!qFuzzyIsNull(expectedMax - max))
260 if(!qFuzzyIsNull(expectedMax - max))
261 QCOMPARE(spy0.count(), 1);
261 QCOMPARE(spy0.count(), 1);
262 if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max)))
262 if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max)))
263 QCOMPARE(spy2.count(), 1);
263 QCOMPARE(spy2.count(), 1);
264
264
265 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
265 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
266 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
266 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
267 QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks);
267 QCOMPARE(m_valuesaxis->tickCount(), expectedTicks);
268
268
269 }
269 }
270
270
271 void tst_QValueAxis::range_raw_data()
271 void tst_QValueAxis::range_raw_data()
272 {
272 {
273 QTest::addColumn<qreal>("min");
273 QTest::addColumn<qreal>("min");
274 QTest::addColumn<qreal>("max");
274 QTest::addColumn<qreal>("max");
275 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
275 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
276 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
276 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
277 QTest::newRow("101.0") << 40.0 << 60.0;
277 QTest::newRow("101.0") << 40.0 << 60.0;
278 }
278 }
279
279
280 void tst_QValueAxis::range_raw()
280 void tst_QValueAxis::range_raw()
281 {
281 {
282 QFETCH(qreal, min);
282 QFETCH(qreal, min);
283 QFETCH(qreal, max);
283 QFETCH(qreal, max);
284
284
285 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
285 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
286 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
286 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
287 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
287 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
288
288
289 m_valuesaxis->setRange(min, max);
289 m_valuesaxis->setRange(min, max);
290 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
290 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
291 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
291 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
292
292
293 QCOMPARE(spy0.count(), 1);
293 QCOMPARE(spy0.count(), 1);
294 QCOMPARE(spy1.count(), 1);
294 QCOMPARE(spy1.count(), 1);
295 QCOMPARE(spy2.count(), 1);
295 QCOMPARE(spy2.count(), 1);
296 }
296 }
297
297
298 void tst_QValueAxis::range_data()
298 void tst_QValueAxis::range_data()
299 {
299 {
300 range_raw_data();
300 range_raw_data();
301 }
301 }
302
302
303 void tst_QValueAxis::range()
303 void tst_QValueAxis::range()
304 {
304 {
305 m_chart->setAxisX(m_valuesaxis, m_series);
305 m_chart->setAxisX(m_valuesaxis, m_series);
306 m_view->show();
306 m_view->show();
307 QTest::qWaitForWindowShown(m_view);
307 QTest::qWaitForWindowShown(m_view);
308 range_raw();
308 range_raw();
309 }
309 }
310
310
311 void tst_QValueAxis::range_animation_data()
311 void tst_QValueAxis::range_animation_data()
312 {
312 {
313 range_data();
313 range_data();
314 }
314 }
315
315
316 void tst_QValueAxis::range_animation()
316 void tst_QValueAxis::range_animation()
317 {
317 {
318 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
318 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
319 range();
319 range();
320 }
320 }
321
321
322 void tst_QValueAxis::ticksCount_data()
322 void tst_QValueAxis::ticksCount_data()
323 {
323 {
324 QTest::addColumn<int>("ticksCount");
324 QTest::addColumn<int>("ticksCount");
325 QTest::addColumn<int>("expectedCount");
325 QTest::addColumn<int>("expectedCount");
326 QTest::newRow("0") << 2;
326 QTest::newRow("0") << 2;
327 QTest::newRow("1") << 2;
327 QTest::newRow("1") << 2;
328 QTest::newRow("2") << 2;
328 QTest::newRow("2") << 2;
329 QTest::newRow("3") << 3;
329 QTest::newRow("3") << 3;
330 QTest::newRow("-1") << 2;
330 QTest::newRow("-1") << 2;
331 }
331 }
332
332
333 void tst_QValueAxis::ticksCount()
333 void tst_QValueAxis::ticksCount()
334 {
334 {
335 QFETCH(int, ticksCount);
335 QFETCH(int, ticksCount);
336
336
337 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
337 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
338 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
338 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
339 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
339 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
340
340
341 m_valuesaxis->setTicksCount(ticksCount);
341 m_valuesaxis->setTickCount(ticksCount);
342 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
342 QCOMPARE(m_valuesaxis->tickCount(), ticksCount);
343
343
344 QCOMPARE(spy0.count(), 0);
344 QCOMPARE(spy0.count(), 0);
345 QCOMPARE(spy1.count(), 0);
345 QCOMPARE(spy1.count(), 0);
346 QCOMPARE(spy2.count(), 0);
346 QCOMPARE(spy2.count(), 0);
347
347
348 m_chart->setAxisX(m_valuesaxis, m_series);
348 m_chart->setAxisX(m_valuesaxis, m_series);
349 m_view->show();
349 m_view->show();
350 QTest::qWaitForWindowShown(m_view);
350 QTest::qWaitForWindowShown(m_view);
351
351
352 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
352 QCOMPARE(m_valuesaxis->tickCount(), ticksCount);
353 }
353 }
354
354
355 void tst_QValueAxis::noautoscale_data()
355 void tst_QValueAxis::noautoscale_data()
356 {
356 {
357 QTest::addColumn<qreal>("min");
357 QTest::addColumn<qreal>("min");
358 QTest::addColumn<qreal>("max");
358 QTest::addColumn<qreal>("max");
359 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
359 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
360 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
360 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
361 QTest::newRow("101.0") << 40.0 << 60.0;
361 QTest::newRow("101.0") << 40.0 << 60.0;
362 }
362 }
363
363
364 void tst_QValueAxis::noautoscale()
364 void tst_QValueAxis::noautoscale()
365 {
365 {
366 QFETCH(qreal, min);
366 QFETCH(qreal, min);
367 QFETCH(qreal, max);
367 QFETCH(qreal, max);
368
368
369 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
369 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
370 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
370 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
371 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
371 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
372
372
373 m_valuesaxis->setRange(min, max);
373 m_valuesaxis->setRange(min, max);
374 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
374 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
375 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
375 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
376
376
377 QCOMPARE(spy0.count(), 1);
377 QCOMPARE(spy0.count(), 1);
378 QCOMPARE(spy1.count(), 1);
378 QCOMPARE(spy1.count(), 1);
379 QCOMPARE(spy2.count(), 1);
379 QCOMPARE(spy2.count(), 1);
380
380
381 m_chart->setAxisX(m_valuesaxis, m_series);
381 m_chart->setAxisX(m_valuesaxis, m_series);
382 m_view->show();
382 m_view->show();
383 QTest::qWaitForWindowShown(m_view);
383 QTest::qWaitForWindowShown(m_view);
384 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
384 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
385 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
385 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
386 }
386 }
387
387
388 void tst_QValueAxis::autoscale_data()
388 void tst_QValueAxis::autoscale_data()
389 {
389 {
390
390
391 }
391 }
392
392
393 void tst_QValueAxis::autoscale()
393 void tst_QValueAxis::autoscale()
394 {
394 {
395 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
395 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
396 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
396 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
397 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
397 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
398
398
399 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
399 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
400 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
400 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
401 m_chart->setAxisX(m_valuesaxis, m_series);
401 m_chart->setAxisX(m_valuesaxis, m_series);
402
402
403 QCOMPARE(spy0.count(), 1);
403 QCOMPARE(spy0.count(), 1);
404 QCOMPARE(spy1.count(), 1);
404 QCOMPARE(spy1.count(), 1);
405 QCOMPARE(spy2.count(), 1);
405 QCOMPARE(spy2.count(), 1);
406
406
407 m_view->show();
407 m_view->show();
408 QTest::qWaitForWindowShown(m_view);
408 QTest::qWaitForWindowShown(m_view);
409 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
409 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
410 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
410 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
411 }
411 }
412
412
413 QTEST_MAIN(tst_QValueAxis)
413 QTEST_MAIN(tst_QValueAxis)
414 #include "tst_qvalueaxis.moc"
414 #include "tst_qvalueaxis.moc"
415
415
General Comments 0
You need to be logged in to leave comments. Login now