@@ -1,121 +1,121 | |||
|
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 <QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QLineSeries> |
|
25 |
#include <Q |
|
|
25 | #include <QCategoryAxis> | |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | int main(int argc, char *argv[]) |
|
30 | 30 | { |
|
31 | 31 | QApplication a(argc, argv); |
|
32 | 32 | |
|
33 | 33 | //![1] |
|
34 | 34 | QLineSeries* series = new QLineSeries(); |
|
35 | 35 | *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26); |
|
36 | 36 | QChart* chart = new QChart(); |
|
37 | 37 | chart->legend()->hide(); |
|
38 | 38 | chart->addSeries(series); |
|
39 | 39 | //![1] |
|
40 | 40 | |
|
41 | 41 | //![2] |
|
42 | 42 | // Customize series |
|
43 | 43 | QPen pen(QRgb(0xfdb157)); |
|
44 | 44 | pen.setWidth(5); |
|
45 | 45 | series->setPen(pen); |
|
46 | 46 | |
|
47 | 47 | // Customize chart title |
|
48 | 48 | QFont font; |
|
49 | 49 | font.setPixelSize(18); |
|
50 | 50 | chart->setTitleFont(font); |
|
51 | 51 | chart->setTitleBrush(QBrush(Qt::white)); |
|
52 | 52 | chart->setTitle("Customchart example"); |
|
53 | 53 | |
|
54 | 54 | // Customize chart background |
|
55 | 55 | QLinearGradient backgroundGradient; |
|
56 | 56 | backgroundGradient.setStart(QPointF(0,0)); |
|
57 | 57 | backgroundGradient.setFinalStop(QPointF(0,1)); |
|
58 | 58 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); |
|
59 | 59 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); |
|
60 | 60 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
61 | 61 | chart->setBackgroundBrush(backgroundGradient); |
|
62 | 62 | //![2] |
|
63 | 63 | |
|
64 | 64 | //![3] |
|
65 |
Q |
|
|
66 |
Q |
|
|
65 | QCategoryAxis* axisX = new QCategoryAxis(); | |
|
66 | QCategoryAxis* axisY = new QCategoryAxis(); | |
|
67 | 67 | |
|
68 | 68 | // Customize axis label font |
|
69 | 69 | QFont labelsFont; |
|
70 | 70 | labelsFont.setPixelSize(12); |
|
71 | 71 | axisX->setLabelsFont(labelsFont); |
|
72 | 72 | axisY->setLabelsFont(labelsFont); |
|
73 | 73 | |
|
74 | 74 | // Customize axis colors |
|
75 | 75 | QPen axisPen(QRgb(0xd18952)); |
|
76 | 76 | axisPen.setWidth(2); |
|
77 | 77 | axisX->setAxisPen(axisPen); |
|
78 | 78 | axisY->setAxisPen(axisPen); |
|
79 | 79 | |
|
80 | 80 | // Customize axis label colors |
|
81 | 81 | QBrush axisBrush(Qt::white); |
|
82 | 82 | axisX->setLabelsBrush(axisBrush); |
|
83 | 83 | axisY->setLabelsBrush(axisBrush); |
|
84 | 84 | |
|
85 | 85 | // Customize grid lines and shades |
|
86 | 86 | axisX->setGridLineVisible(false); |
|
87 | 87 | axisY->setGridLineVisible(false); |
|
88 | 88 | axisY->setShadesPen(Qt::NoPen); |
|
89 | 89 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); |
|
90 | 90 | axisY->setShadesVisible(true); |
|
91 | 91 | //![3] |
|
92 | 92 | |
|
93 | 93 | //![4] |
|
94 | 94 | axisX->append("low", 10); |
|
95 | 95 | axisX->append("optimal", 20); |
|
96 | 96 | axisX->append("high", 30); |
|
97 | 97 | axisX->setRange(0, 30); |
|
98 | 98 | |
|
99 | 99 | axisY->append("slow", 10); |
|
100 | 100 | axisY->append("med", 20); |
|
101 | 101 | axisY->append("fast", 30); |
|
102 | 102 | axisY->setRange(0, 30); |
|
103 | 103 | |
|
104 | 104 | chart->setAxisX(axisX, series); |
|
105 | 105 | chart->setAxisY(axisY, series); |
|
106 | 106 | //![4] |
|
107 | 107 | |
|
108 | 108 | //![5] |
|
109 | 109 | QChartView* chartView = new QChartView(chart); |
|
110 | 110 | chartView->setRenderHint(QPainter::Antialiasing); |
|
111 | 111 | //![5] |
|
112 | 112 | |
|
113 | 113 | //![6] |
|
114 | 114 | QMainWindow window; |
|
115 | 115 | window.setCentralWidget(chartView); |
|
116 | 116 | window.resize(400, 300); |
|
117 | 117 | window.show(); |
|
118 | 118 | //![6] |
|
119 | 119 | |
|
120 | 120 | return a.exec(); |
|
121 | 121 | } |
@@ -1,130 +1,130 | |||
|
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 "chartintervalsaxisx_p.h" |
|
22 | 22 | #include "qintervalsaxis.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 | ChartIntervalAxisX::ChartIntervalAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
34 | 34 | { |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | ChartIntervalAxisX::~ChartIntervalAxisX() |
|
38 | 38 | { |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | QVector<qreal> ChartIntervalAxisX::calculateLayout() const |
|
42 | 42 | { |
|
43 |
Q |
|
|
43 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
|
44 | 44 | int tickCount = axis->intervalsLabels().count() + 1; |
|
45 | 45 | QVector<qreal> points; |
|
46 | 46 | |
|
47 | 47 | if (tickCount < 2) |
|
48 | 48 | return points; |
|
49 | 49 | |
|
50 | 50 | points.resize(tickCount); |
|
51 | 51 | |
|
52 | 52 | qreal scale = m_rect.width() / axis->max(); |
|
53 | 53 | for (int i = 0; i < tickCount; ++i) |
|
54 | 54 | if (i < tickCount - 1) { |
|
55 | 55 | int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left(); |
|
56 | 56 | points[i] = x; |
|
57 | 57 | } else { |
|
58 | 58 | int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left(); |
|
59 | 59 | points[i] = x; |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | return points; |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | void ChartIntervalAxisX::updateGeometry() |
|
66 | 66 | { |
|
67 | 67 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
68 | 68 | |
|
69 | 69 | m_minWidth = 0; |
|
70 | 70 | m_minHeight = 0; |
|
71 | 71 | |
|
72 | 72 | if(layout.isEmpty()) return; |
|
73 | 73 | |
|
74 |
Q |
|
|
74 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
|
75 | 75 | |
|
76 | 76 | QStringList ticksList = intervalAxis->intervalsLabels(); |
|
77 | 77 | |
|
78 | 78 | // createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
79 | 79 | |
|
80 | 80 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
81 | 81 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
82 | 82 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
83 | 83 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
84 | 84 | |
|
85 | 85 | // Q_ASSERT(labels.size() == ticksList.size()); |
|
86 | 86 | // Q_ASSERT(layout.size() == ticksList.size()); |
|
87 | 87 | |
|
88 | 88 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
89 | 89 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
90 | 90 | |
|
91 | 91 | // qreal width = 0; |
|
92 | 92 | for (int i = 0; i < layout.size(); ++i) { |
|
93 | 93 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
94 | 94 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
95 | 95 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
96 | 96 | if (i < ticksList.count()) { |
|
97 | 97 | labelItem->setText(ticksList.at(i)); |
|
98 | 98 | } |
|
99 | 99 | const QRectF& rect = labelItem->boundingRect(); |
|
100 | 100 | QPointF center = rect.center(); |
|
101 | 101 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
102 | 102 | if (i < ticksList.count()) |
|
103 | 103 | labelItem->setPos(layout[i] + (layout[i + 1] - layout[i]) / 2 - center.x(), m_rect.bottom() + label_padding); |
|
104 | 104 | else |
|
105 | 105 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
106 | 106 | |
|
107 | 107 | if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){ |
|
108 | 108 | labelItem->setVisible(false); |
|
109 | 109 | lineItem->setVisible(false); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | m_minWidth += rect.width(); |
|
113 | 113 | m_minHeight = qMax(rect.height(), m_minHeight); |
|
114 | 114 | |
|
115 | 115 | if ((i + 1) % 2 && i > 1) { |
|
116 | 116 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); |
|
117 | 117 | rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height()); |
|
118 | 118 | } |
|
119 | 119 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
120 | 120 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5); |
|
121 | 121 | } |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | void ChartIntervalAxisX::handleAxisUpdated() |
|
125 | 125 | { |
|
126 | 126 | updateGeometry(); |
|
127 | 127 | ChartAxis::handleAxisUpdated(); |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,137 +1,137 | |||
|
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 "chartintervalsaxisy_p.h" |
|
22 | 22 | #include "qintervalsaxis.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 | |
|
30 | 30 | static int label_padding = 5; |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | ChartIntervalAxisY::ChartIntervalAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
35 | 35 | { |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | ChartIntervalAxisY::~ChartIntervalAxisY() |
|
39 | 39 | { |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | QVector<qreal> ChartIntervalAxisY::calculateLayout() const |
|
43 | 43 | { |
|
44 |
Q |
|
|
44 | QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
|
45 | 45 | int tickCount = axis->intervalsLabels().count() + 1; |
|
46 | 46 | QVector<qreal> points; |
|
47 | 47 | |
|
48 | 48 | if (tickCount < 2) |
|
49 | 49 | return points; |
|
50 | 50 | |
|
51 | 51 | points.resize(tickCount); |
|
52 | 52 | |
|
53 | 53 | qreal scale = m_rect.height() / axis->max(); |
|
54 | 54 | for (int i = 0; i < tickCount; ++i) |
|
55 | 55 | if (i < tickCount - 1) { |
|
56 | 56 | int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom(); |
|
57 | 57 | points[i] = y; |
|
58 | 58 | } else { |
|
59 | 59 | int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom(); |
|
60 | 60 | points[i] = y; |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | return points; |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | void ChartIntervalAxisY::updateGeometry() |
|
67 | 67 | { |
|
68 | 68 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
69 | 69 | m_minWidth = 0; |
|
70 | 70 | m_minHeight = 0; |
|
71 | 71 | |
|
72 | 72 | if(layout.isEmpty()) return; |
|
73 | 73 | |
|
74 |
Q |
|
|
74 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); | |
|
75 | 75 | |
|
76 | 76 | QStringList ticksList = intervalAxis->intervalsLabels(); |
|
77 | 77 | |
|
78 | 78 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
79 | 79 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
80 | 80 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
81 | 81 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
82 | 82 | |
|
83 | 83 | // Q_ASSERT(labels.size() == ticksList.size()); |
|
84 | 84 | // Q_ASSERT(layout.size() == ticksList.size()); |
|
85 | 85 | |
|
86 | 86 | qreal height = 2*m_rect.bottom(); |
|
87 | 87 | |
|
88 | 88 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
89 | 89 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
90 | 90 | |
|
91 | 91 | for (int i = 0; i < layout.size(); ++i) { |
|
92 | 92 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
93 | 93 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
94 | 94 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
95 | 95 | |
|
96 | 96 | if (i < ticksList.count()) { |
|
97 | 97 | labelItem->setText(ticksList.at(i)); |
|
98 | 98 | } |
|
99 | 99 | const QRectF& rect = labelItem->boundingRect(); |
|
100 | 100 | |
|
101 | 101 | QPointF center = rect.center(); |
|
102 | 102 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
103 | 103 | |
|
104 | 104 | if (i < ticksList.count()) |
|
105 | 105 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] + (layout[i + 1] - layout[i]) / 2 - center.y()); |
|
106 | 106 | else |
|
107 | 107 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
108 | 108 | |
|
109 | 109 | if(labelItem->pos().y()+rect.height()>height) { |
|
110 | 110 | labelItem->setVisible(false); |
|
111 | 111 | lineItem->setVisible(false); |
|
112 | 112 | } |
|
113 | 113 | else { |
|
114 | 114 | labelItem->setVisible(true); |
|
115 | 115 | lineItem->setVisible(true); |
|
116 | 116 | height=labelItem->pos().y(); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
120 | 120 | m_minHeight+=rect.height(); |
|
121 | 121 | |
|
122 | 122 | if ((i+1)%2 && i>1) { |
|
123 | 123 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
124 | 124 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
125 | 125 | } |
|
126 | 126 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
127 | 127 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
128 | 128 | } |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void ChartIntervalAxisY::handleAxisUpdated() |
|
132 | 132 | { |
|
133 | 133 | updateGeometry(); |
|
134 | 134 | ChartAxis::handleAxisUpdated(); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,249 +1,249 | |||
|
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 "qintervalsaxis.h" |
|
22 | 22 | #include "qintervalsaxis_p.h" |
|
23 | 23 | #include "chartintervalsaxisx_p.h" |
|
24 | 24 | #include "chartintervalsaxisy_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | /*! |
|
30 |
\class Q |
|
|
31 |
\brief The Q |
|
|
30 | \class QCategoryAxis | |
|
31 | \brief The QCategoryAxis class is used for manipulating chart's axis. | |
|
32 | 32 | \mainclass |
|
33 | 33 | */ |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 |
\qmlclass Axis Q |
|
|
36 | \qmlclass Axis QCategoryAxis | |
|
37 | 37 | \brief The Axis element is used for manipulating chart's axes. |
|
38 | 38 | |
|
39 | 39 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
40 | 40 | |
|
41 | 41 | To access Axes you can use ChartView API. For example: |
|
42 | 42 | \code |
|
43 | 43 | // TODO :) |
|
44 | 44 | \endcode |
|
45 | 45 | */ |
|
46 | 46 | |
|
47 | 47 | /*! |
|
48 | 48 | Constructs an axis object which is a child of \a parent. |
|
49 | 49 | */ |
|
50 |
Q |
|
|
51 |
QValueAxis(*new Q |
|
|
50 | QCategoryAxis::QCategoryAxis(QObject *parent): | |
|
51 | QValueAxis(*new QCategoryAxisPrivate(this),parent) | |
|
52 | 52 | { |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | Destroys the object |
|
57 | 57 | */ |
|
58 |
Q |
|
|
58 | QCategoryAxis::~QCategoryAxis() | |
|
59 | 59 | { |
|
60 | 60 | // Q_D(QValueAxis); |
|
61 | 61 | // if(d->m_dataset) { |
|
62 | 62 | // d->m_dataset->removeAxis(this); |
|
63 | 63 | // } |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \internal |
|
68 | 68 | */ |
|
69 |
Q |
|
|
69 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent) | |
|
70 | 70 | { |
|
71 | 71 | |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | Appends new interval to the axis with an \a intervalLabel. |
|
76 | 76 | Interval label has to be unique. |
|
77 | 77 | Parameter \a intervalEnd specifies the high end limit of the interval. |
|
78 | 78 | It has to be greater than the high end limit of the previous interval. |
|
79 | 79 | Otherwise the method returns without adding a new interval. |
|
80 | 80 | */ |
|
81 |
void Q |
|
|
81 | void QCategoryAxis::append(const QString& intervalLabel, qreal intervalEnd) | |
|
82 | 82 | { |
|
83 |
Q_D(Q |
|
|
83 | Q_D(QCategoryAxis); | |
|
84 | 84 | |
|
85 | 85 | if (!d->m_intervals.contains(intervalLabel)) |
|
86 | 86 | { |
|
87 | 87 | if(d->m_intervals.isEmpty()){ |
|
88 | 88 | Range range(d->m_categoryMinimum, intervalEnd); |
|
89 | 89 | d->m_intervalsMap.insert(intervalLabel, range); |
|
90 | 90 | d->m_intervals.append(intervalLabel); |
|
91 | 91 | }else if (intervalEnd > intervalMax(d->m_intervals.last())){ |
|
92 | 92 | Range range = d->m_intervalsMap.value(d->m_intervals.last()); |
|
93 | 93 | d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd)); |
|
94 | 94 | d->m_intervals.append(intervalLabel); |
|
95 | 95 | } |
|
96 | 96 | } |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | Sets to \a min the low end limit of the first interval on the axis. |
|
101 | 101 | */ |
|
102 |
void Q |
|
|
102 | void QCategoryAxis::setFisrtIntervalMinimum(qreal min) | |
|
103 | 103 | { |
|
104 |
Q_D(Q |
|
|
104 | Q_D(QCategoryAxis); | |
|
105 | 105 | if(d->m_intervals.isEmpty()){ |
|
106 | 106 | d->m_categoryMinimum = min; |
|
107 | 107 | }else{ |
|
108 | 108 | Range range = d->m_intervalsMap.value(d->m_intervals.first()); |
|
109 | 109 | d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second)); |
|
110 | 110 | } |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | Returns the low end limit of the interval specified by an \a intervalLabel |
|
115 | 115 | */ |
|
116 |
qreal Q |
|
|
116 | qreal QCategoryAxis::intervalMin(const QString& intervalLabel) const | |
|
117 | 117 | { |
|
118 |
Q_D(const Q |
|
|
118 | Q_D(const QCategoryAxis); | |
|
119 | 119 | return d->m_intervalsMap.value(intervalLabel).first; |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Returns the high end limit of the interval specified by an \a intervalLabel |
|
124 | 124 | */ |
|
125 |
qreal Q |
|
|
125 | qreal QCategoryAxis::intervalMax(const QString& intervalLabel) const | |
|
126 | 126 | { |
|
127 |
Q_D(const Q |
|
|
127 | Q_D(const QCategoryAxis); | |
|
128 | 128 | return d->m_intervalsMap.value(intervalLabel).second; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | Removes an interval specified by the \a intervalLabel from the axis |
|
133 | 133 | */ |
|
134 |
void Q |
|
|
134 | void QCategoryAxis::remove(const QString &intervalLabel) | |
|
135 | 135 | { |
|
136 |
Q_D(Q |
|
|
136 | Q_D(QCategoryAxis); | |
|
137 | 137 | int labelIndex = d->m_intervals.indexOf(intervalLabel); |
|
138 | 138 | |
|
139 | 139 | // check if such label exists |
|
140 | 140 | if (labelIndex != -1) { |
|
141 | 141 | d->m_intervals.removeAt(labelIndex); |
|
142 | 142 | d->m_intervalsMap.remove(intervalLabel); |
|
143 | 143 | |
|
144 | 144 | // the range of the interval that follows (if exists) needs to be updated |
|
145 | 145 | if (labelIndex < d->m_intervals.count()) { |
|
146 | 146 | QString label = d->m_intervals.at(labelIndex); |
|
147 | 147 | Range range = d->m_intervalsMap.value(label); |
|
148 | 148 | |
|
149 | 149 | // set the range |
|
150 | 150 | if (labelIndex == 0) { |
|
151 | 151 | range.first = d->m_categoryMinimum; |
|
152 | 152 | d->m_intervalsMap.insert(label, range); |
|
153 | 153 | } else { |
|
154 | 154 | range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second; |
|
155 | 155 | d->m_intervalsMap.insert(label, range); |
|
156 | 156 | } |
|
157 | 157 | } |
|
158 | 158 | d->emitUpdated(); |
|
159 | 159 | } |
|
160 | 160 | } |
|
161 | 161 | |
|
162 | 162 | /*! |
|
163 | 163 | Replaces \a oldLabel of an existing interval with a \a newLabel |
|
164 | 164 | If the old label does not exist the method returns without making any changes. |
|
165 | 165 | */ |
|
166 |
void Q |
|
|
166 | void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel) | |
|
167 | 167 | { |
|
168 |
Q_D(Q |
|
|
168 | Q_D(QCategoryAxis); | |
|
169 | 169 | int labelIndex = d->m_intervals.indexOf(oldLabel); |
|
170 | 170 | |
|
171 | 171 | // check if such label exists |
|
172 | 172 | if (labelIndex != -1) { |
|
173 | 173 | d->m_intervals.replace(labelIndex, newLabel); |
|
174 | 174 | Range range = d->m_intervalsMap.value(oldLabel); |
|
175 | 175 | d->m_intervalsMap.remove(oldLabel); |
|
176 | 176 | d->m_intervalsMap.insert(newLabel, range); |
|
177 | 177 | d->emitUpdated(); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | /*! |
|
183 | 183 | Returns the list of the intervals labels |
|
184 | 184 | */ |
|
185 |
QStringList Q |
|
|
185 | QStringList QCategoryAxis::intervalsLabels() | |
|
186 | 186 | { |
|
187 |
Q_D(Q |
|
|
187 | Q_D(QCategoryAxis); | |
|
188 | 188 | return d->m_intervals; |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Returns number of intervals. |
|
193 | 193 | */ |
|
194 |
int Q |
|
|
194 | int QCategoryAxis::count() const | |
|
195 | 195 | { |
|
196 |
Q_D(const Q |
|
|
196 | Q_D(const QCategoryAxis); | |
|
197 | 197 | return d->m_intervals.count(); |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Returns the type of the axis |
|
202 | 202 | */ |
|
203 |
QAbstractAxis::AxisType Q |
|
|
203 | QAbstractAxis::AxisType QCategoryAxis::type() const | |
|
204 | 204 | { |
|
205 | 205 | return QAbstractAxis::AxisTypeIntervals; |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
209 | 209 | |
|
210 |
Q |
|
|
210 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q): | |
|
211 | 211 | QValueAxisPrivate(q), |
|
212 | 212 | m_categoryMinimum(0) |
|
213 | 213 | { |
|
214 | 214 | |
|
215 | 215 | } |
|
216 | 216 | |
|
217 |
Q |
|
|
217 | QCategoryAxisPrivate::~QCategoryAxisPrivate() | |
|
218 | 218 | { |
|
219 | 219 | |
|
220 | 220 | } |
|
221 | 221 | |
|
222 |
int Q |
|
|
222 | int QCategoryAxisPrivate::ticksCount() const | |
|
223 | 223 | { |
|
224 | 224 | return m_intervals.count() + 1; |
|
225 | 225 | } |
|
226 | 226 | |
|
227 |
void Q |
|
|
227 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
|
228 | 228 | { |
|
229 | 229 | Q_UNUSED(count); |
|
230 | 230 | Q_UNUSED(min); |
|
231 | 231 | Q_UNUSED(max); |
|
232 | 232 | //m_min = min; |
|
233 | 233 | //m_max = max; |
|
234 | 234 | } |
|
235 | 235 | |
|
236 |
ChartAxis* Q |
|
|
236 | ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) | |
|
237 | 237 | { |
|
238 |
Q_Q(Q |
|
|
238 | Q_Q(QCategoryAxis); | |
|
239 | 239 | if(m_orientation == Qt::Vertical){ |
|
240 | 240 | return new ChartIntervalAxisY(q,presenter); |
|
241 | 241 | }else{ |
|
242 | 242 | return new ChartIntervalAxisX(q,presenter); |
|
243 | 243 | } |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | #include "moc_qintervalsaxis.cpp" |
|
247 | 247 | #include "moc_qintervalsaxis_p.cpp" |
|
248 | 248 | |
|
249 | 249 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,65 | |||
|
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 | #ifndef QCATEGORIESAXIS_H |
|
22 | 22 | #define QCATEGORIESAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | #include "qvalueaxis.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 |
class Q |
|
|
29 | class QCategoryAxisPrivate; | |
|
30 | 30 | |
|
31 |
class QTCOMMERCIALCHART_EXPORT Q |
|
|
31 | class QTCOMMERCIALCHART_EXPORT QCategoryAxis : public QValueAxis | |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | |
|
35 | 35 | public: |
|
36 |
explicit Q |
|
|
37 |
~Q |
|
|
36 | explicit QCategoryAxis(QObject *parent = 0); | |
|
37 | ~QCategoryAxis(); | |
|
38 | 38 | |
|
39 | 39 | protected: |
|
40 |
Q |
|
|
40 | QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent = 0); | |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | AxisType type() const; |
|
44 | 44 | |
|
45 | 45 | void append(const QString& label, qreal intervalEnd); |
|
46 | 46 | void remove(const QString& label); |
|
47 | 47 | void replaceLabel(const QString& oldLabel, const QString& newLabel); |
|
48 | 48 | |
|
49 | 49 | void setFisrtIntervalMinimum(qreal min); |
|
50 | 50 | |
|
51 | 51 | qreal intervalMin(const QString& intervalLabel) const; |
|
52 | 52 | qreal intervalMax(const QString& intervalLabel) const; |
|
53 | 53 | |
|
54 | 54 | QStringList intervalsLabels(); |
|
55 | 55 | int count() const; |
|
56 | 56 | |
|
57 | 57 | |
|
58 | 58 | private: |
|
59 |
Q_DECLARE_PRIVATE(Q |
|
|
60 |
Q_DISABLE_COPY(Q |
|
|
59 | Q_DECLARE_PRIVATE(QCategoryAxis) | |
|
60 | Q_DISABLE_COPY(QCategoryAxis) | |
|
61 | 61 | }; |
|
62 | 62 | |
|
63 | 63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
64 | 64 | |
|
65 | 65 | #endif // QCATEGORIESAXIS_H |
@@ -1,70 +1,70 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | #ifndef QIntervalsAxis_P_H | |
|
31 | #define QIntervalsAxis_P_H | |
|
30 | #ifndef QCATEGORYAXIS_P_H | |
|
31 | #define QCATEGORYAXIS_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qintervalsaxis.h" |
|
34 | 34 | #include "qvalueaxis_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | typedef QPair<qreal, qreal> Range; |
|
39 | 39 | |
|
40 |
class Q |
|
|
40 | class QCategoryAxisPrivate : public QValueAxisPrivate | |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 |
Q |
|
|
46 |
~Q |
|
|
45 | QCategoryAxisPrivate(QCategoryAxis *q); | |
|
46 | ~QCategoryAxisPrivate(); | |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | public: |
|
50 | 50 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
51 | 51 | int ticksCount() const; |
|
52 | 52 | |
|
53 | 53 | Q_SIGNALS: |
|
54 | 54 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); |
|
55 | 55 | |
|
56 | 56 | public Q_SLOTS: |
|
57 | 57 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
58 | 58 | |
|
59 | 59 | private: |
|
60 | 60 | QMap<QString , Range> m_intervalsMap; |
|
61 | 61 | QStringList m_intervals; |
|
62 | 62 | qreal m_categoryMinimum; |
|
63 | 63 | |
|
64 | 64 | private: |
|
65 |
Q_DECLARE_PUBLIC(Q |
|
|
65 | Q_DECLARE_PUBLIC(QCategoryAxis) | |
|
66 | 66 | }; |
|
67 | 67 | |
|
68 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | 69 | |
|
70 |
#endif // QCATEGOR |
|
|
70 | #endif // QCATEGORYAXIS_P_H |
@@ -1,491 +1,491 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartdataset_p.h" |
|
22 | 22 | #include "qchart.h" |
|
23 | 23 | #include "qvalueaxis.h" |
|
24 | 24 | #include "qbarcategoryaxis.h" |
|
25 | 25 | #include "qvalueaxis_p.h" |
|
26 | 26 | #include "qintervalsaxis.h" |
|
27 | 27 | #include "qdatetimeaxis.h" |
|
28 | 28 | #include "qabstractseries_p.h" |
|
29 | 29 | #include "qabstractbarseries.h" |
|
30 | 30 | #include "qstackedbarseries.h" |
|
31 | 31 | #include "qpercentbarseries.h" |
|
32 | 32 | #include "qpieseries.h" |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) |
|
37 | 37 | { |
|
38 | 38 | |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | ChartDataSet::~ChartDataSet() |
|
42 | 42 | { |
|
43 | 43 | removeAllSeries(); |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
47 | 47 | { |
|
48 | 48 | Domain* domain = m_seriesDomainMap.value(series); |
|
49 | 49 | |
|
50 | 50 | if(domain) { |
|
51 | 51 | qWarning() << "Can not add series. Series already on the chart"; |
|
52 | 52 | return; |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | domain = new Domain(series); |
|
56 | 56 | m_seriesDomainMap.insert(series,domain); |
|
57 | 57 | series->d_ptr->scaleDomain(*domain); |
|
58 | 58 | |
|
59 | 59 | createSeriesIndex(series); |
|
60 | 60 | |
|
61 | 61 | series->setParent(this); // take ownership |
|
62 | 62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
63 | 63 | series->d_ptr->m_dataset = this; |
|
64 | 64 | |
|
65 | 65 | emit seriesAdded(series,domain); |
|
66 | 66 | |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
70 | 70 | { |
|
71 | 71 | |
|
72 | 72 | if(!m_seriesDomainMap.contains(series)) { |
|
73 | 73 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
74 | 74 | return; |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | emit seriesRemoved(series); |
|
78 | 78 | |
|
79 | 79 | Domain* domain = m_seriesDomainMap.take(series); |
|
80 | 80 | delete domain; |
|
81 | 81 | domain = 0; |
|
82 | 82 | |
|
83 | 83 | removeSeriesIndex(series); |
|
84 | 84 | |
|
85 | 85 | series->setParent(0); |
|
86 | 86 | series->d_ptr->m_chart = 0; |
|
87 | 87 | series->d_ptr->m_dataset = 0; |
|
88 | 88 | |
|
89 | 89 | removeAxes(series); |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) |
|
95 | 95 | { |
|
96 | 96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
97 | 97 | |
|
98 | 98 | int key=0; |
|
99 | 99 | while (i.hasNext()) { |
|
100 | 100 | i.next(); |
|
101 | 101 | if(i.key()!=key) { |
|
102 | 102 | break; |
|
103 | 103 | } |
|
104 | 104 | key++; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | m_indexSeriesMap.insert(key,series); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) |
|
111 | 111 | { |
|
112 | 112 | int key = seriesIndex(series); |
|
113 | 113 | Q_ASSERT(key!=-1); |
|
114 | 114 | m_indexSeriesMap.remove(key); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void ChartDataSet::createDefaultAxes() |
|
118 | 118 | { |
|
119 | 119 | if (m_seriesDomainMap.isEmpty()) |
|
120 | 120 | return; |
|
121 | 121 | |
|
122 | 122 | QAbstractAxis::AxisTypes typeX(0); |
|
123 | 123 | QAbstractAxis::AxisTypes typeY(0); |
|
124 | 124 | |
|
125 | 125 | // Remove possibly existing axes |
|
126 | 126 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
127 | 127 | while (i.hasNext()) { |
|
128 | 128 | i.next(); |
|
129 | 129 | removeAxes(i.key()); |
|
130 | 130 | } |
|
131 | 131 | |
|
132 | 132 | i.toFront(); |
|
133 | 133 | |
|
134 | 134 | // Select the required axis x and axis y types based on the types of the current series |
|
135 | 135 | while (i.hasNext()) { |
|
136 | 136 | i.next(); |
|
137 | 137 | |
|
138 | 138 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
139 | 139 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
140 | 140 | if(axisX) typeX&=axisX->type(); |
|
141 | 141 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
142 | 142 | if(axisY) typeY&=axisY->type(); |
|
143 | 143 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | // Create the axes of the types selected |
|
147 | 147 | createAxes(typeX, Qt::Horizontal); |
|
148 | 148 | createAxes(typeY, Qt::Vertical); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
152 | 152 | { |
|
153 | 153 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
154 | 154 | |
|
155 | 155 | // TODO: Add a descriptive comment of what happens here |
|
156 | 156 | if (type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) { |
|
157 | 157 | while (i.hasNext()) { |
|
158 | 158 | i.next(); |
|
159 | 159 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation), orientation); |
|
160 | 160 | if (axis) { |
|
161 | 161 | initializeAxis(axis, i.key()); |
|
162 | 162 | emit axisAdded(axis, i.value()); |
|
163 | 163 | } |
|
164 | 164 | } |
|
165 | 165 | } else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
166 | 166 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)), orientation); |
|
167 | 167 | i.toFront(); |
|
168 | 168 | while (i.hasNext()) { |
|
169 | 169 | i.next(); |
|
170 | 170 | initializeAxis(axis,i.key()); |
|
171 | 171 | } |
|
172 | 172 | emit axisAdded(axis,i.value()); |
|
173 | 173 | } |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation) |
|
177 | 177 | { |
|
178 | 178 | QAbstractAxis* axis = 0; |
|
179 | 179 | |
|
180 | 180 | switch(type) { |
|
181 | 181 | case QAbstractAxis::AxisTypeValues: |
|
182 | 182 | axis = new QValueAxis(this); |
|
183 | 183 | break; |
|
184 | 184 | case QAbstractAxis::AxisTypeCategories: |
|
185 | 185 | axis = new QBarCategoryAxis(this); |
|
186 | 186 | break; |
|
187 | 187 | case QAbstractAxis::AxisTypeIntervals: |
|
188 |
axis = new Q |
|
|
188 | axis = new QCategoryAxis(this); | |
|
189 | 189 | break; |
|
190 | 190 | case QAbstractAxis::AxisTypeDateTime: |
|
191 | 191 | axis = new QDateTimeAxis(this); |
|
192 | 192 | break; |
|
193 | 193 | default: |
|
194 | 194 | axis = 0; |
|
195 | 195 | break; |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | if(axis) |
|
199 | 199 | axis->d_ptr->setOrientation(orientation); |
|
200 | 200 | |
|
201 | 201 | return axis; |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) |
|
205 | 205 | { |
|
206 | 206 | Domain* domain = m_seriesDomainMap.value(series); |
|
207 | 207 | axis->d_ptr->m_dataset = this; |
|
208 | 208 | series->d_ptr->initializeAxis(axis); |
|
209 | 209 | axis->d_ptr->intializeDomain(domain); |
|
210 | 210 | if(axis->orientation()==Qt::Horizontal) { |
|
211 | 211 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
212 | 212 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
213 | 213 | m_seriesAxisXMap.insert(series,axis); |
|
214 | 214 | } |
|
215 | 215 | else { |
|
216 | 216 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
217 | 217 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
218 | 218 | m_seriesAxisYMap.insert(series,axis); |
|
219 | 219 | } |
|
220 | 220 | axis->d_ptr->emitUpdated(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
224 | 224 | { |
|
225 | 225 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
226 | 226 | |
|
227 | 227 | if(axisX) { |
|
228 | 228 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
229 | 229 | int x = axesX.indexOf(axisX); |
|
230 | 230 | |
|
231 | 231 | if(x==-1) { |
|
232 | 232 | emit axisRemoved(axisX); |
|
233 | 233 | axisX->d_ptr->m_dataset=0; |
|
234 | 234 | axisX->deleteLater(); |
|
235 | 235 | } |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
239 | 239 | |
|
240 | 240 | if(axisY) { |
|
241 | 241 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
242 | 242 | |
|
243 | 243 | int y = axesY.indexOf(axisY); |
|
244 | 244 | |
|
245 | 245 | if(y==-1) { |
|
246 | 246 | emit axisRemoved(axisY); |
|
247 | 247 | axisY->d_ptr->m_dataset=0; |
|
248 | 248 | axisY->deleteLater(); |
|
249 | 249 | } |
|
250 | 250 | } |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | void ChartDataSet::removeAxis(QAbstractAxis* axis) |
|
254 | 254 | { |
|
255 | 255 | if(!axis->d_ptr->m_dataset) { |
|
256 | 256 | qWarning()<<"UnBound axis found !"; |
|
257 | 257 | return; |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
261 | 261 | |
|
262 | 262 | if(axis->orientation()==Qt::Vertical) { |
|
263 | 263 | seriesAxisMap= &m_seriesAxisYMap; |
|
264 | 264 | } |
|
265 | 265 | else { |
|
266 | 266 | seriesAxisMap= &m_seriesAxisXMap; |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); |
|
270 | 270 | |
|
271 | 271 | while (i.hasNext()) { |
|
272 | 272 | i.next(); |
|
273 | 273 | if(i.value()==axis) { |
|
274 | 274 | removeSeries(i.key()); |
|
275 | 275 | } |
|
276 | 276 | } |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | 279 | void ChartDataSet::removeAllSeries() |
|
280 | 280 | { |
|
281 | 281 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
282 | 282 | foreach(QAbstractSeries *s , series) { |
|
283 | 283 | removeSeries(s); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
287 | 287 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
288 | 288 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
289 | 289 | |
|
290 | 290 | qDeleteAll(series); |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
294 | 294 | { |
|
295 | 295 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
296 | 296 | |
|
297 | 297 | |
|
298 | 298 | blockAxisSignals(true); |
|
299 | 299 | |
|
300 | 300 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
301 | 301 | |
|
302 | 302 | while (i.hasNext()) { |
|
303 | 303 | i.next(); |
|
304 | 304 | i.value()->zoomIn(rect,size); |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | blockAxisSignals(false); |
|
308 | 308 | |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
312 | 312 | { |
|
313 | 313 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
314 | 314 | |
|
315 | 315 | blockAxisSignals(true); |
|
316 | 316 | |
|
317 | 317 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
318 | 318 | |
|
319 | 319 | while (i.hasNext()) { |
|
320 | 320 | i.next(); |
|
321 | 321 | i.value()->zoomOut(rect,size); |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | blockAxisSignals(false); |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
328 | 328 | { |
|
329 | 329 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
330 | 330 | while (i.hasNext()) { |
|
331 | 331 | i.next(); |
|
332 | 332 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
333 | 333 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
334 | 334 | if(axisX) { |
|
335 | 335 | axisX->d_ptr->blockSignals(enabled); |
|
336 | 336 | if(!enabled) { |
|
337 | 337 | axisX->d_ptr->setDirty(false); |
|
338 | 338 | axisX->d_ptr->emitUpdated(); |
|
339 | 339 | } |
|
340 | 340 | } |
|
341 | 341 | if(axisY) { |
|
342 | 342 | axisY->d_ptr->blockSignals(enabled); |
|
343 | 343 | if(!enabled) { |
|
344 | 344 | axisY->d_ptr->setDirty(false); |
|
345 | 345 | axisY->d_ptr->emitUpdated(); |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | } |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
352 | 352 | { |
|
353 | 353 | int count=0; |
|
354 | 354 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
355 | 355 | while (i.hasNext()) { |
|
356 | 356 | i.next(); |
|
357 | 357 | if(i.key()->type()==type) count++; |
|
358 | 358 | } |
|
359 | 359 | return count; |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
363 | 363 | { |
|
364 | 364 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
365 | 365 | while (i.hasNext()) { |
|
366 | 366 | i.next(); |
|
367 | 367 | if (i.value() == series) |
|
368 | 368 | return i.key(); |
|
369 | 369 | } |
|
370 | 370 | return -1; |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
374 | 374 | { |
|
375 | 375 | if(series == 0) { |
|
376 | 376 | |
|
377 | 377 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); |
|
378 | 378 | |
|
379 | 379 | while (i.hasNext()) { |
|
380 | 380 | i.next(); |
|
381 | 381 | if(i.value()->isVisible()) return i.value(); |
|
382 | 382 | } |
|
383 | 383 | return 0; |
|
384 | 384 | } |
|
385 | 385 | return m_seriesAxisXMap.value(series); |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
389 | 389 | { |
|
390 | 390 | if(series == 0) { |
|
391 | 391 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); |
|
392 | 392 | |
|
393 | 393 | while (i.hasNext()) { |
|
394 | 394 | i.next(); |
|
395 | 395 | if(i.value()->isVisible()) return i.value(); |
|
396 | 396 | } |
|
397 | 397 | return 0; |
|
398 | 398 | } |
|
399 | 399 | return m_seriesAxisYMap.value(series); |
|
400 | 400 | } |
|
401 | 401 | |
|
402 | 402 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
403 | 403 | { |
|
404 | 404 | Q_ASSERT(axis); |
|
405 | 405 | |
|
406 | 406 | if(!series) { |
|
407 | 407 | qWarning() << "Series not found on the chart."; |
|
408 | 408 | return; |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | Domain* domain = m_seriesDomainMap.value(series); |
|
412 | 412 | |
|
413 | 413 | if(!domain) { |
|
414 | 414 | qWarning() << "Series not found on the chart."; |
|
415 | 415 | return; |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { |
|
419 | 419 | qWarning()<<"Axis already defined as axis Y"; |
|
420 | 420 | return; |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { |
|
424 | 424 | qWarning()<<"Axis already defined as axis X"; |
|
425 | 425 | return; |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | axis->d_ptr->setOrientation(orientation); |
|
429 | 429 | |
|
430 | 430 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
431 | 431 | |
|
432 | 432 | if(orientation==Qt::Vertical) { |
|
433 | 433 | seriesAxisMap= &m_seriesAxisYMap; |
|
434 | 434 | }else{ |
|
435 | 435 | seriesAxisMap= &m_seriesAxisXMap; |
|
436 | 436 | } |
|
437 | 437 | |
|
438 | 438 | if (seriesAxisMap->value(series) == axis) { |
|
439 | 439 | qWarning() << "The axis already set for the series"; |
|
440 | 440 | return; |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
444 | 444 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); |
|
445 | 445 | if(oldAxis) { |
|
446 | 446 | if(axes.indexOf(oldAxis)==-1) { |
|
447 | 447 | emit axisRemoved(oldAxis); |
|
448 | 448 | oldAxis->disconnect(); |
|
449 | 449 | QObject::disconnect(domain,0,oldAxis,0); |
|
450 | 450 | oldAxis->d_ptr->m_dataset=0; |
|
451 | 451 | oldAxis->deleteLater(); |
|
452 | 452 | } |
|
453 | 453 | } |
|
454 | 454 | |
|
455 | 455 | if(axes.indexOf(axis)==-1) { |
|
456 | 456 | initializeAxis(axis,series); |
|
457 | 457 | emit axisAdded(axis,domain); |
|
458 | 458 | }else{ |
|
459 | 459 | initializeAxis(axis,series); |
|
460 | 460 | } |
|
461 | 461 | } |
|
462 | 462 | |
|
463 | 463 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
464 | 464 | { |
|
465 | 465 | return m_seriesDomainMap.value(series); |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
469 | 469 | { |
|
470 | 470 | blockAxisSignals(true); |
|
471 | 471 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
472 | 472 | while (i.hasNext()) { |
|
473 | 473 | i.next(); |
|
474 | 474 | i.value()->move(dx,dy,size); |
|
475 | 475 | } |
|
476 | 476 | blockAxisSignals(false); |
|
477 | 477 | } |
|
478 | 478 | |
|
479 | 479 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
480 | 480 | { |
|
481 | 481 | return m_seriesDomainMap.keys(); |
|
482 | 482 | } |
|
483 | 483 | |
|
484 | 484 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
485 | 485 | { |
|
486 | 486 | emit seriesUpdated(series); |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | #include "moc_chartdataset_p.cpp" |
|
490 | 490 | |
|
491 | 491 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,304 +1,304 | |||
|
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 "qintervalsaxis.h" |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | |
|
25 |
class tst_Q |
|
|
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 qintervalsaxis_data(); |
|
37 | 37 | void qintervalsaxis(); |
|
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 |
Q |
|
|
62 | QCategoryAxis* m_intervalsaxis; | |
|
63 | 63 | QLineSeries* m_series; |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 |
void tst_Q |
|
|
66 | void tst_QCategoryAxis::initTestCase() | |
|
67 | 67 | { |
|
68 | 68 | } |
|
69 | 69 | |
|
70 |
void tst_Q |
|
|
70 | void tst_QCategoryAxis::cleanupTestCase() | |
|
71 | 71 | { |
|
72 | 72 | } |
|
73 | 73 | |
|
74 |
void tst_Q |
|
|
74 | void tst_QCategoryAxis::init() | |
|
75 | 75 | { |
|
76 |
m_intervalsaxis = new Q |
|
|
76 | m_intervalsaxis = new QCategoryAxis(); | |
|
77 | 77 | m_series = new QLineSeries(); |
|
78 | 78 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); |
|
79 | 79 | tst_QAbstractAxis::init(m_intervalsaxis, m_series); |
|
80 | 80 | m_chart->addSeries(m_series); |
|
81 | 81 | m_chart->createDefaultAxes(); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 |
void tst_Q |
|
|
84 | void tst_QCategoryAxis::cleanup() | |
|
85 | 85 | { |
|
86 | 86 | delete m_series; |
|
87 | 87 | delete m_intervalsaxis; |
|
88 | 88 | m_series = 0; |
|
89 | 89 | m_intervalsaxis = 0; |
|
90 | 90 | tst_QAbstractAxis::cleanup(); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 |
void tst_Q |
|
|
93 | void tst_QCategoryAxis::qintervalsaxis_data() | |
|
94 | 94 | { |
|
95 | 95 | } |
|
96 | 96 | |
|
97 |
void tst_Q |
|
|
97 | void tst_QCategoryAxis::qintervalsaxis() | |
|
98 | 98 | { |
|
99 | 99 | qabstractaxis(); |
|
100 | 100 | |
|
101 | 101 | QVERIFY(qFuzzyIsNull(m_intervalsaxis->max())); |
|
102 | 102 | QVERIFY(qFuzzyIsNull(m_intervalsaxis->min())); |
|
103 | 103 | QCOMPARE(m_intervalsaxis->type(), QAbstractAxis::AxisTypeIntervals); |
|
104 | 104 | |
|
105 | 105 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
106 | 106 | m_view->show(); |
|
107 | 107 | QTest::qWaitForWindowShown(m_view); |
|
108 | 108 | |
|
109 | 109 | QVERIFY(!qFuzzyIsNull(m_intervalsaxis->max())); |
|
110 | 110 | QVERIFY(!qFuzzyIsNull(m_intervalsaxis->min())); |
|
111 | 111 | } |
|
112 | 112 | |
|
113 |
void tst_Q |
|
|
113 | void tst_QCategoryAxis::max_raw_data() | |
|
114 | 114 | { |
|
115 | 115 | QTest::addColumn<qreal>("max"); |
|
116 | 116 | QTest::newRow("1.0") << 1.0; |
|
117 | 117 | QTest::newRow("50.0") << 50.0; |
|
118 | 118 | QTest::newRow("101.0") << 101.0; |
|
119 | 119 | } |
|
120 | 120 | |
|
121 |
void tst_Q |
|
|
121 | void tst_QCategoryAxis::max_raw() | |
|
122 | 122 | { |
|
123 | 123 | QFETCH(qreal, max); |
|
124 | 124 | |
|
125 | 125 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); |
|
126 | 126 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); |
|
127 | 127 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
128 | 128 | |
|
129 | 129 | m_intervalsaxis->setMax(max); |
|
130 | 130 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->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 |
void tst_Q |
|
|
137 | void tst_QCategoryAxis::max_data() | |
|
138 | 138 | { |
|
139 | 139 | max_raw_data(); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 |
void tst_Q |
|
|
142 | void tst_QCategoryAxis::max() | |
|
143 | 143 | { |
|
144 | 144 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
145 | 145 | m_view->show(); |
|
146 | 146 | QTest::qWaitForWindowShown(m_view); |
|
147 | 147 | max_raw(); |
|
148 | 148 | } |
|
149 | 149 | |
|
150 |
void tst_Q |
|
|
150 | void tst_QCategoryAxis::max_animation_data() | |
|
151 | 151 | { |
|
152 | 152 | max_data(); |
|
153 | 153 | } |
|
154 | 154 | |
|
155 |
void tst_Q |
|
|
155 | void tst_QCategoryAxis::max_animation() | |
|
156 | 156 | { |
|
157 | 157 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
158 | 158 | max(); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 |
void tst_Q |
|
|
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 |
void tst_Q |
|
|
169 | void tst_QCategoryAxis::min_raw() | |
|
170 | 170 | { |
|
171 | 171 | QFETCH(qreal, min); |
|
172 | 172 | |
|
173 | 173 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); |
|
174 | 174 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); |
|
175 | 175 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
176 | 176 | |
|
177 | 177 | m_intervalsaxis->setMin(min); |
|
178 | 178 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->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 |
void tst_Q |
|
|
185 | void tst_QCategoryAxis::min_data() | |
|
186 | 186 | { |
|
187 | 187 | min_raw_data(); |
|
188 | 188 | } |
|
189 | 189 | |
|
190 |
void tst_Q |
|
|
190 | void tst_QCategoryAxis::min() | |
|
191 | 191 | { |
|
192 | 192 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
193 | 193 | m_view->show(); |
|
194 | 194 | QTest::qWaitForWindowShown(m_view); |
|
195 | 195 | min_raw(); |
|
196 | 196 | } |
|
197 | 197 | |
|
198 |
void tst_Q |
|
|
198 | void tst_QCategoryAxis::min_animation_data() | |
|
199 | 199 | { |
|
200 | 200 | min_data(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 |
void tst_Q |
|
|
203 | void tst_QCategoryAxis::min_animation() | |
|
204 | 204 | { |
|
205 | 205 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
206 | 206 | min(); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 |
void tst_Q |
|
|
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 | 216 | } |
|
217 | 217 | |
|
218 |
void tst_Q |
|
|
218 | void tst_QCategoryAxis::range_raw() | |
|
219 | 219 | { |
|
220 | 220 | QFETCH(qreal, min); |
|
221 | 221 | QFETCH(qreal, max); |
|
222 | 222 | |
|
223 | 223 | QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal))); |
|
224 | 224 | QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal))); |
|
225 | 225 | QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
226 | 226 | |
|
227 | 227 | m_intervalsaxis->setRange(min, max); |
|
228 | 228 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal"); |
|
229 | 229 | QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal"); |
|
230 | 230 | |
|
231 | 231 | QCOMPARE(spy0.count(), 1); |
|
232 | 232 | QCOMPARE(spy1.count(), 1); |
|
233 | 233 | QCOMPARE(spy2.count(), 1); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 |
void tst_Q |
|
|
236 | void tst_QCategoryAxis::range_data() | |
|
237 | 237 | { |
|
238 | 238 | range_raw_data(); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 |
void tst_Q |
|
|
241 | void tst_QCategoryAxis::range() | |
|
242 | 242 | { |
|
243 | 243 | m_chart->setAxisX(m_intervalsaxis, m_series); |
|
244 | 244 | m_view->show(); |
|
245 | 245 | QTest::qWaitForWindowShown(m_view); |
|
246 | 246 | range_raw(); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 |
void tst_Q |
|
|
249 | void tst_QCategoryAxis::range_animation_data() | |
|
250 | 250 | { |
|
251 | 251 | range_data(); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 |
void tst_Q |
|
|
254 | void tst_QCategoryAxis::range_animation() | |
|
255 | 255 | { |
|
256 | 256 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
257 | 257 | range(); |
|
258 | 258 | } |
|
259 | 259 | |
|
260 |
void tst_Q |
|
|
260 | void tst_QCategoryAxis::interval_data() | |
|
261 | 261 | { |
|
262 | 262 | // |
|
263 | 263 | } |
|
264 | 264 | |
|
265 |
void tst_Q |
|
|
265 | void tst_QCategoryAxis::interval() | |
|
266 | 266 | { |
|
267 | 267 | // append one correct interval |
|
268 | 268 | m_intervalsaxis->append("first", (qreal)45); |
|
269 | 269 | QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0); |
|
270 | 270 | QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45); |
|
271 | 271 | |
|
272 | 272 | // append one more correct interval |
|
273 | 273 | m_intervalsaxis->append("second", (qreal)75); |
|
274 | 274 | QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45); |
|
275 | 275 | QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75); |
|
276 | 276 | |
|
277 | 277 | // append one incorrect interval |
|
278 | 278 | m_intervalsaxis->append("third", (qreal)15); |
|
279 | 279 | QCOMPARE(m_intervalsaxis->count(), 2); |
|
280 | 280 | QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75); |
|
281 | 281 | // QCOMPARE(intervalMax("first"), (qreal)75); |
|
282 | 282 | |
|
283 | 283 | // append one more correct interval |
|
284 | 284 | m_intervalsaxis->append("third", (qreal)100); |
|
285 | 285 | QCOMPARE(m_intervalsaxis->count(), 3); |
|
286 | 286 | QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75); |
|
287 | 287 | QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100); |
|
288 | 288 | |
|
289 | 289 | // remove one interval |
|
290 | 290 | m_intervalsaxis->remove("first"); |
|
291 | 291 | QCOMPARE(m_intervalsaxis->count(), 2); |
|
292 | 292 | QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum |
|
293 | 293 | QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75); |
|
294 | 294 | |
|
295 | 295 | // remove one interval |
|
296 | 296 | m_intervalsaxis->replaceLabel("second", "replaced"); |
|
297 | 297 | QCOMPARE(m_intervalsaxis->count(), 2); |
|
298 | 298 | QCOMPARE(m_intervalsaxis->intervalMin("replaced"), (qreal)0); // second interval should extend to firstInterval minimum |
|
299 | 299 | QCOMPARE(m_intervalsaxis->intervalMax("replaced"), (qreal)75); |
|
300 | 300 | } |
|
301 | 301 | |
|
302 |
QTEST_MAIN(tst_Q |
|
|
302 | QTEST_MAIN(tst_QCategoryAxis) | |
|
303 | 303 | #include "tst_qintervalsaxis.moc" |
|
304 | 304 |
General Comments 0
You need to be logged in to leave comments.
Login now