@@ -1,130 +1,131 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartcategoryaxisx_p.h" |
|
22 | 22 | #include "qcategoryaxis.h" |
|
23 | 23 | #include "qabstractaxis.h" |
|
24 | 24 | #include "chartpresenter_p.h" |
|
25 | 25 | #include <QGraphicsLayout> |
|
26 | 26 | #include <QFontMetrics> |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | 29 | static int label_padding = 5; |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | ChartCategoryAxisX::ChartCategoryAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
34 | 34 | { |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | ChartCategoryAxisX::~ChartCategoryAxisX() |
|
38 | 38 | { |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | QVector<qreal> ChartCategoryAxisX::calculateLayout() const |
|
42 | 42 | { |
|
43 | 43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
44 | 44 | int tickCount = axis->categoriesLabels().count() + 1; |
|
45 | 45 | QVector<qreal> points; |
|
46 | 46 | |
|
47 | 47 | if (tickCount < 2) |
|
48 | 48 | return points; |
|
49 | 49 | |
|
50 | points.resize(tickCount); | |
|
51 | ||
|
52 | qreal scale = m_rect.width() / axis->max(); | |
|
53 | for (int i = 0; i < tickCount; ++i) | |
|
54 |
|
|
|
55 | int x = axis->categoryStart(axis->categoriesLabels().at(i)) * scale + m_rect.left(); | |
|
56 | points[i] = x; | |
|
57 | } else { | |
|
58 | int x = axis->categoryEnd(axis->categoriesLabels().at(i - 1)) * scale + m_rect.left(); | |
|
59 | points[i] = x; | |
|
60 | } | |
|
61 | ||
|
50 | qreal range = axis->max() - axis->min(); | |
|
51 | if (range > 0) { | |
|
52 | points.resize(tickCount); | |
|
53 | qreal scale = m_rect.width() / range; | |
|
54 | for (int i = 0; i < tickCount; ++i) | |
|
55 | if (i < tickCount - 1) { | |
|
56 | int x = (axis->categoryStart(axis->categoriesLabels().at(i)) - axis->min()) * scale + m_rect.left(); | |
|
57 | points[i] = x; | |
|
58 | } else { | |
|
59 | int x = (axis->categoryEnd(axis->categoriesLabels().at(i - 1)) - axis->min()) * scale + m_rect.left(); | |
|
60 | points[i] = x; | |
|
61 | } | |
|
62 | } | |
|
62 | 63 | return points; |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | void ChartCategoryAxisX::updateGeometry() |
|
66 | 67 | { |
|
67 | 68 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
68 | 69 | |
|
69 | 70 | m_minWidth = 0; |
|
70 | 71 | m_minHeight = 0; |
|
71 | 72 | |
|
72 | 73 | if(layout.isEmpty()) return; |
|
73 | 74 | |
|
74 | 75 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
75 | 76 | |
|
76 | 77 | QStringList ticksList = intervalAxis->categoriesLabels(); |
|
77 | 78 | |
|
78 | 79 | // createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
79 | 80 | |
|
80 | 81 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
81 | 82 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
82 | 83 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
83 | 84 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
84 | 85 | |
|
85 | 86 | // Q_ASSERT(labels.size() == ticksList.size()); |
|
86 | 87 | // Q_ASSERT(layout.size() == ticksList.size()); |
|
87 | 88 | |
|
88 | 89 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
89 | 90 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
90 | 91 | |
|
91 | 92 | // qreal width = 0; |
|
92 | 93 | for (int i = 0; i < layout.size(); ++i) { |
|
93 | 94 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
94 | 95 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
95 | 96 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
96 | 97 | if (i < ticksList.count()) { |
|
97 | 98 | labelItem->setText(ticksList.at(i)); |
|
98 | 99 | } |
|
99 | 100 | const QRectF& rect = labelItem->boundingRect(); |
|
100 | 101 | QPointF center = rect.center(); |
|
101 | 102 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
102 | 103 | if (i < ticksList.count()) |
|
103 | 104 | labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding); |
|
104 | 105 | else |
|
105 | 106 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
106 | 107 | |
|
107 | 108 | if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){ |
|
108 | 109 | labelItem->setVisible(false); |
|
109 | 110 | lineItem->setVisible(false); |
|
110 | 111 | } |
|
111 | 112 | |
|
112 | 113 | m_minWidth += rect.width(); |
|
113 | 114 | m_minHeight = qMax(rect.height()+ label_padding, m_minHeight); |
|
114 | 115 | |
|
115 | 116 | if ((i + 1) % 2 && i > 1) { |
|
116 | 117 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); |
|
117 | 118 | rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height()); |
|
118 | 119 | } |
|
119 | 120 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
120 | 121 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5); |
|
121 | 122 | } |
|
122 | 123 | } |
|
123 | 124 | |
|
124 | 125 | void ChartCategoryAxisX::handleAxisUpdated() |
|
125 | 126 | { |
|
126 | 127 | updateGeometry(); |
|
127 | 128 | ChartAxis::handleAxisUpdated(); |
|
128 | 129 | } |
|
129 | 130 | |
|
130 | 131 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,138 +1,140 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartcategoryaxisy_p.h" |
|
22 | 22 | #include "qcategoryaxis.h" |
|
23 | 23 | #include "qabstractaxis.h" |
|
24 | 24 | #include "chartpresenter_p.h" |
|
25 | 25 | #include <QGraphicsLayout> |
|
26 | 26 | #include <QFontMetrics> |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | 29 | static int label_padding = 5; |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | ChartCategoryAxisY::ChartCategoryAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
34 | 34 | { |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | ChartCategoryAxisY::~ChartCategoryAxisY() |
|
38 | 38 | { |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | QVector<qreal> ChartCategoryAxisY::calculateLayout() const |
|
42 | 42 | { |
|
43 | 43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
44 | 44 | int tickCount = axis->categoriesLabels().count() + 1; |
|
45 | 45 | QVector<qreal> points; |
|
46 | 46 | |
|
47 | 47 | if (tickCount < 2) |
|
48 | 48 | return points; |
|
49 | 49 | |
|
50 | points.resize(tickCount); | |
|
51 | ||
|
52 | qreal scale = m_rect.height() / axis->max(); | |
|
53 | for (int i = 0; i < tickCount; ++i) | |
|
54 |
|
|
|
55 | int y = -axis->categoryStart(axis->categoriesLabels().at(i)) * scale + m_rect.bottom(); | |
|
56 | points[i] = y; | |
|
57 | } else { | |
|
58 | int y = -axis->categoryEnd(axis->categoriesLabels().at(i - 1)) * scale + m_rect.bottom(); | |
|
59 | points[i] = y; | |
|
60 | } | |
|
50 | qreal range = axis->max() - axis->min(); | |
|
51 | if (range > 0) { | |
|
52 | points.resize(tickCount); | |
|
53 | qreal scale = m_rect.height() / range; | |
|
54 | for (int i = 0; i < tickCount; ++i) | |
|
55 | if (i < tickCount - 1) { | |
|
56 | int y = -(axis->categoryStart(axis->categoriesLabels().at(i)) - axis->min()) * scale + m_rect.bottom(); | |
|
57 | points[i] = y; | |
|
58 | } else { | |
|
59 | int y = -(axis->categoryEnd(axis->categoriesLabels().at(i - 1)) - axis->min()) * scale + m_rect.bottom(); | |
|
60 | points[i] = y; | |
|
61 | } | |
|
62 | } | |
|
61 | 63 | |
|
62 | 64 | return points; |
|
63 | 65 | } |
|
64 | 66 | |
|
65 | 67 | void ChartCategoryAxisY::updateGeometry() |
|
66 | 68 | { |
|
67 | 69 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
68 | 70 | m_minWidth = 0; |
|
69 | 71 | m_minHeight = 0; |
|
70 | 72 | |
|
71 | 73 | if(layout.isEmpty()) { |
|
72 | 74 | return; |
|
73 | 75 | } |
|
74 | 76 | |
|
75 | 77 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
76 | 78 | |
|
77 | 79 | QStringList ticksList = intervalAxis->categoriesLabels(); |
|
78 | 80 | |
|
79 | 81 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
80 | 82 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
81 | 83 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
82 | 84 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
83 | 85 | |
|
84 | 86 | // Q_ASSERT(labels.size() == ticksList.size()); |
|
85 | 87 | // Q_ASSERT(layout.size() == ticksList.size()); |
|
86 | 88 | |
|
87 | 89 | qreal height = 2*m_rect.bottom(); |
|
88 | 90 | |
|
89 | 91 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
90 | 92 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
91 | 93 | |
|
92 | 94 | for (int i = 0; i < layout.size(); ++i) { |
|
93 | 95 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
94 | 96 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
95 | 97 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
96 | 98 | |
|
97 | 99 | if (i < ticksList.count()) { |
|
98 | 100 | labelItem->setText(ticksList.at(i)); |
|
99 | 101 | } |
|
100 | 102 | const QRectF& rect = labelItem->boundingRect(); |
|
101 | 103 | |
|
102 | 104 | QPointF center = rect.center(); |
|
103 | 105 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
104 | 106 | |
|
105 | 107 | if (i < ticksList.count()) |
|
106 | 108 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y()); |
|
107 | 109 | else |
|
108 | 110 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
109 | 111 | |
|
110 | 112 | if(labelItem->pos().y()+rect.height()>height) { |
|
111 | 113 | labelItem->setVisible(false); |
|
112 | 114 | lineItem->setVisible(false); |
|
113 | 115 | } |
|
114 | 116 | else { |
|
115 | 117 | labelItem->setVisible(true); |
|
116 | 118 | lineItem->setVisible(true); |
|
117 | 119 | height=labelItem->pos().y(); |
|
118 | 120 | } |
|
119 | 121 | |
|
120 | 122 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
121 | 123 | m_minHeight+=rect.height(); |
|
122 | 124 | |
|
123 | 125 | if ((i+1)%2 && i>1) { |
|
124 | 126 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
125 | 127 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
126 | 128 | } |
|
127 | 129 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
128 | 130 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
129 | 131 | } |
|
130 | 132 | } |
|
131 | 133 | |
|
132 | 134 | void ChartCategoryAxisY::handleAxisUpdated() |
|
133 | 135 | { |
|
134 | 136 | updateGeometry(); |
|
135 | 137 | ChartAxis::handleAxisUpdated(); |
|
136 | 138 | } |
|
137 | 139 | |
|
138 | 140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,304 +1,307 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "../qabstractaxis/tst_qabstractaxis.h" |
|
22 | 22 | #include "qcategoryaxis.h" |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | |
|
25 | 25 | class tst_QCategoryAxis: public tst_QAbstractAxis |
|
26 | 26 | { |
|
27 | 27 | Q_OBJECT |
|
28 | 28 | |
|
29 | 29 | public slots: |
|
30 | 30 | void initTestCase(); |
|
31 | 31 | void cleanupTestCase(); |
|
32 | 32 | void init(); |
|
33 | 33 | void cleanup(); |
|
34 | 34 | |
|
35 | 35 | private slots: |
|
36 | 36 | void qcategoryaxis_data(); |
|
37 | 37 | void qcategoryaxis(); |
|
38 | 38 | |
|
39 | 39 | void max_raw_data(); |
|
40 | 40 | void max_raw(); |
|
41 | 41 | void max_data(); |
|
42 | 42 | void max(); |
|
43 | 43 | void max_animation_data(); |
|
44 | 44 | void max_animation(); |
|
45 | 45 | void min_raw_data(); |
|
46 | 46 | void min_raw(); |
|
47 | 47 | void min_data(); |
|
48 | 48 | void min(); |
|
49 | 49 | void min_animation_data(); |
|
50 | 50 | void min_animation(); |
|
51 | 51 | void range_raw_data(); |
|
52 | 52 | void range_raw(); |
|
53 | 53 | void range_data(); |
|
54 | 54 | void range(); |
|
55 | 55 | void range_animation_data(); |
|
56 | 56 | void range_animation(); |
|
57 | 57 | |
|
58 | 58 | void interval_data(); |
|
59 | 59 | void interval(); |
|
60 | 60 | |
|
61 | 61 | private: |
|
62 |
QCategoryAxis* m_ |
|
|
62 | QCategoryAxis* m_categoryaxis; | |
|
63 | 63 | QLineSeries* m_series; |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | 66 | void tst_QCategoryAxis::initTestCase() |
|
67 | 67 | { |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void tst_QCategoryAxis::cleanupTestCase() |
|
71 | 71 | { |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | void tst_QCategoryAxis::init() |
|
75 | 75 | { |
|
76 |
m_ |
|
|
76 | m_categoryaxis = new QCategoryAxis(); | |
|
77 | 77 | m_series = new QLineSeries(); |
|
78 | 78 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); |
|
79 |
tst_QAbstractAxis::init(m_ |
|
|
79 | tst_QAbstractAxis::init(m_categoryaxis, m_series); | |
|
80 | 80 | m_chart->addSeries(m_series); |
|
81 | 81 | m_chart->createDefaultAxes(); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | void tst_QCategoryAxis::cleanup() |
|
85 | 85 | { |
|
86 | 86 | delete m_series; |
|
87 |
delete m_ |
|
|
87 | delete m_categoryaxis; | |
|
88 | 88 | m_series = 0; |
|
89 |
m_ |
|
|
89 | m_categoryaxis = 0; | |
|
90 | 90 | tst_QAbstractAxis::cleanup(); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void tst_QCategoryAxis::qcategoryaxis_data() |
|
94 | 94 | { |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | void tst_QCategoryAxis::qcategoryaxis() |
|
98 | 98 | { |
|
99 | 99 | qabstractaxis(); |
|
100 | 100 | |
|
101 |
QVERIFY(qFuzzyIsNull(m_ |
|
|
102 |
QVERIFY(qFuzzyIsNull(m_ |
|
|
103 |
QCOMPARE(m_ |
|
|
101 | QVERIFY(qFuzzyIsNull(m_categoryaxis->max())); | |
|
102 | QVERIFY(qFuzzyIsNull(m_categoryaxis->min())); | |
|
103 | QCOMPARE(m_categoryaxis->type(), QAbstractAxis::AxisTypeCategory); | |
|
104 | 104 | |
|
105 |
m_chart->setAxisX(m_ |
|
|
105 | m_chart->setAxisX(m_categoryaxis, m_series); | |
|
106 | 106 | m_view->show(); |
|
107 | 107 | QTest::qWaitForWindowShown(m_view); |
|
108 | 108 | |
|
109 |
QVERIFY(!qFuzzyIsNull(m_ |
|
|
110 |
QVERIFY(!qFuzzyIsNull(m_ |
|
|
109 | QVERIFY(!qFuzzyIsNull(m_categoryaxis->max())); | |
|
110 | QVERIFY(!qFuzzyIsNull(m_categoryaxis->min())); | |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | void tst_QCategoryAxis::max_raw_data() |
|
114 | 114 | { |
|
115 | 115 | QTest::addColumn<qreal>("max"); |
|
116 | 116 | QTest::newRow("1.0") << (qreal)1.0; |
|
117 | 117 | QTest::newRow("50.0") << (qreal)50.0; |
|
118 | 118 | QTest::newRow("101.0") << (qreal)101.0; |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | void tst_QCategoryAxis::max_raw() |
|
122 | 122 | { |
|
123 | 123 | QFETCH(qreal, max); |
|
124 | 124 | |
|
125 |
QSignalSpy spy0(m_ |
|
|
126 |
QSignalSpy spy1(m_ |
|
|
127 |
QSignalSpy spy2(m_ |
|
|
125 | QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal))); | |
|
126 | QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal))); | |
|
127 | QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
|
128 | 128 | |
|
129 |
m_ |
|
|
130 |
QVERIFY2(qFuzzyIsNull(m_ |
|
|
129 | m_categoryaxis->setMax(max); | |
|
130 | QVERIFY2(qFuzzyIsNull(m_categoryaxis->max() - max), "Not equal"); | |
|
131 | 131 | |
|
132 | 132 | QCOMPARE(spy0.count(), 1); |
|
133 | 133 | QCOMPARE(spy1.count(), 0); |
|
134 | 134 | QCOMPARE(spy2.count(), 1); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | void tst_QCategoryAxis::max_data() |
|
138 | 138 | { |
|
139 | 139 | max_raw_data(); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | void tst_QCategoryAxis::max() |
|
143 | 143 | { |
|
144 |
m_chart->setAxisX(m_ |
|
|
144 | m_chart->setAxisX(m_categoryaxis, m_series); | |
|
145 | 145 | m_view->show(); |
|
146 | 146 | QTest::qWaitForWindowShown(m_view); |
|
147 | 147 | max_raw(); |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | void tst_QCategoryAxis::max_animation_data() |
|
151 | 151 | { |
|
152 | 152 | max_data(); |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | void tst_QCategoryAxis::max_animation() |
|
156 | 156 | { |
|
157 | 157 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
158 | 158 | max(); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | void tst_QCategoryAxis::min_raw_data() |
|
162 | 162 | { |
|
163 | 163 | QTest::addColumn<qreal>("min"); |
|
164 | 164 | QTest::newRow("-1.0") << -1.0; |
|
165 | 165 | QTest::newRow("-50.0") << -50.0; |
|
166 | 166 | QTest::newRow("-101.0") << -101.0; |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | void tst_QCategoryAxis::min_raw() |
|
170 | 170 | { |
|
171 | 171 | QFETCH(qreal, min); |
|
172 | 172 | |
|
173 |
QSignalSpy spy0(m_ |
|
|
174 |
QSignalSpy spy1(m_ |
|
|
175 |
QSignalSpy spy2(m_ |
|
|
173 | QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal))); | |
|
174 | QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal))); | |
|
175 | QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
|
176 | 176 | |
|
177 |
m_ |
|
|
178 |
QVERIFY2(qFuzzyIsNull(m_ |
|
|
177 | m_categoryaxis->setMin(min); | |
|
178 | QVERIFY2(qFuzzyIsNull(m_categoryaxis->min() - min), "Not equal"); | |
|
179 | 179 | |
|
180 | 180 | QCOMPARE(spy0.count(), 0); |
|
181 | 181 | QCOMPARE(spy1.count(), 1); |
|
182 | 182 | QCOMPARE(spy2.count(), 1); |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | void tst_QCategoryAxis::min_data() |
|
186 | 186 | { |
|
187 | 187 | min_raw_data(); |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | void tst_QCategoryAxis::min() |
|
191 | 191 | { |
|
192 |
m_chart->setAxisX(m_ |
|
|
192 | m_chart->setAxisX(m_categoryaxis, m_series); | |
|
193 | 193 | m_view->show(); |
|
194 | 194 | QTest::qWaitForWindowShown(m_view); |
|
195 | 195 | min_raw(); |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | void tst_QCategoryAxis::min_animation_data() |
|
199 | 199 | { |
|
200 | 200 | min_data(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | void tst_QCategoryAxis::min_animation() |
|
204 | 204 | { |
|
205 | 205 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
206 | 206 | min(); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | void tst_QCategoryAxis::range_raw_data() |
|
210 | 210 | { |
|
211 | 211 | QTest::addColumn<qreal>("min"); |
|
212 | 212 | QTest::addColumn<qreal>("max"); |
|
213 | 213 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; |
|
214 | 214 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; |
|
215 | 215 | QTest::newRow("101.0") << 40.0 << 60.0; |
|
216 | QTest::newRow("-35.0 - 0.0") << -35.0 << 10.0; | |
|
217 | QTest::newRow("-35.0 - 0.0") << -35.0 << -15.0; | |
|
218 | QTest::newRow("0.0 - 0.0") << -0.1 << 0.1; | |
|
216 | 219 | } |
|
217 | 220 | |
|
218 | 221 | void tst_QCategoryAxis::range_raw() |
|
219 | 222 | { |
|
220 | 223 | QFETCH(qreal, min); |
|
221 | 224 | QFETCH(qreal, max); |
|
222 | 225 | |
|
223 |
QSignalSpy spy0(m_ |
|
|
224 |
QSignalSpy spy1(m_ |
|
|
225 |
QSignalSpy spy2(m_ |
|
|
226 | QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal))); | |
|
227 | QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal))); | |
|
228 | QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
|
226 | 229 | |
|
227 |
m_ |
|
|
228 |
QVERIFY2(qFuzzyIsNull(m_ |
|
|
229 |
QVERIFY2(qFuzzyIsNull(m_ |
|
|
230 | m_categoryaxis->setRange(min, max); | |
|
231 | QVERIFY2(qFuzzyIsNull(m_categoryaxis->min() - min), "Min not equal"); | |
|
232 | QVERIFY2(qFuzzyIsNull(m_categoryaxis->max() - max), "Max not equal"); | |
|
230 | 233 | |
|
231 | 234 | QCOMPARE(spy0.count(), 1); |
|
232 | 235 | QCOMPARE(spy1.count(), 1); |
|
233 | 236 | QCOMPARE(spy2.count(), 1); |
|
234 | 237 | } |
|
235 | 238 | |
|
236 | 239 | void tst_QCategoryAxis::range_data() |
|
237 | 240 | { |
|
238 | 241 | range_raw_data(); |
|
239 | 242 | } |
|
240 | 243 | |
|
241 | 244 | void tst_QCategoryAxis::range() |
|
242 | 245 | { |
|
243 |
m_chart->setAxisX(m_ |
|
|
246 | m_chart->setAxisX(m_categoryaxis, m_series); | |
|
244 | 247 | m_view->show(); |
|
245 | 248 | QTest::qWaitForWindowShown(m_view); |
|
246 | 249 | range_raw(); |
|
247 | 250 | } |
|
248 | 251 | |
|
249 | 252 | void tst_QCategoryAxis::range_animation_data() |
|
250 | 253 | { |
|
251 | 254 | range_data(); |
|
252 | 255 | } |
|
253 | 256 | |
|
254 | 257 | void tst_QCategoryAxis::range_animation() |
|
255 | 258 | { |
|
256 | 259 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
257 | 260 | range(); |
|
258 | 261 | } |
|
259 | 262 | |
|
260 | 263 | void tst_QCategoryAxis::interval_data() |
|
261 | 264 | { |
|
262 | 265 | // |
|
263 | 266 | } |
|
264 | 267 | |
|
265 | 268 | void tst_QCategoryAxis::interval() |
|
266 | 269 | { |
|
267 | 270 | // append one correct interval |
|
268 |
m_ |
|
|
269 |
QCOMPARE(m_ |
|
|
270 |
QCOMPARE(m_ |
|
|
271 | m_categoryaxis->append("first", (qreal)45); | |
|
272 | QCOMPARE(m_categoryaxis->categoryStart("first"), (qreal)0); | |
|
273 | QCOMPARE(m_categoryaxis->categoryEnd("first"), (qreal)45); | |
|
271 | 274 | |
|
272 | 275 | // append one more correct interval |
|
273 |
m_ |
|
|
274 |
QCOMPARE(m_ |
|
|
275 |
QCOMPARE(m_ |
|
|
276 | m_categoryaxis->append("second", (qreal)75); | |
|
277 | QCOMPARE(m_categoryaxis->categoryStart("second"), (qreal)45); | |
|
278 | QCOMPARE(m_categoryaxis->categoryEnd("second"), (qreal)75); | |
|
276 | 279 | |
|
277 | 280 | // append one incorrect interval |
|
278 |
m_ |
|
|
279 |
QCOMPARE(m_ |
|
|
280 |
QCOMPARE(m_ |
|
|
281 | m_categoryaxis->append("third", (qreal)15); | |
|
282 | QCOMPARE(m_categoryaxis->count(), 2); | |
|
283 | QCOMPARE(m_categoryaxis->categoryEnd(m_categoryaxis->categoriesLabels().last()), (qreal)75); | |
|
281 | 284 | // QCOMPARE(intervalMax("first"), (qreal)75); |
|
282 | 285 | |
|
283 | 286 | // append one more correct interval |
|
284 |
m_ |
|
|
285 |
QCOMPARE(m_ |
|
|
286 |
QCOMPARE(m_ |
|
|
287 |
QCOMPARE(m_ |
|
|
287 | m_categoryaxis->append("third", (qreal)100); | |
|
288 | QCOMPARE(m_categoryaxis->count(), 3); | |
|
289 | QCOMPARE(m_categoryaxis->categoryStart("third"), (qreal)75); | |
|
290 | QCOMPARE(m_categoryaxis->categoryEnd("third"), (qreal)100); | |
|
288 | 291 | |
|
289 | 292 | // remove one interval |
|
290 |
m_ |
|
|
291 |
QCOMPARE(m_ |
|
|
292 |
QCOMPARE(m_ |
|
|
293 |
QCOMPARE(m_ |
|
|
293 | m_categoryaxis->remove("first"); | |
|
294 | QCOMPARE(m_categoryaxis->count(), 2); | |
|
295 | QCOMPARE(m_categoryaxis->categoryStart("second"), (qreal)0); // second interval should extend to firstInterval minimum | |
|
296 | QCOMPARE(m_categoryaxis->categoryEnd("second"), (qreal)75); | |
|
294 | 297 | |
|
295 | 298 | // remove one interval |
|
296 |
m_ |
|
|
297 |
QCOMPARE(m_ |
|
|
298 |
QCOMPARE(m_ |
|
|
299 |
QCOMPARE(m_ |
|
|
299 | m_categoryaxis->replaceLabel("second", "replaced"); | |
|
300 | QCOMPARE(m_categoryaxis->count(), 2); | |
|
301 | QCOMPARE(m_categoryaxis->categoryStart("replaced"), (qreal)0); // second interval should extend to firstInterval minimum | |
|
302 | QCOMPARE(m_categoryaxis->categoryEnd("replaced"), (qreal)75); | |
|
300 | 303 | } |
|
301 | 304 | |
|
302 | 305 | QTEST_MAIN(tst_QCategoryAxis) |
|
303 | 306 | #include "tst_qcategoryaxis.moc" |
|
304 | 307 |
General Comments 0
You need to be logged in to leave comments.
Login now