@@ -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 | #include "chart.h" |
|
21 | #include "chart.h" | |
22 |
#include <Q |
|
22 | #include <QAxis> | |
23 | #include <QSplineSeries> |
|
23 | #include <QSplineSeries> | |
24 | #include <QTime> |
|
24 | #include <QTime> | |
25 |
|
25 | |||
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | :QChart(parent, wFlags), |
|
27 | :QChart(parent, wFlags), | |
28 | m_step(1), |
|
28 | m_step(1), | |
29 | m_x(0), |
|
29 | m_x(0), | |
30 | m_y(1) |
|
30 | m_y(1) | |
31 | { |
|
31 | { | |
32 | qsrand((uint) QTime::currentTime().msec()); |
|
32 | qsrand((uint) QTime::currentTime().msec()); | |
33 |
|
33 | |||
34 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); |
|
34 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); | |
35 | m_timer.setInterval(1000); |
|
35 | m_timer.setInterval(1000); | |
36 |
|
36 | |||
37 | m_series = new QSplineSeries(this); |
|
37 | m_series = new QSplineSeries(this); | |
38 | QPen green(Qt::red); |
|
38 | QPen green(Qt::red); | |
39 | green.setWidth(3); |
|
39 | green.setWidth(3); | |
40 | m_series->setPen(green); |
|
40 | m_series->setPen(green); | |
41 | m_series->append(m_x, m_y); |
|
41 | m_series->append(m_x, m_y); | |
42 |
|
42 | |||
43 | addSeries(m_series); |
|
43 | addSeries(m_series); | |
44 |
|
44 | |||
45 | axisY()->setRange(-5, 5); |
|
45 | axisY()->setRange(-5, 5); | |
46 | axisX()->setRange(-9, 1); |
|
46 | axisX()->setRange(-9, 1); | |
47 | axisX()->setTicksCount(11); |
|
47 | axisX()->setTicksCount(11); | |
48 |
|
48 | |||
49 | m_timer.start(); |
|
49 | m_timer.start(); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | Chart::~Chart() |
|
52 | Chart::~Chart() | |
53 | { |
|
53 | { | |
54 |
|
54 | |||
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void Chart::handleTimeout() |
|
57 | void Chart::handleTimeout() | |
58 | { |
|
58 | { | |
59 | m_x += m_step; |
|
59 | m_x += m_step; | |
60 | m_y = qrand() % 5 - 2.5; |
|
60 | m_y = qrand() % 5 - 2.5; | |
61 | m_series->append(m_x, m_y); |
|
61 | m_series->append(m_x, m_y); | |
62 | if (m_x >= 10) |
|
62 | if (m_x >= 10) | |
63 | m_series->remove(m_x - 10); |
|
63 | m_series->remove(m_x - 10); | |
64 | scrollRight(); |
|
64 | scrollRight(); | |
65 | } |
|
65 | } |
@@ -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 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | int main(int argc, char *argv[]) |
|
28 | int main(int argc, char *argv[]) | |
29 | { |
|
29 | { | |
30 | QApplication a(argc, argv); |
|
30 | QApplication a(argc, argv); | |
31 |
|
31 | |||
32 | //![1] |
|
32 | //![1] | |
33 | QLineSeries* series = new QLineSeries(); |
|
33 | QLineSeries* series = new QLineSeries(); | |
34 | *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); |
|
34 | *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); | |
35 | QChart* chart = new QChart(); |
|
35 | QChart* chart = new QChart(); | |
36 | chart->addSeries(series); |
|
36 | chart->addSeries(series); | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | // Customize series |
|
40 | // Customize series | |
41 | QPen pen(QRgb(0xfdb157)); |
|
41 | QPen pen(QRgb(0xfdb157)); | |
42 | pen.setWidth(5); |
|
42 | pen.setWidth(5); | |
43 | series->setPen(pen); |
|
43 | series->setPen(pen); | |
44 |
|
44 | |||
45 | // Customize chart title |
|
45 | // Customize chart title | |
46 | QFont font; |
|
46 | QFont font; | |
47 | font.setPixelSize(18); |
|
47 | font.setPixelSize(18); | |
48 | chart->setTitleFont(font); |
|
48 | chart->setTitleFont(font); | |
49 | chart->setTitleBrush(QBrush(Qt::white)); |
|
49 | chart->setTitleBrush(QBrush(Qt::white)); | |
50 | chart->setTitle("Customchart example"); |
|
50 | chart->setTitle("Customchart example"); | |
51 |
|
51 | |||
52 | // Customize chart background |
|
52 | // Customize chart background | |
53 | QLinearGradient backgroundGradient; |
|
53 | QLinearGradient backgroundGradient; | |
54 | backgroundGradient.setStart(QPointF(0,0)); |
|
54 | backgroundGradient.setStart(QPointF(0,0)); | |
55 | backgroundGradient.setFinalStop(QPointF(0,1)); |
|
55 | backgroundGradient.setFinalStop(QPointF(0,1)); | |
56 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); |
|
56 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); | |
57 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); |
|
57 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); | |
58 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
58 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
59 | chart->setBackgroundBrush(backgroundGradient); |
|
59 | chart->setBackgroundBrush(backgroundGradient); | |
60 | //![2] |
|
60 | //![2] | |
61 |
|
61 | |||
62 | //![3] |
|
62 | //![3] | |
63 |
Q |
|
63 | QAxis* axisX = chart->axisX(); | |
64 |
Q |
|
64 | QAxis* axisY = chart->axisY(); | |
65 |
|
65 | |||
66 | // Customize axis label font |
|
66 | // Customize axis label font | |
67 | QFont labelsFont; |
|
67 | QFont labelsFont; | |
68 | labelsFont.setPixelSize(12); |
|
68 | labelsFont.setPixelSize(12); | |
69 | axisX->setLabelsFont(labelsFont); |
|
69 | axisX->setLabelsFont(labelsFont); | |
70 | axisY->setLabelsFont(labelsFont); |
|
70 | axisY->setLabelsFont(labelsFont); | |
71 |
|
71 | |||
72 | // Customize axis colors |
|
72 | // Customize axis colors | |
73 | QPen axisPen(QRgb(0xd18952)); |
|
73 | QPen axisPen(QRgb(0xd18952)); | |
74 | axisPen.setWidth(2); |
|
74 | axisPen.setWidth(2); | |
75 | axisX->setAxisPen(axisPen); |
|
75 | axisX->setAxisPen(axisPen); | |
76 | axisY->setAxisPen(axisPen); |
|
76 | axisY->setAxisPen(axisPen); | |
77 |
|
77 | |||
78 | // Customize axis label colors |
|
78 | // Customize axis label colors | |
79 | QBrush axisBrush(Qt::white); |
|
79 | QBrush axisBrush(Qt::white); | |
80 | axisX->setLabelsBrush(axisBrush); |
|
80 | axisX->setLabelsBrush(axisBrush); | |
81 | axisY->setLabelsBrush(axisBrush); |
|
81 | axisY->setLabelsBrush(axisBrush); | |
82 |
|
82 | |||
83 | // Customize grid lines and shades |
|
83 | // Customize grid lines and shades | |
84 | axisX->setGridLineVisible(false); |
|
84 | axisX->setGridLineVisible(false); | |
85 | axisY->setGridLineVisible(false); |
|
85 | axisY->setGridLineVisible(false); | |
86 | axisY->setShadesPen(Qt::NoPen); |
|
86 | axisY->setShadesPen(Qt::NoPen); | |
87 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); |
|
87 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); | |
88 | axisY->setShadesVisible(true); |
|
88 | axisY->setShadesVisible(true); | |
89 | //![3] |
|
89 | //![3] | |
90 |
|
90 | |||
91 | //![4] |
|
91 | //![4] | |
92 | QChartAxisCategories* categoriesX = chart->axisX()->categories(); |
|
92 | QChartAxisCategories* categoriesX = chart->axisX()->categories(); | |
93 | categoriesX->insert(1,"low"); |
|
93 | categoriesX->insert(1,"low"); | |
94 | categoriesX->insert(5,"optimal"); |
|
94 | categoriesX->insert(5,"optimal"); | |
95 | categoriesX->insert(10,"high"); |
|
95 | categoriesX->insert(10,"high"); | |
96 |
|
96 | |||
97 | QChartAxisCategories* categoriesY = chart->axisY()->categories(); |
|
97 | QChartAxisCategories* categoriesY = chart->axisY()->categories(); | |
98 | categoriesY->insert(1,"slow"); |
|
98 | categoriesY->insert(1,"slow"); | |
99 | categoriesY->insert(5,"med"); |
|
99 | categoriesY->insert(5,"med"); | |
100 | categoriesY->insert(10,"fast"); |
|
100 | categoriesY->insert(10,"fast"); | |
101 |
|
101 | |||
102 | axisX->setRange(0,10); |
|
102 | axisX->setRange(0,10); | |
103 | axisX->setTicksCount(4); |
|
103 | axisX->setTicksCount(4); | |
104 | axisY->setRange(0,10); |
|
104 | axisY->setRange(0,10); | |
105 | axisY->setTicksCount(4); |
|
105 | axisY->setTicksCount(4); | |
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,51 +1,51 | |||||
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 "drilldownchart.h" |
|
21 | #include "drilldownchart.h" | |
22 |
#include <Q |
|
22 | #include <QAxis> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
25 | |||
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | : QChart(parent, wFlags) |
|
27 | : QChart(parent, wFlags) | |
28 | ,m_currentSeries(0) |
|
28 | ,m_currentSeries(0) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void DrilldownChart::changeSeries(QAbstractSeries *series) |
|
32 | void DrilldownChart::changeSeries(QAbstractSeries *series) | |
33 | { |
|
33 | { | |
34 | if (m_currentSeries) { |
|
34 | if (m_currentSeries) { | |
35 | removeSeries(m_currentSeries); |
|
35 | removeSeries(m_currentSeries); | |
36 | } |
|
36 | } | |
37 | m_currentSeries = series; |
|
37 | m_currentSeries = series; | |
38 | addSeries(series); |
|
38 | addSeries(series); | |
39 | setTitle(series->name()); |
|
39 | setTitle(series->name()); | |
40 | axisY()->setNiceNumbersEnabled(true); |
|
40 | axisY()->setNiceNumbersEnabled(true); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void DrilldownChart::handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button) |
|
43 | void DrilldownChart::handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button) | |
44 | { |
|
44 | { | |
45 | Q_UNUSED(barset) |
|
45 | Q_UNUSED(barset) | |
46 | Q_UNUSED(button) |
|
46 | Q_UNUSED(button) | |
47 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); |
|
47 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |
48 | changeSeries(series->drilldownSeries(category)); |
|
48 | changeSeries(series->drilldownSeries(category)); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | #include "moc_drilldownchart.cpp" |
|
51 | #include "moc_drilldownchart.cpp" |
@@ -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 | #include "axisanimation_p.h" |
|
21 | #include "axisanimation_p.h" | |
22 | #include <QTimer> |
|
22 | #include <QTimer> | |
23 |
|
23 | |||
24 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
24 | Q_DECLARE_METATYPE(QVector<qreal>) | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | AxisAnimation::AxisAnimation(Axis *axis): ChartAnimation(axis), |
|
29 | AxisAnimation::AxisAnimation(ChartAxis *axis): ChartAnimation(axis), | |
30 | m_axis(axis) |
|
30 | m_axis(axis) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | AxisAnimation::~AxisAnimation() |
|
34 | AxisAnimation::~AxisAnimation() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const |
|
38 | QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const | |
39 | { |
|
39 | { | |
40 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); |
|
40 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); | |
41 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); |
|
41 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); | |
42 | QVector<qreal> result; |
|
42 | QVector<qreal> result; | |
43 |
|
43 | |||
44 | Q_ASSERT(startVector.count() == endVecotr.count()) ; |
|
44 | Q_ASSERT(startVector.count() == endVecotr.count()) ; | |
45 |
|
45 | |||
46 | for(int i = 0; i < startVector.count(); i++){ |
|
46 | for(int i = 0; i < startVector.count(); i++){ | |
47 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); |
|
47 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); | |
48 | result << value; |
|
48 | result << value; | |
49 | } |
|
49 | } | |
50 | return qVariantFromValue(result); |
|
50 | return qVariantFromValue(result); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | void AxisAnimation::updateCurrentValue (const QVariant &value ) |
|
54 | void AxisAnimation::updateCurrentValue (const QVariant &value ) | |
55 | { |
|
55 | { | |
56 | if (state() != QAbstractAnimation::Stopped)//workaround |
|
56 | if (state() != QAbstractAnimation::Stopped)//workaround | |
57 | { |
|
57 | { | |
58 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); |
|
58 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); | |
59 | Q_ASSERT(vector.count() != 0); |
|
59 | Q_ASSERT(vector.count() != 0); | |
60 | m_axis->setLayout(vector); |
|
60 | m_axis->setLayout(vector); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,46 | |||||
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 AXISANIMATION_H |
|
21 | #ifndef AXISANIMATION_H | |
22 | #define AXISANIMATION_H |
|
22 | #define AXISANIMATION_H | |
23 |
|
23 | |||
24 | #include "axis_p.h" |
|
24 | #include "chartaxis_p.h" | |
25 | #include "chartanimation_p.h" |
|
25 | #include "chartanimation_p.h" | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class AxisAnimation: public ChartAnimation |
|
30 | class AxisAnimation: public ChartAnimation | |
31 | { |
|
31 | { | |
32 | public: |
|
32 | public: | |
33 | AxisAnimation(Axis *axis); |
|
33 | AxisAnimation(ChartAxis *axis); | |
34 | ~AxisAnimation(); |
|
34 | ~AxisAnimation(); | |
35 | protected: |
|
35 | protected: | |
36 | QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress ) const; |
|
36 | QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress ) const; | |
37 | void updateCurrentValue(const QVariant &value ); |
|
37 | void updateCurrentValue(const QVariant &value ); | |
38 | private: |
|
38 | private: | |
39 | Axis *m_axis; |
|
39 | ChartAxis *m_axis; | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | QTCOMMERCIALCHART_END_NAMESPACE |
|
42 | QTCOMMERCIALCHART_END_NAMESPACE | |
43 |
|
43 | |||
44 |
|
44 | |||
45 |
|
45 | |||
46 | #endif /* AXISITEM_H_ */ |
|
46 | #endif /* AXISITEM_H_ */ |
@@ -1,301 +1,301 | |||||
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 "chartanimator_p.h" |
|
21 | #include "chartanimator_p.h" | |
22 | #include "axisanimation_p.h" |
|
22 | #include "axisanimation_p.h" | |
23 | #include "xyanimation_p.h" |
|
23 | #include "xyanimation_p.h" | |
24 | #include "splineanimation_p.h" |
|
24 | #include "splineanimation_p.h" | |
25 | #include "xychartitem_p.h" |
|
25 | #include "xychartitem_p.h" | |
26 | #include "pieanimation_p.h" |
|
26 | #include "pieanimation_p.h" | |
27 | #include "baranimation_p.h" |
|
27 | #include "baranimation_p.h" | |
28 | #include "barchartitem_p.h" |
|
28 | #include "barchartitem_p.h" | |
29 | #include "areachartitem_p.h" |
|
29 | #include "areachartitem_p.h" | |
30 | #include "splinechartitem_p.h" |
|
30 | #include "splinechartitem_p.h" | |
31 | #include "scatterchartitem_p.h" |
|
31 | #include "scatterchartitem_p.h" | |
32 | #include <QTimer> |
|
32 | #include <QTimer> | |
33 |
|
33 | |||
34 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
34 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
35 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
35 | Q_DECLARE_METATYPE(QVector<qreal>) | |
36 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
36 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | const static int duration = 1000; |
|
40 | const static int duration = 1000; | |
41 |
|
41 | |||
42 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent), |
|
42 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent), | |
43 | m_state(ShowState) |
|
43 | m_state(ShowState) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | ChartAnimator::~ChartAnimator() |
|
47 | ChartAnimator::~ChartAnimator() | |
48 | { |
|
48 | { | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void ChartAnimator::addAnimation(Axis *item) |
|
51 | void ChartAnimator::addAnimation(ChartAxis *item) | |
52 | { |
|
52 | { | |
53 | ChartAnimation *animation = m_animations.value(item); |
|
53 | ChartAnimation *animation = m_animations.value(item); | |
54 |
|
54 | |||
55 | if (!animation) { |
|
55 | if (!animation) { | |
56 | animation = new AxisAnimation(item); |
|
56 | animation = new AxisAnimation(item); | |
57 | m_animations.insert(item, animation); |
|
57 | m_animations.insert(item, animation); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | item->setAnimator(this); |
|
60 | item->setAnimator(this); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void ChartAnimator::addAnimation(SplineChartItem *item) |
|
63 | void ChartAnimator::addAnimation(SplineChartItem *item) | |
64 | { |
|
64 | { | |
65 | ChartAnimation *animation = m_animations.value(item); |
|
65 | ChartAnimation *animation = m_animations.value(item); | |
66 |
|
66 | |||
67 | if (!animation) { |
|
67 | if (!animation) { | |
68 | animation = new SplineAnimation(item); |
|
68 | animation = new SplineAnimation(item); | |
69 | m_animations.insert(item, animation); |
|
69 | m_animations.insert(item, animation); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | item->setAnimator(this); |
|
72 | item->setAnimator(this); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartAnimator::addAnimation(ScatterChartItem *item) |
|
75 | void ChartAnimator::addAnimation(ScatterChartItem *item) | |
76 | { |
|
76 | { | |
77 | ChartAnimation *animation = m_animations.value(item); |
|
77 | ChartAnimation *animation = m_animations.value(item); | |
78 |
|
78 | |||
79 | if (!animation) { |
|
79 | if (!animation) { | |
80 | animation = new XYAnimation(item); |
|
80 | animation = new XYAnimation(item); | |
81 | m_animations.insert(item, animation); |
|
81 | m_animations.insert(item, animation); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | item->setAnimator(this); |
|
84 | item->setAnimator(this); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void ChartAnimator::addAnimation(LineChartItem *item) |
|
87 | void ChartAnimator::addAnimation(LineChartItem *item) | |
88 | { |
|
88 | { | |
89 | ChartAnimation *animation = m_animations.value(item); |
|
89 | ChartAnimation *animation = m_animations.value(item); | |
90 |
|
90 | |||
91 | if (!animation) { |
|
91 | if (!animation) { | |
92 | animation = new XYAnimation(item); |
|
92 | animation = new XYAnimation(item); | |
93 | m_animations.insert(item, animation); |
|
93 | m_animations.insert(item, animation); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | item->setAnimator(this); |
|
96 | item->setAnimator(this); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartAnimator::addAnimation(PieChartItem *item) |
|
99 | void ChartAnimator::addAnimation(PieChartItem *item) | |
100 | { |
|
100 | { | |
101 | ChartAnimation *animation = m_animations.value(item); |
|
101 | ChartAnimation *animation = m_animations.value(item); | |
102 |
|
102 | |||
103 | if (!animation) { |
|
103 | if (!animation) { | |
104 | animation = new PieAnimation(item); |
|
104 | animation = new PieAnimation(item); | |
105 | m_animations.insert(item, animation); |
|
105 | m_animations.insert(item, animation); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | item->setAnimator(this); |
|
108 | item->setAnimator(this); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void ChartAnimator::addAnimation(BarChartItem *item) |
|
111 | void ChartAnimator::addAnimation(BarChartItem *item) | |
112 | { |
|
112 | { | |
113 | ChartAnimation *animation = m_animations.value(item); |
|
113 | ChartAnimation *animation = m_animations.value(item); | |
114 |
|
114 | |||
115 | if (!animation) { |
|
115 | if (!animation) { | |
116 | animation = new BarAnimation(item); |
|
116 | animation = new BarAnimation(item); | |
117 | m_animations.insert(item, animation); |
|
117 | m_animations.insert(item, animation); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | item->setAnimator(this); |
|
120 | item->setAnimator(this); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | void ChartAnimator::removeAnimation(Chart *item) |
|
124 | void ChartAnimator::removeAnimation(Chart *item) | |
125 | { |
|
125 | { | |
126 | item->setAnimator(0); |
|
126 | item->setAnimator(0); | |
127 | m_animations.remove(item); |
|
127 | m_animations.remove(item); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void ChartAnimator::updateLayout(Axis *item , QVector<qreal> &newLayout) |
|
130 | void ChartAnimator::updateLayout(ChartAxis *item , QVector<qreal> &newLayout) | |
131 | { |
|
131 | { | |
132 | AxisAnimation *animation = static_cast<AxisAnimation*>(m_animations.value(item)); |
|
132 | AxisAnimation *animation = static_cast<AxisAnimation*>(m_animations.value(item)); | |
133 |
|
133 | |||
134 | Q_ASSERT(animation); |
|
134 | Q_ASSERT(animation); | |
135 |
|
135 | |||
136 | QVector<qreal> oldLayout = item->layout(); |
|
136 | QVector<qreal> oldLayout = item->layout(); | |
137 |
|
137 | |||
138 | if (newLayout.count() == 0) |
|
138 | if (newLayout.count() == 0) | |
139 | return; |
|
139 | return; | |
140 |
|
140 | |||
141 | switch (m_state) { |
|
141 | switch (m_state) { | |
142 | case ZoomOutState: { |
|
142 | case ZoomOutState: { | |
143 | QRectF rect = item->geometry(); |
|
143 | QRectF rect = item->geometry(); | |
144 | oldLayout.resize(newLayout.count()); |
|
144 | oldLayout.resize(newLayout.count()); | |
145 |
|
145 | |||
146 | for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { |
|
146 | for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { | |
147 | oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.bottom(); |
|
147 | oldLayout[i] = item->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.bottom(); | |
148 | oldLayout[j] = item->axisType() == Axis::X_AXIS ? rect.right() : rect.top(); |
|
148 | oldLayout[j] = item->axisType() == ChartAxis::X_AXIS ? rect.right() : rect.top(); | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
151 | break; |
|
151 | break; | |
152 | case ZoomInState: { |
|
152 | case ZoomInState: { | |
153 | int index = qMin(oldLayout.count() * (item->axisType() == Axis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - 1.0); |
|
153 | int index = qMin(oldLayout.count() * (item->axisType() == ChartAxis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - 1.0); | |
154 | oldLayout.resize(newLayout.count()); |
|
154 | oldLayout.resize(newLayout.count()); | |
155 |
|
155 | |||
156 | for(int i = 0; i < oldLayout.count(); i++) |
|
156 | for(int i = 0; i < oldLayout.count(); i++) | |
157 | oldLayout[i]= oldLayout[index]; |
|
157 | oldLayout[i]= oldLayout[index]; | |
158 | } |
|
158 | } | |
159 | break; |
|
159 | break; | |
160 | case ScrollDownState: |
|
160 | case ScrollDownState: | |
161 | case ScrollRightState: { |
|
161 | case ScrollRightState: { | |
162 | oldLayout.resize(newLayout.count()); |
|
162 | oldLayout.resize(newLayout.count()); | |
163 |
|
163 | |||
164 | for(int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) |
|
164 | for(int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) | |
165 | oldLayout[i]= oldLayout[j]; |
|
165 | oldLayout[i]= oldLayout[j]; | |
166 | } |
|
166 | } | |
167 | break; |
|
167 | break; | |
168 | case ScrollUpState: |
|
168 | case ScrollUpState: | |
169 | case ScrollLeftState: { |
|
169 | case ScrollLeftState: { | |
170 | oldLayout.resize(newLayout.count()); |
|
170 | oldLayout.resize(newLayout.count()); | |
171 |
|
171 | |||
172 | for(int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) |
|
172 | for(int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) | |
173 | oldLayout[i]= oldLayout[j]; |
|
173 | oldLayout[i]= oldLayout[j]; | |
174 | } |
|
174 | } | |
175 | break; |
|
175 | break; | |
176 | default: { |
|
176 | default: { | |
177 | oldLayout.resize(newLayout.count()); |
|
177 | oldLayout.resize(newLayout.count()); | |
178 | QRectF rect = item->geometry(); |
|
178 | QRectF rect = item->geometry(); | |
179 | for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) |
|
179 | for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) | |
180 | oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.top(); |
|
180 | oldLayout[i] = item->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.top(); | |
181 | } |
|
181 | } | |
182 | break; |
|
182 | break; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | if (animation->state() != QAbstractAnimation::Stopped) |
|
186 | if (animation->state() != QAbstractAnimation::Stopped) | |
187 | animation->stop(); |
|
187 | animation->stop(); | |
188 |
|
188 | |||
189 | animation->setDuration(duration); |
|
189 | animation->setDuration(duration); | |
190 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
190 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
191 | QVariantAnimation::KeyValues value; |
|
191 | QVariantAnimation::KeyValues value; | |
192 | animation->setKeyValues(value); //workaround for wrong interpolation call |
|
192 | animation->setKeyValues(value); //workaround for wrong interpolation call | |
193 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
193 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
194 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
194 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
195 |
|
195 | |||
196 | QTimer::singleShot(0, animation, SLOT(start())); |
|
196 | QTimer::singleShot(0, animation, SLOT(start())); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void ChartAnimator::updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index) |
|
199 | void ChartAnimator::updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index) | |
200 | { |
|
200 | { | |
201 | SplineAnimation *animation = static_cast<SplineAnimation *>(m_animations.value(item)); |
|
201 | SplineAnimation *animation = static_cast<SplineAnimation *>(m_animations.value(item)); | |
202 |
|
202 | |||
203 | Q_ASSERT(animation); |
|
203 | Q_ASSERT(animation); | |
204 |
|
204 | |||
205 | if (newPoints.count() < 2 || newControlPoints.count() < 2) |
|
205 | if (newPoints.count() < 2 || newControlPoints.count() < 2) | |
206 | return; |
|
206 | return; | |
207 |
|
207 | |||
208 | bool empty = oldPoints.count() == 0; |
|
208 | bool empty = oldPoints.count() == 0; | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | if (animation->state() != QAbstractAnimation::Stopped) |
|
211 | if (animation->state() != QAbstractAnimation::Stopped) | |
212 | animation->stop(); |
|
212 | animation->stop(); | |
213 |
|
213 | |||
214 | animation->setDuration(duration); |
|
214 | animation->setDuration(duration); | |
215 | if (!empty) |
|
215 | if (!empty) | |
216 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); |
|
216 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); | |
217 | else |
|
217 | else | |
218 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); |
|
218 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); | |
219 |
|
219 | |||
220 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
220 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
221 | animation->setValues(oldPoints, newPoints, oldControlPoints, newControlPoints, index); |
|
221 | animation->setValues(oldPoints, newPoints, oldControlPoints, newControlPoints, index); | |
222 |
|
222 | |||
223 | QTimer::singleShot(0, animation, SLOT(start())); |
|
223 | QTimer::singleShot(0, animation, SLOT(start())); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 |
|
226 | |||
227 | void ChartAnimator::updateLayout(XYChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) |
|
227 | void ChartAnimator::updateLayout(XYChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index) | |
228 | { |
|
228 | { | |
229 | XYAnimation *animation = static_cast<XYAnimation *>(m_animations.value(item)); |
|
229 | XYAnimation *animation = static_cast<XYAnimation *>(m_animations.value(item)); | |
230 |
|
230 | |||
231 | Q_ASSERT(animation); |
|
231 | Q_ASSERT(animation); | |
232 |
|
232 | |||
233 | if (newPoints.count() == 0) |
|
233 | if (newPoints.count() == 0) | |
234 | return; |
|
234 | return; | |
235 |
|
235 | |||
236 | bool empty = oldPoints.count() == 0; |
|
236 | bool empty = oldPoints.count() == 0; | |
237 |
|
237 | |||
238 |
|
238 | |||
239 | if (animation->state() != QAbstractAnimation::Stopped) |
|
239 | if (animation->state() != QAbstractAnimation::Stopped) | |
240 | animation->stop(); |
|
240 | animation->stop(); | |
241 |
|
241 | |||
242 | animation->setDuration(duration); |
|
242 | animation->setDuration(duration); | |
243 | if (!empty) |
|
243 | if (!empty) | |
244 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); |
|
244 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); | |
245 | else |
|
245 | else | |
246 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); |
|
246 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); | |
247 |
|
247 | |||
248 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
248 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
249 | animation->setValues(oldPoints, newPoints, index); |
|
249 | animation->setValues(oldPoints, newPoints, index); | |
250 |
|
250 | |||
251 | QTimer::singleShot(0, animation, SLOT(start())); |
|
251 | QTimer::singleShot(0, animation, SLOT(start())); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void ChartAnimator::addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) |
|
254 | void ChartAnimator::addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) | |
255 | { |
|
255 | { | |
256 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
256 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
257 | Q_ASSERT(animation); |
|
257 | Q_ASSERT(animation); | |
258 | animation->addSlice(slice, sliceData, isEmpty); |
|
258 | animation->addSlice(slice, sliceData, isEmpty); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | void ChartAnimator::removeAnimation(PieChartItem *item, QPieSlice *slice) |
|
261 | void ChartAnimator::removeAnimation(PieChartItem *item, QPieSlice *slice) | |
262 | { |
|
262 | { | |
263 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
263 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
264 | Q_ASSERT(animation); |
|
264 | Q_ASSERT(animation); | |
265 | animation->removeSlice(slice); |
|
265 | animation->removeSlice(slice); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void ChartAnimator::updateLayout(PieChartItem *item, const PieLayout &layout) |
|
268 | void ChartAnimator::updateLayout(PieChartItem *item, const PieLayout &layout) | |
269 | { |
|
269 | { | |
270 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
270 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
271 | Q_ASSERT(animation); |
|
271 | Q_ASSERT(animation); | |
272 | animation->updateValues(layout); |
|
272 | animation->updateValues(layout); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | void ChartAnimator::updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData) |
|
275 | void ChartAnimator::updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData) | |
276 | { |
|
276 | { | |
277 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
277 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
278 | Q_ASSERT(animation); |
|
278 | Q_ASSERT(animation); | |
279 | animation->updateValue(slice, sliceData); |
|
279 | animation->updateValue(slice, sliceData); | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) |
|
282 | void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |
283 | { |
|
283 | { | |
284 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); |
|
284 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); | |
285 | Q_ASSERT(animation); |
|
285 | Q_ASSERT(animation); | |
286 | animation->setDuration(duration); |
|
286 | animation->setDuration(duration); | |
287 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
287 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
288 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
288 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
289 | QTimer::singleShot(0, animation, SLOT(start())); |
|
289 | QTimer::singleShot(0, animation, SLOT(start())); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 |
|
292 | |||
293 | void ChartAnimator::setState(State state, const QPointF &point) |
|
293 | void ChartAnimator::setState(State state, const QPointF &point) | |
294 | { |
|
294 | { | |
295 | m_state = state; |
|
295 | m_state = state; | |
296 | m_point = point; |
|
296 | m_point = point; | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | #include "moc_chartanimator_p.cpp" |
|
299 | #include "moc_chartanimator_p.cpp" | |
300 |
|
300 | |||
301 | QTCOMMERCIALCHART_END_NAMESPACE |
|
301 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,79 +1,79 | |||||
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 CHARTANIMATOR_P_H |
|
21 | #ifndef CHARTANIMATOR_P_H | |
22 | #define CHARTANIMATOR_P_H |
|
22 | #define CHARTANIMATOR_P_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "chartanimation_p.h" |
|
25 | #include "chartanimation_p.h" | |
26 | #include "piechartitem_p.h" |
|
26 | #include "piechartitem_p.h" | |
27 | #include "barchartitem_p.h" |
|
27 | #include "barchartitem_p.h" | |
28 | #include <QPointF> |
|
28 | #include <QPointF> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class ChartItem; |
|
32 | class ChartItem; | |
33 | class Axis; |
|
33 | class ChartAxis; | |
34 | class AreaChartItem; |
|
34 | class AreaChartItem; | |
35 | class SplineChartItem; |
|
35 | class SplineChartItem; | |
36 | class ScatterChartItem; |
|
36 | class ScatterChartItem; | |
37 | class LineChartItem; |
|
37 | class LineChartItem; | |
38 | class XYChartItem; |
|
38 | class XYChartItem; | |
39 |
|
39 | |||
40 | class ChartAnimator : public QObject |
|
40 | class ChartAnimator : public QObject | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 | enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState, ScrollRightState, ZoomInState, ZoomOutState}; |
|
44 | enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState, ScrollRightState, ZoomInState, ZoomOutState}; | |
45 |
|
45 | |||
46 | ChartAnimator(QObject *parent = 0); |
|
46 | ChartAnimator(QObject *parent = 0); | |
47 | virtual ~ChartAnimator(); |
|
47 | virtual ~ChartAnimator(); | |
48 |
|
48 | |||
49 | void addAnimation(Axis *item); |
|
49 | void addAnimation(ChartAxis *item); | |
50 | void addAnimation(PieChartItem *item); |
|
50 | void addAnimation(PieChartItem *item); | |
51 | void addAnimation(ScatterChartItem *item); |
|
51 | void addAnimation(ScatterChartItem *item); | |
52 | void addAnimation(LineChartItem *item); |
|
52 | void addAnimation(LineChartItem *item); | |
53 | void addAnimation(SplineChartItem *item); |
|
53 | void addAnimation(SplineChartItem *item); | |
54 | void addAnimation(BarChartItem *item); |
|
54 | void addAnimation(BarChartItem *item); | |
55 | void removeAnimation(Chart *item); |
|
55 | void removeAnimation(Chart *item); | |
56 |
|
56 | |||
57 | void animationStarted(); |
|
57 | void animationStarted(); | |
58 | void updateLayout(XYChartItem *item, QVector<QPointF> &oldLayout, QVector<QPointF> &newLayout, int index); |
|
58 | void updateLayout(XYChartItem *item, QVector<QPointF> &oldLayout, QVector<QPointF> &newLayout, int index); | |
59 | void updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newContorlPoints, int index); |
|
59 | void updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newContorlPoints, int index); | |
60 | void updateLayout(Axis *item, QVector<qreal> &layout); |
|
60 | void updateLayout(ChartAxis *item, QVector<qreal> &layout); | |
61 |
|
61 | |||
62 | void addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); |
|
62 | void addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); | |
63 | void removeAnimation(PieChartItem *item, QPieSlice *slice); |
|
63 | void removeAnimation(PieChartItem *item, QPieSlice *slice); | |
64 | void updateLayout(PieChartItem *item, const PieLayout &layout); |
|
64 | void updateLayout(PieChartItem *item, const PieLayout &layout); | |
65 | void updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData); |
|
65 | void updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData); | |
66 |
|
66 | |||
67 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
67 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
68 |
|
68 | |||
69 | void setState(State state,const QPointF &point = QPointF()); |
|
69 | void setState(State state,const QPointF &point = QPointF()); | |
70 |
|
70 | |||
71 | private: |
|
71 | private: | |
72 | QMap<Chart *, ChartAnimation *> m_animations; |
|
72 | QMap<Chart *, ChartAnimation *> m_animations; | |
73 | State m_state; |
|
73 | State m_state; | |
74 | QPointF m_point; |
|
74 | QPointF m_point; | |
75 | }; |
|
75 | }; | |
76 |
|
76 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE | |
78 |
|
78 | |||
79 | #endif |
|
79 | #endif |
@@ -1,16 +1,16 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/axis.cpp \ |
|
5 | $$PWD/chartaxis.cpp \ | |
6 |
$$PWD/q |
|
6 | $$PWD/qaxis.cpp \ | |
7 | $$PWD/qchartaxiscategories.cpp |
|
7 | $$PWD/qchartaxiscategories.cpp | |
8 |
|
8 | |||
9 | PRIVATE_HEADERS += \ |
|
9 | PRIVATE_HEADERS += \ | |
10 | $$PWD/axis_p.h \ |
|
10 | $$PWD/chartaxis_p.h \ | |
11 |
$$PWD/q |
|
11 | $$PWD/qaxis_p.h \ | |
12 | $$PWD/qchartaxiscategories_p.h |
|
12 | $$PWD/qchartaxiscategories_p.h | |
13 |
|
13 | |||
14 | PUBLIC_HEADERS += \ |
|
14 | PUBLIC_HEADERS += \ | |
15 |
$$PWD/q |
|
15 | $$PWD/qaxis.h \ | |
16 | $$PWD/qchartaxiscategories.h No newline at end of file |
|
16 | $$PWD/qchartaxiscategories.h |
@@ -1,466 +1,466 | |||||
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 "axis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 |
#include "q |
|
22 | #include "qaxis.h" | |
23 |
#include "q |
|
23 | #include "qaxis_p.h" | |
24 | #include "qchartaxiscategories_p.h" |
|
24 | #include "qchartaxiscategories_p.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 | #include <cmath> |
|
29 | #include <cmath> | |
30 |
|
30 | |||
31 | static int label_padding = 5; |
|
31 | static int label_padding = 5; | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 |
Axis::Axis(Q |
|
35 | ChartAxis::ChartAxis(QAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter), | |
36 | m_chartAxis(axis), |
|
36 | m_chartAxis(axis), | |
37 | m_type(type), |
|
37 | m_type(type), | |
38 | m_labelsAngle(0), |
|
38 | m_labelsAngle(0), | |
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
42 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), |
|
42 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
43 | m_min(0), |
|
43 | m_min(0), | |
44 | m_max(0), |
|
44 | m_max(0), | |
45 | m_ticksCount(0) |
|
45 | m_ticksCount(0) | |
46 | { |
|
46 | { | |
47 | //initial initialization |
|
47 | //initial initialization | |
48 | m_axis->setZValue(ChartPresenter::AxisZValue); |
|
48 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
49 | m_axis->setHandlesChildEvents(false); |
|
49 | m_axis->setHandlesChildEvents(false); | |
50 |
|
50 | |||
51 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
51 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
52 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
52 | m_grid->setZValue(ChartPresenter::GridZValue); | |
53 |
|
53 | |||
54 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
54 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
55 | QObject::connect(m_chartAxis->categories()->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); |
|
55 | QObject::connect(m_chartAxis->categories()->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |
56 |
|
56 | |||
57 | handleAxisUpdated(); |
|
57 | handleAxisUpdated(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | Axis::~Axis() |
|
60 | ChartAxis::~ChartAxis() | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void Axis::createItems(int count) |
|
64 | void ChartAxis::createItems(int count) | |
65 | { |
|
65 | { | |
66 |
|
66 | |||
67 | if (m_axis->children().size() == 0) |
|
67 | if (m_axis->children().size() == 0) | |
68 | m_axis->addToGroup(new AxisItem(this)); |
|
68 | m_axis->addToGroup(new AxisItem(this)); | |
69 | for (int i = 0; i < count; ++i) { |
|
69 | for (int i = 0; i < count; ++i) { | |
70 | m_grid->addToGroup(new QGraphicsLineItem()); |
|
70 | m_grid->addToGroup(new QGraphicsLineItem()); | |
71 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); |
|
71 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
72 | m_axis->addToGroup(new QGraphicsLineItem()); |
|
72 | m_axis->addToGroup(new QGraphicsLineItem()); | |
73 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); |
|
73 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); | |
74 | } |
|
74 | } | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void Axis::deleteItems(int count) |
|
77 | void ChartAxis::deleteItems(int count) | |
78 | { |
|
78 | { | |
79 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
79 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
80 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
80 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
81 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
81 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
82 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
82 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
83 |
|
83 | |||
84 | for (int i = 0; i < count; ++i) { |
|
84 | for (int i = 0; i < count; ++i) { | |
85 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
85 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
86 | delete(lines.takeLast()); |
|
86 | delete(lines.takeLast()); | |
87 | delete(labels.takeLast()); |
|
87 | delete(labels.takeLast()); | |
88 | delete(axis.takeLast()); |
|
88 | delete(axis.takeLast()); | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void Axis::updateLayout(QVector<qreal> &layout) |
|
92 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
93 | { |
|
93 | { | |
94 | if (animator()) { |
|
94 | if (animator()) { | |
95 | animator()->updateLayout(this,layout); |
|
95 | animator()->updateLayout(this,layout); | |
96 | } else { |
|
96 | } else { | |
97 | setLayout(layout); |
|
97 | setLayout(layout); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const |
|
101 | bool ChartAxis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const | |
102 | { |
|
102 | { | |
103 | Q_ASSERT(max>=min); |
|
103 | Q_ASSERT(max>=min); | |
104 | Q_ASSERT(ticks>1); |
|
104 | Q_ASSERT(ticks>1); | |
105 |
|
105 | |||
106 | QChartAxisCategories* categories = m_chartAxis->categories(); |
|
106 | QChartAxisCategories* categories = m_chartAxis->categories(); | |
107 |
|
107 | |||
108 | bool category = categories->count()>0; |
|
108 | bool category = categories->count()>0; | |
109 |
|
109 | |||
110 | if (!category) { |
|
110 | if (!category) { | |
111 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
111 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
112 | n++; |
|
112 | n++; | |
113 | for (int i=0; i< ticks; i++) { |
|
113 | for (int i=0; i< ticks; i++) { | |
114 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
114 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
115 | labels << QString::number(value,'f',n); |
|
115 | labels << QString::number(value,'f',n); | |
116 | } |
|
116 | } | |
117 | } else { |
|
117 | } else { | |
118 | QList<qreal> values = categories->values(); |
|
118 | QList<qreal> values = categories->values(); | |
119 | for (int i=0; i< ticks; i++) { |
|
119 | for (int i=0; i< ticks; i++) { | |
120 | qreal value = (min + (i * (max - min)/ (ticks-1))); |
|
120 | qreal value = (min + (i * (max - min)/ (ticks-1))); | |
121 | int j=0; |
|
121 | int j=0; | |
122 | for (; j<values.count(); j++) { |
|
122 | for (; j<values.count(); j++) { | |
123 | if (values.at(j) > value) break; |
|
123 | if (values.at(j) > value) break; | |
124 | } |
|
124 | } | |
125 | if (j!=0) value=values.at(j-1); |
|
125 | if (j!=0) value=values.at(j-1); | |
126 |
|
126 | |||
127 | QString label = categories->label(value); |
|
127 | QString label = categories->label(value); | |
128 | labels << label; |
|
128 | labels << label; | |
129 | } |
|
129 | } | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | return category; |
|
132 | return category; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void Axis::setAxisOpacity(qreal opacity) |
|
135 | void ChartAxis::setAxisOpacity(qreal opacity) | |
136 | { |
|
136 | { | |
137 | m_axis->setOpacity(opacity); |
|
137 | m_axis->setOpacity(opacity); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | qreal Axis::axisOpacity() const |
|
140 | qreal ChartAxis::axisOpacity() const | |
141 | { |
|
141 | { | |
142 | return m_axis->opacity(); |
|
142 | return m_axis->opacity(); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void Axis::setGridOpacity(qreal opacity) |
|
145 | void ChartAxis::setGridOpacity(qreal opacity) | |
146 | { |
|
146 | { | |
147 | m_grid->setOpacity(opacity); |
|
147 | m_grid->setOpacity(opacity); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | qreal Axis::gridOpacity() const |
|
150 | qreal ChartAxis::gridOpacity() const | |
151 | { |
|
151 | { | |
152 | return m_grid->opacity(); |
|
152 | return m_grid->opacity(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void Axis::setLabelsOpacity(qreal opacity) |
|
155 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
156 | { |
|
156 | { | |
157 | m_labels->setOpacity(opacity); |
|
157 | m_labels->setOpacity(opacity); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | qreal Axis::labelsOpacity() const |
|
160 | qreal ChartAxis::labelsOpacity() const | |
161 | { |
|
161 | { | |
162 | return m_labels->opacity(); |
|
162 | return m_labels->opacity(); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void Axis::setShadesOpacity(qreal opacity) |
|
165 | void ChartAxis::setShadesOpacity(qreal opacity) | |
166 | { |
|
166 | { | |
167 | m_shades->setOpacity(opacity); |
|
167 | m_shades->setOpacity(opacity); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | qreal Axis::shadesOpacity() const |
|
170 | qreal ChartAxis::shadesOpacity() const | |
171 | { |
|
171 | { | |
172 | return m_shades->opacity(); |
|
172 | return m_shades->opacity(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void Axis::setLabelsAngle(int angle) |
|
175 | void ChartAxis::setLabelsAngle(int angle) | |
176 | { |
|
176 | { | |
177 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
177 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
178 | item->setRotation(angle); |
|
178 | item->setRotation(angle); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | m_labelsAngle=angle; |
|
181 | m_labelsAngle=angle; | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void Axis::setLabelsPen(const QPen &pen) |
|
184 | void ChartAxis::setLabelsPen(const QPen &pen) | |
185 | { |
|
185 | { | |
186 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
186 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
187 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
187 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void Axis::setLabelsBrush(const QBrush &brush) |
|
191 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
192 | { |
|
192 | { | |
193 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
193 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
194 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
194 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | void Axis::setLabelsFont(const QFont &font) |
|
198 | void ChartAxis::setLabelsFont(const QFont &font) | |
199 | { |
|
199 | { | |
200 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
200 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
201 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
201 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void Axis::setShadesBrush(const QBrush &brush) |
|
205 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
206 | { |
|
206 | { | |
207 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
207 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
208 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
208 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void Axis::setShadesPen(const QPen &pen) |
|
212 | void ChartAxis::setShadesPen(const QPen &pen) | |
213 | { |
|
213 | { | |
214 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
214 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
215 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
215 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void Axis::setAxisPen(const QPen &pen) |
|
219 | void ChartAxis::setAxisPen(const QPen &pen) | |
220 | { |
|
220 | { | |
221 | foreach(QGraphicsItem* item , m_axis->childItems()) { |
|
221 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
222 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
222 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void Axis::setGridPen(const QPen &pen) |
|
226 | void ChartAxis::setGridPen(const QPen &pen) | |
227 | { |
|
227 | { | |
228 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
228 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
229 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
229 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | QVector<qreal> Axis::calculateLayout() const |
|
233 | QVector<qreal> ChartAxis::calculateLayout() const | |
234 | { |
|
234 | { | |
235 | Q_ASSERT(m_ticksCount>=2); |
|
235 | Q_ASSERT(m_ticksCount>=2); | |
236 |
|
236 | |||
237 | QVector<qreal> points; |
|
237 | QVector<qreal> points; | |
238 | points.resize(m_ticksCount); |
|
238 | points.resize(m_ticksCount); | |
239 |
|
239 | |||
240 | switch (m_type) |
|
240 | switch (m_type) | |
241 | { |
|
241 | { | |
242 | case X_AXIS: |
|
242 | case X_AXIS: | |
243 | { |
|
243 | { | |
244 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); |
|
244 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
245 | for (int i = 0; i < m_ticksCount; ++i) { |
|
245 | for (int i = 0; i < m_ticksCount; ++i) { | |
246 | int x = i * deltaX + m_rect.left(); |
|
246 | int x = i * deltaX + m_rect.left(); | |
247 | points[i] = x; |
|
247 | points[i] = x; | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 | break; |
|
250 | break; | |
251 | case Y_AXIS: |
|
251 | case Y_AXIS: | |
252 | { |
|
252 | { | |
253 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); |
|
253 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); | |
254 | for (int i = 0; i < m_ticksCount; ++i) { |
|
254 | for (int i = 0; i < m_ticksCount; ++i) { | |
255 | int y = i * -deltaY + m_rect.bottom(); |
|
255 | int y = i * -deltaY + m_rect.bottom(); | |
256 | points[i] = y; |
|
256 | points[i] = y; | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 | break; |
|
259 | break; | |
260 | } |
|
260 | } | |
261 | return points; |
|
261 | return points; | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | void Axis::setLayout(QVector<qreal> &layout) |
|
264 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
265 | { |
|
265 | { | |
266 | int diff = m_layoutVector.size() - layout.size(); |
|
266 | int diff = m_layoutVector.size() - layout.size(); | |
267 |
|
267 | |||
268 | if (diff>0) { |
|
268 | if (diff>0) { | |
269 | deleteItems(diff); |
|
269 | deleteItems(diff); | |
270 | } else if (diff<0) { |
|
270 | } else if (diff<0) { | |
271 | createItems(-diff); |
|
271 | createItems(-diff); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | if( diff!=0) handleAxisUpdated(); |
|
274 | if( diff!=0) handleAxisUpdated(); | |
275 |
|
275 | |||
276 | QStringList ticksList; |
|
276 | QStringList ticksList; | |
277 |
|
277 | |||
278 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
278 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
279 |
|
279 | |||
280 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
280 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
281 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
281 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
282 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
282 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
283 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
283 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
284 |
|
284 | |||
285 | Q_ASSERT(labels.size() == ticksList.size()); |
|
285 | Q_ASSERT(labels.size() == ticksList.size()); | |
286 | Q_ASSERT(layout.size() == ticksList.size()); |
|
286 | Q_ASSERT(layout.size() == ticksList.size()); | |
287 |
|
287 | |||
288 | qreal minWidth = 0; |
|
288 | qreal minWidth = 0; | |
289 | qreal minHeight = 0; |
|
289 | qreal minHeight = 0; | |
290 |
|
290 | |||
291 | switch (m_type) |
|
291 | switch (m_type) | |
292 | { |
|
292 | { | |
293 | case X_AXIS: |
|
293 | case X_AXIS: | |
294 | { |
|
294 | { | |
295 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
295 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
296 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
296 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
297 |
|
297 | |||
298 | for (int i = 0; i < layout.size(); ++i) { |
|
298 | for (int i = 0; i < layout.size(); ++i) { | |
299 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
299 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
300 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
300 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
301 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
301 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
302 | if (!categories || i<1) { |
|
302 | if (!categories || i<1) { | |
303 | labelItem->setText(ticksList.at(i)); |
|
303 | labelItem->setText(ticksList.at(i)); | |
304 | const QRectF& rect = labelItem->boundingRect(); |
|
304 | const QRectF& rect = labelItem->boundingRect(); | |
305 | minWidth+=rect.width(); |
|
305 | minWidth+=rect.width(); | |
306 | minHeight=qMax(rect.height(),minHeight); |
|
306 | minHeight=qMax(rect.height(),minHeight); | |
307 | QPointF center = rect.center(); |
|
307 | QPointF center = rect.center(); | |
308 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
308 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
309 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
309 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
310 | } else { |
|
310 | } else { | |
311 | labelItem->setText(ticksList.at(i)); |
|
311 | labelItem->setText(ticksList.at(i)); | |
312 | const QRectF& rect = labelItem->boundingRect(); |
|
312 | const QRectF& rect = labelItem->boundingRect(); | |
313 | minWidth+=rect.width(); |
|
313 | minWidth+=rect.width(); | |
314 | minHeight=qMax(rect.height()+label_padding,minHeight); |
|
314 | minHeight=qMax(rect.height()+label_padding,minHeight); | |
315 | QPointF center = rect.center(); |
|
315 | QPointF center = rect.center(); | |
316 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
316 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
317 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
317 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | if ((i+1)%2 && i>1) { |
|
320 | if ((i+1)%2 && i>1) { | |
321 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
321 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
322 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
322 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
323 | } |
|
323 | } | |
324 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
324 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
325 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
325 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | } |
|
328 | } | |
329 | break; |
|
329 | break; | |
330 |
|
330 | |||
331 | case Y_AXIS: |
|
331 | case Y_AXIS: | |
332 | { |
|
332 | { | |
333 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
333 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
334 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
334 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
335 |
|
335 | |||
336 | for (int i = 0; i < layout.size(); ++i) { |
|
336 | for (int i = 0; i < layout.size(); ++i) { | |
337 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
337 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
338 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
338 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
339 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
339 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
340 |
|
340 | |||
341 | if (!categories || i<1) { |
|
341 | if (!categories || i<1) { | |
342 | labelItem->setText(ticksList.at(i)); |
|
342 | labelItem->setText(ticksList.at(i)); | |
343 | const QRectF& rect = labelItem->boundingRect(); |
|
343 | const QRectF& rect = labelItem->boundingRect(); | |
344 | minWidth=qMax(rect.width()+label_padding,minWidth); |
|
344 | minWidth=qMax(rect.width()+label_padding,minWidth); | |
345 | minHeight+=rect.height(); |
|
345 | minHeight+=rect.height(); | |
346 | QPointF center = rect.center(); |
|
346 | QPointF center = rect.center(); | |
347 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
347 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
348 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
348 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
349 | } else { |
|
349 | } else { | |
350 | labelItem->setText(ticksList.at(i)); |
|
350 | labelItem->setText(ticksList.at(i)); | |
351 | const QRectF& rect = labelItem->boundingRect(); |
|
351 | const QRectF& rect = labelItem->boundingRect(); | |
352 | minWidth=qMax(rect.width(),minWidth); |
|
352 | minWidth=qMax(rect.width(),minWidth); | |
353 | minHeight+=rect.height(); |
|
353 | minHeight+=rect.height(); | |
354 | QPointF center = rect.center(); |
|
354 | QPointF center = rect.center(); | |
355 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
355 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
356 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); |
|
356 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | if ((i+1)%2 && i>1) { |
|
359 | if ((i+1)%2 && i>1) { | |
360 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
360 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
361 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
361 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
362 | } |
|
362 | } | |
363 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
363 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
364 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
364 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
365 | } |
|
365 | } | |
366 | } |
|
366 | } | |
367 | break; |
|
367 | break; | |
368 | default: |
|
368 | default: | |
369 | qWarning()<<"Unknown axis type"; |
|
369 | qWarning()<<"Unknown axis type"; | |
370 | break; |
|
370 | break; | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | m_layoutVector=layout; |
|
373 | m_layoutVector=layout; | |
374 |
|
374 | |||
375 | presenter()->setMinimumMarginWidth(this,minWidth); |
|
375 | presenter()->setMinimumMarginWidth(this,minWidth); | |
376 | presenter()->setMinimumMarginHeight(this,minHeight); |
|
376 | presenter()->setMinimumMarginHeight(this,minHeight); | |
377 |
|
377 | |||
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | bool Axis::isEmpty() |
|
380 | bool ChartAxis::isEmpty() | |
381 | { |
|
381 | { | |
382 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; |
|
382 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | //handlers |
|
385 | //handlers | |
386 |
|
386 | |||
387 | void Axis::handleAxisCategoriesUpdated() |
|
387 | void ChartAxis::handleAxisCategoriesUpdated() | |
388 | { |
|
388 | { | |
389 | if (isEmpty()) return; |
|
389 | if (isEmpty()) return; | |
390 | updateLayout(m_layoutVector); |
|
390 | updateLayout(m_layoutVector); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void Axis::handleAxisUpdated() |
|
393 | void ChartAxis::handleAxisUpdated() | |
394 | { |
|
394 | { | |
395 |
|
395 | |||
396 | if (isEmpty()) return; |
|
396 | if (isEmpty()) return; | |
397 |
|
397 | |||
398 | if (m_chartAxis->isAxisVisible()) { |
|
398 | if (m_chartAxis->isAxisVisible()) { | |
399 | setAxisOpacity(100); |
|
399 | setAxisOpacity(100); | |
400 | } else { |
|
400 | } else { | |
401 | setAxisOpacity(0); |
|
401 | setAxisOpacity(0); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | if (m_chartAxis->isGridLineVisible()) { |
|
404 | if (m_chartAxis->isGridLineVisible()) { | |
405 | setGridOpacity(100); |
|
405 | setGridOpacity(100); | |
406 | } else { |
|
406 | } else { | |
407 | setGridOpacity(0); |
|
407 | setGridOpacity(0); | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | if (m_chartAxis->labelsVisible()) { |
|
410 | if (m_chartAxis->labelsVisible()) { | |
411 | setLabelsOpacity(100); |
|
411 | setLabelsOpacity(100); | |
412 | } else { |
|
412 | } else { | |
413 | setLabelsOpacity(0); |
|
413 | setLabelsOpacity(0); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | if (m_chartAxis->shadesVisible()) { |
|
416 | if (m_chartAxis->shadesVisible()) { | |
417 | setShadesOpacity(m_chartAxis->shadesOpacity()); |
|
417 | setShadesOpacity(m_chartAxis->shadesOpacity()); | |
418 | } else { |
|
418 | } else { | |
419 | setShadesOpacity(0); |
|
419 | setShadesOpacity(0); | |
420 | } |
|
420 | } | |
421 |
|
421 | |||
422 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
422 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
423 | setAxisPen(m_chartAxis->axisPen()); |
|
423 | setAxisPen(m_chartAxis->axisPen()); | |
424 | setLabelsPen(m_chartAxis->labelsPen()); |
|
424 | setLabelsPen(m_chartAxis->labelsPen()); | |
425 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
425 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
426 | setLabelsFont(m_chartAxis->labelsFont()); |
|
426 | setLabelsFont(m_chartAxis->labelsFont()); | |
427 | setGridPen(m_chartAxis->gridLinePen()); |
|
427 | setGridPen(m_chartAxis->gridLinePen()); | |
428 | setShadesPen(m_chartAxis->shadesPen()); |
|
428 | setShadesPen(m_chartAxis->shadesPen()); | |
429 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
429 | setShadesBrush(m_chartAxis->shadesBrush()); | |
430 |
|
430 | |||
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) |
|
433 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) | |
434 | { |
|
434 | { | |
435 | if (qFuzzyIsNull(min - max) || tickCount < 2) |
|
435 | if (qFuzzyIsNull(min - max) || tickCount < 2) | |
436 | return; |
|
436 | return; | |
437 |
|
437 | |||
438 | m_min = min; |
|
438 | m_min = min; | |
439 | m_max = max; |
|
439 | m_max = max; | |
440 | m_ticksCount= tickCount; |
|
440 | m_ticksCount= tickCount; | |
441 |
|
441 | |||
442 | if (isEmpty()) return; |
|
442 | if (isEmpty()) return; | |
443 | QVector<qreal> layout = calculateLayout(); |
|
443 | QVector<qreal> layout = calculateLayout(); | |
444 | updateLayout(layout); |
|
444 | updateLayout(layout); | |
445 |
|
445 | |||
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | void Axis::handleGeometryChanged(const QRectF &rect) |
|
448 | void ChartAxis::handleGeometryChanged(const QRectF &rect) | |
449 | { |
|
449 | { | |
450 | if(m_rect != rect) |
|
450 | if(m_rect != rect) | |
451 | { |
|
451 | { | |
452 | m_rect = rect; |
|
452 | m_rect = rect; | |
453 | if (isEmpty()) return; |
|
453 | if (isEmpty()) return; | |
454 | QVector<qreal> layout = calculateLayout(); |
|
454 | QVector<qreal> layout = calculateLayout(); | |
455 | updateLayout(layout); |
|
455 | updateLayout(layout); | |
456 | } |
|
456 | } | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | void Axis::axisSelected() |
|
459 | void ChartAxis::axisSelected() | |
460 | { |
|
460 | { | |
461 | qDebug()<<"TODO: axis clicked"; |
|
461 | qDebug()<<"TODO: axis clicked"; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | #include "moc_axis_p.cpp" |
|
464 | #include "moc_chartaxis_p.cpp" | |
465 |
|
465 | |||
466 | QTCOMMERCIALCHART_END_NAMESPACE |
|
466 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,143 +1,143 | |||||
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 AXIS_H |
|
21 | #ifndef AXIS_H | |
22 | #define AXIS_H |
|
22 | #define AXIS_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "chart_p.h" |
|
25 | #include "chart_p.h" | |
26 | #include <QGraphicsItem> |
|
26 | #include <QGraphicsItem> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 |
class Q |
|
30 | class QAxis; | |
31 | class ChartPresenter; |
|
31 | class ChartPresenter; | |
32 |
|
32 | |||
33 | class Axis : public Chart |
|
33 | class ChartAxis : public Chart | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | public: |
|
36 | public: | |
37 | enum AxisType{X_AXIS,Y_AXIS}; |
|
37 | enum AxisType{X_AXIS,Y_AXIS}; | |
38 |
|
38 | |||
39 |
Axis(Q |
|
39 | ChartAxis(QAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS); | |
40 | ~Axis(); |
|
40 | ~ChartAxis(); | |
41 |
|
41 | |||
42 | AxisType axisType() const { return m_type; } |
|
42 | AxisType axisType() const { return m_type; } | |
43 |
|
43 | |||
44 | void setAxisOpacity(qreal opacity); |
|
44 | void setAxisOpacity(qreal opacity); | |
45 | qreal axisOpacity() const; |
|
45 | qreal axisOpacity() const; | |
46 |
|
46 | |||
47 | void setGridOpacity(qreal opacity); |
|
47 | void setGridOpacity(qreal opacity); | |
48 | qreal gridOpacity() const; |
|
48 | qreal gridOpacity() const; | |
49 |
|
49 | |||
50 | void setLabelsOpacity(qreal opacity); |
|
50 | void setLabelsOpacity(qreal opacity); | |
51 | qreal labelsOpacity() const; |
|
51 | qreal labelsOpacity() const; | |
52 |
|
52 | |||
53 | void setShadesOpacity(qreal opacity); |
|
53 | void setShadesOpacity(qreal opacity); | |
54 | qreal shadesOpacity() const; |
|
54 | qreal shadesOpacity() const; | |
55 |
|
55 | |||
56 | void setLabelsAngle(int angle); |
|
56 | void setLabelsAngle(int angle); | |
57 | int labelsAngle()const { return m_labelsAngle; } |
|
57 | int labelsAngle()const { return m_labelsAngle; } | |
58 |
|
58 | |||
59 | void setShadesBrush(const QBrush &brush); |
|
59 | void setShadesBrush(const QBrush &brush); | |
60 | void setShadesPen(const QPen &pen); |
|
60 | void setShadesPen(const QPen &pen); | |
61 |
|
61 | |||
62 | void setAxisPen(const QPen &pen); |
|
62 | void setAxisPen(const QPen &pen); | |
63 | void setGridPen(const QPen &pen); |
|
63 | void setGridPen(const QPen &pen); | |
64 |
|
64 | |||
65 | void setLabelsPen(const QPen &pen); |
|
65 | void setLabelsPen(const QPen &pen); | |
66 | void setLabelsBrush(const QBrush &brush); |
|
66 | void setLabelsBrush(const QBrush &brush); | |
67 | void setLabelsFont(const QFont &font); |
|
67 | void setLabelsFont(const QFont &font); | |
68 |
|
68 | |||
69 | inline QRectF geometry() const { return m_rect; } |
|
69 | inline QRectF geometry() const { return m_rect; } | |
70 | inline QVector<qreal> layout() { return m_layoutVector; } |
|
70 | inline QVector<qreal> layout() { return m_layoutVector; } | |
71 |
|
71 | |||
72 | public Q_SLOTS: |
|
72 | public Q_SLOTS: | |
73 | void handleAxisUpdated(); |
|
73 | void handleAxisUpdated(); | |
74 | void handleAxisCategoriesUpdated(); |
|
74 | void handleAxisCategoriesUpdated(); | |
75 | void handleRangeChanged(qreal min , qreal max,int tickCount); |
|
75 | void handleRangeChanged(qreal min , qreal max,int tickCount); | |
76 | void handleGeometryChanged(const QRectF &size); |
|
76 | void handleGeometryChanged(const QRectF &size); | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | private: |
|
79 | private: | |
80 | inline bool isEmpty(); |
|
80 | inline bool isEmpty(); | |
81 | void createItems(int count); |
|
81 | void createItems(int count); | |
82 | void deleteItems(int count); |
|
82 | void deleteItems(int count); | |
83 |
|
83 | |||
84 | QVector<qreal> calculateLayout() const; |
|
84 | QVector<qreal> calculateLayout() const; | |
85 | void updateLayout(QVector<qreal> &layout); |
|
85 | void updateLayout(QVector<qreal> &layout); | |
86 | void setLayout(QVector<qreal> &layout); |
|
86 | void setLayout(QVector<qreal> &layout); | |
87 |
|
87 | |||
88 | bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; |
|
88 | bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; | |
89 | void axisSelected(); |
|
89 | void axisSelected(); | |
90 |
|
90 | |||
91 | private: |
|
91 | private: | |
92 |
Q |
|
92 | QAxis* m_chartAxis; | |
93 | AxisType m_type; |
|
93 | AxisType m_type; | |
94 | QRectF m_rect; |
|
94 | QRectF m_rect; | |
95 | int m_labelsAngle; |
|
95 | int m_labelsAngle; | |
96 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
96 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
97 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
97 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
98 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
98 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
99 | QScopedPointer<QGraphicsItemGroup> m_axis; |
|
99 | QScopedPointer<QGraphicsItemGroup> m_axis; | |
100 | QVector<qreal> m_layoutVector; |
|
100 | QVector<qreal> m_layoutVector; | |
101 | qreal m_min; |
|
101 | qreal m_min; | |
102 | qreal m_max; |
|
102 | qreal m_max; | |
103 | int m_ticksCount; |
|
103 | int m_ticksCount; | |
104 |
|
104 | |||
105 | friend class AxisAnimation; |
|
105 | friend class AxisAnimation; | |
106 | friend class AxisItem; |
|
106 | friend class AxisItem; | |
107 |
|
107 | |||
108 | }; |
|
108 | }; | |
109 |
|
109 | |||
110 | class AxisItem: public QGraphicsLineItem |
|
110 | class AxisItem: public QGraphicsLineItem | |
111 | { |
|
111 | { | |
112 |
|
112 | |||
113 | public: |
|
113 | public: | |
114 | explicit AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} |
|
114 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | |
115 |
|
115 | |||
116 | protected: |
|
116 | protected: | |
117 | void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
117 | void mousePressEvent(QGraphicsSceneMouseEvent *event) | |
118 | { |
|
118 | { | |
119 | Q_UNUSED(event) |
|
119 | Q_UNUSED(event) | |
120 | m_axis->axisSelected(); |
|
120 | m_axis->axisSelected(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | QRectF boundingRect() const |
|
123 | QRectF boundingRect() const | |
124 | { |
|
124 | { | |
125 | return shape().boundingRect(); |
|
125 | return shape().boundingRect(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | QPainterPath shape() const |
|
128 | QPainterPath shape() const | |
129 | { |
|
129 | { | |
130 | QPainterPath path = QGraphicsLineItem::shape(); |
|
130 | QPainterPath path = QGraphicsLineItem::shape(); | |
131 | QRectF rect = path.boundingRect(); |
|
131 | QRectF rect = path.boundingRect(); | |
132 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0)); |
|
132 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=ChartAxis::X_AXIS?8:0,m_axis->axisType()!=ChartAxis::Y_AXIS?8:0)); | |
133 | return path; |
|
133 | return path; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | private: |
|
136 | private: | |
137 | Axis* m_axis; |
|
137 | ChartAxis* m_axis; | |
138 |
|
138 | |||
139 | }; |
|
139 | }; | |
140 |
|
140 | |||
141 | QTCOMMERCIALCHART_END_NAMESPACE |
|
141 | QTCOMMERCIALCHART_END_NAMESPACE | |
142 |
|
142 | |||
143 | #endif /* AXISITEM_H_ */ |
|
143 | #endif /* AXISITEM_H_ */ |
@@ -1,533 +1,533 | |||||
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 "q |
|
21 | #include "qaxis.h" | |
22 |
#include "q |
|
22 | #include "qaxis_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QChartAxis |
|
27 | \class QChartAxis | |
28 | \brief The QChartAxis class is used for manipulating chart's axis |
|
28 | \brief The QChartAxis class is used for manipulating chart's axis | |
29 | and for adding optional axes to the chart. |
|
29 | and for adding optional axes to the chart. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | There is only one x Axis, however there can be multiple y axes. |
|
32 | There is only one x Axis, however there can be multiple y axes. | |
33 | Each chart series can be bound to exactly one Y axis and the share common X axis. |
|
33 | Each chart series can be bound to exactly one Y axis and the share common X axis. | |
34 | Axis can be setup to show axis line with ticks, gird lines and shades. |
|
34 | Axis can be setup to show axis line with ticks, gird lines and shades. | |
35 |
|
35 | |||
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 |
\fn bool Q |
|
39 | \fn bool QAxis::isAxisVisible() const | |
40 | \brief Returns if axis is visible |
|
40 | \brief Returns if axis is visible | |
41 | \sa setAxisVisible() |
|
41 | \sa setAxisVisible() | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 |
\fn QPen Q |
|
45 | \fn QPen QAxis::axisPen() const | |
46 | \brief Returns pen used to draw axis and ticks. |
|
46 | \brief Returns pen used to draw axis and ticks. | |
47 | \sa setAxisPen() |
|
47 | \sa setAxisPen() | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 |
\fn bool Q |
|
52 | \fn bool QAxis::isGridLineVisible() const | |
53 | \brief Returns if grid is visible |
|
53 | \brief Returns if grid is visible | |
54 | \sa setGridLineVisible() |
|
54 | \sa setGridLineVisible() | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 |
\fn QPen Q |
|
58 | \fn QPen QAxis::gridLinePen() const | |
59 | \brief Returns pen used to draw grid. |
|
59 | \brief Returns pen used to draw grid. | |
60 | \sa setGridLinePen() |
|
60 | \sa setGridLinePen() | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 |
\fn bool Q |
|
64 | \fn bool QAxis::labelsVisible() const | |
65 | \brief Returns if grid is visible |
|
65 | \brief Returns if grid is visible | |
66 | \sa setLabelsVisible() |
|
66 | \sa setLabelsVisible() | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 |
\fn QPen Q |
|
70 | \fn QPen QAxis::labelsPen() const | |
71 | \brief Returns the pen used to labels. |
|
71 | \brief Returns the pen used to labels. | |
72 | \sa setLabelsPen() |
|
72 | \sa setLabelsPen() | |
73 | */ |
|
73 | */ | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 |
\fn QBrush Q |
|
76 | \fn QBrush QAxis::labelsBrush() const | |
77 | \brief Returns brush used to draw labels. |
|
77 | \brief Returns brush used to draw labels. | |
78 | \sa setLabelsBrush() |
|
78 | \sa setLabelsBrush() | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 |
\fn QFont Q |
|
82 | \fn QFont QAxis::labelsFont() const | |
83 | \brief Returns font used to draw labels. |
|
83 | \brief Returns font used to draw labels. | |
84 | \sa setLabelsFont() |
|
84 | \sa setLabelsFont() | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 |
\fn QFont Q |
|
88 | \fn QFont QAxis::labelsAngle() const | |
89 | \brief Returns angle used to draw labels. |
|
89 | \brief Returns angle used to draw labels. | |
90 | \sa setLabelsAngle() |
|
90 | \sa setLabelsAngle() | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 |
\fn bool Q |
|
94 | \fn bool QAxis::shadesVisible() const | |
95 | \brief Returns if shades are visible. |
|
95 | \brief Returns if shades are visible. | |
96 | \sa setShadesVisible() |
|
96 | \sa setShadesVisible() | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 |
\fn qreal Q |
|
100 | \fn qreal QAxis::shadesOpacity() const | |
101 | \brief Returns opacity of shades. |
|
101 | \brief Returns opacity of shades. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 |
\fn QPen Q |
|
105 | \fn QPen QAxis::shadesPen() const | |
106 | \brief Returns pen used to draw shades. |
|
106 | \brief Returns pen used to draw shades. | |
107 | \sa setShadesPen() |
|
107 | \sa setShadesPen() | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 |
\fn QBrush Q |
|
111 | \fn QBrush QAxis::shadesBrush() const | |
112 | \brief Returns brush used to draw shades. |
|
112 | \brief Returns brush used to draw shades. | |
113 | \sa setShadesBrush() |
|
113 | \sa setShadesBrush() | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 |
\fn qreal Q |
|
117 | \fn qreal QAxis::min() const | |
118 | \brief Returns minimum value on the axis. |
|
118 | \brief Returns minimum value on the axis. | |
119 | \sa setMin() |
|
119 | \sa setMin() | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 |
\fn qreal Q |
|
123 | \fn qreal QAxis::max() const | |
124 | \brief Returns maximim value on the axis. |
|
124 | \brief Returns maximim value on the axis. | |
125 | \sa setMax() |
|
125 | \sa setMax() | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 |
\fn void Q |
|
129 | \fn void QAxis::minChanged(qreal min) | |
130 | \brief Axis emits signal when \a min of axis has changed. |
|
130 | \brief Axis emits signal when \a min of axis has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 |
\fn void Q |
|
134 | \fn void QAxis::maxChanged(qreal max) | |
135 | \brief Axis emits signal when \a max of axis has changed. |
|
135 | \brief Axis emits signal when \a max of axis has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 |
\fn void Q |
|
139 | \fn void QAxis::rangeChanged(qreal min, qreal max) | |
140 | \brief Axis emits signal when \a min or \a max of axis has changed. |
|
140 | \brief Axis emits signal when \a min or \a max of axis has changed. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 |
\fn int Q |
|
144 | \fn int QAxis::ticksCount() const | |
145 | \brief Return number of ticks on the axis |
|
145 | \brief Return number of ticks on the axis | |
146 | \sa setTicksCount() |
|
146 | \sa setTicksCount() | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 |
\fn QChartAxisCategories* Q |
|
150 | \fn QChartAxisCategories* QAxis::categories() | |
151 | \brief Returns pointer to the list of categories which correspond to the values on the axis. |
|
151 | \brief Returns pointer to the list of categories which correspond to the values on the axis. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 |
\fn void Q |
|
155 | \fn void QAxis::ticksCountChanged(int count) | |
156 | \brief Emits the new \a count of ticks on the axis |
|
156 | \brief Emits the new \a count of ticks on the axis | |
157 | Signal is emitted when the number of the ticks on the axis has been changed to a different value. |
|
157 | Signal is emitted when the number of the ticks on the axis has been changed to a different value. | |
158 | Parementer count\a count is the new number of ticks on the axis. |
|
158 | Parementer count\a count is the new number of ticks on the axis. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
162 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
163 | QChatView or QChart when axis added. |
|
163 | QChatView or QChart when axis added. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 |
Q |
|
166 | QAxis::QAxis(QObject *parent) : QObject(parent), | |
167 |
d_ptr(new Q |
|
167 | d_ptr(new QAxisPrivate(this)) | |
168 | { |
|
168 | { | |
169 |
|
169 | |||
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
173 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 |
Q |
|
176 | QAxis::~QAxis() | |
177 | { |
|
177 | { | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Sets \a pen used to draw axis line and ticks. |
|
181 | Sets \a pen used to draw axis line and ticks. | |
182 | */ |
|
182 | */ | |
183 |
void Q |
|
183 | void QAxis::setAxisPen(const QPen &pen) | |
184 | { |
|
184 | { | |
185 | if (d_ptr->m_axisPen!=pen) { |
|
185 | if (d_ptr->m_axisPen!=pen) { | |
186 | d_ptr->m_axisPen = pen; |
|
186 | d_ptr->m_axisPen = pen; | |
187 | emit d_ptr->updated(); |
|
187 | emit d_ptr->updated(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 |
QPen Q |
|
191 | QPen QAxis::axisPen() const | |
192 | { |
|
192 | { | |
193 | return d_ptr->m_axisPen; |
|
193 | return d_ptr->m_axisPen; | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | Sets if axis and ticks are \a visible. |
|
197 | Sets if axis and ticks are \a visible. | |
198 | */ |
|
198 | */ | |
199 |
void Q |
|
199 | void QAxis::setAxisVisible(bool visible) | |
200 | { |
|
200 | { | |
201 | if (d_ptr->m_axisVisible != visible) { |
|
201 | if (d_ptr->m_axisVisible != visible) { | |
202 | d_ptr->m_axisVisible = visible; |
|
202 | d_ptr->m_axisVisible = visible; | |
203 | emit d_ptr->updated(); |
|
203 | emit d_ptr->updated(); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 |
bool Q |
|
207 | bool QAxis::isAxisVisible() const | |
208 | { |
|
208 | { | |
209 | return d_ptr->m_axisVisible; |
|
209 | return d_ptr->m_axisVisible; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Sets if grid line is \a visible. |
|
213 | Sets if grid line is \a visible. | |
214 | */ |
|
214 | */ | |
215 |
void Q |
|
215 | void QAxis::setGridLineVisible(bool visible) | |
216 | { |
|
216 | { | |
217 | if (d_ptr->m_gridLineVisible != visible) { |
|
217 | if (d_ptr->m_gridLineVisible != visible) { | |
218 | d_ptr->m_gridLineVisible = visible; |
|
218 | d_ptr->m_gridLineVisible = visible; | |
219 | emit d_ptr->updated(); |
|
219 | emit d_ptr->updated(); | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 |
bool Q |
|
223 | bool QAxis::isGridLineVisible() const | |
224 | { |
|
224 | { | |
225 | return d_ptr->m_gridLineVisible; |
|
225 | return d_ptr->m_gridLineVisible; | |
226 | } |
|
226 | } | |
227 | /*! |
|
227 | /*! | |
228 | Sets \a pen used to draw grid line. |
|
228 | Sets \a pen used to draw grid line. | |
229 | */ |
|
229 | */ | |
230 |
void Q |
|
230 | void QAxis::setGridLinePen(const QPen &pen) | |
231 | { |
|
231 | { | |
232 | if (d_ptr->m_gridLinePen != pen) { |
|
232 | if (d_ptr->m_gridLinePen != pen) { | |
233 | d_ptr->m_gridLinePen = pen; |
|
233 | d_ptr->m_gridLinePen = pen; | |
234 | emit d_ptr->updated(); |
|
234 | emit d_ptr->updated(); | |
235 | } |
|
235 | } | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 |
QPen Q |
|
238 | QPen QAxis::gridLinePen() const | |
239 | { |
|
239 | { | |
240 | return d_ptr->m_gridLinePen; |
|
240 | return d_ptr->m_gridLinePen; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Sets if axis' labels are \a visible. |
|
244 | Sets if axis' labels are \a visible. | |
245 | */ |
|
245 | */ | |
246 |
void Q |
|
246 | void QAxis::setLabelsVisible(bool visible) | |
247 | { |
|
247 | { | |
248 | if (d_ptr->m_labelsVisible != visible) { |
|
248 | if (d_ptr->m_labelsVisible != visible) { | |
249 | d_ptr->m_labelsVisible = visible; |
|
249 | d_ptr->m_labelsVisible = visible; | |
250 | emit d_ptr->updated(); |
|
250 | emit d_ptr->updated(); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 |
bool Q |
|
254 | bool QAxis::labelsVisible() const | |
255 | { |
|
255 | { | |
256 | return d_ptr->m_labelsVisible; |
|
256 | return d_ptr->m_labelsVisible; | |
257 | } |
|
257 | } | |
258 | /*! |
|
258 | /*! | |
259 | Sets \a pen used to draw labels. |
|
259 | Sets \a pen used to draw labels. | |
260 | */ |
|
260 | */ | |
261 |
void Q |
|
261 | void QAxis::setLabelsPen(const QPen &pen) | |
262 | { |
|
262 | { | |
263 | if (d_ptr->m_labelsPen != pen) { |
|
263 | if (d_ptr->m_labelsPen != pen) { | |
264 | d_ptr->m_labelsPen = pen; |
|
264 | d_ptr->m_labelsPen = pen; | |
265 | emit d_ptr->updated(); |
|
265 | emit d_ptr->updated(); | |
266 | } |
|
266 | } | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 |
QPen Q |
|
269 | QPen QAxis::labelsPen() const | |
270 | { |
|
270 | { | |
271 | return d_ptr->m_labelsPen; |
|
271 | return d_ptr->m_labelsPen; | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | /*! |
|
274 | /*! | |
275 | Sets \a brush used to draw labels. |
|
275 | Sets \a brush used to draw labels. | |
276 | */ |
|
276 | */ | |
277 |
void Q |
|
277 | void QAxis::setLabelsBrush(const QBrush &brush) | |
278 | { |
|
278 | { | |
279 | if (d_ptr->m_labelsBrush != brush) { |
|
279 | if (d_ptr->m_labelsBrush != brush) { | |
280 | d_ptr->m_labelsBrush = brush; |
|
280 | d_ptr->m_labelsBrush = brush; | |
281 | emit d_ptr->updated(); |
|
281 | emit d_ptr->updated(); | |
282 | } |
|
282 | } | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 |
QBrush Q |
|
285 | QBrush QAxis::labelsBrush() const | |
286 | { |
|
286 | { | |
287 | return d_ptr->m_labelsBrush; |
|
287 | return d_ptr->m_labelsBrush; | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | /*! |
|
290 | /*! | |
291 | Sets \a font used to draw labels. |
|
291 | Sets \a font used to draw labels. | |
292 | */ |
|
292 | */ | |
293 |
void Q |
|
293 | void QAxis::setLabelsFont(const QFont &font) | |
294 | { |
|
294 | { | |
295 | if (d_ptr->m_labelsFont != font) { |
|
295 | if (d_ptr->m_labelsFont != font) { | |
296 | d_ptr->m_labelsFont = font; |
|
296 | d_ptr->m_labelsFont = font; | |
297 | emit d_ptr->updated(); |
|
297 | emit d_ptr->updated(); | |
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 |
QFont Q |
|
301 | QFont QAxis::labelsFont() const | |
302 | { |
|
302 | { | |
303 | return d_ptr->m_labelsFont; |
|
303 | return d_ptr->m_labelsFont; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 | Sets \a angle for all the labels on given axis. |
|
307 | Sets \a angle for all the labels on given axis. | |
308 | */ |
|
308 | */ | |
309 |
void Q |
|
309 | void QAxis::setLabelsAngle(int angle) | |
310 | { |
|
310 | { | |
311 | if (d_ptr->m_labelsAngle != angle) { |
|
311 | if (d_ptr->m_labelsAngle != angle) { | |
312 | d_ptr->m_labelsAngle = angle; |
|
312 | d_ptr->m_labelsAngle = angle; | |
313 | emit d_ptr->updated(); |
|
313 | emit d_ptr->updated(); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 |
int Q |
|
317 | int QAxis::labelsAngle() const | |
318 | { |
|
318 | { | |
319 | return d_ptr->m_labelsAngle; |
|
319 | return d_ptr->m_labelsAngle; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | /*! |
|
322 | /*! | |
323 | Sets if shades are \a visible. |
|
323 | Sets if shades are \a visible. | |
324 | */ |
|
324 | */ | |
325 |
void Q |
|
325 | void QAxis::setShadesVisible(bool visible) | |
326 | { |
|
326 | { | |
327 | if (d_ptr->m_shadesVisible != visible) { |
|
327 | if (d_ptr->m_shadesVisible != visible) { | |
328 | d_ptr->m_shadesVisible = visible; |
|
328 | d_ptr->m_shadesVisible = visible; | |
329 | emit d_ptr->updated(); |
|
329 | emit d_ptr->updated(); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 |
bool Q |
|
333 | bool QAxis::shadesVisible() const | |
334 | { |
|
334 | { | |
335 | return d_ptr->m_shadesVisible; |
|
335 | return d_ptr->m_shadesVisible; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | /*! |
|
338 | /*! | |
339 | Sets \a pen used to draw shades. |
|
339 | Sets \a pen used to draw shades. | |
340 | */ |
|
340 | */ | |
341 |
void Q |
|
341 | void QAxis::setShadesPen(const QPen &pen) | |
342 | { |
|
342 | { | |
343 | if (d_ptr->m_shadesPen != pen) { |
|
343 | if (d_ptr->m_shadesPen != pen) { | |
344 | d_ptr->m_shadesPen = pen; |
|
344 | d_ptr->m_shadesPen = pen; | |
345 | emit d_ptr->updated(); |
|
345 | emit d_ptr->updated(); | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 |
QPen Q |
|
349 | QPen QAxis::shadesPen() const | |
350 | { |
|
350 | { | |
351 | return d_ptr->m_shadesPen; |
|
351 | return d_ptr->m_shadesPen; | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Sets \a brush used to draw shades. |
|
355 | Sets \a brush used to draw shades. | |
356 | */ |
|
356 | */ | |
357 |
void Q |
|
357 | void QAxis::setShadesBrush(const QBrush &brush) | |
358 | { |
|
358 | { | |
359 | if (d_ptr->m_shadesBrush != brush) { |
|
359 | if (d_ptr->m_shadesBrush != brush) { | |
360 | d_ptr->m_shadesBrush = brush; |
|
360 | d_ptr->m_shadesBrush = brush; | |
361 | emit d_ptr->updated(); |
|
361 | emit d_ptr->updated(); | |
362 | } |
|
362 | } | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 |
QBrush Q |
|
365 | QBrush QAxis::shadesBrush() const | |
366 | { |
|
366 | { | |
367 | return d_ptr->m_shadesBrush; |
|
367 | return d_ptr->m_shadesBrush; | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Sets \a opacity of the shades. |
|
371 | Sets \a opacity of the shades. | |
372 | */ |
|
372 | */ | |
373 |
void Q |
|
373 | void QAxis::setShadesOpacity(qreal opacity) | |
374 | { |
|
374 | { | |
375 | if (d_ptr->m_shadesOpacity != opacity) { |
|
375 | if (d_ptr->m_shadesOpacity != opacity) { | |
376 | d_ptr->m_shadesOpacity=opacity; |
|
376 | d_ptr->m_shadesOpacity=opacity; | |
377 | emit d_ptr->updated(); |
|
377 | emit d_ptr->updated(); | |
378 | } |
|
378 | } | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 |
qreal Q |
|
381 | qreal QAxis::shadesOpacity() const | |
382 | { |
|
382 | { | |
383 | return d_ptr->m_shadesOpacity; |
|
383 | return d_ptr->m_shadesOpacity; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | /*! |
|
386 | /*! | |
387 | Sets \a min value on the axis. |
|
387 | Sets \a min value on the axis. | |
388 | */ |
|
388 | */ | |
389 |
void Q |
|
389 | void QAxis::setMin(qreal min) | |
390 | { |
|
390 | { | |
391 | setRange(min,d_ptr->m_max); |
|
391 | setRange(min,d_ptr->m_max); | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 |
qreal Q |
|
394 | qreal QAxis::min() const | |
395 | { |
|
395 | { | |
396 | return d_ptr->m_min; |
|
396 | return d_ptr->m_min; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | /*! |
|
399 | /*! | |
400 | Sets \a max value on the axis. |
|
400 | Sets \a max value on the axis. | |
401 | */ |
|
401 | */ | |
402 |
void Q |
|
402 | void QAxis::setMax(qreal max) | |
403 | { |
|
403 | { | |
404 | setRange(d_ptr->m_min,max); |
|
404 | setRange(d_ptr->m_min,max); | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 |
qreal Q |
|
407 | qreal QAxis::max() const | |
408 | { |
|
408 | { | |
409 | return d_ptr->m_max; |
|
409 | return d_ptr->m_max; | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | /*! |
|
412 | /*! | |
413 | Sets range from \a min to \a max on the axis. |
|
413 | Sets range from \a min to \a max on the axis. | |
414 | */ |
|
414 | */ | |
415 |
void Q |
|
415 | void QAxis::setRange(qreal min, qreal max) | |
416 | { |
|
416 | { | |
417 | bool changed = false; |
|
417 | bool changed = false; | |
418 | if (!qFuzzyIsNull(d_ptr->m_min - min)) { |
|
418 | if (!qFuzzyIsNull(d_ptr->m_min - min)) { | |
419 | d_ptr->m_min = min; |
|
419 | d_ptr->m_min = min; | |
420 | changed = true; |
|
420 | changed = true; | |
421 | emit minChanged(min); |
|
421 | emit minChanged(min); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | if (!qFuzzyIsNull(d_ptr->m_max - max)) { |
|
424 | if (!qFuzzyIsNull(d_ptr->m_max - max)) { | |
425 | d_ptr->m_max = max; |
|
425 | d_ptr->m_max = max; | |
426 | changed = true; |
|
426 | changed = true; | |
427 | emit maxChanged(max); |
|
427 | emit maxChanged(max); | |
428 | } |
|
428 | } | |
429 |
|
429 | |||
430 | if (changed) { |
|
430 | if (changed) { | |
431 | emit rangeChanged(d_ptr->m_min,d_ptr->m_max); |
|
431 | emit rangeChanged(d_ptr->m_min,d_ptr->m_max); | |
432 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
432 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | |
433 | } |
|
433 | } | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | /*! |
|
436 | /*! | |
437 | Sets \a count for ticks on the axis. |
|
437 | Sets \a count for ticks on the axis. | |
438 | */ |
|
438 | */ | |
439 |
void Q |
|
439 | void QAxis::setTicksCount(int count) | |
440 | { |
|
440 | { | |
441 | if (d_ptr->m_ticksCount != count) { |
|
441 | if (d_ptr->m_ticksCount != count) { | |
442 | d_ptr->m_ticksCount = count; |
|
442 | d_ptr->m_ticksCount = count; | |
443 | emit ticksCountChanged(count); |
|
443 | emit ticksCountChanged(count); | |
444 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
444 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | |
445 | } |
|
445 | } | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 |
int Q |
|
448 | int QAxis::ticksCount() const | |
449 | { |
|
449 | { | |
450 | return d_ptr->m_ticksCount; |
|
450 | return d_ptr->m_ticksCount; | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | /*! |
|
453 | /*! | |
454 | Sets axis, shades, labels and grid lines to be visible. |
|
454 | Sets axis, shades, labels and grid lines to be visible. | |
455 | */ |
|
455 | */ | |
456 |
void Q |
|
456 | void QAxis::show() | |
457 | { |
|
457 | { | |
458 | d_ptr->m_axisVisible=true; |
|
458 | d_ptr->m_axisVisible=true; | |
459 | d_ptr->m_gridLineVisible=true; |
|
459 | d_ptr->m_gridLineVisible=true; | |
460 | d_ptr->m_labelsVisible=true; |
|
460 | d_ptr->m_labelsVisible=true; | |
461 | d_ptr->m_shadesVisible=true; |
|
461 | d_ptr->m_shadesVisible=true; | |
462 | emit d_ptr->updated(); |
|
462 | emit d_ptr->updated(); | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | /*! |
|
465 | /*! | |
466 | Sets axis, shades, labels and grid lines to not be visible. |
|
466 | Sets axis, shades, labels and grid lines to not be visible. | |
467 | */ |
|
467 | */ | |
468 |
void Q |
|
468 | void QAxis::hide() | |
469 | { |
|
469 | { | |
470 | d_ptr->m_axisVisible = false; |
|
470 | d_ptr->m_axisVisible = false; | |
471 | d_ptr->m_gridLineVisible = false; |
|
471 | d_ptr->m_gridLineVisible = false; | |
472 | d_ptr->m_labelsVisible = false; |
|
472 | d_ptr->m_labelsVisible = false; | |
473 | d_ptr->m_shadesVisible = false; |
|
473 | d_ptr->m_shadesVisible = false; | |
474 | emit d_ptr->updated(); |
|
474 | emit d_ptr->updated(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets the nice numbers state to \a enable |
|
478 | Sets the nice numbers state to \a enable | |
479 | */ |
|
479 | */ | |
480 |
void Q |
|
480 | void QAxis::setNiceNumbersEnabled(bool enable) | |
481 | { |
|
481 | { | |
482 | if (d_ptr->m_niceNumbers != enable){ |
|
482 | if (d_ptr->m_niceNumbers != enable){ | |
483 | d_ptr->m_niceNumbers = enable; |
|
483 | d_ptr->m_niceNumbers = enable; | |
484 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
484 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | |
485 | } |
|
485 | } | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | /*! |
|
488 | /*! | |
489 | Returns whether nice numbers are enabled or not. |
|
489 | Returns whether nice numbers are enabled or not. | |
490 | */ |
|
490 | */ | |
491 |
bool Q |
|
491 | bool QAxis::niceNumbersEnabled() const | |
492 | { |
|
492 | { | |
493 | return d_ptr->m_niceNumbers; |
|
493 | return d_ptr->m_niceNumbers; | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 |
QChartAxisCategories* Q |
|
496 | QChartAxisCategories* QAxis::categories() | |
497 | { |
|
497 | { | |
498 | return &d_ptr->m_category; |
|
498 | return &d_ptr->m_category; | |
499 | } |
|
499 | } | |
500 |
|
500 | |||
501 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
501 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
502 |
|
502 | |||
503 |
Q |
|
503 | QAxisPrivate::QAxisPrivate(QAxis* q): | |
504 | q_ptr(q), |
|
504 | q_ptr(q), | |
505 | m_axisVisible(true), |
|
505 | m_axisVisible(true), | |
506 | m_gridLineVisible(true), |
|
506 | m_gridLineVisible(true), | |
507 | m_labelsVisible(true), |
|
507 | m_labelsVisible(true), | |
508 | m_labelsAngle(0), |
|
508 | m_labelsAngle(0), | |
509 | m_shadesVisible(false), |
|
509 | m_shadesVisible(false), | |
510 | m_shadesOpacity(1.0), |
|
510 | m_shadesOpacity(1.0), | |
511 | m_min(0), |
|
511 | m_min(0), | |
512 | m_max(0), |
|
512 | m_max(0), | |
513 | m_ticksCount(5), |
|
513 | m_ticksCount(5), | |
514 | m_niceNumbers(false) |
|
514 | m_niceNumbers(false) | |
515 | { |
|
515 | { | |
516 |
|
516 | |||
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 |
Q |
|
519 | QAxisPrivate::~QAxisPrivate() | |
520 | { |
|
520 | { | |
521 |
|
521 | |||
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 |
void Q |
|
524 | void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
525 | { |
|
525 | { | |
526 | q_ptr->setRange(min,max); |
|
526 | q_ptr->setRange(min,max); | |
527 | q_ptr->setTicksCount(count); |
|
527 | q_ptr->setTicksCount(count); | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
530 |
#include "moc_q |
|
530 | #include "moc_qaxis.cpp" | |
531 |
#include "moc_q |
|
531 | #include "moc_qaxis_p.cpp" | |
532 |
|
532 | |||
533 | QTCOMMERCIALCHART_END_NAMESPACE |
|
533 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,108 +1,108 | |||||
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 Q |
|
21 | #ifndef QAXIS_H | |
22 |
#define Q |
|
22 | #define QAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qchartaxiscategories.h> |
|
25 | #include <qchartaxiscategories.h> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 |
class Q |
|
31 | class QAxisPrivate; | |
32 |
|
32 | |||
33 |
class QTCOMMERCIALCHART_EXPORT Q |
|
33 | class QTCOMMERCIALCHART_EXPORT QAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | public: |
|
36 | public: | |
37 |
|
37 | |||
38 |
Q |
|
38 | QAxis(QObject *parent =0); | |
39 |
~Q |
|
39 | ~QAxis(); | |
40 |
|
40 | |||
41 | //axis handling |
|
41 | //axis handling | |
42 | bool isAxisVisible() const; |
|
42 | bool isAxisVisible() const; | |
43 | void setAxisVisible(bool visible = true); |
|
43 | void setAxisVisible(bool visible = true); | |
44 | void setAxisPen(const QPen &pen); |
|
44 | void setAxisPen(const QPen &pen); | |
45 | QPen axisPen() const; |
|
45 | QPen axisPen() const; | |
46 |
|
46 | |||
47 | //grid handling |
|
47 | //grid handling | |
48 | bool isGridLineVisible() const; |
|
48 | bool isGridLineVisible() const; | |
49 | void setGridLineVisible(bool visible = true); |
|
49 | void setGridLineVisible(bool visible = true); | |
50 | void setGridLinePen(const QPen &pen); |
|
50 | void setGridLinePen(const QPen &pen); | |
51 | QPen gridLinePen() const; |
|
51 | QPen gridLinePen() const; | |
52 |
|
52 | |||
53 | //labels handling |
|
53 | //labels handling | |
54 | bool labelsVisible() const; |
|
54 | bool labelsVisible() const; | |
55 | void setLabelsVisible(bool visible = true); |
|
55 | void setLabelsVisible(bool visible = true); | |
56 | void setLabelsPen(const QPen &pen); |
|
56 | void setLabelsPen(const QPen &pen); | |
57 | QPen labelsPen() const; |
|
57 | QPen labelsPen() const; | |
58 | void setLabelsBrush(const QBrush &brush); |
|
58 | void setLabelsBrush(const QBrush &brush); | |
59 | QBrush labelsBrush() const; |
|
59 | QBrush labelsBrush() const; | |
60 | void setLabelsFont(const QFont &font); |
|
60 | void setLabelsFont(const QFont &font); | |
61 | QFont labelsFont() const; |
|
61 | QFont labelsFont() const; | |
62 | void setLabelsAngle(int angle); |
|
62 | void setLabelsAngle(int angle); | |
63 | int labelsAngle() const; |
|
63 | int labelsAngle() const; | |
64 |
|
64 | |||
65 | //shades handling |
|
65 | //shades handling | |
66 | bool shadesVisible() const; |
|
66 | bool shadesVisible() const; | |
67 | void setShadesVisible(bool visible = true); |
|
67 | void setShadesVisible(bool visible = true); | |
68 | void setShadesPen(const QPen &pen); |
|
68 | void setShadesPen(const QPen &pen); | |
69 | QPen shadesPen() const; |
|
69 | QPen shadesPen() const; | |
70 | void setShadesBrush(const QBrush &brush); |
|
70 | void setShadesBrush(const QBrush &brush); | |
71 | QBrush shadesBrush() const; |
|
71 | QBrush shadesBrush() const; | |
72 | void setShadesOpacity(qreal opacity); |
|
72 | void setShadesOpacity(qreal opacity); | |
73 | qreal shadesOpacity() const; |
|
73 | qreal shadesOpacity() const; | |
74 |
|
74 | |||
75 | //range handling |
|
75 | //range handling | |
76 | void setMin(qreal min); |
|
76 | void setMin(qreal min); | |
77 | qreal min() const; |
|
77 | qreal min() const; | |
78 | void setMax(qreal max); |
|
78 | void setMax(qreal max); | |
79 | qreal max() const; |
|
79 | qreal max() const; | |
80 | void setRange(qreal min, qreal max); |
|
80 | void setRange(qreal min, qreal max); | |
81 |
|
81 | |||
82 | //ticks handling |
|
82 | //ticks handling | |
83 | void setTicksCount(int count); |
|
83 | void setTicksCount(int count); | |
84 | int ticksCount() const; |
|
84 | int ticksCount() const; | |
85 |
|
85 | |||
86 | void setNiceNumbersEnabled(bool enable = true); |
|
86 | void setNiceNumbersEnabled(bool enable = true); | |
87 | bool niceNumbersEnabled() const; |
|
87 | bool niceNumbersEnabled() const; | |
88 |
|
88 | |||
89 | QChartAxisCategories* categories(); |
|
89 | QChartAxisCategories* categories(); | |
90 |
|
90 | |||
91 | void show(); |
|
91 | void show(); | |
92 | void hide(); |
|
92 | void hide(); | |
93 |
|
93 | |||
94 | Q_SIGNALS: |
|
94 | Q_SIGNALS: | |
95 | void minChanged(qreal min); |
|
95 | void minChanged(qreal min); | |
96 | void maxChanged(qreal max); |
|
96 | void maxChanged(qreal max); | |
97 | void rangeChanged(qreal min, qreal max); |
|
97 | void rangeChanged(qreal min, qreal max); | |
98 | void ticksCountChanged(int count); |
|
98 | void ticksCountChanged(int count); | |
99 |
|
99 | |||
100 | private: |
|
100 | private: | |
101 |
QScopedPointer<Q |
|
101 | QScopedPointer<QAxisPrivate> d_ptr; | |
102 |
Q_DISABLE_COPY(Q |
|
102 | Q_DISABLE_COPY(QAxis); | |
103 | friend class ChartDataSet; |
|
103 | friend class ChartDataSet; | |
104 | friend class Axis; |
|
104 | friend class ChartAxis; | |
105 | }; |
|
105 | }; | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 | #endif /* QCHARTAXIS_H_ */ |
|
108 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,85 +1,85 | |||||
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 Q |
|
30 | #ifndef QAXIS_P_H | |
31 |
#define Q |
|
31 | #define QAXIS_P_H | |
32 |
|
32 | |||
33 |
#include "q |
|
33 | #include "qaxis.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 |
class Q |
|
37 | class QAxisPrivate : public QObject | |
38 | { |
|
38 | { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
40 | public: |
|
40 | public: | |
41 |
Q |
|
41 | QAxisPrivate(QAxis *q); | |
42 |
~Q |
|
42 | ~QAxisPrivate(); | |
43 |
|
43 | |||
44 | Q_SIGNALS: |
|
44 | Q_SIGNALS: | |
45 | void updated(); |
|
45 | void updated(); | |
46 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); |
|
46 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); | |
47 |
|
47 | |||
48 | public Q_SLOTS: |
|
48 | public Q_SLOTS: | |
49 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
49 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 |
Q |
|
52 | QAxis *q_ptr; | |
53 |
|
53 | |||
54 | bool m_axisVisible; |
|
54 | bool m_axisVisible; | |
55 | QPen m_axisPen; |
|
55 | QPen m_axisPen; | |
56 | QBrush m_axisBrush; |
|
56 | QBrush m_axisBrush; | |
57 |
|
57 | |||
58 | bool m_gridLineVisible; |
|
58 | bool m_gridLineVisible; | |
59 | QPen m_gridLinePen; |
|
59 | QPen m_gridLinePen; | |
60 |
|
60 | |||
61 | bool m_labelsVisible; |
|
61 | bool m_labelsVisible; | |
62 | QPen m_labelsPen; |
|
62 | QPen m_labelsPen; | |
63 | QBrush m_labelsBrush; |
|
63 | QBrush m_labelsBrush; | |
64 | QFont m_labelsFont; |
|
64 | QFont m_labelsFont; | |
65 | int m_labelsAngle; |
|
65 | int m_labelsAngle; | |
66 |
|
66 | |||
67 | bool m_shadesVisible; |
|
67 | bool m_shadesVisible; | |
68 | QPen m_shadesPen; |
|
68 | QPen m_shadesPen; | |
69 | QBrush m_shadesBrush; |
|
69 | QBrush m_shadesBrush; | |
70 | qreal m_shadesOpacity; |
|
70 | qreal m_shadesOpacity; | |
71 |
|
71 | |||
72 | qreal m_min; |
|
72 | qreal m_min; | |
73 | qreal m_max; |
|
73 | qreal m_max; | |
74 |
|
74 | |||
75 | int m_ticksCount; |
|
75 | int m_ticksCount; | |
76 | QChartAxisCategories m_category; |
|
76 | QChartAxisCategories m_category; | |
77 |
|
77 | |||
78 | bool m_niceNumbers; |
|
78 | bool m_niceNumbers; | |
79 |
|
79 | |||
80 |
friend class Q |
|
80 | friend class QAxis; | |
81 | }; |
|
81 | }; | |
82 |
|
82 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
84 | |||
85 | #endif |
|
85 | #endif |
@@ -1,56 +1,56 | |||||
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 QCHARTAXISCATEGORIES_H |
|
21 | #ifndef QCHARTAXISCATEGORIES_H | |
22 | #define QCHARTAXISCATEGORIES_H |
|
22 | #define QCHARTAXISCATEGORIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qbarseries.h> |
|
25 | #include <qbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QChartAxisCategoriesPrivate; |
|
29 | class QChartAxisCategoriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject |
|
31 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | private: |
|
34 | private: | |
35 | QChartAxisCategories(); |
|
35 | QChartAxisCategories(); | |
36 | public: |
|
36 | public: | |
37 | ~QChartAxisCategories(); |
|
37 | ~QChartAxisCategories(); | |
38 |
|
38 | |||
39 | void insert(const QBarCategories &category); |
|
39 | void insert(const QBarCategories &category); | |
40 | void insert(qreal value,QString label); |
|
40 | void insert(qreal value,QString label); | |
41 | void remove(qreal value); |
|
41 | void remove(qreal value); | |
42 | QList<qreal> values() const; |
|
42 | QList<qreal> values() const; | |
43 | QString label(qreal value) const; |
|
43 | QString label(qreal value) const; | |
44 | void clear(); |
|
44 | void clear(); | |
45 | int count(); |
|
45 | int count(); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | QScopedPointer<QChartAxisCategoriesPrivate> d_ptr; |
|
48 | QScopedPointer<QChartAxisCategoriesPrivate> d_ptr; | |
49 |
friend class Q |
|
49 | friend class QAxisPrivate; | |
50 | friend class Axis; |
|
50 | friend class ChartAxis; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
55 |
|
55 | |||
56 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
|
56 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
@@ -1,206 +1,206 | |||||
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 "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarset_p.h" |
|
25 | #include "qbarset_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qbarseries.h" | |
27 | #include "qbarseries_p.h" |
|
27 | #include "qbarseries_p.h" | |
28 | #include "qchart.h" |
|
28 | #include "qchart.h" | |
29 | #include "qchartaxis.h" |
|
29 | //#include "qchartaxis.h" | |
30 | #include "qchartaxiscategories.h" |
|
30 | #include "qchartaxiscategories.h" | |
31 | #include "chartpresenter_p.h" |
|
31 | #include "chartpresenter_p.h" | |
32 | #include "chartanimator_p.h" |
|
32 | #include "chartanimator_p.h" | |
33 | #include "chartdataset_p.h" |
|
33 | #include "chartdataset_p.h" | |
34 | #include <QPainter> |
|
34 | #include <QPainter> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
38 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
39 | ChartItem(presenter), |
|
39 | ChartItem(presenter), | |
40 | m_layoutSet(false), |
|
40 | m_layoutSet(false), | |
41 | m_series(series) |
|
41 | m_series(series) | |
42 | { |
|
42 | { | |
43 | setFlag(ItemClipsChildrenToShape); |
|
43 | setFlag(ItemClipsChildrenToShape); | |
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
45 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); |
|
45 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
46 | setZValue(ChartPresenter::BarSeriesZValue); |
|
46 | setZValue(ChartPresenter::BarSeriesZValue); | |
47 | dataChanged(); |
|
47 | dataChanged(); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | BarChartItem::~BarChartItem() |
|
50 | BarChartItem::~BarChartItem() | |
51 | { |
|
51 | { | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
55 | { | |
56 | Q_UNUSED(painter); |
|
56 | Q_UNUSED(painter); | |
57 | Q_UNUSED(option); |
|
57 | Q_UNUSED(option); | |
58 | Q_UNUSED(widget); |
|
58 | Q_UNUSED(widget); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | QRectF BarChartItem::boundingRect() const |
|
61 | QRectF BarChartItem::boundingRect() const | |
62 | { |
|
62 | { | |
63 | return m_rect; |
|
63 | return m_rect; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void BarChartItem::dataChanged() |
|
66 | void BarChartItem::dataChanged() | |
67 | { |
|
67 | { | |
68 | foreach(QGraphicsItem *item, childItems()) { |
|
68 | foreach(QGraphicsItem *item, childItems()) { | |
69 | delete item; |
|
69 | delete item; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | m_bars.clear(); |
|
72 | m_bars.clear(); | |
73 | m_labels.clear(); |
|
73 | m_labels.clear(); | |
74 | m_layout.clear(); |
|
74 | m_layout.clear(); | |
75 |
|
75 | |||
76 | // Create new graphic items for bars |
|
76 | // Create new graphic items for bars | |
77 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
77 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
78 | QString category = m_series->d_func()->categoryName(c); |
|
78 | QString category = m_series->d_func()->categoryName(c); | |
79 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
79 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
80 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
80 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
81 | Bar *bar = new Bar(set,category,this); |
|
81 | Bar *bar = new Bar(set,category,this); | |
82 | m_bars.append(bar); |
|
82 | m_bars.append(bar); | |
83 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); |
|
83 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); | |
84 | connect(bar, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), m_series, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons))); |
|
84 | connect(bar, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), m_series, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons))); | |
85 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); |
|
85 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); | |
86 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
86 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
87 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
87 | m_layout.append(QRectF(0, 0, 0, 0)); | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | // Create labels |
|
91 | // Create labels | |
92 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
92 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
93 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
93 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
94 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
94 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
95 | BarLabel *value = new BarLabel(*set, this); |
|
95 | BarLabel *value = new BarLabel(*set, this); | |
96 | m_labels.append(value); |
|
96 | m_labels.append(value); | |
97 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); |
|
97 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | QVector<QRectF> BarChartItem::calculateLayout() |
|
102 | QVector<QRectF> BarChartItem::calculateLayout() | |
103 | { |
|
103 | { | |
104 | QVector<QRectF> layout; |
|
104 | QVector<QRectF> layout; | |
105 |
|
105 | |||
106 | // Use temporary qreals for accurancy |
|
106 | // Use temporary qreals for accurancy | |
107 | qreal categoryCount = m_series->categoryCount(); |
|
107 | qreal categoryCount = m_series->categoryCount(); | |
108 | qreal setCount = m_series->barsetCount(); |
|
108 | qreal setCount = m_series->barsetCount(); | |
109 |
|
109 | |||
110 | // Domain: |
|
110 | // Domain: | |
111 | qreal width = geometry().width(); |
|
111 | qreal width = geometry().width(); | |
112 | qreal height = geometry().height(); |
|
112 | qreal height = geometry().height(); | |
113 | qreal range = m_domainMaxY - m_domainMinY; |
|
113 | qreal range = m_domainMaxY - m_domainMinY; | |
114 | qreal scale = (height / range); |
|
114 | qreal scale = (height / range); | |
115 | qreal categoryWidth = width / categoryCount; |
|
115 | qreal categoryWidth = width / categoryCount; | |
116 | qreal barWidth = categoryWidth / (setCount+1); |
|
116 | qreal barWidth = categoryWidth / (setCount+1); | |
117 |
|
117 | |||
118 | int itemIndex(0); |
|
118 | int itemIndex(0); | |
119 | for (int category = 0; category < categoryCount; category++) { |
|
119 | for (int category = 0; category < categoryCount; category++) { | |
120 | qreal xPos = categoryWidth * category + barWidth / 2 + geometry().topLeft().x(); |
|
120 | qreal xPos = categoryWidth * category + barWidth / 2 + geometry().topLeft().x(); | |
121 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); |
|
121 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); | |
122 | for (int set = 0; set < setCount; set++) { |
|
122 | for (int set = 0; set < setCount; set++) { | |
123 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
123 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
124 |
|
124 | |||
125 | qreal barHeight = barSet->at(category) * scale; |
|
125 | qreal barHeight = barSet->at(category) * scale; | |
126 | Bar* bar = m_bars.at(itemIndex); |
|
126 | Bar* bar = m_bars.at(itemIndex); | |
127 |
|
127 | |||
128 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
128 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
129 | layout.append(rect); |
|
129 | layout.append(rect); | |
130 | bar->setPen(barSet->pen()); |
|
130 | bar->setPen(barSet->pen()); | |
131 | bar->setBrush(barSet->brush()); |
|
131 | bar->setBrush(barSet->brush()); | |
132 |
|
132 | |||
133 | BarLabel* label = m_labels.at(itemIndex); |
|
133 | BarLabel* label = m_labels.at(itemIndex); | |
134 |
|
134 | |||
135 | if (!qFuzzyIsNull(barSet->at(category))) { |
|
135 | if (!qFuzzyIsNull(barSet->at(category))) { | |
136 | label->setText(QString::number(barSet->at(category))); |
|
136 | label->setText(QString::number(barSet->at(category))); | |
137 | } else { |
|
137 | } else { | |
138 | label->setText(QString("")); |
|
138 | label->setText(QString("")); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
141 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
142 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
142 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
143 | label->setFont(barSet->labelFont()); |
|
143 | label->setFont(barSet->labelFont()); | |
144 |
|
144 | |||
145 | itemIndex++; |
|
145 | itemIndex++; | |
146 | xPos += barWidth; |
|
146 | xPos += barWidth; | |
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 | return layout; |
|
149 | return layout; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
152 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
153 | { |
|
153 | { | |
154 | if (animator()) |
|
154 | if (animator()) | |
155 | animator()->updateLayout(this, m_layout, layout); |
|
155 | animator()->updateLayout(this, m_layout, layout); | |
156 | else |
|
156 | else | |
157 | setLayout(layout); |
|
157 | setLayout(layout); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
160 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
161 | { |
|
161 | { | |
162 | m_layout = layout; |
|
162 | m_layout = layout; | |
163 |
|
163 | |||
164 | for (int i=0; i < m_bars.count(); i++) |
|
164 | for (int i=0; i < m_bars.count(); i++) | |
165 | m_bars.at(i)->setRect(layout.at(i)); |
|
165 | m_bars.at(i)->setRect(layout.at(i)); | |
166 |
|
166 | |||
167 | update(); |
|
167 | update(); | |
168 | } |
|
168 | } | |
169 | //handlers |
|
169 | //handlers | |
170 |
|
170 | |||
171 | void BarChartItem::handleModelChanged() |
|
171 | void BarChartItem::handleModelChanged() | |
172 | { |
|
172 | { | |
173 | dataChanged(); |
|
173 | dataChanged(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
176 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
177 | { |
|
177 | { | |
178 | m_domainMinX = minX; |
|
178 | m_domainMinX = minX; | |
179 | m_domainMaxX = maxX; |
|
179 | m_domainMaxX = maxX; | |
180 | m_domainMinY = minY; |
|
180 | m_domainMinY = minY; | |
181 | m_domainMaxY = maxY; |
|
181 | m_domainMaxY = maxY; | |
182 | handleLayoutChanged(); |
|
182 | handleLayoutChanged(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
185 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
186 | { |
|
186 | { | |
187 | prepareGeometryChange(); |
|
187 | prepareGeometryChange(); | |
188 | m_rect = rect; |
|
188 | m_rect = rect; | |
189 | handleLayoutChanged(); |
|
189 | handleLayoutChanged(); | |
190 | m_layoutSet = true; |
|
190 | m_layoutSet = true; | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | void BarChartItem::handleLayoutChanged() |
|
193 | void BarChartItem::handleLayoutChanged() | |
194 | { |
|
194 | { | |
195 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
195 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
196 | // rect size zero. |
|
196 | // rect size zero. | |
197 | return; |
|
197 | return; | |
198 | } |
|
198 | } | |
199 | QVector<QRectF> layout = calculateLayout(); |
|
199 | QVector<QRectF> layout = calculateLayout(); | |
200 | applyLayout(layout); |
|
200 | applyLayout(layout); | |
201 | update(); |
|
201 | update(); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | #include "moc_barchartitem_p.cpp" |
|
204 | #include "moc_barchartitem_p.cpp" | |
205 |
|
205 | |||
206 | QTCOMMERCIALCHART_END_NAMESPACE |
|
206 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,252 +1,252 | |||||
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 "q |
|
22 | #include "qaxis.h" | |
23 |
#include "q |
|
23 | #include "qaxis_p.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qstackedbarseries.h" |
|
26 | #include "qstackedbarseries.h" | |
27 | #include "qpercentbarseries.h" |
|
27 | #include "qpercentbarseries.h" | |
28 | #include "qpieseries.h" |
|
28 | #include "qpieseries.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
33 |
m_axisX(new Q |
|
33 | m_axisX(new QAxis(this)), | |
34 |
m_axisY(new Q |
|
34 | m_axisY(new QAxis(this)), | |
35 | m_domainIndex(0), |
|
35 | m_domainIndex(0), | |
36 | m_axisXInitialized(false) |
|
36 | m_axisXInitialized(false) | |
37 | { |
|
37 | { | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | ChartDataSet::~ChartDataSet() |
|
40 | ChartDataSet::~ChartDataSet() | |
41 | { |
|
41 | { | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 |
void ChartDataSet::addSeries(QAbstractSeries* series, Q |
|
44 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) | |
45 | { |
|
45 | { | |
46 | if(axisY==0) axisY = m_axisY; |
|
46 | if(axisY==0) axisY = m_axisY; | |
47 |
|
47 | |||
48 |
Q |
|
48 | QAxis* axis = m_seriesAxisMap.value(series); | |
49 |
|
49 | |||
50 | if(axis) { |
|
50 | if(axis) { | |
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 | series->setParent(this); // take ownership |
|
55 | series->setParent(this); // take ownership | |
56 | axisY->setParent(this); // take ownership |
|
56 | axisY->setParent(this); // take ownership | |
57 |
|
57 | |||
58 | Domain* domain = m_axisDomainMap.value(axisY); |
|
58 | Domain* domain = m_axisDomainMap.value(axisY); | |
59 |
|
59 | |||
60 | if(!domain) { |
|
60 | if(!domain) { | |
61 | domain = new Domain(axisY); |
|
61 | domain = new Domain(axisY); | |
62 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
62 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
63 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
63 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
64 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
64 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
65 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX()->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
65 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX()->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
66 | //initialize |
|
66 | //initialize | |
67 | m_axisDomainMap.insert(axisY,domain); |
|
67 | m_axisDomainMap.insert(axisY,domain); | |
68 | emit axisAdded(axisY,domain); |
|
68 | emit axisAdded(axisY,domain); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | if(!m_axisXInitialized){ |
|
71 | if(!m_axisXInitialized){ | |
72 | emit axisAdded(axisX(),domain); |
|
72 | emit axisAdded(axisX(),domain); | |
73 | m_axisXInitialized=true; |
|
73 | m_axisXInitialized=true; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | series->d_ptr->scaleDomain(*domain); |
|
76 | series->d_ptr->scaleDomain(*domain); | |
77 |
|
77 | |||
78 | if(series->type() == QAbstractSeries::SeriesTypeBar |
|
78 | if(series->type() == QAbstractSeries::SeriesTypeBar | |
79 | || series->type() == QAbstractSeries::SeriesTypeStackedBar |
|
79 | || series->type() == QAbstractSeries::SeriesTypeStackedBar | |
80 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { |
|
80 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { | |
81 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
81 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
82 | setupCategories(barSeries); |
|
82 | setupCategories(barSeries); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { |
|
85 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { | |
86 | axisX()->hide(); |
|
86 | axisX()->hide(); | |
87 | this->axisY()->hide(); |
|
87 | this->axisY()->hide(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | m_seriesAxisMap.insert(series,axisY); |
|
90 | m_seriesAxisMap.insert(series,axisY); | |
91 |
|
91 | |||
92 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
92 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
93 |
|
93 | |||
94 | int key=0; |
|
94 | int key=0; | |
95 | while (i.hasNext()) { |
|
95 | while (i.hasNext()) { | |
96 | i.next(); |
|
96 | i.next(); | |
97 | if(i.key()!=key) { |
|
97 | if(i.key()!=key) { | |
98 | break; |
|
98 | break; | |
99 | } |
|
99 | } | |
100 | key++; |
|
100 | key++; | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | m_indexSeriesMap.insert(key,series); |
|
103 | m_indexSeriesMap.insert(key,series); | |
104 |
|
104 | |||
105 | emit seriesAdded(series,domain); |
|
105 | emit seriesAdded(series,domain); | |
106 |
|
106 | |||
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 |
Q |
|
109 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) | |
110 | { |
|
110 | { | |
111 |
Q |
|
111 | QAxis* axis = m_seriesAxisMap.value(series); | |
112 |
|
112 | |||
113 | if(!axis){ |
|
113 | if(!axis){ | |
114 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
114 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
115 | return 0; |
|
115 | return 0; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | emit seriesRemoved(series); |
|
118 | emit seriesRemoved(series); | |
119 |
|
119 | |||
120 | m_seriesAxisMap.remove(series); |
|
120 | m_seriesAxisMap.remove(series); | |
121 | int key = seriesIndex(series); |
|
121 | int key = seriesIndex(series); | |
122 | Q_ASSERT(key!=-1); |
|
122 | Q_ASSERT(key!=-1); | |
123 |
|
123 | |||
124 | m_indexSeriesMap.remove(key); |
|
124 | m_indexSeriesMap.remove(key); | |
125 | series->setParent(0); |
|
125 | series->setParent(0); | |
126 |
|
126 | |||
127 |
QList<Q |
|
127 | QList<QAxis*> axes = m_seriesAxisMap.values(); | |
128 |
|
128 | |||
129 | int i = axes.indexOf(axis); |
|
129 | int i = axes.indexOf(axis); | |
130 |
|
130 | |||
131 | if(i==-1){ |
|
131 | if(i==-1){ | |
132 | Domain* domain = m_axisDomainMap.take(axis); |
|
132 | Domain* domain = m_axisDomainMap.take(axis); | |
133 | emit axisRemoved(axis); |
|
133 | emit axisRemoved(axis); | |
134 | if(axis!=axisY()){ |
|
134 | if(axis!=axisY()){ | |
135 | axis->setParent(0); |
|
135 | axis->setParent(0); | |
136 | } |
|
136 | } | |
137 | delete domain; |
|
137 | delete domain; | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | if(m_seriesAxisMap.values().size()==0) |
|
140 | if(m_seriesAxisMap.values().size()==0) | |
141 | { |
|
141 | { | |
142 | m_axisXInitialized=false; |
|
142 | m_axisXInitialized=false; | |
143 | emit axisRemoved(axisX()); |
|
143 | emit axisRemoved(axisX()); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | return axis; |
|
146 | return axis; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void ChartDataSet::removeAllSeries() |
|
149 | void ChartDataSet::removeAllSeries() | |
150 | { |
|
150 | { | |
151 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); |
|
151 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); | |
152 |
QList<Q |
|
152 | QList<QAxis*> axes; | |
153 | foreach(QAbstractSeries *s , series) { |
|
153 | foreach(QAbstractSeries *s , series) { | |
154 |
Q |
|
154 | QAxis* axis = removeSeries(s); | |
155 | if(axis==axisY()) continue; |
|
155 | if(axis==axisY()) continue; | |
156 | int i = axes.indexOf(axis); |
|
156 | int i = axes.indexOf(axis); | |
157 | if(i==-1){ |
|
157 | if(i==-1){ | |
158 | axes<<axis; |
|
158 | axes<<axis; | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
162 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
163 | Q_ASSERT(m_axisDomainMap.count()==0); |
|
163 | Q_ASSERT(m_axisDomainMap.count()==0); | |
164 |
|
164 | |||
165 | qDeleteAll(series); |
|
165 | qDeleteAll(series); | |
166 | qDeleteAll(axes); |
|
166 | qDeleteAll(axes); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
169 | void ChartDataSet::setupCategories(QBarSeries* series) | |
170 | { |
|
170 | { | |
171 | QChartAxisCategories* categories = axisX()->categories(); |
|
171 | QChartAxisCategories* categories = axisX()->categories(); | |
172 | categories->clear(); |
|
172 | categories->clear(); | |
173 | categories->insert(series->categories()); |
|
173 | categories->insert(series->categories()); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
176 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
177 | { |
|
177 | { | |
178 |
QMapIterator<Q |
|
178 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
179 | while (i.hasNext()) { |
|
179 | while (i.hasNext()) { | |
180 | i.next(); |
|
180 | i.next(); | |
181 | i.value()->zoomIn(rect,size); |
|
181 | i.value()->zoomIn(rect,size); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
185 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
186 | { |
|
186 | { | |
187 |
QMapIterator<Q |
|
187 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
188 | while (i.hasNext()) { |
|
188 | while (i.hasNext()) { | |
189 | i.next(); |
|
189 | i.next(); | |
190 | i.value()->zoomOut(rect,size); |
|
190 | i.value()->zoomOut(rect,size); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | int ChartDataSet::seriesCount(QAbstractSeries::QSeriesType type) |
|
194 | int ChartDataSet::seriesCount(QAbstractSeries::QSeriesType type) | |
195 | { |
|
195 | { | |
196 | int count=0; |
|
196 | int count=0; | |
197 |
QMapIterator<QAbstractSeries*, Q |
|
197 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); | |
198 | while (i.hasNext()) { |
|
198 | while (i.hasNext()) { | |
199 | i.next(); |
|
199 | i.next(); | |
200 | if(i.key()->type()==type) count++; |
|
200 | if(i.key()->type()==type) count++; | |
201 | } |
|
201 | } | |
202 | return count; |
|
202 | return count; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
205 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
206 | { |
|
206 | { | |
207 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
207 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
208 | while (i.hasNext()) { |
|
208 | while (i.hasNext()) { | |
209 | i.next(); |
|
209 | i.next(); | |
210 | if (i.value() == series) |
|
210 | if (i.value() == series) | |
211 | return i.key(); |
|
211 | return i.key(); | |
212 | } |
|
212 | } | |
213 | return -1; |
|
213 | return -1; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 |
Q |
|
216 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
217 | { |
|
217 | { | |
218 | if(series == 0) return m_axisY; |
|
218 | if(series == 0) return m_axisY; | |
219 | return m_seriesAxisMap.value(series); |
|
219 | return m_seriesAxisMap.value(series); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
222 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
223 | { |
|
223 | { | |
224 |
Q |
|
224 | QAxis* axis = m_seriesAxisMap.value(series); | |
225 | if(axis){ |
|
225 | if(axis){ | |
226 | return m_axisDomainMap.value(axis); |
|
226 | return m_axisDomainMap.value(axis); | |
227 | }else |
|
227 | }else | |
228 | return 0; |
|
228 | return 0; | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 |
Domain* ChartDataSet::domain(Q |
|
231 | Domain* ChartDataSet::domain(QAxis* axis) const | |
232 | { |
|
232 | { | |
233 | if(!axis || axis==axisX()) { |
|
233 | if(!axis || axis==axisX()) { | |
234 | return m_axisDomainMap.value(axisY()); |
|
234 | return m_axisDomainMap.value(axisY()); | |
235 | } |
|
235 | } | |
236 | else { |
|
236 | else { | |
237 | return m_axisDomainMap.value(axis); |
|
237 | return m_axisDomainMap.value(axis); | |
238 | } |
|
238 | } | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
241 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) | |
242 | { |
|
242 | { | |
243 |
QMapIterator<Q |
|
243 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); | |
244 | while (i.hasNext()) { |
|
244 | while (i.hasNext()) { | |
245 | i.next(); |
|
245 | i.next(); | |
246 | i.value()->move(dx,dy,size); |
|
246 | i.value()->move(dx,dy,size); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | #include "moc_chartdataset_p.cpp" |
|
250 | #include "moc_chartdataset_p.cpp" | |
251 |
|
251 | |||
252 | QTCOMMERCIALCHART_END_NAMESPACE |
|
252 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +1,90 | |||||
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 CHARTDATASET_P_H |
|
30 | #ifndef CHARTDATASET_P_H | |
31 | #define CHARTDATASET_P_H |
|
31 | #define CHARTDATASET_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 | #include <QVector> |
|
35 | #include <QVector> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 |
class Q |
|
39 | class QAxis; | |
40 | class QBarSeries; |
|
40 | class QBarSeries; | |
41 |
|
41 | |||
42 | class ChartDataSet : public QObject |
|
42 | class ChartDataSet : public QObject | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | ChartDataSet(QObject* parent=0); |
|
46 | ChartDataSet(QObject* parent=0); | |
47 | virtual ~ChartDataSet(); |
|
47 | virtual ~ChartDataSet(); | |
48 |
|
48 | |||
49 |
void addSeries(QAbstractSeries* series,Q |
|
49 | void addSeries(QAbstractSeries* series,QAxis *axisY = 0); | |
50 |
Q |
|
50 | QAxis* removeSeries(QAbstractSeries* series); | |
51 | void removeAllSeries(); |
|
51 | void removeAllSeries(); | |
52 |
|
52 | |||
53 | void zoomInDomain(const QRectF& rect, const QSizeF& size); |
|
53 | void zoomInDomain(const QRectF& rect, const QSizeF& size); | |
54 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); |
|
54 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); | |
55 | void scrollDomain(int dx,int dy,const QSizeF& size); |
|
55 | void scrollDomain(int dx,int dy,const QSizeF& size); | |
56 |
|
56 | |||
57 | int seriesCount(QAbstractSeries::QSeriesType type); |
|
57 | int seriesCount(QAbstractSeries::QSeriesType type); | |
58 | int seriesIndex(QAbstractSeries *series); |
|
58 | int seriesIndex(QAbstractSeries *series); | |
59 |
|
59 | |||
60 | Domain* domain(QAbstractSeries* series) const; |
|
60 | Domain* domain(QAbstractSeries* series) const; | |
61 |
Domain* domain(Q |
|
61 | Domain* domain(QAxis* axis) const; | |
62 |
|
62 | |||
63 |
Q |
|
63 | QAxis* axisX() const { return m_axisX; } | |
64 |
Q |
|
64 | QAxis* axisY(QAbstractSeries *series = 0) const; | |
65 |
|
65 | |||
66 | Q_SIGNALS: |
|
66 | Q_SIGNALS: | |
67 | void seriesAdded(QAbstractSeries* series, Domain* domain); |
|
67 | void seriesAdded(QAbstractSeries* series, Domain* domain); | |
68 | void seriesRemoved(QAbstractSeries* series); |
|
68 | void seriesRemoved(QAbstractSeries* series); | |
69 |
void axisAdded(Q |
|
69 | void axisAdded(QAxis* axis,Domain* domain); | |
70 |
void axisRemoved(Q |
|
70 | void axisRemoved(QAxis* axis); | |
71 |
|
71 | |||
72 | private: |
|
72 | private: | |
73 |
QStringList createLabels(Q |
|
73 | QStringList createLabels(QAxis* axis,qreal min, qreal max); | |
74 | void calculateDomain(QAbstractSeries* series,Domain* domain); |
|
74 | void calculateDomain(QAbstractSeries* series,Domain* domain); | |
75 | void setupCategories(QBarSeries* series); |
|
75 | void setupCategories(QBarSeries* series); | |
76 |
|
76 | |||
77 | private: |
|
77 | private: | |
78 |
QMap<QAbstractSeries *, Q |
|
78 | QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap; | |
79 |
QMap<Q |
|
79 | QMap<QAxis*, Domain *> m_axisDomainMap; | |
80 | QMap<int, QAbstractSeries *> m_indexSeriesMap; |
|
80 | QMap<int, QAbstractSeries *> m_indexSeriesMap; | |
81 |
Q |
|
81 | QAxis* m_axisX; | |
82 |
Q |
|
82 | QAxis* m_axisY; | |
83 |
|
83 | |||
84 | int m_domainIndex; |
|
84 | int m_domainIndex; | |
85 | bool m_axisXInitialized; |
|
85 | bool m_axisXInitialized; | |
86 | }; |
|
86 | }; | |
87 |
|
87 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE | |
89 |
|
89 | |||
90 | #endif /* CHARTENGINE_P_H_ */ |
|
90 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,401 +1,402 | |||||
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 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 |
#include "q |
|
23 | #include "qaxis.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include "qabstractseries_p.h" |
|
27 | #include "qabstractseries_p.h" | |
28 | #include "qareaseries.h" |
|
28 | #include "qareaseries.h" | |
29 | #include "axis_p.h" |
|
29 | #include "chartaxis_p.h" | |
30 | #include "areachartitem_p.h" |
|
30 | #include "areachartitem_p.h" | |
|
31 | #include "chartbackground_p.h" | |||
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
34 | |||
34 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
35 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
35 | m_chart(chart), |
|
36 | m_chart(chart), | |
36 | m_animator(0), |
|
37 | m_animator(0), | |
37 | m_dataset(dataset), |
|
38 | m_dataset(dataset), | |
38 | m_chartTheme(0), |
|
39 | m_chartTheme(0), | |
39 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), |
|
40 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), | |
40 | m_options(QChart::NoAnimation), |
|
41 | m_options(QChart::NoAnimation), | |
41 | m_minLeftMargin(0), |
|
42 | m_minLeftMargin(0), | |
42 | m_minBottomMargin(0), |
|
43 | m_minBottomMargin(0), | |
43 | m_backgroundItem(0), |
|
44 | m_backgroundItem(0), | |
44 | m_titleItem(0), |
|
45 | m_titleItem(0), | |
45 | m_marginBig(60), |
|
46 | m_marginBig(60), | |
46 | m_marginSmall(20), |
|
47 | m_marginSmall(20), | |
47 | m_marginTiny(10), |
|
48 | m_marginTiny(10), | |
48 | m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) |
|
49 | m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) | |
49 | { |
|
50 | { | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | ChartPresenter::~ChartPresenter() |
|
53 | ChartPresenter::~ChartPresenter() | |
53 | { |
|
54 | { | |
54 | delete m_chartTheme; |
|
55 | delete m_chartTheme; | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | void ChartPresenter::setGeometry(const QRectF& rect) |
|
58 | void ChartPresenter::setGeometry(const QRectF& rect) | |
58 | { |
|
59 | { | |
59 | m_rect = rect; |
|
60 | m_rect = rect; | |
60 | Q_ASSERT(m_rect.isValid()); |
|
61 | Q_ASSERT(m_rect.isValid()); | |
61 | updateLayout(); |
|
62 | updateLayout(); | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) |
|
65 | void ChartPresenter::setMinimumMarginWidth(ChartAxis* axis, qreal width) | |
65 | { |
|
66 | { | |
66 | switch(axis->axisType()){ |
|
67 | switch(axis->axisType()){ | |
67 | case Axis::X_AXIS: |
|
68 | case ChartAxis::X_AXIS: | |
68 | { |
|
69 | { | |
69 | if(width>m_chartRect.width()+ m_chartMargins.left()) { |
|
70 | if(width>m_chartRect.width()+ m_chartMargins.left()) { | |
70 | m_minLeftMargin= width - m_chartRect.width(); |
|
71 | m_minLeftMargin= width - m_chartRect.width(); | |
71 | updateLayout(); |
|
72 | updateLayout(); | |
72 | } |
|
73 | } | |
73 | break; |
|
74 | break; | |
74 | } |
|
75 | } | |
75 | case Axis::Y_AXIS: |
|
76 | case ChartAxis::Y_AXIS: | |
76 | { |
|
77 | { | |
77 |
|
78 | |||
78 | if(m_minLeftMargin!=width){ |
|
79 | if(m_minLeftMargin!=width){ | |
79 | m_minLeftMargin= width; |
|
80 | m_minLeftMargin= width; | |
80 | updateLayout(); |
|
81 | updateLayout(); | |
81 | } |
|
82 | } | |
82 | break; |
|
83 | break; | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | } |
|
86 | } | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 | void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height) |
|
89 | void ChartPresenter::setMinimumMarginHeight(ChartAxis* axis, qreal height) | |
89 | { |
|
90 | { | |
90 | switch(axis->axisType()){ |
|
91 | switch(axis->axisType()){ | |
91 | case Axis::X_AXIS: |
|
92 | case ChartAxis::X_AXIS: | |
92 | { |
|
93 | { | |
93 | if(m_minBottomMargin!=height) { |
|
94 | if(m_minBottomMargin!=height) { | |
94 | m_minBottomMargin= height; |
|
95 | m_minBottomMargin= height; | |
95 | updateLayout(); |
|
96 | updateLayout(); | |
96 | } |
|
97 | } | |
97 | break; |
|
98 | break; | |
98 | } |
|
99 | } | |
99 | case Axis::Y_AXIS: |
|
100 | case ChartAxis::Y_AXIS: | |
100 | { |
|
101 | { | |
101 |
|
102 | |||
102 | if(height>m_chartMargins.bottom()+m_chartRect.height()){ |
|
103 | if(height>m_chartMargins.bottom()+m_chartRect.height()){ | |
103 | m_minBottomMargin= height - m_chartRect.height(); |
|
104 | m_minBottomMargin= height - m_chartRect.height(); | |
104 | updateLayout(); |
|
105 | updateLayout(); | |
105 | } |
|
106 | } | |
106 | break; |
|
107 | break; | |
107 | } |
|
108 | } | |
108 |
|
109 | |||
109 | } |
|
110 | } | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 |
void ChartPresenter::handleAxisAdded(Q |
|
113 | void ChartPresenter::handleAxisAdded(QAxis* axis,Domain* domain) | |
113 | { |
|
114 | { | |
114 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); |
|
115 | ChartAxis* item = new ChartAxis(axis,this,axis==m_dataset->axisX()?ChartAxis::X_AXIS : ChartAxis::Y_AXIS); | |
115 |
|
116 | |||
116 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
117 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
117 | m_animator->addAnimation(item); |
|
118 | m_animator->addAnimation(item); | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | if(axis==m_dataset->axisX()){ |
|
121 | if(axis==m_dataset->axisX()){ | |
121 | m_chartTheme->decorate(axis,true); |
|
122 | m_chartTheme->decorate(axis,true); | |
122 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
123 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
123 | //initialize |
|
124 | //initialize | |
124 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
125 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
125 |
|
126 | |||
126 | } |
|
127 | } | |
127 | else{ |
|
128 | else{ | |
128 | m_chartTheme->decorate(axis,false); |
|
129 | m_chartTheme->decorate(axis,false); | |
129 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
130 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
130 | //initialize |
|
131 | //initialize | |
131 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
132 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
135 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
135 | //initialize |
|
136 | //initialize | |
136 | item->handleGeometryChanged(m_chartRect); |
|
137 | item->handleGeometryChanged(m_chartRect); | |
137 | m_axisItems.insert(axis, item); |
|
138 | m_axisItems.insert(axis, item); | |
138 | } |
|
139 | } | |
139 |
|
140 | |||
140 |
void ChartPresenter::handleAxisRemoved(Q |
|
141 | void ChartPresenter::handleAxisRemoved(QAxis* axis) | |
141 | { |
|
142 | { | |
142 | Axis* item = m_axisItems.take(axis); |
|
143 | ChartAxis* item = m_axisItems.take(axis); | |
143 | Q_ASSERT(item); |
|
144 | Q_ASSERT(item); | |
144 | if(m_animator) m_animator->removeAnimation(item); |
|
145 | if(m_animator) m_animator->removeAnimation(item); | |
145 | delete item; |
|
146 | delete item; | |
146 | } |
|
147 | } | |
147 |
|
148 | |||
148 |
|
149 | |||
149 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) |
|
150 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) | |
150 | { |
|
151 | { | |
151 | Chart *item = series->d_ptr->createGraphics(this); |
|
152 | Chart *item = series->d_ptr->createGraphics(this); | |
152 | Q_ASSERT(item); |
|
153 | Q_ASSERT(item); | |
153 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
154 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
154 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
155 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
155 | //initialize |
|
156 | //initialize | |
156 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
157 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
157 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); |
|
158 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); | |
158 | m_chartItems.insert(series,item); |
|
159 | m_chartItems.insert(series,item); | |
159 | } |
|
160 | } | |
160 |
|
161 | |||
161 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) |
|
162 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) | |
162 | { |
|
163 | { | |
163 | Chart* item = m_chartItems.take(series); |
|
164 | Chart* item = m_chartItems.take(series); | |
164 | Q_ASSERT(item); |
|
165 | Q_ASSERT(item); | |
165 | if(m_animator) { |
|
166 | if(m_animator) { | |
166 | //small hack to handle area animations |
|
167 | //small hack to handle area animations | |
167 | if(series->type() == QAbstractSeries::SeriesTypeArea){ |
|
168 | if(series->type() == QAbstractSeries::SeriesTypeArea){ | |
168 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
169 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
169 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
170 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
170 | m_animator->removeAnimation(area->upperLineItem()); |
|
171 | m_animator->removeAnimation(area->upperLineItem()); | |
171 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
172 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
172 | }else |
|
173 | }else | |
173 | m_animator->removeAnimation(item); |
|
174 | m_animator->removeAnimation(item); | |
174 | } |
|
175 | } | |
175 | delete item; |
|
176 | delete item; | |
176 | } |
|
177 | } | |
177 |
|
178 | |||
178 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
179 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
179 | { |
|
180 | { | |
180 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
181 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
181 | delete m_chartTheme; |
|
182 | delete m_chartTheme; | |
182 | m_chartTheme = ChartTheme::createTheme(theme); |
|
183 | m_chartTheme = ChartTheme::createTheme(theme); | |
183 | m_chartTheme->setForced(force); |
|
184 | m_chartTheme->setForced(force); | |
184 | m_chartTheme->decorate(m_chart); |
|
185 | m_chartTheme->decorate(m_chart); | |
185 | m_chartTheme->decorate(m_chart->legend()); |
|
186 | m_chartTheme->decorate(m_chart->legend()); | |
186 | resetAllElements(); |
|
187 | resetAllElements(); | |
187 | } |
|
188 | } | |
188 |
|
189 | |||
189 | QChart::ChartTheme ChartPresenter::theme() |
|
190 | QChart::ChartTheme ChartPresenter::theme() | |
190 | { |
|
191 | { | |
191 | return m_chartTheme->id(); |
|
192 | return m_chartTheme->id(); | |
192 | } |
|
193 | } | |
193 |
|
194 | |||
194 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
195 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
195 | { |
|
196 | { | |
196 | if(m_options!=options) { |
|
197 | if(m_options!=options) { | |
197 |
|
198 | |||
198 | m_options=options; |
|
199 | m_options=options; | |
199 |
|
200 | |||
200 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
201 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
201 | m_animator= new ChartAnimator(this); |
|
202 | m_animator= new ChartAnimator(this); | |
202 | } |
|
203 | } | |
203 | resetAllElements(); |
|
204 | resetAllElements(); | |
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | } |
|
207 | } | |
207 |
|
208 | |||
208 | void ChartPresenter::resetAllElements() |
|
209 | void ChartPresenter::resetAllElements() | |
209 | { |
|
210 | { | |
210 |
QList<Q |
|
211 | QList<QAxis *> axisList = m_axisItems.uniqueKeys(); | |
211 | QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys(); |
|
212 | QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys(); | |
212 |
|
213 | |||
213 |
foreach(Q |
|
214 | foreach(QAxis *axis, axisList) { | |
214 | handleAxisRemoved(axis); |
|
215 | handleAxisRemoved(axis); | |
215 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
216 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
216 | } |
|
217 | } | |
217 | foreach(QAbstractSeries *series, seriesList) { |
|
218 | foreach(QAbstractSeries *series, seriesList) { | |
218 | handleSeriesRemoved(series); |
|
219 | handleSeriesRemoved(series); | |
219 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
220 | handleSeriesAdded(series,m_dataset->domain(series)); | |
220 | } |
|
221 | } | |
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | void ChartPresenter::zoomIn() |
|
224 | void ChartPresenter::zoomIn() | |
224 | { |
|
225 | { | |
225 | QRectF rect = chartGeometry(); |
|
226 | QRectF rect = chartGeometry(); | |
226 | rect.setWidth(rect.width()/2); |
|
227 | rect.setWidth(rect.width()/2); | |
227 | rect.setHeight(rect.height()/2); |
|
228 | rect.setHeight(rect.height()/2); | |
228 | rect.moveCenter(chartGeometry().center()); |
|
229 | rect.moveCenter(chartGeometry().center()); | |
229 | zoomIn(rect); |
|
230 | zoomIn(rect); | |
230 | } |
|
231 | } | |
231 |
|
232 | |||
232 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
233 | void ChartPresenter::zoomIn(const QRectF& rect) | |
233 | { |
|
234 | { | |
234 | QRectF r = rect.normalized(); |
|
235 | QRectF r = rect.normalized(); | |
235 | r.translate(-m_chartMargins.topLeft()); |
|
236 | r.translate(-m_chartMargins.topLeft()); | |
236 | if(m_animator) { |
|
237 | if(m_animator) { | |
237 |
|
238 | |||
238 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); |
|
239 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); | |
239 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
240 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
240 | } |
|
241 | } | |
241 | m_dataset->zoomInDomain(r,chartGeometry().size()); |
|
242 | m_dataset->zoomInDomain(r,chartGeometry().size()); | |
242 | if(m_animator) { |
|
243 | if(m_animator) { | |
243 | m_animator->setState(ChartAnimator::ShowState); |
|
244 | m_animator->setState(ChartAnimator::ShowState); | |
244 | } |
|
245 | } | |
245 | } |
|
246 | } | |
246 |
|
247 | |||
247 | void ChartPresenter::zoomOut() |
|
248 | void ChartPresenter::zoomOut() | |
248 | { |
|
249 | { | |
249 | if(m_animator) |
|
250 | if(m_animator) | |
250 | { |
|
251 | { | |
251 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
252 | m_animator->setState(ChartAnimator::ZoomOutState); | |
252 | } |
|
253 | } | |
253 |
|
254 | |||
254 | QSizeF size = chartGeometry().size(); |
|
255 | QSizeF size = chartGeometry().size(); | |
255 | QRectF rect = chartGeometry(); |
|
256 | QRectF rect = chartGeometry(); | |
256 | rect.translate(-m_chartMargins.topLeft()); |
|
257 | rect.translate(-m_chartMargins.topLeft()); | |
257 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); |
|
258 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); | |
258 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
259 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
259 |
|
260 | |||
260 | if(m_animator){ |
|
261 | if(m_animator){ | |
261 | m_animator->setState(ChartAnimator::ShowState); |
|
262 | m_animator->setState(ChartAnimator::ShowState); | |
262 | } |
|
263 | } | |
263 | } |
|
264 | } | |
264 |
|
265 | |||
265 | void ChartPresenter::scroll(int dx,int dy) |
|
266 | void ChartPresenter::scroll(int dx,int dy) | |
266 | { |
|
267 | { | |
267 | if(m_animator){ |
|
268 | if(m_animator){ | |
268 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
269 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
269 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
270 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
270 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
271 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
271 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
272 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); |
|
275 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); | |
275 |
|
276 | |||
276 | if(m_animator){ |
|
277 | if(m_animator){ | |
277 | m_animator->setState(ChartAnimator::ShowState); |
|
278 | m_animator->setState(ChartAnimator::ShowState); | |
278 | } |
|
279 | } | |
279 | } |
|
280 | } | |
280 |
|
281 | |||
281 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
282 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
282 | { |
|
283 | { | |
283 | return m_options; |
|
284 | return m_options; | |
284 | } |
|
285 | } | |
285 |
|
286 | |||
286 | void ChartPresenter::updateLayout() |
|
287 | void ChartPresenter::updateLayout() | |
287 | { |
|
288 | { | |
288 | if (!m_rect.isValid()) return; |
|
289 | if (!m_rect.isValid()) return; | |
289 |
|
290 | |||
290 | // recalculate title size |
|
291 | // recalculate title size | |
291 |
|
292 | |||
292 | QSize titleSize; |
|
293 | QSize titleSize; | |
293 | int titlePadding=0; |
|
294 | int titlePadding=0; | |
294 |
|
295 | |||
295 | if (m_titleItem) { |
|
296 | if (m_titleItem) { | |
296 | titleSize= m_titleItem->boundingRect().size().toSize(); |
|
297 | titleSize= m_titleItem->boundingRect().size().toSize(); | |
297 | } |
|
298 | } | |
298 |
|
299 | |||
299 | //defaults |
|
300 | //defaults | |
300 | m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig)); |
|
301 | m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig)); | |
301 | titlePadding = m_chartMargins.top()/2; |
|
302 | titlePadding = m_chartMargins.top()/2; | |
302 |
|
303 | |||
303 | QLegend* legend = m_chart->d_ptr->m_legend; |
|
304 | QLegend* legend = m_chart->d_ptr->m_legend; | |
304 |
|
305 | |||
305 | // recalculate legend position |
|
306 | // recalculate legend position | |
306 | if (legend->isAttachedToChart() && legend->isEnabled()) { |
|
307 | if (legend->isAttachedToChart() && legend->isEnabled()) { | |
307 |
|
308 | |||
308 | QRect legendRect; |
|
309 | QRect legendRect; | |
309 |
|
310 | |||
310 | // Reserve some space for legend |
|
311 | // Reserve some space for legend | |
311 | switch (legend->alignment()) { |
|
312 | switch (legend->alignment()) { | |
312 |
|
313 | |||
313 | case QLegend::AlignmentTop: { |
|
314 | case QLegend::AlignmentTop: { | |
314 | int ledgendSize = legend->minHeight(); |
|
315 | int ledgendSize = legend->minHeight(); | |
315 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; |
|
316 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; | |
316 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
|
317 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |
317 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); |
|
318 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); | |
318 | titlePadding = m_marginTiny + m_marginTiny; |
|
319 | titlePadding = m_marginTiny + m_marginTiny; | |
319 | break; |
|
320 | break; | |
320 | } |
|
321 | } | |
321 | case QLegend::AlignmentBottom: { |
|
322 | case QLegend::AlignmentBottom: { | |
322 | int ledgendSize = legend->minHeight(); |
|
323 | int ledgendSize = legend->minHeight(); | |
323 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; |
|
324 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; | |
324 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); |
|
325 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); | |
325 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); |
|
326 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); | |
326 | titlePadding = m_chartMargins.top()/2; |
|
327 | titlePadding = m_chartMargins.top()/2; | |
327 | break; |
|
328 | break; | |
328 | } |
|
329 | } | |
329 | case QLegend::AlignmentLeft: { |
|
330 | case QLegend::AlignmentLeft: { | |
330 | int ledgendSize = legend->minWidth(); |
|
331 | int ledgendSize = legend->minWidth(); | |
331 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; |
|
332 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; | |
332 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
|
333 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |
333 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); |
|
334 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); | |
334 | titlePadding = m_chartMargins.top()/2; |
|
335 | titlePadding = m_chartMargins.top()/2; | |
335 | break; |
|
336 | break; | |
336 | } |
|
337 | } | |
337 | case QLegend::AlignmentRight: { |
|
338 | case QLegend::AlignmentRight: { | |
338 | int ledgendSize = legend->minWidth(); |
|
339 | int ledgendSize = legend->minWidth(); | |
339 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; |
|
340 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; | |
340 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); |
|
341 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); | |
341 | m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); |
|
342 | m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); | |
342 | titlePadding = m_chartMargins.top()/2; |
|
343 | titlePadding = m_chartMargins.top()/2; | |
343 | break; |
|
344 | break; | |
344 | } |
|
345 | } | |
345 | default: { |
|
346 | default: { | |
346 | break; |
|
347 | break; | |
347 | } |
|
348 | } | |
348 | } |
|
349 | } | |
349 | } |
|
350 | } | |
350 |
|
351 | |||
351 | if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom())) |
|
352 | if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom())) | |
352 | { |
|
353 | { | |
353 | m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom())); |
|
354 | m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom())); | |
354 | return; |
|
355 | return; | |
355 | } |
|
356 | } | |
356 |
|
357 | |||
357 |
|
358 | |||
358 | // recalculate title position |
|
359 | // recalculate title position | |
359 | if (m_titleItem) { |
|
360 | if (m_titleItem) { | |
360 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
361 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
361 | m_titleItem->setPos(center.x(),titlePadding); |
|
362 | m_titleItem->setPos(center.x(),titlePadding); | |
362 | } |
|
363 | } | |
363 |
|
364 | |||
364 | //recalculate background gradient |
|
365 | //recalculate background gradient | |
365 | if (m_backgroundItem) { |
|
366 | if (m_backgroundItem) { | |
366 | m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); |
|
367 | m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); | |
367 | } |
|
368 | } | |
368 |
|
369 | |||
369 |
|
370 | |||
370 | QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom()); |
|
371 | QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom()); | |
371 |
|
372 | |||
372 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); |
|
373 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); | |
373 |
|
374 | |||
374 | if(m_chartRect!=chartRect){ |
|
375 | if(m_chartRect!=chartRect){ | |
375 | m_chartRect=chartRect; |
|
376 | m_chartRect=chartRect; | |
376 | emit geometryChanged(m_chartRect); |
|
377 | emit geometryChanged(m_chartRect); | |
377 | } |
|
378 | } | |
378 |
|
379 | |||
379 |
|
380 | |||
380 | } |
|
381 | } | |
381 |
|
382 | |||
382 | void ChartPresenter::createChartBackgroundItem() |
|
383 | void ChartPresenter::createChartBackgroundItem() | |
383 | { |
|
384 | { | |
384 | if (!m_backgroundItem) { |
|
385 | if (!m_backgroundItem) { | |
385 | m_backgroundItem = new ChartBackground(rootItem()); |
|
386 | m_backgroundItem = new ChartBackground(rootItem()); | |
386 | m_backgroundItem->setPen(Qt::NoPen); |
|
387 | m_backgroundItem->setPen(Qt::NoPen); | |
387 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
388 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
388 | } |
|
389 | } | |
389 | } |
|
390 | } | |
390 |
|
391 | |||
391 | void ChartPresenter::createChartTitleItem() |
|
392 | void ChartPresenter::createChartTitleItem() | |
392 | { |
|
393 | { | |
393 | if (!m_titleItem) { |
|
394 | if (!m_titleItem) { | |
394 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); |
|
395 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); | |
395 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
396 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
396 | } |
|
397 | } | |
397 | } |
|
398 | } | |
398 |
|
399 | |||
399 | #include "moc_chartpresenter_p.cpp" |
|
400 | #include "moc_chartpresenter_p.cpp" | |
400 |
|
401 | |||
401 | QTCOMMERCIALCHART_END_NAMESPACE |
|
402 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,125 +1,124 | |||||
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 CHARTPRESENTER_H |
|
21 | #ifndef CHARTPRESENTER_H | |
22 | #define CHARTPRESENTER_H |
|
22 | #define CHARTPRESENTER_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "chartbackground_p.h" //TODO fix me |
|
|||
26 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
25 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
27 | #include "qchartaxis.h" |
|
|||
28 | #include <QRectF> |
|
26 | #include <QRectF> | |
29 |
|
27 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
29 | |||
32 | class Chart; |
|
30 | class Chart; | |
33 | class QAbstractSeries; |
|
31 | class QAbstractSeries; | |
34 | class ChartDataSet; |
|
32 | class ChartDataSet; | |
35 | class Domain; |
|
33 | class Domain; | |
36 | class Axis; |
|
34 | class ChartAxis; | |
37 | class ChartTheme; |
|
35 | class ChartTheme; | |
38 | class ChartAnimator; |
|
36 | class ChartAnimator; | |
|
37 | class ChartBackground; | |||
39 |
|
38 | |||
40 | class ChartPresenter: public QObject |
|
39 | class ChartPresenter: public QObject | |
41 | { |
|
40 | { | |
42 | Q_OBJECT |
|
41 | Q_OBJECT | |
43 | public: |
|
42 | public: | |
44 | enum ZValues { |
|
43 | enum ZValues { | |
45 | BackgroundZValue = -1, |
|
44 | BackgroundZValue = -1, | |
46 | ShadesZValue, |
|
45 | ShadesZValue, | |
47 | GridZValue, |
|
46 | GridZValue, | |
48 | LineChartZValue, |
|
47 | LineChartZValue, | |
49 | BarSeriesZValue, |
|
48 | BarSeriesZValue, | |
50 | ScatterSeriesZValue, |
|
49 | ScatterSeriesZValue, | |
51 | PieSeriesZValue, |
|
50 | PieSeriesZValue, | |
52 | AxisZValue, |
|
51 | AxisZValue, | |
53 | LegendZValue |
|
52 | LegendZValue | |
54 | }; |
|
53 | }; | |
55 |
|
54 | |||
56 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
55 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
57 | virtual ~ChartPresenter(); |
|
56 | virtual ~ChartPresenter(); | |
58 |
|
57 | |||
59 | ChartAnimator* animator() const { return m_animator; } |
|
58 | ChartAnimator* animator() const { return m_animator; } | |
60 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
59 | ChartTheme *chartTheme() const { return m_chartTheme; } | |
61 | ChartDataSet *dataSet() const { return m_dataset; } |
|
60 | ChartDataSet *dataSet() const { return m_dataset; } | |
62 | QGraphicsItem* rootItem() const { return m_chart; } |
|
61 | QGraphicsItem* rootItem() const { return m_chart; } | |
63 |
|
62 | |||
64 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
63 | void setTheme(QChart::ChartTheme theme,bool force = true); | |
65 | QChart::ChartTheme theme(); |
|
64 | QChart::ChartTheme theme(); | |
66 |
|
65 | |||
67 | void setAnimationOptions(QChart::AnimationOptions options); |
|
66 | void setAnimationOptions(QChart::AnimationOptions options); | |
68 | QChart::AnimationOptions animationOptions() const; |
|
67 | QChart::AnimationOptions animationOptions() const; | |
69 |
|
68 | |||
70 | void zoomIn(); |
|
69 | void zoomIn(); | |
71 | void zoomIn(const QRectF& rect); |
|
70 | void zoomIn(const QRectF& rect); | |
72 | void zoomOut(); |
|
71 | void zoomOut(); | |
73 | void scroll(int dx,int dy); |
|
72 | void scroll(int dx,int dy); | |
74 |
|
73 | |||
75 | void setGeometry(const QRectF& rect); |
|
74 | void setGeometry(const QRectF& rect); | |
76 | QRectF chartGeometry() const { return m_chartRect; } |
|
75 | QRectF chartGeometry() const { return m_chartRect; } | |
77 |
|
76 | |||
78 | void setMinimumMarginHeight(Axis* axis, qreal height); |
|
77 | void setMinimumMarginHeight(ChartAxis* axis, qreal height); | |
79 | void setMinimumMarginWidth(Axis* axis, qreal width); |
|
78 | void setMinimumMarginWidth(ChartAxis* axis, qreal width); | |
80 | qreal minimumLeftMargin() const { return m_minLeftMargin; } |
|
79 | qreal minimumLeftMargin() const { return m_minLeftMargin; } | |
81 | qreal minimumBottomMargin() const { return m_minBottomMargin; } |
|
80 | qreal minimumBottomMargin() const { return m_minBottomMargin; } | |
82 |
|
81 | |||
83 | public: //TODO: fix me |
|
82 | public: //TODO: fix me | |
84 | void resetAllElements(); |
|
83 | void resetAllElements(); | |
85 | void createChartBackgroundItem(); |
|
84 | void createChartBackgroundItem(); | |
86 | void createChartTitleItem(); |
|
85 | void createChartTitleItem(); | |
87 | QRectF margins() const { return m_chartMargins;} |
|
86 | QRectF margins() const { return m_chartMargins;} | |
88 |
|
87 | |||
89 | public Q_SLOTS: |
|
88 | public Q_SLOTS: | |
90 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); |
|
89 | void handleSeriesAdded(QAbstractSeries* series,Domain* domain); | |
91 | void handleSeriesRemoved(QAbstractSeries* series); |
|
90 | void handleSeriesRemoved(QAbstractSeries* series); | |
92 |
void handleAxisAdded(Q |
|
91 | void handleAxisAdded(QAxis* axis,Domain* domain); | |
93 |
void handleAxisRemoved(Q |
|
92 | void handleAxisRemoved(QAxis* axis); | |
94 | void updateLayout(); |
|
93 | void updateLayout(); | |
95 |
|
94 | |||
96 | Q_SIGNALS: |
|
95 | Q_SIGNALS: | |
97 | void geometryChanged(const QRectF& rect); |
|
96 | void geometryChanged(const QRectF& rect); | |
98 |
|
97 | |||
99 |
|
98 | |||
100 | private: |
|
99 | private: | |
101 | QChart* m_chart; |
|
100 | QChart* m_chart; | |
102 | ChartAnimator* m_animator; |
|
101 | ChartAnimator* m_animator; | |
103 | ChartDataSet* m_dataset; |
|
102 | ChartDataSet* m_dataset; | |
104 | ChartTheme *m_chartTheme; |
|
103 | ChartTheme *m_chartTheme; | |
105 | QMap<QAbstractSeries *, Chart *> m_chartItems; |
|
104 | QMap<QAbstractSeries *, Chart *> m_chartItems; | |
106 |
QMap<Q |
|
105 | QMap<QAxis *, ChartAxis *> m_axisItems; | |
107 | QRectF m_rect; |
|
106 | QRectF m_rect; | |
108 | QRectF m_chartRect; |
|
107 | QRectF m_chartRect; | |
109 | QChart::AnimationOptions m_options; |
|
108 | QChart::AnimationOptions m_options; | |
110 | qreal m_minLeftMargin; |
|
109 | qreal m_minLeftMargin; | |
111 | qreal m_minBottomMargin; |
|
110 | qreal m_minBottomMargin; | |
112 | public: //TODO: fixme |
|
111 | public: //TODO: fixme | |
113 | ChartBackground* m_backgroundItem; |
|
112 | ChartBackground* m_backgroundItem; | |
114 | QGraphicsSimpleTextItem* m_titleItem; |
|
113 | QGraphicsSimpleTextItem* m_titleItem; | |
115 | int m_marginBig; |
|
114 | int m_marginBig; | |
116 | int m_marginSmall; |
|
115 | int m_marginSmall; | |
117 | int m_marginTiny; |
|
116 | int m_marginTiny; | |
118 | QRectF m_chartMargins; |
|
117 | QRectF m_chartMargins; | |
119 | QRectF m_legendMargins; |
|
118 | QRectF m_legendMargins; | |
120 |
|
119 | |||
121 | }; |
|
120 | }; | |
122 |
|
121 | |||
123 | QTCOMMERCIALCHART_END_NAMESPACE |
|
122 | QTCOMMERCIALCHART_END_NAMESPACE | |
124 |
|
123 | |||
125 | #endif /* CHARTPRESENTER_H_ */ |
|
124 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,400 +1,400 | |||||
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 "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qchartview.h" |
|
24 | #include "qchartview.h" | |
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 |
#include "q |
|
26 | #include "qaxis.h" | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 |
|
28 | |||
29 | //series |
|
29 | //series | |
30 | #include "qbarset.h" |
|
30 | #include "qbarset.h" | |
31 | #include "qbarseries.h" |
|
31 | #include "qbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
32 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
33 | #include "qpercentbarseries.h" | |
34 | #include "qlineseries.h" |
|
34 | #include "qlineseries.h" | |
35 | #include "qareaseries.h" |
|
35 | #include "qareaseries.h" | |
36 | #include "qscatterseries.h" |
|
36 | #include "qscatterseries.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "qsplineseries.h" |
|
39 | #include "qsplineseries.h" | |
40 |
|
40 | |||
41 | //items |
|
41 | //items | |
42 | #include "axis_p.h" |
|
42 | #include "chartaxis_p.h" | |
43 | #include "barchartitem_p.h" |
|
43 | #include "barchartitem_p.h" | |
44 | #include "stackedbarchartitem_p.h" |
|
44 | #include "stackedbarchartitem_p.h" | |
45 | #include "percentbarchartitem_p.h" |
|
45 | #include "percentbarchartitem_p.h" | |
46 | #include "linechartitem_p.h" |
|
46 | #include "linechartitem_p.h" | |
47 | #include "areachartitem_p.h" |
|
47 | #include "areachartitem_p.h" | |
48 | #include "scatterchartitem_p.h" |
|
48 | #include "scatterchartitem_p.h" | |
49 | #include "piechartitem_p.h" |
|
49 | #include "piechartitem_p.h" | |
50 | #include "splinechartitem_p.h" |
|
50 | #include "splinechartitem_p.h" | |
51 |
|
51 | |||
52 | //themes |
|
52 | //themes | |
53 | #include "chartthemesystem_p.h" |
|
53 | #include "chartthemesystem_p.h" | |
54 | #include "chartthemelight_p.h" |
|
54 | #include "chartthemelight_p.h" | |
55 | #include "chartthemebluecerulean_p.h" |
|
55 | #include "chartthemebluecerulean_p.h" | |
56 | #include "chartthemedark_p.h" |
|
56 | #include "chartthemedark_p.h" | |
57 | #include "chartthemebrownsand_p.h" |
|
57 | #include "chartthemebrownsand_p.h" | |
58 | #include "chartthemebluencs_p.h" |
|
58 | #include "chartthemebluencs_p.h" | |
59 | #include "chartthemehighcontrast_p.h" |
|
59 | #include "chartthemehighcontrast_p.h" | |
60 | #include "chartthemeblueicy_p.h" |
|
60 | #include "chartthemeblueicy_p.h" | |
61 |
|
61 | |||
62 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
62 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
63 |
|
63 | |||
64 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
64 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
65 | m_masterFont(QFont("arial", 14)), |
|
65 | m_masterFont(QFont("arial", 14)), | |
66 | m_labelFont(QFont("arial", 10)), |
|
66 | m_labelFont(QFont("arial", 10)), | |
67 | m_titleBrush(QColor(QRgb(0x000000))), |
|
67 | m_titleBrush(QColor(QRgb(0x000000))), | |
68 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
68 | m_axisLinePen(QPen(QRgb(0x000000))), | |
69 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
69 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
70 | m_backgroundShadesPen(Qt::NoPen), |
|
70 | m_backgroundShadesPen(Qt::NoPen), | |
71 | m_backgroundShadesBrush(Qt::NoBrush), |
|
71 | m_backgroundShadesBrush(Qt::NoBrush), | |
72 | m_backgroundShades(BackgroundShadesNone), |
|
72 | m_backgroundShades(BackgroundShadesNone), | |
73 | m_backgroundDropShadowEnabled(false), |
|
73 | m_backgroundDropShadowEnabled(false), | |
74 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
74 | m_gridLinePen(QPen(QRgb(0x000000))), | |
75 | m_force(false) |
|
75 | m_force(false) | |
76 | { |
|
76 | { | |
77 | m_id = id; |
|
77 | m_id = id; | |
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
83 | { |
|
83 | { | |
84 | switch(theme) { |
|
84 | switch(theme) { | |
85 | case QChart::ChartThemeLight: |
|
85 | case QChart::ChartThemeLight: | |
86 | return new ChartThemeLight(); |
|
86 | return new ChartThemeLight(); | |
87 | case QChart::ChartThemeBlueCerulean: |
|
87 | case QChart::ChartThemeBlueCerulean: | |
88 | return new ChartThemeBlueCerulean(); |
|
88 | return new ChartThemeBlueCerulean(); | |
89 | case QChart::ChartThemeDark: |
|
89 | case QChart::ChartThemeDark: | |
90 | return new ChartThemeDark(); |
|
90 | return new ChartThemeDark(); | |
91 | case QChart::ChartThemeBrownSand: |
|
91 | case QChart::ChartThemeBrownSand: | |
92 | return new ChartThemeBrownSand(); |
|
92 | return new ChartThemeBrownSand(); | |
93 | case QChart::ChartThemeBlueNcs: |
|
93 | case QChart::ChartThemeBlueNcs: | |
94 | return new ChartThemeBlueNcs(); |
|
94 | return new ChartThemeBlueNcs(); | |
95 | case QChart::ChartThemeHighContrast: |
|
95 | case QChart::ChartThemeHighContrast: | |
96 | return new ChartThemeHighContrast(); |
|
96 | return new ChartThemeHighContrast(); | |
97 | case QChart::ChartThemeBlueIcy: |
|
97 | case QChart::ChartThemeBlueIcy: | |
98 | return new ChartThemeBlueIcy(); |
|
98 | return new ChartThemeBlueIcy(); | |
99 | default: |
|
99 | default: | |
100 | return new ChartThemeSystem(); |
|
100 | return new ChartThemeSystem(); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartTheme::decorate(QChart *chart) |
|
104 | void ChartTheme::decorate(QChart *chart) | |
105 | { |
|
105 | { | |
106 | QBrush brush; |
|
106 | QBrush brush; | |
107 |
|
107 | |||
108 | if(brush == chart->backgroundBrush() || m_force) |
|
108 | if(brush == chart->backgroundBrush() || m_force) | |
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
110 | chart->setTitleFont(m_masterFont); |
|
110 | chart->setTitleFont(m_masterFont); | |
111 | chart->setTitleBrush(m_titleBrush); |
|
111 | chart->setTitleBrush(m_titleBrush); | |
112 | chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
112 | chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void ChartTheme::decorate(QLegend *legend) |
|
115 | void ChartTheme::decorate(QLegend *legend) | |
116 | { |
|
116 | { | |
117 | QPen pen; |
|
117 | QPen pen; | |
118 | QBrush brush; |
|
118 | QBrush brush; | |
119 |
|
119 | |||
120 | if (pen == legend->pen() || m_force){ |
|
120 | if (pen == legend->pen() || m_force){ | |
121 | legend->setPen(Qt::NoPen); |
|
121 | legend->setPen(Qt::NoPen); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | if (brush == legend->brush() || m_force) { |
|
124 | if (brush == legend->brush() || m_force) { | |
125 | legend->setBrush(m_chartBackgroundGradient); |
|
125 | legend->setBrush(m_chartBackgroundGradient); | |
126 | } |
|
126 | } | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
129 | void ChartTheme::decorate(QAreaSeries *series, int index) | |
130 | { |
|
130 | { | |
131 | QPen pen; |
|
131 | QPen pen; | |
132 | QBrush brush; |
|
132 | QBrush brush; | |
133 |
|
133 | |||
134 | if (pen == series->pen() || m_force){ |
|
134 | if (pen == series->pen() || m_force){ | |
135 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
135 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
136 | pen.setWidthF(2); |
|
136 | pen.setWidthF(2); | |
137 | series->setPen(pen); |
|
137 | series->setPen(pen); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | if (brush == series->brush() || m_force) { |
|
140 | if (brush == series->brush() || m_force) { | |
141 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
141 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
142 | series->setBrush(brush); |
|
142 | series->setBrush(brush); | |
143 | } |
|
143 | } | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | void ChartTheme::decorate(QLineSeries *series,int index) |
|
147 | void ChartTheme::decorate(QLineSeries *series,int index) | |
148 | { |
|
148 | { | |
149 | QPen pen; |
|
149 | QPen pen; | |
150 | if(pen == series->pen() || m_force ){ |
|
150 | if(pen == series->pen() || m_force ){ | |
151 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
151 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
152 | pen.setWidthF(2); |
|
152 | pen.setWidthF(2); | |
153 | series->setPen(pen); |
|
153 | series->setPen(pen); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void ChartTheme::decorate(QBarSeries *series, int index) |
|
157 | void ChartTheme::decorate(QBarSeries *series, int index) | |
158 | { |
|
158 | { | |
159 | QBrush brush; |
|
159 | QBrush brush; | |
160 | QPen pen; |
|
160 | QPen pen; | |
161 | QList<QBarSet *> sets = series->barSets(); |
|
161 | QList<QBarSet *> sets = series->barSets(); | |
162 |
|
162 | |||
163 | qreal takeAtPos = 0.5; |
|
163 | qreal takeAtPos = 0.5; | |
164 | qreal step = 0.2; |
|
164 | qreal step = 0.2; | |
165 | if (sets.count() > 1 ) { |
|
165 | if (sets.count() > 1 ) { | |
166 | step = 1.0 / (qreal) sets.count(); |
|
166 | step = 1.0 / (qreal) sets.count(); | |
167 | if (sets.count() % m_seriesGradients.count()) |
|
167 | if (sets.count() % m_seriesGradients.count()) | |
168 | step *= m_seriesGradients.count(); |
|
168 | step *= m_seriesGradients.count(); | |
169 | else |
|
169 | else | |
170 | step *= (m_seriesGradients.count() - 1); |
|
170 | step *= (m_seriesGradients.count() - 1); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | for (int i(0); i < sets.count(); i++) { |
|
173 | for (int i(0); i < sets.count(); i++) { | |
174 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
174 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
175 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
175 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
176 | // There is no dedicated base color for each sets, generate more colors |
|
176 | // There is no dedicated base color for each sets, generate more colors | |
177 | takeAtPos += step; |
|
177 | takeAtPos += step; | |
178 | if (takeAtPos == 1.0) |
|
178 | if (takeAtPos == 1.0) | |
179 | takeAtPos += step; |
|
179 | takeAtPos += step; | |
180 | takeAtPos -= (int) takeAtPos; |
|
180 | takeAtPos -= (int) takeAtPos; | |
181 | } |
|
181 | } | |
182 | if (brush == sets.at(i)->brush() || m_force ) |
|
182 | if (brush == sets.at(i)->brush() || m_force ) | |
183 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
183 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
184 |
|
184 | |||
185 | // Pick label color from the opposite end of the gradient. |
|
185 | // Pick label color from the opposite end of the gradient. | |
186 | // 0.3 as a boundary seems to work well. |
|
186 | // 0.3 as a boundary seems to work well. | |
187 | if (takeAtPos < 0.3) |
|
187 | if (takeAtPos < 0.3) | |
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
189 | else |
|
189 | else | |
190 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
190 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
191 |
|
191 | |||
192 | if (pen == sets.at(i)->pen() || m_force) { |
|
192 | if (pen == sets.at(i)->pen() || m_force) { | |
193 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
193 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
194 | sets.at(i)->setPen(c); |
|
194 | sets.at(i)->setPen(c); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
199 | void ChartTheme::decorate(QScatterSeries *series, int index) | |
200 | { |
|
200 | { | |
201 | QPen pen; |
|
201 | QPen pen; | |
202 | QBrush brush; |
|
202 | QBrush brush; | |
203 |
|
203 | |||
204 | if (pen == series->pen() || m_force) { |
|
204 | if (pen == series->pen() || m_force) { | |
205 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
205 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
206 | pen.setWidthF(2); |
|
206 | pen.setWidthF(2); | |
207 | series->setPen(pen); |
|
207 | series->setPen(pen); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | if (brush == series->brush() || m_force) { |
|
210 | if (brush == series->brush() || m_force) { | |
211 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
211 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
212 | series->setBrush(brush); |
|
212 | series->setBrush(brush); | |
213 | } |
|
213 | } | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
216 | void ChartTheme::decorate(QPieSeries *series, int index) | |
217 | { |
|
217 | { | |
218 |
|
218 | |||
219 | for (int i(0); i < series->slices().count(); i++) { |
|
219 | for (int i(0); i < series->slices().count(); i++) { | |
220 |
|
220 | |||
221 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
221 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
222 |
|
222 | |||
223 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
223 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
224 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
224 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
225 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
225 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
226 |
|
226 | |||
227 | QPieSlice *s = series->slices().at(i); |
|
227 | QPieSlice *s = series->slices().at(i); | |
228 | PieSliceData data = PieSliceData::data(s); |
|
228 | PieSliceData data = PieSliceData::data(s); | |
229 |
|
229 | |||
230 | if (data.m_slicePen.isThemed() || m_force) { |
|
230 | if (data.m_slicePen.isThemed() || m_force) { | |
231 | data.m_slicePen = penColor; |
|
231 | data.m_slicePen = penColor; | |
232 | data.m_slicePen.setThemed(true); |
|
232 | data.m_slicePen.setThemed(true); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | if (data.m_sliceBrush.isThemed() || m_force) { |
|
235 | if (data.m_sliceBrush.isThemed() || m_force) { | |
236 | data.m_sliceBrush = brushColor; |
|
236 | data.m_sliceBrush = brushColor; | |
237 | data.m_sliceBrush.setThemed(true); |
|
237 | data.m_sliceBrush.setThemed(true); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | if (data.m_labelPen.isThemed() || m_force) { |
|
240 | if (data.m_labelPen.isThemed() || m_force) { | |
241 | data.m_labelPen = QPen(m_titleBrush.color()); |
|
241 | data.m_labelPen = QPen(m_titleBrush.color()); | |
242 | data.m_labelPen.setThemed(true); |
|
242 | data.m_labelPen.setThemed(true); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | if (data.m_labelFont.isThemed() || m_force) { |
|
245 | if (data.m_labelFont.isThemed() || m_force) { | |
246 | data.m_labelFont = m_labelFont; |
|
246 | data.m_labelFont = m_labelFont; | |
247 | data.m_labelFont.setThemed(true); |
|
247 | data.m_labelFont.setThemed(true); | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | if (PieSliceData::data(s) != data) { |
|
250 | if (PieSliceData::data(s) != data) { | |
251 | PieSliceData::data(s) = data; |
|
251 | PieSliceData::data(s) = data; | |
252 | emit PieSliceData::data(s).emitChangedSignal(s); |
|
252 | emit PieSliceData::data(s).emitChangedSignal(s); | |
253 | } |
|
253 | } | |
254 | } |
|
254 | } | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
257 | void ChartTheme::decorate(QSplineSeries *series, int index) | |
258 | { |
|
258 | { | |
259 | QPen pen; |
|
259 | QPen pen; | |
260 | if(pen == series->pen() || m_force){ |
|
260 | if(pen == series->pen() || m_force){ | |
261 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
261 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
262 | pen.setWidthF(2); |
|
262 | pen.setWidthF(2); | |
263 | series->setPen(pen); |
|
263 | series->setPen(pen); | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 |
void ChartTheme::decorate(Q |
|
267 | void ChartTheme::decorate(QAxis *axis,bool axisX) | |
268 | { |
|
268 | { | |
269 | QPen pen; |
|
269 | QPen pen; | |
270 | QBrush brush; |
|
270 | QBrush brush; | |
271 | QFont font; |
|
271 | QFont font; | |
272 |
|
272 | |||
273 | if (axis->isAxisVisible()) { |
|
273 | if (axis->isAxisVisible()) { | |
274 |
|
274 | |||
275 | if(brush == axis->labelsBrush() || m_force){ |
|
275 | if(brush == axis->labelsBrush() || m_force){ | |
276 | axis->setLabelsBrush(m_axisLabelBrush); |
|
276 | axis->setLabelsBrush(m_axisLabelBrush); | |
277 | } |
|
277 | } | |
278 | if(pen == axis->labelsPen() || m_force){ |
|
278 | if(pen == axis->labelsPen() || m_force){ | |
279 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
279 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 |
|
282 | |||
283 | if (axis->shadesVisible() || m_force) { |
|
283 | if (axis->shadesVisible() || m_force) { | |
284 |
|
284 | |||
285 | if(brush == axis->shadesBrush() || m_force){ |
|
285 | if(brush == axis->shadesBrush() || m_force){ | |
286 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
286 | axis->setShadesBrush(m_backgroundShadesBrush); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | if(pen == axis->shadesPen() || m_force){ |
|
289 | if(pen == axis->shadesPen() || m_force){ | |
290 | axis->setShadesPen(m_backgroundShadesPen); |
|
290 | axis->setShadesPen(m_backgroundShadesPen); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | if( m_force && (m_backgroundShades == BackgroundShadesBoth |
|
293 | if( m_force && (m_backgroundShades == BackgroundShadesBoth | |
294 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
294 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
295 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
295 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
296 | axis->setShadesVisible(true); |
|
296 | axis->setShadesVisible(true); | |
297 |
|
297 | |||
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | if(pen == axis->axisPen() || m_force){ |
|
301 | if(pen == axis->axisPen() || m_force){ | |
302 | axis->setAxisPen(m_axisLinePen); |
|
302 | axis->setAxisPen(m_axisLinePen); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | if(pen == axis->gridLinePen() || m_force){ |
|
305 | if(pen == axis->gridLinePen() || m_force){ | |
306 | axis->setGridLinePen(m_gridLinePen); |
|
306 | axis->setGridLinePen(m_gridLinePen); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | if(font == axis->labelsFont() || m_force){ |
|
309 | if(font == axis->labelsFont() || m_force){ | |
310 | axis->setLabelsFont(m_labelFont); |
|
310 | axis->setLabelsFont(m_labelFont); | |
311 | } |
|
311 | } | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void ChartTheme::generateSeriesGradients() |
|
315 | void ChartTheme::generateSeriesGradients() | |
316 | { |
|
316 | { | |
317 | // Generate gradients in HSV color space |
|
317 | // Generate gradients in HSV color space | |
318 | foreach (const QColor& color, m_seriesColors) { |
|
318 | foreach (const QColor& color, m_seriesColors) { | |
319 | QLinearGradient g; |
|
319 | QLinearGradient g; | |
320 | qreal h = color.hsvHueF(); |
|
320 | qreal h = color.hsvHueF(); | |
321 | qreal s = color.hsvSaturationF(); |
|
321 | qreal s = color.hsvSaturationF(); | |
322 |
|
322 | |||
323 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
323 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
324 | // most themes. The rest of the gradients we can define manually in theme specific |
|
324 | // most themes. The rest of the gradients we can define manually in theme specific | |
325 | // implementation. |
|
325 | // implementation. | |
326 | QColor start = color; |
|
326 | QColor start = color; | |
327 | start.setHsvF(h, 0.0, 1.0); |
|
327 | start.setHsvF(h, 0.0, 1.0); | |
328 | g.setColorAt(0.0, start); |
|
328 | g.setColorAt(0.0, start); | |
329 |
|
329 | |||
330 | g.setColorAt(0.5, color); |
|
330 | g.setColorAt(0.5, color); | |
331 |
|
331 | |||
332 | QColor end = color; |
|
332 | QColor end = color; | |
333 | end.setHsvF(h, s, 0.25); |
|
333 | end.setHsvF(h, s, 0.25); | |
334 | g.setColorAt(1.0, end); |
|
334 | g.setColorAt(1.0, end); | |
335 |
|
335 | |||
336 | m_seriesGradients << g; |
|
336 | m_seriesGradients << g; | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 |
|
340 | |||
341 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
341 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
342 | { |
|
342 | { | |
343 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
343 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
344 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
344 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
345 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
345 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
346 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
346 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
347 | QColor c; |
|
347 | QColor c; | |
348 | c.setRgbF(r, g, b); |
|
348 | c.setRgbF(r, g, b); | |
349 | return c; |
|
349 | return c; | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
352 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
353 | { |
|
353 | { | |
354 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
354 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
355 |
|
355 | |||
356 | // another possibility: |
|
356 | // another possibility: | |
357 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
357 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
358 |
|
358 | |||
359 | QGradientStops stops = gradient.stops(); |
|
359 | QGradientStops stops = gradient.stops(); | |
360 | int count = stops.count(); |
|
360 | int count = stops.count(); | |
361 |
|
361 | |||
362 | // find previous stop relative to position |
|
362 | // find previous stop relative to position | |
363 | QGradientStop prev = stops.first(); |
|
363 | QGradientStop prev = stops.first(); | |
364 | for (int i = 0; i < count; i++) { |
|
364 | for (int i = 0; i < count; i++) { | |
365 | QGradientStop stop = stops.at(i); |
|
365 | QGradientStop stop = stops.at(i); | |
366 | if (pos > stop.first) |
|
366 | if (pos > stop.first) | |
367 | prev = stop; |
|
367 | prev = stop; | |
368 |
|
368 | |||
369 | // given position is actually a stop position? |
|
369 | // given position is actually a stop position? | |
370 | if (pos == stop.first) { |
|
370 | if (pos == stop.first) { | |
371 | //qDebug() << "stop color" << pos; |
|
371 | //qDebug() << "stop color" << pos; | |
372 | return stop.second; |
|
372 | return stop.second; | |
373 | } |
|
373 | } | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | // find next stop relative to position |
|
376 | // find next stop relative to position | |
377 | QGradientStop next = stops.last(); |
|
377 | QGradientStop next = stops.last(); | |
378 | for (int i = count - 1; i >= 0; i--) { |
|
378 | for (int i = count - 1; i >= 0; i--) { | |
379 | QGradientStop stop = stops.at(i); |
|
379 | QGradientStop stop = stops.at(i); | |
380 | if (pos < stop.first) |
|
380 | if (pos < stop.first) | |
381 | next = stop; |
|
381 | next = stop; | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
384 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
385 |
|
385 | |||
386 | qreal range = next.first - prev.first; |
|
386 | qreal range = next.first - prev.first; | |
387 | qreal posDelta = pos - prev.first; |
|
387 | qreal posDelta = pos - prev.first; | |
388 | qreal relativePos = posDelta / range; |
|
388 | qreal relativePos = posDelta / range; | |
389 |
|
389 | |||
390 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
390 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
391 |
|
391 | |||
392 | return colorAt(prev.second, next.second, relativePos); |
|
392 | return colorAt(prev.second, next.second, relativePos); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | void ChartTheme::setForced(bool enabled) |
|
395 | void ChartTheme::setForced(bool enabled) | |
396 | { |
|
396 | { | |
397 | m_force=enabled; |
|
397 | m_force=enabled; | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | QTCOMMERCIALCHART_END_NAMESPACE |
|
400 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,102 +1,102 | |||||
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 CHARTTHEME_H |
|
21 | #ifndef CHARTTHEME_H | |
22 | #define CHARTTHEME_H |
|
22 | #define CHARTTHEME_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include <QColor> |
|
26 | #include <QColor> | |
27 | #include <QGradientStops> |
|
27 | #include <QGradientStops> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class ChartItem; |
|
31 | class ChartItem; | |
32 | class LineChartItem; |
|
32 | class LineChartItem; | |
33 | class QLineSeries; |
|
33 | class QLineSeries; | |
34 | class BarChartItem; |
|
34 | class BarChartItem; | |
35 | class QBarSeries; |
|
35 | class QBarSeries; | |
36 | class StackedBarChartItem; |
|
36 | class StackedBarChartItem; | |
37 | class QStackedBarSeries; |
|
37 | class QStackedBarSeries; | |
38 | class QPercentBarSeries; |
|
38 | class QPercentBarSeries; | |
39 | class PercentBarChartItem; |
|
39 | class PercentBarChartItem; | |
40 | class QScatterSeries; |
|
40 | class QScatterSeries; | |
41 | class ScatterChartItem; |
|
41 | class ScatterChartItem; | |
42 | class PieChartItem; |
|
42 | class PieChartItem; | |
43 | class QPieSeries; |
|
43 | class QPieSeries; | |
44 | class SplineChartItem; |
|
44 | class SplineChartItem; | |
45 | class QSplineSeries; |
|
45 | class QSplineSeries; | |
46 | class AreaChartItem; |
|
46 | class AreaChartItem; | |
47 | class QAreaSeries; |
|
47 | class QAreaSeries; | |
48 |
|
48 | |||
49 | class ChartTheme |
|
49 | class ChartTheme | |
50 | { |
|
50 | { | |
51 | public: |
|
51 | public: | |
52 | enum BackgroundShadesMode { |
|
52 | enum BackgroundShadesMode { | |
53 | BackgroundShadesNone = 0, |
|
53 | BackgroundShadesNone = 0, | |
54 | BackgroundShadesVertical, |
|
54 | BackgroundShadesVertical, | |
55 | BackgroundShadesHorizontal, |
|
55 | BackgroundShadesHorizontal, | |
56 | BackgroundShadesBoth |
|
56 | BackgroundShadesBoth | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | protected: |
|
59 | protected: | |
60 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight); |
|
60 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight); | |
61 | public: |
|
61 | public: | |
62 | static ChartTheme *createTheme(QChart::ChartTheme theme); |
|
62 | static ChartTheme *createTheme(QChart::ChartTheme theme); | |
63 | QChart::ChartTheme id() const {return m_id;} |
|
63 | QChart::ChartTheme id() const {return m_id;} | |
64 | void decorate(QChart *chart); |
|
64 | void decorate(QChart *chart); | |
65 | void decorate(QLegend *legend); |
|
65 | void decorate(QLegend *legend); | |
66 | void decorate(QBarSeries *series, int index); |
|
66 | void decorate(QBarSeries *series, int index); | |
67 | void decorate(QLineSeries *series, int index); |
|
67 | void decorate(QLineSeries *series, int index); | |
68 | void decorate(QAreaSeries *series, int index); |
|
68 | void decorate(QAreaSeries *series, int index); | |
69 | void decorate(QScatterSeries *series, int index); |
|
69 | void decorate(QScatterSeries *series, int index); | |
70 | void decorate(QPieSeries *series, int index); |
|
70 | void decorate(QPieSeries *series, int index); | |
71 | void decorate(QSplineSeries *series, int index); |
|
71 | void decorate(QSplineSeries *series, int index); | |
72 |
void decorate(Q |
|
72 | void decorate(QAxis *axis, bool axisX); | |
73 | void setForced(bool enabled); |
|
73 | void setForced(bool enabled); | |
74 | bool isForced() { return m_force; } |
|
74 | bool isForced() { return m_force; } | |
75 |
|
75 | |||
76 | public: // utils |
|
76 | public: // utils | |
77 | void generateSeriesGradients(); |
|
77 | void generateSeriesGradients(); | |
78 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
78 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); | |
79 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
79 | static QColor colorAt(const QGradient &gradient, qreal pos); | |
80 |
|
80 | |||
81 | protected: |
|
81 | protected: | |
82 | QChart::ChartTheme m_id; |
|
82 | QChart::ChartTheme m_id; | |
83 | QList<QColor> m_seriesColors; |
|
83 | QList<QColor> m_seriesColors; | |
84 | QList<QGradient> m_seriesGradients; |
|
84 | QList<QGradient> m_seriesGradients; | |
85 | QLinearGradient m_chartBackgroundGradient; |
|
85 | QLinearGradient m_chartBackgroundGradient; | |
86 |
|
86 | |||
87 | QFont m_masterFont; |
|
87 | QFont m_masterFont; | |
88 | QFont m_labelFont; |
|
88 | QFont m_labelFont; | |
89 | QBrush m_titleBrush; |
|
89 | QBrush m_titleBrush; | |
90 | QPen m_axisLinePen; |
|
90 | QPen m_axisLinePen; | |
91 | QBrush m_axisLabelBrush; |
|
91 | QBrush m_axisLabelBrush; | |
92 | QPen m_backgroundShadesPen; |
|
92 | QPen m_backgroundShadesPen; | |
93 | QBrush m_backgroundShadesBrush; |
|
93 | QBrush m_backgroundShadesBrush; | |
94 | BackgroundShadesMode m_backgroundShades; |
|
94 | BackgroundShadesMode m_backgroundShades; | |
95 | bool m_backgroundDropShadowEnabled; |
|
95 | bool m_backgroundDropShadowEnabled; | |
96 | QPen m_gridLinePen; |
|
96 | QPen m_gridLinePen; | |
97 | bool m_force; |
|
97 | bool m_force; | |
98 | }; |
|
98 | }; | |
99 |
|
99 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE | |
101 |
|
101 | |||
102 | #endif // CHARTTHEME_H |
|
102 | #endif // CHARTTHEME_H |
@@ -1,434 +1,436 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
|
25 | #include "chartbackground_p.h" | |||
|
26 | #include "qaxis.h" | |||
25 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
26 | #include <QGraphicsSceneResizeEvent> |
|
28 | #include <QGraphicsSceneResizeEvent> | |
27 |
|
29 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
31 | |||
30 | /*! |
|
32 | /*! | |
31 | \enum QChart::ChartTheme |
|
33 | \enum QChart::ChartTheme | |
32 |
|
34 | |||
33 | This enum describes the theme used by the chart. |
|
35 | This enum describes the theme used by the chart. | |
34 |
|
36 | |||
35 | \value ChartThemeLight The default theme |
|
37 | \value ChartThemeLight The default theme | |
36 | \value ChartThemeBlueCerulean |
|
38 | \value ChartThemeBlueCerulean | |
37 | \value ChartThemeDark |
|
39 | \value ChartThemeDark | |
38 | \value ChartThemeBrownSand |
|
40 | \value ChartThemeBrownSand | |
39 | \value ChartThemeBlueNcs |
|
41 | \value ChartThemeBlueNcs | |
40 | \value ChartThemeHighContrast |
|
42 | \value ChartThemeHighContrast | |
41 | \value ChartThemeBlueIcy |
|
43 | \value ChartThemeBlueIcy | |
42 | */ |
|
44 | */ | |
43 |
|
45 | |||
44 | /*! |
|
46 | /*! | |
45 | \enum QChart::AnimationOption |
|
47 | \enum QChart::AnimationOption | |
46 |
|
48 | |||
47 | For enabling/disabling animations. Defaults to NoAnimation. |
|
49 | For enabling/disabling animations. Defaults to NoAnimation. | |
48 |
|
50 | |||
49 | \value NoAnimation |
|
51 | \value NoAnimation | |
50 | \value GridAxisAnimations |
|
52 | \value GridAxisAnimations | |
51 | \value SeriesAnimations |
|
53 | \value SeriesAnimations | |
52 | \value AllAnimations |
|
54 | \value AllAnimations | |
53 | */ |
|
55 | */ | |
54 |
|
56 | |||
55 | /*! |
|
57 | /*! | |
56 | \class QChart |
|
58 | \class QChart | |
57 | \brief QtCommercial chart API. |
|
59 | \brief QtCommercial chart API. | |
58 |
|
60 | |||
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
61 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
60 | representation of different types of QChartSeries and other chart related objects like |
|
62 | representation of different types of QChartSeries and other chart related objects like | |
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
63 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
62 | convenience class QChartView instead of QChart. |
|
64 | convenience class QChartView instead of QChart. | |
63 | \sa QChartView |
|
65 | \sa QChartView | |
64 | */ |
|
66 | */ | |
65 |
|
67 | |||
66 | /*! |
|
68 | /*! | |
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
69 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
68 | */ |
|
70 | */ | |
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
71 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
70 | d_ptr(new QChartPrivate()) |
|
72 | d_ptr(new QChartPrivate()) | |
71 | { |
|
73 | { | |
72 | d_ptr->m_dataset = new ChartDataSet(this); |
|
74 | d_ptr->m_dataset = new ChartDataSet(this); | |
73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
74 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
75 | d_ptr->m_legend = new LegendScroller(this); |
|
77 | d_ptr->m_legend = new LegendScroller(this); | |
76 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
77 | } |
|
79 | } | |
78 |
|
80 | |||
79 | /*! |
|
81 | /*! | |
80 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
82 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
81 | */ |
|
83 | */ | |
82 | QChart::~QChart() |
|
84 | QChart::~QChart() | |
83 | { |
|
85 | { | |
84 | //delete first presenter , since this is a root of all the graphical items |
|
86 | //delete first presenter , since this is a root of all the graphical items | |
85 | delete d_ptr->m_presenter; |
|
87 | delete d_ptr->m_presenter; | |
86 | d_ptr->m_presenter=0; |
|
88 | d_ptr->m_presenter=0; | |
87 | } |
|
89 | } | |
88 |
|
90 | |||
89 | /*! |
|
91 | /*! | |
90 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
91 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
92 | the y axis). |
|
94 | the y axis). | |
93 | */ |
|
95 | */ | |
94 |
void QChart::addSeries(QAbstractSeries *series, Q |
|
96 | void QChart::addSeries(QAbstractSeries *series, QAxis *axisY) | |
95 | { |
|
97 | { | |
96 | Q_ASSERT(series); |
|
98 | Q_ASSERT(series); | |
97 | d_ptr->m_dataset->addSeries(series, axisY); |
|
99 | d_ptr->m_dataset->addSeries(series, axisY); | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 | /*! |
|
102 | /*! | |
101 | Removes the \a series specified in a perameter from the QChartView. |
|
103 | Removes the \a series specified in a perameter from the QChartView. | |
102 | It releses its ownership of the specified QChartSeries object. |
|
104 | It releses its ownership of the specified QChartSeries object. | |
103 | It does not delete the pointed QChartSeries data object |
|
105 | It does not delete the pointed QChartSeries data object | |
104 | \sa addSeries(), removeAllSeries() |
|
106 | \sa addSeries(), removeAllSeries() | |
105 | */ |
|
107 | */ | |
106 | void QChart::removeSeries(QAbstractSeries *series) |
|
108 | void QChart::removeSeries(QAbstractSeries *series) | |
107 | { |
|
109 | { | |
108 | Q_ASSERT(series); |
|
110 | Q_ASSERT(series); | |
109 | d_ptr->m_dataset->removeSeries(series); |
|
111 | d_ptr->m_dataset->removeSeries(series); | |
110 | } |
|
112 | } | |
111 |
|
113 | |||
112 | /*! |
|
114 | /*! | |
113 | Removes all the QChartSeries that have been added to the QChartView |
|
115 | Removes all the QChartSeries that have been added to the QChartView | |
114 | It also deletes the pointed QChartSeries data objects |
|
116 | It also deletes the pointed QChartSeries data objects | |
115 | \sa addSeries(), removeSeries() |
|
117 | \sa addSeries(), removeSeries() | |
116 | */ |
|
118 | */ | |
117 | void QChart::removeAllSeries() |
|
119 | void QChart::removeAllSeries() | |
118 | { |
|
120 | { | |
119 | d_ptr->m_dataset->removeAllSeries(); |
|
121 | d_ptr->m_dataset->removeAllSeries(); | |
120 | } |
|
122 | } | |
121 |
|
123 | |||
122 | /*! |
|
124 | /*! | |
123 | Sets the \a brush that is used for painting the background of the chart area. |
|
125 | Sets the \a brush that is used for painting the background of the chart area. | |
124 | */ |
|
126 | */ | |
125 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
127 | void QChart::setBackgroundBrush(const QBrush& brush) | |
126 | { |
|
128 | { | |
127 | //TODO: refactor me |
|
129 | //TODO: refactor me | |
128 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
130 | d_ptr->m_presenter->createChartBackgroundItem(); | |
129 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
131 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
130 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
132 | d_ptr->m_presenter->m_backgroundItem->update(); | |
131 | } |
|
133 | } | |
132 |
|
134 | |||
133 | /*! |
|
135 | /*! | |
134 | Gets the brush that is used for painting the background of the chart area. |
|
136 | Gets the brush that is used for painting the background of the chart area. | |
135 | */ |
|
137 | */ | |
136 | QBrush QChart::backgroundBrush() const |
|
138 | QBrush QChart::backgroundBrush() const | |
137 | { |
|
139 | { | |
138 | //TODO: refactor me |
|
140 | //TODO: refactor me | |
139 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
141 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
140 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
142 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
141 | } |
|
143 | } | |
142 |
|
144 | |||
143 | /*! |
|
145 | /*! | |
144 | Sets the \a pen that is used for painting the background of the chart area. |
|
146 | Sets the \a pen that is used for painting the background of the chart area. | |
145 | */ |
|
147 | */ | |
146 | void QChart::setBackgroundPen(const QPen& pen) |
|
148 | void QChart::setBackgroundPen(const QPen& pen) | |
147 | { |
|
149 | { | |
148 | //TODO: refactor me |
|
150 | //TODO: refactor me | |
149 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
151 | d_ptr->m_presenter->createChartBackgroundItem(); | |
150 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
152 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
151 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
153 | d_ptr->m_presenter->m_backgroundItem->update(); | |
152 | } |
|
154 | } | |
153 |
|
155 | |||
154 | /*! |
|
156 | /*! | |
155 | Gets the pen that is used for painting the background of the chart area. |
|
157 | Gets the pen that is used for painting the background of the chart area. | |
156 | */ |
|
158 | */ | |
157 | QPen QChart::backgroundPen() const |
|
159 | QPen QChart::backgroundPen() const | |
158 | { |
|
160 | { | |
159 | //TODO: refactor me |
|
161 | //TODO: refactor me | |
160 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
162 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
161 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
163 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
162 | } |
|
164 | } | |
163 |
|
165 | |||
164 | /*! |
|
166 | /*! | |
165 | Sets the chart \a title. The description text that is drawn above the chart. |
|
167 | Sets the chart \a title. The description text that is drawn above the chart. | |
166 | */ |
|
168 | */ | |
167 | void QChart::setTitle(const QString& title) |
|
169 | void QChart::setTitle(const QString& title) | |
168 | { |
|
170 | { | |
169 | //TODO: refactor me |
|
171 | //TODO: refactor me | |
170 | d_ptr->m_presenter->createChartTitleItem(); |
|
172 | d_ptr->m_presenter->createChartTitleItem(); | |
171 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
173 | d_ptr->m_presenter->m_titleItem->setText(title); | |
172 | d_ptr->m_presenter->updateLayout(); |
|
174 | d_ptr->m_presenter->updateLayout(); | |
173 | } |
|
175 | } | |
174 |
|
176 | |||
175 | /*! |
|
177 | /*! | |
176 | Returns the chart title. The description text that is drawn above the chart. |
|
178 | Returns the chart title. The description text that is drawn above the chart. | |
177 | */ |
|
179 | */ | |
178 | QString QChart::title() const |
|
180 | QString QChart::title() const | |
179 | { |
|
181 | { | |
180 | //TODO: refactor me |
|
182 | //TODO: refactor me | |
181 | if (d_ptr->m_presenter->m_titleItem) |
|
183 | if (d_ptr->m_presenter->m_titleItem) | |
182 | return d_ptr->m_presenter->m_titleItem->text(); |
|
184 | return d_ptr->m_presenter->m_titleItem->text(); | |
183 | else |
|
185 | else | |
184 | return QString(); |
|
186 | return QString(); | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | /*! |
|
189 | /*! | |
188 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
190 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
189 | */ |
|
191 | */ | |
190 | void QChart::setTitleFont(const QFont& font) |
|
192 | void QChart::setTitleFont(const QFont& font) | |
191 | { |
|
193 | { | |
192 | //TODO: refactor me |
|
194 | //TODO: refactor me | |
193 | d_ptr->m_presenter->createChartTitleItem(); |
|
195 | d_ptr->m_presenter->createChartTitleItem(); | |
194 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
196 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
195 | d_ptr->m_presenter->updateLayout(); |
|
197 | d_ptr->m_presenter->updateLayout(); | |
196 | } |
|
198 | } | |
197 |
|
199 | |||
198 | /*! |
|
200 | /*! | |
199 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
201 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
200 | */ |
|
202 | */ | |
201 | QFont QChart::titleFont() const |
|
203 | QFont QChart::titleFont() const | |
202 | { |
|
204 | { | |
203 | if (d_ptr->m_presenter->m_titleItem) |
|
205 | if (d_ptr->m_presenter->m_titleItem) | |
204 | return d_ptr->m_presenter->m_titleItem->font(); |
|
206 | return d_ptr->m_presenter->m_titleItem->font(); | |
205 | else |
|
207 | else | |
206 | return QFont(); |
|
208 | return QFont(); | |
207 | } |
|
209 | } | |
208 |
|
210 | |||
209 | /*! |
|
211 | /*! | |
210 | Sets the \a brush used for rendering the title text. |
|
212 | Sets the \a brush used for rendering the title text. | |
211 | */ |
|
213 | */ | |
212 | void QChart::setTitleBrush(const QBrush &brush) |
|
214 | void QChart::setTitleBrush(const QBrush &brush) | |
213 | { |
|
215 | { | |
214 | //TODO: refactor me |
|
216 | //TODO: refactor me | |
215 | d_ptr->m_presenter->createChartTitleItem(); |
|
217 | d_ptr->m_presenter->createChartTitleItem(); | |
216 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
218 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
217 | d_ptr->m_presenter->updateLayout(); |
|
219 | d_ptr->m_presenter->updateLayout(); | |
218 | } |
|
220 | } | |
219 |
|
221 | |||
220 | /*! |
|
222 | /*! | |
221 | Returns the brush used for rendering the title text. |
|
223 | Returns the brush used for rendering the title text. | |
222 | */ |
|
224 | */ | |
223 | QBrush QChart::titleBrush() const |
|
225 | QBrush QChart::titleBrush() const | |
224 | { |
|
226 | { | |
225 | //TODO: refactor me |
|
227 | //TODO: refactor me | |
226 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
228 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
227 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
229 | return d_ptr->m_presenter->m_titleItem->brush(); | |
228 | } |
|
230 | } | |
229 |
|
231 | |||
230 | /*! |
|
232 | /*! | |
231 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
233 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
232 | \sa theme() |
|
234 | \sa theme() | |
233 | */ |
|
235 | */ | |
234 | void QChart::setTheme(QChart::ChartTheme theme) |
|
236 | void QChart::setTheme(QChart::ChartTheme theme) | |
235 | { |
|
237 | { | |
236 | d_ptr->m_presenter->setTheme(theme); |
|
238 | d_ptr->m_presenter->setTheme(theme); | |
237 | } |
|
239 | } | |
238 |
|
240 | |||
239 | /*! |
|
241 | /*! | |
240 | Returns the theme enum used by the chart. |
|
242 | Returns the theme enum used by the chart. | |
241 | \sa ChartTheme, setTheme() |
|
243 | \sa ChartTheme, setTheme() | |
242 | */ |
|
244 | */ | |
243 | QChart::ChartTheme QChart::theme() const |
|
245 | QChart::ChartTheme QChart::theme() const | |
244 | { |
|
246 | { | |
245 | return d_ptr->m_presenter->theme(); |
|
247 | return d_ptr->m_presenter->theme(); | |
246 | } |
|
248 | } | |
247 |
|
249 | |||
248 | /*! |
|
250 | /*! | |
249 | Zooms in the view by a factor of 2 |
|
251 | Zooms in the view by a factor of 2 | |
250 | */ |
|
252 | */ | |
251 | void QChart::zoomIn() |
|
253 | void QChart::zoomIn() | |
252 | { |
|
254 | { | |
253 | d_ptr->m_presenter->zoomIn(); |
|
255 | d_ptr->m_presenter->zoomIn(); | |
254 | } |
|
256 | } | |
255 |
|
257 | |||
256 | /*! |
|
258 | /*! | |
257 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
259 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
258 | */ |
|
260 | */ | |
259 | void QChart::zoomIn(const QRectF& rect) |
|
261 | void QChart::zoomIn(const QRectF& rect) | |
260 | { |
|
262 | { | |
261 | if (!rect.isValid()) return; |
|
263 | if (!rect.isValid()) return; | |
262 | d_ptr->m_presenter->zoomIn(rect); |
|
264 | d_ptr->m_presenter->zoomIn(rect); | |
263 | } |
|
265 | } | |
264 |
|
266 | |||
265 | /*! |
|
267 | /*! | |
266 | Restores the view zoom level to the previous one. |
|
268 | Restores the view zoom level to the previous one. | |
267 | */ |
|
269 | */ | |
268 | void QChart::zoomOut() |
|
270 | void QChart::zoomOut() | |
269 | { |
|
271 | { | |
270 | d_ptr->m_presenter->zoomOut(); |
|
272 | d_ptr->m_presenter->zoomOut(); | |
271 | } |
|
273 | } | |
272 |
|
274 | |||
273 | /*! |
|
275 | /*! | |
274 | Returns the pointer to the x axis object of the chart |
|
276 | Returns the pointer to the x axis object of the chart | |
275 | */ |
|
277 | */ | |
276 |
Q |
|
278 | QAxis* QChart::axisX() const | |
277 | { |
|
279 | { | |
278 | return d_ptr->m_dataset->axisX(); |
|
280 | return d_ptr->m_dataset->axisX(); | |
279 | } |
|
281 | } | |
280 |
|
282 | |||
281 | /*! |
|
283 | /*! | |
282 | Returns the pointer to the y axis object of the \a series |
|
284 | Returns the pointer to the y axis object of the \a series | |
283 | If no \a series is provided then default Y axis of the chart is returned. |
|
285 | If no \a series is provided then default Y axis of the chart is returned. | |
284 | */ |
|
286 | */ | |
285 |
Q |
|
287 | QAxis* QChart::axisY(QAbstractSeries *series) const | |
286 | { |
|
288 | { | |
287 | return d_ptr->m_dataset->axisY(series); |
|
289 | return d_ptr->m_dataset->axisY(series); | |
288 | } |
|
290 | } | |
289 |
|
291 | |||
290 | /*! |
|
292 | /*! | |
291 | Returns the legend object of the chart. Ownership stays in chart. |
|
293 | Returns the legend object of the chart. Ownership stays in chart. | |
292 | */ |
|
294 | */ | |
293 | QLegend* QChart::legend() const |
|
295 | QLegend* QChart::legend() const | |
294 | { |
|
296 | { | |
295 | return d_ptr->m_legend; |
|
297 | return d_ptr->m_legend; | |
296 | } |
|
298 | } | |
297 |
|
299 | |||
298 | /*! |
|
300 | /*! | |
299 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
301 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
300 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
302 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
301 | */ |
|
303 | */ | |
302 | QRectF QChart::margins() const |
|
304 | QRectF QChart::margins() const | |
303 | { |
|
305 | { | |
304 | return d_ptr->m_presenter->margins(); |
|
306 | return d_ptr->m_presenter->margins(); | |
305 | } |
|
307 | } | |
306 |
|
308 | |||
307 |
|
309 | |||
308 | /*! |
|
310 | /*! | |
309 | Resizes and updates the chart area using the \a event data |
|
311 | Resizes and updates the chart area using the \a event data | |
310 | */ |
|
312 | */ | |
311 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
313 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
312 | { |
|
314 | { | |
313 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
315 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
314 | QGraphicsWidget::resizeEvent(event); |
|
316 | QGraphicsWidget::resizeEvent(event); | |
315 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
317 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
316 | } |
|
318 | } | |
317 |
|
319 | |||
318 | /*! |
|
320 | /*! | |
319 | Sets animation \a options for the chart |
|
321 | Sets animation \a options for the chart | |
320 | */ |
|
322 | */ | |
321 | void QChart::setAnimationOptions(AnimationOptions options) |
|
323 | void QChart::setAnimationOptions(AnimationOptions options) | |
322 | { |
|
324 | { | |
323 | d_ptr->m_presenter->setAnimationOptions(options); |
|
325 | d_ptr->m_presenter->setAnimationOptions(options); | |
324 | } |
|
326 | } | |
325 |
|
327 | |||
326 | /*! |
|
328 | /*! | |
327 | Returns animation options for the chart |
|
329 | Returns animation options for the chart | |
328 | */ |
|
330 | */ | |
329 | QChart::AnimationOptions QChart::animationOptions() const |
|
331 | QChart::AnimationOptions QChart::animationOptions() const | |
330 | { |
|
332 | { | |
331 | return d_ptr->m_presenter->animationOptions(); |
|
333 | return d_ptr->m_presenter->animationOptions(); | |
332 | } |
|
334 | } | |
333 |
|
335 | |||
334 | /*! |
|
336 | /*! | |
335 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks |
|
337 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks | |
336 | */ |
|
338 | */ | |
337 | void QChart::scrollLeft() |
|
339 | void QChart::scrollLeft() | |
338 | { |
|
340 | { | |
339 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
341 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
340 | } |
|
342 | } | |
341 |
|
343 | |||
342 | /*! |
|
344 | /*! | |
343 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks |
|
345 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks | |
344 | */ |
|
346 | */ | |
345 | void QChart::scrollRight() |
|
347 | void QChart::scrollRight() | |
346 | { |
|
348 | { | |
347 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
349 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
348 | } |
|
350 | } | |
349 |
|
351 | |||
350 | /*! |
|
352 | /*! | |
351 | Scrolls the visible area of the chart up by the distance between two y axis ticks |
|
353 | Scrolls the visible area of the chart up by the distance between two y axis ticks | |
352 | */ |
|
354 | */ | |
353 | void QChart::scrollUp() |
|
355 | void QChart::scrollUp() | |
354 | { |
|
356 | { | |
355 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
357 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
356 | } |
|
358 | } | |
357 |
|
359 | |||
358 | /*! |
|
360 | /*! | |
359 | Scrolls the visible area of the chart down by the distance between two y axis ticks |
|
361 | Scrolls the visible area of the chart down by the distance between two y axis ticks | |
360 | */ |
|
362 | */ | |
361 | void QChart::scrollDown() |
|
363 | void QChart::scrollDown() | |
362 | { |
|
364 | { | |
363 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
365 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
364 | } |
|
366 | } | |
365 |
|
367 | |||
366 | /*! |
|
368 | /*! | |
367 | Sets the chart background visibility state to \a visible |
|
369 | Sets the chart background visibility state to \a visible | |
368 | */ |
|
370 | */ | |
369 | void QChart::setBackgroundVisible(bool visible) |
|
371 | void QChart::setBackgroundVisible(bool visible) | |
370 | { |
|
372 | { | |
371 | //TODO: refactor me |
|
373 | //TODO: refactor me | |
372 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
374 | d_ptr->m_presenter->createChartBackgroundItem(); | |
373 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
375 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
374 | } |
|
376 | } | |
375 |
|
377 | |||
376 | /*! |
|
378 | /*! | |
377 | Returns the chart's background visibility state |
|
379 | Returns the chart's background visibility state | |
378 | */ |
|
380 | */ | |
379 | bool QChart::isBackgroundVisible() const |
|
381 | bool QChart::isBackgroundVisible() const | |
380 | { |
|
382 | { | |
381 | //TODO: refactor me |
|
383 | //TODO: refactor me | |
382 | if (!d_ptr->m_presenter->m_backgroundItem) |
|
384 | if (!d_ptr->m_presenter->m_backgroundItem) | |
383 | return false; |
|
385 | return false; | |
384 |
|
386 | |||
385 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
387 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
386 | } |
|
388 | } | |
387 |
|
389 | |||
388 | /*! |
|
390 | /*! | |
389 | Sets the background drop shadow effect state to \a enabled. |
|
391 | Sets the background drop shadow effect state to \a enabled. | |
390 | */ |
|
392 | */ | |
391 | void QChart::setBackgroundDropShadowEnabled(bool enabled) |
|
393 | void QChart::setBackgroundDropShadowEnabled(bool enabled) | |
392 | { |
|
394 | { | |
393 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
395 | d_ptr->m_presenter->createChartBackgroundItem(); | |
394 | d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled); |
|
396 | d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled); | |
395 | } |
|
397 | } | |
396 |
|
398 | |||
397 | /*! |
|
399 | /*! | |
398 | Returns true if the drop shadow effect is enabled for the chart background. |
|
400 | Returns true if the drop shadow effect is enabled for the chart background. | |
399 | */ |
|
401 | */ | |
400 | bool QChart::isBackgroundDropShadowEnabled() const |
|
402 | bool QChart::isBackgroundDropShadowEnabled() const | |
401 | { |
|
403 | { | |
402 | if (!d_ptr->m_presenter->m_backgroundItem) |
|
404 | if (!d_ptr->m_presenter->m_backgroundItem) | |
403 | return false; |
|
405 | return false; | |
404 |
|
406 | |||
405 | return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled(); |
|
407 | return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled(); | |
406 | } |
|
408 | } | |
407 |
|
409 | |||
408 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
410 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
409 |
|
411 | |||
410 | QChartPrivate::QChartPrivate(): |
|
412 | QChartPrivate::QChartPrivate(): | |
411 | m_legend(0), |
|
413 | m_legend(0), | |
412 | m_dataset(0), |
|
414 | m_dataset(0), | |
413 | m_presenter(0) |
|
415 | m_presenter(0) | |
414 | { |
|
416 | { | |
415 |
|
417 | |||
416 | } |
|
418 | } | |
417 |
|
419 | |||
418 | QChartPrivate::~QChartPrivate() |
|
420 | QChartPrivate::~QChartPrivate() | |
419 | { |
|
421 | { | |
420 |
|
422 | |||
421 | } |
|
423 | } | |
422 |
|
424 | |||
423 | void QChartPrivate::createConnections() |
|
425 | void QChartPrivate::createConnections() | |
424 | { |
|
426 | { | |
425 |
|
427 | |||
426 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries *, Domain *)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries *, Domain *))); |
|
428 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries *, Domain *)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries *, Domain *))); | |
427 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries *)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries *))); |
|
429 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries *)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries *))); | |
428 |
QObject::connect(m_dataset,SIGNAL(axisAdded(Q |
|
430 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*))); | |
429 |
QObject::connect(m_dataset,SIGNAL(axisRemoved(Q |
|
431 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*))); | |
430 | } |
|
432 | } | |
431 |
|
433 | |||
432 | #include "moc_qchart.cpp" |
|
434 | #include "moc_qchart.cpp" | |
433 |
|
435 | |||
434 | QTCOMMERCIALCHART_END_NAMESPACE |
|
436 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,120 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QAbstractSeries> |
|
24 | #include <QAbstractSeries> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include <QGraphicsWidget> |
|
26 | #include <QGraphicsWidget> | |
27 |
|
27 | |||
28 | class QGraphicsSceneResizeEvent; |
|
28 | class QGraphicsSceneResizeEvent; | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QAbstractSeries; |
|
32 | class QAbstractSeries; | |
33 |
class Q |
|
33 | class QAxis; | |
34 | class QLegend; |
|
34 | class QLegend; | |
35 | struct QChartPrivate; |
|
35 | struct QChartPrivate; | |
36 |
|
36 | |||
37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
38 | { |
|
38 | { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
40 | Q_ENUMS(ChartTheme) |
|
40 | Q_ENUMS(ChartTheme) | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | enum ChartTheme { |
|
43 | enum ChartTheme { | |
44 | ChartThemeLight = 0, |
|
44 | ChartThemeLight = 0, | |
45 | ChartThemeBlueCerulean, |
|
45 | ChartThemeBlueCerulean, | |
46 | ChartThemeDark, |
|
46 | ChartThemeDark, | |
47 | ChartThemeBrownSand, |
|
47 | ChartThemeBrownSand, | |
48 | ChartThemeBlueNcs, |
|
48 | ChartThemeBlueNcs, | |
49 | ChartThemeHighContrast, |
|
49 | ChartThemeHighContrast, | |
50 | ChartThemeBlueIcy |
|
50 | ChartThemeBlueIcy | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | enum AnimationOption { |
|
53 | enum AnimationOption { | |
54 | NoAnimation = 0x0, |
|
54 | NoAnimation = 0x0, | |
55 | GridAxisAnimations = 0x1, |
|
55 | GridAxisAnimations = 0x1, | |
56 | SeriesAnimations =0x2, |
|
56 | SeriesAnimations =0x2, | |
57 | AllAnimations = 0x3 |
|
57 | AllAnimations = 0x3 | |
58 | }; |
|
58 | }; | |
59 |
|
59 | |||
60 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
60 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
61 |
|
61 | |||
62 | public: |
|
62 | public: | |
63 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
63 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
64 | ~QChart(); |
|
64 | ~QChart(); | |
65 |
|
65 | |||
66 |
void addSeries(QAbstractSeries *series, Q |
|
66 | void addSeries(QAbstractSeries *series, QAxis *axisY = 0); | |
67 | void removeSeries(QAbstractSeries *series); |
|
67 | void removeSeries(QAbstractSeries *series); | |
68 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
69 |
|
69 | |||
70 | void setTheme(QChart::ChartTheme theme); |
|
70 | void setTheme(QChart::ChartTheme theme); | |
71 | QChart::ChartTheme theme() const; |
|
71 | QChart::ChartTheme theme() const; | |
72 |
|
72 | |||
73 | void setTitle(const QString& title); |
|
73 | void setTitle(const QString& title); | |
74 | QString title() const; |
|
74 | QString title() const; | |
75 | void setTitleFont(const QFont& font); |
|
75 | void setTitleFont(const QFont& font); | |
76 | QFont titleFont() const; |
|
76 | QFont titleFont() const; | |
77 | void setTitleBrush(const QBrush &brush); |
|
77 | void setTitleBrush(const QBrush &brush); | |
78 | QBrush titleBrush() const; |
|
78 | QBrush titleBrush() const; | |
79 |
|
79 | |||
80 | void setBackgroundBrush(const QBrush &brush); |
|
80 | void setBackgroundBrush(const QBrush &brush); | |
81 | QBrush backgroundBrush() const; |
|
81 | QBrush backgroundBrush() const; | |
82 | void setBackgroundPen(const QPen &pen); |
|
82 | void setBackgroundPen(const QPen &pen); | |
83 | QPen backgroundPen() const; |
|
83 | QPen backgroundPen() const; | |
84 | void setBackgroundVisible(bool visible = true); |
|
84 | void setBackgroundVisible(bool visible = true); | |
85 | bool isBackgroundVisible() const; |
|
85 | bool isBackgroundVisible() const; | |
86 | void setBackgroundDropShadowEnabled(bool enabled = true); |
|
86 | void setBackgroundDropShadowEnabled(bool enabled = true); | |
87 | bool isBackgroundDropShadowEnabled() const; |
|
87 | bool isBackgroundDropShadowEnabled() const; | |
88 |
|
88 | |||
89 | void setAnimationOptions(AnimationOptions options); |
|
89 | void setAnimationOptions(AnimationOptions options); | |
90 | AnimationOptions animationOptions() const; |
|
90 | AnimationOptions animationOptions() const; | |
91 |
|
91 | |||
92 | void zoomIn(); |
|
92 | void zoomIn(); | |
93 | void zoomIn(const QRectF &rect); |
|
93 | void zoomIn(const QRectF &rect); | |
94 | void zoomOut(); |
|
94 | void zoomOut(); | |
95 | void scrollLeft(); |
|
95 | void scrollLeft(); | |
96 | void scrollRight(); |
|
96 | void scrollRight(); | |
97 | void scrollUp(); |
|
97 | void scrollUp(); | |
98 | void scrollDown(); |
|
98 | void scrollDown(); | |
99 |
|
99 | |||
100 |
Q |
|
100 | QAxis* axisX() const; | |
101 |
Q |
|
101 | QAxis* axisY(QAbstractSeries* series = 0) const; | |
102 |
|
102 | |||
103 | QLegend* legend() const; |
|
103 | QLegend* legend() const; | |
104 | QRectF margins() const; |
|
104 | QRectF margins() const; | |
105 |
|
105 | |||
106 | protected: |
|
106 | protected: | |
107 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
107 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
108 |
|
108 | |||
109 | protected: |
|
109 | protected: | |
110 | QScopedPointer<QChartPrivate> d_ptr; |
|
110 | QScopedPointer<QChartPrivate> d_ptr; | |
111 | friend class QLegend; |
|
111 | friend class QLegend; | |
112 | friend class ChartPresenter; |
|
112 | friend class ChartPresenter; | |
113 | Q_DISABLE_COPY(QChart) |
|
113 | Q_DISABLE_COPY(QChart) | |
114 | }; |
|
114 | }; | |
115 |
|
115 | |||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | QTCOMMERCIALCHART_END_NAMESPACE | |
117 |
|
117 | |||
118 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
118 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
119 |
|
119 | |||
120 | #endif |
|
120 | #endif |
@@ -1,71 +1,71 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHARTVIEW_H |
|
21 | #ifndef QCHARTVIEW_H | |
22 | #define QCHARTVIEW_H |
|
22 | #define QCHARTVIEW_H | |
23 |
|
23 | |||
24 |
#include <Q |
|
24 | #include <QAxis> | |
25 | #include <QAbstractSeries> |
|
25 | #include <QAbstractSeries> | |
26 | #include <QChart> |
|
26 | #include <QChart> | |
27 | #include <QGraphicsView> |
|
27 | #include <QGraphicsView> | |
28 |
|
28 | |||
29 | class QGraphicsScene; |
|
29 | class QGraphicsScene; | |
30 | class QRubberBand; |
|
30 | class QRubberBand; | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | struct QChartViewPrivate; |
|
34 | struct QChartViewPrivate; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
36 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 |
|
41 | |||
42 | enum RubberBand{ |
|
42 | enum RubberBand{ | |
43 | NoRubberBand = 0x0, |
|
43 | NoRubberBand = 0x0, | |
44 | VerticalRubberBand = 0x1, |
|
44 | VerticalRubberBand = 0x1, | |
45 | HorizonalRubberBand = 0x2, |
|
45 | HorizonalRubberBand = 0x2, | |
46 | RectangleRubberBand = 0x3 |
|
46 | RectangleRubberBand = 0x3 | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | Q_DECLARE_FLAGS(RubberBands, RubberBand) |
|
49 | Q_DECLARE_FLAGS(RubberBands, RubberBand) | |
50 |
|
50 | |||
51 | explicit QChartView(QChart *chart,QWidget *parent = 0); |
|
51 | explicit QChartView(QChart *chart,QWidget *parent = 0); | |
52 | ~QChartView(); |
|
52 | ~QChartView(); | |
53 |
|
53 | |||
54 | void setRubberBand(const RubberBands& rubberBands); |
|
54 | void setRubberBand(const RubberBands& rubberBands); | |
55 | RubberBands rubberBand() const; |
|
55 | RubberBands rubberBand() const; | |
56 | QChart* chart() const; |
|
56 | QChart* chart() const; | |
57 |
|
57 | |||
58 | protected: |
|
58 | protected: | |
59 | void resizeEvent(QResizeEvent *event); |
|
59 | void resizeEvent(QResizeEvent *event); | |
60 | void mousePressEvent(QMouseEvent *event); |
|
60 | void mousePressEvent(QMouseEvent *event); | |
61 | void mouseMoveEvent(QMouseEvent *event); |
|
61 | void mouseMoveEvent(QMouseEvent *event); | |
62 | void mouseReleaseEvent(QMouseEvent *event); |
|
62 | void mouseReleaseEvent(QMouseEvent *event); | |
63 |
|
63 | |||
64 | protected: |
|
64 | protected: | |
65 | QScopedPointer<QChartViewPrivate> d_ptr; |
|
65 | QScopedPointer<QChartViewPrivate> d_ptr; | |
66 | Q_DISABLE_COPY(QChartView) |
|
66 | Q_DISABLE_COPY(QChartView) | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
70 | |||
71 | #endif // QCHARTWIDGET_H |
|
71 | #endif // QCHARTWIDGET_H |
@@ -1,570 +1,570 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 |
#include <q |
|
22 | #include <qaxis.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <private/chartdataset_p.h> |
|
24 | #include <private/chartdataset_p.h> | |
25 | #include <private/domain_p.h> |
|
25 | #include <private/domain_p.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | Q_DECLARE_METATYPE(Domain *) |
|
29 | Q_DECLARE_METATYPE(Domain *) | |
30 |
Q_DECLARE_METATYPE(Q |
|
30 | Q_DECLARE_METATYPE(QAxis *) | |
31 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
31 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
32 | Q_DECLARE_METATYPE(QLineSeries *) |
|
32 | Q_DECLARE_METATYPE(QLineSeries *) | |
33 |
|
33 | |||
34 | class tst_ChartDataSet: public QObject { |
|
34 | class tst_ChartDataSet: public QObject { | |
35 |
|
35 | |||
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
39 | void initTestCase(); |
|
39 | void initTestCase(); | |
40 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
41 | void init(); |
|
41 | void init(); | |
42 | void cleanup(); |
|
42 | void cleanup(); | |
43 |
|
43 | |||
44 | private Q_SLOTS: |
|
44 | private Q_SLOTS: | |
45 | void chartdataset_data(); |
|
45 | void chartdataset_data(); | |
46 | void chartdataset(); |
|
46 | void chartdataset(); | |
47 | void addSeries_data(); |
|
47 | void addSeries_data(); | |
48 | void addSeries(); |
|
48 | void addSeries(); | |
49 | void removeSeries_data(); |
|
49 | void removeSeries_data(); | |
50 | void removeSeries(); |
|
50 | void removeSeries(); | |
51 | void removeAllSeries_data(); |
|
51 | void removeAllSeries_data(); | |
52 | void removeAllSeries(); |
|
52 | void removeAllSeries(); | |
53 | void axisY_data(); |
|
53 | void axisY_data(); | |
54 | void axisY(); |
|
54 | void axisY(); | |
55 | void seriesCount_data(); |
|
55 | void seriesCount_data(); | |
56 | void seriesCount(); |
|
56 | void seriesCount(); | |
57 | void seriesIndex_data(); |
|
57 | void seriesIndex_data(); | |
58 | void seriesIndex(); |
|
58 | void seriesIndex(); | |
59 | void domain_data(); |
|
59 | void domain_data(); | |
60 | void domain(); |
|
60 | void domain(); | |
61 | void zoomInDomain_data(); |
|
61 | void zoomInDomain_data(); | |
62 | void zoomInDomain(); |
|
62 | void zoomInDomain(); | |
63 | void zoomOutDomain_data(); |
|
63 | void zoomOutDomain_data(); | |
64 | void zoomOutDomain(); |
|
64 | void zoomOutDomain(); | |
65 | void scrollDomain_data(); |
|
65 | void scrollDomain_data(); | |
66 | void scrollDomain(); |
|
66 | void scrollDomain(); | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | void tst_ChartDataSet::initTestCase() |
|
69 | void tst_ChartDataSet::initTestCase() | |
70 | { |
|
70 | { | |
71 | qRegisterMetaType<Domain*>(); |
|
71 | qRegisterMetaType<Domain*>(); | |
72 |
qRegisterMetaType<Q |
|
72 | qRegisterMetaType<QAxis*>(); | |
73 | qRegisterMetaType<QAbstractSeries*>(); |
|
73 | qRegisterMetaType<QAbstractSeries*>(); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void tst_ChartDataSet::cleanupTestCase() |
|
76 | void tst_ChartDataSet::cleanupTestCase() | |
77 | { |
|
77 | { | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_ChartDataSet::init() |
|
80 | void tst_ChartDataSet::init() | |
81 | { |
|
81 | { | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void tst_ChartDataSet::cleanup() |
|
84 | void tst_ChartDataSet::cleanup() | |
85 | { |
|
85 | { | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void tst_ChartDataSet::chartdataset_data() |
|
88 | void tst_ChartDataSet::chartdataset_data() | |
89 | { |
|
89 | { | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void tst_ChartDataSet::chartdataset() |
|
92 | void tst_ChartDataSet::chartdataset() | |
93 | { |
|
93 | { | |
94 | ChartDataSet dataSet; |
|
94 | ChartDataSet dataSet; | |
95 | QVERIFY2(dataSet.axisX(), "Missing axisX."); |
|
95 | QVERIFY2(dataSet.axisX(), "Missing axisX."); | |
96 | QVERIFY2(dataSet.axisY(), "Missing axisY."); |
|
96 | QVERIFY2(dataSet.axisY(), "Missing axisY."); | |
97 | //check if not dangling pointer |
|
97 | //check if not dangling pointer | |
98 | dataSet.axisX()->objectName(); |
|
98 | dataSet.axisX()->objectName(); | |
99 | dataSet.axisY()->objectName(); |
|
99 | dataSet.axisY()->objectName(); | |
100 | QLineSeries* series = new QLineSeries(this); |
|
100 | QLineSeries* series = new QLineSeries(this); | |
101 | QCOMPARE(dataSet.seriesIndex(series),-1); |
|
101 | QCOMPARE(dataSet.seriesIndex(series),-1); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void tst_ChartDataSet::addSeries_data() |
|
104 | void tst_ChartDataSet::addSeries_data() | |
105 | { |
|
105 | { | |
106 | QTest::addColumn<QLineSeries*>("series0"); |
|
106 | QTest::addColumn<QLineSeries*>("series0"); | |
107 |
QTest::addColumn<Q |
|
107 | QTest::addColumn<QAxis*>("axis0"); | |
108 | QTest::addColumn<QLineSeries*>("series1"); |
|
108 | QTest::addColumn<QLineSeries*>("series1"); | |
109 |
QTest::addColumn<Q |
|
109 | QTest::addColumn<QAxis*>("axis1"); | |
110 | QTest::addColumn<QLineSeries*>("series2"); |
|
110 | QTest::addColumn<QLineSeries*>("series2"); | |
111 |
QTest::addColumn<Q |
|
111 | QTest::addColumn<QAxis*>("axis2"); | |
112 | QTest::addColumn<int>("axisCount"); |
|
112 | QTest::addColumn<int>("axisCount"); | |
113 |
|
113 | |||
114 | QLineSeries* series0 = new QLineSeries(this); |
|
114 | QLineSeries* series0 = new QLineSeries(this); | |
115 | QLineSeries* series1 = new QLineSeries(this); |
|
115 | QLineSeries* series1 = new QLineSeries(this); | |
116 | QLineSeries* series2 = new QLineSeries(this); |
|
116 | QLineSeries* series2 = new QLineSeries(this); | |
117 |
|
117 | |||
118 |
Q |
|
118 | QAxis* axis0 = new QAxis(this); | |
119 |
Q |
|
119 | QAxis* axis1 = new QAxis(this); | |
120 |
Q |
|
120 | QAxis* axis2 = new QAxis(this); | |
121 |
|
121 | |||
122 |
QTest::newRow("default axis Y: series0,series1,series2") << series0 << (Q |
|
122 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QAxis*)0 << series1 << (QAxis*)0 << series2 << (QAxis*)0 << 2; | |
123 |
QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (Q |
|
123 | QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QAxis*)0 << series1 << axis0 << series2 << axis0 << 3; | |
124 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; |
|
124 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void tst_ChartDataSet::addSeries() |
|
127 | void tst_ChartDataSet::addSeries() | |
128 | { |
|
128 | { | |
129 | QFETCH(QLineSeries*, series0); |
|
129 | QFETCH(QLineSeries*, series0); | |
130 |
QFETCH(Q |
|
130 | QFETCH(QAxis*, axis0); | |
131 | QFETCH(QLineSeries*, series1); |
|
131 | QFETCH(QLineSeries*, series1); | |
132 |
QFETCH(Q |
|
132 | QFETCH(QAxis*, axis1); | |
133 | QFETCH(QLineSeries*, series2); |
|
133 | QFETCH(QLineSeries*, series2); | |
134 |
QFETCH(Q |
|
134 | QFETCH(QAxis*, axis2); | |
135 | QFETCH(int, axisCount); |
|
135 | QFETCH(int, axisCount); | |
136 |
|
136 | |||
137 | ChartDataSet dataSet; |
|
137 | ChartDataSet dataSet; | |
138 |
|
138 | |||
139 |
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(Q |
|
139 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QAxis*,Domain*))); | |
140 |
QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(Q |
|
140 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QAxis*))); | |
141 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
141 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
142 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
142 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
143 |
|
143 | |||
144 | dataSet.addSeries(series0,axis0); |
|
144 | dataSet.addSeries(series0,axis0); | |
145 | dataSet.addSeries(series1,axis1); |
|
145 | dataSet.addSeries(series1,axis1); | |
146 | dataSet.addSeries(series2,axis2); |
|
146 | dataSet.addSeries(series2,axis2); | |
147 |
|
147 | |||
148 | QCOMPARE(spy0.count(), axisCount); |
|
148 | QCOMPARE(spy0.count(), axisCount); | |
149 | QCOMPARE(spy1.count(), 0); |
|
149 | QCOMPARE(spy1.count(), 0); | |
150 | QCOMPARE(spy2.count(), 3); |
|
150 | QCOMPARE(spy2.count(), 3); | |
151 | QCOMPARE(spy3.count(), 0); |
|
151 | QCOMPARE(spy3.count(), 0); | |
152 |
|
152 | |||
153 | if(axis0==0) axis0 = dataSet.axisY(); |
|
153 | if(axis0==0) axis0 = dataSet.axisY(); | |
154 | if(axis1==0) axis1 = dataSet.axisY(); |
|
154 | if(axis1==0) axis1 = dataSet.axisY(); | |
155 | if(axis2==0) axis2 = dataSet.axisY(); |
|
155 | if(axis2==0) axis2 = dataSet.axisY(); | |
156 |
|
156 | |||
157 | QVERIFY(axis0 == dataSet.removeSeries(series0)); |
|
157 | QVERIFY(axis0 == dataSet.removeSeries(series0)); | |
158 | QVERIFY(axis1 == dataSet.removeSeries(series1)); |
|
158 | QVERIFY(axis1 == dataSet.removeSeries(series1)); | |
159 | QVERIFY(axis2 == dataSet.removeSeries(series2)); |
|
159 | QVERIFY(axis2 == dataSet.removeSeries(series2)); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void tst_ChartDataSet::removeSeries_data() |
|
162 | void tst_ChartDataSet::removeSeries_data() | |
163 | { |
|
163 | { | |
164 | addSeries_data(); |
|
164 | addSeries_data(); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void tst_ChartDataSet::removeSeries() |
|
167 | void tst_ChartDataSet::removeSeries() | |
168 | { |
|
168 | { | |
169 | QFETCH(QLineSeries*, series0); |
|
169 | QFETCH(QLineSeries*, series0); | |
170 |
QFETCH(Q |
|
170 | QFETCH(QAxis*, axis0); | |
171 | QFETCH(QLineSeries*, series1); |
|
171 | QFETCH(QLineSeries*, series1); | |
172 |
QFETCH(Q |
|
172 | QFETCH(QAxis*, axis1); | |
173 | QFETCH(QLineSeries*, series2); |
|
173 | QFETCH(QLineSeries*, series2); | |
174 |
QFETCH(Q |
|
174 | QFETCH(QAxis*, axis2); | |
175 | QFETCH(int, axisCount); |
|
175 | QFETCH(int, axisCount); | |
176 |
|
176 | |||
177 | ChartDataSet dataSet; |
|
177 | ChartDataSet dataSet; | |
178 |
|
178 | |||
179 | dataSet.addSeries(series0,axis0); |
|
179 | dataSet.addSeries(series0,axis0); | |
180 | dataSet.addSeries(series1,axis1); |
|
180 | dataSet.addSeries(series1,axis1); | |
181 | dataSet.addSeries(series2,axis2); |
|
181 | dataSet.addSeries(series2,axis2); | |
182 |
|
182 | |||
183 |
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(Q |
|
183 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QAxis *, Domain *))); | |
184 |
QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(Q |
|
184 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QAxis *))); | |
185 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
185 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
186 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
186 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
187 |
|
187 | |||
188 | dataSet.removeSeries(series0); |
|
188 | dataSet.removeSeries(series0); | |
189 | dataSet.removeSeries(series1); |
|
189 | dataSet.removeSeries(series1); | |
190 | dataSet.removeSeries(series2); |
|
190 | dataSet.removeSeries(series2); | |
191 |
|
191 | |||
192 | QCOMPARE(spy0.count(), 0); |
|
192 | QCOMPARE(spy0.count(), 0); | |
193 | QCOMPARE(spy1.count(), axisCount); |
|
193 | QCOMPARE(spy1.count(), axisCount); | |
194 | QCOMPARE(spy2.count(), 0); |
|
194 | QCOMPARE(spy2.count(), 0); | |
195 | QCOMPARE(spy3.count(), 3); |
|
195 | QCOMPARE(spy3.count(), 3); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | void tst_ChartDataSet::removeAllSeries_data() |
|
198 | void tst_ChartDataSet::removeAllSeries_data() | |
199 | { |
|
199 | { | |
200 |
|
200 | |||
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void tst_ChartDataSet::removeAllSeries() |
|
203 | void tst_ChartDataSet::removeAllSeries() | |
204 | { |
|
204 | { | |
205 | QLineSeries* series0 = new QLineSeries(this); |
|
205 | QLineSeries* series0 = new QLineSeries(this); | |
206 | QLineSeries* series1 = new QLineSeries(this); |
|
206 | QLineSeries* series1 = new QLineSeries(this); | |
207 | QLineSeries* series2 = new QLineSeries(this); |
|
207 | QLineSeries* series2 = new QLineSeries(this); | |
208 |
|
208 | |||
209 |
Q |
|
209 | QAxis* axis0 = new QAxis(this); | |
210 |
Q |
|
210 | QAxis* axis1 = new QAxis(this); | |
211 |
Q |
|
211 | QAxis* axis2 = new QAxis(this); | |
212 |
|
212 | |||
213 |
|
213 | |||
214 | ChartDataSet dataSet; |
|
214 | ChartDataSet dataSet; | |
215 |
|
215 | |||
216 | dataSet.addSeries(series0, axis0); |
|
216 | dataSet.addSeries(series0, axis0); | |
217 | dataSet.addSeries(series1, axis1); |
|
217 | dataSet.addSeries(series1, axis1); | |
218 | dataSet.addSeries(series2, axis2); |
|
218 | dataSet.addSeries(series2, axis2); | |
219 |
|
219 | |||
220 |
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(Q |
|
220 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QAxis *, Domain *))); | |
221 |
QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(Q |
|
221 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QAxis *))); | |
222 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
222 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
223 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
223 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
224 |
|
224 | |||
225 | dataSet.removeAllSeries(); |
|
225 | dataSet.removeAllSeries(); | |
226 |
|
226 | |||
227 | QCOMPARE(spy0.count(), 0); |
|
227 | QCOMPARE(spy0.count(), 0); | |
228 | QCOMPARE(spy1.count(), 4); |
|
228 | QCOMPARE(spy1.count(), 4); | |
229 | QCOMPARE(spy2.count(), 0); |
|
229 | QCOMPARE(spy2.count(), 0); | |
230 | QCOMPARE(spy3.count(), 3); |
|
230 | QCOMPARE(spy3.count(), 3); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 |
|
233 | |||
234 | void tst_ChartDataSet::axisY_data() |
|
234 | void tst_ChartDataSet::axisY_data() | |
235 | { |
|
235 | { | |
236 |
QTest::addColumn<Q |
|
236 | QTest::addColumn<QAxis*>("axis0"); | |
237 |
QTest::addColumn<Q |
|
237 | QTest::addColumn<QAxis*>("axis1"); | |
238 |
QTest::addColumn<Q |
|
238 | QTest::addColumn<QAxis*>("axis2"); | |
239 |
QTest::newRow("1 defualt, 2 optional") << (Q |
|
239 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); | |
240 |
QTest::newRow("3 optional") << new Q |
|
240 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | void tst_ChartDataSet::axisY() |
|
243 | void tst_ChartDataSet::axisY() | |
244 | { |
|
244 | { | |
245 |
QFETCH(Q |
|
245 | QFETCH(QAxis*, axis0); | |
246 |
QFETCH(Q |
|
246 | QFETCH(QAxis*, axis1); | |
247 |
QFETCH(Q |
|
247 | QFETCH(QAxis*, axis2); | |
248 |
|
248 | |||
249 | ChartDataSet dataSet; |
|
249 | ChartDataSet dataSet; | |
250 |
|
250 | |||
251 |
Q |
|
251 | QAxis* defaultAxisY = dataSet.axisY(); | |
252 |
|
252 | |||
253 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
253 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
254 |
|
254 | |||
255 | QLineSeries* series0 = new QLineSeries(); |
|
255 | QLineSeries* series0 = new QLineSeries(); | |
256 | dataSet.addSeries(series0,axis0); |
|
256 | dataSet.addSeries(series0,axis0); | |
257 |
|
257 | |||
258 | QLineSeries* series1 = new QLineSeries(); |
|
258 | QLineSeries* series1 = new QLineSeries(); | |
259 | dataSet.addSeries(series1,axis1); |
|
259 | dataSet.addSeries(series1,axis1); | |
260 |
|
260 | |||
261 | QLineSeries* series2 = new QLineSeries(); |
|
261 | QLineSeries* series2 = new QLineSeries(); | |
262 | dataSet.addSeries(series2,axis2); |
|
262 | dataSet.addSeries(series2,axis2); | |
263 |
|
263 | |||
264 | if(!axis0) axis0=defaultAxisY ; |
|
264 | if(!axis0) axis0=defaultAxisY ; | |
265 | if(!axis1) axis1=defaultAxisY ; |
|
265 | if(!axis1) axis1=defaultAxisY ; | |
266 | if(!axis2) axis2=defaultAxisY ; |
|
266 | if(!axis2) axis2=defaultAxisY ; | |
267 |
|
267 | |||
268 | QVERIFY(dataSet.axisY(series0) == axis0); |
|
268 | QVERIFY(dataSet.axisY(series0) == axis0); | |
269 | QVERIFY(dataSet.axisY(series1) == axis1); |
|
269 | QVERIFY(dataSet.axisY(series1) == axis1); | |
270 | QVERIFY(dataSet.axisY(series2) == axis2); |
|
270 | QVERIFY(dataSet.axisY(series2) == axis2); | |
271 |
|
271 | |||
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | void tst_ChartDataSet::seriesCount_data() |
|
274 | void tst_ChartDataSet::seriesCount_data() | |
275 | { |
|
275 | { | |
276 | addSeries_data(); |
|
276 | addSeries_data(); | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void tst_ChartDataSet::seriesCount() |
|
279 | void tst_ChartDataSet::seriesCount() | |
280 | { |
|
280 | { | |
281 | QFETCH(QLineSeries*, series0); |
|
281 | QFETCH(QLineSeries*, series0); | |
282 |
QFETCH(Q |
|
282 | QFETCH(QAxis*, axis0); | |
283 | QFETCH(QLineSeries*, series1); |
|
283 | QFETCH(QLineSeries*, series1); | |
284 |
QFETCH(Q |
|
284 | QFETCH(QAxis*, axis1); | |
285 | QFETCH(QLineSeries*, series2); |
|
285 | QFETCH(QLineSeries*, series2); | |
286 |
QFETCH(Q |
|
286 | QFETCH(QAxis*, axis2); | |
287 | QFETCH(int, axisCount); |
|
287 | QFETCH(int, axisCount); | |
288 | Q_UNUSED(axisCount); |
|
288 | Q_UNUSED(axisCount); | |
289 |
|
289 | |||
290 | ChartDataSet dataSet; |
|
290 | ChartDataSet dataSet; | |
291 |
|
291 | |||
292 | dataSet.addSeries(series0, axis0); |
|
292 | dataSet.addSeries(series0, axis0); | |
293 | dataSet.addSeries(series1, axis1); |
|
293 | dataSet.addSeries(series1, axis1); | |
294 | dataSet.addSeries(series2, axis2); |
|
294 | dataSet.addSeries(series2, axis2); | |
295 |
|
295 | |||
296 |
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(Q |
|
296 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QAxis *, Domain *))); | |
297 |
QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(Q |
|
297 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QAxis *))); | |
298 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
298 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
299 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
299 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
300 |
|
300 | |||
301 | QCOMPARE(dataSet.seriesCount(series0->type()),3); |
|
301 | QCOMPARE(dataSet.seriesCount(series0->type()),3); | |
302 | QCOMPARE(spy0.count(), 0); |
|
302 | QCOMPARE(spy0.count(), 0); | |
303 | QCOMPARE(spy1.count(), 0); |
|
303 | QCOMPARE(spy1.count(), 0); | |
304 | QCOMPARE(spy2.count(), 0); |
|
304 | QCOMPARE(spy2.count(), 0); | |
305 | QCOMPARE(spy3.count(), 0); |
|
305 | QCOMPARE(spy3.count(), 0); | |
306 |
|
306 | |||
307 | dataSet.removeSeries(series0); |
|
307 | dataSet.removeSeries(series0); | |
308 | dataSet.removeSeries(series1); |
|
308 | dataSet.removeSeries(series1); | |
309 | dataSet.removeSeries(series2); |
|
309 | dataSet.removeSeries(series2); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void tst_ChartDataSet::seriesIndex_data() |
|
312 | void tst_ChartDataSet::seriesIndex_data() | |
313 | { |
|
313 | { | |
314 | addSeries_data(); |
|
314 | addSeries_data(); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void tst_ChartDataSet::seriesIndex() |
|
317 | void tst_ChartDataSet::seriesIndex() | |
318 | { |
|
318 | { | |
319 | //TODO: rewrite this series_index_data to match better |
|
319 | //TODO: rewrite this series_index_data to match better | |
320 |
|
320 | |||
321 | QFETCH(QLineSeries*, series0); |
|
321 | QFETCH(QLineSeries*, series0); | |
322 |
QFETCH(Q |
|
322 | QFETCH(QAxis*, axis0); | |
323 | QFETCH(QLineSeries*, series1); |
|
323 | QFETCH(QLineSeries*, series1); | |
324 |
QFETCH(Q |
|
324 | QFETCH(QAxis*, axis1); | |
325 | QFETCH(QLineSeries*, series2); |
|
325 | QFETCH(QLineSeries*, series2); | |
326 |
QFETCH(Q |
|
326 | QFETCH(QAxis*, axis2); | |
327 | QFETCH(int, axisCount); |
|
327 | QFETCH(int, axisCount); | |
328 | Q_UNUSED(axisCount); |
|
328 | Q_UNUSED(axisCount); | |
329 |
|
329 | |||
330 | ChartDataSet dataSet; |
|
330 | ChartDataSet dataSet; | |
331 |
|
331 | |||
332 | dataSet.addSeries(series0, axis0); |
|
332 | dataSet.addSeries(series0, axis0); | |
333 | dataSet.addSeries(series1, axis1); |
|
333 | dataSet.addSeries(series1, axis1); | |
334 | dataSet.addSeries(series2, axis2); |
|
334 | dataSet.addSeries(series2, axis2); | |
335 |
|
335 | |||
336 |
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(Q |
|
336 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QAxis*,Domain*))); | |
337 |
QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(Q |
|
337 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QAxis*))); | |
338 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); |
|
338 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); | |
339 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
339 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
340 |
|
340 | |||
341 | QCOMPARE(dataSet.seriesIndex(series0),0); |
|
341 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
342 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
342 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
343 | QCOMPARE(dataSet.seriesIndex(series2),2); |
|
343 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
344 |
|
344 | |||
345 | QCOMPARE(spy0.count(), 0); |
|
345 | QCOMPARE(spy0.count(), 0); | |
346 | QCOMPARE(spy1.count(), 0); |
|
346 | QCOMPARE(spy1.count(), 0); | |
347 | QCOMPARE(spy2.count(), 0); |
|
347 | QCOMPARE(spy2.count(), 0); | |
348 | QCOMPARE(spy3.count(), 0); |
|
348 | QCOMPARE(spy3.count(), 0); | |
349 |
|
349 | |||
350 | dataSet.removeSeries(series0); |
|
350 | dataSet.removeSeries(series0); | |
351 | dataSet.removeSeries(series1); |
|
351 | dataSet.removeSeries(series1); | |
352 | dataSet.removeSeries(series2); |
|
352 | dataSet.removeSeries(series2); | |
353 |
|
353 | |||
354 | QCOMPARE(dataSet.seriesIndex(series0),-1); |
|
354 | QCOMPARE(dataSet.seriesIndex(series0),-1); | |
355 | QCOMPARE(dataSet.seriesIndex(series1),-1); |
|
355 | QCOMPARE(dataSet.seriesIndex(series1),-1); | |
356 | QCOMPARE(dataSet.seriesIndex(series2),-1); |
|
356 | QCOMPARE(dataSet.seriesIndex(series2),-1); | |
357 |
|
357 | |||
358 | dataSet.addSeries(series0, axis0); |
|
358 | dataSet.addSeries(series0, axis0); | |
359 | dataSet.addSeries(series1, axis1); |
|
359 | dataSet.addSeries(series1, axis1); | |
360 | dataSet.addSeries(series2, axis2); |
|
360 | dataSet.addSeries(series2, axis2); | |
361 |
|
361 | |||
362 | QCOMPARE(dataSet.seriesIndex(series0),0); |
|
362 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
363 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
363 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
364 | QCOMPARE(dataSet.seriesIndex(series2),2); |
|
364 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
365 |
|
365 | |||
366 | dataSet.removeSeries(series1); |
|
366 | dataSet.removeSeries(series1); | |
367 |
|
367 | |||
368 | QCOMPARE(dataSet.seriesIndex(series0),0); |
|
368 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
369 | QCOMPARE(dataSet.seriesIndex(series1),-1); |
|
369 | QCOMPARE(dataSet.seriesIndex(series1),-1); | |
370 | QCOMPARE(dataSet.seriesIndex(series2),2); |
|
370 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
371 |
|
371 | |||
372 | dataSet.addSeries(series1, axis1); |
|
372 | dataSet.addSeries(series1, axis1); | |
373 | QCOMPARE(dataSet.seriesIndex(series0),0); |
|
373 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
374 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
374 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
375 | QCOMPARE(dataSet.seriesIndex(series2),2); |
|
375 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
376 |
|
376 | |||
377 | dataSet.removeSeries(series2); |
|
377 | dataSet.removeSeries(series2); | |
378 | QCOMPARE(dataSet.seriesIndex(series0),0); |
|
378 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
379 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
379 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
380 | QCOMPARE(dataSet.seriesIndex(series2),-1); |
|
380 | QCOMPARE(dataSet.seriesIndex(series2),-1); | |
381 |
|
381 | |||
382 | dataSet.removeSeries(series0); |
|
382 | dataSet.removeSeries(series0); | |
383 | QCOMPARE(dataSet.seriesIndex(series0),-1); |
|
383 | QCOMPARE(dataSet.seriesIndex(series0),-1); | |
384 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
384 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
385 | QCOMPARE(dataSet.seriesIndex(series2),-1); |
|
385 | QCOMPARE(dataSet.seriesIndex(series2),-1); | |
386 |
|
386 | |||
387 | dataSet.addSeries(series2); |
|
387 | dataSet.addSeries(series2); | |
388 | QCOMPARE(dataSet.seriesIndex(series0),-1); |
|
388 | QCOMPARE(dataSet.seriesIndex(series0),-1); | |
389 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
389 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
390 | QCOMPARE(dataSet.seriesIndex(series2),0); |
|
390 | QCOMPARE(dataSet.seriesIndex(series2),0); | |
391 |
|
391 | |||
392 | dataSet.addSeries(series0); |
|
392 | dataSet.addSeries(series0); | |
393 | QCOMPARE(dataSet.seriesIndex(series0),2); |
|
393 | QCOMPARE(dataSet.seriesIndex(series0),2); | |
394 | QCOMPARE(dataSet.seriesIndex(series1),1); |
|
394 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
395 | QCOMPARE(dataSet.seriesIndex(series2),0); |
|
395 | QCOMPARE(dataSet.seriesIndex(series2),0); | |
396 |
|
396 | |||
397 | dataSet.removeSeries(series0); |
|
397 | dataSet.removeSeries(series0); | |
398 | dataSet.removeSeries(series1); |
|
398 | dataSet.removeSeries(series1); | |
399 | dataSet.removeSeries(series2); |
|
399 | dataSet.removeSeries(series2); | |
400 |
|
400 | |||
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void tst_ChartDataSet::domain_data() |
|
403 | void tst_ChartDataSet::domain_data() | |
404 | { |
|
404 | { | |
405 | addSeries_data(); |
|
405 | addSeries_data(); | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void tst_ChartDataSet::domain() |
|
408 | void tst_ChartDataSet::domain() | |
409 | { |
|
409 | { | |
410 | QFETCH(QLineSeries*, series0); |
|
410 | QFETCH(QLineSeries*, series0); | |
411 |
QFETCH(Q |
|
411 | QFETCH(QAxis*, axis0); | |
412 | QFETCH(QLineSeries*, series1); |
|
412 | QFETCH(QLineSeries*, series1); | |
413 |
QFETCH(Q |
|
413 | QFETCH(QAxis*, axis1); | |
414 | QFETCH(QLineSeries*, series2); |
|
414 | QFETCH(QLineSeries*, series2); | |
415 |
QFETCH(Q |
|
415 | QFETCH(QAxis*, axis2); | |
416 | QFETCH(int, axisCount); |
|
416 | QFETCH(int, axisCount); | |
417 | Q_UNUSED(axisCount); |
|
417 | Q_UNUSED(axisCount); | |
418 |
|
418 | |||
419 | ChartDataSet dataSet; |
|
419 | ChartDataSet dataSet; | |
420 |
|
420 | |||
421 | dataSet.addSeries(series0, axis0); |
|
421 | dataSet.addSeries(series0, axis0); | |
422 | dataSet.addSeries(series1, axis1); |
|
422 | dataSet.addSeries(series1, axis1); | |
423 | dataSet.addSeries(series2, axis2); |
|
423 | dataSet.addSeries(series2, axis2); | |
424 |
|
424 | |||
425 |
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(Q |
|
425 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QAxis *, Domain *))); | |
426 |
QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(Q |
|
426 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QAxis *))); | |
427 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
427 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
428 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
428 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
429 |
|
429 | |||
430 | QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0)); |
|
430 | QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0)); | |
431 | QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1)); |
|
431 | QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1)); | |
432 | QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2)); |
|
432 | QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2)); | |
433 | QCOMPARE(spy0.count(), 0); |
|
433 | QCOMPARE(spy0.count(), 0); | |
434 | QCOMPARE(spy1.count(), 0); |
|
434 | QCOMPARE(spy1.count(), 0); | |
435 | QCOMPARE(spy2.count(), 0); |
|
435 | QCOMPARE(spy2.count(), 0); | |
436 | QCOMPARE(spy3.count(), 0); |
|
436 | QCOMPARE(spy3.count(), 0); | |
437 |
|
437 | |||
438 | dataSet.removeSeries(series0); |
|
438 | dataSet.removeSeries(series0); | |
439 | dataSet.removeSeries(series1); |
|
439 | dataSet.removeSeries(series1); | |
440 | dataSet.removeSeries(series2); |
|
440 | dataSet.removeSeries(series2); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | void tst_ChartDataSet::zoomInDomain_data() |
|
443 | void tst_ChartDataSet::zoomInDomain_data() | |
444 | { |
|
444 | { | |
445 | addSeries_data(); |
|
445 | addSeries_data(); | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | void tst_ChartDataSet::zoomInDomain() |
|
448 | void tst_ChartDataSet::zoomInDomain() | |
449 | { |
|
449 | { | |
450 | QFETCH(QLineSeries*, series0); |
|
450 | QFETCH(QLineSeries*, series0); | |
451 |
QFETCH(Q |
|
451 | QFETCH(QAxis*, axis0); | |
452 | QFETCH(QLineSeries*, series1); |
|
452 | QFETCH(QLineSeries*, series1); | |
453 |
QFETCH(Q |
|
453 | QFETCH(QAxis*, axis1); | |
454 | QFETCH(QLineSeries*, series2); |
|
454 | QFETCH(QLineSeries*, series2); | |
455 |
QFETCH(Q |
|
455 | QFETCH(QAxis*, axis2); | |
456 | QFETCH(int, axisCount); |
|
456 | QFETCH(int, axisCount); | |
457 |
|
457 | |||
458 | Q_UNUSED(axisCount); |
|
458 | Q_UNUSED(axisCount); | |
459 | ChartDataSet dataSet; |
|
459 | ChartDataSet dataSet; | |
460 |
|
460 | |||
461 | dataSet.addSeries(series0, axis0); |
|
461 | dataSet.addSeries(series0, axis0); | |
462 | dataSet.addSeries(series1, axis1); |
|
462 | dataSet.addSeries(series1, axis1); | |
463 | dataSet.addSeries(series2, axis2); |
|
463 | dataSet.addSeries(series2, axis2); | |
464 |
|
464 | |||
465 | Domain* domain0 = dataSet.domain(series0); |
|
465 | Domain* domain0 = dataSet.domain(series0); | |
466 | Domain* domain1 = dataSet.domain(series1); |
|
466 | Domain* domain1 = dataSet.domain(series1); | |
467 | Domain* domain2 = dataSet.domain(series2); |
|
467 | Domain* domain2 = dataSet.domain(series2); | |
468 |
|
468 | |||
469 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
469 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
470 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
470 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
471 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
471 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
472 |
|
472 | |||
473 | dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
473 | dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
474 |
|
474 | |||
475 | QCOMPARE(spy0.count(), 1); |
|
475 | QCOMPARE(spy0.count(), 1); | |
476 | QCOMPARE(spy1.count(), 1); |
|
476 | QCOMPARE(spy1.count(), 1); | |
477 | QCOMPARE(spy2.count(), 1); |
|
477 | QCOMPARE(spy2.count(), 1); | |
478 |
|
478 | |||
479 | dataSet.removeSeries(series0); |
|
479 | dataSet.removeSeries(series0); | |
480 | dataSet.removeSeries(series1); |
|
480 | dataSet.removeSeries(series1); | |
481 | dataSet.removeSeries(series2); |
|
481 | dataSet.removeSeries(series2); | |
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | void tst_ChartDataSet::zoomOutDomain_data() |
|
484 | void tst_ChartDataSet::zoomOutDomain_data() | |
485 | { |
|
485 | { | |
486 | addSeries_data(); |
|
486 | addSeries_data(); | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | void tst_ChartDataSet::zoomOutDomain() |
|
489 | void tst_ChartDataSet::zoomOutDomain() | |
490 | { |
|
490 | { | |
491 | QFETCH(QLineSeries*, series0); |
|
491 | QFETCH(QLineSeries*, series0); | |
492 |
QFETCH(Q |
|
492 | QFETCH(QAxis*, axis0); | |
493 | QFETCH(QLineSeries*, series1); |
|
493 | QFETCH(QLineSeries*, series1); | |
494 |
QFETCH(Q |
|
494 | QFETCH(QAxis*, axis1); | |
495 | QFETCH(QLineSeries*, series2); |
|
495 | QFETCH(QLineSeries*, series2); | |
496 |
QFETCH(Q |
|
496 | QFETCH(QAxis*, axis2); | |
497 | QFETCH(int, axisCount); |
|
497 | QFETCH(int, axisCount); | |
498 |
|
498 | |||
499 | Q_UNUSED(axisCount); |
|
499 | Q_UNUSED(axisCount); | |
500 |
|
500 | |||
501 | ChartDataSet dataSet; |
|
501 | ChartDataSet dataSet; | |
502 |
|
502 | |||
503 | dataSet.addSeries(series0, axis0); |
|
503 | dataSet.addSeries(series0, axis0); | |
504 | dataSet.addSeries(series1, axis1); |
|
504 | dataSet.addSeries(series1, axis1); | |
505 | dataSet.addSeries(series2, axis2); |
|
505 | dataSet.addSeries(series2, axis2); | |
506 |
|
506 | |||
507 | Domain* domain0 = dataSet.domain(series0); |
|
507 | Domain* domain0 = dataSet.domain(series0); | |
508 | Domain* domain1 = dataSet.domain(series1); |
|
508 | Domain* domain1 = dataSet.domain(series1); | |
509 | Domain* domain2 = dataSet.domain(series2); |
|
509 | Domain* domain2 = dataSet.domain(series2); | |
510 |
|
510 | |||
511 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
511 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
512 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
512 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
513 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
513 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
514 |
|
514 | |||
515 | dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
515 | dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
516 |
|
516 | |||
517 | QCOMPARE(spy0.count(), 1); |
|
517 | QCOMPARE(spy0.count(), 1); | |
518 | QCOMPARE(spy1.count(), 1); |
|
518 | QCOMPARE(spy1.count(), 1); | |
519 | QCOMPARE(spy2.count(), 1); |
|
519 | QCOMPARE(spy2.count(), 1); | |
520 |
|
520 | |||
521 | dataSet.removeSeries(series0); |
|
521 | dataSet.removeSeries(series0); | |
522 | dataSet.removeSeries(series1); |
|
522 | dataSet.removeSeries(series1); | |
523 | dataSet.removeSeries(series2); |
|
523 | dataSet.removeSeries(series2); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | void tst_ChartDataSet::scrollDomain_data() |
|
526 | void tst_ChartDataSet::scrollDomain_data() | |
527 | { |
|
527 | { | |
528 | addSeries_data(); |
|
528 | addSeries_data(); | |
529 | } |
|
529 | } | |
530 |
|
530 | |||
531 | void tst_ChartDataSet::scrollDomain() |
|
531 | void tst_ChartDataSet::scrollDomain() | |
532 | { |
|
532 | { | |
533 | QFETCH(QLineSeries*, series0); |
|
533 | QFETCH(QLineSeries*, series0); | |
534 |
QFETCH(Q |
|
534 | QFETCH(QAxis*, axis0); | |
535 | QFETCH(QLineSeries*, series1); |
|
535 | QFETCH(QLineSeries*, series1); | |
536 |
QFETCH(Q |
|
536 | QFETCH(QAxis*, axis1); | |
537 | QFETCH(QLineSeries*, series2); |
|
537 | QFETCH(QLineSeries*, series2); | |
538 |
QFETCH(Q |
|
538 | QFETCH(QAxis*, axis2); | |
539 | QFETCH(int, axisCount); |
|
539 | QFETCH(int, axisCount); | |
540 |
|
540 | |||
541 | Q_UNUSED(axisCount); |
|
541 | Q_UNUSED(axisCount); | |
542 |
|
542 | |||
543 | ChartDataSet dataSet; |
|
543 | ChartDataSet dataSet; | |
544 |
|
544 | |||
545 | dataSet.addSeries(series0, axis0); |
|
545 | dataSet.addSeries(series0, axis0); | |
546 | dataSet.addSeries(series1, axis1); |
|
546 | dataSet.addSeries(series1, axis1); | |
547 | dataSet.addSeries(series2, axis2); |
|
547 | dataSet.addSeries(series2, axis2); | |
548 |
|
548 | |||
549 | Domain* domain0 = dataSet.domain(series0); |
|
549 | Domain* domain0 = dataSet.domain(series0); | |
550 | Domain* domain1 = dataSet.domain(series1); |
|
550 | Domain* domain1 = dataSet.domain(series1); | |
551 | Domain* domain2 = dataSet.domain(series2); |
|
551 | Domain* domain2 = dataSet.domain(series2); | |
552 |
|
552 | |||
553 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
553 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
554 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
554 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
555 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
555 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
556 |
|
556 | |||
557 | dataSet.scrollDomain(10,10,QSize(1000,1000)); |
|
557 | dataSet.scrollDomain(10,10,QSize(1000,1000)); | |
558 |
|
558 | |||
559 | QCOMPARE(spy0.count(), 1); |
|
559 | QCOMPARE(spy0.count(), 1); | |
560 | QCOMPARE(spy1.count(), 1); |
|
560 | QCOMPARE(spy1.count(), 1); | |
561 | QCOMPARE(spy2.count(), 1); |
|
561 | QCOMPARE(spy2.count(), 1); | |
562 |
|
562 | |||
563 | dataSet.removeSeries(series0); |
|
563 | dataSet.removeSeries(series0); | |
564 | dataSet.removeSeries(series1); |
|
564 | dataSet.removeSeries(series1); | |
565 | dataSet.removeSeries(series2); |
|
565 | dataSet.removeSeries(series2); | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | QTEST_MAIN(tst_ChartDataSet) |
|
568 | QTEST_MAIN(tst_ChartDataSet) | |
569 | #include "tst_chartdataset.moc" |
|
569 | #include "tst_chartdataset.moc" | |
570 |
|
570 |
@@ -1,712 +1,712 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <private/domain_p.h> |
|
22 | #include <private/domain_p.h> | |
23 |
#include <q |
|
23 | #include <qaxis.h> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
26 | |||
27 | Q_DECLARE_METATYPE(Domain*) |
|
27 | Q_DECLARE_METATYPE(Domain*) | |
28 | Q_DECLARE_METATYPE(QSizeF) |
|
28 | Q_DECLARE_METATYPE(QSizeF) | |
29 |
|
29 | |||
30 | class tst_Domain: public QObject |
|
30 | class tst_Domain: public QObject | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 |
|
33 | |||
34 | public Q_SLOTS: |
|
34 | public Q_SLOTS: | |
35 | void initTestCase(); |
|
35 | void initTestCase(); | |
36 | void cleanupTestCase(); |
|
36 | void cleanupTestCase(); | |
37 | void init(); |
|
37 | void init(); | |
38 | void cleanup(); |
|
38 | void cleanup(); | |
39 |
|
39 | |||
40 | private Q_SLOTS: |
|
40 | private Q_SLOTS: | |
41 | void domain(); |
|
41 | void domain(); | |
42 | void handleAxisRangeXChanged_data(); |
|
42 | void handleAxisRangeXChanged_data(); | |
43 | void handleAxisRangeXChanged(); |
|
43 | void handleAxisRangeXChanged(); | |
44 | void handleAxisRangeYChanged_data(); |
|
44 | void handleAxisRangeYChanged_data(); | |
45 | void handleAxisRangeYChanged(); |
|
45 | void handleAxisRangeYChanged(); | |
46 | void isEmpty_data(); |
|
46 | void isEmpty_data(); | |
47 | void isEmpty(); |
|
47 | void isEmpty(); | |
48 | void maxX_data(); |
|
48 | void maxX_data(); | |
49 | void maxX(); |
|
49 | void maxX(); | |
50 | void maxY_data(); |
|
50 | void maxY_data(); | |
51 | void maxY(); |
|
51 | void maxY(); | |
52 | void minX_data(); |
|
52 | void minX_data(); | |
53 | void minX(); |
|
53 | void minX(); | |
54 | void minY_data(); |
|
54 | void minY_data(); | |
55 | void minY(); |
|
55 | void minY(); | |
56 | void operatorEquals_data(); |
|
56 | void operatorEquals_data(); | |
57 | void operatorEquals(); |
|
57 | void operatorEquals(); | |
58 | void setRange_data(); |
|
58 | void setRange_data(); | |
59 | void setRange(); |
|
59 | void setRange(); | |
60 | void setRangeX_data(); |
|
60 | void setRangeX_data(); | |
61 | void setRangeX(); |
|
61 | void setRangeX(); | |
62 | void setRangeY_data(); |
|
62 | void setRangeY_data(); | |
63 | void setRangeY(); |
|
63 | void setRangeY(); | |
64 | void spanX_data(); |
|
64 | void spanX_data(); | |
65 | void spanX(); |
|
65 | void spanX(); | |
66 | void spanY_data(); |
|
66 | void spanY_data(); | |
67 | void spanY(); |
|
67 | void spanY(); | |
68 | void zoom_data(); |
|
68 | void zoom_data(); | |
69 | void zoom(); |
|
69 | void zoom(); | |
70 | void move_data(); |
|
70 | void move_data(); | |
71 | void move(); |
|
71 | void move(); | |
72 | void handleAxisXChanged_data(); |
|
72 | void handleAxisXChanged_data(); | |
73 | void handleAxisXChanged(); |
|
73 | void handleAxisXChanged(); | |
74 | void handleAxisYChanged_data(); |
|
74 | void handleAxisYChanged_data(); | |
75 | void handleAxisYChanged(); |
|
75 | void handleAxisYChanged(); | |
76 | }; |
|
76 | }; | |
77 |
|
77 | |||
78 | void tst_Domain::initTestCase() |
|
78 | void tst_Domain::initTestCase() | |
79 | { |
|
79 | { | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void tst_Domain::cleanupTestCase() |
|
82 | void tst_Domain::cleanupTestCase() | |
83 | { |
|
83 | { | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void tst_Domain::init() |
|
86 | void tst_Domain::init() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_Domain::cleanup() |
|
90 | void tst_Domain::cleanup() | |
91 | { |
|
91 | { | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void tst_Domain::domain() |
|
94 | void tst_Domain::domain() | |
95 | { |
|
95 | { | |
96 | Domain domain; |
|
96 | Domain domain; | |
97 |
|
97 | |||
98 | QCOMPARE(domain.isEmpty(), true); |
|
98 | QCOMPARE(domain.isEmpty(), true); | |
99 | QCOMPARE(domain.maxX(), 0.0); |
|
99 | QCOMPARE(domain.maxX(), 0.0); | |
100 | QCOMPARE(domain.maxY(), 0.0); |
|
100 | QCOMPARE(domain.maxY(), 0.0); | |
101 | QCOMPARE(domain.minX(), 0.0); |
|
101 | QCOMPARE(domain.minX(), 0.0); | |
102 | QCOMPARE(domain.minY(), 0.0); |
|
102 | QCOMPARE(domain.minY(), 0.0); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void tst_Domain::handleAxisRangeXChanged_data() |
|
105 | void tst_Domain::handleAxisRangeXChanged_data() | |
106 | { |
|
106 | { | |
107 | QTest::addColumn<qreal>("min"); |
|
107 | QTest::addColumn<qreal>("min"); | |
108 | QTest::addColumn<qreal>("max"); |
|
108 | QTest::addColumn<qreal>("max"); | |
109 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
109 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
110 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
110 | QTest::newRow("0 1") << 0.0 << 1.0; | |
111 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
111 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void tst_Domain::handleAxisRangeXChanged() |
|
114 | void tst_Domain::handleAxisRangeXChanged() | |
115 | { |
|
115 | { | |
116 | QFETCH(qreal, min); |
|
116 | QFETCH(qreal, min); | |
117 | QFETCH(qreal, max); |
|
117 | QFETCH(qreal, max); | |
118 |
|
118 | |||
119 | Domain domain; |
|
119 | Domain domain; | |
120 |
|
120 | |||
121 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
121 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
122 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
122 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
123 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
123 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
124 |
|
124 | |||
125 | domain.handleAxisXChanged(min, max); |
|
125 | domain.handleAxisXChanged(min, max); | |
126 |
|
126 | |||
127 | QList<QVariant> arg0 = spy0.first(); |
|
127 | QList<QVariant> arg0 = spy0.first(); | |
128 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); |
|
128 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); | |
129 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); |
|
129 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); | |
130 |
|
130 | |||
131 | QList<QVariant> arg1 = spy1.first(); |
|
131 | QList<QVariant> arg1 = spy1.first(); | |
132 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
132 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
133 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
133 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
134 |
|
134 | |||
135 | QCOMPARE(spy0.count(), 1); |
|
135 | QCOMPARE(spy0.count(), 1); | |
136 | QCOMPARE(spy1.count(), 1); |
|
136 | QCOMPARE(spy1.count(), 1); | |
137 | QCOMPARE(spy2.count(), 0); |
|
137 | QCOMPARE(spy2.count(), 0); | |
138 |
|
138 | |||
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void tst_Domain::handleAxisRangeYChanged_data() |
|
141 | void tst_Domain::handleAxisRangeYChanged_data() | |
142 | { |
|
142 | { | |
143 | QTest::addColumn<qreal>("min"); |
|
143 | QTest::addColumn<qreal>("min"); | |
144 | QTest::addColumn<qreal>("max"); |
|
144 | QTest::addColumn<qreal>("max"); | |
145 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
145 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
146 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
146 | QTest::newRow("0 1") << 0.0 << 1.0; | |
147 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
147 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void tst_Domain::handleAxisRangeYChanged() |
|
150 | void tst_Domain::handleAxisRangeYChanged() | |
151 | { |
|
151 | { | |
152 | QFETCH(qreal, min); |
|
152 | QFETCH(qreal, min); | |
153 | QFETCH(qreal, max); |
|
153 | QFETCH(qreal, max); | |
154 |
|
154 | |||
155 | Domain domain; |
|
155 | Domain domain; | |
156 |
|
156 | |||
157 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
157 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
158 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
158 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
159 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
159 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
160 |
|
160 | |||
161 | domain.handleAxisYChanged(min, max, 5); |
|
161 | domain.handleAxisYChanged(min, max, 5); | |
162 |
|
162 | |||
163 | QList<QVariant> arg0 = spy0.first(); |
|
163 | QList<QVariant> arg0 = spy0.first(); | |
164 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); |
|
164 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); | |
165 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); |
|
165 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); | |
166 |
|
166 | |||
167 | QList<QVariant> arg1 = spy2.first(); |
|
167 | QList<QVariant> arg1 = spy2.first(); | |
168 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
168 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
169 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
169 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
170 |
|
170 | |||
171 | QCOMPARE(spy0.count(), 1); |
|
171 | QCOMPARE(spy0.count(), 1); | |
172 | QCOMPARE(spy1.count(), 0); |
|
172 | QCOMPARE(spy1.count(), 0); | |
173 | QCOMPARE(spy2.count(), 1); |
|
173 | QCOMPARE(spy2.count(), 1); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void tst_Domain::isEmpty_data() |
|
176 | void tst_Domain::isEmpty_data() | |
177 | { |
|
177 | { | |
178 | QTest::addColumn<qreal>("minX"); |
|
178 | QTest::addColumn<qreal>("minX"); | |
179 | QTest::addColumn<qreal>("maxX"); |
|
179 | QTest::addColumn<qreal>("maxX"); | |
180 | QTest::addColumn<qreal>("minY"); |
|
180 | QTest::addColumn<qreal>("minY"); | |
181 | QTest::addColumn<qreal>("maxY"); |
|
181 | QTest::addColumn<qreal>("maxY"); | |
182 | QTest::addColumn<bool>("isEmpty"); |
|
182 | QTest::addColumn<bool>("isEmpty"); | |
183 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
183 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; | |
184 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
184 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; | |
185 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
185 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; | |
186 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
186 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void tst_Domain::isEmpty() |
|
189 | void tst_Domain::isEmpty() | |
190 | { |
|
190 | { | |
191 | QFETCH(qreal, minX); |
|
191 | QFETCH(qreal, minX); | |
192 | QFETCH(qreal, maxX); |
|
192 | QFETCH(qreal, maxX); | |
193 | QFETCH(qreal, minY); |
|
193 | QFETCH(qreal, minY); | |
194 | QFETCH(qreal, maxY); |
|
194 | QFETCH(qreal, maxY); | |
195 | QFETCH(bool, isEmpty); |
|
195 | QFETCH(bool, isEmpty); | |
196 |
|
196 | |||
197 | Domain domain; |
|
197 | Domain domain; | |
198 | domain.setRange(minX, maxX, minY, maxY); |
|
198 | domain.setRange(minX, maxX, minY, maxY); | |
199 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
199 | QCOMPARE(domain.isEmpty(), isEmpty); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void tst_Domain::maxX_data() |
|
202 | void tst_Domain::maxX_data() | |
203 | { |
|
203 | { | |
204 | QTest::addColumn<qreal>("maxX1"); |
|
204 | QTest::addColumn<qreal>("maxX1"); | |
205 | QTest::addColumn<qreal>("maxX2"); |
|
205 | QTest::addColumn<qreal>("maxX2"); | |
206 | QTest::addColumn<int>("count"); |
|
206 | QTest::addColumn<int>("count"); | |
207 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
207 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
208 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
208 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
209 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
209 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void tst_Domain::maxX() |
|
212 | void tst_Domain::maxX() | |
213 | { |
|
213 | { | |
214 | QFETCH(qreal, maxX1); |
|
214 | QFETCH(qreal, maxX1); | |
215 | QFETCH(qreal, maxX2); |
|
215 | QFETCH(qreal, maxX2); | |
216 | QFETCH(int, count); |
|
216 | QFETCH(int, count); | |
217 |
|
217 | |||
218 | Domain domain; |
|
218 | Domain domain; | |
219 |
|
219 | |||
220 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
220 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
221 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
221 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
222 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
222 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
223 |
|
223 | |||
224 | domain.setMaxX(maxX1); |
|
224 | domain.setMaxX(maxX1); | |
225 | QCOMPARE(domain.maxX(), maxX1); |
|
225 | QCOMPARE(domain.maxX(), maxX1); | |
226 | domain.setMaxX(maxX2); |
|
226 | domain.setMaxX(maxX2); | |
227 | QCOMPARE(domain.maxX(), maxX2); |
|
227 | QCOMPARE(domain.maxX(), maxX2); | |
228 |
|
228 | |||
229 | QCOMPARE(spy0.count(), count); |
|
229 | QCOMPARE(spy0.count(), count); | |
230 | QCOMPARE(spy1.count(), count); |
|
230 | QCOMPARE(spy1.count(), count); | |
231 | QCOMPARE(spy2.count(), 0); |
|
231 | QCOMPARE(spy2.count(), 0); | |
232 |
|
232 | |||
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void tst_Domain::maxY_data() |
|
235 | void tst_Domain::maxY_data() | |
236 | { |
|
236 | { | |
237 | QTest::addColumn<qreal>("maxY1"); |
|
237 | QTest::addColumn<qreal>("maxY1"); | |
238 | QTest::addColumn<qreal>("maxY2"); |
|
238 | QTest::addColumn<qreal>("maxY2"); | |
239 | QTest::addColumn<int>("count"); |
|
239 | QTest::addColumn<int>("count"); | |
240 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
240 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
241 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
241 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
242 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
242 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void tst_Domain::maxY() |
|
245 | void tst_Domain::maxY() | |
246 | { |
|
246 | { | |
247 | QFETCH(qreal, maxY1); |
|
247 | QFETCH(qreal, maxY1); | |
248 | QFETCH(qreal, maxY2); |
|
248 | QFETCH(qreal, maxY2); | |
249 | QFETCH(int, count); |
|
249 | QFETCH(int, count); | |
250 |
|
250 | |||
251 | Domain domain; |
|
251 | Domain domain; | |
252 |
|
252 | |||
253 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
253 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
254 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
254 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
255 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
255 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
256 |
|
256 | |||
257 | domain.setMaxY(maxY1); |
|
257 | domain.setMaxY(maxY1); | |
258 | QCOMPARE(domain.maxY(), maxY1); |
|
258 | QCOMPARE(domain.maxY(), maxY1); | |
259 | domain.setMaxY(maxY2); |
|
259 | domain.setMaxY(maxY2); | |
260 | QCOMPARE(domain.maxY(), maxY2); |
|
260 | QCOMPARE(domain.maxY(), maxY2); | |
261 |
|
261 | |||
262 | QCOMPARE(spy0.count(), count); |
|
262 | QCOMPARE(spy0.count(), count); | |
263 | QCOMPARE(spy1.count(), 0); |
|
263 | QCOMPARE(spy1.count(), 0); | |
264 | QCOMPARE(spy2.count(), count); |
|
264 | QCOMPARE(spy2.count(), count); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void tst_Domain::minX_data() |
|
267 | void tst_Domain::minX_data() | |
268 | { |
|
268 | { | |
269 | QTest::addColumn<qreal>("minX1"); |
|
269 | QTest::addColumn<qreal>("minX1"); | |
270 | QTest::addColumn<qreal>("minX2"); |
|
270 | QTest::addColumn<qreal>("minX2"); | |
271 | QTest::addColumn<int>("count"); |
|
271 | QTest::addColumn<int>("count"); | |
272 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
272 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
273 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
273 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
274 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
274 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void tst_Domain::minX() |
|
277 | void tst_Domain::minX() | |
278 | { |
|
278 | { | |
279 | QFETCH(qreal, minX1); |
|
279 | QFETCH(qreal, minX1); | |
280 | QFETCH(qreal, minX2); |
|
280 | QFETCH(qreal, minX2); | |
281 | QFETCH(int, count); |
|
281 | QFETCH(int, count); | |
282 |
|
282 | |||
283 | Domain domain; |
|
283 | Domain domain; | |
284 |
|
284 | |||
285 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
285 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
286 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
286 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
287 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
287 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
288 |
|
288 | |||
289 | domain.setMinX(minX1); |
|
289 | domain.setMinX(minX1); | |
290 | QCOMPARE(domain.minX(), minX1); |
|
290 | QCOMPARE(domain.minX(), minX1); | |
291 | domain.setMinX(minX2); |
|
291 | domain.setMinX(minX2); | |
292 | QCOMPARE(domain.minX(), minX2); |
|
292 | QCOMPARE(domain.minX(), minX2); | |
293 |
|
293 | |||
294 | QCOMPARE(spy0.count(), count); |
|
294 | QCOMPARE(spy0.count(), count); | |
295 | QCOMPARE(spy1.count(), count); |
|
295 | QCOMPARE(spy1.count(), count); | |
296 | QCOMPARE(spy2.count(), 0); |
|
296 | QCOMPARE(spy2.count(), 0); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | void tst_Domain::minY_data() |
|
299 | void tst_Domain::minY_data() | |
300 | { |
|
300 | { | |
301 | QTest::addColumn<qreal>("minY1"); |
|
301 | QTest::addColumn<qreal>("minY1"); | |
302 | QTest::addColumn<qreal>("minY2"); |
|
302 | QTest::addColumn<qreal>("minY2"); | |
303 | QTest::addColumn<int>("count"); |
|
303 | QTest::addColumn<int>("count"); | |
304 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
304 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
305 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
305 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
306 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
306 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void tst_Domain::minY() |
|
309 | void tst_Domain::minY() | |
310 | { |
|
310 | { | |
311 | QFETCH(qreal, minY1); |
|
311 | QFETCH(qreal, minY1); | |
312 | QFETCH(qreal, minY2); |
|
312 | QFETCH(qreal, minY2); | |
313 | QFETCH(int, count); |
|
313 | QFETCH(int, count); | |
314 |
|
314 | |||
315 | Domain domain; |
|
315 | Domain domain; | |
316 |
|
316 | |||
317 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
317 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
318 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
318 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
319 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
319 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
320 |
|
320 | |||
321 | domain.setMinY(minY1); |
|
321 | domain.setMinY(minY1); | |
322 | QCOMPARE(domain.minY(), minY1); |
|
322 | QCOMPARE(domain.minY(), minY1); | |
323 | domain.setMinY(minY2); |
|
323 | domain.setMinY(minY2); | |
324 | QCOMPARE(domain.minY(), minY2); |
|
324 | QCOMPARE(domain.minY(), minY2); | |
325 |
|
325 | |||
326 | QCOMPARE(spy0.count(), count); |
|
326 | QCOMPARE(spy0.count(), count); | |
327 | QCOMPARE(spy1.count(), 0); |
|
327 | QCOMPARE(spy1.count(), 0); | |
328 | QCOMPARE(spy2.count(), count); |
|
328 | QCOMPARE(spy2.count(), count); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | void tst_Domain::operatorEquals_data() |
|
331 | void tst_Domain::operatorEquals_data() | |
332 | { |
|
332 | { | |
333 |
|
333 | |||
334 | QTest::addColumn<Domain*>("domain1"); |
|
334 | QTest::addColumn<Domain*>("domain1"); | |
335 | QTest::addColumn<Domain*>("domain2"); |
|
335 | QTest::addColumn<Domain*>("domain2"); | |
336 | QTest::addColumn<bool>("equals"); |
|
336 | QTest::addColumn<bool>("equals"); | |
337 | QTest::addColumn<bool>("notEquals"); |
|
337 | QTest::addColumn<bool>("notEquals"); | |
338 | Domain* a; |
|
338 | Domain* a; | |
339 | Domain* b; |
|
339 | Domain* b; | |
340 | a = new Domain(); |
|
340 | a = new Domain(); | |
341 | a->setRange(0, 100, 0, 100); |
|
341 | a->setRange(0, 100, 0, 100); | |
342 | b = new Domain(); |
|
342 | b = new Domain(); | |
343 | b->setRange(0, 100, 0, 100); |
|
343 | b->setRange(0, 100, 0, 100); | |
344 | QTest::newRow("equals") << a << b << true << false; |
|
344 | QTest::newRow("equals") << a << b << true << false; | |
345 | a = new Domain(); |
|
345 | a = new Domain(); | |
346 | a->setRange(0, 100, 0, 100); |
|
346 | a->setRange(0, 100, 0, 100); | |
347 | b = new Domain(); |
|
347 | b = new Domain(); | |
348 | b->setRange(0, 100, 0, 1); |
|
348 | b->setRange(0, 100, 0, 1); | |
349 | QTest::newRow("equals") << a << b << false << true; |
|
349 | QTest::newRow("equals") << a << b << false << true; | |
350 | a = new Domain(); |
|
350 | a = new Domain(); | |
351 | a->setRange(0, 100, 0, 100); |
|
351 | a->setRange(0, 100, 0, 100); | |
352 | b = new Domain(); |
|
352 | b = new Domain(); | |
353 | b->setRange(0, 1, 0, 100); |
|
353 | b->setRange(0, 1, 0, 100); | |
354 | QTest::newRow("equals") << a << b << false << true; |
|
354 | QTest::newRow("equals") << a << b << false << true; | |
355 |
|
355 | |||
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | void tst_Domain::operatorEquals() |
|
358 | void tst_Domain::operatorEquals() | |
359 | { |
|
359 | { | |
360 | QFETCH(Domain*, domain1); |
|
360 | QFETCH(Domain*, domain1); | |
361 | QFETCH(Domain*, domain2); |
|
361 | QFETCH(Domain*, domain2); | |
362 | QFETCH(bool, equals); |
|
362 | QFETCH(bool, equals); | |
363 | QFETCH(bool, notEquals); |
|
363 | QFETCH(bool, notEquals); | |
364 |
|
364 | |||
365 | Domain domain; |
|
365 | Domain domain; | |
366 |
|
366 | |||
367 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
367 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
368 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
368 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
369 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
369 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
370 |
|
370 | |||
371 | QCOMPARE(*domain1==*domain2, equals); |
|
371 | QCOMPARE(*domain1==*domain2, equals); | |
372 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
372 | QCOMPARE(*domain1!=*domain2, notEquals); | |
373 |
|
373 | |||
374 | QCOMPARE(spy0.count(), 0); |
|
374 | QCOMPARE(spy0.count(), 0); | |
375 | QCOMPARE(spy1.count(), 0); |
|
375 | QCOMPARE(spy1.count(), 0); | |
376 | QCOMPARE(spy2.count(), 0); |
|
376 | QCOMPARE(spy2.count(), 0); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | void tst_Domain::setRange_data() |
|
379 | void tst_Domain::setRange_data() | |
380 | { |
|
380 | { | |
381 | QTest::addColumn<qreal>("minX"); |
|
381 | QTest::addColumn<qreal>("minX"); | |
382 | QTest::addColumn<qreal>("maxX"); |
|
382 | QTest::addColumn<qreal>("maxX"); | |
383 | QTest::addColumn<qreal>("minY"); |
|
383 | QTest::addColumn<qreal>("minY"); | |
384 | QTest::addColumn<qreal>("maxY"); |
|
384 | QTest::addColumn<qreal>("maxY"); | |
385 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
385 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; | |
386 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
386 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; | |
387 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
387 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | void tst_Domain::setRange() |
|
390 | void tst_Domain::setRange() | |
391 | { |
|
391 | { | |
392 | QFETCH(qreal, minX); |
|
392 | QFETCH(qreal, minX); | |
393 | QFETCH(qreal, maxX); |
|
393 | QFETCH(qreal, maxX); | |
394 | QFETCH(qreal, minY); |
|
394 | QFETCH(qreal, minY); | |
395 | QFETCH(qreal, maxY); |
|
395 | QFETCH(qreal, maxY); | |
396 |
|
396 | |||
397 | Domain domain; |
|
397 | Domain domain; | |
398 |
|
398 | |||
399 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
399 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
400 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
400 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
401 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
401 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
402 |
|
402 | |||
403 | domain.setRange(minX, maxX, minY, maxY); |
|
403 | domain.setRange(minX, maxX, minY, maxY); | |
404 |
|
404 | |||
405 | QCOMPARE(domain.minX(), minX); |
|
405 | QCOMPARE(domain.minX(), minX); | |
406 | QCOMPARE(domain.maxX(), maxX); |
|
406 | QCOMPARE(domain.maxX(), maxX); | |
407 | QCOMPARE(domain.minY(), minY); |
|
407 | QCOMPARE(domain.minY(), minY); | |
408 | QCOMPARE(domain.maxY(), maxY); |
|
408 | QCOMPARE(domain.maxY(), maxY); | |
409 |
|
409 | |||
410 | QCOMPARE(spy0.count(), 1); |
|
410 | QCOMPARE(spy0.count(), 1); | |
411 | QCOMPARE(spy1.count(), 1); |
|
411 | QCOMPARE(spy1.count(), 1); | |
412 | QCOMPARE(spy2.count(), 1); |
|
412 | QCOMPARE(spy2.count(), 1); | |
413 |
|
413 | |||
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | void tst_Domain::setRangeX_data() |
|
416 | void tst_Domain::setRangeX_data() | |
417 | { |
|
417 | { | |
418 | QTest::addColumn<qreal>("min"); |
|
418 | QTest::addColumn<qreal>("min"); | |
419 | QTest::addColumn<qreal>("max"); |
|
419 | QTest::addColumn<qreal>("max"); | |
420 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
420 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
421 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
421 | QTest::newRow("0 1") << 0.0 << 1.0; | |
422 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
422 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void tst_Domain::setRangeX() |
|
425 | void tst_Domain::setRangeX() | |
426 | { |
|
426 | { | |
427 | QFETCH(qreal, min); |
|
427 | QFETCH(qreal, min); | |
428 | QFETCH(qreal, max); |
|
428 | QFETCH(qreal, max); | |
429 |
|
429 | |||
430 | Domain domain; |
|
430 | Domain domain; | |
431 |
|
431 | |||
432 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
432 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
433 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
433 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
434 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
434 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
435 |
|
435 | |||
436 | domain.setRangeX(min, max); |
|
436 | domain.setRangeX(min, max); | |
437 |
|
437 | |||
438 | QList<QVariant> arg0 = spy0.first(); |
|
438 | QList<QVariant> arg0 = spy0.first(); | |
439 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); |
|
439 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); | |
440 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); |
|
440 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); | |
441 |
|
441 | |||
442 | QList<QVariant> arg1 = spy1.first(); |
|
442 | QList<QVariant> arg1 = spy1.first(); | |
443 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
443 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
444 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
444 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
445 |
|
445 | |||
446 | QCOMPARE(spy0.count(), 1); |
|
446 | QCOMPARE(spy0.count(), 1); | |
447 | QCOMPARE(spy1.count(), 1); |
|
447 | QCOMPARE(spy1.count(), 1); | |
448 | QCOMPARE(spy2.count(), 0); |
|
448 | QCOMPARE(spy2.count(), 0); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void tst_Domain::setRangeY_data() |
|
451 | void tst_Domain::setRangeY_data() | |
452 | { |
|
452 | { | |
453 | QTest::addColumn<qreal>("min"); |
|
453 | QTest::addColumn<qreal>("min"); | |
454 | QTest::addColumn<qreal>("max"); |
|
454 | QTest::addColumn<qreal>("max"); | |
455 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
455 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
456 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
456 | QTest::newRow("0 1") << 0.0 << 1.0; | |
457 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
457 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 | void tst_Domain::setRangeY() |
|
460 | void tst_Domain::setRangeY() | |
461 | { |
|
461 | { | |
462 | QFETCH(qreal, min); |
|
462 | QFETCH(qreal, min); | |
463 | QFETCH(qreal, max); |
|
463 | QFETCH(qreal, max); | |
464 |
|
464 | |||
465 | Domain domain; |
|
465 | Domain domain; | |
466 |
|
466 | |||
467 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
467 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
468 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
468 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
469 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
469 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
470 |
|
470 | |||
471 | domain.setRangeY(min, max); |
|
471 | domain.setRangeY(min, max); | |
472 |
|
472 | |||
473 | QList<QVariant> arg0 = spy0.first(); |
|
473 | QList<QVariant> arg0 = spy0.first(); | |
474 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); |
|
474 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); | |
475 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); |
|
475 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); | |
476 |
|
476 | |||
477 | QList<QVariant> arg1 = spy2.first(); |
|
477 | QList<QVariant> arg1 = spy2.first(); | |
478 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
478 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
479 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
479 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
480 |
|
480 | |||
481 | QCOMPARE(spy0.count(), 1); |
|
481 | QCOMPARE(spy0.count(), 1); | |
482 | QCOMPARE(spy1.count(), 0); |
|
482 | QCOMPARE(spy1.count(), 0); | |
483 | QCOMPARE(spy2.count(), 1); |
|
483 | QCOMPARE(spy2.count(), 1); | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | void tst_Domain::spanX_data() |
|
486 | void tst_Domain::spanX_data() | |
487 | { |
|
487 | { | |
488 | QTest::addColumn<qreal>("minX"); |
|
488 | QTest::addColumn<qreal>("minX"); | |
489 | QTest::addColumn<qreal>("maxX"); |
|
489 | QTest::addColumn<qreal>("maxX"); | |
490 | QTest::addColumn<qreal>("spanX"); |
|
490 | QTest::addColumn<qreal>("spanX"); | |
491 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
491 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | |
492 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
492 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | void tst_Domain::spanX() |
|
495 | void tst_Domain::spanX() | |
496 | { |
|
496 | { | |
497 | QFETCH(qreal, minX); |
|
497 | QFETCH(qreal, minX); | |
498 | QFETCH(qreal, maxX); |
|
498 | QFETCH(qreal, maxX); | |
499 | QFETCH(qreal, spanX); |
|
499 | QFETCH(qreal, spanX); | |
500 |
|
500 | |||
501 | Domain domain; |
|
501 | Domain domain; | |
502 |
|
502 | |||
503 | domain.setRangeX(minX, maxX); |
|
503 | domain.setRangeX(minX, maxX); | |
504 |
|
504 | |||
505 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
505 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
506 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
506 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
507 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
507 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
508 |
|
508 | |||
509 | QCOMPARE(domain.spanX(), spanX); |
|
509 | QCOMPARE(domain.spanX(), spanX); | |
510 |
|
510 | |||
511 | QCOMPARE(spy0.count(), 0); |
|
511 | QCOMPARE(spy0.count(), 0); | |
512 | QCOMPARE(spy1.count(), 0); |
|
512 | QCOMPARE(spy1.count(), 0); | |
513 | QCOMPARE(spy2.count(), 0); |
|
513 | QCOMPARE(spy2.count(), 0); | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
516 | void tst_Domain::spanY_data() |
|
516 | void tst_Domain::spanY_data() | |
517 | { |
|
517 | { | |
518 | QTest::addColumn<qreal>("minY"); |
|
518 | QTest::addColumn<qreal>("minY"); | |
519 | QTest::addColumn<qreal>("maxY"); |
|
519 | QTest::addColumn<qreal>("maxY"); | |
520 | QTest::addColumn<qreal>("spanY"); |
|
520 | QTest::addColumn<qreal>("spanY"); | |
521 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
521 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | |
522 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
522 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | |
523 | } |
|
523 | } | |
524 |
|
524 | |||
525 | void tst_Domain::spanY() |
|
525 | void tst_Domain::spanY() | |
526 | { |
|
526 | { | |
527 | QFETCH(qreal, minY); |
|
527 | QFETCH(qreal, minY); | |
528 | QFETCH(qreal, maxY); |
|
528 | QFETCH(qreal, maxY); | |
529 | QFETCH(qreal, spanY); |
|
529 | QFETCH(qreal, spanY); | |
530 |
|
530 | |||
531 | Domain domain; |
|
531 | Domain domain; | |
532 |
|
532 | |||
533 | domain.setRangeY(minY, maxY); |
|
533 | domain.setRangeY(minY, maxY); | |
534 |
|
534 | |||
535 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
535 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
536 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
536 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
537 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
537 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
538 |
|
538 | |||
539 | QCOMPARE(domain.spanY(), spanY); |
|
539 | QCOMPARE(domain.spanY(), spanY); | |
540 |
|
540 | |||
541 | QCOMPARE(spy0.count(), 0); |
|
541 | QCOMPARE(spy0.count(), 0); | |
542 | QCOMPARE(spy1.count(), 0); |
|
542 | QCOMPARE(spy1.count(), 0); | |
543 | QCOMPARE(spy2.count(), 0); |
|
543 | QCOMPARE(spy2.count(), 0); | |
544 | } |
|
544 | } | |
545 |
|
545 | |||
546 | void tst_Domain::zoom_data() |
|
546 | void tst_Domain::zoom_data() | |
547 | { |
|
547 | { | |
548 | QTest::addColumn<QRectF>("rect0"); |
|
548 | QTest::addColumn<QRectF>("rect0"); | |
549 | QTest::addColumn<QSizeF>("size0"); |
|
549 | QTest::addColumn<QSizeF>("size0"); | |
550 | QTest::addColumn<QRectF>("rect1"); |
|
550 | QTest::addColumn<QRectF>("rect1"); | |
551 | QTest::addColumn<QSizeF>("size1"); |
|
551 | QTest::addColumn<QSizeF>("size1"); | |
552 | QTest::addColumn<QRectF>("rect2"); |
|
552 | QTest::addColumn<QRectF>("rect2"); | |
553 | QTest::addColumn<QSizeF>("size2"); |
|
553 | QTest::addColumn<QSizeF>("size2"); | |
554 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) |
|
554 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) | |
555 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
555 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) | |
556 | << QSizeF(1000, 1000); |
|
556 | << QSizeF(1000, 1000); | |
557 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) |
|
557 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) | |
558 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
558 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) | |
559 | << QSizeF(1000, 1000); |
|
559 | << QSizeF(1000, 1000); | |
560 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) |
|
560 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) | |
561 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); |
|
561 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); | |
562 | } |
|
562 | } | |
563 |
|
563 | |||
564 | void tst_Domain::zoom() |
|
564 | void tst_Domain::zoom() | |
565 | { |
|
565 | { | |
566 | QFETCH(QRectF, rect0); |
|
566 | QFETCH(QRectF, rect0); | |
567 | QFETCH(QSizeF, size0); |
|
567 | QFETCH(QSizeF, size0); | |
568 | QFETCH(QRectF, rect1); |
|
568 | QFETCH(QRectF, rect1); | |
569 | QFETCH(QSizeF, size1); |
|
569 | QFETCH(QSizeF, size1); | |
570 | QFETCH(QRectF, rect2); |
|
570 | QFETCH(QRectF, rect2); | |
571 | QFETCH(QSizeF, size2); |
|
571 | QFETCH(QSizeF, size2); | |
572 |
|
572 | |||
573 | Domain domain; |
|
573 | Domain domain; | |
574 |
|
574 | |||
575 | domain.setRange(0, 1000, 0, 1000); |
|
575 | domain.setRange(0, 1000, 0, 1000); | |
576 |
|
576 | |||
577 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
577 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
578 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
578 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
579 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
579 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
580 |
|
580 | |||
581 | Domain domain0; |
|
581 | Domain domain0; | |
582 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
582 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); | |
583 | domain.zoomIn(rect0, size0); |
|
583 | domain.zoomIn(rect0, size0); | |
584 | Domain domain1; |
|
584 | Domain domain1; | |
585 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
585 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); | |
586 | domain.zoomIn(rect1, size1); |
|
586 | domain.zoomIn(rect1, size1); | |
587 | Domain domain2; |
|
587 | Domain domain2; | |
588 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
588 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); | |
589 | domain.zoomIn(rect2, size2); |
|
589 | domain.zoomIn(rect2, size2); | |
590 | domain.zoomOut(rect2, size2); |
|
590 | domain.zoomOut(rect2, size2); | |
591 | QCOMPARE(domain == domain2, true); |
|
591 | QCOMPARE(domain == domain2, true); | |
592 | domain.zoomOut(rect1, size1); |
|
592 | domain.zoomOut(rect1, size1); | |
593 | QCOMPARE(domain == domain1, true); |
|
593 | QCOMPARE(domain == domain1, true); | |
594 | domain.zoomOut(rect0, size0); |
|
594 | domain.zoomOut(rect0, size0); | |
595 | QCOMPARE(domain == domain0, true); |
|
595 | QCOMPARE(domain == domain0, true); | |
596 | QCOMPARE(spy0.count(), 6); |
|
596 | QCOMPARE(spy0.count(), 6); | |
597 | QCOMPARE(spy1.count(), 6); |
|
597 | QCOMPARE(spy1.count(), 6); | |
598 | QCOMPARE(spy2.count(), 6); |
|
598 | QCOMPARE(spy2.count(), 6); | |
599 |
|
599 | |||
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | void tst_Domain::move_data() |
|
602 | void tst_Domain::move_data() | |
603 | { |
|
603 | { | |
604 | QTest::addColumn<int>("dx"); |
|
604 | QTest::addColumn<int>("dx"); | |
605 | QTest::addColumn<int>("dy"); |
|
605 | QTest::addColumn<int>("dy"); | |
606 | QTest::addColumn<QSizeF>("size"); |
|
606 | QTest::addColumn<QSizeF>("size"); | |
607 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); |
|
607 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); | |
608 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); |
|
608 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); | |
609 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); |
|
609 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); | |
610 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); |
|
610 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); | |
611 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); |
|
611 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); | |
612 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); |
|
612 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); | |
613 | } |
|
613 | } | |
614 |
|
614 | |||
615 | void tst_Domain::move() |
|
615 | void tst_Domain::move() | |
616 | { |
|
616 | { | |
617 | QFETCH(int, dx); |
|
617 | QFETCH(int, dx); | |
618 | QFETCH(int, dy); |
|
618 | QFETCH(int, dy); | |
619 | QFETCH(QSizeF, size); |
|
619 | QFETCH(QSizeF, size); | |
620 | Domain domain; |
|
620 | Domain domain; | |
621 |
|
621 | |||
622 | domain.setRange(0, size.width(), 0, size.height()); |
|
622 | domain.setRange(0, size.width(), 0, size.height()); | |
623 |
|
623 | |||
624 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
624 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
625 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
625 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
626 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
626 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
627 |
|
627 | |||
628 | domain.move(dx, dy, size); |
|
628 | domain.move(dx, dy, size); | |
629 |
|
629 | |||
630 | Domain result; |
|
630 | Domain result; | |
631 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
631 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); | |
632 |
|
632 | |||
633 | QCOMPARE(domain == result, true); |
|
633 | QCOMPARE(domain == result, true); | |
634 | QCOMPARE(spy0.count(), 1); |
|
634 | QCOMPARE(spy0.count(), 1); | |
635 | QCOMPARE(spy1.count(), dx!=0?1:0); |
|
635 | QCOMPARE(spy1.count(), dx!=0?1:0); | |
636 | QCOMPARE(spy2.count(), dy!=0?1:0); |
|
636 | QCOMPARE(spy2.count(), dy!=0?1:0); | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | void tst_Domain::handleAxisXChanged_data() |
|
639 | void tst_Domain::handleAxisXChanged_data() | |
640 | { |
|
640 | { | |
641 | QTest::addColumn<qreal>("min"); |
|
641 | QTest::addColumn<qreal>("min"); | |
642 | QTest::addColumn<qreal>("max"); |
|
642 | QTest::addColumn<qreal>("max"); | |
643 | QTest::addColumn<int>("tickCount"); |
|
643 | QTest::addColumn<int>("tickCount"); | |
644 | QTest::addColumn<bool>("niceNumbers"); |
|
644 | QTest::addColumn<bool>("niceNumbers"); | |
645 | QTest::addColumn<qreal>("resultMin"); |
|
645 | QTest::addColumn<qreal>("resultMin"); | |
646 | QTest::addColumn<qreal>("resultMax"); |
|
646 | QTest::addColumn<qreal>("resultMax"); | |
647 | QTest::addColumn<int>("resultTickCount"); |
|
647 | QTest::addColumn<int>("resultTickCount"); | |
648 | QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5; |
|
648 | QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5; | |
649 | QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6; |
|
649 | QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6; | |
650 | QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6; |
|
650 | QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6; | |
651 | QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6; |
|
651 | QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6; | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | void tst_Domain::handleAxisXChanged() |
|
654 | void tst_Domain::handleAxisXChanged() | |
655 | { |
|
655 | { | |
656 | QFETCH(qreal, min); |
|
656 | QFETCH(qreal, min); | |
657 | QFETCH(qreal, max); |
|
657 | QFETCH(qreal, max); | |
658 | QFETCH(int, tickCount); |
|
658 | QFETCH(int, tickCount); | |
659 | QFETCH(bool, niceNumbers); |
|
659 | QFETCH(bool, niceNumbers); | |
660 | QFETCH(qreal, resultMin); |
|
660 | QFETCH(qreal, resultMin); | |
661 | QFETCH(qreal, resultMax); |
|
661 | QFETCH(qreal, resultMax); | |
662 | QFETCH(int, resultTickCount); |
|
662 | QFETCH(int, resultTickCount); | |
663 |
|
663 | |||
664 | Domain domain; |
|
664 | Domain domain; | |
665 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
665 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
666 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
666 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
667 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
667 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
668 |
|
668 | |||
669 | domain.handleAxisXChanged(min, max, tickCount, niceNumbers); |
|
669 | domain.handleAxisXChanged(min, max, tickCount, niceNumbers); | |
670 |
|
670 | |||
671 | QCOMPARE(resultMin, domain.minX()); |
|
671 | QCOMPARE(resultMin, domain.minX()); | |
672 | QCOMPARE(resultMax, domain.maxX()); |
|
672 | QCOMPARE(resultMax, domain.maxX()); | |
673 | QCOMPARE(resultTickCount, domain.tickXCount()); |
|
673 | QCOMPARE(resultTickCount, domain.tickXCount()); | |
674 | QCOMPARE(spy0.count(), 1); |
|
674 | QCOMPARE(spy0.count(), 1); | |
675 | QCOMPARE(spy1.count(), 1); |
|
675 | QCOMPARE(spy1.count(), 1); | |
676 | QCOMPARE(spy2.count(), 0); |
|
676 | QCOMPARE(spy2.count(), 0); | |
677 |
|
677 | |||
678 | } |
|
678 | } | |
679 |
|
679 | |||
680 | void tst_Domain::handleAxisYChanged_data() |
|
680 | void tst_Domain::handleAxisYChanged_data() | |
681 | { |
|
681 | { | |
682 | handleAxisXChanged_data(); |
|
682 | handleAxisXChanged_data(); | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 | void tst_Domain::handleAxisYChanged() |
|
685 | void tst_Domain::handleAxisYChanged() | |
686 | { |
|
686 | { | |
687 | QFETCH(qreal, min); |
|
687 | QFETCH(qreal, min); | |
688 | QFETCH(qreal, max); |
|
688 | QFETCH(qreal, max); | |
689 | QFETCH(int, tickCount); |
|
689 | QFETCH(int, tickCount); | |
690 | QFETCH(bool, niceNumbers); |
|
690 | QFETCH(bool, niceNumbers); | |
691 | QFETCH(qreal, resultMin); |
|
691 | QFETCH(qreal, resultMin); | |
692 | QFETCH(qreal, resultMax); |
|
692 | QFETCH(qreal, resultMax); | |
693 | QFETCH(int, resultTickCount); |
|
693 | QFETCH(int, resultTickCount); | |
694 |
|
694 | |||
695 | Domain domain; |
|
695 | Domain domain; | |
696 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
696 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
697 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
697 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
698 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
698 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
699 |
|
699 | |||
700 | domain.handleAxisYChanged(min, max, tickCount, niceNumbers); |
|
700 | domain.handleAxisYChanged(min, max, tickCount, niceNumbers); | |
701 |
|
701 | |||
702 | QCOMPARE(resultMin, domain.minY()); |
|
702 | QCOMPARE(resultMin, domain.minY()); | |
703 | QCOMPARE(resultMax, domain.maxY()); |
|
703 | QCOMPARE(resultMax, domain.maxY()); | |
704 | QCOMPARE(resultTickCount, domain.tickYCount()); |
|
704 | QCOMPARE(resultTickCount, domain.tickYCount()); | |
705 | QCOMPARE(spy0.count(), 1); |
|
705 | QCOMPARE(spy0.count(), 1); | |
706 | QCOMPARE(spy1.count(), 0); |
|
706 | QCOMPARE(spy1.count(), 0); | |
707 | QCOMPARE(spy2.count(), 1); |
|
707 | QCOMPARE(spy2.count(), 1); | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | QTEST_MAIN(tst_Domain) |
|
710 | QTEST_MAIN(tst_Domain) | |
711 | #include "tst_domain.moc" |
|
711 | #include "tst_domain.moc" | |
712 |
|
712 |
@@ -1,572 +1,572 | |||||
1 | #include <QtTest/QtTest> |
|
1 | #include <QtTest/QtTest> | |
2 | #include <qchartview.h> |
|
2 | #include <qchartview.h> | |
3 | #include <qlineseries.h> |
|
3 | #include <qlineseries.h> | |
4 | #include <qareaseries.h> |
|
4 | #include <qareaseries.h> | |
5 | #include <qscatterseries.h> |
|
5 | #include <qscatterseries.h> | |
6 | #include <qsplineseries.h> |
|
6 | #include <qsplineseries.h> | |
7 | #include <qpieseries.h> |
|
7 | #include <qpieseries.h> | |
8 | #include <qbarseries.h> |
|
8 | #include <qbarseries.h> | |
9 | #include <qpercentbarseries.h> |
|
9 | #include <qpercentbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
10 | #include <qstackedbarseries.h> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 |
Q_DECLARE_METATYPE(Q |
|
14 | Q_DECLARE_METATYPE(QAxis *) | |
15 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
15 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
17 | Q_DECLARE_METATYPE(QBrush) |
|
17 | Q_DECLARE_METATYPE(QBrush) | |
18 | Q_DECLARE_METATYPE(QPen) |
|
18 | Q_DECLARE_METATYPE(QPen) | |
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
20 |
|
20 | |||
21 | class tst_QChart : public QObject |
|
21 | class tst_QChart : public QObject | |
22 | { |
|
22 | { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 |
|
24 | |||
25 | public slots: |
|
25 | public slots: | |
26 | void initTestCase(); |
|
26 | void initTestCase(); | |
27 | void cleanupTestCase(); |
|
27 | void cleanupTestCase(); | |
28 | void init(); |
|
28 | void init(); | |
29 | void cleanup(); |
|
29 | void cleanup(); | |
30 |
|
30 | |||
31 | private slots: |
|
31 | private slots: | |
32 | void qchart_data(); |
|
32 | void qchart_data(); | |
33 | void qchart(); |
|
33 | void qchart(); | |
34 |
|
34 | |||
35 | void addSeries_data(); |
|
35 | void addSeries_data(); | |
36 | void addSeries(); |
|
36 | void addSeries(); | |
37 | void animationOptions_data(); |
|
37 | void animationOptions_data(); | |
38 | void animationOptions(); |
|
38 | void animationOptions(); | |
39 | void axisX_data(); |
|
39 | void axisX_data(); | |
40 | void axisX(); |
|
40 | void axisX(); | |
41 | void axisY_data(); |
|
41 | void axisY_data(); | |
42 | void axisY(); |
|
42 | void axisY(); | |
43 | void backgroundBrush_data(); |
|
43 | void backgroundBrush_data(); | |
44 | void backgroundBrush(); |
|
44 | void backgroundBrush(); | |
45 | void backgroundPen_data(); |
|
45 | void backgroundPen_data(); | |
46 | void backgroundPen(); |
|
46 | void backgroundPen(); | |
47 | void isBackgroundVisible_data(); |
|
47 | void isBackgroundVisible_data(); | |
48 | void isBackgroundVisible(); |
|
48 | void isBackgroundVisible(); | |
49 | void legend_data(); |
|
49 | void legend_data(); | |
50 | void legend(); |
|
50 | void legend(); | |
51 | void margins_data(); |
|
51 | void margins_data(); | |
52 | void margins(); |
|
52 | void margins(); | |
53 | void removeAllSeries_data(); |
|
53 | void removeAllSeries_data(); | |
54 | void removeAllSeries(); |
|
54 | void removeAllSeries(); | |
55 | void removeSeries_data(); |
|
55 | void removeSeries_data(); | |
56 | void removeSeries(); |
|
56 | void removeSeries(); | |
57 | void scrollDown_data(); |
|
57 | void scrollDown_data(); | |
58 | void scrollDown(); |
|
58 | void scrollDown(); | |
59 | void scrollLeft_data(); |
|
59 | void scrollLeft_data(); | |
60 | void scrollLeft(); |
|
60 | void scrollLeft(); | |
61 | void scrollRight_data(); |
|
61 | void scrollRight_data(); | |
62 | void scrollRight(); |
|
62 | void scrollRight(); | |
63 | void scrollUp_data(); |
|
63 | void scrollUp_data(); | |
64 | void scrollUp(); |
|
64 | void scrollUp(); | |
65 | void theme_data(); |
|
65 | void theme_data(); | |
66 | void theme(); |
|
66 | void theme(); | |
67 | void title_data(); |
|
67 | void title_data(); | |
68 | void title(); |
|
68 | void title(); | |
69 | void titleBrush_data(); |
|
69 | void titleBrush_data(); | |
70 | void titleBrush(); |
|
70 | void titleBrush(); | |
71 | void titleFont_data(); |
|
71 | void titleFont_data(); | |
72 | void titleFont(); |
|
72 | void titleFont(); | |
73 | void zoomIn_data(); |
|
73 | void zoomIn_data(); | |
74 | void zoomIn(); |
|
74 | void zoomIn(); | |
75 | void zoomOut_data(); |
|
75 | void zoomOut_data(); | |
76 | void zoomOut(); |
|
76 | void zoomOut(); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | void createTestData(); |
|
79 | void createTestData(); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | QChartView* m_view; |
|
82 | QChartView* m_view; | |
83 | QChart* m_chart; |
|
83 | QChart* m_chart; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void tst_QChart::initTestCase() |
|
86 | void tst_QChart::initTestCase() | |
87 | { |
|
87 | { | |
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void tst_QChart::cleanupTestCase() |
|
91 | void tst_QChart::cleanupTestCase() | |
92 | { |
|
92 | { | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_QChart::init() |
|
96 | void tst_QChart::init() | |
97 | { |
|
97 | { | |
98 | m_view = new QChartView(new QChart()); |
|
98 | m_view = new QChartView(new QChart()); | |
99 | m_chart = m_view->chart(); |
|
99 | m_chart = m_view->chart(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void tst_QChart::createTestData() |
|
102 | void tst_QChart::createTestData() | |
103 | { |
|
103 | { | |
104 | QLineSeries* series0 = new QLineSeries(this); |
|
104 | QLineSeries* series0 = new QLineSeries(this); | |
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
106 | m_chart->addSeries(series0); |
|
106 | m_chart->addSeries(series0); | |
107 | m_view->show(); |
|
107 | m_view->show(); | |
108 | QTest::qWaitForWindowShown(m_view); |
|
108 | QTest::qWaitForWindowShown(m_view); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void tst_QChart::cleanup() |
|
111 | void tst_QChart::cleanup() | |
112 | { |
|
112 | { | |
113 | delete m_view; |
|
113 | delete m_view; | |
114 | m_view = 0; |
|
114 | m_view = 0; | |
115 | m_chart = 0; |
|
115 | m_chart = 0; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_QChart::qchart_data() |
|
118 | void tst_QChart::qchart_data() | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QChart::qchart() |
|
122 | void tst_QChart::qchart() | |
123 | { |
|
123 | { | |
124 | QVERIFY(m_chart); |
|
124 | QVERIFY(m_chart); | |
125 | QVERIFY(m_chart->legend()); |
|
125 | QVERIFY(m_chart->legend()); | |
126 | QVERIFY(!m_chart->legend()->isVisible()); |
|
126 | QVERIFY(!m_chart->legend()->isVisible()); | |
127 |
|
127 | |||
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
129 | QVERIFY(m_chart->axisX()); |
|
129 | QVERIFY(m_chart->axisX()); | |
130 | QVERIFY(m_chart->axisY()); |
|
130 | QVERIFY(m_chart->axisY()); | |
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
134 |
|
134 | |||
135 | QVERIFY(m_chart->margins().top()>0); |
|
135 | QVERIFY(m_chart->margins().top()>0); | |
136 | QVERIFY(m_chart->margins().left()>0); |
|
136 | QVERIFY(m_chart->margins().left()>0); | |
137 | QVERIFY(m_chart->margins().right()>0); |
|
137 | QVERIFY(m_chart->margins().right()>0); | |
138 | QVERIFY(m_chart->margins().bottom()>0); |
|
138 | QVERIFY(m_chart->margins().bottom()>0); | |
139 |
|
139 | |||
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
141 | QCOMPARE(m_chart->title(), QString()); |
|
141 | QCOMPARE(m_chart->title(), QString()); | |
142 |
|
142 | |||
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
144 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
144 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
145 |
|
145 | |||
146 | m_chart->removeAllSeries(); |
|
146 | m_chart->removeAllSeries(); | |
147 | m_chart->scrollDown(); |
|
147 | m_chart->scrollDown(); | |
148 | m_chart->scrollLeft(); |
|
148 | m_chart->scrollLeft(); | |
149 | m_chart->scrollRight(); |
|
149 | m_chart->scrollRight(); | |
150 | m_chart->scrollUp(); |
|
150 | m_chart->scrollUp(); | |
151 |
|
151 | |||
152 | m_chart->zoomIn(); |
|
152 | m_chart->zoomIn(); | |
153 | m_chart->zoomIn(QRectF()); |
|
153 | m_chart->zoomIn(QRectF()); | |
154 | m_chart->zoomOut(); |
|
154 | m_chart->zoomOut(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void tst_QChart::addSeries_data() |
|
157 | void tst_QChart::addSeries_data() | |
158 | { |
|
158 | { | |
159 | QTest::addColumn<QAbstractSeries *>("series"); |
|
159 | QTest::addColumn<QAbstractSeries *>("series"); | |
160 |
QTest::addColumn<Q |
|
160 | QTest::addColumn<QAxis *>("axis"); | |
161 |
|
161 | |||
162 | QAbstractSeries* series0 = new QLineSeries(this); |
|
162 | QAbstractSeries* series0 = new QLineSeries(this); | |
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); | |
164 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
164 | QAbstractSeries* series2 = new QScatterSeries(this); | |
165 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
165 | QAbstractSeries* series3 = new QSplineSeries(this); | |
166 | QAbstractSeries* series4 = new QPieSeries(this); |
|
166 | QAbstractSeries* series4 = new QPieSeries(this); | |
167 | QAbstractSeries* series5 = new QBarSeries(QBarCategories(),this); |
|
167 | QAbstractSeries* series5 = new QBarSeries(QBarCategories(),this); | |
168 | QAbstractSeries* series6 = new QPercentBarSeries(QBarCategories(),this); |
|
168 | QAbstractSeries* series6 = new QPercentBarSeries(QBarCategories(),this); | |
169 | QAbstractSeries* series7 = new QStackedBarSeries(QBarCategories(),this); |
|
169 | QAbstractSeries* series7 = new QStackedBarSeries(QBarCategories(),this); | |
170 |
|
170 | |||
171 |
Q |
|
171 | QAxis* axis = new QAxis(this); | |
172 |
|
172 | |||
173 |
QTest::newRow("default axis: lineSeries") << series0 << (Q |
|
173 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; | |
174 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
174 | QTest::newRow("axis0: lineSeries") << series0 << axis; | |
175 |
QTest::newRow("default axis: areaSeries") << series1 << (Q |
|
175 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; | |
176 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
176 | QTest::newRow("axis: areaSeries") << series1 << axis; | |
177 |
QTest::newRow("default axis: scatterSeries") << series2 << (Q |
|
177 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; | |
178 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
178 | QTest::newRow("axis1: scatterSeries") << series2 << axis; | |
179 |
QTest::newRow("default axis: splineSeries") << series3 << (Q |
|
179 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; | |
180 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
180 | QTest::newRow("axis: splineSeries") << series3 << axis; | |
181 |
QTest::newRow("default axis: pieSeries") << series4 << (Q |
|
181 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; | |
182 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
182 | QTest::newRow("axis: pieSeries") << series4 << axis; | |
183 |
QTest::newRow("default axis: barSeries") << series5 << (Q |
|
183 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; | |
184 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
184 | QTest::newRow("axis: barSeries") << series5 << axis; | |
185 |
QTest::newRow("default axis: percentBarSeries") << series6 << (Q |
|
185 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; | |
186 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
186 | QTest::newRow("axis: barSeries") << series6 << axis; | |
187 |
QTest::newRow("default axis: stackedBarSeries") << series7 << (Q |
|
187 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; | |
188 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
188 | QTest::newRow("axis: barSeries") << series7 << axis; | |
189 |
|
189 | |||
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void tst_QChart::addSeries() |
|
192 | void tst_QChart::addSeries() | |
193 | { |
|
193 | { | |
194 | QFETCH(QAbstractSeries *, series); |
|
194 | QFETCH(QAbstractSeries *, series); | |
195 |
QFETCH(Q |
|
195 | QFETCH(QAxis *, axis); | |
196 | m_view->show(); |
|
196 | m_view->show(); | |
197 | QTest::qWaitForWindowShown(m_view); |
|
197 | QTest::qWaitForWindowShown(m_view); | |
198 | if(!axis) axis = m_chart->axisY(); |
|
198 | if(!axis) axis = m_chart->axisY(); | |
199 | m_chart->addSeries(series,axis); |
|
199 | m_chart->addSeries(series,axis); | |
200 | QCOMPARE(m_chart->axisY(series),axis); |
|
200 | QCOMPARE(m_chart->axisY(series),axis); | |
201 | m_chart->removeSeries(series); |
|
201 | m_chart->removeSeries(series); | |
202 |
|
202 | |||
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void tst_QChart::animationOptions_data() |
|
205 | void tst_QChart::animationOptions_data() | |
206 | { |
|
206 | { | |
207 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
207 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
208 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
208 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
209 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
209 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
210 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
210 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
211 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
211 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void tst_QChart::animationOptions() |
|
214 | void tst_QChart::animationOptions() | |
215 | { |
|
215 | { | |
216 | createTestData(); |
|
216 | createTestData(); | |
217 | QFETCH(QChart::AnimationOption, animationOptions); |
|
217 | QFETCH(QChart::AnimationOption, animationOptions); | |
218 | m_chart->setAnimationOptions(animationOptions); |
|
218 | m_chart->setAnimationOptions(animationOptions); | |
219 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
219 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void tst_QChart::axisX_data() |
|
222 | void tst_QChart::axisX_data() | |
223 | { |
|
223 | { | |
224 |
|
224 | |||
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void tst_QChart::axisX() |
|
227 | void tst_QChart::axisX() | |
228 | { |
|
228 | { | |
229 | QVERIFY(m_chart->axisX()); |
|
229 | QVERIFY(m_chart->axisX()); | |
230 |
Q |
|
230 | QAxis* axis = m_chart->axisX(); | |
231 | createTestData(); |
|
231 | createTestData(); | |
232 | //it should be the same axis |
|
232 | //it should be the same axis | |
233 | QCOMPARE(axis,m_chart->axisX()); |
|
233 | QCOMPARE(axis,m_chart->axisX()); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void tst_QChart::axisY_data() |
|
236 | void tst_QChart::axisY_data() | |
237 | { |
|
237 | { | |
238 |
QTest::addColumn<Q |
|
238 | QTest::addColumn<QAxis*>("axis0"); | |
239 |
QTest::addColumn<Q |
|
239 | QTest::addColumn<QAxis*>("axis1"); | |
240 |
QTest::addColumn<Q |
|
240 | QTest::addColumn<QAxis*>("axis2"); | |
241 |
QTest::newRow("1 defualt, 2 optional") << (Q |
|
241 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); | |
242 |
QTest::newRow("3 optional") << new Q |
|
242 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 |
|
245 | |||
246 | void tst_QChart::axisY() |
|
246 | void tst_QChart::axisY() | |
247 | { |
|
247 | { | |
248 |
QFETCH(Q |
|
248 | QFETCH(QAxis*, axis0); | |
249 |
QFETCH(Q |
|
249 | QFETCH(QAxis*, axis1); | |
250 |
QFETCH(Q |
|
250 | QFETCH(QAxis*, axis2); | |
251 |
|
251 | |||
252 |
Q |
|
252 | QAxis* defaultAxisY = m_chart->axisY(); | |
253 |
|
253 | |||
254 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
254 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
255 |
|
255 | |||
256 | QLineSeries* series0 = new QLineSeries(); |
|
256 | QLineSeries* series0 = new QLineSeries(); | |
257 | m_chart->addSeries(series0, axis0); |
|
257 | m_chart->addSeries(series0, axis0); | |
258 |
|
258 | |||
259 | QLineSeries* series1 = new QLineSeries(); |
|
259 | QLineSeries* series1 = new QLineSeries(); | |
260 | m_chart->addSeries(series1, axis1); |
|
260 | m_chart->addSeries(series1, axis1); | |
261 |
|
261 | |||
262 | QLineSeries* series2 = new QLineSeries(); |
|
262 | QLineSeries* series2 = new QLineSeries(); | |
263 | m_chart->addSeries(series2, axis2); |
|
263 | m_chart->addSeries(series2, axis2); | |
264 |
|
264 | |||
265 | if (!axis0) |
|
265 | if (!axis0) | |
266 | axis0 = defaultAxisY; |
|
266 | axis0 = defaultAxisY; | |
267 | if (!axis1) |
|
267 | if (!axis1) | |
268 | axis1 = defaultAxisY; |
|
268 | axis1 = defaultAxisY; | |
269 | if (!axis2) |
|
269 | if (!axis2) | |
270 | axis2 = defaultAxisY; |
|
270 | axis2 = defaultAxisY; | |
271 |
|
271 | |||
272 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
272 | QVERIFY(m_chart->axisY(series0) == axis0); | |
273 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
273 | QVERIFY(m_chart->axisY(series1) == axis1); | |
274 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
274 | QVERIFY(m_chart->axisY(series2) == axis2); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void tst_QChart::backgroundBrush_data() |
|
277 | void tst_QChart::backgroundBrush_data() | |
278 | { |
|
278 | { | |
279 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
279 | QTest::addColumn<QBrush>("backgroundBrush"); | |
280 | QTest::newRow("null") << QBrush(); |
|
280 | QTest::newRow("null") << QBrush(); | |
281 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
281 | QTest::newRow("blue") << QBrush(Qt::blue); | |
282 | QTest::newRow("white") << QBrush(Qt::white); |
|
282 | QTest::newRow("white") << QBrush(Qt::white); | |
283 | QTest::newRow("black") << QBrush(Qt::black); |
|
283 | QTest::newRow("black") << QBrush(Qt::black); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | void tst_QChart::backgroundBrush() |
|
286 | void tst_QChart::backgroundBrush() | |
287 | { |
|
287 | { | |
288 | QFETCH(QBrush, backgroundBrush); |
|
288 | QFETCH(QBrush, backgroundBrush); | |
289 | m_chart->setBackgroundBrush(backgroundBrush); |
|
289 | m_chart->setBackgroundBrush(backgroundBrush); | |
290 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
290 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void tst_QChart::backgroundPen_data() |
|
293 | void tst_QChart::backgroundPen_data() | |
294 | { |
|
294 | { | |
295 | QTest::addColumn<QPen>("backgroundPen"); |
|
295 | QTest::addColumn<QPen>("backgroundPen"); | |
296 | QTest::newRow("null") << QPen(); |
|
296 | QTest::newRow("null") << QPen(); | |
297 | QTest::newRow("blue") << QPen(Qt::blue); |
|
297 | QTest::newRow("blue") << QPen(Qt::blue); | |
298 | QTest::newRow("white") << QPen(Qt::white); |
|
298 | QTest::newRow("white") << QPen(Qt::white); | |
299 | QTest::newRow("black") << QPen(Qt::black); |
|
299 | QTest::newRow("black") << QPen(Qt::black); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 |
|
302 | |||
303 | void tst_QChart::backgroundPen() |
|
303 | void tst_QChart::backgroundPen() | |
304 | { |
|
304 | { | |
305 | QFETCH(QPen, backgroundPen); |
|
305 | QFETCH(QPen, backgroundPen); | |
306 | m_chart->setBackgroundPen(backgroundPen); |
|
306 | m_chart->setBackgroundPen(backgroundPen); | |
307 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
307 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | void tst_QChart::isBackgroundVisible_data() |
|
310 | void tst_QChart::isBackgroundVisible_data() | |
311 | { |
|
311 | { | |
312 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
312 | QTest::addColumn<bool>("isBackgroundVisible"); | |
313 | QTest::newRow("true") << true; |
|
313 | QTest::newRow("true") << true; | |
314 | QTest::newRow("false") << false; |
|
314 | QTest::newRow("false") << false; | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void tst_QChart::isBackgroundVisible() |
|
317 | void tst_QChart::isBackgroundVisible() | |
318 | { |
|
318 | { | |
319 | QFETCH(bool, isBackgroundVisible); |
|
319 | QFETCH(bool, isBackgroundVisible); | |
320 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
320 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
321 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
321 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
322 |
|
322 | |||
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void tst_QChart::legend_data() |
|
325 | void tst_QChart::legend_data() | |
326 | { |
|
326 | { | |
327 |
|
327 | |||
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | void tst_QChart::legend() |
|
330 | void tst_QChart::legend() | |
331 | { |
|
331 | { | |
332 | QVERIFY(m_chart->legend()); |
|
332 | QVERIFY(m_chart->legend()); | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void tst_QChart::margins_data() |
|
335 | void tst_QChart::margins_data() | |
336 | { |
|
336 | { | |
337 |
|
337 | |||
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void tst_QChart::margins() |
|
340 | void tst_QChart::margins() | |
341 | {QTest::addColumn<int>("seriesCount"); |
|
341 | {QTest::addColumn<int>("seriesCount"); | |
342 | QTest::newRow("0") << 0; |
|
342 | QTest::newRow("0") << 0; | |
343 | QTest::newRow("-1") << -1; |
|
343 | QTest::newRow("-1") << -1; | |
344 | createTestData(); |
|
344 | createTestData(); | |
345 | QRectF rect = m_chart->geometry(); |
|
345 | QRectF rect = m_chart->geometry(); | |
346 |
|
346 | |||
347 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
347 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
348 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
348 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
349 |
|
349 | |||
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void tst_QChart::removeAllSeries_data() |
|
352 | void tst_QChart::removeAllSeries_data() | |
353 | { |
|
353 | { | |
354 |
|
354 | |||
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void tst_QChart::removeAllSeries() |
|
357 | void tst_QChart::removeAllSeries() | |
358 | { |
|
358 | { | |
359 | QLineSeries* series0 = new QLineSeries(this); |
|
359 | QLineSeries* series0 = new QLineSeries(this); | |
360 | QLineSeries* series1 = new QLineSeries(this); |
|
360 | QLineSeries* series1 = new QLineSeries(this); | |
361 | QLineSeries* series2 = new QLineSeries(this); |
|
361 | QLineSeries* series2 = new QLineSeries(this); | |
362 |
|
362 | |||
363 | m_chart->addSeries(series0); |
|
363 | m_chart->addSeries(series0); | |
364 | m_chart->addSeries(series1); |
|
364 | m_chart->addSeries(series1); | |
365 | m_chart->addSeries(series2); |
|
365 | m_chart->addSeries(series2); | |
366 | m_view->show(); |
|
366 | m_view->show(); | |
367 | QTest::qWaitForWindowShown(m_view); |
|
367 | QTest::qWaitForWindowShown(m_view); | |
368 |
|
368 | |||
369 | QVERIFY(m_chart->axisY(series0)!=0); |
|
369 | QVERIFY(m_chart->axisY(series0)!=0); | |
370 | QVERIFY(m_chart->axisY(series1)!=0); |
|
370 | QVERIFY(m_chart->axisY(series1)!=0); | |
371 | QVERIFY(m_chart->axisY(series2)!=0); |
|
371 | QVERIFY(m_chart->axisY(series2)!=0); | |
372 |
|
372 | |||
373 | m_chart->removeAllSeries(); |
|
373 | m_chart->removeAllSeries(); | |
374 |
|
374 | |||
375 | QVERIFY(m_chart->axisY(series0)==0); |
|
375 | QVERIFY(m_chart->axisY(series0)==0); | |
376 | QVERIFY(m_chart->axisY(series1)==0); |
|
376 | QVERIFY(m_chart->axisY(series1)==0); | |
377 | QVERIFY(m_chart->axisY(series2)==0); |
|
377 | QVERIFY(m_chart->axisY(series2)==0); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | void tst_QChart::removeSeries_data() |
|
380 | void tst_QChart::removeSeries_data() | |
381 | { |
|
381 | { | |
382 | addSeries_data(); |
|
382 | addSeries_data(); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | void tst_QChart::removeSeries() |
|
385 | void tst_QChart::removeSeries() | |
386 | { |
|
386 | { | |
387 | QFETCH(QAbstractSeries *, series); |
|
387 | QFETCH(QAbstractSeries *, series); | |
388 |
QFETCH(Q |
|
388 | QFETCH(QAxis *, axis); | |
389 | m_view->show(); |
|
389 | m_view->show(); | |
390 | QTest::qWaitForWindowShown(m_view); |
|
390 | QTest::qWaitForWindowShown(m_view); | |
391 | if(!axis) axis = m_chart->axisY(); |
|
391 | if(!axis) axis = m_chart->axisY(); | |
392 | m_chart->addSeries(series,axis); |
|
392 | m_chart->addSeries(series,axis); | |
393 | QCOMPARE(m_chart->axisY(series),axis); |
|
393 | QCOMPARE(m_chart->axisY(series),axis); | |
394 | m_chart->removeSeries(series); |
|
394 | m_chart->removeSeries(series); | |
395 | QVERIFY(m_chart->axisY(series)==0); |
|
395 | QVERIFY(m_chart->axisY(series)==0); | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | void tst_QChart::scrollDown_data() |
|
398 | void tst_QChart::scrollDown_data() | |
399 | { |
|
399 | { | |
400 |
|
400 | |||
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void tst_QChart::scrollDown() |
|
403 | void tst_QChart::scrollDown() | |
404 | { |
|
404 | { | |
405 | createTestData(); |
|
405 | createTestData(); | |
406 | qreal min = m_chart->axisY()->min(); |
|
406 | qreal min = m_chart->axisY()->min(); | |
407 | m_chart->scrollDown(); |
|
407 | m_chart->scrollDown(); | |
408 | QVERIFY(m_chart->axisY()->min()<min); |
|
408 | QVERIFY(m_chart->axisY()->min()<min); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void tst_QChart::scrollLeft_data() |
|
411 | void tst_QChart::scrollLeft_data() | |
412 | { |
|
412 | { | |
413 |
|
413 | |||
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | void tst_QChart::scrollLeft() |
|
416 | void tst_QChart::scrollLeft() | |
417 | { |
|
417 | { | |
418 | createTestData(); |
|
418 | createTestData(); | |
419 | qreal min = m_chart->axisX()->min(); |
|
419 | qreal min = m_chart->axisX()->min(); | |
420 | m_chart->scrollLeft(); |
|
420 | m_chart->scrollLeft(); | |
421 | QVERIFY(m_chart->axisX()->min()<min); |
|
421 | QVERIFY(m_chart->axisX()->min()<min); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | void tst_QChart::scrollRight_data() |
|
424 | void tst_QChart::scrollRight_data() | |
425 | { |
|
425 | { | |
426 |
|
426 | |||
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | void tst_QChart::scrollRight() |
|
429 | void tst_QChart::scrollRight() | |
430 | { |
|
430 | { | |
431 | createTestData(); |
|
431 | createTestData(); | |
432 | qreal min = m_chart->axisX()->min(); |
|
432 | qreal min = m_chart->axisX()->min(); | |
433 | m_chart->scrollRight(); |
|
433 | m_chart->scrollRight(); | |
434 | QVERIFY(m_chart->axisX()->min()>min); |
|
434 | QVERIFY(m_chart->axisX()->min()>min); | |
435 | } |
|
435 | } | |
436 |
|
436 | |||
437 | void tst_QChart::scrollUp_data() |
|
437 | void tst_QChart::scrollUp_data() | |
438 | { |
|
438 | { | |
439 |
|
439 | |||
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | void tst_QChart::scrollUp() |
|
442 | void tst_QChart::scrollUp() | |
443 | { |
|
443 | { | |
444 | createTestData(); |
|
444 | createTestData(); | |
445 | qreal min = m_chart->axisY()->min(); |
|
445 | qreal min = m_chart->axisY()->min(); | |
446 | m_chart->scrollUp(); |
|
446 | m_chart->scrollUp(); | |
447 | QVERIFY(m_chart->axisY()->min()>min); |
|
447 | QVERIFY(m_chart->axisY()->min()>min); | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | void tst_QChart::theme_data() |
|
450 | void tst_QChart::theme_data() | |
451 | { |
|
451 | { | |
452 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
452 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
453 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
453 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
454 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
454 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
455 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
455 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
456 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
456 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
457 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
457 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
458 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
458 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
459 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
459 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | void tst_QChart::theme() |
|
462 | void tst_QChart::theme() | |
463 | { |
|
463 | { | |
464 | QFETCH(QChart::ChartTheme, theme); |
|
464 | QFETCH(QChart::ChartTheme, theme); | |
465 | createTestData(); |
|
465 | createTestData(); | |
466 | m_chart->setTheme(theme); |
|
466 | m_chart->setTheme(theme); | |
467 | QVERIFY(m_chart->theme()==theme); |
|
467 | QVERIFY(m_chart->theme()==theme); | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | void tst_QChart::title_data() |
|
470 | void tst_QChart::title_data() | |
471 | { |
|
471 | { | |
472 | QTest::addColumn<QString>("title"); |
|
472 | QTest::addColumn<QString>("title"); | |
473 | QTest::newRow("null") << QString(); |
|
473 | QTest::newRow("null") << QString(); | |
474 | QTest::newRow("foo") << QString("foo"); |
|
474 | QTest::newRow("foo") << QString("foo"); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void tst_QChart::title() |
|
477 | void tst_QChart::title() | |
478 | { |
|
478 | { | |
479 | QFETCH(QString, title); |
|
479 | QFETCH(QString, title); | |
480 | m_chart->setTitle(title); |
|
480 | m_chart->setTitle(title); | |
481 | QCOMPARE(m_chart->title(), title); |
|
481 | QCOMPARE(m_chart->title(), title); | |
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | void tst_QChart::titleBrush_data() |
|
484 | void tst_QChart::titleBrush_data() | |
485 | { |
|
485 | { | |
486 | QTest::addColumn<QBrush>("titleBrush"); |
|
486 | QTest::addColumn<QBrush>("titleBrush"); | |
487 | QTest::newRow("null") << QBrush(); |
|
487 | QTest::newRow("null") << QBrush(); | |
488 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
488 | QTest::newRow("blue") << QBrush(Qt::blue); | |
489 | QTest::newRow("white") << QBrush(Qt::white); |
|
489 | QTest::newRow("white") << QBrush(Qt::white); | |
490 | QTest::newRow("black") << QBrush(Qt::black); |
|
490 | QTest::newRow("black") << QBrush(Qt::black); | |
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | void tst_QChart::titleBrush() |
|
493 | void tst_QChart::titleBrush() | |
494 | { |
|
494 | { | |
495 | QFETCH(QBrush, titleBrush); |
|
495 | QFETCH(QBrush, titleBrush); | |
496 | m_chart->setTitleBrush(titleBrush); |
|
496 | m_chart->setTitleBrush(titleBrush); | |
497 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
497 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
498 | } |
|
498 | } | |
499 |
|
499 | |||
500 | void tst_QChart::titleFont_data() |
|
500 | void tst_QChart::titleFont_data() | |
501 | { |
|
501 | { | |
502 | QTest::addColumn<QFont>("titleFont"); |
|
502 | QTest::addColumn<QFont>("titleFont"); | |
503 | QTest::newRow("null") << QFont(); |
|
503 | QTest::newRow("null") << QFont(); | |
504 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
504 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | void tst_QChart::titleFont() |
|
507 | void tst_QChart::titleFont() | |
508 | { |
|
508 | { | |
509 | QFETCH(QFont, titleFont); |
|
509 | QFETCH(QFont, titleFont); | |
510 | m_chart->setTitleFont(titleFont); |
|
510 | m_chart->setTitleFont(titleFont); | |
511 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
511 | QCOMPARE(m_chart->titleFont(), titleFont); | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | void tst_QChart::zoomIn_data() |
|
514 | void tst_QChart::zoomIn_data() | |
515 | { |
|
515 | { | |
516 | QTest::addColumn<QRectF>("rect"); |
|
516 | QTest::addColumn<QRectF>("rect"); | |
517 | QTest::newRow("null") << QRectF(); |
|
517 | QTest::newRow("null") << QRectF(); | |
518 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
518 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
519 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
519 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
522 |
|
522 | |||
523 | void tst_QChart::zoomIn() |
|
523 | void tst_QChart::zoomIn() | |
524 | { |
|
524 | { | |
525 | QFETCH(QRectF, rect); |
|
525 | QFETCH(QRectF, rect); | |
526 | createTestData(); |
|
526 | createTestData(); | |
527 | QRectF marigns = m_chart->margins(); |
|
527 | QRectF marigns = m_chart->margins(); | |
528 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
528 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
529 | qreal minX = m_chart->axisX()->min(); |
|
529 | qreal minX = m_chart->axisX()->min(); | |
530 | qreal minY = m_chart->axisY()->min(); |
|
530 | qreal minY = m_chart->axisY()->min(); | |
531 | qreal maxX = m_chart->axisX()->max(); |
|
531 | qreal maxX = m_chart->axisX()->max(); | |
532 | qreal maxY = m_chart->axisY()->max(); |
|
532 | qreal maxY = m_chart->axisY()->max(); | |
533 | m_chart->zoomIn(rect); |
|
533 | m_chart->zoomIn(rect); | |
534 | if(rect.isValid()){ |
|
534 | if(rect.isValid()){ | |
535 | QVERIFY(minX<m_chart->axisX()->min()); |
|
535 | QVERIFY(minX<m_chart->axisX()->min()); | |
536 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
536 | QVERIFY(maxX>m_chart->axisX()->max()); | |
537 | QVERIFY(minY<m_chart->axisY()->min()); |
|
537 | QVERIFY(minY<m_chart->axisY()->min()); | |
538 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
538 | QVERIFY(maxY>m_chart->axisY()->max()); | |
539 | } |
|
539 | } | |
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | void tst_QChart::zoomOut_data() |
|
542 | void tst_QChart::zoomOut_data() | |
543 | { |
|
543 | { | |
544 |
|
544 | |||
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | void tst_QChart::zoomOut() |
|
547 | void tst_QChart::zoomOut() | |
548 | { |
|
548 | { | |
549 | createTestData(); |
|
549 | createTestData(); | |
550 | qreal minX = m_chart->axisX()->min(); |
|
550 | qreal minX = m_chart->axisX()->min(); | |
551 | qreal minY = m_chart->axisY()->min(); |
|
551 | qreal minY = m_chart->axisY()->min(); | |
552 | qreal maxX = m_chart->axisX()->max(); |
|
552 | qreal maxX = m_chart->axisX()->max(); | |
553 | qreal maxY = m_chart->axisY()->max(); |
|
553 | qreal maxY = m_chart->axisY()->max(); | |
554 |
|
554 | |||
555 | m_chart->zoomIn(); |
|
555 | m_chart->zoomIn(); | |
556 |
|
556 | |||
557 | QVERIFY(minX<m_chart->axisX()->min()); |
|
557 | QVERIFY(minX<m_chart->axisX()->min()); | |
558 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
558 | QVERIFY(maxX>m_chart->axisX()->max()); | |
559 | QVERIFY(minY<m_chart->axisY()->min()); |
|
559 | QVERIFY(minY<m_chart->axisY()->min()); | |
560 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
560 | QVERIFY(maxY>m_chart->axisY()->max()); | |
561 |
|
561 | |||
562 | m_chart->zoomOut(); |
|
562 | m_chart->zoomOut(); | |
563 |
|
563 | |||
564 | QVERIFY(minX==m_chart->axisX()->min()); |
|
564 | QVERIFY(minX==m_chart->axisX()->min()); | |
565 | QVERIFY(maxX==m_chart->axisX()->max()); |
|
565 | QVERIFY(maxX==m_chart->axisX()->max()); | |
566 | QVERIFY(minY==m_chart->axisY()->min()); |
|
566 | QVERIFY(minY==m_chart->axisY()->min()); | |
567 | QVERIFY(maxY==m_chart->axisY()->max()); |
|
567 | QVERIFY(maxY==m_chart->axisY()->max()); | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | QTEST_MAIN(tst_QChart) |
|
570 | QTEST_MAIN(tst_QChart) | |
571 | #include "tst_qchart.moc" |
|
571 | #include "tst_qchart.moc" | |
572 |
|
572 |
@@ -1,215 +1,215 | |||||
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 |
|
21 | |||
22 | #include <QtTest/QtTest> |
|
22 | #include <QtTest/QtTest> | |
23 | #include <qchartview.h> |
|
23 | #include <qchartview.h> | |
24 | #include <qlineseries.h> |
|
24 | #include <qlineseries.h> | |
25 | #include <cmath> |
|
25 | #include <cmath> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QChart*) |
|
30 | Q_DECLARE_METATYPE(QChart*) | |
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) |
|
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) | |
32 | Q_DECLARE_METATYPE(Qt::Key) |
|
32 | Q_DECLARE_METATYPE(Qt::Key) | |
33 |
|
33 | |||
34 | class tst_QChartView : public QObject |
|
34 | class tst_QChartView : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
39 | void initTestCase(); |
|
39 | void initTestCase(); | |
40 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
41 | void init(); |
|
41 | void init(); | |
42 | void cleanup(); |
|
42 | void cleanup(); | |
43 |
|
43 | |||
44 | private Q_SLOTS: |
|
44 | private Q_SLOTS: | |
45 | void qchartview_data(); |
|
45 | void qchartview_data(); | |
46 | void qchartview(); |
|
46 | void qchartview(); | |
47 | void chart_data(); |
|
47 | void chart_data(); | |
48 | void chart(); |
|
48 | void chart(); | |
49 | void rubberBand_data(); |
|
49 | void rubberBand_data(); | |
50 | void rubberBand(); |
|
50 | void rubberBand(); | |
51 | void keys_data(); |
|
51 | void keys_data(); | |
52 | void keys(); |
|
52 | void keys(); | |
53 |
|
53 | |||
54 | private: |
|
54 | private: | |
55 | QChartView* m_view; |
|
55 | QChartView* m_view; | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | void tst_QChartView::initTestCase() |
|
58 | void tst_QChartView::initTestCase() | |
59 | { |
|
59 | { | |
60 | //test tracks mouse, give a while to user to relese it |
|
60 | //test tracks mouse, give a while to user to relese it | |
61 | QTest::qWait(1000); |
|
61 | QTest::qWait(1000); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void tst_QChartView::cleanupTestCase() |
|
64 | void tst_QChartView::cleanupTestCase() | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void tst_QChartView::init() |
|
68 | void tst_QChartView::init() | |
69 | { |
|
69 | { | |
70 | m_view = new QChartView(new QChart()); |
|
70 | m_view = new QChartView(new QChart()); | |
71 | m_view->chart()->legend()->setVisible(false); |
|
71 | m_view->chart()->legend()->setVisible(false); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void tst_QChartView::cleanup() |
|
74 | void tst_QChartView::cleanup() | |
75 | { |
|
75 | { | |
76 | delete m_view; |
|
76 | delete m_view; | |
77 | m_view =0; |
|
77 | m_view =0; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_QChartView::qchartview_data() |
|
80 | void tst_QChartView::qchartview_data() | |
81 | { |
|
81 | { | |
82 |
|
82 | |||
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void tst_QChartView::qchartview() |
|
85 | void tst_QChartView::qchartview() | |
86 | { |
|
86 | { | |
87 | QVERIFY(m_view->chart()); |
|
87 | QVERIFY(m_view->chart()); | |
88 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
88 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); | |
89 | m_view->show(); |
|
89 | m_view->show(); | |
90 | QTest::qWaitForWindowShown(m_view); |
|
90 | QTest::qWaitForWindowShown(m_view); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_QChartView::chart_data() |
|
93 | void tst_QChartView::chart_data() | |
94 | { |
|
94 | { | |
95 |
|
95 | |||
96 | QTest::addColumn<QChart*>("chart"); |
|
96 | QTest::addColumn<QChart*>("chart"); | |
97 | QTest::newRow("qchart") << new QChart(); |
|
97 | QTest::newRow("qchart") << new QChart(); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void tst_QChartView::chart() |
|
100 | void tst_QChartView::chart() | |
101 | { |
|
101 | { | |
102 | QFETCH(QChart*, chart); |
|
102 | QFETCH(QChart*, chart); | |
103 | QChartView* view = new QChartView(chart); |
|
103 | QChartView* view = new QChartView(chart); | |
104 | QCOMPARE(view->chart(), chart); |
|
104 | QCOMPARE(view->chart(), chart); | |
105 | delete view; |
|
105 | delete view; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void tst_QChartView::rubberBand_data() |
|
108 | void tst_QChartView::rubberBand_data() | |
109 | { |
|
109 | { | |
110 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
110 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); | |
111 | QTest::addColumn<int>("Xcount"); |
|
111 | QTest::addColumn<int>("Xcount"); | |
112 | QTest::addColumn<int>("Ycount"); |
|
112 | QTest::addColumn<int>("Ycount"); | |
113 |
|
113 | |||
114 | QTest::addColumn<int>("minX"); |
|
114 | QTest::addColumn<int>("minX"); | |
115 | QTest::addColumn<int>("maxX"); |
|
115 | QTest::addColumn<int>("maxX"); | |
116 | QTest::addColumn<int>("minY"); |
|
116 | QTest::addColumn<int>("minY"); | |
117 | QTest::addColumn<int>("maxY"); |
|
117 | QTest::addColumn<int>("maxY"); | |
118 |
|
118 | |||
119 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; |
|
119 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; | |
120 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; |
|
120 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; | |
121 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; |
|
121 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void tst_QChartView::rubberBand() |
|
124 | void tst_QChartView::rubberBand() | |
125 | { |
|
125 | { | |
126 | QFETCH(QChartView::RubberBands, rubberBand); |
|
126 | QFETCH(QChartView::RubberBands, rubberBand); | |
127 | QFETCH(int, Xcount); |
|
127 | QFETCH(int, Xcount); | |
128 | QFETCH(int, Ycount); |
|
128 | QFETCH(int, Ycount); | |
129 | QFETCH(int, minX); |
|
129 | QFETCH(int, minX); | |
130 | QFETCH(int, maxX); |
|
130 | QFETCH(int, maxX); | |
131 | QFETCH(int, minY); |
|
131 | QFETCH(int, minY); | |
132 | QFETCH(int, maxY); |
|
132 | QFETCH(int, maxY); | |
133 |
|
133 | |||
134 | m_view->setRubberBand(rubberBand); |
|
134 | m_view->setRubberBand(rubberBand); | |
135 | QRectF padding = m_view->chart()->margins(); |
|
135 | QRectF padding = m_view->chart()->margins(); | |
136 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
136 | QCOMPARE(m_view->rubberBand(), rubberBand); | |
137 |
|
137 | |||
138 | QLineSeries* line = new QLineSeries(); |
|
138 | QLineSeries* line = new QLineSeries(); | |
139 | *line << QPointF(0, 0) << QPointF(200, 200); |
|
139 | *line << QPointF(0, 0) << QPointF(200, 200); | |
140 |
|
140 | |||
141 | m_view->chart()->addSeries(line); |
|
141 | m_view->chart()->addSeries(line); | |
142 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); |
|
142 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); | |
143 | m_view->show(); |
|
143 | m_view->show(); | |
144 |
|
144 | |||
145 | //this is hack since view does not get events otherwise |
|
145 | //this is hack since view does not get events otherwise | |
146 | m_view->setMouseTracking(true); |
|
146 | m_view->setMouseTracking(true); | |
147 |
|
147 | |||
148 |
Q |
|
148 | QAxis* axisY = m_view->chart()->axisY(); | |
149 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
149 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); | |
150 |
Q |
|
150 | QAxis* axisX = m_view->chart()->axisX(); | |
151 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
151 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); | |
152 |
|
152 | |||
153 | QTest::qWaitForWindowShown(m_view); |
|
153 | QTest::qWaitForWindowShown(m_view); | |
154 | QTest::qWait(500); |
|
154 | QTest::qWait(500); | |
155 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
155 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); | |
156 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
156 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); | |
157 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
157 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); | |
158 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
158 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); | |
159 |
|
159 | |||
160 | QCOMPARE(spy0.count(), Xcount); |
|
160 | QCOMPARE(spy0.count(), Xcount); | |
161 | QCOMPARE(spy1.count(), Ycount); |
|
161 | QCOMPARE(spy1.count(), Ycount); | |
162 |
|
162 | |||
163 | //this is hack since view does not get events otherwise |
|
163 | //this is hack since view does not get events otherwise | |
164 | m_view->setMouseTracking(false); |
|
164 | m_view->setMouseTracking(false); | |
165 |
|
165 | |||
166 | QVERIFY(axisX->min() - minX < 1); |
|
166 | QVERIFY(axisX->min() - minX < 1); | |
167 | QVERIFY(axisX->max() - maxX < 1); |
|
167 | QVERIFY(axisX->max() - maxX < 1); | |
168 | QVERIFY(axisY->min() - minY < 1); |
|
168 | QVERIFY(axisY->min() - minY < 1); | |
169 | QVERIFY(axisY->max() - maxY < 1); |
|
169 | QVERIFY(axisY->max() - maxY < 1); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void tst_QChartView::keys_data() |
|
172 | void tst_QChartView::keys_data() | |
173 | { |
|
173 | { | |
174 | QTest::addColumn<Qt::Key>("key"); |
|
174 | QTest::addColumn<Qt::Key>("key"); | |
175 | QTest::addColumn<int>("Xcount"); |
|
175 | QTest::addColumn<int>("Xcount"); | |
176 | QTest::addColumn<int>("Ycount"); |
|
176 | QTest::addColumn<int>("Ycount"); | |
177 | QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1; |
|
177 | QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1; | |
178 | QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1; |
|
178 | QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1; | |
179 | QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1; |
|
179 | QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1; | |
180 | QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1; |
|
180 | QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1; | |
181 | QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0; |
|
181 | QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0; | |
182 | QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0; |
|
182 | QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void tst_QChartView::keys() |
|
185 | void tst_QChartView::keys() | |
186 | { |
|
186 | { | |
187 | QFETCH(Qt::Key,key); |
|
187 | QFETCH(Qt::Key,key); | |
188 | QFETCH(int, Xcount); |
|
188 | QFETCH(int, Xcount); | |
189 | QFETCH(int, Ycount); |
|
189 | QFETCH(int, Ycount); | |
190 |
|
190 | |||
191 | QRectF padding = m_view->chart()->margins(); |
|
191 | QRectF padding = m_view->chart()->margins(); | |
192 |
|
192 | |||
193 | QLineSeries* line = new QLineSeries(); |
|
193 | QLineSeries* line = new QLineSeries(); | |
194 | *line << QPointF(0, 0) << QPointF(100, 100); |
|
194 | *line << QPointF(0, 0) << QPointF(100, 100); | |
195 |
|
195 | |||
196 | m_view->chart()->addSeries(line); |
|
196 | m_view->chart()->addSeries(line); | |
197 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); |
|
197 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); | |
198 | m_view->show(); |
|
198 | m_view->show(); | |
199 |
|
199 | |||
200 |
Q |
|
200 | QAxis* axisY = m_view->chart()->axisY(); | |
201 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
201 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); | |
202 |
Q |
|
202 | QAxis* axisX = m_view->chart()->axisX(); | |
203 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
203 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); | |
204 |
|
204 | |||
205 | QTest::keyPress(m_view, key); |
|
205 | QTest::keyPress(m_view, key); | |
206 | QTest::keyRelease(m_view, key); |
|
206 | QTest::keyRelease(m_view, key); | |
207 |
|
207 | |||
208 | QCOMPARE(spy0.count(), Ycount); |
|
208 | QCOMPARE(spy0.count(), Ycount); | |
209 | QCOMPARE(spy1.count(), Xcount); |
|
209 | QCOMPARE(spy1.count(), Xcount); | |
210 |
|
210 | |||
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | QTEST_MAIN(tst_QChartView) |
|
213 | QTEST_MAIN(tst_QChartView) | |
214 | #include "tst_qchartview.moc" |
|
214 | #include "tst_qchartview.moc" | |
215 |
|
215 |
@@ -1,244 +1,244 | |||||
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 "widget.h" |
|
21 | #include "widget.h" | |
22 |
|
22 | |||
23 | #include <QChart> |
|
23 | #include <QChart> | |
24 | #include <QScatterSeries> |
|
24 | #include <QScatterSeries> | |
25 |
#include <Q |
|
25 | #include <QAxis> | |
26 | #include <QBarSet> |
|
26 | #include <QBarSet> | |
27 | #include <QBarSeries> |
|
27 | #include <QBarSeries> | |
28 | #include <QLegend> |
|
28 | #include <QLegend> | |
29 |
|
29 | |||
30 | #include <QGridLayout> |
|
30 | #include <QGridLayout> | |
31 | #include <QPushButton> |
|
31 | #include <QPushButton> | |
32 | #include <QLabel> |
|
32 | #include <QLabel> | |
33 | #include <QListWidget> |
|
33 | #include <QListWidget> | |
34 | #include <QPrinter> |
|
34 | #include <QPrinter> | |
35 | #include <QPrintDialog> |
|
35 | #include <QPrintDialog> | |
36 | #include <QRadioButton> |
|
36 | #include <QRadioButton> | |
37 | #include <QStringList> |
|
37 | #include <QStringList> | |
38 | #include <QSqlQuery> |
|
38 | #include <QSqlQuery> | |
39 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
41 | QTCOMMERCIALCHART_USE_NAMESPACE | |
42 |
|
42 | |||
43 | Widget::Widget(QWidget *parent) |
|
43 | Widget::Widget(QWidget *parent) | |
44 | : QWidget(parent) |
|
44 | : QWidget(parent) | |
45 | { |
|
45 | { | |
46 | setGeometry(100, 100, 1000, 600); |
|
46 | setGeometry(100, 100, 1000, 600); | |
47 |
|
47 | |||
48 | // right panel layout |
|
48 | // right panel layout | |
49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); |
|
49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); | |
50 | barChartRadioButton->setChecked(true); |
|
50 | barChartRadioButton->setChecked(true); | |
51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); |
|
51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); | |
52 | scatterChartRadioButton->setChecked(false); |
|
52 | scatterChartRadioButton->setChecked(false); | |
53 | countrieslist = new QListWidget; |
|
53 | countrieslist = new QListWidget; | |
54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); |
|
54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); | |
55 |
|
55 | |||
56 | //list of years widget |
|
56 | //list of years widget | |
57 | yearslist = new QListWidget; |
|
57 | yearslist = new QListWidget; | |
58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
59 | for (int i = 1990; i < 2011; i++) |
|
59 | for (int i = 1990; i < 2011; i++) | |
60 | yearslist->addItem(QString("%1").arg(i)); |
|
60 | yearslist->addItem(QString("%1").arg(i)); | |
61 |
|
61 | |||
62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); |
|
62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); | |
63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); |
|
63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); | |
64 |
|
64 | |||
65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); |
|
65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); | |
66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); |
|
66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); | |
67 |
|
67 | |||
68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; |
|
68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; | |
69 | rightPanelLayout->addWidget(barChartRadioButton); |
|
69 | rightPanelLayout->addWidget(barChartRadioButton); | |
70 | rightPanelLayout->addWidget(scatterChartRadioButton); |
|
70 | rightPanelLayout->addWidget(scatterChartRadioButton); | |
71 | rightPanelLayout->addWidget(countrieslist); |
|
71 | rightPanelLayout->addWidget(countrieslist); | |
72 | rightPanelLayout->addWidget(yearslist); |
|
72 | rightPanelLayout->addWidget(yearslist); | |
73 | rightPanelLayout->addWidget(refreshButton); |
|
73 | rightPanelLayout->addWidget(refreshButton); | |
74 | rightPanelLayout->addWidget(printButton); |
|
74 | rightPanelLayout->addWidget(printButton); | |
75 | rightPanelLayout->setStretch(0, 1); |
|
75 | rightPanelLayout->setStretch(0, 1); | |
76 | rightPanelLayout->setStretch(1, 0); |
|
76 | rightPanelLayout->setStretch(1, 0); | |
77 |
|
77 | |||
78 | QChart *chart = new QChart(); |
|
78 | QChart *chart = new QChart(); | |
79 | chart->setTitle("GDP by country"); |
|
79 | chart->setTitle("GDP by country"); | |
80 | chart->legend()->setVisible(true); |
|
80 | chart->legend()->setVisible(true); | |
81 |
|
81 | |||
82 | // main layout |
|
82 | // main layout | |
83 | chartView = new QChartView(chart); |
|
83 | chartView = new QChartView(chart); | |
84 | QGridLayout* mainLayout = new QGridLayout; |
|
84 | QGridLayout* mainLayout = new QGridLayout; | |
85 | mainLayout->addWidget(chartView, 0, 0); |
|
85 | mainLayout->addWidget(chartView, 0, 0); | |
86 | mainLayout->addLayout(rightPanelLayout, 0, 1); |
|
86 | mainLayout->addLayout(rightPanelLayout, 0, 1); | |
87 | mainLayout->setColumnStretch(0,1); |
|
87 | mainLayout->setColumnStretch(0,1); | |
88 | setLayout(mainLayout); |
|
88 | setLayout(mainLayout); | |
89 |
|
89 | |||
90 | // connect to the database |
|
90 | // connect to the database | |
91 | db = QSqlDatabase::addDatabase("QSQLITE"); |
|
91 | db = QSqlDatabase::addDatabase("QSQLITE"); | |
92 | db.setDatabaseName("gdpData"); |
|
92 | db.setDatabaseName("gdpData"); | |
93 | if(!db.open()) |
|
93 | if(!db.open()) | |
94 | { |
|
94 | { | |
95 | qDebug() << "could not open database. SQLite db file missing (?)"; |
|
95 | qDebug() << "could not open database. SQLite db file missing (?)"; | |
96 | return; |
|
96 | return; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | // get the list of all countires and regions. |
|
99 | // get the list of all countires and regions. | |
100 | QSqlQuery query; |
|
100 | QSqlQuery query; | |
101 | query.exec("SELECT DISTINCT country FROM gdp2"); |
|
101 | query.exec("SELECT DISTINCT country FROM gdp2"); | |
102 |
|
102 | |||
103 | // add the countries to the country filter |
|
103 | // add the countries to the country filter | |
104 | while (query.next()) { |
|
104 | while (query.next()) { | |
105 | countrieslist->addItem(query.value(0).toString()); |
|
105 | countrieslist->addItem(query.value(0).toString()); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | Widget::~Widget() |
|
109 | Widget::~Widget() | |
110 | { |
|
110 | { | |
111 | // |
|
111 | // | |
112 | db.close(); |
|
112 | db.close(); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | refreshes the chart |
|
116 | refreshes the chart | |
117 | */ |
|
117 | */ | |
118 | void Widget::refreshChart() |
|
118 | void Widget::refreshChart() | |
119 | { |
|
119 | { | |
120 | chartView->chart()->removeAllSeries(); |
|
120 | chartView->chart()->removeAllSeries(); | |
121 |
|
121 | |||
122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. |
|
122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. | |
123 | QStringList selectedCountriesStrings; |
|
123 | QStringList selectedCountriesStrings; | |
124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); |
|
124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); | |
125 | for (int i = 0; i < selectedCountriesItems.size(); i++) |
|
125 | for (int i = 0; i < selectedCountriesItems.size(); i++) | |
126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); |
|
126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); | |
127 | selectedCountriesStrings.sort(); |
|
127 | selectedCountriesStrings.sort(); | |
128 |
|
128 | |||
129 | QSqlQuery query; |
|
129 | QSqlQuery query; | |
130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. |
|
130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. | |
131 | QList<int> selectedYearsInts; |
|
131 | QList<int> selectedYearsInts; | |
132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); |
|
132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); | |
133 | for (int i = 0; i < selectedYearsItems.size(); i++) |
|
133 | for (int i = 0; i < selectedYearsItems.size(); i++) | |
134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); |
|
134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); | |
135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); |
|
135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); | |
136 |
|
136 | |||
137 | if (barChartRadioButton->isChecked()) |
|
137 | if (barChartRadioButton->isChecked()) | |
138 | { |
|
138 | { | |
139 | // use the sorted selected coutries list to initialize BarCategory |
|
139 | // use the sorted selected coutries list to initialize BarCategory | |
140 | QStringList category; |
|
140 | QStringList category; | |
141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
142 | category << selectedCountriesStrings[i]; |
|
142 | category << selectedCountriesStrings[i]; | |
143 | QBarSeries* series0 = new QBarSeries(category); |
|
143 | QBarSeries* series0 = new QBarSeries(category); | |
144 | series0 = new QBarSeries(category); |
|
144 | series0 = new QBarSeries(category); | |
145 |
|
145 | |||
146 | // prepare the selected counries SQL query |
|
146 | // prepare the selected counries SQL query | |
147 | QString countriesQuery = "country IN ("; |
|
147 | QString countriesQuery = "country IN ("; | |
148 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
148 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
149 | { |
|
149 | { | |
150 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); |
|
150 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); | |
151 | if ( i < selectedCountriesStrings.size() - 1) |
|
151 | if ( i < selectedCountriesStrings.size() - 1) | |
152 | countriesQuery.append(","); |
|
152 | countriesQuery.append(","); | |
153 | else |
|
153 | else | |
154 | countriesQuery.append(")"); |
|
154 | countriesQuery.append(")"); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | // perform a query for each selected year |
|
157 | // perform a query for each selected year | |
158 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
158 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
159 | { |
|
159 | { | |
160 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); |
|
160 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); | |
161 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); |
|
161 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); | |
162 |
|
162 | |||
163 | // while (query.next()) { |
|
163 | // while (query.next()) { | |
164 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); |
|
164 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); | |
165 | // } |
|
165 | // } | |
166 | query.first(); |
|
166 | query.first(); | |
167 |
|
167 | |||
168 | // the data for some of the coutries for some years might be missing. |
|
168 | // the data for some of the coutries for some years might be missing. | |
169 | // QBarChart needs bars to have same size |
|
169 | // QBarChart needs bars to have same size | |
170 | for (int k = 0; k < selectedCountriesStrings.size(); k++) |
|
170 | for (int k = 0; k < selectedCountriesStrings.size(); k++) | |
171 | { |
|
171 | { | |
172 | if (selectedCountriesStrings[k] == query.value(0).toString()) |
|
172 | if (selectedCountriesStrings[k] == query.value(0).toString()) | |
173 | { |
|
173 | { | |
174 | *barSet << query.value(1).toReal(); |
|
174 | *barSet << query.value(1).toReal(); | |
175 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
175 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); | |
176 | query.next(); |
|
176 | query.next(); | |
177 | } |
|
177 | } | |
178 | else |
|
178 | else | |
179 | { |
|
179 | { | |
180 | // data missing, put 0 |
|
180 | // data missing, put 0 | |
181 | *barSet << 0.0f; |
|
181 | *barSet << 0.0f; | |
182 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
182 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 | series0->appendBarSet(barSet); |
|
185 | series0->appendBarSet(barSet); | |
186 | } |
|
186 | } | |
187 | // add the serie to the chart |
|
187 | // add the serie to the chart | |
188 | chartView->chart()->addSeries(series0); |
|
188 | chartView->chart()->addSeries(series0); | |
189 | } |
|
189 | } | |
190 | else if (scatterChartRadioButton->isChecked()) |
|
190 | else if (scatterChartRadioButton->isChecked()) | |
191 | { |
|
191 | { | |
192 | QString yearsQuery = "year IN ("; |
|
192 | QString yearsQuery = "year IN ("; | |
193 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
193 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
194 | { |
|
194 | { | |
195 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); |
|
195 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); | |
196 | if ( i < selectedYearsInts.size() - 1) |
|
196 | if ( i < selectedYearsInts.size() - 1) | |
197 | yearsQuery.append(","); |
|
197 | yearsQuery.append(","); | |
198 | else |
|
198 | else | |
199 | yearsQuery.append(")"); |
|
199 | yearsQuery.append(")"); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | // perform a query for each selected country |
|
202 | // perform a query for each selected country | |
203 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
203 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
204 | { |
|
204 | { | |
205 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); |
|
205 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); | |
206 | query.first(); |
|
206 | query.first(); | |
207 |
|
207 | |||
208 | QScatterSeries* series = new QScatterSeries; |
|
208 | QScatterSeries* series = new QScatterSeries; | |
209 | series->setName(selectedCountriesStrings[i]); |
|
209 | series->setName(selectedCountriesStrings[i]); | |
210 | // the data for some of the coutries for some years might be missing. |
|
210 | // the data for some of the coutries for some years might be missing. | |
211 | for (int k = 0; k < selectedYearsInts.size(); k++) |
|
211 | for (int k = 0; k < selectedYearsInts.size(); k++) | |
212 | { |
|
212 | { | |
213 | if (selectedYearsInts[k] == query.value(0).toInt()) |
|
213 | if (selectedYearsInts[k] == query.value(0).toInt()) | |
214 | { |
|
214 | { | |
215 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); |
|
215 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); | |
216 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); |
|
216 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); | |
217 | query.next(); |
|
217 | query.next(); | |
218 | } |
|
218 | } | |
219 | else |
|
219 | else | |
220 | { |
|
220 | { | |
221 | // data missing, put 0 |
|
221 | // data missing, put 0 | |
222 | *series << QPointF(selectedYearsInts[k] , 0.0f); |
|
222 | *series << QPointF(selectedYearsInts[k] , 0.0f); | |
223 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); |
|
223 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); | |
224 | } |
|
224 | } | |
225 | } |
|
225 | } | |
226 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); |
|
226 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); | |
227 | chartView->chart()->addSeries(series); |
|
227 | chartView->chart()->addSeries(series); | |
228 | } |
|
228 | } | |
229 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); |
|
229 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void Widget::printChart() |
|
233 | void Widget::printChart() | |
234 | { |
|
234 | { | |
235 | QPrinter printer; |
|
235 | QPrinter printer; | |
236 | // QPrinter printer(QPrinter::HighResolution); |
|
236 | // QPrinter printer(QPrinter::HighResolution); | |
237 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
237 | printer.setOutputFormat(QPrinter::PdfFormat); | |
238 | printer.setOrientation(QPrinter::Landscape); |
|
238 | printer.setOrientation(QPrinter::Landscape); | |
239 | printer.setOutputFileName("print.pdf"); |
|
239 | printer.setOutputFileName("print.pdf"); | |
240 |
|
240 | |||
241 | QPainter painter; |
|
241 | QPainter painter; | |
242 | painter.begin(&printer); |
|
242 | painter.begin(&printer); | |
243 | chartView->render(&painter); |
|
243 | chartView->render(&painter); | |
244 | } |
|
244 | } |
@@ -1,336 +1,336 | |||||
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 "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include <QGridLayout> |
|
22 | #include <QGridLayout> | |
23 | #include <QTableView> |
|
23 | #include <QTableView> | |
24 | #include <QStyledItemDelegate> |
|
24 | #include <QStyledItemDelegate> | |
25 | #include <QLineSeries> |
|
25 | #include <QLineSeries> | |
26 | #include <QSplineSeries> |
|
26 | #include <QSplineSeries> | |
27 | #include <QScatterSeries> |
|
27 | #include <QScatterSeries> | |
28 | #include "customtablemodel.h" |
|
28 | #include "customtablemodel.h" | |
29 | #include <QPieSeries> |
|
29 | #include <QPieSeries> | |
30 | #include <QPieSlice> |
|
30 | #include <QPieSlice> | |
31 | #include <QAreaSeries> |
|
31 | #include <QAreaSeries> | |
32 | #include <QBarSeries> |
|
32 | #include <QBarSeries> | |
33 | #include <QBarSet> |
|
33 | #include <QBarSet> | |
34 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
35 | #include <QRadioButton> |
|
35 | #include <QRadioButton> | |
36 | #include <QLabel> |
|
36 | #include <QLabel> | |
37 | #include <QSpinBox> |
|
37 | #include <QSpinBox> | |
38 | #include <QTime> |
|
38 | #include <QTime> | |
39 |
|
39 | |||
40 | TableWidget::TableWidget(QWidget *parent) |
|
40 | TableWidget::TableWidget(QWidget *parent) | |
41 | : QWidget(parent) |
|
41 | : QWidget(parent) | |
42 | { |
|
42 | { | |
43 | setGeometry(100, 100, 1000, 600); |
|
43 | setGeometry(100, 100, 1000, 600); | |
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
45 | // create simple model for storing data |
|
45 | // create simple model for storing data | |
46 | // user's table data model |
|
46 | // user's table data model | |
47 | m_model = new CustomTableModel; |
|
47 | m_model = new CustomTableModel; | |
48 | m_tableView = new QTableView; |
|
48 | m_tableView = new QTableView; | |
49 | m_tableView->setModel(m_model); |
|
49 | m_tableView->setModel(m_model); | |
50 | m_tableView->setMinimumHeight(300); |
|
50 | m_tableView->setMinimumHeight(300); | |
51 | // tableView->setMinimumSize(340, 480); |
|
51 | // tableView->setMinimumSize(340, 480); | |
52 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
52 | // tableView->setItemDelegate(new QStyledItemDelegate); | |
53 | m_chart = new QChart; |
|
53 | m_chart = new QChart; | |
54 | m_chartView = new QChartView(m_chart); |
|
54 | m_chartView = new QChartView(m_chart); | |
55 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
55 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
56 | m_chartView->setMinimumSize(640, 480); |
|
56 | m_chartView->setMinimumSize(640, 480); | |
57 |
|
57 | |||
58 | // add, remove data buttons |
|
58 | // add, remove data buttons | |
59 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
59 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
60 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
60 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
61 |
|
61 | |||
62 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
62 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
63 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
63 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
64 |
|
64 | |||
65 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
65 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
66 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
66 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
67 |
|
67 | |||
68 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
68 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
69 |
|
69 | |||
70 | // spin box for setting number of affected items (add, remove) |
|
70 | // spin box for setting number of affected items (add, remove) | |
71 | m_linesCountSpinBox = new QSpinBox; |
|
71 | m_linesCountSpinBox = new QSpinBox; | |
72 | m_linesCountSpinBox->setRange(1, 10); |
|
72 | m_linesCountSpinBox->setRange(1, 10); | |
73 | m_linesCountSpinBox->setValue(1); |
|
73 | m_linesCountSpinBox->setValue(1); | |
74 |
|
74 | |||
75 | // buttons layout |
|
75 | // buttons layout | |
76 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
76 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
77 | buttonsLayout->addWidget(spinBoxLabel); |
|
77 | buttonsLayout->addWidget(spinBoxLabel); | |
78 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
78 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
79 | buttonsLayout->addWidget(addRowAboveButton); |
|
79 | buttonsLayout->addWidget(addRowAboveButton); | |
80 | buttonsLayout->addWidget(addRowBelowButton); |
|
80 | buttonsLayout->addWidget(addRowBelowButton); | |
81 | buttonsLayout->addWidget(removeRowButton); |
|
81 | buttonsLayout->addWidget(removeRowButton); | |
82 | buttonsLayout->addStretch(); |
|
82 | buttonsLayout->addStretch(); | |
83 |
|
83 | |||
84 | // chart type radio buttons |
|
84 | // chart type radio buttons | |
85 | m_lineRadioButton = new QRadioButton("Line"); |
|
85 | m_lineRadioButton = new QRadioButton("Line"); | |
86 | m_splineRadioButton = new QRadioButton("Spline"); |
|
86 | m_splineRadioButton = new QRadioButton("Spline"); | |
87 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
87 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
88 | m_pieRadioButton = new QRadioButton("Pie"); |
|
88 | m_pieRadioButton = new QRadioButton("Pie"); | |
89 | m_areaRadioButton = new QRadioButton("Area"); |
|
89 | m_areaRadioButton = new QRadioButton("Area"); | |
90 | m_barRadioButton = new QRadioButton("Bar"); |
|
90 | m_barRadioButton = new QRadioButton("Bar"); | |
91 |
|
91 | |||
92 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
92 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
93 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
93 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
94 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
94 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
95 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
95 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
96 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
96 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
97 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
97 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
98 | m_lineRadioButton->setChecked(true); |
|
98 | m_lineRadioButton->setChecked(true); | |
99 |
|
99 | |||
100 | // radio buttons layout |
|
100 | // radio buttons layout | |
101 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
101 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
102 | radioLayout->addWidget(m_lineRadioButton); |
|
102 | radioLayout->addWidget(m_lineRadioButton); | |
103 | radioLayout->addWidget(m_splineRadioButton); |
|
103 | radioLayout->addWidget(m_splineRadioButton); | |
104 | radioLayout->addWidget(m_scatterRadioButton); |
|
104 | radioLayout->addWidget(m_scatterRadioButton); | |
105 | radioLayout->addWidget(m_pieRadioButton); |
|
105 | radioLayout->addWidget(m_pieRadioButton); | |
106 | radioLayout->addWidget(m_areaRadioButton); |
|
106 | radioLayout->addWidget(m_areaRadioButton); | |
107 | radioLayout->addWidget(m_barRadioButton); |
|
107 | radioLayout->addWidget(m_barRadioButton); | |
108 | radioLayout->addStretch(); |
|
108 | radioLayout->addStretch(); | |
109 |
|
109 | |||
110 | // create main layout |
|
110 | // create main layout | |
111 | QGridLayout* mainLayout = new QGridLayout; |
|
111 | QGridLayout* mainLayout = new QGridLayout; | |
112 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
112 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
113 | mainLayout->addLayout(radioLayout, 2, 1); |
|
113 | mainLayout->addLayout(radioLayout, 2, 1); | |
114 | mainLayout->addWidget(m_tableView, 1, 0); |
|
114 | mainLayout->addWidget(m_tableView, 1, 0); | |
115 | mainLayout->addWidget(m_chartView, 2, 0); |
|
115 | mainLayout->addWidget(m_chartView, 2, 0); | |
116 | setLayout(mainLayout); |
|
116 | setLayout(mainLayout); | |
117 | m_lineRadioButton->setFocus(); |
|
117 | m_lineRadioButton->setFocus(); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void TableWidget::addRowAbove() |
|
120 | void TableWidget::addRowAbove() | |
121 | { |
|
121 | { | |
122 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
122 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
123 |
|
123 | |||
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void TableWidget::addRowBelow() |
|
126 | void TableWidget::addRowBelow() | |
127 | { |
|
127 | { | |
128 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
128 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
129 |
|
129 | |||
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void TableWidget::removeRow() |
|
132 | void TableWidget::removeRow() | |
133 | { |
|
133 | { | |
134 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
134 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void TableWidget::updateChartType(bool toggle) |
|
137 | void TableWidget::updateChartType(bool toggle) | |
138 | { |
|
138 | { | |
139 | // this if is needed, so that the function is only called once. |
|
139 | // this if is needed, so that the function is only called once. | |
140 | // For the radioButton that was enabled. |
|
140 | // For the radioButton that was enabled. | |
141 | if (toggle) { |
|
141 | if (toggle) { | |
142 | m_chart->removeAllSeries(); |
|
142 | m_chart->removeAllSeries(); | |
143 |
|
143 | |||
144 | // renable axes of the chart (pie hides them) |
|
144 | // renable axes of the chart (pie hides them) | |
145 | // x axis |
|
145 | // x axis | |
146 |
Q |
|
146 | QAxis *axis = m_chart->axisX(); | |
147 | axis->setAxisVisible(true); |
|
147 | axis->setAxisVisible(true); | |
148 | axis->setGridLineVisible(true); |
|
148 | axis->setGridLineVisible(true); | |
149 | axis->setLabelsVisible(true); |
|
149 | axis->setLabelsVisible(true); | |
150 |
|
150 | |||
151 | // y axis |
|
151 | // y axis | |
152 | axis = m_chart->axisY(); |
|
152 | axis = m_chart->axisY(); | |
153 | axis->setAxisVisible(true); |
|
153 | axis->setAxisVisible(true); | |
154 | axis->setGridLineVisible(true); |
|
154 | axis->setGridLineVisible(true); | |
155 | axis->setLabelsVisible(true); |
|
155 | axis->setLabelsVisible(true); | |
156 |
|
156 | |||
157 | m_model->clearMapping(); |
|
157 | m_model->clearMapping(); | |
158 |
|
158 | |||
159 | QString seriesColorHex = "#000000"; |
|
159 | QString seriesColorHex = "#000000"; | |
160 | QPen pen; |
|
160 | QPen pen; | |
161 | pen.setWidth(2); |
|
161 | pen.setWidth(2); | |
162 |
|
162 | |||
163 | if (m_lineRadioButton->isChecked()) |
|
163 | if (m_lineRadioButton->isChecked()) | |
164 | { |
|
164 | { | |
165 | // series 1 |
|
165 | // series 1 | |
166 | m_series = new QLineSeries; |
|
166 | m_series = new QLineSeries; | |
167 | m_series->setModel(m_model); |
|
167 | m_series->setModel(m_model); | |
168 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
168 | m_series->setModelMapping(0,1, Qt::Vertical); | |
169 | // m_series->setModelMappingRange(1, 4); |
|
169 | // m_series->setModelMappingRange(1, 4); | |
170 | m_chart->addSeries(m_series); |
|
170 | m_chart->addSeries(m_series); | |
171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
173 |
|
173 | |||
174 | // series 2 |
|
174 | // series 2 | |
175 | m_series = new QLineSeries; |
|
175 | m_series = new QLineSeries; | |
176 | m_series->setModel(m_model); |
|
176 | m_series->setModel(m_model); | |
177 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
177 | m_series->setModelMapping(2,3, Qt::Vertical); | |
178 | m_chart->addSeries(m_series); |
|
178 | m_chart->addSeries(m_series); | |
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
180 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
180 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
181 |
|
181 | |||
182 | // series 3 |
|
182 | // series 3 | |
183 | m_series = new QLineSeries; |
|
183 | m_series = new QLineSeries; | |
184 | m_series->setModel(m_model); |
|
184 | m_series->setModel(m_model); | |
185 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
185 | m_series->setModelMapping(4,5, Qt::Vertical); | |
186 | // m_series->setModelMappingRange(2, 0); |
|
186 | // m_series->setModelMappingRange(2, 0); | |
187 | m_chart->addSeries(m_series); |
|
187 | m_chart->addSeries(m_series); | |
188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
190 | } |
|
190 | } | |
191 | else if (m_splineRadioButton->isChecked()) |
|
191 | else if (m_splineRadioButton->isChecked()) | |
192 | { |
|
192 | { | |
193 | // series 1 |
|
193 | // series 1 | |
194 | m_series = new QSplineSeries; |
|
194 | m_series = new QSplineSeries; | |
195 | m_series->setModel(m_model); |
|
195 | m_series->setModel(m_model); | |
196 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
196 | m_series->setModelMapping(0,1, Qt::Vertical); | |
197 | // m_series->setModelMappingRange(1, 4); |
|
197 | // m_series->setModelMappingRange(1, 4); | |
198 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
198 | // series->setModelMapping(0,1, Qt::Horizontal); | |
199 | m_chart->addSeries(m_series); |
|
199 | m_chart->addSeries(m_series); | |
200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
201 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
201 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
202 |
|
202 | |||
203 | // series 2 |
|
203 | // series 2 | |
204 | m_series = new QSplineSeries; |
|
204 | m_series = new QSplineSeries; | |
205 | m_series->setModel(m_model); |
|
205 | m_series->setModel(m_model); | |
206 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
206 | m_series->setModelMapping(2,3, Qt::Vertical); | |
207 | // m_series->setModelMappingRange(0, 0); |
|
207 | // m_series->setModelMappingRange(0, 0); | |
208 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
208 | // series->setModelMapping(2,3, Qt::Horizontal); | |
209 | m_chart->addSeries(m_series); |
|
209 | m_chart->addSeries(m_series); | |
210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
211 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
211 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
212 |
|
212 | |||
213 | // series 3 |
|
213 | // series 3 | |
214 | m_series = new QSplineSeries; |
|
214 | m_series = new QSplineSeries; | |
215 | m_series->setModel(m_model); |
|
215 | m_series->setModel(m_model); | |
216 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
216 | m_series->setModelMapping(4,5, Qt::Vertical); | |
217 | // m_series->setModelMappingRange(2, 0); |
|
217 | // m_series->setModelMappingRange(2, 0); | |
218 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
218 | // series->setModelMapping(4,5, Qt::Horizontal); | |
219 | m_chart->addSeries(m_series); |
|
219 | m_chart->addSeries(m_series); | |
220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
221 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
221 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
222 | } |
|
222 | } | |
223 | else if (m_scatterRadioButton->isChecked()) |
|
223 | else if (m_scatterRadioButton->isChecked()) | |
224 | { |
|
224 | { | |
225 | // series 1 |
|
225 | // series 1 | |
226 | m_series = new QScatterSeries; |
|
226 | m_series = new QScatterSeries; | |
227 | m_series->setModel(m_model); |
|
227 | m_series->setModel(m_model); | |
228 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
228 | m_series->setModelMapping(0,1, Qt::Vertical); | |
229 | // m_series->setModelMappingRange(2, 0); |
|
229 | // m_series->setModelMappingRange(2, 0); | |
230 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
230 | // series->setModelMapping(0,1, Qt::Horizontal); | |
231 | m_chart->addSeries(m_series); |
|
231 | m_chart->addSeries(m_series); | |
232 |
|
232 | |||
233 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
233 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
234 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
234 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
235 |
|
235 | |||
236 | // series 2 |
|
236 | // series 2 | |
237 | m_series = new QScatterSeries; |
|
237 | m_series = new QScatterSeries; | |
238 | m_series->setModel(m_model); |
|
238 | m_series->setModel(m_model); | |
239 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
239 | m_series->setModelMapping(2,3, Qt::Vertical); | |
240 | // m_series->setModelMappingRange(1, 6); |
|
240 | // m_series->setModelMappingRange(1, 6); | |
241 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
241 | // series->setModelMapping(2,3, Qt::Horizontal); | |
242 | m_chart->addSeries(m_series); |
|
242 | m_chart->addSeries(m_series); | |
243 |
|
243 | |||
244 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
244 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
245 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
245 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
246 |
|
246 | |||
247 | // series 3 |
|
247 | // series 3 | |
248 | m_series = new QScatterSeries; |
|
248 | m_series = new QScatterSeries; | |
249 | m_series->setModel(m_model); |
|
249 | m_series->setModel(m_model); | |
250 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
250 | m_series->setModelMapping(4,5, Qt::Vertical); | |
251 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
251 | // series->setModelMapping(4,5, Qt::Horizontal); | |
252 | m_chart->addSeries(m_series); |
|
252 | m_chart->addSeries(m_series); | |
253 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
253 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
254 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
254 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
255 | } |
|
255 | } | |
256 | else if (m_pieRadioButton->isChecked()) |
|
256 | else if (m_pieRadioButton->isChecked()) | |
257 | { |
|
257 | { | |
258 | // pie 1 |
|
258 | // pie 1 | |
259 | QPieSeries* pieSeries = new QPieSeries; |
|
259 | QPieSeries* pieSeries = new QPieSeries; | |
260 | pieSeries->setModel(m_model); |
|
260 | pieSeries->setModel(m_model); | |
261 | pieSeries->setModelMapping(0,0, Qt::Vertical); |
|
261 | pieSeries->setModelMapping(0,0, Qt::Vertical); | |
262 | pieSeries->setLabelsVisible(true); |
|
262 | pieSeries->setLabelsVisible(true); | |
263 | pieSeries->setPieSize(0.4); |
|
263 | pieSeries->setPieSize(0.4); | |
264 | pieSeries->setHorizontalPosition(0.2); |
|
264 | pieSeries->setHorizontalPosition(0.2); | |
265 | pieSeries->setVerticalPosition(0.35); |
|
265 | pieSeries->setVerticalPosition(0.35); | |
266 |
|
266 | |||
267 | m_chart->addSeries(pieSeries); |
|
267 | m_chart->addSeries(pieSeries); | |
268 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
268 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
269 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); |
|
269 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); | |
270 |
|
270 | |||
271 | // pie 2 |
|
271 | // pie 2 | |
272 | pieSeries = new QPieSeries; |
|
272 | pieSeries = new QPieSeries; | |
273 | pieSeries->setModel(m_model); |
|
273 | pieSeries->setModel(m_model); | |
274 | pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
274 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
275 | pieSeries->setLabelsVisible(true); |
|
275 | pieSeries->setLabelsVisible(true); | |
276 | pieSeries->setPieSize(0.4); |
|
276 | pieSeries->setPieSize(0.4); | |
277 | pieSeries->setHorizontalPosition(0.8); |
|
277 | pieSeries->setHorizontalPosition(0.8); | |
278 | pieSeries->setVerticalPosition(0.35); |
|
278 | pieSeries->setVerticalPosition(0.35); | |
279 | m_chart->addSeries(pieSeries); |
|
279 | m_chart->addSeries(pieSeries); | |
280 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
280 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
281 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); |
|
281 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); | |
282 |
|
282 | |||
283 | // pie 3 |
|
283 | // pie 3 | |
284 | pieSeries = new QPieSeries; |
|
284 | pieSeries = new QPieSeries; | |
285 | pieSeries->setModel(m_model); |
|
285 | pieSeries->setModel(m_model); | |
286 | pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
286 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
287 | pieSeries->setLabelsVisible(true); |
|
287 | pieSeries->setLabelsVisible(true); | |
288 | pieSeries->setPieSize(0.4); |
|
288 | pieSeries->setPieSize(0.4); | |
289 | pieSeries->setHorizontalPosition(0.5); |
|
289 | pieSeries->setHorizontalPosition(0.5); | |
290 | pieSeries->setVerticalPosition(0.65); |
|
290 | pieSeries->setVerticalPosition(0.65); | |
291 | m_chart->addSeries(pieSeries); |
|
291 | m_chart->addSeries(pieSeries); | |
292 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
292 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
293 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
293 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
294 | } |
|
294 | } | |
295 | else if (m_areaRadioButton->isChecked()) |
|
295 | else if (m_areaRadioButton->isChecked()) | |
296 | { |
|
296 | { | |
297 | QLineSeries* upperLineSeries = new QLineSeries; |
|
297 | QLineSeries* upperLineSeries = new QLineSeries; | |
298 | upperLineSeries->setModel(m_model); |
|
298 | upperLineSeries->setModel(m_model); | |
299 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
299 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
300 | // upperLineSeries->setModelMappingRange(1, 5); |
|
300 | // upperLineSeries->setModelMappingRange(1, 5); | |
301 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
301 | QLineSeries* lowerLineSeries = new QLineSeries; | |
302 | lowerLineSeries->setModel(m_model); |
|
302 | lowerLineSeries->setModel(m_model); | |
303 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
303 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
304 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
304 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
305 | m_chart->addSeries(areaSeries); |
|
305 | m_chart->addSeries(areaSeries); | |
306 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
306 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
307 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
307 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
308 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
308 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
309 | } |
|
309 | } | |
310 | else if (m_barRadioButton->isChecked()) |
|
310 | else if (m_barRadioButton->isChecked()) | |
311 | { |
|
311 | { | |
312 | QBarSeries* barSeries = new QBarSeries(QStringList()); |
|
312 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
313 | barSeries->setModel(m_model); |
|
313 | barSeries->setModel(m_model); | |
314 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
314 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
315 | m_chart->addSeries(barSeries); |
|
315 | m_chart->addSeries(barSeries); | |
316 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
316 | QList<QBarSet*> barsets = barSeries->barSets(); | |
317 | for (int i = 0; i < barsets.count(); i++) { |
|
317 | for (int i = 0; i < barsets.count(); i++) { | |
318 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
318 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
319 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
319 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
320 | } |
|
320 | } | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 |
|
323 | |||
324 | m_chart->axisX()->setRange(0, 500); |
|
324 | m_chart->axisX()->setRange(0, 500); | |
325 | m_chart->axisY()->setRange(0, 120); |
|
325 | m_chart->axisY()->setRange(0, 120); | |
326 |
|
326 | |||
327 | // repaint table view colors |
|
327 | // repaint table view colors | |
328 | m_tableView->repaint(); |
|
328 | m_tableView->repaint(); | |
329 | m_tableView->setFocus(); |
|
329 | m_tableView->setFocus(); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | TableWidget::~TableWidget() |
|
333 | TableWidget::~TableWidget() | |
334 | { |
|
334 | { | |
335 |
|
335 | |||
336 | } |
|
336 | } |
General Comments 0
You need to be logged in to leave comments.
Login now