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