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