@@ -1,101 +1,101 | |||||
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 <QtDeclarative/qdeclarativeextensionplugin.h> |
|
21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
22 | #include <QtDeclarative/qdeclarative.h> |
|
22 | #include <QtDeclarative/qdeclarative.h> | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
#include "qvalue |
|
25 | #include "qvalueaxis.h" | |
26 | #include "qbarcategoriesaxis.h" |
|
26 | #include "qbarcategoriesaxis.h" | |
27 | #include "declarativechart.h" |
|
27 | #include "declarativechart.h" | |
28 | #include "declarativexypoint.h" |
|
28 | #include "declarativexypoint.h" | |
29 | #include "declarativelineseries.h" |
|
29 | #include "declarativelineseries.h" | |
30 | #include "declarativesplineseries.h" |
|
30 | #include "declarativesplineseries.h" | |
31 | #include "declarativeareaseries.h" |
|
31 | #include "declarativeareaseries.h" | |
32 | #include "declarativescatterseries.h" |
|
32 | #include "declarativescatterseries.h" | |
33 | #include "declarativebarseries.h" |
|
33 | #include "declarativebarseries.h" | |
34 | #include "declarativepieseries.h" |
|
34 | #include "declarativepieseries.h" | |
35 | #include "qvxymodelmapper.h" |
|
35 | #include "qvxymodelmapper.h" | |
36 | #include "qhxymodelmapper.h" |
|
36 | #include "qhxymodelmapper.h" | |
37 | #include "qhpiemodelmapper.h" |
|
37 | #include "qhpiemodelmapper.h" | |
38 | #include "qvpiemodelmapper.h" |
|
38 | #include "qvpiemodelmapper.h" | |
39 | #include "qhbarmodelmapper.h" |
|
39 | #include "qhbarmodelmapper.h" | |
40 | #include "qvbarmodelmapper.h" |
|
40 | #include "qvbarmodelmapper.h" | |
41 | #include <QAbstractItemModel> |
|
41 | #include <QAbstractItemModel> | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
44 | |||
45 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
45 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | virtual void registerTypes(const char *uri) |
|
49 | virtual void registerTypes(const char *uri) | |
50 | { |
|
50 | { | |
51 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
51 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
52 |
|
52 | |||
53 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
53 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
54 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
54 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); | |
55 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
55 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
56 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
56 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
57 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
57 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
58 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
58 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
59 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
59 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
60 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
60 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); | |
61 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
61 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); | |
62 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
62 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
63 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
63 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
64 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
64 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
65 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
65 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); | |
66 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
66 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); | |
67 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
67 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); | |
68 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
68 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); | |
69 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
69 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); | |
70 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
70 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); | |
71 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); |
|
71 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); | |
72 | qmlRegisterType<QBarCategoriesAxis>(uri, 1, 0, "BarCategoriesAxis"); |
|
72 | qmlRegisterType<QBarCategoriesAxis>(uri, 1, 0, "BarCategoriesAxis"); | |
73 |
|
73 | |||
74 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
74 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", | |
75 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
75 | QLatin1String("Trying to create uncreatable: Legend.")); | |
76 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
76 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", | |
77 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
77 | QLatin1String("Trying to create uncreatable: XYSeries.")); | |
78 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
78 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", | |
79 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
79 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); | |
80 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
80 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
81 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
81 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
82 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
82 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
83 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
83 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
84 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
84 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", | |
85 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
85 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); | |
86 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
86 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", | |
87 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
87 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); | |
88 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", |
|
88 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", | |
89 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); |
|
89 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); | |
90 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
90 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", | |
91 | QLatin1String("Trying to create uncreatable: AbstractAxis.")); |
|
91 | QLatin1String("Trying to create uncreatable: AbstractAxis.")); | |
92 | } |
|
92 | } | |
93 | }; |
|
93 | }; | |
94 |
|
94 | |||
95 | #include "plugin.moc" |
|
95 | #include "plugin.moc" | |
96 |
|
96 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
98 |
|
98 | |||
99 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
99 | QTCOMMERCIALCHART_USE_NAMESPACE | |
100 |
|
100 | |||
101 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
101 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,396 +1,396 | |||||
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 "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "legendmarker_p.h" |
|
25 | #include "legendmarker_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 |
#include "qvalue |
|
29 | #include "qvalueaxis.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QAreaSeries |
|
34 | \class QAreaSeries | |
35 | \brief The QAreaSeries class is used for making area charts. |
|
35 | \brief The QAreaSeries class is used for making area charts. | |
36 |
|
36 | |||
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
44 |
|
44 | |||
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
46 | \image examples_areachart.png |
|
46 | \image examples_areachart.png | |
47 | */ |
|
47 | */ | |
48 | /*! |
|
48 | /*! | |
49 | \qmlclass AreaSeries QAreaSeries |
|
49 | \qmlclass AreaSeries QAreaSeries | |
50 |
|
50 | |||
51 | The following QML shows how to create a simple area chart: |
|
51 | The following QML shows how to create a simple area chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image demos_qmlchart4.png |
|
54 | \image demos_qmlchart4.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QAreaSeries::upperSeries |
|
60 | \property QAreaSeries::upperSeries | |
61 | \brief The upper one of the two line series used to define area series boundaries. |
|
61 | \brief The upper one of the two line series used to define area series boundaries. | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
64 | \qmlproperty LineSeries AreaSeries::upperSeries | |
65 | The upper one of the two line series used to define area series boundaries. |
|
65 | The upper one of the two line series used to define area series boundaries. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QAreaSeries::lowerSeries |
|
69 | \property QAreaSeries::lowerSeries | |
70 | The lower one of the two line series used to define are series boundaries. Note if |
|
70 | The lower one of the two line series used to define are series boundaries. Note if | |
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
72 | */ |
|
72 | */ | |
73 | /*! |
|
73 | /*! | |
74 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
74 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
75 | The lower one of the two line series used to define are series boundaries. Note if |
|
75 | The lower one of the two line series used to define are series boundaries. Note if | |
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QAreaSeries::color |
|
80 | \property QAreaSeries::color | |
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
82 | \sa QAreaSeries::brush() |
|
82 | \sa QAreaSeries::brush() | |
83 | */ |
|
83 | */ | |
84 | /*! |
|
84 | /*! | |
85 | \qmlproperty color AreaSeries::color |
|
85 | \qmlproperty color AreaSeries::color | |
86 | Fill (brush) color of the series. |
|
86 | Fill (brush) color of the series. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QAreaSeries::borderColor |
|
90 | \property QAreaSeries::borderColor | |
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
92 | \sa QAreaSeries::pen() |
|
92 | \sa QAreaSeries::pen() | |
93 | */ |
|
93 | */ | |
94 | /*! |
|
94 | /*! | |
95 | \qmlproperty color AreaSeries::borderColor |
|
95 | \qmlproperty color AreaSeries::borderColor | |
96 | Line (pen) color of the series. |
|
96 | Line (pen) color of the series. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \fn QPen QAreaSeries::pen() const |
|
100 | \fn QPen QAreaSeries::pen() const | |
101 | \brief Returns the pen used to draw line for this series. |
|
101 | \brief Returns the pen used to draw line for this series. | |
102 | \sa setPen() |
|
102 | \sa setPen() | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \fn QPen QAreaSeries::brush() const |
|
106 | \fn QPen QAreaSeries::brush() const | |
107 | \brief Returns the brush used to draw line for this series. |
|
107 | \brief Returns the brush used to draw line for this series. | |
108 | \sa setBrush() |
|
108 | \sa setBrush() | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \fn void QAreaSeries::colorChanged(QColor color) |
|
112 | \fn void QAreaSeries::colorChanged(QColor color) | |
113 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
113 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
116 | \qmlsignal AreaSeries::onColorChanged(color color) | |
117 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
117 | Signal is emitted when the fill (brush) color has changed to \a color. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
121 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
123 | */ |
|
123 | */ | |
124 | /*! |
|
124 | /*! | |
125 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
125 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
126 | Signal is emitted when the line (pen) color has changed to \a color. |
|
126 | Signal is emitted when the line (pen) color has changed to \a color. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
130 | \fn void QAreaSeries::clicked(const QPointF& point) | |
131 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
131 | \brief Signal is emitted when user clicks the \a point on area chart. | |
132 | */ |
|
132 | */ | |
133 | /*! |
|
133 | /*! | |
134 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
134 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
135 | Signal is emitted when user clicks the \a point on area chart. |
|
135 | Signal is emitted when user clicks the \a point on area chart. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QAreaSeries::selected() |
|
139 | \fn void QAreaSeries::selected() | |
140 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
140 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
141 | implemented by the user of QAreaSeries API. |
|
141 | implemented by the user of QAreaSeries API. | |
142 | */ |
|
142 | */ | |
143 | /*! |
|
143 | /*! | |
144 | \qmlsignal AreaSeries::onSelected() |
|
144 | \qmlsignal AreaSeries::onSelected() | |
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
146 | implemented by the user of AreaSeries API. |
|
146 | implemented by the user of AreaSeries API. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QAreaSeriesPrivate::updated() |
|
150 | \fn void QAreaSeriesPrivate::updated() | |
151 | \brief \internal |
|
151 | \brief \internal | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
155 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
156 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
156 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
157 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
157 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
158 | */ |
|
158 | */ | |
159 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
159 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
160 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) |
|
160 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) | |
161 | { |
|
161 | { | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Constructs area series object without upper or lower series with \a parent object. |
|
165 | Constructs area series object without upper or lower series with \a parent object. | |
166 | */ |
|
166 | */ | |
167 | QAreaSeries::QAreaSeries(QObject *parent) |
|
167 | QAreaSeries::QAreaSeries(QObject *parent) | |
168 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
168 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
169 | { |
|
169 | { | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Destroys the object. |
|
173 | Destroys the object. | |
174 | */ |
|
174 | */ | |
175 | QAreaSeries::~QAreaSeries() |
|
175 | QAreaSeries::~QAreaSeries() | |
176 | { |
|
176 | { | |
177 | Q_D(QAreaSeries); |
|
177 | Q_D(QAreaSeries); | |
178 | if(d->m_dataset){ |
|
178 | if(d->m_dataset){ | |
179 | d->m_dataset->removeSeries(this); |
|
179 | d->m_dataset->removeSeries(this); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | Returns QChartSeries::SeriesTypeArea. |
|
184 | Returns QChartSeries::SeriesTypeArea. | |
185 | */ |
|
185 | */ | |
186 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
186 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
187 | { |
|
187 | { | |
188 | return QAbstractSeries::SeriesTypeArea; |
|
188 | return QAbstractSeries::SeriesTypeArea; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Sets the \a series that is to be used as the area chart upper series. |
|
192 | Sets the \a series that is to be used as the area chart upper series. | |
193 | */ |
|
193 | */ | |
194 | void QAreaSeries::setUpperSeries(QLineSeries* series) |
|
194 | void QAreaSeries::setUpperSeries(QLineSeries* series) | |
195 | { |
|
195 | { | |
196 | Q_D(QAreaSeries); |
|
196 | Q_D(QAreaSeries); | |
197 | d->m_upperSeries = series; |
|
197 | d->m_upperSeries = series; | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | QLineSeries* QAreaSeries::upperSeries() const |
|
200 | QLineSeries* QAreaSeries::upperSeries() const | |
201 | { |
|
201 | { | |
202 | Q_D(const QAreaSeries); |
|
202 | Q_D(const QAreaSeries); | |
203 | return d->m_upperSeries; |
|
203 | return d->m_upperSeries; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Sets the \a series that is to be used as the area chart lower series. |
|
207 | Sets the \a series that is to be used as the area chart lower series. | |
208 | */ |
|
208 | */ | |
209 | void QAreaSeries::setLowerSeries(QLineSeries* series) |
|
209 | void QAreaSeries::setLowerSeries(QLineSeries* series) | |
210 | { |
|
210 | { | |
211 | Q_D(QAreaSeries); |
|
211 | Q_D(QAreaSeries); | |
212 | d->m_lowerSeries = series; |
|
212 | d->m_lowerSeries = series; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | QLineSeries* QAreaSeries::lowerSeries() const |
|
215 | QLineSeries* QAreaSeries::lowerSeries() const | |
216 | { |
|
216 | { | |
217 | Q_D(const QAreaSeries); |
|
217 | Q_D(const QAreaSeries); | |
218 | return d->m_lowerSeries; |
|
218 | return d->m_lowerSeries; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Sets \a pen used for drawing area outline. |
|
222 | Sets \a pen used for drawing area outline. | |
223 | */ |
|
223 | */ | |
224 | void QAreaSeries::setPen(const QPen &pen) |
|
224 | void QAreaSeries::setPen(const QPen &pen) | |
225 | { |
|
225 | { | |
226 | Q_D(QAreaSeries); |
|
226 | Q_D(QAreaSeries); | |
227 | if (d->m_pen != pen) { |
|
227 | if (d->m_pen != pen) { | |
228 | d->m_pen = pen; |
|
228 | d->m_pen = pen; | |
229 | emit d->updated(); |
|
229 | emit d->updated(); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | QPen QAreaSeries::pen() const |
|
233 | QPen QAreaSeries::pen() const | |
234 | { |
|
234 | { | |
235 | Q_D(const QAreaSeries); |
|
235 | Q_D(const QAreaSeries); | |
236 | return d->m_pen; |
|
236 | return d->m_pen; | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Sets \a brush used for filling the area. |
|
240 | Sets \a brush used for filling the area. | |
241 | */ |
|
241 | */ | |
242 | void QAreaSeries::setBrush(const QBrush &brush) |
|
242 | void QAreaSeries::setBrush(const QBrush &brush) | |
243 | { |
|
243 | { | |
244 | Q_D(QAreaSeries); |
|
244 | Q_D(QAreaSeries); | |
245 | if (d->m_brush != brush) { |
|
245 | if (d->m_brush != brush) { | |
246 | d->m_brush = brush; |
|
246 | d->m_brush = brush; | |
247 | emit d->updated(); |
|
247 | emit d->updated(); | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | QBrush QAreaSeries::brush() const |
|
251 | QBrush QAreaSeries::brush() const | |
252 | { |
|
252 | { | |
253 | Q_D(const QAreaSeries); |
|
253 | Q_D(const QAreaSeries); | |
254 | return d->m_brush; |
|
254 | return d->m_brush; | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void QAreaSeries::setColor(const QColor &color) |
|
257 | void QAreaSeries::setColor(const QColor &color) | |
258 | { |
|
258 | { | |
259 | QBrush b = brush(); |
|
259 | QBrush b = brush(); | |
260 | if (b.color() != color) { |
|
260 | if (b.color() != color) { | |
261 | b.setColor(color); |
|
261 | b.setColor(color); | |
262 | setBrush(b); |
|
262 | setBrush(b); | |
263 | emit colorChanged(color); |
|
263 | emit colorChanged(color); | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | QColor QAreaSeries::color() const |
|
267 | QColor QAreaSeries::color() const | |
268 | { |
|
268 | { | |
269 | return brush().color(); |
|
269 | return brush().color(); | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void QAreaSeries::setBorderColor(const QColor &color) |
|
272 | void QAreaSeries::setBorderColor(const QColor &color) | |
273 | { |
|
273 | { | |
274 | QPen p = pen(); |
|
274 | QPen p = pen(); | |
275 | if (p.color() != color) { |
|
275 | if (p.color() != color) { | |
276 | p.setColor(color); |
|
276 | p.setColor(color); | |
277 | setPen(p); |
|
277 | setPen(p); | |
278 | emit borderColorChanged(color); |
|
278 | emit borderColorChanged(color); | |
279 | } |
|
279 | } | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | QColor QAreaSeries::borderColor() const |
|
282 | QColor QAreaSeries::borderColor() const | |
283 | { |
|
283 | { | |
284 | return pen().color(); |
|
284 | return pen().color(); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Sets if data points are \a visible and should be drawn on line. |
|
288 | Sets if data points are \a visible and should be drawn on line. | |
289 | */ |
|
289 | */ | |
290 | void QAreaSeries::setPointsVisible(bool visible) |
|
290 | void QAreaSeries::setPointsVisible(bool visible) | |
291 | { |
|
291 | { | |
292 | Q_D(QAreaSeries); |
|
292 | Q_D(QAreaSeries); | |
293 | if (d->m_pointsVisible != visible) { |
|
293 | if (d->m_pointsVisible != visible) { | |
294 | d->m_pointsVisible = visible; |
|
294 | d->m_pointsVisible = visible; | |
295 | emit d->updated(); |
|
295 | emit d->updated(); | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Returns if the points are drawn for this series. |
|
300 | Returns if the points are drawn for this series. | |
301 | \sa setPointsVisible() |
|
301 | \sa setPointsVisible() | |
302 | */ |
|
302 | */ | |
303 | bool QAreaSeries::pointsVisible() const |
|
303 | bool QAreaSeries::pointsVisible() const | |
304 | { |
|
304 | { | |
305 | Q_D(const QAreaSeries); |
|
305 | Q_D(const QAreaSeries); | |
306 | return d->m_pointsVisible; |
|
306 | return d->m_pointsVisible; | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
309 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
310 |
|
310 | |||
311 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : |
|
311 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : | |
312 | QAbstractSeriesPrivate(q), |
|
312 | QAbstractSeriesPrivate(q), | |
313 | m_upperSeries(upperSeries), |
|
313 | m_upperSeries(upperSeries), | |
314 | m_lowerSeries(lowerSeries), |
|
314 | m_lowerSeries(lowerSeries), | |
315 | m_pointsVisible(false) |
|
315 | m_pointsVisible(false) | |
316 | { |
|
316 | { | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) |
|
319 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) | |
320 | { |
|
320 | { | |
321 | Q_Q(QAreaSeries); |
|
321 | Q_Q(QAreaSeries); | |
322 |
|
322 | |||
323 | qreal minX(domain.minX()); |
|
323 | qreal minX(domain.minX()); | |
324 | qreal minY(domain.minY()); |
|
324 | qreal minY(domain.minY()); | |
325 | qreal maxX(domain.maxX()); |
|
325 | qreal maxX(domain.maxX()); | |
326 | qreal maxY(domain.maxY()); |
|
326 | qreal maxY(domain.maxY()); | |
327 |
|
327 | |||
328 | QLineSeries* upperSeries = q->upperSeries(); |
|
328 | QLineSeries* upperSeries = q->upperSeries(); | |
329 | QLineSeries* lowerSeries = q->lowerSeries(); |
|
329 | QLineSeries* lowerSeries = q->lowerSeries(); | |
330 |
|
330 | |||
331 | const QList<QPointF>& points = upperSeries->points(); |
|
331 | const QList<QPointF>& points = upperSeries->points(); | |
332 |
|
332 | |||
333 | for (int i = 0; i < points.count(); i++) |
|
333 | for (int i = 0; i < points.count(); i++) | |
334 | { |
|
334 | { | |
335 | qreal x = points[i].x(); |
|
335 | qreal x = points[i].x(); | |
336 | qreal y = points[i].y(); |
|
336 | qreal y = points[i].y(); | |
337 | minX = qMin(minX, x); |
|
337 | minX = qMin(minX, x); | |
338 | minY = qMin(minY, y); |
|
338 | minY = qMin(minY, y); | |
339 | maxX = qMax(maxX, x); |
|
339 | maxX = qMax(maxX, x); | |
340 | maxY = qMax(maxY, y); |
|
340 | maxY = qMax(maxY, y); | |
341 | } |
|
341 | } | |
342 | if(lowerSeries) { |
|
342 | if(lowerSeries) { | |
343 |
|
343 | |||
344 | const QList<QPointF>& points = lowerSeries->points(); |
|
344 | const QList<QPointF>& points = lowerSeries->points(); | |
345 |
|
345 | |||
346 | for (int i = 0; i < points.count(); i++) |
|
346 | for (int i = 0; i < points.count(); i++) | |
347 | { |
|
347 | { | |
348 | qreal x = points[i].x(); |
|
348 | qreal x = points[i].x(); | |
349 | qreal y = points[i].y(); |
|
349 | qreal y = points[i].y(); | |
350 | minX = qMin(minX, x); |
|
350 | minX = qMin(minX, x); | |
351 | minY = qMin(minY, y); |
|
351 | minY = qMin(minY, y); | |
352 | maxX = qMax(maxX, x); |
|
352 | maxX = qMax(maxX, x); | |
353 | maxY = qMax(maxY, y); |
|
353 | maxY = qMax(maxY, y); | |
354 | }} |
|
354 | }} | |
355 |
|
355 | |||
356 | domain.setRange(minX,maxX,minY,maxY); |
|
356 | domain.setRange(minX,maxX,minY,maxY); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | ChartElement* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
359 | ChartElement* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
360 | { |
|
360 | { | |
361 | Q_Q(QAreaSeries); |
|
361 | Q_Q(QAreaSeries); | |
362 |
|
362 | |||
363 | AreaChartItem* area = new AreaChartItem(q,presenter); |
|
363 | AreaChartItem* area = new AreaChartItem(q,presenter); | |
364 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
364 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
365 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
365 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
366 | if(q->lowerSeries()) { |
|
366 | if(q->lowerSeries()) { | |
367 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
367 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
368 | } |
|
368 | } | |
369 | } |
|
369 | } | |
370 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
370 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
371 | return area; |
|
371 | return area; | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) |
|
374 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) | |
375 | { |
|
375 | { | |
376 | Q_Q(QAreaSeries); |
|
376 | Q_Q(QAreaSeries); | |
377 | QList<LegendMarker*> list; |
|
377 | QList<LegendMarker*> list; | |
378 | return list << new AreaLegendMarker(q,legend); |
|
378 | return list << new AreaLegendMarker(q,legend); | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 |
|
381 | |||
382 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
382 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
383 | { |
|
383 | { | |
384 | Q_UNUSED(axis); |
|
384 | Q_UNUSED(axis); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
387 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
388 | { |
|
388 | { | |
389 | Q_UNUSED(orientation); |
|
389 | Q_UNUSED(orientation); | |
390 | return QAbstractAxis::AxisTypeValues; |
|
390 | return QAbstractAxis::AxisTypeValues; | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | #include "moc_qareaseries.cpp" |
|
393 | #include "moc_qareaseries.cpp" | |
394 | #include "moc_qareaseries_p.cpp" |
|
394 | #include "moc_qareaseries_p.cpp" | |
395 |
|
395 | |||
396 | QTCOMMERCIALCHART_END_NAMESPACE |
|
396 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||||
1 | #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well. |
|
1 | #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well. | |
2 |
|
2 | |||
3 | INCLUDEPATH += $$PWD \ |
|
3 | INCLUDEPATH += $$PWD \ | |
4 |
$$PWD/value |
|
4 | $$PWD/valueaxis \ | |
5 | $$PWD/categoriesaxis \ |
|
5 | $$PWD/categoriesaxis \ | |
6 | $$PWD/intervalsaxis \ |
|
6 | $$PWD/intervalsaxis \ | |
7 | $$PWD/datetimeaxis |
|
7 | $$PWD/datetimeaxis | |
8 |
|
8 | |||
9 | DEPENDPATH += $$PWD \ |
|
9 | DEPENDPATH += $$PWD \ | |
10 |
$$PWD/value |
|
10 | $$PWD/valueaxis \ | |
11 | $$PWD/categoriesaxis \ |
|
11 | $$PWD/categoriesaxis \ | |
12 | $$PWD/intervalsaxis \ |
|
12 | $$PWD/intervalsaxis \ | |
13 | $$PWD/datetimeaxis |
|
13 | $$PWD/datetimeaxis | |
14 |
|
14 | |||
15 | SOURCES += \ |
|
15 | SOURCES += \ | |
16 | $$PWD/chartaxis.cpp \ |
|
16 | $$PWD/chartaxis.cpp \ | |
17 | $$PWD/qabstractaxis.cpp \ |
|
17 | $$PWD/qabstractaxis.cpp \ | |
18 |
$$PWD/value |
|
18 | $$PWD/valueaxis/chartvalueaxisx.cpp \ | |
19 |
$$PWD/value |
|
19 | $$PWD/valueaxis/chartvalueaxisy.cpp \ | |
20 |
$$PWD/value |
|
20 | $$PWD/valueaxis/qvalueaxis.cpp \ | |
21 | $$PWD/categoriesaxis/chartcategoriesaxisx.cpp \ |
|
21 | $$PWD/categoriesaxis/chartcategoriesaxisx.cpp \ | |
22 | $$PWD/categoriesaxis/chartcategoriesaxisy.cpp \ |
|
22 | $$PWD/categoriesaxis/chartcategoriesaxisy.cpp \ | |
23 | $$PWD/categoriesaxis/qbarcategoriesaxis.cpp \ |
|
23 | $$PWD/categoriesaxis/qbarcategoriesaxis.cpp \ | |
24 | $$PWD/intervalsaxis/chartintervalsaxisx.cpp \ |
|
24 | $$PWD/intervalsaxis/chartintervalsaxisx.cpp \ | |
25 | $$PWD/intervalsaxis/chartintervalsaxisy.cpp \ |
|
25 | $$PWD/intervalsaxis/chartintervalsaxisy.cpp \ | |
26 | $$PWD/intervalsaxis/qintervalsaxis.cpp \ |
|
26 | $$PWD/intervalsaxis/qintervalsaxis.cpp \ | |
27 | $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \ |
|
27 | $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \ | |
28 | $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \ |
|
28 | $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \ | |
29 | $$PWD/datetimeaxis/qdatetimeaxis.cpp |
|
29 | $$PWD/datetimeaxis/qdatetimeaxis.cpp | |
30 |
|
30 | |||
31 | PRIVATE_HEADERS += \ |
|
31 | PRIVATE_HEADERS += \ | |
32 | $$PWD/chartaxis_p.h \ |
|
32 | $$PWD/chartaxis_p.h \ | |
33 | $$PWD/qabstractaxis_p.h \ |
|
33 | $$PWD/qabstractaxis_p.h \ | |
34 |
$$PWD/value |
|
34 | $$PWD/valueaxis/chartvalueaxisx_p.h \ | |
35 |
$$PWD/value |
|
35 | $$PWD/valueaxis/chartvalueaxisy_p.h \ | |
36 |
$$PWD/value |
|
36 | $$PWD/valueaxis/qvalueaxis_p.h \ | |
37 | $$PWD/categoriesaxis/chartcategoriesaxisx_p.h \ |
|
37 | $$PWD/categoriesaxis/chartcategoriesaxisx_p.h \ | |
38 | $$PWD/categoriesaxis/chartcategoriesaxisy_p.h \ |
|
38 | $$PWD/categoriesaxis/chartcategoriesaxisy_p.h \ | |
39 | $$PWD/categoriesaxis/qbarcategoriesaxis_p.h \ |
|
39 | $$PWD/categoriesaxis/qbarcategoriesaxis_p.h \ | |
40 | $$PWD/intervalsaxis/chartintervalsaxisx_p.h \ |
|
40 | $$PWD/intervalsaxis/chartintervalsaxisx_p.h \ | |
41 | $$PWD/intervalsaxis/chartintervalsaxisy_p.h \ |
|
41 | $$PWD/intervalsaxis/chartintervalsaxisy_p.h \ | |
42 | $$PWD/intervalsaxis/qintervalsaxis_p.h \ |
|
42 | $$PWD/intervalsaxis/qintervalsaxis_p.h \ | |
43 | $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \ |
|
43 | $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \ | |
44 | $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \ |
|
44 | $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \ | |
45 | $$PWD/datetimeaxis/qdatetimeaxis_p.h |
|
45 | $$PWD/datetimeaxis/qdatetimeaxis_p.h | |
46 |
|
46 | |||
47 | PUBLIC_HEADERS += \ |
|
47 | PUBLIC_HEADERS += \ | |
48 | $$PWD/qabstractaxis.h \ |
|
48 | $$PWD/qabstractaxis.h \ | |
49 |
$$PWD/value |
|
49 | $$PWD/valueaxis/qvalueaxis.h \ | |
50 | $$PWD/categoriesaxis/qbarcategoriesaxis.h \ |
|
50 | $$PWD/categoriesaxis/qbarcategoriesaxis.h \ | |
51 | $$PWD/intervalsaxis/qintervalsaxis.h \ |
|
51 | $$PWD/intervalsaxis/qintervalsaxis.h \ | |
52 | $$PWD/datetimeaxis/qdatetimeaxis.h |
|
52 | $$PWD/datetimeaxis/qdatetimeaxis.h |
@@ -1,65 +1,65 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCATEGORIESAXIS_H |
|
21 | #ifndef QCATEGORIESAXIS_H | |
22 | #define QCATEGORIESAXIS_H |
|
22 | #define QCATEGORIESAXIS_H | |
23 |
|
23 | |||
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
#include "qvalue |
|
25 | #include "qvalueaxis.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QIntervalsAxisPrivate; |
|
29 | class QIntervalsAxisPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QIntervalsAxis : public QValueAxis |
|
31 | class QTCOMMERCIALCHART_EXPORT QIntervalsAxis : public QValueAxis | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | explicit QIntervalsAxis(QObject *parent = 0); |
|
36 | explicit QIntervalsAxis(QObject *parent = 0); | |
37 | ~QIntervalsAxis(); |
|
37 | ~QIntervalsAxis(); | |
38 |
|
38 | |||
39 | protected: |
|
39 | protected: | |
40 | QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent = 0); |
|
40 | QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent = 0); | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | AxisType type() const; |
|
43 | AxisType type() const; | |
44 |
|
44 | |||
45 | void append(const QString& label, qreal intervalEnd); |
|
45 | void append(const QString& label, qreal intervalEnd); | |
46 | void remove(const QString& label); |
|
46 | void remove(const QString& label); | |
47 | void replaceLabel(const QString& oldLabel, const QString& newLabel); |
|
47 | void replaceLabel(const QString& oldLabel, const QString& newLabel); | |
48 |
|
48 | |||
49 | void setFisrtIntervalMinimum(qreal min); |
|
49 | void setFisrtIntervalMinimum(qreal min); | |
50 |
|
50 | |||
51 | qreal intervalMin(const QString& intervalLabel) const; |
|
51 | qreal intervalMin(const QString& intervalLabel) const; | |
52 | qreal intervalMax(const QString& intervalLabel) const; |
|
52 | qreal intervalMax(const QString& intervalLabel) const; | |
53 |
|
53 | |||
54 | QStringList intervalsLabels(); |
|
54 | QStringList intervalsLabels(); | |
55 | int count() const; |
|
55 | int count() const; | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | Q_DECLARE_PRIVATE(QIntervalsAxis) |
|
59 | Q_DECLARE_PRIVATE(QIntervalsAxis) | |
60 | Q_DISABLE_COPY(QIntervalsAxis) |
|
60 | Q_DISABLE_COPY(QIntervalsAxis) | |
61 | }; |
|
61 | }; | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
64 | |||
65 | #endif // QCATEGORIESAXIS_H |
|
65 | #endif // QCATEGORIESAXIS_H |
@@ -1,70 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QIntervalsAxis_P_H |
|
30 | #ifndef QIntervalsAxis_P_H | |
31 | #define QIntervalsAxis_P_H |
|
31 | #define QIntervalsAxis_P_H | |
32 |
|
32 | |||
33 | #include "qintervalsaxis.h" |
|
33 | #include "qintervalsaxis.h" | |
34 |
#include "qvalue |
|
34 | #include "qvalueaxis_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | typedef QPair<qreal, qreal> Range; |
|
38 | typedef QPair<qreal, qreal> Range; | |
39 |
|
39 | |||
40 | class QIntervalsAxisPrivate : public QValueAxisPrivate |
|
40 | class QIntervalsAxisPrivate : public QValueAxisPrivate | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | QIntervalsAxisPrivate(QIntervalsAxis *q); |
|
45 | QIntervalsAxisPrivate(QIntervalsAxis *q); | |
46 | ~QIntervalsAxisPrivate(); |
|
46 | ~QIntervalsAxisPrivate(); | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
50 | ChartAxis* createGraphics(ChartPresenter* presenter); | |
51 | int ticksCount() const; |
|
51 | int ticksCount() const; | |
52 |
|
52 | |||
53 | Q_SIGNALS: |
|
53 | Q_SIGNALS: | |
54 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); |
|
54 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); | |
55 |
|
55 | |||
56 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
57 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
57 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
58 |
|
58 | |||
59 | private: |
|
59 | private: | |
60 | QMap<QString , Range> m_intervalsMap; |
|
60 | QMap<QString , Range> m_intervalsMap; | |
61 | QStringList m_intervals; |
|
61 | QStringList m_intervals; | |
62 | qreal m_categoryMinimum; |
|
62 | qreal m_categoryMinimum; | |
63 |
|
63 | |||
64 | private: |
|
64 | private: | |
65 | Q_DECLARE_PUBLIC(QIntervalsAxis) |
|
65 | Q_DECLARE_PUBLIC(QIntervalsAxis) | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
69 | |||
70 | #endif // QCATEGORIESAXIS_P_H |
|
70 | #endif // QCATEGORIESAXIS_P_H |
@@ -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 |
#include "chartvalue |
|
21 | #include "chartvalueaxisx_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 |
#include "qvalue |
|
24 | #include "qvalueaxis.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 |
ChartValue |
|
33 | ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
34 | m_tickCount(0) |
|
34 | m_tickCount(0) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 |
ChartValue |
|
38 | ChartValueAxisX::~ChartValueAxisX() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
QVector<qreal> ChartValue |
|
42 | QVector<qreal> ChartValueAxisX::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | Q_ASSERT(m_tickCount>=2); |
|
44 | Q_ASSERT(m_tickCount>=2); | |
45 |
|
45 | |||
46 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
47 | points.resize(m_tickCount); |
|
47 | points.resize(m_tickCount); | |
48 |
|
48 | |||
49 | const qreal deltaX = m_rect.width()/(m_tickCount-1); |
|
49 | const qreal deltaX = m_rect.width()/(m_tickCount-1); | |
50 | for (int i = 0; i < m_tickCount; ++i) { |
|
50 | for (int i = 0; i < m_tickCount; ++i) { | |
51 | int x = i * deltaX + m_rect.left(); |
|
51 | int x = i * deltaX + m_rect.left(); | |
52 | points[i] = x; |
|
52 | points[i] = x; | |
53 | } |
|
53 | } | |
54 | return points; |
|
54 | return points; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
void ChartValue |
|
57 | void ChartValueAxisX::updateGeometry() | |
58 | { |
|
58 | { | |
59 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
59 | const QVector<qreal>& layout = ChartAxis::layout(); | |
60 |
|
60 | |||
61 | m_minWidth = 0; |
|
61 | m_minWidth = 0; | |
62 | m_minHeight = 0; |
|
62 | m_minHeight = 0; | |
63 |
|
63 | |||
64 | if(layout.isEmpty()) return; |
|
64 | if(layout.isEmpty()) return; | |
65 |
|
65 | |||
66 | QStringList ticksList; |
|
66 | QStringList ticksList; | |
67 |
|
67 | |||
68 | createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
68 | createNumberLabels(ticksList,m_min,m_max,layout.size()); | |
69 |
|
69 | |||
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
73 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
73 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
74 |
|
74 | |||
75 | Q_ASSERT(labels.size() == ticksList.size()); |
|
75 | Q_ASSERT(labels.size() == ticksList.size()); | |
76 | Q_ASSERT(layout.size() == ticksList.size()); |
|
76 | Q_ASSERT(layout.size() == ticksList.size()); | |
77 |
|
77 | |||
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
79 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
79 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
80 |
|
80 | |||
81 | qreal width = 0; |
|
81 | qreal width = 0; | |
82 | for (int i = 0; i < layout.size(); ++i) { |
|
82 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
84 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | labelItem->setText(ticksList.at(i)); |
|
86 | labelItem->setText(ticksList.at(i)); | |
87 | const QRectF& rect = labelItem->boundingRect(); |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
88 | QPointF center = rect.center(); |
|
88 | QPointF center = rect.center(); | |
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
91 |
|
91 | |||
92 | if(labelItem->pos().x()<=width){ |
|
92 | if(labelItem->pos().x()<=width){ | |
93 | labelItem->setVisible(false); |
|
93 | labelItem->setVisible(false); | |
94 | lineItem->setVisible(false); |
|
94 | lineItem->setVisible(false); | |
95 | }else{ |
|
95 | }else{ | |
96 | labelItem->setVisible(true); |
|
96 | labelItem->setVisible(true); | |
97 | lineItem->setVisible(true); |
|
97 | lineItem->setVisible(true); | |
98 | width=rect.width()+labelItem->pos().x(); |
|
98 | width=rect.width()+labelItem->pos().x(); | |
99 | } |
|
99 | } | |
100 | m_minWidth+=rect.width(); |
|
100 | m_minWidth+=rect.width(); | |
101 | m_minHeight=qMax(rect.height(),m_minHeight); |
|
101 | m_minHeight=qMax(rect.height(),m_minHeight); | |
102 |
|
102 | |||
103 | if ((i+1)%2 && i>1) { |
|
103 | if ((i+1)%2 && i>1) { | |
104 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
104 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
105 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
105 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
106 | } |
|
106 | } | |
107 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
107 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
108 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
108 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
109 | } |
|
109 | } | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 |
void ChartValue |
|
112 | void ChartValueAxisX::handleAxisUpdated() | |
113 | { |
|
113 | { | |
114 | //TODO:: fix this |
|
114 | //TODO:: fix this | |
115 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); |
|
115 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); | |
116 | m_tickCount = axis->ticksCount(); |
|
116 | m_tickCount = axis->ticksCount(); | |
117 | ChartAxis::handleAxisUpdated(); |
|
117 | ChartAxis::handleAxisUpdated(); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,60 | |||||
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 CHARTVALUESAXISX_H |
|
30 | #ifndef CHARTVALUESAXISX_H | |
31 | #define CHARTVALUESAXISX_H |
|
31 | #define CHARTVALUESAXISX_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 |
class ChartValue |
|
40 | class ChartValueAxisX : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
ChartValue |
|
43 | ChartValueAxisX(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 |
~ChartValue |
|
44 | ~ChartValueAxisX(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return X_AXIS;} |
|
46 | AxisType axisType() const { return X_AXIS;} | |
47 |
|
47 | |||
48 | protected: |
|
48 | protected: | |
49 | void handleAxisUpdated(); |
|
49 | void handleAxisUpdated(); | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
52 |
|
52 | |||
53 | private: |
|
53 | private: | |
54 | int m_tickCount; |
|
54 | int m_tickCount; | |
55 |
|
55 | |||
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 |
|
59 | |||
60 | #endif /* CHARTVALUESAXISX_H */ |
|
60 | #endif /* CHARTVALUESAXISX_H */ |
@@ -1,126 +1,126 | |||||
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 "chartvalue |
|
21 | #include "chartvalueaxisy_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 |
#include "qvalue |
|
24 | #include "qvalueaxis.h" | |
25 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
26 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 |
ChartValue |
|
33 | ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), | |
34 | m_tickCount(0) |
|
34 | m_tickCount(0) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 |
ChartValue |
|
38 | ChartValueAxisY::~ChartValueAxisY() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
QVector<qreal> ChartValue |
|
42 | QVector<qreal> ChartValueAxisY::calculateLayout() const | |
43 | { |
|
43 | { | |
44 | Q_ASSERT(m_tickCount>=2); |
|
44 | Q_ASSERT(m_tickCount>=2); | |
45 |
|
45 | |||
46 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
47 | points.resize(m_tickCount); |
|
47 | points.resize(m_tickCount); | |
48 |
|
48 | |||
49 | const qreal deltaY = m_rect.height()/(m_tickCount-1); |
|
49 | const qreal deltaY = m_rect.height()/(m_tickCount-1); | |
50 | for (int i = 0; i < m_tickCount; ++i) { |
|
50 | for (int i = 0; i < m_tickCount; ++i) { | |
51 | int y = i * -deltaY + m_rect.bottom(); |
|
51 | int y = i * -deltaY + m_rect.bottom(); | |
52 | points[i] = y; |
|
52 | points[i] = y; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | return points; |
|
55 | return points; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 |
void ChartValue |
|
58 | void ChartValueAxisY::updateGeometry() | |
59 | { |
|
59 | { | |
60 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
60 | const QVector<qreal> &layout = ChartAxis::layout(); | |
61 | m_minWidth = 0; |
|
61 | m_minWidth = 0; | |
62 | m_minHeight = 0; |
|
62 | m_minHeight = 0; | |
63 |
|
63 | |||
64 | if(layout.isEmpty()) return; |
|
64 | if(layout.isEmpty()) return; | |
65 |
|
65 | |||
66 | QStringList ticksList; |
|
66 | QStringList ticksList; | |
67 |
|
67 | |||
68 | createNumberLabels(ticksList,m_min,m_max,layout.size()); |
|
68 | createNumberLabels(ticksList,m_min,m_max,layout.size()); | |
69 |
|
69 | |||
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
73 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
73 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
74 |
|
74 | |||
75 | Q_ASSERT(labels.size() == ticksList.size()); |
|
75 | Q_ASSERT(labels.size() == ticksList.size()); | |
76 | Q_ASSERT(layout.size() == ticksList.size()); |
|
76 | Q_ASSERT(layout.size() == ticksList.size()); | |
77 |
|
77 | |||
78 | qreal height = 2*m_rect.bottom(); |
|
78 | qreal height = 2*m_rect.bottom(); | |
79 |
|
79 | |||
80 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
80 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
81 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
81 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
82 |
|
82 | |||
83 | for (int i = 0; i < layout.size(); ++i) { |
|
83 | for (int i = 0; i < layout.size(); ++i) { | |
84 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
84 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
85 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
85 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
86 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
86 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
87 |
|
87 | |||
88 | labelItem->setText(ticksList.at(i)); |
|
88 | labelItem->setText(ticksList.at(i)); | |
89 | const QRectF& rect = labelItem->boundingRect(); |
|
89 | const QRectF& rect = labelItem->boundingRect(); | |
90 |
|
90 | |||
91 | QPointF center = rect.center(); |
|
91 | QPointF center = rect.center(); | |
92 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
92 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
93 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
93 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
94 |
|
94 | |||
95 | if(labelItem->pos().y()+rect.height()>height) { |
|
95 | if(labelItem->pos().y()+rect.height()>height) { | |
96 | labelItem->setVisible(false); |
|
96 | labelItem->setVisible(false); | |
97 | lineItem->setVisible(false); |
|
97 | lineItem->setVisible(false); | |
98 | } |
|
98 | } | |
99 | else { |
|
99 | else { | |
100 | labelItem->setVisible(true); |
|
100 | labelItem->setVisible(true); | |
101 | lineItem->setVisible(true); |
|
101 | lineItem->setVisible(true); | |
102 | height=labelItem->pos().y(); |
|
102 | height=labelItem->pos().y(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
105 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); | |
106 | m_minHeight+=rect.height(); |
|
106 | m_minHeight+=rect.height(); | |
107 |
|
107 | |||
108 | if ((i+1)%2 && i>1) { |
|
108 | if ((i+1)%2 && i>1) { | |
109 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
109 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
110 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
110 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
111 | } |
|
111 | } | |
112 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
112 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
113 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
113 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 |
void ChartValue |
|
117 | void ChartValueAxisY::handleAxisUpdated() | |
118 | { |
|
118 | { | |
119 | //TODO:: fix this |
|
119 | //TODO:: fix this | |
120 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); |
|
120 | QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis); | |
121 | m_tickCount = axis->ticksCount(); |
|
121 | m_tickCount = axis->ticksCount(); | |
122 | ChartAxis::handleAxisUpdated(); |
|
122 | ChartAxis::handleAxisUpdated(); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 |
|
125 | |||
126 | QTCOMMERCIALCHART_END_NAMESPACE |
|
126 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
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 CHARTVALUESAXISY_H |
|
30 | #ifndef CHARTVALUESAXISY_H | |
31 | #define CHARTVALUESAXISY_H |
|
31 | #define CHARTVALUESAXISY_H | |
32 |
|
32 | |||
33 | #include "chartaxis_p.h" |
|
33 | #include "chartaxis_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAbstractAxis; |
|
37 | class QAbstractAxis; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 |
|
39 | |||
40 |
class ChartValue |
|
40 | class ChartValueAxisY : public ChartAxis | |
41 | { |
|
41 | { | |
42 | public: |
|
42 | public: | |
43 |
ChartValue |
|
43 | ChartValueAxisY(QAbstractAxis *axis, ChartPresenter *presenter); | |
44 |
~ChartValue |
|
44 | ~ChartValueAxisY(); | |
45 |
|
45 | |||
46 | AxisType axisType() const { return Y_AXIS;} |
|
46 | AxisType axisType() const { return Y_AXIS;} | |
47 |
|
47 | |||
48 | protected: |
|
48 | protected: | |
49 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
50 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
51 | void handleAxisUpdated(); |
|
51 | void handleAxisUpdated(); | |
52 | private: |
|
52 | private: | |
53 | int m_tickCount; |
|
53 | int m_tickCount; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif /* CHARTVALUESAXISY_H */ |
|
58 | #endif /* CHARTVALUESAXISY_H */ |
@@ -1,384 +1,384 | |||||
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 "qvalue |
|
21 | #include "qvalueaxis.h" | |
22 |
#include "qvalue |
|
22 | #include "qvalueaxis_p.h" | |
23 |
#include "chartvalue |
|
23 | #include "chartvalueaxisx_p.h" | |
24 |
#include "chartvalue |
|
24 | #include "chartvalueaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 | /*! |
|
31 | /*! | |
32 | \class QValueAxis |
|
32 | \class QValueAxis | |
33 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
33 | \brief The QValueAxis class is used for manipulating chart's axis. | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
37 | Values of axis are drawn to position of ticks |
|
37 | Values of axis are drawn to position of ticks | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \qmlclass ValuesAxis QValueAxis |
|
41 | \qmlclass ValuesAxis QValueAxis | |
42 | \brief The ValuesAxis element is used for manipulating chart's axes |
|
42 | \brief The ValuesAxis element is used for manipulating chart's axes | |
43 |
|
43 | |||
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Values of axis are drawn to position of ticks |
|
45 | Values of axis are drawn to position of ticks | |
46 |
|
46 | |||
47 | To access Axes you can use ChartView API. For example: |
|
47 | To access Axes you can use ChartView API. For example: | |
48 | \code |
|
48 | \code | |
49 | ChartView { |
|
49 | ChartView { | |
50 | ValuesAxis { |
|
50 | ValuesAxis { | |
51 | id: xAxis |
|
51 | id: xAxis | |
52 | min: 0 |
|
52 | min: 0 | |
53 | max: 10 |
|
53 | max: 10 | |
54 | } |
|
54 | } | |
55 | // Add a few series... |
|
55 | // Add a few series... | |
56 | } |
|
56 | } | |
57 | \endcode |
|
57 | \endcode | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QValueAxis::min |
|
61 | \property QValueAxis::min | |
62 | Defines the minimum value on the axis. |
|
62 | Defines the minimum value on the axis. | |
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty real ValuesAxis::min |
|
66 | \qmlproperty real ValuesAxis::min | |
67 | Defines the minimum value on the axis. |
|
67 | Defines the minimum value on the axis. | |
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QValueAxis::max |
|
72 | \property QValueAxis::max | |
73 | Defines the maximum value on the axis. |
|
73 | Defines the maximum value on the axis. | |
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty real ValuesAxis::max |
|
77 | \qmlproperty real ValuesAxis::max | |
78 | Defines the maximum value on the axis. |
|
78 | Defines the maximum value on the axis. | |
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \fn void QValueAxis::minChanged(qreal min) |
|
83 | \fn void QValueAxis::minChanged(qreal min) | |
84 | Axis emits signal when \a min of axis has changed. |
|
84 | Axis emits signal when \a min of axis has changed. | |
85 | */ |
|
85 | */ | |
86 | /*! |
|
86 | /*! | |
87 | \qmlsignal ValuesAxis::onMinChanged(real min) |
|
87 | \qmlsignal ValuesAxis::onMinChanged(real min) | |
88 | Axis emits signal when \a min of axis has changed. |
|
88 | Axis emits signal when \a min of axis has changed. | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \fn void QValueAxis::maxChanged(qreal max) |
|
92 | \fn void QValueAxis::maxChanged(qreal max) | |
93 | Axis emits signal when \a max of axis has changed. |
|
93 | Axis emits signal when \a max of axis has changed. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal ValuesAxis::onMaxChanged(real max) |
|
96 | \qmlsignal ValuesAxis::onMaxChanged(real max) | |
97 | Axis emits signal when \a max of axis has changed. |
|
97 | Axis emits signal when \a max of axis has changed. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
101 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) | |
102 | Axis emits signal when \a min or \a max of axis has changed. |
|
102 | Axis emits signal when \a min or \a max of axis has changed. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QValueAxis::ticksCount |
|
106 | \property QValueAxis::ticksCount | |
107 | The number of tick marks for the axis. |
|
107 | The number of tick marks for the axis. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty int ValuesAxis::ticksCount |
|
111 | \qmlproperty int ValuesAxis::ticksCount | |
112 | The number of tick marks for the axis. |
|
112 | The number of tick marks for the axis. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \property QValueAxis::niceNumbersEnabled |
|
116 | \property QValueAxis::niceNumbersEnabled | |
117 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
117 | Whether the nice numbers algorithm is enabled or not for the axis. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \qmlproperty bool ValuesAxis::niceNumbersEnabled |
|
121 | \qmlproperty bool ValuesAxis::niceNumbersEnabled | |
122 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
122 | Whether the nice numbers algorithm is enabled or not for the axis. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | Constructs an axis object which is a child of \a parent. |
|
126 | Constructs an axis object which is a child of \a parent. | |
127 | */ |
|
127 | */ | |
128 | QValueAxis::QValueAxis(QObject *parent) : |
|
128 | QValueAxis::QValueAxis(QObject *parent) : | |
129 | QAbstractAxis(*new QValueAxisPrivate(this),parent) |
|
129 | QAbstractAxis(*new QValueAxisPrivate(this),parent) | |
130 | { |
|
130 | { | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \internal |
|
135 | \internal | |
136 | */ |
|
136 | */ | |
137 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
137 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
138 | { |
|
138 | { | |
139 |
|
139 | |||
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Destroys the object |
|
143 | Destroys the object | |
144 | */ |
|
144 | */ | |
145 | QValueAxis::~QValueAxis() |
|
145 | QValueAxis::~QValueAxis() | |
146 | { |
|
146 | { | |
147 | Q_D(QValueAxis); |
|
147 | Q_D(QValueAxis); | |
148 | if(d->m_dataset) { |
|
148 | if(d->m_dataset) { | |
149 | d->m_dataset->removeAxis(this); |
|
149 | d->m_dataset->removeAxis(this); | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void QValueAxis::setMin(qreal min) |
|
153 | void QValueAxis::setMin(qreal min) | |
154 | { |
|
154 | { | |
155 | Q_D(QValueAxis); |
|
155 | Q_D(QValueAxis); | |
156 | setRange(min, qMax(d->m_max, min)); |
|
156 | setRange(min, qMax(d->m_max, min)); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | qreal QValueAxis::min() const |
|
159 | qreal QValueAxis::min() const | |
160 | { |
|
160 | { | |
161 | Q_D(const QValueAxis); |
|
161 | Q_D(const QValueAxis); | |
162 | return d->m_min; |
|
162 | return d->m_min; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void QValueAxis::setMax(qreal max) |
|
165 | void QValueAxis::setMax(qreal max) | |
166 | { |
|
166 | { | |
167 | Q_D(QValueAxis); |
|
167 | Q_D(QValueAxis); | |
168 | setRange(qMin(d->m_min, max), max); |
|
168 | setRange(qMin(d->m_min, max), max); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | qreal QValueAxis::max() const |
|
171 | qreal QValueAxis::max() const | |
172 | { |
|
172 | { | |
173 | Q_D(const QValueAxis); |
|
173 | Q_D(const QValueAxis); | |
174 | return d->m_max; |
|
174 | return d->m_max; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Sets range from \a min to \a max on the axis. |
|
178 | Sets range from \a min to \a max on the axis. | |
179 | If min is greater than max then this function returns without making any changes. |
|
179 | If min is greater than max then this function returns without making any changes. | |
180 | */ |
|
180 | */ | |
181 | void QValueAxis::setRange(qreal min, qreal max) |
|
181 | void QValueAxis::setRange(qreal min, qreal max) | |
182 | { |
|
182 | { | |
183 | Q_D(QValueAxis); |
|
183 | Q_D(QValueAxis); | |
184 | bool changed = false; |
|
184 | bool changed = false; | |
185 |
|
185 | |||
186 | if (min > max) return; |
|
186 | if (min > max) return; | |
187 |
|
187 | |||
188 | if(d->m_niceNumbers) { |
|
188 | if(d->m_niceNumbers) { | |
189 | int ticks = d->m_tickCount; |
|
189 | int ticks = d->m_tickCount; | |
190 | d->looseNiceNumbers(min, max, ticks); |
|
190 | d->looseNiceNumbers(min, max, ticks); | |
191 | if(ticks!=d->m_tickCount) setTicksCount(ticks); |
|
191 | if(ticks!=d->m_tickCount) setTicksCount(ticks); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
194 | if (!qFuzzyIsNull(d->m_min - min)) { | |
195 | d->m_min = min; |
|
195 | d->m_min = min; | |
196 | changed = true; |
|
196 | changed = true; | |
197 | emit minChanged(min); |
|
197 | emit minChanged(min); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
200 | if (!qFuzzyIsNull(d->m_max - max)) { | |
201 | d->m_max = max; |
|
201 | d->m_max = max; | |
202 | changed = true; |
|
202 | changed = true; | |
203 | emit maxChanged(max); |
|
203 | emit maxChanged(max); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | if (changed) { |
|
206 | if (changed) { | |
207 | emit rangeChanged(min,max); |
|
207 | emit rangeChanged(min,max); | |
208 | d->emitUpdated(); |
|
208 | d->emitUpdated(); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Sets \a count for ticks on the axis. |
|
213 | Sets \a count for ticks on the axis. | |
214 | */ |
|
214 | */ | |
215 | void QValueAxis::setTicksCount(int count) |
|
215 | void QValueAxis::setTicksCount(int count) | |
216 | { |
|
216 | { | |
217 | Q_D(QValueAxis); |
|
217 | Q_D(QValueAxis); | |
218 | if (d->m_tickCount != count && count >=2) { |
|
218 | if (d->m_tickCount != count && count >=2) { | |
219 | d->m_tickCount = count; |
|
219 | d->m_tickCount = count; | |
220 | d->emitUpdated(); |
|
220 | d->emitUpdated(); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | \fn int QValueAxis::ticksCount() const |
|
225 | \fn int QValueAxis::ticksCount() const | |
226 | Return number of ticks on the axis |
|
226 | Return number of ticks on the axis | |
227 | */ |
|
227 | */ | |
228 | int QValueAxis::ticksCount() const |
|
228 | int QValueAxis::ticksCount() const | |
229 | { |
|
229 | { | |
230 | Q_D(const QValueAxis); |
|
230 | Q_D(const QValueAxis); | |
231 | return d->m_tickCount; |
|
231 | return d->m_tickCount; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
234 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
235 | { |
|
235 | { | |
236 | Q_D(QValueAxis); |
|
236 | Q_D(QValueAxis); | |
237 | if (d->m_niceNumbers != enable){ |
|
237 | if (d->m_niceNumbers != enable){ | |
238 | d->m_niceNumbers = enable; |
|
238 | d->m_niceNumbers = enable; | |
239 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { |
|
239 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { | |
240 | setRange(d->m_min,d->m_max); |
|
240 | setRange(d->m_min,d->m_max); | |
241 | } |
|
241 | } | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | bool QValueAxis::niceNumbersEnabled() const |
|
245 | bool QValueAxis::niceNumbersEnabled() const | |
246 | { |
|
246 | { | |
247 | Q_D(const QValueAxis); |
|
247 | Q_D(const QValueAxis); | |
248 | return d->m_niceNumbers; |
|
248 | return d->m_niceNumbers; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | Returns the type of the axis |
|
252 | Returns the type of the axis | |
253 | */ |
|
253 | */ | |
254 | QAbstractAxis::AxisType QValueAxis::type() const |
|
254 | QAbstractAxis::AxisType QValueAxis::type() const | |
255 | { |
|
255 | { | |
256 | return AxisTypeValues; |
|
256 | return AxisTypeValues; | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
259 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
260 |
|
260 | |||
261 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): |
|
261 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): | |
262 | QAbstractAxisPrivate(q), |
|
262 | QAbstractAxisPrivate(q), | |
263 | m_min(0), |
|
263 | m_min(0), | |
264 | m_max(0), |
|
264 | m_max(0), | |
265 | m_tickCount(5), |
|
265 | m_tickCount(5), | |
266 | m_niceNumbers(false) |
|
266 | m_niceNumbers(false) | |
267 | { |
|
267 | { | |
268 |
|
268 | |||
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | QValueAxisPrivate::~QValueAxisPrivate() |
|
271 | QValueAxisPrivate::~QValueAxisPrivate() | |
272 | { |
|
272 | { | |
273 |
|
273 | |||
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void QValueAxisPrivate::handleDomainUpdated() |
|
276 | void QValueAxisPrivate::handleDomainUpdated() | |
277 | { |
|
277 | { | |
278 | Q_Q(QValueAxis); |
|
278 | Q_Q(QValueAxis); | |
279 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
279 | Domain* domain = qobject_cast<Domain*>(sender()); | |
280 | Q_ASSERT(domain); |
|
280 | Q_ASSERT(domain); | |
281 |
|
281 | |||
282 | if(orientation()==Qt::Horizontal){ |
|
282 | if(orientation()==Qt::Horizontal){ | |
283 | q->setRange(domain->minX(),domain->maxX()); |
|
283 | q->setRange(domain->minX(),domain->maxX()); | |
284 | }else if(orientation()==Qt::Vertical){ |
|
284 | }else if(orientation()==Qt::Vertical){ | |
285 | q->setRange(domain->minY(),domain->maxY()); |
|
285 | q->setRange(domain->minY(),domain->maxY()); | |
286 | } |
|
286 | } | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 |
|
289 | |||
290 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
290 | void QValueAxisPrivate::setMin(const QVariant &min) | |
291 | { |
|
291 | { | |
292 | Q_Q(QValueAxis); |
|
292 | Q_Q(QValueAxis); | |
293 | bool ok; |
|
293 | bool ok; | |
294 | qreal value = min.toReal(&ok); |
|
294 | qreal value = min.toReal(&ok); | |
295 | if(ok) q->setMin(value); |
|
295 | if(ok) q->setMin(value); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
298 | void QValueAxisPrivate::setMax(const QVariant &max) | |
299 | { |
|
299 | { | |
300 |
|
300 | |||
301 | Q_Q(QValueAxis); |
|
301 | Q_Q(QValueAxis); | |
302 | bool ok; |
|
302 | bool ok; | |
303 | qreal value = max.toReal(&ok); |
|
303 | qreal value = max.toReal(&ok); | |
304 | if(ok) q->setMax(value); |
|
304 | if(ok) q->setMax(value); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
307 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
308 | { |
|
308 | { | |
309 | Q_Q(QValueAxis); |
|
309 | Q_Q(QValueAxis); | |
310 | bool ok1; |
|
310 | bool ok1; | |
311 | bool ok2; |
|
311 | bool ok2; | |
312 | qreal value1 = min.toReal(&ok1); |
|
312 | qreal value1 = min.toReal(&ok1); | |
313 | qreal value2 = max.toReal(&ok2); |
|
313 | qreal value2 = max.toReal(&ok2); | |
314 | if(ok1&&ok2) q->setRange(value1,value2); |
|
314 | if(ok1&&ok2) q->setRange(value1,value2); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
317 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) | |
318 | { |
|
318 | { | |
319 | Q_Q(QValueAxis); |
|
319 | Q_Q(QValueAxis); | |
320 | if(m_orientation == Qt::Vertical){ |
|
320 | if(m_orientation == Qt::Vertical){ | |
321 |
return new ChartValue |
|
321 | return new ChartValueAxisY(q,presenter); | |
322 | }else{ |
|
322 | }else{ | |
323 |
return new ChartValue |
|
323 | return new ChartValueAxisX(q,presenter); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | void QValueAxisPrivate::intializeDomain(Domain* domain) |
|
328 | void QValueAxisPrivate::intializeDomain(Domain* domain) | |
329 | { |
|
329 | { | |
330 | Q_Q(QValueAxis); |
|
330 | Q_Q(QValueAxis); | |
331 | if(qFuzzyCompare(m_max,m_min)) { |
|
331 | if(qFuzzyCompare(m_max,m_min)) { | |
332 | if(m_orientation==Qt::Vertical){ |
|
332 | if(m_orientation==Qt::Vertical){ | |
333 | q->setRange(domain->minY(),domain->maxY()); |
|
333 | q->setRange(domain->minY(),domain->maxY()); | |
334 | }else{ |
|
334 | }else{ | |
335 | q->setRange(domain->minX(), domain->maxX()); |
|
335 | q->setRange(domain->minX(), domain->maxX()); | |
336 | } |
|
336 | } | |
337 | } else { |
|
337 | } else { | |
338 | if(m_orientation==Qt::Vertical){ |
|
338 | if(m_orientation==Qt::Vertical){ | |
339 | domain->setRangeY(m_min, m_max); |
|
339 | domain->setRangeY(m_min, m_max); | |
340 | }else{ |
|
340 | }else{ | |
341 | domain->setRangeX(m_min, m_max); |
|
341 | domain->setRangeX(m_min, m_max); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
346 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |
347 |
|
347 | |||
348 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
348 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const | |
349 | { |
|
349 | { | |
350 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
350 | qreal range = niceNumber(max-min,true); //range with ceiling | |
351 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
351 | qreal step = niceNumber(range/(ticksCount-1),false); | |
352 | min = qFloor(min/step); |
|
352 | min = qFloor(min/step); | |
353 | max = qCeil(max/step); |
|
353 | max = qCeil(max/step); | |
354 | ticksCount = int(max-min) +1; |
|
354 | ticksCount = int(max-min) +1; | |
355 | min*=step; |
|
355 | min*=step; | |
356 | max*=step; |
|
356 | max*=step; | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
359 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |
360 |
|
360 | |||
361 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const |
|
361 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const | |
362 | { |
|
362 | { | |
363 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
363 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |
364 | qreal q = x/z;//q<10 && q>=1; |
|
364 | qreal q = x/z;//q<10 && q>=1; | |
365 |
|
365 | |||
366 | if(ceiling) { |
|
366 | if(ceiling) { | |
367 | if(q <= 1.0) q=1; |
|
367 | if(q <= 1.0) q=1; | |
368 | else if(q <= 2.0) q=2; |
|
368 | else if(q <= 2.0) q=2; | |
369 | else if(q <= 5.0) q=5; |
|
369 | else if(q <= 5.0) q=5; | |
370 | else q=10; |
|
370 | else q=10; | |
371 | } |
|
371 | } | |
372 | else { |
|
372 | else { | |
373 | if(q < 1.5) q=1; |
|
373 | if(q < 1.5) q=1; | |
374 | else if(q < 3.0) q=2; |
|
374 | else if(q < 3.0) q=2; | |
375 | else if(q < 7.0) q=5; |
|
375 | else if(q < 7.0) q=5; | |
376 | else q=10; |
|
376 | else q=10; | |
377 | } |
|
377 | } | |
378 | return q*z; |
|
378 | return q*z; | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 |
#include "moc_qvalue |
|
381 | #include "moc_qvalueaxis.cpp" | |
382 |
#include "moc_qvalue |
|
382 | #include "moc_qvalueaxis_p.cpp" | |
383 |
|
383 | |||
384 | QTCOMMERCIALCHART_END_NAMESPACE |
|
384 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from src/axis/valuesaxis/qvaluesaxis.h to src/axis/valueaxis/qvalueaxis.h |
|
NO CONTENT: file renamed from src/axis/valuesaxis/qvaluesaxis.h to src/axis/valueaxis/qvalueaxis.h |
@@ -1,72 +1,72 | |||||
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 QVALUESAXIS_P_H |
|
30 | #ifndef QVALUESAXIS_P_H | |
31 | #define QVALUESAXIS_P_H |
|
31 | #define QVALUESAXIS_P_H | |
32 |
|
32 | |||
33 |
#include "qvalue |
|
33 | #include "qvalueaxis.h" | |
34 | #include "qabstractaxis_p.h" |
|
34 | #include "qabstractaxis_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class QValueAxisPrivate : public QAbstractAxisPrivate |
|
38 | class QValueAxisPrivate : public QAbstractAxisPrivate | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | QValueAxisPrivate(QValueAxis *q); |
|
42 | QValueAxisPrivate(QValueAxis *q); | |
43 | ~QValueAxisPrivate(); |
|
43 | ~QValueAxisPrivate(); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
46 | ChartAxis* createGraphics(ChartPresenter* presenter); | |
47 | void intializeDomain(Domain* domain); |
|
47 | void intializeDomain(Domain* domain); | |
48 | void handleDomainUpdated(); |
|
48 | void handleDomainUpdated(); | |
49 | qreal min(){ return m_min; }; |
|
49 | qreal min(){ return m_min; }; | |
50 | qreal max(){ return m_max; }; |
|
50 | qreal max(){ return m_max; }; | |
51 | int count() const { return m_tickCount;} |
|
51 | int count() const { return m_tickCount;} | |
52 |
|
52 | |||
53 | protected: |
|
53 | protected: | |
54 | void setMin(const QVariant &min); |
|
54 | void setMin(const QVariant &min); | |
55 | void setMax(const QVariant &max); |
|
55 | void setMax(const QVariant &max); | |
56 | void setRange(const QVariant &min, const QVariant &max); |
|
56 | void setRange(const QVariant &min, const QVariant &max); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const; |
|
59 | void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const; | |
60 | qreal niceNumber(qreal x,bool ceiling) const; |
|
60 | qreal niceNumber(qreal x,bool ceiling) const; | |
61 |
|
61 | |||
62 | private: |
|
62 | private: | |
63 | qreal m_min; |
|
63 | qreal m_min; | |
64 | qreal m_max; |
|
64 | qreal m_max; | |
65 | int m_tickCount; |
|
65 | int m_tickCount; | |
66 | bool m_niceNumbers; |
|
66 | bool m_niceNumbers; | |
67 | Q_DECLARE_PUBLIC(QValueAxis) |
|
67 | Q_DECLARE_PUBLIC(QValueAxis) | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
71 | |||
72 | #endif // QVALUESAXIS_P_H |
|
72 | #endif // QVALUESAXIS_P_H |
@@ -1,828 +1,828 | |||||
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 "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 |
#include "qvalue |
|
29 | #include "qvalueaxis.h" | |
30 | #include "qbarcategoriesaxis.h" |
|
30 | #include "qbarcategoriesaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractBarSeries |
|
35 | \class QAbstractBarSeries | |
36 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
42 | shows the x-values. |
|
42 | shows the x-values. | |
43 |
|
43 | |||
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
45 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
46 |
|
46 | |||
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
50 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
51 | \inherits QAbstractSeries |
|
51 | \inherits QAbstractSeries | |
52 |
|
52 | |||
53 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
55 |
|
55 | |||
56 | \beginfloatleft |
|
56 | \beginfloatleft | |
57 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
58 | \endfloat |
|
58 | \endfloat | |
59 | \clearfloat |
|
59 | \clearfloat | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QAbstractBarSeries::barWidth |
|
63 | \property QAbstractBarSeries::barWidth | |
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
68 | \sa QBarSeries |
|
68 | \sa QBarSeries | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty real AbstractBarSeries::barWidth |
|
71 | \qmlproperty real AbstractBarSeries::barWidth | |
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QAbstractBarSeries::count |
|
79 | \property QAbstractBarSeries::count | |
80 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty int AbstractBarSeries::count |
|
83 | \qmlproperty int AbstractBarSeries::count | |
84 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QAbstractBarSeries::labelsVisible |
|
88 | \property QAbstractBarSeries::labelsVisible | |
89 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
92 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
93 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
99 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
100 | */ |
|
100 | */ | |
101 | /*! |
|
101 | /*! | |
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
104 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
109 |
|
109 | |||
110 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
116 |
|
116 | |||
117 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QAbstractBarSeries::countChanged() |
|
123 | \fn void QAbstractBarSeries::countChanged() | |
124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
125 | */ |
|
125 | */ | |
126 | /*! |
|
126 | /*! | |
127 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
127 | \qmlsignal AbstractBarSeries::onCountChanged() | |
128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
133 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
134 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
139 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
140 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
141 | */ |
|
141 | */ | |
142 | /*! |
|
142 | /*! | |
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
144 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
149 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
150 | \sa remove() |
|
150 | \sa remove() | |
151 | */ |
|
151 | */ | |
152 | /*! |
|
152 | /*! | |
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
154 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
159 | Returns bar set at \a index. Returns null if the index is not valid. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
165 | For example: |
|
165 | For example: | |
166 | \code |
|
166 | \code | |
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
169 | \endcode |
|
169 | \endcode | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
176 | appended. |
|
176 | appended. | |
177 | \sa AbstractBarSeries::append() |
|
177 | \sa AbstractBarSeries::append() | |
178 | */ |
|
178 | */ | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
182 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
182 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \qmlmethod AbstractBarSeries::clear() |
|
186 | \qmlmethod AbstractBarSeries::clear() | |
187 | Removes all barsets from the series. |
|
187 | Removes all barsets from the series. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | This is depreciated constructor. |
|
191 | This is depreciated constructor. | |
192 | */ |
|
192 | */ | |
193 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
193 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
194 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) |
|
194 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) | |
195 | { |
|
195 | { | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | Destructs abstractbarseries and owned barsets. |
|
199 | Destructs abstractbarseries and owned barsets. | |
200 | */ |
|
200 | */ | |
201 | QAbstractBarSeries::~QAbstractBarSeries() |
|
201 | QAbstractBarSeries::~QAbstractBarSeries() | |
202 | { |
|
202 | { | |
203 |
|
203 | |||
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | \internal |
|
207 | \internal | |
208 | */ |
|
208 | */ | |
209 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
209 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
210 | QAbstractSeries(d,parent) |
|
210 | QAbstractSeries(d,parent) | |
211 | { |
|
211 | { | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
215 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
216 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
216 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
217 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
217 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
218 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
218 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
219 | */ |
|
219 | */ | |
220 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
220 | void QAbstractBarSeries::setBarWidth(qreal width) | |
221 | { |
|
221 | { | |
222 | Q_D(QAbstractBarSeries); |
|
222 | Q_D(QAbstractBarSeries); | |
223 | d->setBarWidth(width); |
|
223 | d->setBarWidth(width); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | /*! |
|
226 | /*! | |
227 | Returns the width of the bars of the series. |
|
227 | Returns the width of the bars of the series. | |
228 | \sa setBarWidth() |
|
228 | \sa setBarWidth() | |
229 | */ |
|
229 | */ | |
230 | qreal QAbstractBarSeries::barWidth() const |
|
230 | qreal QAbstractBarSeries::barWidth() const | |
231 | { |
|
231 | { | |
232 | Q_D(const QAbstractBarSeries); |
|
232 | Q_D(const QAbstractBarSeries); | |
233 | return d->barWidth(); |
|
233 | return d->barWidth(); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
237 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
238 | Returns true, if appending succeeded. |
|
238 | Returns true, if appending succeeded. | |
239 | */ |
|
239 | */ | |
240 | bool QAbstractBarSeries::append(QBarSet *set) |
|
240 | bool QAbstractBarSeries::append(QBarSet *set) | |
241 | { |
|
241 | { | |
242 | Q_D(QAbstractBarSeries); |
|
242 | Q_D(QAbstractBarSeries); | |
243 | bool success = d->append(set); |
|
243 | bool success = d->append(set); | |
244 | if (success) { |
|
244 | if (success) { | |
245 | QList<QBarSet*> sets; |
|
245 | QList<QBarSet*> sets; | |
246 | sets.append(set); |
|
246 | sets.append(set); | |
247 | set->setParent(this); |
|
247 | set->setParent(this); | |
248 | emit barsetsAdded(sets); |
|
248 | emit barsetsAdded(sets); | |
249 | emit countChanged(); |
|
249 | emit countChanged(); | |
250 | } |
|
250 | } | |
251 | return success; |
|
251 | return success; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
255 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
256 | was successful. |
|
256 | was successful. | |
257 | Returns true, if set was removed. |
|
257 | Returns true, if set was removed. | |
258 | */ |
|
258 | */ | |
259 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
259 | bool QAbstractBarSeries::remove(QBarSet *set) | |
260 | { |
|
260 | { | |
261 | Q_D(QAbstractBarSeries); |
|
261 | Q_D(QAbstractBarSeries); | |
262 | bool success = d->remove(set); |
|
262 | bool success = d->remove(set); | |
263 | if (success) { |
|
263 | if (success) { | |
264 | QList<QBarSet*> sets; |
|
264 | QList<QBarSet*> sets; | |
265 | sets.append(set); |
|
265 | sets.append(set); | |
266 | set->setParent(0); |
|
266 | set->setParent(0); | |
267 | emit barsetsRemoved(sets); |
|
267 | emit barsetsRemoved(sets); | |
268 | emit countChanged(); |
|
268 | emit countChanged(); | |
269 | delete set; |
|
269 | delete set; | |
270 | set = 0; |
|
270 | set = 0; | |
271 | } |
|
271 | } | |
272 | return success; |
|
272 | return success; | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Takes a single \a set from the series. Does not delete the barset object. |
|
276 | Takes a single \a set from the series. Does not delete the barset object. | |
277 |
|
277 | |||
278 | NOTE: The series remains as the barset's parent object. You must set the |
|
278 | NOTE: The series remains as the barset's parent object. You must set the | |
279 | parent object to take full ownership. |
|
279 | parent object to take full ownership. | |
280 |
|
280 | |||
281 | Returns true if take was successfull. |
|
281 | Returns true if take was successfull. | |
282 | */ |
|
282 | */ | |
283 | bool QAbstractBarSeries::take(QBarSet *set) |
|
283 | bool QAbstractBarSeries::take(QBarSet *set) | |
284 | { |
|
284 | { | |
285 | Q_D(QAbstractBarSeries); |
|
285 | Q_D(QAbstractBarSeries); | |
286 | bool success = d->remove(set); |
|
286 | bool success = d->remove(set); | |
287 | if (success) { |
|
287 | if (success) { | |
288 | QList<QBarSet*> sets; |
|
288 | QList<QBarSet*> sets; | |
289 | sets.append(set); |
|
289 | sets.append(set); | |
290 | emit barsetsRemoved(sets); |
|
290 | emit barsetsRemoved(sets); | |
291 | emit countChanged(); |
|
291 | emit countChanged(); | |
292 | } |
|
292 | } | |
293 | return success; |
|
293 | return success; | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
297 | Adds a list of barsets to series. Takes ownership of \a sets. | |
298 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
298 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
299 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
299 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
300 | and function returns false. |
|
300 | and function returns false. | |
301 | */ |
|
301 | */ | |
302 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
302 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
303 | { |
|
303 | { | |
304 | Q_D(QAbstractBarSeries); |
|
304 | Q_D(QAbstractBarSeries); | |
305 | bool success = d->append(sets); |
|
305 | bool success = d->append(sets); | |
306 | if (success) { |
|
306 | if (success) { | |
307 | emit barsetsAdded(sets); |
|
307 | emit barsetsAdded(sets); | |
308 | emit countChanged(); |
|
308 | emit countChanged(); | |
309 | } |
|
309 | } | |
310 | return success; |
|
310 | return success; | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | /*! |
|
313 | /*! | |
314 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
314 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
315 | Returns true, if inserting succeeded. |
|
315 | Returns true, if inserting succeeded. | |
316 |
|
316 | |||
317 | */ |
|
317 | */ | |
318 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
318 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
319 | { |
|
319 | { | |
320 | Q_D(QAbstractBarSeries); |
|
320 | Q_D(QAbstractBarSeries); | |
321 | bool success = d->insert(index, set); |
|
321 | bool success = d->insert(index, set); | |
322 | if (success) { |
|
322 | if (success) { | |
323 | QList<QBarSet*> sets; |
|
323 | QList<QBarSet*> sets; | |
324 | sets.append(set); |
|
324 | sets.append(set); | |
325 | emit barsetsAdded(sets); |
|
325 | emit barsetsAdded(sets); | |
326 | emit countChanged(); |
|
326 | emit countChanged(); | |
327 | } |
|
327 | } | |
328 | return success; |
|
328 | return success; | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | /*! |
|
331 | /*! | |
332 | Removes all barsets from the series. Deletes removed sets. |
|
332 | Removes all barsets from the series. Deletes removed sets. | |
333 | */ |
|
333 | */ | |
334 | void QAbstractBarSeries::clear() |
|
334 | void QAbstractBarSeries::clear() | |
335 | { |
|
335 | { | |
336 | Q_D(QAbstractBarSeries); |
|
336 | Q_D(QAbstractBarSeries); | |
337 | QList<QBarSet *> sets = barSets(); |
|
337 | QList<QBarSet *> sets = barSets(); | |
338 | bool success = d->remove(sets); |
|
338 | bool success = d->remove(sets); | |
339 | if (success) { |
|
339 | if (success) { | |
340 | emit barsetsRemoved(sets); |
|
340 | emit barsetsRemoved(sets); | |
341 | emit countChanged(); |
|
341 | emit countChanged(); | |
342 | foreach (QBarSet* set, sets) { |
|
342 | foreach (QBarSet* set, sets) { | |
343 | delete set; |
|
343 | delete set; | |
344 | } |
|
344 | } | |
345 | } |
|
345 | } | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | /*! |
|
348 | /*! | |
349 | Returns number of sets in series. |
|
349 | Returns number of sets in series. | |
350 | */ |
|
350 | */ | |
351 | int QAbstractBarSeries::count() const |
|
351 | int QAbstractBarSeries::count() const | |
352 | { |
|
352 | { | |
353 | Q_D(const QAbstractBarSeries); |
|
353 | Q_D(const QAbstractBarSeries); | |
354 | return d->m_barSets.count(); |
|
354 | return d->m_barSets.count(); | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | /*! |
|
357 | /*! | |
358 | Returns a list of sets in series. Keeps ownership of sets. |
|
358 | Returns a list of sets in series. Keeps ownership of sets. | |
359 | */ |
|
359 | */ | |
360 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
360 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
361 | { |
|
361 | { | |
362 | Q_D(const QAbstractBarSeries); |
|
362 | Q_D(const QAbstractBarSeries); | |
363 | return d->m_barSets; |
|
363 | return d->m_barSets; | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | /*! |
|
366 | /*! | |
367 | Sets the visibility of labels in series to \a visible |
|
367 | Sets the visibility of labels in series to \a visible | |
368 | */ |
|
368 | */ | |
369 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
369 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
370 | { |
|
370 | { | |
371 | Q_D(QAbstractBarSeries); |
|
371 | Q_D(QAbstractBarSeries); | |
372 | if (d->m_labelsVisible != visible) { |
|
372 | if (d->m_labelsVisible != visible) { | |
373 | d->setLabelsVisible(visible); |
|
373 | d->setLabelsVisible(visible); | |
374 | emit labelsVisibleChanged(); |
|
374 | emit labelsVisibleChanged(); | |
375 | } |
|
375 | } | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Returns the visibility of labels |
|
379 | Returns the visibility of labels | |
380 | */ |
|
380 | */ | |
381 | bool QAbstractBarSeries::isLabelsVisible() const |
|
381 | bool QAbstractBarSeries::isLabelsVisible() const | |
382 | { |
|
382 | { | |
383 | Q_D(const QAbstractBarSeries); |
|
383 | Q_D(const QAbstractBarSeries); | |
384 | return d->m_labelsVisible; |
|
384 | return d->m_labelsVisible; | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | void QAbstractBarSeries::setGrouping(bool grouping) |
|
387 | void QAbstractBarSeries::setGrouping(bool grouping) | |
388 | { |
|
388 | { | |
389 | Q_D(QAbstractBarSeries); |
|
389 | Q_D(QAbstractBarSeries); | |
390 | d->setGrouping(grouping); |
|
390 | d->setGrouping(grouping); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 |
|
393 | |||
394 |
|
394 | |||
395 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
395 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
396 |
|
396 | |||
397 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
397 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
398 | QAbstractSeriesPrivate(q), |
|
398 | QAbstractSeriesPrivate(q), | |
399 | m_barWidth(0.5), // Default value is 50% of category width |
|
399 | m_barWidth(0.5), // Default value is 50% of category width | |
400 | m_labelsVisible(false), |
|
400 | m_labelsVisible(false), | |
401 | m_visible(true), |
|
401 | m_visible(true), | |
402 | m_grouping(true) |
|
402 | m_grouping(true) | |
403 | { |
|
403 | { | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
406 | int QAbstractBarSeriesPrivate::categoryCount() const | |
407 | { |
|
407 | { | |
408 | // No categories defined. return count of longest set. |
|
408 | // No categories defined. return count of longest set. | |
409 | int count = 0; |
|
409 | int count = 0; | |
410 | for (int i=0; i<m_barSets.count(); i++) { |
|
410 | for (int i=0; i<m_barSets.count(); i++) { | |
411 | if (m_barSets.at(i)->count() > count) { |
|
411 | if (m_barSets.at(i)->count() > count) { | |
412 | count = m_barSets.at(i)->count(); |
|
412 | count = m_barSets.at(i)->count(); | |
413 | } |
|
413 | } | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | return count; |
|
416 | return count; | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
419 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
420 | { |
|
420 | { | |
421 | if (width < 0.0) { |
|
421 | if (width < 0.0) { | |
422 | width = 0.0; |
|
422 | width = 0.0; | |
423 | } |
|
423 | } | |
424 | m_barWidth = width; |
|
424 | m_barWidth = width; | |
425 | emit updatedBars(); |
|
425 | emit updatedBars(); | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
428 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
429 | { |
|
429 | { | |
430 | return m_barWidth; |
|
430 | return m_barWidth; | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
433 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
434 | { |
|
434 | { | |
435 | return m_barSets.at(index); |
|
435 | return m_barSets.at(index); | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
438 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
439 | { |
|
439 | { | |
440 | m_visible = visible; |
|
440 | m_visible = visible; | |
441 | emit updatedBars(); |
|
441 | emit updatedBars(); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
444 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
445 | { |
|
445 | { | |
446 | m_labelsVisible = visible; |
|
446 | m_labelsVisible = visible; | |
447 | emit labelsVisibleChanged(visible); |
|
447 | emit labelsVisibleChanged(visible); | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | void QAbstractBarSeriesPrivate::setGrouping(bool grouping) |
|
450 | void QAbstractBarSeriesPrivate::setGrouping(bool grouping) | |
451 | { |
|
451 | { | |
452 | if (m_grouping != grouping) { |
|
452 | if (m_grouping != grouping) { | |
453 | m_grouping = grouping; |
|
453 | m_grouping = grouping; | |
454 | emit updatedBars(); |
|
454 | emit updatedBars(); | |
455 | } |
|
455 | } | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | qreal QAbstractBarSeriesPrivate::min() |
|
458 | qreal QAbstractBarSeriesPrivate::min() | |
459 | { |
|
459 | { | |
460 | if (m_barSets.count() <= 0) { |
|
460 | if (m_barSets.count() <= 0) { | |
461 | return 0; |
|
461 | return 0; | |
462 | } |
|
462 | } | |
463 | qreal min = INT_MAX; |
|
463 | qreal min = INT_MAX; | |
464 |
|
464 | |||
465 | for (int i = 0; i < m_barSets.count(); i++) { |
|
465 | for (int i = 0; i < m_barSets.count(); i++) { | |
466 | int categoryCount = m_barSets.at(i)->count(); |
|
466 | int categoryCount = m_barSets.at(i)->count(); | |
467 | for (int j = 0; j < categoryCount; j++) { |
|
467 | for (int j = 0; j < categoryCount; j++) { | |
468 | qreal temp = m_barSets.at(i)->at(j); |
|
468 | qreal temp = m_barSets.at(i)->at(j); | |
469 | if (temp < min) |
|
469 | if (temp < min) | |
470 | min = temp; |
|
470 | min = temp; | |
471 | } |
|
471 | } | |
472 | } |
|
472 | } | |
473 | return min; |
|
473 | return min; | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | qreal QAbstractBarSeriesPrivate::max() |
|
476 | qreal QAbstractBarSeriesPrivate::max() | |
477 | { |
|
477 | { | |
478 | if (m_barSets.count() <= 0) { |
|
478 | if (m_barSets.count() <= 0) { | |
479 | return 0; |
|
479 | return 0; | |
480 | } |
|
480 | } | |
481 | qreal max = INT_MIN; |
|
481 | qreal max = INT_MIN; | |
482 |
|
482 | |||
483 | for (int i = 0; i < m_barSets.count(); i++) { |
|
483 | for (int i = 0; i < m_barSets.count(); i++) { | |
484 | int categoryCount = m_barSets.at(i)->count(); |
|
484 | int categoryCount = m_barSets.at(i)->count(); | |
485 | for (int j = 0; j < categoryCount; j++) { |
|
485 | for (int j = 0; j < categoryCount; j++) { | |
486 | qreal temp = m_barSets.at(i)->at(j); |
|
486 | qreal temp = m_barSets.at(i)->at(j); | |
487 | if (temp > max) |
|
487 | if (temp > max) | |
488 | max = temp; |
|
488 | max = temp; | |
489 | } |
|
489 | } | |
490 | } |
|
490 | } | |
491 |
|
491 | |||
492 | return max; |
|
492 | return max; | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
495 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
496 | { |
|
496 | { | |
497 | if ((set < 0) || (set >= m_barSets.count())) { |
|
497 | if ((set < 0) || (set >= m_barSets.count())) { | |
498 | // No set, no value. |
|
498 | // No set, no value. | |
499 | return 0; |
|
499 | return 0; | |
500 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
500 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
501 | // No category, no value. |
|
501 | // No category, no value. | |
502 | return 0; |
|
502 | return 0; | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | return m_barSets.at(set)->at(category); |
|
505 | return m_barSets.at(set)->at(category); | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
508 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
509 | { |
|
509 | { | |
510 | if ((set < 0) || (set >= m_barSets.count())) { |
|
510 | if ((set < 0) || (set >= m_barSets.count())) { | |
511 | // No set, no value. |
|
511 | // No set, no value. | |
512 | return 0; |
|
512 | return 0; | |
513 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
513 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
514 | // No category, no value. |
|
514 | // No category, no value. | |
515 | return 0; |
|
515 | return 0; | |
516 | } |
|
516 | } | |
517 |
|
517 | |||
518 | qreal value = m_barSets.at(set)->at(category); |
|
518 | qreal value = m_barSets.at(set)->at(category); | |
519 | qreal sum = categorySum(category); |
|
519 | qreal sum = categorySum(category); | |
520 | if ( qFuzzyIsNull(sum) ) { |
|
520 | if ( qFuzzyIsNull(sum) ) { | |
521 | return 0; |
|
521 | return 0; | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | return value / sum; |
|
524 | return value / sum; | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
527 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
528 | { |
|
528 | { | |
529 | qreal sum(0); |
|
529 | qreal sum(0); | |
530 | int count = m_barSets.count(); // Count sets |
|
530 | int count = m_barSets.count(); // Count sets | |
531 | for (int set = 0; set < count; set++) { |
|
531 | for (int set = 0; set < count; set++) { | |
532 | if (category < m_barSets.at(set)->count()) |
|
532 | if (category < m_barSets.at(set)->count()) | |
533 | sum += m_barSets.at(set)->at(category); |
|
533 | sum += m_barSets.at(set)->at(category); | |
534 | } |
|
534 | } | |
535 | return sum; |
|
535 | return sum; | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
538 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
539 | { |
|
539 | { | |
540 | qreal sum(0); |
|
540 | qreal sum(0); | |
541 | int count = m_barSets.count(); // Count sets |
|
541 | int count = m_barSets.count(); // Count sets | |
542 | for (int set = 0; set < count; set++) { |
|
542 | for (int set = 0; set < count; set++) { | |
543 | if (category < m_barSets.at(set)->count()) |
|
543 | if (category < m_barSets.at(set)->count()) | |
544 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
544 | sum += qAbs(m_barSets.at(set)->at(category)); | |
545 | } |
|
545 | } | |
546 | return sum; |
|
546 | return sum; | |
547 | } |
|
547 | } | |
548 |
|
548 | |||
549 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
549 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
550 | { |
|
550 | { | |
551 | qreal max = INT_MIN; |
|
551 | qreal max = INT_MIN; | |
552 | int count = categoryCount(); |
|
552 | int count = categoryCount(); | |
553 | for (int i = 0; i < count; i++) { |
|
553 | for (int i = 0; i < count; i++) { | |
554 | qreal sum = categorySum(i); |
|
554 | qreal sum = categorySum(i); | |
555 | if (sum > max) |
|
555 | if (sum > max) | |
556 | max = sum; |
|
556 | max = sum; | |
557 | } |
|
557 | } | |
558 | return max; |
|
558 | return max; | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | qreal QAbstractBarSeriesPrivate::minX() |
|
561 | qreal QAbstractBarSeriesPrivate::minX() | |
562 | { |
|
562 | { | |
563 | if (m_barSets.count() <= 0) { |
|
563 | if (m_barSets.count() <= 0) { | |
564 | return 0; |
|
564 | return 0; | |
565 | } |
|
565 | } | |
566 | qreal min = INT_MAX; |
|
566 | qreal min = INT_MAX; | |
567 |
|
567 | |||
568 | for (int i = 0; i < m_barSets.count(); i++) { |
|
568 | for (int i = 0; i < m_barSets.count(); i++) { | |
569 | int categoryCount = m_barSets.at(i)->count(); |
|
569 | int categoryCount = m_barSets.at(i)->count(); | |
570 | for (int j = 0; j < categoryCount; j++) { |
|
570 | for (int j = 0; j < categoryCount; j++) { | |
571 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
571 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
572 | if (temp < min) |
|
572 | if (temp < min) | |
573 | min = temp; |
|
573 | min = temp; | |
574 | } |
|
574 | } | |
575 | } |
|
575 | } | |
576 | return min; |
|
576 | return min; | |
577 | } |
|
577 | } | |
578 |
|
578 | |||
579 | qreal QAbstractBarSeriesPrivate::maxX() |
|
579 | qreal QAbstractBarSeriesPrivate::maxX() | |
580 | { |
|
580 | { | |
581 | if (m_barSets.count() <= 0) { |
|
581 | if (m_barSets.count() <= 0) { | |
582 | return 0; |
|
582 | return 0; | |
583 | } |
|
583 | } | |
584 | qreal max = INT_MIN; |
|
584 | qreal max = INT_MIN; | |
585 |
|
585 | |||
586 | for (int i = 0; i < m_barSets.count(); i++) { |
|
586 | for (int i = 0; i < m_barSets.count(); i++) { | |
587 | int categoryCount = m_barSets.at(i)->count(); |
|
587 | int categoryCount = m_barSets.at(i)->count(); | |
588 | for (int j = 0; j < categoryCount; j++) { |
|
588 | for (int j = 0; j < categoryCount; j++) { | |
589 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
589 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
590 | if (temp > max) |
|
590 | if (temp > max) | |
591 | max = temp; |
|
591 | max = temp; | |
592 | } |
|
592 | } | |
593 | } |
|
593 | } | |
594 |
|
594 | |||
595 | return max; |
|
595 | return max; | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 |
|
598 | |||
599 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
599 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
600 | { |
|
600 | { | |
601 | qreal minX(domain.minX()); |
|
601 | qreal minX(domain.minX()); | |
602 | qreal minY(domain.minY()); |
|
602 | qreal minY(domain.minY()); | |
603 | qreal maxX(domain.maxX()); |
|
603 | qreal maxX(domain.maxX()); | |
604 | qreal maxY(domain.maxY()); |
|
604 | qreal maxY(domain.maxY()); | |
605 |
|
605 | |||
606 | qreal seriesMinX = this->minX(); |
|
606 | qreal seriesMinX = this->minX(); | |
607 | qreal seriesMaxX = this->maxX(); |
|
607 | qreal seriesMaxX = this->maxX(); | |
608 | qreal y = max(); |
|
608 | qreal y = max(); | |
609 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
609 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
610 | minY = qMin(minY, y); |
|
610 | minY = qMin(minY, y); | |
611 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
611 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
612 | maxY = qMax(maxY, y); |
|
612 | maxY = qMax(maxY, y); | |
613 |
|
613 | |||
614 | domain.setRange(minX,maxX,minY,maxY); |
|
614 | domain.setRange(minX,maxX,minY,maxY); | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
617 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
618 | { |
|
618 | { | |
619 | Q_UNUSED(presenter); |
|
619 | Q_UNUSED(presenter); | |
620 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
620 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
621 | return 0; |
|
621 | return 0; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
624 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
625 | { |
|
625 | { | |
626 | Q_Q(QAbstractBarSeries); |
|
626 | Q_Q(QAbstractBarSeries); | |
627 | QList<LegendMarker*> markers; |
|
627 | QList<LegendMarker*> markers; | |
628 | foreach(QBarSet* set, q->barSets()) { |
|
628 | foreach(QBarSet* set, q->barSets()) { | |
629 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
629 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
630 | markers << marker; |
|
630 | markers << marker; | |
631 | } |
|
631 | } | |
632 |
|
632 | |||
633 | return markers; |
|
633 | return markers; | |
634 | } |
|
634 | } | |
635 |
|
635 | |||
636 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
636 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
637 | { |
|
637 | { | |
638 | Q_Q(QAbstractBarSeries); |
|
638 | Q_Q(QAbstractBarSeries); | |
639 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
639 | if ((m_barSets.contains(set)) || (set == 0)) { | |
640 | // Fail if set is already in list or set is null. |
|
640 | // Fail if set is already in list or set is null. | |
641 | return false; |
|
641 | return false; | |
642 | } |
|
642 | } | |
643 | m_barSets.append(set); |
|
643 | m_barSets.append(set); | |
644 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
644 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
645 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
645 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
646 | emit restructuredBars(); // this notifies barchartitem |
|
646 | emit restructuredBars(); // this notifies barchartitem | |
647 | if (m_dataset) { |
|
647 | if (m_dataset) { | |
648 | m_dataset->updateSeries(q); // this notifies legend |
|
648 | m_dataset->updateSeries(q); // this notifies legend | |
649 | } |
|
649 | } | |
650 | return true; |
|
650 | return true; | |
651 | } |
|
651 | } | |
652 |
|
652 | |||
653 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
653 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
654 | { |
|
654 | { | |
655 | Q_Q(QAbstractBarSeries); |
|
655 | Q_Q(QAbstractBarSeries); | |
656 | if (!m_barSets.contains(set)) { |
|
656 | if (!m_barSets.contains(set)) { | |
657 | // Fail if set is not in list |
|
657 | // Fail if set is not in list | |
658 | return false; |
|
658 | return false; | |
659 | } |
|
659 | } | |
660 | m_barSets.removeOne(set); |
|
660 | m_barSets.removeOne(set); | |
661 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
661 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
662 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
662 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
663 | emit restructuredBars(); // this notifies barchartitem |
|
663 | emit restructuredBars(); // this notifies barchartitem | |
664 | if (m_dataset) { |
|
664 | if (m_dataset) { | |
665 | m_dataset->updateSeries(q); // this notifies legend |
|
665 | m_dataset->updateSeries(q); // this notifies legend | |
666 | } |
|
666 | } | |
667 | return true; |
|
667 | return true; | |
668 | } |
|
668 | } | |
669 |
|
669 | |||
670 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
670 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
671 | { |
|
671 | { | |
672 | Q_Q(QAbstractBarSeries); |
|
672 | Q_Q(QAbstractBarSeries); | |
673 | foreach (QBarSet* set, sets) { |
|
673 | foreach (QBarSet* set, sets) { | |
674 | if ((set == 0) || (m_barSets.contains(set))) { |
|
674 | if ((set == 0) || (m_barSets.contains(set))) { | |
675 | // Fail if any of the sets is null or is already appended. |
|
675 | // Fail if any of the sets is null or is already appended. | |
676 | return false; |
|
676 | return false; | |
677 | } |
|
677 | } | |
678 | if (sets.count(set) != 1) { |
|
678 | if (sets.count(set) != 1) { | |
679 | // Also fail if same set is more than once in given list. |
|
679 | // Also fail if same set is more than once in given list. | |
680 | return false; |
|
680 | return false; | |
681 | } |
|
681 | } | |
682 | } |
|
682 | } | |
683 |
|
683 | |||
684 | foreach (QBarSet* set, sets) { |
|
684 | foreach (QBarSet* set, sets) { | |
685 | m_barSets.append(set); |
|
685 | m_barSets.append(set); | |
686 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
686 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
687 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
687 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
688 | } |
|
688 | } | |
689 | emit restructuredBars(); // this notifies barchartitem |
|
689 | emit restructuredBars(); // this notifies barchartitem | |
690 | if (m_dataset) { |
|
690 | if (m_dataset) { | |
691 | m_dataset->updateSeries(q); // this notifies legend |
|
691 | m_dataset->updateSeries(q); // this notifies legend | |
692 | } |
|
692 | } | |
693 | return true; |
|
693 | return true; | |
694 | } |
|
694 | } | |
695 |
|
695 | |||
696 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
696 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
697 | { |
|
697 | { | |
698 | Q_Q(QAbstractBarSeries); |
|
698 | Q_Q(QAbstractBarSeries); | |
699 | if (sets.count() == 0) { |
|
699 | if (sets.count() == 0) { | |
700 | return false; |
|
700 | return false; | |
701 | } |
|
701 | } | |
702 | foreach (QBarSet* set, sets) { |
|
702 | foreach (QBarSet* set, sets) { | |
703 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
703 | if ((set == 0) || (!m_barSets.contains(set))) { | |
704 | // Fail if any of the sets is null or is not in series |
|
704 | // Fail if any of the sets is null or is not in series | |
705 | return false; |
|
705 | return false; | |
706 | } |
|
706 | } | |
707 | if (sets.count(set) != 1) { |
|
707 | if (sets.count(set) != 1) { | |
708 | // Also fail if same set is more than once in given list. |
|
708 | // Also fail if same set is more than once in given list. | |
709 | return false; |
|
709 | return false; | |
710 | } |
|
710 | } | |
711 | } |
|
711 | } | |
712 |
|
712 | |||
713 | foreach (QBarSet* set, sets) { |
|
713 | foreach (QBarSet* set, sets) { | |
714 | m_barSets.removeOne(set); |
|
714 | m_barSets.removeOne(set); | |
715 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
715 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
716 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
716 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
717 | } |
|
717 | } | |
718 |
|
718 | |||
719 | emit restructuredBars(); // this notifies barchartitem |
|
719 | emit restructuredBars(); // this notifies barchartitem | |
720 | if (m_dataset) { |
|
720 | if (m_dataset) { | |
721 | m_dataset->updateSeries(q); // this notifies legend |
|
721 | m_dataset->updateSeries(q); // this notifies legend | |
722 | } |
|
722 | } | |
723 | return true; |
|
723 | return true; | |
724 | } |
|
724 | } | |
725 |
|
725 | |||
726 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
726 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
727 | { |
|
727 | { | |
728 | Q_Q(QAbstractBarSeries); |
|
728 | Q_Q(QAbstractBarSeries); | |
729 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
729 | if ((m_barSets.contains(set)) || (set == 0)) { | |
730 | // Fail if set is already in list or set is null. |
|
730 | // Fail if set is already in list or set is null. | |
731 | return false; |
|
731 | return false; | |
732 | } |
|
732 | } | |
733 | m_barSets.insert(index, set); |
|
733 | m_barSets.insert(index, set); | |
734 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
734 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
735 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
735 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
736 | emit restructuredBars(); // this notifies barchartitem |
|
736 | emit restructuredBars(); // this notifies barchartitem | |
737 | if (m_dataset) { |
|
737 | if (m_dataset) { | |
738 | m_dataset->updateSeries(q); // this notifies legend |
|
738 | m_dataset->updateSeries(q); // this notifies legend | |
739 | } |
|
739 | } | |
740 | return true; |
|
740 | return true; | |
741 | } |
|
741 | } | |
742 |
|
742 | |||
743 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
743 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
744 | { |
|
744 | { | |
745 | Q_Q(QAbstractBarSeries); |
|
745 | Q_Q(QAbstractBarSeries); | |
746 |
|
746 | |||
747 | if(axis->type()==QAbstractAxis::AxisTypeCategories) { |
|
747 | if(axis->type()==QAbstractAxis::AxisTypeCategories) { | |
748 |
|
748 | |||
749 | switch(q->type()) { |
|
749 | switch(q->type()) { | |
750 |
|
750 | |||
751 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
751 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
752 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
752 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
753 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
753 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
754 |
|
754 | |||
755 | if(axis->orientation()==Qt::Vertical) |
|
755 | if(axis->orientation()==Qt::Vertical) | |
756 | { |
|
756 | { | |
757 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); |
|
757 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); | |
758 | } |
|
758 | } | |
759 | break; |
|
759 | break; | |
760 | } |
|
760 | } | |
761 | case QAbstractSeries::SeriesTypeBar: |
|
761 | case QAbstractSeries::SeriesTypeBar: | |
762 | case QAbstractSeries::SeriesTypePercentBar: |
|
762 | case QAbstractSeries::SeriesTypePercentBar: | |
763 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
763 | case QAbstractSeries::SeriesTypeStackedBar: { | |
764 |
|
764 | |||
765 | if(axis->orientation()==Qt::Horizontal) |
|
765 | if(axis->orientation()==Qt::Horizontal) | |
766 | { |
|
766 | { | |
767 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); |
|
767 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); | |
768 | } |
|
768 | } | |
769 | break; |
|
769 | break; | |
770 | } |
|
770 | } | |
771 | default: |
|
771 | default: | |
772 | qWarning()<<"Unexpected series type"; |
|
772 | qWarning()<<"Unexpected series type"; | |
773 | break; |
|
773 | break; | |
774 |
|
774 | |||
775 | } |
|
775 | } | |
776 | } |
|
776 | } | |
777 | } |
|
777 | } | |
778 |
|
778 | |||
779 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
779 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
780 | { |
|
780 | { | |
781 | Q_Q(const QAbstractBarSeries); |
|
781 | Q_Q(const QAbstractBarSeries); | |
782 |
|
782 | |||
783 | switch(q->type()) { |
|
783 | switch(q->type()) { | |
784 |
|
784 | |||
785 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
785 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
786 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
786 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
787 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
787 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
788 |
|
788 | |||
789 | if(orientation==Qt::Vertical) |
|
789 | if(orientation==Qt::Vertical) | |
790 | { |
|
790 | { | |
791 | return QAbstractAxis::AxisTypeCategories; |
|
791 | return QAbstractAxis::AxisTypeCategories; | |
792 | } |
|
792 | } | |
793 | break; |
|
793 | break; | |
794 | } |
|
794 | } | |
795 | case QAbstractSeries::SeriesTypeBar: |
|
795 | case QAbstractSeries::SeriesTypeBar: | |
796 | case QAbstractSeries::SeriesTypePercentBar: |
|
796 | case QAbstractSeries::SeriesTypePercentBar: | |
797 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
797 | case QAbstractSeries::SeriesTypeStackedBar: { | |
798 |
|
798 | |||
799 | if(orientation==Qt::Horizontal) |
|
799 | if(orientation==Qt::Horizontal) | |
800 | { |
|
800 | { | |
801 | return QAbstractAxis::AxisTypeCategories; |
|
801 | return QAbstractAxis::AxisTypeCategories; | |
802 | } |
|
802 | } | |
803 | break; |
|
803 | break; | |
804 | } |
|
804 | } | |
805 | default: |
|
805 | default: | |
806 | qWarning()<<"Unexpected series type"; |
|
806 | qWarning()<<"Unexpected series type"; | |
807 | break; |
|
807 | break; | |
808 |
|
808 | |||
809 | } |
|
809 | } | |
810 | return QAbstractAxis::AxisTypeValues; |
|
810 | return QAbstractAxis::AxisTypeValues; | |
811 |
|
811 | |||
812 | } |
|
812 | } | |
813 |
|
813 | |||
814 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoriesAxis* axis) |
|
814 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoriesAxis* axis) | |
815 | { |
|
815 | { | |
816 | QStringList categories; |
|
816 | QStringList categories; | |
817 | if(axis->categories().isEmpty()) { |
|
817 | if(axis->categories().isEmpty()) { | |
818 | for (int i(1); i < categoryCount()+1; i++) |
|
818 | for (int i(1); i < categoryCount()+1; i++) | |
819 | categories << QString::number(i); |
|
819 | categories << QString::number(i); | |
820 | axis->append(categories); |
|
820 | axis->append(categories); | |
821 | } |
|
821 | } | |
822 | } |
|
822 | } | |
823 |
|
823 | |||
824 | #include "moc_qabstractbarseries.cpp" |
|
824 | #include "moc_qabstractbarseries.cpp" | |
825 | #include "moc_qabstractbarseries_p.cpp" |
|
825 | #include "moc_qabstractbarseries_p.cpp" | |
826 |
|
826 | |||
827 |
|
827 | |||
828 | QTCOMMERCIALCHART_END_NAMESPACE |
|
828 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "barchartitem_p.h" |
|
23 | #include "barchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "baranimation_p.h" |
|
26 | #include "baranimation_p.h" | |
27 |
#include "qvalue |
|
27 | #include "qvalueaxis.h" | |
28 | #include "qbarcategoriesaxis.h" |
|
28 | #include "qbarcategoriesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QBarSeries |
|
33 | \class QBarSeries | |
34 | \brief Series for creating bar chart |
|
34 | \brief Series for creating bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data | |
39 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. | |
42 | \image examples_barchart.png |
|
42 | \image examples_barchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass BarSeries QBarSeries |
|
47 | \qmlclass BarSeries QBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple grouped bar chart: |
|
50 | The following QML shows how to create a simple grouped bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart6.png |
|
53 | \image demos_qmlchart6.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QBarSeries. |
|
59 | Constructs empty QBarSeries. | |
60 | QBarSeries is QObject which is a child of a \a parent. |
|
60 | QBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QBarSeries::QBarSeries(QObject *parent) |
|
62 | QBarSeries::QBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypeBar. |
|
68 | Returns QChartSeries::SeriesTypeBar. | |
69 | */ |
|
69 | */ | |
70 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QBarSeries::type() const | |
71 | { |
|
71 | { | |
72 | return QAbstractSeries::SeriesTypeBar; |
|
72 | return QAbstractSeries::SeriesTypeBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QBarSeries::~QBarSeries() |
|
75 | QBarSeries::~QBarSeries() | |
76 | { |
|
76 | { | |
77 | Q_D(QBarSeries); |
|
77 | Q_D(QBarSeries); | |
78 | if(d->m_dataset) { |
|
78 | if(d->m_dataset) { | |
79 | d->m_dataset->removeSeries(this); |
|
79 | d->m_dataset->removeSeries(this); | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
83 | |||
84 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
84 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
89 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
90 | { | |
91 | qreal minX(domain.minX()); |
|
91 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
92 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
93 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
94 | qreal maxY(domain.maxY()); | |
95 |
|
95 | |||
96 | qreal x = categoryCount(); |
|
96 | qreal x = categoryCount(); | |
97 | minX = qMin(minX, - (qreal)0.5); |
|
97 | minX = qMin(minX, - (qreal)0.5); | |
98 | minY = qMin(minY, min()); |
|
98 | minY = qMin(minY, min()); | |
99 | maxX = qMax(maxX, x - (qreal)0.5); |
|
99 | maxX = qMax(maxX, x - (qreal)0.5); | |
100 | maxY = qMax(maxY, max()); |
|
100 | maxY = qMax(maxY, max()); | |
101 |
|
101 | |||
102 | domain.setRange(minX,maxX,minY,maxY); |
|
102 | domain.setRange(minX,maxX,minY,maxY); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
106 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
107 | { |
|
107 | { | |
108 | Q_Q(QBarSeries); |
|
108 | Q_Q(QBarSeries); | |
109 |
|
109 | |||
110 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
110 | BarChartItem* bar = new BarChartItem(q,presenter); | |
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
112 | bar->setAnimation(new BarAnimation(bar)); |
|
112 | bar->setAnimation(new BarAnimation(bar)); | |
113 | } |
|
113 | } | |
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
115 | return bar; |
|
115 | return bar; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | #include "moc_qbarseries.cpp" |
|
118 | #include "moc_qbarseries.cpp" | |
119 |
|
119 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE | |
121 |
|
121 |
@@ -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 "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 |
#include "qvalue |
|
26 | #include "qvalueaxis.h" | |
27 | #include "percentbaranimation_p.h" |
|
27 | #include "percentbaranimation_p.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QPercentBarSeries |
|
32 | \class QPercentBarSeries | |
33 | \brief Series for creating percent bar chart |
|
33 | \brief Series for creating percent bar chart | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
37 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
37 | as stacks, where each bar is shown as percentage of all bars in that category. | |
38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
39 |
|
39 | |||
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
41 | \image examples_percentbarchart.png |
|
41 | \image examples_percentbarchart.png | |
42 |
|
42 | |||
43 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
|
43 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries | |
44 | */ |
|
44 | */ | |
45 | /*! |
|
45 | /*! | |
46 | \qmlclass PercentBarSeries QPercentBarSeries |
|
46 | \qmlclass PercentBarSeries QPercentBarSeries | |
47 | \inherits QAbstractBarSeries |
|
47 | \inherits QAbstractBarSeries | |
48 |
|
48 | |||
49 | The following QML shows how to create a simple percent bar chart: |
|
49 | The following QML shows how to create a simple percent bar chart: | |
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
51 | \beginfloatleft |
|
51 | \beginfloatleft | |
52 | \image demos_qmlchart8.png |
|
52 | \image demos_qmlchart8.png | |
53 | \endfloat |
|
53 | \endfloat | |
54 | \clearfloat |
|
54 | \clearfloat | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | Constructs empty QPercentBarSeries. |
|
58 | Constructs empty QPercentBarSeries. | |
59 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
59 | QPercentBarSeries is QObject which is a child of a \a parent. | |
60 | */ |
|
60 | */ | |
61 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
61 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
62 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
62 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QPercentBarSeries::~QPercentBarSeries() |
|
66 | QPercentBarSeries::~QPercentBarSeries() | |
67 | { |
|
67 | { | |
68 | Q_D(QPercentBarSeries); |
|
68 | Q_D(QPercentBarSeries); | |
69 | if(d->m_dataset) { |
|
69 | if(d->m_dataset) { | |
70 | d->m_dataset->removeSeries(this); |
|
70 | d->m_dataset->removeSeries(this); | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | Returns QChartSeries::SeriesTypePercentBar. |
|
75 | Returns QChartSeries::SeriesTypePercentBar. | |
76 | */ |
|
76 | */ | |
77 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
77 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
78 | { |
|
78 | { | |
79 | return QAbstractSeries::SeriesTypePercentBar; |
|
79 | return QAbstractSeries::SeriesTypePercentBar; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
83 | |||
84 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
84 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
89 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
90 | { | |
91 | qreal minX(domain.minX()); |
|
91 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
92 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
93 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
94 | qreal maxY(domain.maxY()); | |
95 |
|
95 | |||
96 | qreal x = categoryCount(); |
|
96 | qreal x = categoryCount(); | |
97 | minX = qMin(minX, - (qreal)0.5); |
|
97 | minX = qMin(minX, - (qreal)0.5); | |
98 | maxX = qMax(maxX, x - (qreal)0.5); |
|
98 | maxX = qMax(maxX, x - (qreal)0.5); | |
99 | minY = 0; |
|
99 | minY = 0; | |
100 | maxY = 100; |
|
100 | maxY = 100; | |
101 |
|
101 | |||
102 | domain.setRange(minX,maxX,minY,maxY); |
|
102 | domain.setRange(minX,maxX,minY,maxY); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | ChartElement* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
106 | ChartElement* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
107 | { |
|
107 | { | |
108 | Q_Q(QPercentBarSeries); |
|
108 | Q_Q(QPercentBarSeries); | |
109 |
|
109 | |||
110 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
110 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
112 | bar->setAnimation(new PercentBarAnimation(bar)); |
|
112 | bar->setAnimation(new PercentBarAnimation(bar)); | |
113 | } |
|
113 | } | |
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
115 | return bar; |
|
115 | return bar; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | #include "moc_qpercentbarseries.cpp" |
|
118 | #include "moc_qpercentbarseries.cpp" | |
119 |
|
119 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE | |
121 |
|
121 |
@@ -1,122 +1,122 | |||||
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 "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 |
#include "qvalue |
|
26 | #include "qvalueaxis.h" | |
27 | #include "stackedbaranimation_p.h" |
|
27 | #include "stackedbaranimation_p.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QStackedBarSeries |
|
32 | \class QStackedBarSeries | |
33 | \brief Series for creating stacked bar chart |
|
33 | \brief Series for creating stacked bar chart | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
37 | as stacks, where bars in same category are stacked on top of each other. |
|
37 | as stacks, where bars in same category are stacked on top of each other. | |
38 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
38 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
39 |
|
39 | |||
40 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
40 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
41 | \image examples_stackedbarchart.png |
|
41 | \image examples_stackedbarchart.png | |
42 |
|
42 | |||
43 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
43 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \qmlclass StackedBarSeries QStackedBarSeries |
|
47 | \qmlclass StackedBarSeries QStackedBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple stacked bar chart: |
|
50 | The following QML shows how to create a simple stacked bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart7.png |
|
53 | \image demos_qmlchart7.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QStackedBarSeries. |
|
59 | Constructs empty QStackedBarSeries. | |
60 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
60 | QStackedBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
62 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | QStackedBarSeries::~QStackedBarSeries() |
|
67 | QStackedBarSeries::~QStackedBarSeries() | |
68 | { |
|
68 | { | |
69 | Q_D(QStackedBarSeries); |
|
69 | Q_D(QStackedBarSeries); | |
70 | if(d->m_dataset) { |
|
70 | if(d->m_dataset) { | |
71 | d->m_dataset->removeSeries(this); |
|
71 | d->m_dataset->removeSeries(this); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 | /*! |
|
74 | /*! | |
75 | Returns QChartSeries::SeriesTypeStackedBar. |
|
75 | Returns QChartSeries::SeriesTypeStackedBar. | |
76 | */ |
|
76 | */ | |
77 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
77 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
78 | { |
|
78 | { | |
79 | return QAbstractSeries::SeriesTypeStackedBar; |
|
79 | return QAbstractSeries::SeriesTypeStackedBar; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
83 | |||
84 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
84 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
89 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
90 | { | |
91 | qreal minX(domain.minX()); |
|
91 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
92 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
93 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
94 | qreal maxY(domain.maxY()); | |
95 |
|
95 | |||
96 | qreal x = categoryCount(); |
|
96 | qreal x = categoryCount(); | |
97 | qreal y = maxCategorySum(); |
|
97 | qreal y = maxCategorySum(); | |
98 | minX = qMin(minX, - (qreal)0.5); |
|
98 | minX = qMin(minX, - (qreal)0.5); | |
99 | minY = qMin(minY, y); |
|
99 | minY = qMin(minY, y); | |
100 | maxX = qMax(maxX, x - (qreal)0.5); |
|
100 | maxX = qMax(maxX, x - (qreal)0.5); | |
101 | maxY = qMax(maxY, y); |
|
101 | maxY = qMax(maxY, y); | |
102 |
|
102 | |||
103 | domain.setRange(minX,maxX,minY,maxY); |
|
103 | domain.setRange(minX,maxX,minY,maxY); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | ChartElement* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
107 | ChartElement* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
108 | { |
|
108 | { | |
109 | Q_Q(QStackedBarSeries); |
|
109 | Q_Q(QStackedBarSeries); | |
110 |
|
110 | |||
111 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
111 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
112 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
112 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
113 | bar->setAnimation(new StackedBarAnimation(bar)); |
|
113 | bar->setAnimation(new StackedBarAnimation(bar)); | |
114 | } |
|
114 | } | |
115 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
115 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
116 | return bar; |
|
116 | return bar; | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | #include "moc_qstackedbarseries.cpp" |
|
119 | #include "moc_qstackedbarseries.cpp" | |
120 |
|
120 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
121 | QTCOMMERCIALCHART_END_NAMESPACE | |
122 |
|
122 |
@@ -1,484 +1,484 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 |
#include "qvalue |
|
23 | #include "qvalueaxis.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include "qbarcategoriesaxis.h" | |
25 |
#include "qvalue |
|
25 | #include "qvalueaxis_p.h" | |
26 | #include "qintervalsaxis.h" |
|
26 | #include "qintervalsaxis.h" | |
27 | #include "qdatetimeaxis.h" |
|
27 | #include "qdatetimeaxis.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qabstractbarseries.h" |
|
29 | #include "qabstractbarseries.h" | |
30 | #include "qstackedbarseries.h" |
|
30 | #include "qstackedbarseries.h" | |
31 | #include "qpercentbarseries.h" |
|
31 | #include "qpercentbarseries.h" | |
32 | #include "qpieseries.h" |
|
32 | #include "qpieseries.h" | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) |
|
36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) | |
37 | { |
|
37 | { | |
38 |
|
38 | |||
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartDataSet::~ChartDataSet() |
|
41 | ChartDataSet::~ChartDataSet() | |
42 | { |
|
42 | { | |
43 | removeAllSeries(); |
|
43 | removeAllSeries(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
46 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
47 | { |
|
47 | { | |
48 | Domain* domain = m_seriesDomainMap.value(series); |
|
48 | Domain* domain = m_seriesDomainMap.value(series); | |
49 |
|
49 | |||
50 | if(domain) { |
|
50 | if(domain) { | |
51 | qWarning() << "Can not add series. Series already on the chart"; |
|
51 | qWarning() << "Can not add series. Series already on the chart"; | |
52 | return; |
|
52 | return; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | domain = new Domain(series); |
|
55 | domain = new Domain(series); | |
56 | m_seriesDomainMap.insert(series,domain); |
|
56 | m_seriesDomainMap.insert(series,domain); | |
57 | series->d_ptr->scaleDomain(*domain); |
|
57 | series->d_ptr->scaleDomain(*domain); | |
58 |
|
58 | |||
59 | createSeriesIndex(series); |
|
59 | createSeriesIndex(series); | |
60 |
|
60 | |||
61 | series->setParent(this); // take ownership |
|
61 | series->setParent(this); // take ownership | |
62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
63 | series->d_ptr->m_dataset = this; |
|
63 | series->d_ptr->m_dataset = this; | |
64 |
|
64 | |||
65 | emit seriesAdded(series,domain); |
|
65 | emit seriesAdded(series,domain); | |
66 |
|
66 | |||
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
69 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
70 | { |
|
70 | { | |
71 |
|
71 | |||
72 | if(!m_seriesDomainMap.contains(series)) { |
|
72 | if(!m_seriesDomainMap.contains(series)) { | |
73 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
73 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
74 | return; |
|
74 | return; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | emit seriesRemoved(series); |
|
77 | emit seriesRemoved(series); | |
78 |
|
78 | |||
79 | Domain* domain = m_seriesDomainMap.take(series); |
|
79 | Domain* domain = m_seriesDomainMap.take(series); | |
80 | delete domain; |
|
80 | delete domain; | |
81 | domain = 0; |
|
81 | domain = 0; | |
82 |
|
82 | |||
83 | removeSeriesIndex(series); |
|
83 | removeSeriesIndex(series); | |
84 |
|
84 | |||
85 | series->setParent(0); |
|
85 | series->setParent(0); | |
86 | series->d_ptr->m_chart = 0; |
|
86 | series->d_ptr->m_chart = 0; | |
87 | series->d_ptr->m_dataset = 0; |
|
87 | series->d_ptr->m_dataset = 0; | |
88 |
|
88 | |||
89 | removeAxes(series); |
|
89 | removeAxes(series); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
92 | |||
93 |
|
93 | |||
94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) |
|
94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) | |
95 | { |
|
95 | { | |
96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
97 |
|
97 | |||
98 | int key=0; |
|
98 | int key=0; | |
99 | while (i.hasNext()) { |
|
99 | while (i.hasNext()) { | |
100 | i.next(); |
|
100 | i.next(); | |
101 | if(i.key()!=key) { |
|
101 | if(i.key()!=key) { | |
102 | break; |
|
102 | break; | |
103 | } |
|
103 | } | |
104 | key++; |
|
104 | key++; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | m_indexSeriesMap.insert(key,series); |
|
107 | m_indexSeriesMap.insert(key,series); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) |
|
110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) | |
111 | { |
|
111 | { | |
112 | int key = seriesIndex(series); |
|
112 | int key = seriesIndex(series); | |
113 | Q_ASSERT(key!=-1); |
|
113 | Q_ASSERT(key!=-1); | |
114 | m_indexSeriesMap.remove(key); |
|
114 | m_indexSeriesMap.remove(key); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void ChartDataSet::createDefaultAxes() |
|
117 | void ChartDataSet::createDefaultAxes() | |
118 | { |
|
118 | { | |
119 |
|
119 | |||
120 | if(m_seriesDomainMap.isEmpty()) return; |
|
120 | if(m_seriesDomainMap.isEmpty()) return; | |
121 |
|
121 | |||
122 | QAbstractAxis::AxisTypes typeX(0); |
|
122 | QAbstractAxis::AxisTypes typeX(0); | |
123 | QAbstractAxis::AxisTypes typeY(0); |
|
123 | QAbstractAxis::AxisTypes typeY(0); | |
124 |
|
124 | |||
125 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
125 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
126 | while (i.hasNext()) { |
|
126 | while (i.hasNext()) { | |
127 | i.next(); |
|
127 | i.next(); | |
128 | removeAxes(i.key()); |
|
128 | removeAxes(i.key()); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | i.toFront(); |
|
131 | i.toFront(); | |
132 |
|
132 | |||
133 | while (i.hasNext()) { |
|
133 | while (i.hasNext()) { | |
134 | i.next(); |
|
134 | i.next(); | |
135 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
135 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
136 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
136 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
137 | if(axisX) typeX&=axisX->type(); |
|
137 | if(axisX) typeX&=axisX->type(); | |
138 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
138 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); | |
139 | if(axisY) typeY&=axisY->type(); |
|
139 | if(axisY) typeY&=axisY->type(); | |
140 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
140 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | createAxes(typeX,Qt::Horizontal); |
|
143 | createAxes(typeX,Qt::Horizontal); | |
144 | createAxes(typeY,Qt::Vertical); |
|
144 | createAxes(typeY,Qt::Vertical); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) |
|
147 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) | |
148 | { |
|
148 | { | |
149 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
149 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
150 |
|
150 | |||
151 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) |
|
151 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) | |
152 | { |
|
152 | { | |
153 | while (i.hasNext()) { |
|
153 | while (i.hasNext()) { | |
154 | i.next(); |
|
154 | i.next(); | |
155 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); |
|
155 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); | |
156 | if(!axis) continue; |
|
156 | if(!axis) continue; | |
157 | initializeAxis(axis,i.key()); |
|
157 | initializeAxis(axis,i.key()); | |
158 | emit axisAdded(axis,i.value()); |
|
158 | emit axisAdded(axis,i.value()); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
162 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
163 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); |
|
163 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); | |
164 | i.toFront(); |
|
164 | i.toFront(); | |
165 | while (i.hasNext()) { |
|
165 | while (i.hasNext()) { | |
166 | i.next(); |
|
166 | i.next(); | |
167 | initializeAxis(axis,i.key()); |
|
167 | initializeAxis(axis,i.key()); | |
168 | } |
|
168 | } | |
169 | emit axisAdded(axis,i.value()); |
|
169 | emit axisAdded(axis,i.value()); | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 |
|
173 | |||
174 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) |
|
174 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) | |
175 | { |
|
175 | { | |
176 | QAbstractAxis* axis =0; |
|
176 | QAbstractAxis* axis =0; | |
177 |
|
177 | |||
178 | switch(type) { |
|
178 | switch(type) { | |
179 | case QAbstractAxis::AxisTypeValues: |
|
179 | case QAbstractAxis::AxisTypeValues: | |
180 | axis = new QValueAxis(this); |
|
180 | axis = new QValueAxis(this); | |
181 | break; |
|
181 | break; | |
182 | case QAbstractAxis::AxisTypeCategories: |
|
182 | case QAbstractAxis::AxisTypeCategories: | |
183 | axis = new QBarCategoriesAxis(this); |
|
183 | axis = new QBarCategoriesAxis(this); | |
184 | break; |
|
184 | break; | |
185 | case QAbstractAxis::AxisTypeIntervals: |
|
185 | case QAbstractAxis::AxisTypeIntervals: | |
186 | axis = new QIntervalsAxis(this); |
|
186 | axis = new QIntervalsAxis(this); | |
187 | break; |
|
187 | break; | |
188 | case QAbstractAxis::AxisTypeDateTime: |
|
188 | case QAbstractAxis::AxisTypeDateTime: | |
189 | axis = new QDateTimeAxis(this); |
|
189 | axis = new QDateTimeAxis(this); | |
190 | break; |
|
190 | break; | |
191 | default: |
|
191 | default: | |
192 | axis = 0; |
|
192 | axis = 0; | |
193 | break; |
|
193 | break; | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | if(axis) |
|
196 | if(axis) | |
197 | axis->d_ptr->setOrientation(orientation); |
|
197 | axis->d_ptr->setOrientation(orientation); | |
198 |
|
198 | |||
199 | return axis; |
|
199 | return axis; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) |
|
202 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) | |
203 | { |
|
203 | { | |
204 | Domain* domain = m_seriesDomainMap.value(series); |
|
204 | Domain* domain = m_seriesDomainMap.value(series); | |
205 | axis->d_ptr->m_dataset = this; |
|
205 | axis->d_ptr->m_dataset = this; | |
206 | series->d_ptr->initializeAxis(axis); |
|
206 | series->d_ptr->initializeAxis(axis); | |
207 | axis->d_ptr->intializeDomain(domain); |
|
207 | axis->d_ptr->intializeDomain(domain); | |
208 | if(axis->orientation()==Qt::Horizontal) { |
|
208 | if(axis->orientation()==Qt::Horizontal) { | |
209 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
209 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
210 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
210 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
211 | m_seriesAxisXMap.insert(series,axis); |
|
211 | m_seriesAxisXMap.insert(series,axis); | |
212 | } |
|
212 | } | |
213 | else { |
|
213 | else { | |
214 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
214 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
215 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
215 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
216 | m_seriesAxisYMap.insert(series,axis); |
|
216 | m_seriesAxisYMap.insert(series,axis); | |
217 | } |
|
217 | } | |
218 | axis->d_ptr->emitUpdated(); |
|
218 | axis->d_ptr->emitUpdated(); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
221 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |
222 | { |
|
222 | { | |
223 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
223 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
224 |
|
224 | |||
225 | if(axisX) { |
|
225 | if(axisX) { | |
226 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
226 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
227 | int x = axesX.indexOf(axisX); |
|
227 | int x = axesX.indexOf(axisX); | |
228 |
|
228 | |||
229 | if(x==-1) { |
|
229 | if(x==-1) { | |
230 | emit axisRemoved(axisX); |
|
230 | emit axisRemoved(axisX); | |
231 | axisX->d_ptr->m_dataset=0; |
|
231 | axisX->d_ptr->m_dataset=0; | |
232 | axisX->deleteLater(); |
|
232 | axisX->deleteLater(); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
236 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
237 |
|
237 | |||
238 | if(axisY) { |
|
238 | if(axisY) { | |
239 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
239 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
240 |
|
240 | |||
241 | int y = axesY.indexOf(axisY); |
|
241 | int y = axesY.indexOf(axisY); | |
242 |
|
242 | |||
243 | if(y==-1) { |
|
243 | if(y==-1) { | |
244 | emit axisRemoved(axisY); |
|
244 | emit axisRemoved(axisY); | |
245 | axisY->d_ptr->m_dataset=0; |
|
245 | axisY->d_ptr->m_dataset=0; | |
246 | axisY->deleteLater(); |
|
246 | axisY->deleteLater(); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void ChartDataSet::removeAxis(QAbstractAxis* axis) |
|
251 | void ChartDataSet::removeAxis(QAbstractAxis* axis) | |
252 | { |
|
252 | { | |
253 | if(!axis->d_ptr->m_dataset) { |
|
253 | if(!axis->d_ptr->m_dataset) { | |
254 | qWarning()<<"UnBound axis found !"; |
|
254 | qWarning()<<"UnBound axis found !"; | |
255 | return; |
|
255 | return; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
258 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
259 |
|
259 | |||
260 | if(axis->orientation()==Qt::Vertical) { |
|
260 | if(axis->orientation()==Qt::Vertical) { | |
261 | seriesAxisMap= &m_seriesAxisYMap; |
|
261 | seriesAxisMap= &m_seriesAxisYMap; | |
262 | } |
|
262 | } | |
263 | else { |
|
263 | else { | |
264 | seriesAxisMap= &m_seriesAxisXMap; |
|
264 | seriesAxisMap= &m_seriesAxisXMap; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); |
|
267 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); | |
268 |
|
268 | |||
269 | while (i.hasNext()) { |
|
269 | while (i.hasNext()) { | |
270 | i.next(); |
|
270 | i.next(); | |
271 | if(i.value()==axis) { |
|
271 | if(i.value()==axis) { | |
272 | removeSeries(i.key()); |
|
272 | removeSeries(i.key()); | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void ChartDataSet::removeAllSeries() |
|
277 | void ChartDataSet::removeAllSeries() | |
278 | { |
|
278 | { | |
279 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
279 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
280 | foreach(QAbstractSeries *s , series) { |
|
280 | foreach(QAbstractSeries *s , series) { | |
281 | removeSeries(s); |
|
281 | removeSeries(s); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
284 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
285 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
285 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
286 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
286 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
287 |
|
287 | |||
288 | qDeleteAll(series); |
|
288 | qDeleteAll(series); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
291 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
292 | { |
|
292 | { | |
293 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
293 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
294 |
|
294 | |||
295 |
|
295 | |||
296 | blockAxisSignals(true); |
|
296 | blockAxisSignals(true); | |
297 |
|
297 | |||
298 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
298 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
299 |
|
299 | |||
300 | while (i.hasNext()) { |
|
300 | while (i.hasNext()) { | |
301 | i.next(); |
|
301 | i.next(); | |
302 | i.value()->zoomIn(rect,size); |
|
302 | i.value()->zoomIn(rect,size); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | blockAxisSignals(false); |
|
305 | blockAxisSignals(false); | |
306 |
|
306 | |||
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
309 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
310 | { |
|
310 | { | |
311 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
311 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
312 |
|
312 | |||
313 | blockAxisSignals(true); |
|
313 | blockAxisSignals(true); | |
314 |
|
314 | |||
315 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
315 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
316 |
|
316 | |||
317 | while (i.hasNext()) { |
|
317 | while (i.hasNext()) { | |
318 | i.next(); |
|
318 | i.next(); | |
319 | i.value()->zoomOut(rect,size); |
|
319 | i.value()->zoomOut(rect,size); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | blockAxisSignals(false); |
|
322 | blockAxisSignals(false); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
325 | void ChartDataSet::blockAxisSignals(bool enabled) | |
326 | { |
|
326 | { | |
327 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
327 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
328 | while (i.hasNext()) { |
|
328 | while (i.hasNext()) { | |
329 | i.next(); |
|
329 | i.next(); | |
330 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
330 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
331 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
331 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
332 | if(axisX) { |
|
332 | if(axisX) { | |
333 | axisX->d_ptr->blockSignals(enabled); |
|
333 | axisX->d_ptr->blockSignals(enabled); | |
334 | if(!enabled) { |
|
334 | if(!enabled) { | |
335 | axisX->d_ptr->setDirty(false); |
|
335 | axisX->d_ptr->setDirty(false); | |
336 | axisX->d_ptr->emitUpdated(); |
|
336 | axisX->d_ptr->emitUpdated(); | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 | if(axisY) { |
|
339 | if(axisY) { | |
340 | axisY->d_ptr->blockSignals(enabled); |
|
340 | axisY->d_ptr->blockSignals(enabled); | |
341 | if(!enabled) { |
|
341 | if(!enabled) { | |
342 | axisY->d_ptr->setDirty(false); |
|
342 | axisY->d_ptr->setDirty(false); | |
343 | axisY->d_ptr->emitUpdated(); |
|
343 | axisY->d_ptr->emitUpdated(); | |
344 | } |
|
344 | } | |
345 | } |
|
345 | } | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
349 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
350 | { |
|
350 | { | |
351 | int count=0; |
|
351 | int count=0; | |
352 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
352 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
353 | while (i.hasNext()) { |
|
353 | while (i.hasNext()) { | |
354 | i.next(); |
|
354 | i.next(); | |
355 | if(i.key()->type()==type) count++; |
|
355 | if(i.key()->type()==type) count++; | |
356 | } |
|
356 | } | |
357 | return count; |
|
357 | return count; | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
360 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
361 | { |
|
361 | { | |
362 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
362 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
363 | while (i.hasNext()) { |
|
363 | while (i.hasNext()) { | |
364 | i.next(); |
|
364 | i.next(); | |
365 | if (i.value() == series) |
|
365 | if (i.value() == series) | |
366 | return i.key(); |
|
366 | return i.key(); | |
367 | } |
|
367 | } | |
368 | return -1; |
|
368 | return -1; | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
371 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
372 | { |
|
372 | { | |
373 | if(series == 0) { |
|
373 | if(series == 0) { | |
374 |
|
374 | |||
375 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); |
|
375 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); | |
376 |
|
376 | |||
377 | while (i.hasNext()) { |
|
377 | while (i.hasNext()) { | |
378 | i.next(); |
|
378 | i.next(); | |
379 | if(i.value()->isVisible()) return i.value(); |
|
379 | if(i.value()->isVisible()) return i.value(); | |
380 | } |
|
380 | } | |
381 | return 0; |
|
381 | return 0; | |
382 | } |
|
382 | } | |
383 | return m_seriesAxisXMap.value(series); |
|
383 | return m_seriesAxisXMap.value(series); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
386 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
387 | { |
|
387 | { | |
388 | if(series == 0) { |
|
388 | if(series == 0) { | |
389 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); |
|
389 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); | |
390 |
|
390 | |||
391 | while (i.hasNext()) { |
|
391 | while (i.hasNext()) { | |
392 | i.next(); |
|
392 | i.next(); | |
393 | if(i.value()->isVisible()) return i.value(); |
|
393 | if(i.value()->isVisible()) return i.value(); | |
394 | } |
|
394 | } | |
395 | return 0; |
|
395 | return 0; | |
396 | } |
|
396 | } | |
397 | return m_seriesAxisYMap.value(series); |
|
397 | return m_seriesAxisYMap.value(series); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
400 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) | |
401 | { |
|
401 | { | |
402 | Q_ASSERT(axis); |
|
402 | Q_ASSERT(axis); | |
403 |
|
403 | |||
404 | if(!series) { |
|
404 | if(!series) { | |
405 | qWarning() << "Series not found on the chart."; |
|
405 | qWarning() << "Series not found on the chart."; | |
406 | return; |
|
406 | return; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | Domain* domain = m_seriesDomainMap.value(series); |
|
409 | Domain* domain = m_seriesDomainMap.value(series); | |
410 |
|
410 | |||
411 | if(!domain) { |
|
411 | if(!domain) { | |
412 | qWarning() << "Series not found on the chart."; |
|
412 | qWarning() << "Series not found on the chart."; | |
413 | return; |
|
413 | return; | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { |
|
416 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { | |
417 | qWarning()<<"Axis already defined as axis Y"; |
|
417 | qWarning()<<"Axis already defined as axis Y"; | |
418 | return; |
|
418 | return; | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { |
|
421 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { | |
422 | qWarning()<<"Axis already defined as axis X"; |
|
422 | qWarning()<<"Axis already defined as axis X"; | |
423 | return; |
|
423 | return; | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | axis->d_ptr->setOrientation(orientation); |
|
426 | axis->d_ptr->setOrientation(orientation); | |
427 |
|
427 | |||
428 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
428 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
429 |
|
429 | |||
430 | if(orientation==Qt::Vertical) { |
|
430 | if(orientation==Qt::Vertical) { | |
431 | seriesAxisMap= &m_seriesAxisYMap; |
|
431 | seriesAxisMap= &m_seriesAxisYMap; | |
432 | }else{ |
|
432 | }else{ | |
433 | seriesAxisMap= &m_seriesAxisXMap; |
|
433 | seriesAxisMap= &m_seriesAxisXMap; | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
436 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); | |
437 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); |
|
437 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); | |
438 | if(oldAxis) { |
|
438 | if(oldAxis) { | |
439 | if(axes.indexOf(oldAxis)==-1) { |
|
439 | if(axes.indexOf(oldAxis)==-1) { | |
440 | emit axisRemoved(oldAxis); |
|
440 | emit axisRemoved(oldAxis); | |
441 | oldAxis->disconnect(); |
|
441 | oldAxis->disconnect(); | |
442 | QObject::disconnect(domain,0,oldAxis,0); |
|
442 | QObject::disconnect(domain,0,oldAxis,0); | |
443 | oldAxis->d_ptr->m_dataset=0; |
|
443 | oldAxis->d_ptr->m_dataset=0; | |
444 | oldAxis->deleteLater(); |
|
444 | oldAxis->deleteLater(); | |
445 | } |
|
445 | } | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | if(axes.indexOf(axis)==-1) { |
|
448 | if(axes.indexOf(axis)==-1) { | |
449 | initializeAxis(axis,series); |
|
449 | initializeAxis(axis,series); | |
450 | emit axisAdded(axis,domain); |
|
450 | emit axisAdded(axis,domain); | |
451 | }else{ |
|
451 | }else{ | |
452 | initializeAxis(axis,series); |
|
452 | initializeAxis(axis,series); | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
456 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
457 | { |
|
457 | { | |
458 | return m_seriesDomainMap.value(series); |
|
458 | return m_seriesDomainMap.value(series); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
461 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
462 | { |
|
462 | { | |
463 | blockAxisSignals(true); |
|
463 | blockAxisSignals(true); | |
464 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
464 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
465 | while (i.hasNext()) { |
|
465 | while (i.hasNext()) { | |
466 | i.next(); |
|
466 | i.next(); | |
467 | i.value()->move(dx,dy,size); |
|
467 | i.value()->move(dx,dy,size); | |
468 | } |
|
468 | } | |
469 | blockAxisSignals(false); |
|
469 | blockAxisSignals(false); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
472 | QList<QAbstractSeries*> ChartDataSet::series() const | |
473 | { |
|
473 | { | |
474 | return m_seriesDomainMap.keys(); |
|
474 | return m_seriesDomainMap.keys(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
477 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
478 | { |
|
478 | { | |
479 | emit seriesUpdated(series); |
|
479 | emit seriesUpdated(series); | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | #include "moc_chartdataset_p.cpp" |
|
482 | #include "moc_chartdataset_p.cpp" | |
483 |
|
483 | |||
484 | QTCOMMERCIALCHART_END_NAMESPACE |
|
484 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,469 +1,469 | |||||
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 "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 |
#include "qvalue |
|
25 | #include "qvalueaxis.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QXYSeries |
|
30 | \class QXYSeries | |
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
32 | */ |
|
32 | */ | |
33 | /*! |
|
33 | /*! | |
34 | \qmlclass XYSeries |
|
34 | \qmlclass XYSeries | |
35 | \inherits AbstractSeries |
|
35 | \inherits AbstractSeries | |
36 | The XYSeries class is a base class for line, spline and scatter series. |
|
36 | The XYSeries class is a base class for line, spline and scatter series. | |
37 |
|
37 | |||
38 | The class cannot be instantiated directly. |
|
38 | The class cannot be instantiated directly. | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \property QXYSeries::pointsVisible |
|
42 | \property QXYSeries::pointsVisible | |
43 | Controls if the data points are visible and should be drawn. |
|
43 | Controls if the data points are visible and should be drawn. | |
44 | */ |
|
44 | */ | |
45 | /*! |
|
45 | /*! | |
46 | \qmlproperty bool XYSeries::pointsVisible |
|
46 | \qmlproperty bool XYSeries::pointsVisible | |
47 | Controls if the data points are visible and should be drawn. |
|
47 | Controls if the data points are visible and should be drawn. | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \fn QPen QXYSeries::pen() const |
|
51 | \fn QPen QXYSeries::pen() const | |
52 | \brief Returns pen used to draw points for series. |
|
52 | \brief Returns pen used to draw points for series. | |
53 | \sa setPen() |
|
53 | \sa setPen() | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn QBrush QXYSeries::brush() const |
|
57 | \fn QBrush QXYSeries::brush() const | |
58 | \brief Returns brush used to draw points for series. |
|
58 | \brief Returns brush used to draw points for series. | |
59 | \sa setBrush() |
|
59 | \sa setBrush() | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QXYSeries::color |
|
63 | \property QXYSeries::color | |
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
66 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
66 | \sa QXYSeries::pen(), QXYSeries::brush() | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty color XYSeries::color |
|
69 | \qmlproperty color XYSeries::color | |
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
71 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
71 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \fn void QXYSeries::clicked(const QPointF& point) |
|
75 | \fn void QXYSeries::clicked(const QPointF& point) | |
76 | \brief Signal is emitted when user clicks the \a point on chart. |
|
76 | \brief Signal is emitted when user clicks the \a point on chart. | |
77 | */ |
|
77 | */ | |
78 | /*! |
|
78 | /*! | |
79 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
79 | \qmlsignal XYSeries::onClicked(QPointF point) | |
80 | Signal is emitted when user clicks the \a point on chart. For example: |
|
80 | Signal is emitted when user clicks the \a point on chart. For example: | |
81 | \code |
|
81 | \code | |
82 | LineSeries { |
|
82 | LineSeries { | |
83 | XYPoint { x: 0; y: 0 } |
|
83 | XYPoint { x: 0; y: 0 } | |
84 | XYPoint { x: 1.1; y: 2.1 } |
|
84 | XYPoint { x: 1.1; y: 2.1 } | |
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
86 | } |
|
86 | } | |
87 | \endcode |
|
87 | \endcode | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \fn void QXYSeries::pointReplaced(int index) |
|
91 | \fn void QXYSeries::pointReplaced(int index) | |
92 | Signal is emitted when a point has been replaced at \a index. |
|
92 | Signal is emitted when a point has been replaced at \a index. | |
93 | \sa replace() |
|
93 | \sa replace() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
96 | \qmlsignal XYSeries::onPointReplaced(int index) | |
97 | Signal is emitted when a point has been replaced at \a index. |
|
97 | Signal is emitted when a point has been replaced at \a index. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QXYSeries::pointsReplaced() |
|
101 | \fn void QXYSeries::pointsReplaced() | |
102 | Signal is emitted when all points have been replaced with another points. |
|
102 | Signal is emitted when all points have been replaced with another points. | |
103 | \sa replace() |
|
103 | \sa replace() | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlsignal XYSeries::onPointsReplaced() |
|
106 | \qmlsignal XYSeries::onPointsReplaced() | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \fn void QXYSeries::pointAdded(int index) |
|
110 | \fn void QXYSeries::pointAdded(int index) | |
111 | Signal is emitted when a point has been added at \a index. |
|
111 | Signal is emitted when a point has been added at \a index. | |
112 | \sa append(), insert() |
|
112 | \sa append(), insert() | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal XYSeries::onPointAdded(int index) |
|
115 | \qmlsignal XYSeries::onPointAdded(int index) | |
116 | Signal is emitted when a point has been added at \a index. |
|
116 | Signal is emitted when a point has been added at \a index. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QXYSeries::pointRemoved(int index) |
|
120 | \fn void QXYSeries::pointRemoved(int index) | |
121 | Signal is emitted when a point has been removed from \a index. |
|
121 | Signal is emitted when a point has been removed from \a index. | |
122 | \sa remove() |
|
122 | \sa remove() | |
123 | */ |
|
123 | */ | |
124 | /*! |
|
124 | /*! | |
125 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
125 | \qmlsignal XYSeries::onPointRemoved(int index) | |
126 | Signal is emitted when a point has been removed from \a index. |
|
126 | Signal is emitted when a point has been removed from \a index. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QXYSeries::colorChanged(QColor color) |
|
130 | \fn void QXYSeries::colorChanged(QColor color) | |
131 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
131 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
132 | */ |
|
132 | */ | |
133 | /*! |
|
133 | /*! | |
134 | \qmlsignal XYSeries::onColorChanged(color color) |
|
134 | \qmlsignal XYSeries::onColorChanged(color color) | |
135 | Signal is emitted when the line (pen) color has changed to \a color. |
|
135 | Signal is emitted when the line (pen) color has changed to \a color. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QXYSeriesPrivate::updated() |
|
139 | \fn void QXYSeriesPrivate::updated() | |
140 | \brief \internal |
|
140 | \brief \internal | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \qmlmethod XYSeries::append(real x, real y) |
|
144 | \qmlmethod XYSeries::append(real x, real y) | |
145 | Append point (\a x, \a y) to the series |
|
145 | Append point (\a x, \a y) to the series | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
149 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
150 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
150 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
151 | exist. |
|
151 | exist. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \qmlmethod XYSeries::remove(real x, real y) |
|
155 | \qmlmethod XYSeries::remove(real x, real y) | |
156 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
156 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
160 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
161 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
161 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
162 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
162 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \qmlmethod QPointF XYSeries::at(int index) |
|
166 | \qmlmethod QPointF XYSeries::at(int index) | |
167 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
167 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \internal |
|
171 | \internal | |
172 |
|
172 | |||
173 | Constructs empty series object which is a child of \a parent. |
|
173 | Constructs empty series object which is a child of \a parent. | |
174 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
174 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
175 | */ |
|
175 | */ | |
176 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
176 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) | |
177 | { |
|
177 | { | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
181 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
182 | and are deleted when mentioned object are destroyed. |
|
182 | and are deleted when mentioned object are destroyed. | |
183 | */ |
|
183 | */ | |
184 | QXYSeries::~QXYSeries() |
|
184 | QXYSeries::~QXYSeries() | |
185 | { |
|
185 | { | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
189 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
190 | */ |
|
190 | */ | |
191 | void QXYSeries::append(qreal x,qreal y) |
|
191 | void QXYSeries::append(qreal x,qreal y) | |
192 | { |
|
192 | { | |
193 | append(QPointF(x,y)); |
|
193 | append(QPointF(x,y)); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | This is an overloaded function. |
|
197 | This is an overloaded function. | |
198 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
198 | Adds data \a point to the series. Points are connected with lines on the chart. | |
199 | */ |
|
199 | */ | |
200 | void QXYSeries::append(const QPointF &point) |
|
200 | void QXYSeries::append(const QPointF &point) | |
201 | { |
|
201 | { | |
202 | Q_D(QXYSeries); |
|
202 | Q_D(QXYSeries); | |
203 | d->m_points<<point; |
|
203 | d->m_points<<point; | |
204 | emit pointAdded(d->m_points.count()-1); |
|
204 | emit pointAdded(d->m_points.count()-1); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | This is an overloaded function. |
|
208 | This is an overloaded function. | |
209 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
209 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
210 | */ |
|
210 | */ | |
211 | void QXYSeries::append(const QList<QPointF> &points) |
|
211 | void QXYSeries::append(const QList<QPointF> &points) | |
212 | { |
|
212 | { | |
213 | foreach(const QPointF& point , points) { |
|
213 | foreach(const QPointF& point , points) { | |
214 | append(point); |
|
214 | append(point); | |
215 | } |
|
215 | } | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
219 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. | |
220 | \sa QXYSeries::pointReplaced() |
|
220 | \sa QXYSeries::pointReplaced() | |
221 | */ |
|
221 | */ | |
222 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
222 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) | |
223 | { |
|
223 | { | |
224 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
224 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Replaces \a oldPoint with \a newPoint. |
|
228 | Replaces \a oldPoint with \a newPoint. | |
229 | \sa QXYSeries::pointReplaced() |
|
229 | \sa QXYSeries::pointReplaced() | |
230 | */ |
|
230 | */ | |
231 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
231 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) | |
232 | { |
|
232 | { | |
233 | Q_D(QXYSeries); |
|
233 | Q_D(QXYSeries); | |
234 | int index = d->m_points.indexOf(oldPoint); |
|
234 | int index = d->m_points.indexOf(oldPoint); | |
235 | if(index==-1) return; |
|
235 | if(index==-1) return; | |
236 | d->m_points[index] = newPoint; |
|
236 | d->m_points[index] = newPoint; | |
237 | emit pointReplaced(index); |
|
237 | emit pointReplaced(index); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | Replaces the current points with \a points. This is faster than replacing data points one by one, |
|
241 | Replaces the current points with \a points. This is faster than replacing data points one by one, | |
242 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
242 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() | |
243 | when the points have been replaced. |
|
243 | when the points have been replaced. | |
244 | \sa QXYSeries::pointsReplaced() |
|
244 | \sa QXYSeries::pointsReplaced() | |
245 | */ |
|
245 | */ | |
246 | void QXYSeries::replace(QList<QPointF> points) |
|
246 | void QXYSeries::replace(QList<QPointF> points) | |
247 | { |
|
247 | { | |
248 | Q_D(QXYSeries); |
|
248 | Q_D(QXYSeries); | |
249 | d->m_points = points.toVector(); |
|
249 | d->m_points = points.toVector(); | |
250 | emit pointsReplaced(); |
|
250 | emit pointsReplaced(); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Removes current \a x and \a y value. |
|
254 | Removes current \a x and \a y value. | |
255 | */ |
|
255 | */ | |
256 | void QXYSeries::remove(qreal x,qreal y) |
|
256 | void QXYSeries::remove(qreal x,qreal y) | |
257 | { |
|
257 | { | |
258 | remove(QPointF(x,y)); |
|
258 | remove(QPointF(x,y)); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Removes current \a point x value. |
|
262 | Removes current \a point x value. | |
263 |
|
263 | |||
264 | Note: point y value is ignored. |
|
264 | Note: point y value is ignored. | |
265 | */ |
|
265 | */ | |
266 | void QXYSeries::remove(const QPointF &point) |
|
266 | void QXYSeries::remove(const QPointF &point) | |
267 | { |
|
267 | { | |
268 | Q_D(QXYSeries); |
|
268 | Q_D(QXYSeries); | |
269 | int index = d->m_points.indexOf(point); |
|
269 | int index = d->m_points.indexOf(point); | |
270 | if(index==-1) return; |
|
270 | if(index==-1) return; | |
271 | d->m_points.remove(index); |
|
271 | d->m_points.remove(index); | |
272 | emit pointRemoved(index); |
|
272 | emit pointRemoved(index); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Inserts a \a point in the series at \a index position. |
|
276 | Inserts a \a point in the series at \a index position. | |
277 | */ |
|
277 | */ | |
278 | void QXYSeries::insert(int index, const QPointF &point) |
|
278 | void QXYSeries::insert(int index, const QPointF &point) | |
279 | { |
|
279 | { | |
280 | Q_D(QXYSeries); |
|
280 | Q_D(QXYSeries); | |
281 | d->m_points.insert(index, point); |
|
281 | d->m_points.insert(index, point); | |
282 | emit pointAdded(index); |
|
282 | emit pointAdded(index); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | /*! |
|
285 | /*! | |
286 | Removes all points from the series. |
|
286 | Removes all points from the series. | |
287 | */ |
|
287 | */ | |
288 | void QXYSeries::clear() |
|
288 | void QXYSeries::clear() | |
289 | { |
|
289 | { | |
290 | Q_D(QXYSeries); |
|
290 | Q_D(QXYSeries); | |
291 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
291 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
292 | remove(d->m_points.at(i)); |
|
292 | remove(d->m_points.at(i)); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | /*! |
|
295 | /*! | |
296 | Returns list of points in the series. |
|
296 | Returns list of points in the series. | |
297 | */ |
|
297 | */ | |
298 | QList<QPointF> QXYSeries::points() const |
|
298 | QList<QPointF> QXYSeries::points() const | |
299 | { |
|
299 | { | |
300 | Q_D(const QXYSeries); |
|
300 | Q_D(const QXYSeries); | |
301 | return d->m_points.toList(); |
|
301 | return d->m_points.toList(); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | /*! |
|
304 | /*! | |
305 | Returns number of data points within series. |
|
305 | Returns number of data points within series. | |
306 | */ |
|
306 | */ | |
307 | int QXYSeries::count() const |
|
307 | int QXYSeries::count() const | |
308 | { |
|
308 | { | |
309 | Q_D(const QXYSeries); |
|
309 | Q_D(const QXYSeries); | |
310 | return d->m_points.count(); |
|
310 | return d->m_points.count(); | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 |
|
313 | |||
314 | /*! |
|
314 | /*! | |
315 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
315 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
316 | pen from chart theme is used. |
|
316 | pen from chart theme is used. | |
317 | \sa QChart::setTheme() |
|
317 | \sa QChart::setTheme() | |
318 | */ |
|
318 | */ | |
319 | void QXYSeries::setPen(const QPen &pen) |
|
319 | void QXYSeries::setPen(const QPen &pen) | |
320 | { |
|
320 | { | |
321 | Q_D(QXYSeries); |
|
321 | Q_D(QXYSeries); | |
322 | if (d->m_pen != pen) { |
|
322 | if (d->m_pen != pen) { | |
323 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
323 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
324 | d->m_pen = pen; |
|
324 | d->m_pen = pen; | |
325 | emit d->updated(); |
|
325 | emit d->updated(); | |
326 | if (emitColorChanged) |
|
326 | if (emitColorChanged) | |
327 | emit colorChanged(pen.color()); |
|
327 | emit colorChanged(pen.color()); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | QPen QXYSeries::pen() const |
|
331 | QPen QXYSeries::pen() const | |
332 | { |
|
332 | { | |
333 | Q_D(const QXYSeries); |
|
333 | Q_D(const QXYSeries); | |
334 | return d->m_pen; |
|
334 | return d->m_pen; | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | /*! |
|
337 | /*! | |
338 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
338 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
339 | from chart theme setting is used. |
|
339 | from chart theme setting is used. | |
340 | \sa QChart::setTheme() |
|
340 | \sa QChart::setTheme() | |
341 | */ |
|
341 | */ | |
342 | void QXYSeries::setBrush(const QBrush &brush) |
|
342 | void QXYSeries::setBrush(const QBrush &brush) | |
343 | { |
|
343 | { | |
344 | Q_D(QXYSeries); |
|
344 | Q_D(QXYSeries); | |
345 | if (d->m_brush!=brush) { |
|
345 | if (d->m_brush!=brush) { | |
346 | d->m_brush = brush; |
|
346 | d->m_brush = brush; | |
347 | emit d->updated(); |
|
347 | emit d->updated(); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | QBrush QXYSeries::brush() const |
|
351 | QBrush QXYSeries::brush() const | |
352 | { |
|
352 | { | |
353 | Q_D(const QXYSeries); |
|
353 | Q_D(const QXYSeries); | |
354 | return d->m_brush; |
|
354 | return d->m_brush; | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void QXYSeries::setColor(const QColor &color) |
|
357 | void QXYSeries::setColor(const QColor &color) | |
358 | { |
|
358 | { | |
359 | QPen p = pen(); |
|
359 | QPen p = pen(); | |
360 | if (p.color() != color) { |
|
360 | if (p.color() != color) { | |
361 | p.setColor(color); |
|
361 | p.setColor(color); | |
362 | setPen(p); |
|
362 | setPen(p); | |
363 | } |
|
363 | } | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | QColor QXYSeries::color() const |
|
366 | QColor QXYSeries::color() const | |
367 | { |
|
367 | { | |
368 | return pen().color(); |
|
368 | return pen().color(); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void QXYSeries::setPointsVisible(bool visible) |
|
371 | void QXYSeries::setPointsVisible(bool visible) | |
372 | { |
|
372 | { | |
373 | Q_D(QXYSeries); |
|
373 | Q_D(QXYSeries); | |
374 | if (d->m_pointsVisible != visible){ |
|
374 | if (d->m_pointsVisible != visible){ | |
375 | d->m_pointsVisible = visible; |
|
375 | d->m_pointsVisible = visible; | |
376 | emit d->updated(); |
|
376 | emit d->updated(); | |
377 | } |
|
377 | } | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | bool QXYSeries::pointsVisible() const |
|
380 | bool QXYSeries::pointsVisible() const | |
381 | { |
|
381 | { | |
382 | Q_D(const QXYSeries); |
|
382 | Q_D(const QXYSeries); | |
383 | return d->m_pointsVisible; |
|
383 | return d->m_pointsVisible; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 |
|
386 | |||
387 | /*! |
|
387 | /*! | |
388 | Stream operator for adding a data \a point to the series. |
|
388 | Stream operator for adding a data \a point to the series. | |
389 | \sa append() |
|
389 | \sa append() | |
390 | */ |
|
390 | */ | |
391 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
391 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
392 | { |
|
392 | { | |
393 | append(point); |
|
393 | append(point); | |
394 | return *this; |
|
394 | return *this; | |
395 | } |
|
395 | } | |
396 |
|
396 | |||
397 |
|
397 | |||
398 | /*! |
|
398 | /*! | |
399 | Stream operator for adding a list of \a points to the series. |
|
399 | Stream operator for adding a list of \a points to the series. | |
400 | \sa append() |
|
400 | \sa append() | |
401 | */ |
|
401 | */ | |
402 |
|
402 | |||
403 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
403 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) | |
404 | { |
|
404 | { | |
405 | append(points); |
|
405 | append(points); | |
406 | return *this; |
|
406 | return *this; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
409 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
410 |
|
410 | |||
411 |
|
411 | |||
412 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
412 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : | |
413 | QAbstractSeriesPrivate(q), |
|
413 | QAbstractSeriesPrivate(q), | |
414 | m_pointsVisible(false) |
|
414 | m_pointsVisible(false) | |
415 | { |
|
415 | { | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
418 | void QXYSeriesPrivate::scaleDomain(Domain& domain) | |
419 | { |
|
419 | { | |
420 | qreal minX(0); |
|
420 | qreal minX(0); | |
421 | qreal minY(0); |
|
421 | qreal minY(0); | |
422 | qreal maxX(1); |
|
422 | qreal maxX(1); | |
423 | qreal maxY(1); |
|
423 | qreal maxY(1); | |
424 |
|
424 | |||
425 | Q_Q(QXYSeries); |
|
425 | Q_Q(QXYSeries); | |
426 |
|
426 | |||
427 | const QList<QPointF>& points = q->points(); |
|
427 | const QList<QPointF>& points = q->points(); | |
428 |
|
428 | |||
429 | if (!points.isEmpty()){ |
|
429 | if (!points.isEmpty()){ | |
430 | minX = points[0].x(); |
|
430 | minX = points[0].x(); | |
431 | minY = points[0].y(); |
|
431 | minY = points[0].y(); | |
432 | maxX = minX; |
|
432 | maxX = minX; | |
433 | maxY = minY; |
|
433 | maxY = minY; | |
434 |
|
434 | |||
435 | for (int i = 0; i < points.count(); i++) { |
|
435 | for (int i = 0; i < points.count(); i++) { | |
436 | qreal x = points[i].x(); |
|
436 | qreal x = points[i].x(); | |
437 | qreal y = points[i].y(); |
|
437 | qreal y = points[i].y(); | |
438 | minX = qMin(minX, x); |
|
438 | minX = qMin(minX, x); | |
439 | minY = qMin(minY, y); |
|
439 | minY = qMin(minY, y); | |
440 | maxX = qMax(maxX, x); |
|
440 | maxX = qMax(maxX, x); | |
441 | maxY = qMax(maxY, y); |
|
441 | maxY = qMax(maxY, y); | |
442 | } |
|
442 | } | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | domain.setRange(minX,maxX,minY,maxY); |
|
445 | domain.setRange(minX,maxX,minY,maxY); | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
448 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |
449 | { |
|
449 | { | |
450 | Q_Q(QXYSeries); |
|
450 | Q_Q(QXYSeries); | |
451 | QList<LegendMarker*> list; |
|
451 | QList<LegendMarker*> list; | |
452 | return list << new XYLegendMarker(q,legend); |
|
452 | return list << new XYLegendMarker(q,legend); | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
455 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
456 | { |
|
456 | { | |
457 | Q_UNUSED(axis); |
|
457 | Q_UNUSED(axis); | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
460 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
461 | { |
|
461 | { | |
462 | Q_UNUSED(orientation); |
|
462 | Q_UNUSED(orientation); | |
463 | return QAbstractAxis::AxisTypeValues; |
|
463 | return QAbstractAxis::AxisTypeValues; | |
464 | } |
|
464 | } | |
465 |
|
465 | |||
466 | #include "moc_qxyseries.cpp" |
|
466 | #include "moc_qxyseries.cpp" | |
467 | #include "moc_qxyseries_p.cpp" |
|
467 | #include "moc_qxyseries_p.cpp" | |
468 |
|
468 | |||
469 | QTCOMMERCIALCHART_END_NAMESPACE |
|
469 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,107 +1,107 | |||||
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 XYCHARTITEM_H |
|
30 | #ifndef XYCHARTITEM_H | |
31 | #define XYCHARTITEM_H |
|
31 | #define XYCHARTITEM_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "xyanimation_p.h" |
|
35 | #include "xyanimation_p.h" | |
36 |
#include "qvalue |
|
36 | #include "qvalueaxis.h" | |
37 | #include <QPen> |
|
37 | #include <QPen> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartPresenter; |
|
41 | class ChartPresenter; | |
42 | class QXYSeries; |
|
42 | class QXYSeries; | |
43 |
|
43 | |||
44 | class XYChart : public ChartElement |
|
44 | class XYChart : public ChartElement | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | explicit XYChart(QXYSeries *series, ChartPresenter *presenter); |
|
48 | explicit XYChart(QXYSeries *series, ChartPresenter *presenter); | |
49 | ~XYChart() {} |
|
49 | ~XYChart() {} | |
50 |
|
50 | |||
51 | void setGeometryPoints(const QVector<QPointF>& points); |
|
51 | void setGeometryPoints(const QVector<QPointF>& points); | |
52 | QVector<QPointF> geometryPoints() const { return m_points; } |
|
52 | QVector<QPointF> geometryPoints() const { return m_points; } | |
53 |
|
53 | |||
54 | void setClipRect(const QRectF &rect); |
|
54 | void setClipRect(const QRectF &rect); | |
55 | QRectF clipRect() const { return m_clipRect; } |
|
55 | QRectF clipRect() const { return m_clipRect; } | |
56 |
|
56 | |||
57 | QSizeF size() const { return m_size; } |
|
57 | QSizeF size() const { return m_size; } | |
58 | QPointF origin() const { return m_origin; } |
|
58 | QPointF origin() const { return m_origin; } | |
59 |
|
59 | |||
60 | void setAnimation(XYAnimation* animation); |
|
60 | void setAnimation(XYAnimation* animation); | |
61 | ChartAnimation* animation() const { return m_animation; } |
|
61 | ChartAnimation* animation() const { return m_animation; } | |
62 | virtual void updateGeometry() = 0; |
|
62 | virtual void updateGeometry() = 0; | |
63 |
|
63 | |||
64 | bool isDirty() const { return m_dirty; } |
|
64 | bool isDirty() const { return m_dirty; } | |
65 | void setDirty(bool dirty); |
|
65 | void setDirty(bool dirty); | |
66 |
|
66 | |||
67 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
68 | void handlePointAdded(int index); |
|
68 | void handlePointAdded(int index); | |
69 | void handlePointRemoved(int index); |
|
69 | void handlePointRemoved(int index); | |
70 | void handlePointReplaced(int index); |
|
70 | void handlePointReplaced(int index); | |
71 | void handlePointsReplaced(); |
|
71 | void handlePointsReplaced(); | |
72 | void handleDomainUpdated(); |
|
72 | void handleDomainUpdated(); | |
73 | void handleGeometryChanged(const QRectF &size); |
|
73 | void handleGeometryChanged(const QRectF &size); | |
74 |
|
74 | |||
75 | Q_SIGNALS: |
|
75 | Q_SIGNALS: | |
76 | void clicked(const QPointF& point); |
|
76 | void clicked(const QPointF& point); | |
77 |
|
77 | |||
78 | protected: |
|
78 | protected: | |
79 | virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1); |
|
79 | virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1); | |
80 | QPointF calculateGeometryPoint(const QPointF &point) const; |
|
80 | QPointF calculateGeometryPoint(const QPointF &point) const; | |
81 | QPointF calculateGeometryPoint(int index) const; |
|
81 | QPointF calculateGeometryPoint(int index) const; | |
82 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
82 | QPointF calculateDomainPoint(const QPointF &point) const; | |
83 | QVector<QPointF> calculateGeometryPoints() const; |
|
83 | QVector<QPointF> calculateGeometryPoints() const; | |
84 |
|
84 | |||
85 | private: |
|
85 | private: | |
86 | inline bool isEmpty(); |
|
86 | inline bool isEmpty(); | |
87 |
|
87 | |||
88 | protected: |
|
88 | protected: | |
89 | qreal m_minX; |
|
89 | qreal m_minX; | |
90 | qreal m_maxX; |
|
90 | qreal m_maxX; | |
91 | qreal m_minY; |
|
91 | qreal m_minY; | |
92 | qreal m_maxY; |
|
92 | qreal m_maxY; | |
93 | QXYSeries* m_series; |
|
93 | QXYSeries* m_series; | |
94 | QSizeF m_size; |
|
94 | QSizeF m_size; | |
95 | QPointF m_origin; |
|
95 | QPointF m_origin; | |
96 | QRectF m_clipRect; |
|
96 | QRectF m_clipRect; | |
97 | QVector<QPointF> m_points; |
|
97 | QVector<QPointF> m_points; | |
98 | XYAnimation* m_animation; |
|
98 | XYAnimation* m_animation; | |
99 | bool m_dirty; |
|
99 | bool m_dirty; | |
100 |
|
100 | |||
101 | friend class AreaChartItem; |
|
101 | friend class AreaChartItem; | |
102 |
|
102 | |||
103 | }; |
|
103 | }; | |
104 |
|
104 | |||
105 | QTCOMMERCIALCHART_END_NAMESPACE |
|
105 | QTCOMMERCIALCHART_END_NAMESPACE | |
106 |
|
106 | |||
107 | #endif |
|
107 | #endif |
@@ -1,30 +1,30 | |||||
1 | !include( ../tests.pri ) { |
|
1 | !include( ../tests.pri ) { | |
2 | error( "Couldn't find the tests.pri file!" ) |
|
2 | error( "Couldn't find the tests.pri file!" ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TEMPLATE = subdirs |
|
5 | TEMPLATE = subdirs | |
6 | SUBDIRS += \ |
|
6 | SUBDIRS += \ | |
7 | qchartview \ |
|
7 | qchartview \ | |
8 | qchart \ |
|
8 | qchart \ | |
9 | qlineseries \ |
|
9 | qlineseries \ | |
10 | qbarset \ |
|
10 | qbarset \ | |
11 | qbarseries \ |
|
11 | qbarseries \ | |
12 | qstackedbarseries \ |
|
12 | qstackedbarseries \ | |
13 | qpercentbarseries \ |
|
13 | qpercentbarseries \ | |
14 | qpieslice qpieseries \ |
|
14 | qpieslice qpieseries \ | |
15 | qpiemodelmapper \ |
|
15 | qpiemodelmapper \ | |
16 | qsplineseries \ |
|
16 | qsplineseries \ | |
17 | qscatterseries \ |
|
17 | qscatterseries \ | |
18 | qxymodelmapper \ |
|
18 | qxymodelmapper \ | |
19 | qbarmodelmapper \ |
|
19 | qbarmodelmapper \ | |
20 | qhorizontalbarseries \ |
|
20 | qhorizontalbarseries \ | |
21 | qhorizontalstackedbarseries \ |
|
21 | qhorizontalstackedbarseries \ | |
22 | qhorizontalpercentbarseries \ |
|
22 | qhorizontalpercentbarseries \ | |
23 |
qvalue |
|
23 | qvalueaxis \ | |
24 | qintervalsaxis \ |
|
24 | qintervalsaxis \ | |
25 | qdatetimeaxis \ |
|
25 | qdatetimeaxis \ | |
26 | qbarcategoriesaxis |
|
26 | qbarcategoriesaxis | |
27 |
|
27 | |||
28 | test_private:{ |
|
28 | test_private:{ | |
29 | SUBDIRS += domain chartdataset |
|
29 | SUBDIRS += domain chartdataset | |
30 | } |
|
30 | } |
@@ -1,623 +1,623 | |||||
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 <qabstractaxis.h> |
|
22 | #include <qabstractaxis.h> | |
23 |
#include <qvalue |
|
23 | #include <qvalueaxis.h> | |
24 | #include <qbarcategoriesaxis.h> |
|
24 | #include <qbarcategoriesaxis.h> | |
25 | #include <qlineseries.h> |
|
25 | #include <qlineseries.h> | |
26 | #include <qareaseries.h> |
|
26 | #include <qareaseries.h> | |
27 | #include <qscatterseries.h> |
|
27 | #include <qscatterseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qpieseries.h> |
|
29 | #include <qpieseries.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qpercentbarseries.h> |
|
31 | #include <qpercentbarseries.h> | |
32 | #include <qstackedbarseries.h> |
|
32 | #include <qstackedbarseries.h> | |
33 | #include <private/chartdataset_p.h> |
|
33 | #include <private/chartdataset_p.h> | |
34 | #include <private/domain_p.h> |
|
34 | #include <private/domain_p.h> | |
35 | #include <tst_definitions.h> |
|
35 | #include <tst_definitions.h> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | QTCOMMERCIALCHART_USE_NAMESPACE | |
38 |
|
38 | |||
39 | Q_DECLARE_METATYPE(Domain *) |
|
39 | Q_DECLARE_METATYPE(Domain *) | |
40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
40 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
41 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
44 | Q_DECLARE_METATYPE(QLineSeries *) | |
45 |
|
45 | |||
46 | class tst_ChartDataSet: public QObject { |
|
46 | class tst_ChartDataSet: public QObject { | |
47 |
|
47 | |||
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 |
|
49 | |||
50 | public Q_SLOTS: |
|
50 | public Q_SLOTS: | |
51 | void initTestCase(); |
|
51 | void initTestCase(); | |
52 | void cleanupTestCase(); |
|
52 | void cleanupTestCase(); | |
53 | void init(); |
|
53 | void init(); | |
54 | void cleanup(); |
|
54 | void cleanup(); | |
55 |
|
55 | |||
56 | private Q_SLOTS: |
|
56 | private Q_SLOTS: | |
57 | void chartdataset_data(); |
|
57 | void chartdataset_data(); | |
58 | void chartdataset(); |
|
58 | void chartdataset(); | |
59 | void addSeries_data(); |
|
59 | void addSeries_data(); | |
60 | void addSeries(); |
|
60 | void addSeries(); | |
61 | void setAxisX_data(); |
|
61 | void setAxisX_data(); | |
62 | void setAxisX(); |
|
62 | void setAxisX(); | |
63 | void setAxisY_data(); |
|
63 | void setAxisY_data(); | |
64 | void setAxisY(); |
|
64 | void setAxisY(); | |
65 | void removeSeries_data(); |
|
65 | void removeSeries_data(); | |
66 | void removeSeries(); |
|
66 | void removeSeries(); | |
67 | void removeAllSeries_data(); |
|
67 | void removeAllSeries_data(); | |
68 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
69 | void seriesCount_data(); |
|
69 | void seriesCount_data(); | |
70 | void seriesCount(); |
|
70 | void seriesCount(); | |
71 | void seriesIndex_data(); |
|
71 | void seriesIndex_data(); | |
72 | void seriesIndex(); |
|
72 | void seriesIndex(); | |
73 | void domain_data(); |
|
73 | void domain_data(); | |
74 | void domain(); |
|
74 | void domain(); | |
75 | void zoomInDomain_data(); |
|
75 | void zoomInDomain_data(); | |
76 | void zoomInDomain(); |
|
76 | void zoomInDomain(); | |
77 | void zoomOutDomain_data(); |
|
77 | void zoomOutDomain_data(); | |
78 | void zoomOutDomain(); |
|
78 | void zoomOutDomain(); | |
79 | void scrollDomain_data(); |
|
79 | void scrollDomain_data(); | |
80 | void scrollDomain(); |
|
80 | void scrollDomain(); | |
81 |
|
81 | |||
82 | private: |
|
82 | private: | |
83 | ChartDataSet* m_dataset; |
|
83 | ChartDataSet* m_dataset; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void tst_ChartDataSet::initTestCase() |
|
86 | void tst_ChartDataSet::initTestCase() | |
87 | { |
|
87 | { | |
88 | qRegisterMetaType<Domain*>(); |
|
88 | qRegisterMetaType<Domain*>(); | |
89 | qRegisterMetaType<QAbstractAxis*>(); |
|
89 | qRegisterMetaType<QAbstractAxis*>(); | |
90 | qRegisterMetaType<QAbstractSeries*>(); |
|
90 | qRegisterMetaType<QAbstractSeries*>(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_ChartDataSet::cleanupTestCase() |
|
93 | void tst_ChartDataSet::cleanupTestCase() | |
94 | { |
|
94 | { | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void tst_ChartDataSet::init() |
|
97 | void tst_ChartDataSet::init() | |
98 | { |
|
98 | { | |
99 | m_dataset = new ChartDataSet(); |
|
99 | m_dataset = new ChartDataSet(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | void tst_ChartDataSet::cleanup() |
|
103 | void tst_ChartDataSet::cleanup() | |
104 | { |
|
104 | { | |
105 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
105 | QList<QAbstractSeries*> series = m_dataset->series(); | |
106 | foreach(QAbstractSeries* serie, series) |
|
106 | foreach(QAbstractSeries* serie, series) | |
107 | { |
|
107 | { | |
108 | m_dataset->removeSeries(serie); |
|
108 | m_dataset->removeSeries(serie); | |
109 | } |
|
109 | } | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void tst_ChartDataSet::chartdataset_data() |
|
112 | void tst_ChartDataSet::chartdataset_data() | |
113 | { |
|
113 | { | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void tst_ChartDataSet::chartdataset() |
|
116 | void tst_ChartDataSet::chartdataset() | |
117 | { |
|
117 | { | |
118 | QVERIFY(m_dataset->axisX(0) == 0); |
|
118 | QVERIFY(m_dataset->axisX(0) == 0); | |
119 | QVERIFY(m_dataset->axisY(0) == 0); |
|
119 | QVERIFY(m_dataset->axisY(0) == 0); | |
120 | QLineSeries* series = new QLineSeries(this); |
|
120 | QLineSeries* series = new QLineSeries(this); | |
121 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
121 | QCOMPARE(m_dataset->seriesIndex(series),-1); | |
122 | QVERIFY(m_dataset->domain(series) == 0); |
|
122 | QVERIFY(m_dataset->domain(series) == 0); | |
123 | QVERIFY(m_dataset->axisX(series) == 0); |
|
123 | QVERIFY(m_dataset->axisX(series) == 0); | |
124 | QVERIFY(m_dataset->axisY(series) == 0); |
|
124 | QVERIFY(m_dataset->axisY(series) == 0); | |
125 | m_dataset->createDefaultAxes(); |
|
125 | m_dataset->createDefaultAxes(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | void tst_ChartDataSet::addSeries_data() |
|
129 | void tst_ChartDataSet::addSeries_data() | |
130 | { |
|
130 | { | |
131 | QTest::addColumn<QAbstractSeries*>("series"); |
|
131 | QTest::addColumn<QAbstractSeries*>("series"); | |
132 |
|
132 | |||
133 | QAbstractSeries* line = new QLineSeries(this); |
|
133 | QAbstractSeries* line = new QLineSeries(this); | |
134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
135 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
135 | QAbstractSeries* scatter = new QScatterSeries(this); | |
136 | QAbstractSeries* spline = new QSplineSeries(this); |
|
136 | QAbstractSeries* spline = new QSplineSeries(this); | |
137 | QAbstractSeries* pie = new QPieSeries(this); |
|
137 | QAbstractSeries* pie = new QPieSeries(this); | |
138 | QAbstractSeries* bar = new QBarSeries(this); |
|
138 | QAbstractSeries* bar = new QBarSeries(this); | |
139 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
139 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
140 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
140 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
141 |
|
141 | |||
142 | QTest::newRow("line") << line; |
|
142 | QTest::newRow("line") << line; | |
143 | QTest::newRow("area") << area; |
|
143 | QTest::newRow("area") << area; | |
144 | QTest::newRow("scatter") << scatter; |
|
144 | QTest::newRow("scatter") << scatter; | |
145 | QTest::newRow("spline") << spline; |
|
145 | QTest::newRow("spline") << spline; | |
146 | QTest::newRow("pie") << pie; |
|
146 | QTest::newRow("pie") << pie; | |
147 | QTest::newRow("bar") << bar; |
|
147 | QTest::newRow("bar") << bar; | |
148 | QTest::newRow("percent") << percent; |
|
148 | QTest::newRow("percent") << percent; | |
149 | QTest::newRow("stacked") << stacked; |
|
149 | QTest::newRow("stacked") << stacked; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void tst_ChartDataSet::addSeries() |
|
152 | void tst_ChartDataSet::addSeries() | |
153 | { |
|
153 | { | |
154 |
|
154 | |||
155 | QFETCH(QAbstractSeries*, series); |
|
155 | QFETCH(QAbstractSeries*, series); | |
156 |
|
156 | |||
157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
161 |
|
161 | |||
162 | m_dataset->addSeries(series); |
|
162 | m_dataset->addSeries(series); | |
163 | m_dataset->createDefaultAxes(); |
|
163 | m_dataset->createDefaultAxes(); | |
164 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
164 | if(series->type()==QAbstractSeries::SeriesTypePie){ | |
165 | TRY_COMPARE(spy0.count(), 0); |
|
165 | TRY_COMPARE(spy0.count(), 0); | |
166 | }else{ |
|
166 | }else{ | |
167 | TRY_COMPARE(spy0.count(), 2); |
|
167 | TRY_COMPARE(spy0.count(), 2); | |
168 | } |
|
168 | } | |
169 | TRY_COMPARE(spy1.count(), 0); |
|
169 | TRY_COMPARE(spy1.count(), 0); | |
170 | TRY_COMPARE(spy2.count(), 1); |
|
170 | TRY_COMPARE(spy2.count(), 1); | |
171 | TRY_COMPARE(spy3.count(), 0); |
|
171 | TRY_COMPARE(spy3.count(), 0); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 |
|
174 | |||
175 | void tst_ChartDataSet::setAxisX_data() |
|
175 | void tst_ChartDataSet::setAxisX_data() | |
176 | { |
|
176 | { | |
177 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
177 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
178 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
178 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
179 | QTest::addColumn<int>("axisCount"); |
|
179 | QTest::addColumn<int>("axisCount"); | |
180 |
|
180 | |||
181 | QAbstractSeries* line = new QLineSeries(this); |
|
181 | QAbstractSeries* line = new QLineSeries(this); | |
182 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
182 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
183 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
183 | QAbstractSeries* scatter = new QScatterSeries(this); | |
184 | QAbstractSeries* spline = new QSplineSeries(this); |
|
184 | QAbstractSeries* spline = new QSplineSeries(this); | |
185 | QAbstractSeries* pie = new QPieSeries(this); |
|
185 | QAbstractSeries* pie = new QPieSeries(this); | |
186 | QAbstractSeries* bar = new QBarSeries(this); |
|
186 | QAbstractSeries* bar = new QBarSeries(this); | |
187 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
187 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
188 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
188 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
189 |
|
189 | |||
190 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
190 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
191 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
191 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
192 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3; |
|
192 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3; | |
193 |
|
193 | |||
194 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
194 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) | |
195 | << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1; |
|
195 | << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1; | |
196 |
|
196 | |||
197 | QList<QAbstractAxis*> axes0; |
|
197 | QList<QAbstractAxis*> axes0; | |
198 | axes0 << new QValueAxis(this) << new QValueAxis(this); |
|
198 | axes0 << new QValueAxis(this) << new QValueAxis(this); | |
199 | axes0 << axes0.last(); |
|
199 | axes0 << axes0.last(); | |
200 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
200 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") | |
201 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
201 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
202 | << axes0 << 2; |
|
202 | << axes0 << 2; | |
203 | //TODO: add more test cases |
|
203 | //TODO: add more test cases | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void tst_ChartDataSet::setAxisX() |
|
206 | void tst_ChartDataSet::setAxisX() | |
207 | { |
|
207 | { | |
208 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
208 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
209 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
209 | QFETCH(QList<QAbstractAxis*>, axisList); | |
210 | QFETCH(int, axisCount); |
|
210 | QFETCH(int, axisCount); | |
211 |
|
211 | |||
212 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
212 | Q_ASSERT(seriesList.count() == axisList.count()); | |
213 |
|
213 | |||
214 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
214 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
215 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
215 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
216 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
216 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
217 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
217 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
218 |
|
218 | |||
219 | foreach(QAbstractSeries* series, seriesList){ |
|
219 | foreach(QAbstractSeries* series, seriesList){ | |
220 | m_dataset->addSeries(series); |
|
220 | m_dataset->addSeries(series); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | TRY_COMPARE(spy0.count(), 0); |
|
223 | TRY_COMPARE(spy0.count(), 0); | |
224 | TRY_COMPARE(spy1.count(), 0); |
|
224 | TRY_COMPARE(spy1.count(), 0); | |
225 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
225 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
226 | TRY_COMPARE(spy3.count(), 0); |
|
226 | TRY_COMPARE(spy3.count(), 0); | |
227 |
|
227 | |||
228 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
228 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
229 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
229 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
230 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
230 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
231 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
231 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
232 |
|
232 | |||
233 | for(int i=0 ; i < seriesList.count(); i++){ |
|
233 | for(int i=0 ; i < seriesList.count(); i++){ | |
234 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal); |
|
234 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | TRY_COMPARE(spy4.count(), axisCount); |
|
237 | TRY_COMPARE(spy4.count(), axisCount); | |
238 | TRY_COMPARE(spy5.count(), 0); |
|
238 | TRY_COMPARE(spy5.count(), 0); | |
239 | TRY_COMPARE(spy6.count(), 0); |
|
239 | TRY_COMPARE(spy6.count(), 0); | |
240 | TRY_COMPARE(spy7.count(), 0); |
|
240 | TRY_COMPARE(spy7.count(), 0); | |
241 |
|
241 | |||
242 | for(int i=0 ; i < seriesList.count(); i++){ |
|
242 | for(int i=0 ; i < seriesList.count(); i++){ | |
243 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
243 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); | |
244 | } |
|
244 | } | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | void tst_ChartDataSet::setAxisY_data() |
|
247 | void tst_ChartDataSet::setAxisY_data() | |
248 | { |
|
248 | { | |
249 | setAxisX_data(); |
|
249 | setAxisX_data(); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void tst_ChartDataSet::setAxisY() |
|
252 | void tst_ChartDataSet::setAxisY() | |
253 | { |
|
253 | { | |
254 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
254 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
255 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
255 | QFETCH(QList<QAbstractAxis*>, axisList); | |
256 | QFETCH(int, axisCount); |
|
256 | QFETCH(int, axisCount); | |
257 |
|
257 | |||
258 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
258 | Q_ASSERT(seriesList.count() == axisList.count()); | |
259 |
|
259 | |||
260 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
260 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
261 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
261 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
262 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
262 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
263 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
263 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
264 |
|
264 | |||
265 | foreach(QAbstractSeries* series, seriesList){ |
|
265 | foreach(QAbstractSeries* series, seriesList){ | |
266 | m_dataset->addSeries(series); |
|
266 | m_dataset->addSeries(series); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | TRY_COMPARE(spy0.count(), 0); |
|
269 | TRY_COMPARE(spy0.count(), 0); | |
270 | TRY_COMPARE(spy1.count(), 0); |
|
270 | TRY_COMPARE(spy1.count(), 0); | |
271 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
271 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
272 | TRY_COMPARE(spy3.count(), 0); |
|
272 | TRY_COMPARE(spy3.count(), 0); | |
273 |
|
273 | |||
274 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
274 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
275 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
275 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
276 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
276 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
277 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
277 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
278 |
|
278 | |||
279 | for(int i=0 ; i < seriesList.count(); i++){ |
|
279 | for(int i=0 ; i < seriesList.count(); i++){ | |
280 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical); |
|
280 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | TRY_COMPARE(spy4.count(), axisCount); |
|
283 | TRY_COMPARE(spy4.count(), axisCount); | |
284 | TRY_COMPARE(spy5.count(), 0); |
|
284 | TRY_COMPARE(spy5.count(), 0); | |
285 | TRY_COMPARE(spy6.count(), 0); |
|
285 | TRY_COMPARE(spy6.count(), 0); | |
286 | TRY_COMPARE(spy7.count(), 0); |
|
286 | TRY_COMPARE(spy7.count(), 0); | |
287 |
|
287 | |||
288 | for(int i=0 ; i < seriesList.count(); i++){ |
|
288 | for(int i=0 ; i < seriesList.count(); i++){ | |
289 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
289 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); | |
290 | } |
|
290 | } | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void tst_ChartDataSet::removeSeries_data() |
|
293 | void tst_ChartDataSet::removeSeries_data() | |
294 | { |
|
294 | { | |
295 | addSeries_data(); |
|
295 | addSeries_data(); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | void tst_ChartDataSet::removeSeries() |
|
298 | void tst_ChartDataSet::removeSeries() | |
299 | { |
|
299 | { | |
300 | QFETCH(QAbstractSeries*, series); |
|
300 | QFETCH(QAbstractSeries*, series); | |
301 |
|
301 | |||
302 | m_dataset->addSeries(series); |
|
302 | m_dataset->addSeries(series); | |
303 | m_dataset->createDefaultAxes(); |
|
303 | m_dataset->createDefaultAxes(); | |
304 |
|
304 | |||
305 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
305 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
306 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
306 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
307 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
307 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
308 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
308 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
309 |
|
309 | |||
310 | m_dataset->removeSeries(series); |
|
310 | m_dataset->removeSeries(series); | |
311 |
|
311 | |||
312 | TRY_COMPARE(spy0.count(), 0); |
|
312 | TRY_COMPARE(spy0.count(), 0); | |
313 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
313 | if (series->type() == QAbstractSeries::SeriesTypePie) { | |
314 | TRY_COMPARE(spy1.count(), 0); |
|
314 | TRY_COMPARE(spy1.count(), 0); | |
315 | } |
|
315 | } | |
316 | else { |
|
316 | else { | |
317 | TRY_COMPARE(spy1.count(), 2); |
|
317 | TRY_COMPARE(spy1.count(), 2); | |
318 | } |
|
318 | } | |
319 | TRY_COMPARE(spy2.count(), 0); |
|
319 | TRY_COMPARE(spy2.count(), 0); | |
320 | TRY_COMPARE(spy3.count(), 1); |
|
320 | TRY_COMPARE(spy3.count(), 1); | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | void tst_ChartDataSet::removeAllSeries_data() |
|
323 | void tst_ChartDataSet::removeAllSeries_data() | |
324 | { |
|
324 | { | |
325 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
325 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
326 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
326 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
327 | QTest::addColumn<int>("axisCount"); |
|
327 | QTest::addColumn<int>("axisCount"); | |
328 |
|
328 | |||
329 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
329 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
330 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
330 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) | |
331 | << new QScatterSeries(this)) |
|
331 | << new QScatterSeries(this)) | |
332 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) |
|
332 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) | |
333 | << new QValueAxis(this)) << 3; |
|
333 | << new QValueAxis(this)) << 3; | |
334 | //TODO: |
|
334 | //TODO: | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void tst_ChartDataSet::removeAllSeries() |
|
337 | void tst_ChartDataSet::removeAllSeries() | |
338 | { |
|
338 | { | |
339 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
339 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
340 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
340 | QFETCH(QList<QAbstractAxis*>, axisList); | |
341 | QFETCH(int, axisCount); |
|
341 | QFETCH(int, axisCount); | |
342 |
|
342 | |||
343 | foreach(QAbstractSeries* series, seriesList) { |
|
343 | foreach(QAbstractSeries* series, seriesList) { | |
344 | m_dataset->addSeries(series); |
|
344 | m_dataset->addSeries(series); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | for (int i = 0; i < seriesList.count(); i++) { |
|
347 | for (int i = 0; i < seriesList.count(); i++) { | |
348 | m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal); |
|
348 | m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
351 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
352 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
352 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
353 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
353 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
354 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
354 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
355 |
|
355 | |||
356 | m_dataset->removeAllSeries(); |
|
356 | m_dataset->removeAllSeries(); | |
357 |
|
357 | |||
358 | TRY_COMPARE(spy0.count(), 0); |
|
358 | TRY_COMPARE(spy0.count(), 0); | |
359 | TRY_COMPARE(spy1.count(), axisCount); |
|
359 | TRY_COMPARE(spy1.count(), axisCount); | |
360 | TRY_COMPARE(spy2.count(), 0); |
|
360 | TRY_COMPARE(spy2.count(), 0); | |
361 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
361 | TRY_COMPARE(spy3.count(), seriesList.count()); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 |
|
364 | |||
365 | void tst_ChartDataSet::seriesCount_data() |
|
365 | void tst_ChartDataSet::seriesCount_data() | |
366 | { |
|
366 | { | |
367 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
367 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
368 | QTest::addColumn<int>("seriesCount"); |
|
368 | QTest::addColumn<int>("seriesCount"); | |
369 |
|
369 | |||
370 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
370 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; | |
371 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
371 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | void tst_ChartDataSet::seriesCount() |
|
374 | void tst_ChartDataSet::seriesCount() | |
375 | { |
|
375 | { | |
376 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
376 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
377 | QFETCH(int, seriesCount); |
|
377 | QFETCH(int, seriesCount); | |
378 |
|
378 | |||
379 | foreach(QAbstractSeries* series, seriesList){ |
|
379 | foreach(QAbstractSeries* series, seriesList){ | |
380 | m_dataset->addSeries(series); |
|
380 | m_dataset->addSeries(series); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
383 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
384 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
384 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
385 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
385 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
386 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
386 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
387 |
|
387 | |||
388 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
388 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); | |
389 | TRY_COMPARE(spy0.count(), 0); |
|
389 | TRY_COMPARE(spy0.count(), 0); | |
390 | TRY_COMPARE(spy1.count(), 0); |
|
390 | TRY_COMPARE(spy1.count(), 0); | |
391 | TRY_COMPARE(spy2.count(), 0); |
|
391 | TRY_COMPARE(spy2.count(), 0); | |
392 | TRY_COMPARE(spy3.count(), 0); |
|
392 | TRY_COMPARE(spy3.count(), 0); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | void tst_ChartDataSet::seriesIndex_data() |
|
395 | void tst_ChartDataSet::seriesIndex_data() | |
396 | { |
|
396 | { | |
397 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
397 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
398 |
|
398 | |||
399 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
399 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
400 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
400 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void tst_ChartDataSet::seriesIndex() |
|
403 | void tst_ChartDataSet::seriesIndex() | |
404 | { |
|
404 | { | |
405 |
|
405 | |||
406 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
406 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
407 |
|
407 | |||
408 | foreach(QAbstractSeries* series, seriesList) { |
|
408 | foreach(QAbstractSeries* series, seriesList) { | |
409 | m_dataset->addSeries(series); |
|
409 | m_dataset->addSeries(series); | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
412 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
413 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
413 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
414 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
414 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); | |
415 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
415 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
416 |
|
416 | |||
417 | for (int i = 0; i < seriesList.count(); i++) { |
|
417 | for (int i = 0; i < seriesList.count(); i++) { | |
418 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
418 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | TRY_COMPARE(spy0.count(), 0); |
|
421 | TRY_COMPARE(spy0.count(), 0); | |
422 | TRY_COMPARE(spy1.count(), 0); |
|
422 | TRY_COMPARE(spy1.count(), 0); | |
423 | TRY_COMPARE(spy2.count(), 0); |
|
423 | TRY_COMPARE(spy2.count(), 0); | |
424 | TRY_COMPARE(spy3.count(), 0); |
|
424 | TRY_COMPARE(spy3.count(), 0); | |
425 |
|
425 | |||
426 | foreach(QAbstractSeries* series, seriesList) { |
|
426 | foreach(QAbstractSeries* series, seriesList) { | |
427 | m_dataset->removeSeries(series); |
|
427 | m_dataset->removeSeries(series); | |
428 | } |
|
428 | } | |
429 |
|
429 | |||
430 | for (int i = 0; i < seriesList.count(); i++) { |
|
430 | for (int i = 0; i < seriesList.count(); i++) { | |
431 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
431 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
432 | } |
|
432 | } | |
433 |
|
433 | |||
434 | foreach(QAbstractSeries* series, seriesList) { |
|
434 | foreach(QAbstractSeries* series, seriesList) { | |
435 | m_dataset->addSeries(series); |
|
435 | m_dataset->addSeries(series); | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 | for (int i = 0; i < seriesList.count(); i++) { |
|
438 | for (int i = 0; i < seriesList.count(); i++) { | |
439 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
439 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | m_dataset->removeSeries(seriesList.at(1)); |
|
442 | m_dataset->removeSeries(seriesList.at(1)); | |
443 |
|
443 | |||
444 | for (int i = 0; i < seriesList.count(); i++) { |
|
444 | for (int i = 0; i < seriesList.count(); i++) { | |
445 | if (i != 1) |
|
445 | if (i != 1) | |
446 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
446 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
447 | else |
|
447 | else | |
448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | m_dataset->addSeries(seriesList.at(1)); |
|
451 | m_dataset->addSeries(seriesList.at(1)); | |
452 |
|
452 | |||
453 | for (int i = 0; i < seriesList.count(); i++) { |
|
453 | for (int i = 0; i < seriesList.count(); i++) { | |
454 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
454 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | m_dataset->removeSeries(seriesList.at(2)); |
|
457 | m_dataset->removeSeries(seriesList.at(2)); | |
458 |
|
458 | |||
459 | for (int i = 0; i < seriesList.count(); i++) { |
|
459 | for (int i = 0; i < seriesList.count(); i++) { | |
460 | if (i != 2) |
|
460 | if (i != 2) | |
461 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
461 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
462 | else |
|
462 | else | |
463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
464 | } |
|
464 | } | |
465 |
|
465 | |||
466 | m_dataset->removeSeries(seriesList.at(0)); |
|
466 | m_dataset->removeSeries(seriesList.at(0)); | |
467 |
|
467 | |||
468 | for (int i = 0; i < seriesList.count(); i++) { |
|
468 | for (int i = 0; i < seriesList.count(); i++) { | |
469 | if (i != 2 && i != 0) |
|
469 | if (i != 2 && i != 0) | |
470 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
470 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
471 | else |
|
471 | else | |
472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | m_dataset->addSeries(seriesList.at(2)); |
|
475 | m_dataset->addSeries(seriesList.at(2)); | |
476 | m_dataset->addSeries(seriesList.at(0)); |
|
476 | m_dataset->addSeries(seriesList.at(0)); | |
477 |
|
477 | |||
478 | for (int i = 0; i < seriesList.count(); i++) { |
|
478 | for (int i = 0; i < seriesList.count(); i++) { | |
479 | if (i == 2) |
|
479 | if (i == 2) | |
480 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
480 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); | |
481 | else if (i == 0) |
|
481 | else if (i == 0) | |
482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); | |
483 | else |
|
483 | else | |
484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | void tst_ChartDataSet::domain_data() |
|
489 | void tst_ChartDataSet::domain_data() | |
490 | { |
|
490 | { | |
491 | addSeries_data(); |
|
491 | addSeries_data(); | |
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | void tst_ChartDataSet::domain() |
|
494 | void tst_ChartDataSet::domain() | |
495 | { |
|
495 | { | |
496 | QFETCH(QAbstractSeries*, series); |
|
496 | QFETCH(QAbstractSeries*, series); | |
497 |
|
497 | |||
498 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
498 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
499 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
499 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
500 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
500 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
501 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
501 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
502 |
|
502 | |||
503 | m_dataset->addSeries(series); |
|
503 | m_dataset->addSeries(series); | |
504 | QVERIFY(m_dataset->domain(series)); |
|
504 | QVERIFY(m_dataset->domain(series)); | |
505 |
|
505 | |||
506 |
|
506 | |||
507 | TRY_COMPARE(spy0.count(), 0); |
|
507 | TRY_COMPARE(spy0.count(), 0); | |
508 | TRY_COMPARE(spy1.count(), 0); |
|
508 | TRY_COMPARE(spy1.count(), 0); | |
509 | TRY_COMPARE(spy2.count(), 1); |
|
509 | TRY_COMPARE(spy2.count(), 1); | |
510 |
|
510 | |||
511 | QList<QVariant> arguments = spy2.takeFirst(); |
|
511 | QList<QVariant> arguments = spy2.takeFirst(); | |
512 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
512 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); | |
513 | QVERIFY(m_dataset->domain(series) == domain); |
|
513 | QVERIFY(m_dataset->domain(series) == domain); | |
514 |
|
514 | |||
515 | TRY_COMPARE(spy3.count(), 0); |
|
515 | TRY_COMPARE(spy3.count(), 0); | |
516 |
|
516 | |||
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | void tst_ChartDataSet::zoomInDomain_data() |
|
519 | void tst_ChartDataSet::zoomInDomain_data() | |
520 | { |
|
520 | { | |
521 | QTest::addColumn<bool >("sameAxis"); |
|
521 | QTest::addColumn<bool >("sameAxis"); | |
522 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
522 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
523 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
523 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
524 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
524 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | void tst_ChartDataSet::zoomInDomain() |
|
527 | void tst_ChartDataSet::zoomInDomain() | |
528 | { |
|
528 | { | |
529 | QFETCH(bool, sameAxis); |
|
529 | QFETCH(bool, sameAxis); | |
530 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
530 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
531 |
|
531 | |||
532 | foreach(QAbstractSeries* series, seriesList) { |
|
532 | foreach(QAbstractSeries* series, seriesList) { | |
533 | m_dataset->addSeries(series); |
|
533 | m_dataset->addSeries(series); | |
534 | } |
|
534 | } | |
535 |
|
535 | |||
536 | if(sameAxis) m_dataset->createDefaultAxes(); |
|
536 | if(sameAxis) m_dataset->createDefaultAxes(); | |
537 |
|
537 | |||
538 | QList<QSignalSpy*> spyList; |
|
538 | QList<QSignalSpy*> spyList; | |
539 |
|
539 | |||
540 | foreach(QAbstractSeries* series, seriesList) { |
|
540 | foreach(QAbstractSeries* series, seriesList) { | |
541 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated())); |
|
541 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated())); | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
544 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); | |
545 |
|
545 | |||
546 | foreach(QSignalSpy* spy, spyList) { |
|
546 | foreach(QSignalSpy* spy, spyList) { | |
547 | TRY_COMPARE(spy->count(), 1); |
|
547 | TRY_COMPARE(spy->count(), 1); | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | qDeleteAll(spyList); |
|
550 | qDeleteAll(spyList); | |
551 | } |
|
551 | } | |
552 |
|
552 | |||
553 |
|
553 | |||
554 |
|
554 | |||
555 | void tst_ChartDataSet::zoomOutDomain_data() |
|
555 | void tst_ChartDataSet::zoomOutDomain_data() | |
556 | { |
|
556 | { | |
557 | zoomInDomain_data(); |
|
557 | zoomInDomain_data(); | |
558 | } |
|
558 | } | |
559 |
|
559 | |||
560 | void tst_ChartDataSet::zoomOutDomain() |
|
560 | void tst_ChartDataSet::zoomOutDomain() | |
561 | { |
|
561 | { | |
562 | QFETCH(bool, sameAxis); |
|
562 | QFETCH(bool, sameAxis); | |
563 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
563 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
564 |
|
564 | |||
565 | foreach(QAbstractSeries* series, seriesList) { |
|
565 | foreach(QAbstractSeries* series, seriesList) { | |
566 | m_dataset->addSeries(series); |
|
566 | m_dataset->addSeries(series); | |
567 | } |
|
567 | } | |
568 |
|
568 | |||
569 | if (sameAxis) |
|
569 | if (sameAxis) | |
570 | m_dataset->createDefaultAxes(); |
|
570 | m_dataset->createDefaultAxes(); | |
571 |
|
571 | |||
572 | QList<QSignalSpy*> spyList; |
|
572 | QList<QSignalSpy*> spyList; | |
573 |
|
573 | |||
574 | foreach(QAbstractSeries* series, seriesList) { |
|
574 | foreach(QAbstractSeries* series, seriesList) { | |
575 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated())); |
|
575 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated())); | |
576 | } |
|
576 | } | |
577 |
|
577 | |||
578 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
578 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); | |
579 |
|
579 | |||
580 | foreach(QSignalSpy* spy, spyList) { |
|
580 | foreach(QSignalSpy* spy, spyList) { | |
581 | TRY_COMPARE(spy->count(), 1); |
|
581 | TRY_COMPARE(spy->count(), 1); | |
582 | } |
|
582 | } | |
583 |
|
583 | |||
584 | qDeleteAll (spyList); |
|
584 | qDeleteAll (spyList); | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | void tst_ChartDataSet::scrollDomain_data() |
|
587 | void tst_ChartDataSet::scrollDomain_data() | |
588 | { |
|
588 | { | |
589 | zoomInDomain_data(); |
|
589 | zoomInDomain_data(); | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | void tst_ChartDataSet::scrollDomain() |
|
592 | void tst_ChartDataSet::scrollDomain() | |
593 | { |
|
593 | { | |
594 | QFETCH(bool, sameAxis); |
|
594 | QFETCH(bool, sameAxis); | |
595 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
595 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
596 |
|
596 | |||
597 | foreach(QAbstractSeries* series, seriesList) { |
|
597 | foreach(QAbstractSeries* series, seriesList) { | |
598 | m_dataset->addSeries(series); |
|
598 | m_dataset->addSeries(series); | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | if (sameAxis) |
|
601 | if (sameAxis) | |
602 | m_dataset->createDefaultAxes(); |
|
602 | m_dataset->createDefaultAxes(); | |
603 |
|
603 | |||
604 | QList<QSignalSpy*> spyList; |
|
604 | QList<QSignalSpy*> spyList; | |
605 |
|
605 | |||
606 | foreach(QAbstractSeries* series, seriesList) { |
|
606 | foreach(QAbstractSeries* series, seriesList) { | |
607 | spyList |
|
607 | spyList | |
608 | << new QSignalSpy(m_dataset->domain(series), |
|
608 | << new QSignalSpy(m_dataset->domain(series), | |
609 | SIGNAL(updated())); |
|
609 | SIGNAL(updated())); | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); |
|
612 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); | |
613 |
|
613 | |||
614 | foreach(QSignalSpy* spy, spyList) { |
|
614 | foreach(QSignalSpy* spy, spyList) { | |
615 | TRY_COMPARE(spy->count(), 1); |
|
615 | TRY_COMPARE(spy->count(), 1); | |
616 | } |
|
616 | } | |
617 |
|
617 | |||
618 | qDeleteAll(spyList); |
|
618 | qDeleteAll(spyList); | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | QTEST_MAIN(tst_ChartDataSet) |
|
621 | QTEST_MAIN(tst_ChartDataSet) | |
622 | #include "tst_chartdataset.moc" |
|
622 | #include "tst_chartdataset.moc" | |
623 |
|
623 |
@@ -1,788 +1,788 | |||||
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 <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <qareaseries.h> |
|
24 | #include <qareaseries.h> | |
25 | #include <qscatterseries.h> |
|
25 | #include <qscatterseries.h> | |
26 | #include <qsplineseries.h> |
|
26 | #include <qsplineseries.h> | |
27 | #include <qpieseries.h> |
|
27 | #include <qpieseries.h> | |
28 | #include <qabstractbarseries.h> |
|
28 | #include <qabstractbarseries.h> | |
29 | #include <qbarseries.h> |
|
29 | #include <qbarseries.h> | |
30 | #include <qpercentbarseries.h> |
|
30 | #include <qpercentbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 |
#include <qvalue |
|
32 | #include <qvalueaxis.h> | |
33 | #include <qbarcategoriesaxis.h> |
|
33 | #include <qbarcategoriesaxis.h> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
36 |
|
36 | |||
37 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
37 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
38 | Q_DECLARE_METATYPE(QValueAxis *) |
|
38 | Q_DECLARE_METATYPE(QValueAxis *) | |
39 | Q_DECLARE_METATYPE(QBarCategoriesAxis *) |
|
39 | Q_DECLARE_METATYPE(QBarCategoriesAxis *) | |
40 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
40 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
41 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
41 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
42 | Q_DECLARE_METATYPE(QBrush) |
|
42 | Q_DECLARE_METATYPE(QBrush) | |
43 | Q_DECLARE_METATYPE(QPen) |
|
43 | Q_DECLARE_METATYPE(QPen) | |
44 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
44 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
45 |
|
45 | |||
46 | class tst_QChart : public QObject |
|
46 | class tst_QChart : public QObject | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 |
|
49 | |||
50 | public slots: |
|
50 | public slots: | |
51 | void initTestCase(); |
|
51 | void initTestCase(); | |
52 | void cleanupTestCase(); |
|
52 | void cleanupTestCase(); | |
53 | void init(); |
|
53 | void init(); | |
54 | void cleanup(); |
|
54 | void cleanup(); | |
55 |
|
55 | |||
56 | private slots: |
|
56 | private slots: | |
57 | void qchart_data(); |
|
57 | void qchart_data(); | |
58 | void qchart(); |
|
58 | void qchart(); | |
59 | void addSeries_data(); |
|
59 | void addSeries_data(); | |
60 | void addSeries(); |
|
60 | void addSeries(); | |
61 | void animationOptions_data(); |
|
61 | void animationOptions_data(); | |
62 | void animationOptions(); |
|
62 | void animationOptions(); | |
63 | void axisX_data(); |
|
63 | void axisX_data(); | |
64 | void axisX(); |
|
64 | void axisX(); | |
65 | void axisY_data(); |
|
65 | void axisY_data(); | |
66 | void axisY(); |
|
66 | void axisY(); | |
67 | void backgroundBrush_data(); |
|
67 | void backgroundBrush_data(); | |
68 | void backgroundBrush(); |
|
68 | void backgroundBrush(); | |
69 | void backgroundPen_data(); |
|
69 | void backgroundPen_data(); | |
70 | void backgroundPen(); |
|
70 | void backgroundPen(); | |
71 | void isBackgroundVisible_data(); |
|
71 | void isBackgroundVisible_data(); | |
72 | void isBackgroundVisible(); |
|
72 | void isBackgroundVisible(); | |
73 | void legend_data(); |
|
73 | void legend_data(); | |
74 | void legend(); |
|
74 | void legend(); | |
75 | void margins_data(); |
|
75 | void margins_data(); | |
76 | void margins(); |
|
76 | void margins(); | |
77 | void removeAllSeries_data(); |
|
77 | void removeAllSeries_data(); | |
78 | void removeAllSeries(); |
|
78 | void removeAllSeries(); | |
79 | void removeSeries_data(); |
|
79 | void removeSeries_data(); | |
80 | void removeSeries(); |
|
80 | void removeSeries(); | |
81 | void scroll_right_data(); |
|
81 | void scroll_right_data(); | |
82 | void scroll_right(); |
|
82 | void scroll_right(); | |
83 | void scroll_left_data(); |
|
83 | void scroll_left_data(); | |
84 | void scroll_left(); |
|
84 | void scroll_left(); | |
85 | void scroll_up_data(); |
|
85 | void scroll_up_data(); | |
86 | void scroll_up(); |
|
86 | void scroll_up(); | |
87 | void scroll_down_data(); |
|
87 | void scroll_down_data(); | |
88 | void scroll_down(); |
|
88 | void scroll_down(); | |
89 | void theme_data(); |
|
89 | void theme_data(); | |
90 | void theme(); |
|
90 | void theme(); | |
91 | void title_data(); |
|
91 | void title_data(); | |
92 | void title(); |
|
92 | void title(); | |
93 | void titleBrush_data(); |
|
93 | void titleBrush_data(); | |
94 | void titleBrush(); |
|
94 | void titleBrush(); | |
95 | void titleFont_data(); |
|
95 | void titleFont_data(); | |
96 | void titleFont(); |
|
96 | void titleFont(); | |
97 | void zoomIn_data(); |
|
97 | void zoomIn_data(); | |
98 | void zoomIn(); |
|
98 | void zoomIn(); | |
99 | void zoomOut_data(); |
|
99 | void zoomOut_data(); | |
100 | void zoomOut(); |
|
100 | void zoomOut(); | |
101 |
|
101 | |||
102 | private: |
|
102 | private: | |
103 | void createTestData(); |
|
103 | void createTestData(); | |
104 |
|
104 | |||
105 | private: |
|
105 | private: | |
106 | QChartView* m_view; |
|
106 | QChartView* m_view; | |
107 | QChart* m_chart; |
|
107 | QChart* m_chart; | |
108 | }; |
|
108 | }; | |
109 |
|
109 | |||
110 | void tst_QChart::initTestCase() |
|
110 | void tst_QChart::initTestCase() | |
111 | { |
|
111 | { | |
112 |
|
112 | |||
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void tst_QChart::cleanupTestCase() |
|
115 | void tst_QChart::cleanupTestCase() | |
116 | { |
|
116 | { | |
117 |
|
117 | |||
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void tst_QChart::init() |
|
120 | void tst_QChart::init() | |
121 | { |
|
121 | { | |
122 | m_view = new QChartView(new QChart()); |
|
122 | m_view = new QChartView(new QChart()); | |
123 | m_chart = m_view->chart(); |
|
123 | m_chart = m_view->chart(); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void tst_QChart::cleanup() |
|
126 | void tst_QChart::cleanup() | |
127 | { |
|
127 | { | |
128 | delete m_view; |
|
128 | delete m_view; | |
129 | m_view = 0; |
|
129 | m_view = 0; | |
130 | m_chart = 0; |
|
130 | m_chart = 0; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 |
|
133 | |||
134 | void tst_QChart::createTestData() |
|
134 | void tst_QChart::createTestData() | |
135 | { |
|
135 | { | |
136 | QLineSeries* series0 = new QLineSeries(this); |
|
136 | QLineSeries* series0 = new QLineSeries(this); | |
137 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
137 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
138 | m_chart->addSeries(series0); |
|
138 | m_chart->addSeries(series0); | |
139 | m_view->show(); |
|
139 | m_view->show(); | |
140 | QTest::qWaitForWindowShown(m_view); |
|
140 | QTest::qWaitForWindowShown(m_view); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void tst_QChart::qchart_data() |
|
143 | void tst_QChart::qchart_data() | |
144 | { |
|
144 | { | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void tst_QChart::qchart() |
|
147 | void tst_QChart::qchart() | |
148 | { |
|
148 | { | |
149 | QVERIFY(m_chart); |
|
149 | QVERIFY(m_chart); | |
150 | QVERIFY(m_chart->legend()); |
|
150 | QVERIFY(m_chart->legend()); | |
151 | QVERIFY(m_chart->legend()->isVisible()); |
|
151 | QVERIFY(m_chart->legend()->isVisible()); | |
152 |
|
152 | |||
153 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
153 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
154 | QVERIFY(!m_chart->axisX()); |
|
154 | QVERIFY(!m_chart->axisX()); | |
155 | QVERIFY(!m_chart->axisY()); |
|
155 | QVERIFY(!m_chart->axisY()); | |
156 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
156 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
157 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
157 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
158 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
158 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
159 |
|
159 | |||
160 | QVERIFY(m_chart->margins().top()>0); |
|
160 | QVERIFY(m_chart->margins().top()>0); | |
161 | QVERIFY(m_chart->margins().left()>0); |
|
161 | QVERIFY(m_chart->margins().left()>0); | |
162 | QVERIFY(m_chart->margins().right()>0); |
|
162 | QVERIFY(m_chart->margins().right()>0); | |
163 | QVERIFY(m_chart->margins().bottom()>0); |
|
163 | QVERIFY(m_chart->margins().bottom()>0); | |
164 |
|
164 | |||
165 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
165 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
166 | QCOMPARE(m_chart->title(), QString()); |
|
166 | QCOMPARE(m_chart->title(), QString()); | |
167 |
|
167 | |||
168 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
168 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
169 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
169 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
170 |
|
170 | |||
171 | m_chart->removeAllSeries(); |
|
171 | m_chart->removeAllSeries(); | |
172 | m_chart->scroll(0,0); |
|
172 | m_chart->scroll(0,0); | |
173 |
|
173 | |||
174 | m_chart->zoomIn(); |
|
174 | m_chart->zoomIn(); | |
175 | m_chart->zoomIn(QRectF()); |
|
175 | m_chart->zoomIn(QRectF()); | |
176 | m_chart->zoomOut(); |
|
176 | m_chart->zoomOut(); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void tst_QChart::addSeries_data() |
|
179 | void tst_QChart::addSeries_data() | |
180 | { |
|
180 | { | |
181 | QTest::addColumn<QAbstractSeries *>("series"); |
|
181 | QTest::addColumn<QAbstractSeries *>("series"); | |
182 |
|
182 | |||
183 | QAbstractSeries* line = new QLineSeries(this); |
|
183 | QAbstractSeries* line = new QLineSeries(this); | |
184 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
184 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
185 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
185 | QAbstractSeries* scatter = new QScatterSeries(this); | |
186 | QAbstractSeries* spline = new QSplineSeries(this); |
|
186 | QAbstractSeries* spline = new QSplineSeries(this); | |
187 | QAbstractSeries* pie = new QPieSeries(this); |
|
187 | QAbstractSeries* pie = new QPieSeries(this); | |
188 | QAbstractSeries* bar = new QBarSeries(this); |
|
188 | QAbstractSeries* bar = new QBarSeries(this); | |
189 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
189 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
190 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
190 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
191 |
|
191 | |||
192 | QTest::newRow("lineSeries") << line; |
|
192 | QTest::newRow("lineSeries") << line; | |
193 | QTest::newRow("areaSeries") << area; |
|
193 | QTest::newRow("areaSeries") << area; | |
194 | QTest::newRow("scatterSeries") << scatter; |
|
194 | QTest::newRow("scatterSeries") << scatter; | |
195 | QTest::newRow("splineSeries") << spline; |
|
195 | QTest::newRow("splineSeries") << spline; | |
196 | QTest::newRow("pieSeries") << pie; |
|
196 | QTest::newRow("pieSeries") << pie; | |
197 | QTest::newRow("barSeries") << bar; |
|
197 | QTest::newRow("barSeries") << bar; | |
198 | QTest::newRow("percentBarSeries") << percent; |
|
198 | QTest::newRow("percentBarSeries") << percent; | |
199 | QTest::newRow("stackedBarSeries") << stacked; |
|
199 | QTest::newRow("stackedBarSeries") << stacked; | |
200 |
|
200 | |||
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void tst_QChart::addSeries() |
|
203 | void tst_QChart::addSeries() | |
204 | { |
|
204 | { | |
205 | QFETCH(QAbstractSeries *, series); |
|
205 | QFETCH(QAbstractSeries *, series); | |
206 | m_view->show(); |
|
206 | m_view->show(); | |
207 | QTest::qWaitForWindowShown(m_view); |
|
207 | QTest::qWaitForWindowShown(m_view); | |
208 | QVERIFY(!series->chart()); |
|
208 | QVERIFY(!series->chart()); | |
209 | QCOMPARE(m_chart->series().count(), 0); |
|
209 | QCOMPARE(m_chart->series().count(), 0); | |
210 | m_chart->addSeries(series); |
|
210 | m_chart->addSeries(series); | |
211 | QCOMPARE(m_chart->series().count(), 1); |
|
211 | QCOMPARE(m_chart->series().count(), 1); | |
212 | QCOMPARE(m_chart->series().first(), series); |
|
212 | QCOMPARE(m_chart->series().first(), series); | |
213 | QVERIFY(series->chart() == m_chart); |
|
213 | QVERIFY(series->chart() == m_chart); | |
214 | m_chart->createDefaultAxes(); |
|
214 | m_chart->createDefaultAxes(); | |
215 | if(series->type()!=QAbstractSeries::SeriesTypePie){ |
|
215 | if(series->type()!=QAbstractSeries::SeriesTypePie){ | |
216 | QVERIFY(m_chart->axisY(series)); |
|
216 | QVERIFY(m_chart->axisY(series)); | |
217 | QVERIFY(m_chart->axisX(series)); |
|
217 | QVERIFY(m_chart->axisX(series)); | |
218 | }else{ |
|
218 | }else{ | |
219 | QVERIFY(!m_chart->axisY(series)); |
|
219 | QVERIFY(!m_chart->axisY(series)); | |
220 | QVERIFY(!m_chart->axisX(series)); |
|
220 | QVERIFY(!m_chart->axisX(series)); | |
221 | } |
|
221 | } | |
222 | m_chart->removeSeries(series); |
|
222 | m_chart->removeSeries(series); | |
223 | QVERIFY(!series->chart()); |
|
223 | QVERIFY(!series->chart()); | |
224 | QCOMPARE(m_chart->series().count(), 0); |
|
224 | QCOMPARE(m_chart->series().count(), 0); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void tst_QChart::animationOptions_data() |
|
227 | void tst_QChart::animationOptions_data() | |
228 | { |
|
228 | { | |
229 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
229 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
230 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
230 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
231 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
231 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
232 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
232 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
233 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
233 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void tst_QChart::animationOptions() |
|
236 | void tst_QChart::animationOptions() | |
237 | { |
|
237 | { | |
238 | createTestData(); |
|
238 | createTestData(); | |
239 | QFETCH(QChart::AnimationOption, animationOptions); |
|
239 | QFETCH(QChart::AnimationOption, animationOptions); | |
240 | m_chart->setAnimationOptions(animationOptions); |
|
240 | m_chart->setAnimationOptions(animationOptions); | |
241 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
241 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | void tst_QChart::axisX_data() |
|
244 | void tst_QChart::axisX_data() | |
245 | { |
|
245 | { | |
246 |
|
246 | |||
247 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
247 | QTest::addColumn<QAbstractAxis*>("axis"); | |
248 | QTest::addColumn<QAbstractSeries *>("series"); |
|
248 | QTest::addColumn<QAbstractSeries *>("series"); | |
249 |
|
249 | |||
250 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
250 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QLineSeries(this); | |
251 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
251 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | |
252 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
252 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QScatterSeries(this); | |
253 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
253 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QSplineSeries(this); | |
254 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
254 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPieSeries(this); | |
255 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
255 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QBarSeries(this); | |
256 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
256 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | |
257 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
257 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | |
258 |
|
258 | |||
259 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
259 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); | |
260 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
260 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | |
261 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
261 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); | |
262 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
262 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); | |
263 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
263 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); | |
264 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
264 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); | |
265 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
265 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | |
266 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
266 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | |
267 |
|
267 | |||
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | void tst_QChart::axisX() |
|
270 | void tst_QChart::axisX() | |
271 | { |
|
271 | { | |
272 | QFETCH(QAbstractAxis*, axis); |
|
272 | QFETCH(QAbstractAxis*, axis); | |
273 | QFETCH(QAbstractSeries*, series); |
|
273 | QFETCH(QAbstractSeries*, series); | |
274 | QVERIFY(!m_chart->axisX()); |
|
274 | QVERIFY(!m_chart->axisX()); | |
275 | m_view->show(); |
|
275 | m_view->show(); | |
276 | QTest::qWaitForWindowShown(m_view); |
|
276 | QTest::qWaitForWindowShown(m_view); | |
277 | m_chart->addSeries(series); |
|
277 | m_chart->addSeries(series); | |
278 | m_chart->setAxisX(axis,series); |
|
278 | m_chart->setAxisX(axis,series); | |
279 | QVERIFY(m_chart->axisX(series)==axis); |
|
279 | QVERIFY(m_chart->axisX(series)==axis); | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void tst_QChart::axisY_data() |
|
282 | void tst_QChart::axisY_data() | |
283 | { |
|
283 | { | |
284 | axisX_data(); |
|
284 | axisX_data(); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 |
|
287 | |||
288 | void tst_QChart::axisY() |
|
288 | void tst_QChart::axisY() | |
289 | { |
|
289 | { | |
290 | QFETCH(QAbstractAxis*, axis); |
|
290 | QFETCH(QAbstractAxis*, axis); | |
291 | QFETCH(QAbstractSeries*, series); |
|
291 | QFETCH(QAbstractSeries*, series); | |
292 | QVERIFY(!m_chart->axisY()); |
|
292 | QVERIFY(!m_chart->axisY()); | |
293 | m_view->show(); |
|
293 | m_view->show(); | |
294 | QTest::qWaitForWindowShown(m_view); |
|
294 | QTest::qWaitForWindowShown(m_view); | |
295 | m_chart->addSeries(series); |
|
295 | m_chart->addSeries(series); | |
296 | m_chart->setAxisY(axis,series); |
|
296 | m_chart->setAxisY(axis,series); | |
297 | QVERIFY(m_chart->axisY(series)==axis); |
|
297 | QVERIFY(m_chart->axisY(series)==axis); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void tst_QChart::backgroundBrush_data() |
|
300 | void tst_QChart::backgroundBrush_data() | |
301 | { |
|
301 | { | |
302 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
302 | QTest::addColumn<QBrush>("backgroundBrush"); | |
303 | QTest::newRow("null") << QBrush(); |
|
303 | QTest::newRow("null") << QBrush(); | |
304 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
304 | QTest::newRow("blue") << QBrush(Qt::blue); | |
305 | QTest::newRow("white") << QBrush(Qt::white); |
|
305 | QTest::newRow("white") << QBrush(Qt::white); | |
306 | QTest::newRow("black") << QBrush(Qt::black); |
|
306 | QTest::newRow("black") << QBrush(Qt::black); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void tst_QChart::backgroundBrush() |
|
309 | void tst_QChart::backgroundBrush() | |
310 | { |
|
310 | { | |
311 | QFETCH(QBrush, backgroundBrush); |
|
311 | QFETCH(QBrush, backgroundBrush); | |
312 | m_chart->setBackgroundBrush(backgroundBrush); |
|
312 | m_chart->setBackgroundBrush(backgroundBrush); | |
313 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
313 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void tst_QChart::backgroundPen_data() |
|
316 | void tst_QChart::backgroundPen_data() | |
317 | { |
|
317 | { | |
318 | QTest::addColumn<QPen>("backgroundPen"); |
|
318 | QTest::addColumn<QPen>("backgroundPen"); | |
319 | QTest::newRow("null") << QPen(); |
|
319 | QTest::newRow("null") << QPen(); | |
320 | QTest::newRow("blue") << QPen(Qt::blue); |
|
320 | QTest::newRow("blue") << QPen(Qt::blue); | |
321 | QTest::newRow("white") << QPen(Qt::white); |
|
321 | QTest::newRow("white") << QPen(Qt::white); | |
322 | QTest::newRow("black") << QPen(Qt::black); |
|
322 | QTest::newRow("black") << QPen(Qt::black); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 |
|
325 | |||
326 | void tst_QChart::backgroundPen() |
|
326 | void tst_QChart::backgroundPen() | |
327 | { |
|
327 | { | |
328 | QFETCH(QPen, backgroundPen); |
|
328 | QFETCH(QPen, backgroundPen); | |
329 | m_chart->setBackgroundPen(backgroundPen); |
|
329 | m_chart->setBackgroundPen(backgroundPen); | |
330 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
330 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void tst_QChart::isBackgroundVisible_data() |
|
333 | void tst_QChart::isBackgroundVisible_data() | |
334 | { |
|
334 | { | |
335 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
335 | QTest::addColumn<bool>("isBackgroundVisible"); | |
336 | QTest::newRow("true") << true; |
|
336 | QTest::newRow("true") << true; | |
337 | QTest::newRow("false") << false; |
|
337 | QTest::newRow("false") << false; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void tst_QChart::isBackgroundVisible() |
|
340 | void tst_QChart::isBackgroundVisible() | |
341 | { |
|
341 | { | |
342 | QFETCH(bool, isBackgroundVisible); |
|
342 | QFETCH(bool, isBackgroundVisible); | |
343 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
343 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
344 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
344 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void tst_QChart::legend_data() |
|
347 | void tst_QChart::legend_data() | |
348 | { |
|
348 | { | |
349 |
|
349 | |||
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void tst_QChart::legend() |
|
352 | void tst_QChart::legend() | |
353 | { |
|
353 | { | |
354 | QLegend *legend = m_chart->legend(); |
|
354 | QLegend *legend = m_chart->legend(); | |
355 | QVERIFY(legend); |
|
355 | QVERIFY(legend); | |
356 |
|
356 | |||
357 | // Colors related signals |
|
357 | // Colors related signals | |
358 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
358 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | |
359 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
359 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | |
360 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
360 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | |
361 |
|
361 | |||
362 | // colorChanged |
|
362 | // colorChanged | |
363 | legend->setColor(QColor("aliceblue")); |
|
363 | legend->setColor(QColor("aliceblue")); | |
364 | QCOMPARE(colorSpy.count(), 1); |
|
364 | QCOMPARE(colorSpy.count(), 1); | |
365 | QBrush b = legend->brush(); |
|
365 | QBrush b = legend->brush(); | |
366 | b.setColor(QColor("aqua")); |
|
366 | b.setColor(QColor("aqua")); | |
367 | legend->setBrush(b); |
|
367 | legend->setBrush(b); | |
368 | QCOMPARE(colorSpy.count(), 2); |
|
368 | QCOMPARE(colorSpy.count(), 2); | |
369 |
|
369 | |||
370 | // borderColorChanged |
|
370 | // borderColorChanged | |
371 | legend->setBorderColor(QColor("aliceblue")); |
|
371 | legend->setBorderColor(QColor("aliceblue")); | |
372 | QCOMPARE(borderColorSpy.count(), 1); |
|
372 | QCOMPARE(borderColorSpy.count(), 1); | |
373 | QPen p = legend->pen(); |
|
373 | QPen p = legend->pen(); | |
374 | p.setColor(QColor("aqua")); |
|
374 | p.setColor(QColor("aqua")); | |
375 | legend->setPen(p); |
|
375 | legend->setPen(p); | |
376 | QCOMPARE(borderColorSpy.count(), 2); |
|
376 | QCOMPARE(borderColorSpy.count(), 2); | |
377 |
|
377 | |||
378 | // labelColorChanged |
|
378 | // labelColorChanged | |
379 | legend->setLabelColor(QColor("lightsalmon")); |
|
379 | legend->setLabelColor(QColor("lightsalmon")); | |
380 | QCOMPARE(labelColorSpy.count(), 1); |
|
380 | QCOMPARE(labelColorSpy.count(), 1); | |
381 | b = legend->labelBrush(); |
|
381 | b = legend->labelBrush(); | |
382 | b.setColor(QColor("lightseagreen")); |
|
382 | b.setColor(QColor("lightseagreen")); | |
383 | legend->setLabelBrush(b); |
|
383 | legend->setLabelBrush(b); | |
384 | QCOMPARE(labelColorSpy.count(), 2); |
|
384 | QCOMPARE(labelColorSpy.count(), 2); | |
385 |
|
385 | |||
386 | // fontChanged |
|
386 | // fontChanged | |
387 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
387 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | |
388 | QFont f = legend->font(); |
|
388 | QFont f = legend->font(); | |
389 | f.setBold(!f.bold()); |
|
389 | f.setBold(!f.bold()); | |
390 | legend->setFont(f); |
|
390 | legend->setFont(f); | |
391 | QCOMPARE(fontSpy.count(), 1); |
|
391 | QCOMPARE(fontSpy.count(), 1); | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | void tst_QChart::margins_data() |
|
394 | void tst_QChart::margins_data() | |
395 | { |
|
395 | { | |
396 |
|
396 | |||
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | void tst_QChart::margins() |
|
399 | void tst_QChart::margins() | |
400 | { |
|
400 | { | |
401 | createTestData(); |
|
401 | createTestData(); | |
402 | QRectF rect = m_chart->geometry(); |
|
402 | QRectF rect = m_chart->geometry(); | |
403 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
403 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
404 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
404 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | void tst_QChart::removeAllSeries_data() |
|
407 | void tst_QChart::removeAllSeries_data() | |
408 | { |
|
408 | { | |
409 |
|
409 | |||
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | void tst_QChart::removeAllSeries() |
|
412 | void tst_QChart::removeAllSeries() | |
413 | { |
|
413 | { | |
414 | QLineSeries* series0 = new QLineSeries(this); |
|
414 | QLineSeries* series0 = new QLineSeries(this); | |
415 | QLineSeries* series1 = new QLineSeries(this); |
|
415 | QLineSeries* series1 = new QLineSeries(this); | |
416 | QLineSeries* series2 = new QLineSeries(this); |
|
416 | QLineSeries* series2 = new QLineSeries(this); | |
417 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
417 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
418 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
418 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
419 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
419 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
420 |
|
420 | |||
421 | m_chart->addSeries(series0); |
|
421 | m_chart->addSeries(series0); | |
422 | m_chart->addSeries(series1); |
|
422 | m_chart->addSeries(series1); | |
423 | m_chart->addSeries(series2); |
|
423 | m_chart->addSeries(series2); | |
424 | m_view->show(); |
|
424 | m_view->show(); | |
425 | QTest::qWaitForWindowShown(m_view); |
|
425 | QTest::qWaitForWindowShown(m_view); | |
426 | m_chart->createDefaultAxes(); |
|
426 | m_chart->createDefaultAxes(); | |
427 | QVERIFY(m_chart->axisY(series0)!=0); |
|
427 | QVERIFY(m_chart->axisY(series0)!=0); | |
428 | QVERIFY(m_chart->axisY(series1)!=0); |
|
428 | QVERIFY(m_chart->axisY(series1)!=0); | |
429 | QVERIFY(m_chart->axisY(series2)!=0); |
|
429 | QVERIFY(m_chart->axisY(series2)!=0); | |
430 |
|
430 | |||
431 | m_chart->removeAllSeries(); |
|
431 | m_chart->removeAllSeries(); | |
432 | QVERIFY(m_chart->axisY(series0)==0); |
|
432 | QVERIFY(m_chart->axisY(series0)==0); | |
433 | QVERIFY(m_chart->axisY(series1)==0); |
|
433 | QVERIFY(m_chart->axisY(series1)==0); | |
434 | QVERIFY(m_chart->axisY(series2)==0); |
|
434 | QVERIFY(m_chart->axisY(series2)==0); | |
435 | QCOMPARE(deleteSpy1.count(), 1); |
|
435 | QCOMPARE(deleteSpy1.count(), 1); | |
436 | QCOMPARE(deleteSpy2.count(), 1); |
|
436 | QCOMPARE(deleteSpy2.count(), 1); | |
437 | QCOMPARE(deleteSpy3.count(), 1); |
|
437 | QCOMPARE(deleteSpy3.count(), 1); | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | void tst_QChart::removeSeries_data() |
|
440 | void tst_QChart::removeSeries_data() | |
441 | { |
|
441 | { | |
442 | axisX_data(); |
|
442 | axisX_data(); | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | void tst_QChart::removeSeries() |
|
445 | void tst_QChart::removeSeries() | |
446 | { |
|
446 | { | |
447 | QFETCH(QAbstractAxis *, axis); |
|
447 | QFETCH(QAbstractAxis *, axis); | |
448 | QFETCH(QAbstractSeries *, series); |
|
448 | QFETCH(QAbstractSeries *, series); | |
449 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
449 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
450 | m_view->show(); |
|
450 | m_view->show(); | |
451 | QTest::qWaitForWindowShown(m_view); |
|
451 | QTest::qWaitForWindowShown(m_view); | |
452 | if(!axis) axis = m_chart->axisY(); |
|
452 | if(!axis) axis = m_chart->axisY(); | |
453 | m_chart->addSeries(series); |
|
453 | m_chart->addSeries(series); | |
454 | m_chart->setAxisY(axis,series); |
|
454 | m_chart->setAxisY(axis,series); | |
455 | QCOMPARE(m_chart->axisY(series),axis); |
|
455 | QCOMPARE(m_chart->axisY(series),axis); | |
456 | m_chart->removeSeries(series); |
|
456 | m_chart->removeSeries(series); | |
457 | QVERIFY(m_chart->axisY(series)==0); |
|
457 | QVERIFY(m_chart->axisY(series)==0); | |
458 | QCOMPARE(deleteSpy.count(), 0); |
|
458 | QCOMPARE(deleteSpy.count(), 0); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | void tst_QChart::scroll_right_data() |
|
461 | void tst_QChart::scroll_right_data() | |
462 | { |
|
462 | { | |
463 | QTest::addColumn<QAbstractSeries *>("series"); |
|
463 | QTest::addColumn<QAbstractSeries *>("series"); | |
464 |
|
464 | |||
465 | QLineSeries* series0 = new QLineSeries(this); |
|
465 | QLineSeries* series0 = new QLineSeries(this); | |
466 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
466 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
467 |
|
467 | |||
468 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; |
|
468 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; | |
469 |
|
469 | |||
470 |
|
470 | |||
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | void tst_QChart::scroll_right() |
|
473 | void tst_QChart::scroll_right() | |
474 | { |
|
474 | { | |
475 | QFETCH(QAbstractSeries *, series); |
|
475 | QFETCH(QAbstractSeries *, series); | |
476 | m_chart->addSeries(series); |
|
476 | m_chart->addSeries(series); | |
477 | m_chart->createDefaultAxes(); |
|
477 | m_chart->createDefaultAxes(); | |
478 | m_view->show(); |
|
478 | m_view->show(); | |
479 | QTest::qWaitForWindowShown(m_view); |
|
479 | QTest::qWaitForWindowShown(m_view); | |
480 | QAbstractAxis * axis = m_chart->axisX(); |
|
480 | QAbstractAxis * axis = m_chart->axisX(); | |
481 | QVERIFY(axis!=0); |
|
481 | QVERIFY(axis!=0); | |
482 |
|
482 | |||
483 | switch(axis->type()) |
|
483 | switch(axis->type()) | |
484 | { |
|
484 | { | |
485 | case QAbstractAxis::AxisTypeValues:{ |
|
485 | case QAbstractAxis::AxisTypeValues:{ | |
486 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
486 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
487 | QVERIFY(vaxis!=0); |
|
487 | QVERIFY(vaxis!=0); | |
488 | qreal min = vaxis->min(); |
|
488 | qreal min = vaxis->min(); | |
489 | qreal max = vaxis->max(); |
|
489 | qreal max = vaxis->max(); | |
490 | QVERIFY(max>min); |
|
490 | QVERIFY(max>min); | |
491 | m_chart->scroll(50, 0); |
|
491 | m_chart->scroll(50, 0); | |
492 | QVERIFY(min<vaxis->min()); |
|
492 | QVERIFY(min<vaxis->min()); | |
493 | QVERIFY(max<vaxis->max()); |
|
493 | QVERIFY(max<vaxis->max()); | |
494 | break; |
|
494 | break; | |
495 | } |
|
495 | } | |
496 | case QAbstractAxis::AxisTypeCategories:{ |
|
496 | case QAbstractAxis::AxisTypeCategories:{ | |
497 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
497 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); | |
498 | QVERIFY(caxis!=0); |
|
498 | QVERIFY(caxis!=0); | |
499 | qreal min = caxis->min().toDouble(); |
|
499 | qreal min = caxis->min().toDouble(); | |
500 | qreal max = caxis->max().toDouble(); |
|
500 | qreal max = caxis->max().toDouble(); | |
501 | m_chart->scroll(50, 0); |
|
501 | m_chart->scroll(50, 0); | |
502 | QVERIFY(min<caxis->min().toDouble()); |
|
502 | QVERIFY(min<caxis->min().toDouble()); | |
503 | QVERIFY(max<caxis->max().toDouble()); |
|
503 | QVERIFY(max<caxis->max().toDouble()); | |
504 | break; |
|
504 | break; | |
505 | } |
|
505 | } | |
506 | default: |
|
506 | default: | |
507 | qFatal("Unsupported type"); |
|
507 | qFatal("Unsupported type"); | |
508 | break; |
|
508 | break; | |
509 | } |
|
509 | } | |
510 | } |
|
510 | } | |
511 |
|
511 | |||
512 | void tst_QChart::scroll_left_data() |
|
512 | void tst_QChart::scroll_left_data() | |
513 | { |
|
513 | { | |
514 | scroll_right_data(); |
|
514 | scroll_right_data(); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | void tst_QChart::scroll_left() |
|
517 | void tst_QChart::scroll_left() | |
518 | { |
|
518 | { | |
519 | QFETCH(QAbstractSeries *, series); |
|
519 | QFETCH(QAbstractSeries *, series); | |
520 | m_chart->addSeries(series); |
|
520 | m_chart->addSeries(series); | |
521 | m_chart->createDefaultAxes(); |
|
521 | m_chart->createDefaultAxes(); | |
522 | m_view->show(); |
|
522 | m_view->show(); | |
523 | QTest::qWaitForWindowShown(m_view); |
|
523 | QTest::qWaitForWindowShown(m_view); | |
524 | QAbstractAxis * axis = m_chart->axisX(); |
|
524 | QAbstractAxis * axis = m_chart->axisX(); | |
525 | QVERIFY(axis!=0); |
|
525 | QVERIFY(axis!=0); | |
526 |
|
526 | |||
527 | switch(axis->type()) |
|
527 | switch(axis->type()) | |
528 | { |
|
528 | { | |
529 | case QAbstractAxis::AxisTypeValues:{ |
|
529 | case QAbstractAxis::AxisTypeValues:{ | |
530 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
530 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
531 | QVERIFY(vaxis!=0); |
|
531 | QVERIFY(vaxis!=0); | |
532 | qreal min = vaxis->min(); |
|
532 | qreal min = vaxis->min(); | |
533 | qreal max = vaxis->max(); |
|
533 | qreal max = vaxis->max(); | |
534 | m_chart->scroll(-50, 0); |
|
534 | m_chart->scroll(-50, 0); | |
535 | QVERIFY(min>vaxis->min()); |
|
535 | QVERIFY(min>vaxis->min()); | |
536 | QVERIFY(max>vaxis->max()); |
|
536 | QVERIFY(max>vaxis->max()); | |
537 | break; |
|
537 | break; | |
538 | } |
|
538 | } | |
539 | case QAbstractAxis::AxisTypeCategories:{ |
|
539 | case QAbstractAxis::AxisTypeCategories:{ | |
540 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
540 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); | |
541 | QVERIFY(caxis!=0); |
|
541 | QVERIFY(caxis!=0); | |
542 | qreal min = caxis->min().toDouble(); |
|
542 | qreal min = caxis->min().toDouble(); | |
543 | qreal max = caxis->max().toDouble(); |
|
543 | qreal max = caxis->max().toDouble(); | |
544 | m_chart->scroll(-50, 0); |
|
544 | m_chart->scroll(-50, 0); | |
545 | QVERIFY(min>caxis->min().toDouble()); |
|
545 | QVERIFY(min>caxis->min().toDouble()); | |
546 | QVERIFY(max>caxis->max().toDouble()); |
|
546 | QVERIFY(max>caxis->max().toDouble()); | |
547 | break; |
|
547 | break; | |
548 | } |
|
548 | } | |
549 | default: |
|
549 | default: | |
550 | qFatal("Unsupported type"); |
|
550 | qFatal("Unsupported type"); | |
551 | break; |
|
551 | break; | |
552 | } |
|
552 | } | |
553 | } |
|
553 | } | |
554 |
|
554 | |||
555 | void tst_QChart::scroll_up_data() |
|
555 | void tst_QChart::scroll_up_data() | |
556 | { |
|
556 | { | |
557 | scroll_right_data(); |
|
557 | scroll_right_data(); | |
558 | } |
|
558 | } | |
559 |
|
559 | |||
560 | void tst_QChart::scroll_up() |
|
560 | void tst_QChart::scroll_up() | |
561 | { |
|
561 | { | |
562 | QFETCH(QAbstractSeries *, series); |
|
562 | QFETCH(QAbstractSeries *, series); | |
563 | m_chart->addSeries(series); |
|
563 | m_chart->addSeries(series); | |
564 | m_chart->createDefaultAxes(); |
|
564 | m_chart->createDefaultAxes(); | |
565 | m_view->show(); |
|
565 | m_view->show(); | |
566 | QTest::qWaitForWindowShown(m_view); |
|
566 | QTest::qWaitForWindowShown(m_view); | |
567 | QAbstractAxis * axis = m_chart->axisY(); |
|
567 | QAbstractAxis * axis = m_chart->axisY(); | |
568 | QVERIFY(axis!=0); |
|
568 | QVERIFY(axis!=0); | |
569 |
|
569 | |||
570 | switch(axis->type()) |
|
570 | switch(axis->type()) | |
571 | { |
|
571 | { | |
572 | case QAbstractAxis::AxisTypeValues:{ |
|
572 | case QAbstractAxis::AxisTypeValues:{ | |
573 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
573 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
574 | QVERIFY(vaxis!=0); |
|
574 | QVERIFY(vaxis!=0); | |
575 | qreal min = vaxis->min(); |
|
575 | qreal min = vaxis->min(); | |
576 | qreal max = vaxis->max(); |
|
576 | qreal max = vaxis->max(); | |
577 | m_chart->scroll(0, 50); |
|
577 | m_chart->scroll(0, 50); | |
578 | QVERIFY(min<vaxis->min()); |
|
578 | QVERIFY(min<vaxis->min()); | |
579 | QVERIFY(max<vaxis->max()); |
|
579 | QVERIFY(max<vaxis->max()); | |
580 | break; |
|
580 | break; | |
581 | } |
|
581 | } | |
582 | case QAbstractAxis::AxisTypeCategories:{ |
|
582 | case QAbstractAxis::AxisTypeCategories:{ | |
583 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
583 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); | |
584 | QVERIFY(caxis!=0); |
|
584 | QVERIFY(caxis!=0); | |
585 | qreal min = caxis->min().toDouble(); |
|
585 | qreal min = caxis->min().toDouble(); | |
586 | qreal max = caxis->max().toDouble(); |
|
586 | qreal max = caxis->max().toDouble(); | |
587 | m_chart->scroll(0, 50); |
|
587 | m_chart->scroll(0, 50); | |
588 | QVERIFY(min<caxis->min().toDouble()); |
|
588 | QVERIFY(min<caxis->min().toDouble()); | |
589 | QVERIFY(max<caxis->max().toDouble()); |
|
589 | QVERIFY(max<caxis->max().toDouble()); | |
590 | break; |
|
590 | break; | |
591 | } |
|
591 | } | |
592 | default: |
|
592 | default: | |
593 | qFatal("Unsupported type"); |
|
593 | qFatal("Unsupported type"); | |
594 | break; |
|
594 | break; | |
595 | } |
|
595 | } | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 | void tst_QChart::scroll_down_data() |
|
598 | void tst_QChart::scroll_down_data() | |
599 | { |
|
599 | { | |
600 | scroll_right_data(); |
|
600 | scroll_right_data(); | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 | void tst_QChart::scroll_down() |
|
603 | void tst_QChart::scroll_down() | |
604 | { |
|
604 | { | |
605 | QFETCH(QAbstractSeries *, series); |
|
605 | QFETCH(QAbstractSeries *, series); | |
606 | m_chart->addSeries(series); |
|
606 | m_chart->addSeries(series); | |
607 | m_chart->createDefaultAxes(); |
|
607 | m_chart->createDefaultAxes(); | |
608 | m_view->show(); |
|
608 | m_view->show(); | |
609 | QTest::qWaitForWindowShown(m_view); |
|
609 | QTest::qWaitForWindowShown(m_view); | |
610 | QAbstractAxis * axis = m_chart->axisY(); |
|
610 | QAbstractAxis * axis = m_chart->axisY(); | |
611 | QVERIFY(axis!=0); |
|
611 | QVERIFY(axis!=0); | |
612 |
|
612 | |||
613 | switch(axis->type()) |
|
613 | switch(axis->type()) | |
614 | { |
|
614 | { | |
615 | case QAbstractAxis::AxisTypeValues:{ |
|
615 | case QAbstractAxis::AxisTypeValues:{ | |
616 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
616 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
617 | QVERIFY(vaxis!=0); |
|
617 | QVERIFY(vaxis!=0); | |
618 | qreal min = vaxis->min(); |
|
618 | qreal min = vaxis->min(); | |
619 | qreal max = vaxis->max(); |
|
619 | qreal max = vaxis->max(); | |
620 | m_chart->scroll(0, -50); |
|
620 | m_chart->scroll(0, -50); | |
621 | QVERIFY(min>vaxis->min()); |
|
621 | QVERIFY(min>vaxis->min()); | |
622 | QVERIFY(max>vaxis->max()); |
|
622 | QVERIFY(max>vaxis->max()); | |
623 | break; |
|
623 | break; | |
624 | } |
|
624 | } | |
625 | case QAbstractAxis::AxisTypeCategories:{ |
|
625 | case QAbstractAxis::AxisTypeCategories:{ | |
626 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); |
|
626 | QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis); | |
627 | QVERIFY(caxis!=0); |
|
627 | QVERIFY(caxis!=0); | |
628 | qreal min = caxis->min().toDouble(); |
|
628 | qreal min = caxis->min().toDouble(); | |
629 | qreal max = caxis->max().toDouble(); |
|
629 | qreal max = caxis->max().toDouble(); | |
630 | m_chart->scroll(0, -50); |
|
630 | m_chart->scroll(0, -50); | |
631 | QVERIFY(min>caxis->min().toDouble()); |
|
631 | QVERIFY(min>caxis->min().toDouble()); | |
632 | QVERIFY(max>caxis->max().toDouble()); |
|
632 | QVERIFY(max>caxis->max().toDouble()); | |
633 | break; |
|
633 | break; | |
634 | } |
|
634 | } | |
635 | default: |
|
635 | default: | |
636 | qFatal("Unsupported type"); |
|
636 | qFatal("Unsupported type"); | |
637 | break; |
|
637 | break; | |
638 | } |
|
638 | } | |
639 | } |
|
639 | } | |
640 |
|
640 | |||
641 | void tst_QChart::theme_data() |
|
641 | void tst_QChart::theme_data() | |
642 | { |
|
642 | { | |
643 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
643 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
644 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
644 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
645 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
645 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
646 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
646 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
647 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
647 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
648 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
648 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
649 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
649 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
650 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
650 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
651 | } |
|
651 | } | |
652 |
|
652 | |||
653 | void tst_QChart::theme() |
|
653 | void tst_QChart::theme() | |
654 | { |
|
654 | { | |
655 | QFETCH(QChart::ChartTheme, theme); |
|
655 | QFETCH(QChart::ChartTheme, theme); | |
656 | createTestData(); |
|
656 | createTestData(); | |
657 | m_chart->setTheme(theme); |
|
657 | m_chart->setTheme(theme); | |
658 | QVERIFY(m_chart->theme()==theme); |
|
658 | QVERIFY(m_chart->theme()==theme); | |
659 | } |
|
659 | } | |
660 |
|
660 | |||
661 | void tst_QChart::title_data() |
|
661 | void tst_QChart::title_data() | |
662 | { |
|
662 | { | |
663 | QTest::addColumn<QString>("title"); |
|
663 | QTest::addColumn<QString>("title"); | |
664 | QTest::newRow("null") << QString(); |
|
664 | QTest::newRow("null") << QString(); | |
665 | QTest::newRow("foo") << QString("foo"); |
|
665 | QTest::newRow("foo") << QString("foo"); | |
666 | } |
|
666 | } | |
667 |
|
667 | |||
668 | void tst_QChart::title() |
|
668 | void tst_QChart::title() | |
669 | { |
|
669 | { | |
670 | QFETCH(QString, title); |
|
670 | QFETCH(QString, title); | |
671 | m_chart->setTitle(title); |
|
671 | m_chart->setTitle(title); | |
672 | QCOMPARE(m_chart->title(), title); |
|
672 | QCOMPARE(m_chart->title(), title); | |
673 | } |
|
673 | } | |
674 |
|
674 | |||
675 | void tst_QChart::titleBrush_data() |
|
675 | void tst_QChart::titleBrush_data() | |
676 | { |
|
676 | { | |
677 | QTest::addColumn<QBrush>("titleBrush"); |
|
677 | QTest::addColumn<QBrush>("titleBrush"); | |
678 | QTest::newRow("null") << QBrush(); |
|
678 | QTest::newRow("null") << QBrush(); | |
679 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
679 | QTest::newRow("blue") << QBrush(Qt::blue); | |
680 | QTest::newRow("white") << QBrush(Qt::white); |
|
680 | QTest::newRow("white") << QBrush(Qt::white); | |
681 | QTest::newRow("black") << QBrush(Qt::black); |
|
681 | QTest::newRow("black") << QBrush(Qt::black); | |
682 | } |
|
682 | } | |
683 |
|
683 | |||
684 | void tst_QChart::titleBrush() |
|
684 | void tst_QChart::titleBrush() | |
685 | { |
|
685 | { | |
686 | QFETCH(QBrush, titleBrush); |
|
686 | QFETCH(QBrush, titleBrush); | |
687 | m_chart->setTitleBrush(titleBrush); |
|
687 | m_chart->setTitleBrush(titleBrush); | |
688 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
688 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
689 | } |
|
689 | } | |
690 |
|
690 | |||
691 | void tst_QChart::titleFont_data() |
|
691 | void tst_QChart::titleFont_data() | |
692 | { |
|
692 | { | |
693 | QTest::addColumn<QFont>("titleFont"); |
|
693 | QTest::addColumn<QFont>("titleFont"); | |
694 | QTest::newRow("null") << QFont(); |
|
694 | QTest::newRow("null") << QFont(); | |
695 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
695 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
696 | } |
|
696 | } | |
697 |
|
697 | |||
698 | void tst_QChart::titleFont() |
|
698 | void tst_QChart::titleFont() | |
699 | { |
|
699 | { | |
700 | QFETCH(QFont, titleFont); |
|
700 | QFETCH(QFont, titleFont); | |
701 | m_chart->setTitleFont(titleFont); |
|
701 | m_chart->setTitleFont(titleFont); | |
702 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
702 | QCOMPARE(m_chart->titleFont(), titleFont); | |
703 | } |
|
703 | } | |
704 |
|
704 | |||
705 | void tst_QChart::zoomIn_data() |
|
705 | void tst_QChart::zoomIn_data() | |
706 | { |
|
706 | { | |
707 | QTest::addColumn<QRectF>("rect"); |
|
707 | QTest::addColumn<QRectF>("rect"); | |
708 | QTest::newRow("null") << QRectF(); |
|
708 | QTest::newRow("null") << QRectF(); | |
709 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
709 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
710 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
710 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
711 | } |
|
711 | } | |
712 |
|
712 | |||
713 |
|
713 | |||
714 | void tst_QChart::zoomIn() |
|
714 | void tst_QChart::zoomIn() | |
715 | { |
|
715 | { | |
716 |
|
716 | |||
717 | QFETCH(QRectF, rect); |
|
717 | QFETCH(QRectF, rect); | |
718 | createTestData(); |
|
718 | createTestData(); | |
719 | m_chart->createDefaultAxes(); |
|
719 | m_chart->createDefaultAxes(); | |
720 | QRectF marigns = m_chart->margins(); |
|
720 | QRectF marigns = m_chart->margins(); | |
721 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
721 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
722 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
722 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | |
723 | QVERIFY(axisX!=0); |
|
723 | QVERIFY(axisX!=0); | |
724 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
724 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | |
725 | QVERIFY(axisY!=0); |
|
725 | QVERIFY(axisY!=0); | |
726 | qreal minX = axisX->min(); |
|
726 | qreal minX = axisX->min(); | |
727 | qreal minY = axisY->min(); |
|
727 | qreal minY = axisY->min(); | |
728 | qreal maxX = axisX->max(); |
|
728 | qreal maxX = axisX->max(); | |
729 | qreal maxY = axisY->max(); |
|
729 | qreal maxY = axisY->max(); | |
730 | m_chart->zoomIn(rect); |
|
730 | m_chart->zoomIn(rect); | |
731 | if(rect.isValid()){ |
|
731 | if(rect.isValid()){ | |
732 | QVERIFY(minX<axisX->min()); |
|
732 | QVERIFY(minX<axisX->min()); | |
733 | QVERIFY(maxX>axisX->max()); |
|
733 | QVERIFY(maxX>axisX->max()); | |
734 | QVERIFY(minY<axisY->min()); |
|
734 | QVERIFY(minY<axisY->min()); | |
735 | QVERIFY(maxY>axisY->max()); |
|
735 | QVERIFY(maxY>axisY->max()); | |
736 | } |
|
736 | } | |
737 |
|
737 | |||
738 | } |
|
738 | } | |
739 |
|
739 | |||
740 | void tst_QChart::zoomOut_data() |
|
740 | void tst_QChart::zoomOut_data() | |
741 | { |
|
741 | { | |
742 |
|
742 | |||
743 | } |
|
743 | } | |
744 |
|
744 | |||
745 | void tst_QChart::zoomOut() |
|
745 | void tst_QChart::zoomOut() | |
746 | { |
|
746 | { | |
747 | createTestData(); |
|
747 | createTestData(); | |
748 | m_chart->createDefaultAxes(); |
|
748 | m_chart->createDefaultAxes(); | |
749 |
|
749 | |||
750 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
750 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | |
751 | QVERIFY(axisX!=0); |
|
751 | QVERIFY(axisX!=0); | |
752 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
752 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | |
753 | QVERIFY(axisY!=0); |
|
753 | QVERIFY(axisY!=0); | |
754 |
|
754 | |||
755 | qreal minX = axisX->min(); |
|
755 | qreal minX = axisX->min(); | |
756 | qreal minY = axisY->min(); |
|
756 | qreal minY = axisY->min(); | |
757 | qreal maxX = axisX->max(); |
|
757 | qreal maxX = axisX->max(); | |
758 | qreal maxY = axisY->max(); |
|
758 | qreal maxY = axisY->max(); | |
759 |
|
759 | |||
760 | m_chart->zoomIn(); |
|
760 | m_chart->zoomIn(); | |
761 |
|
761 | |||
762 | QVERIFY(minX < axisX->min()); |
|
762 | QVERIFY(minX < axisX->min()); | |
763 | QVERIFY(maxX > axisX->max()); |
|
763 | QVERIFY(maxX > axisX->max()); | |
764 | QVERIFY(minY < axisY->min()); |
|
764 | QVERIFY(minY < axisY->min()); | |
765 | QVERIFY(maxY > axisY->max()); |
|
765 | QVERIFY(maxY > axisY->max()); | |
766 |
|
766 | |||
767 | m_chart->zoomOut(); |
|
767 | m_chart->zoomOut(); | |
768 |
|
768 | |||
769 | // min x may be a zero value |
|
769 | // min x may be a zero value | |
770 | if (qFuzzyIsNull(minX)) |
|
770 | if (qFuzzyIsNull(minX)) | |
771 | QVERIFY(qFuzzyIsNull(axisX->min())); |
|
771 | QVERIFY(qFuzzyIsNull(axisX->min())); | |
772 | else |
|
772 | else | |
773 | QCOMPARE(minX, axisX->min()); |
|
773 | QCOMPARE(minX, axisX->min()); | |
774 |
|
774 | |||
775 | // min y may be a zero value |
|
775 | // min y may be a zero value | |
776 | if (qFuzzyIsNull(minY)) |
|
776 | if (qFuzzyIsNull(minY)) | |
777 | QVERIFY(qFuzzyIsNull(axisY->min())); |
|
777 | QVERIFY(qFuzzyIsNull(axisY->min())); | |
778 | else |
|
778 | else | |
779 | QCOMPARE(minY, axisY->min()); |
|
779 | QCOMPARE(minY, axisY->min()); | |
780 |
|
780 | |||
781 | QVERIFY(maxX == axisX->max()); |
|
781 | QVERIFY(maxX == axisX->max()); | |
782 | QVERIFY(maxY == axisY->max()); |
|
782 | QVERIFY(maxY == axisY->max()); | |
783 |
|
783 | |||
784 | } |
|
784 | } | |
785 |
|
785 | |||
786 | QTEST_MAIN(tst_QChart) |
|
786 | QTEST_MAIN(tst_QChart) | |
787 | #include "tst_qchart.moc" |
|
787 | #include "tst_qchart.moc" | |
788 |
|
788 |
@@ -1,183 +1,183 | |||||
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 <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <cmath> |
|
24 | #include <cmath> | |
25 | #include <tst_definitions.h> |
|
25 | #include <tst_definitions.h> | |
26 |
#include <qvalue |
|
26 | #include <qvalueaxis.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | Q_DECLARE_METATYPE(QChart*) |
|
31 | Q_DECLARE_METATYPE(QChart*) | |
32 | Q_DECLARE_METATYPE(QChartView::RubberBands) |
|
32 | Q_DECLARE_METATYPE(QChartView::RubberBands) | |
33 | Q_DECLARE_METATYPE(Qt::Key) |
|
33 | Q_DECLARE_METATYPE(Qt::Key) | |
34 |
|
34 | |||
35 | class tst_QChartView : public QObject |
|
35 | class tst_QChartView : public QObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 |
|
38 | |||
39 | public Q_SLOTS: |
|
39 | public Q_SLOTS: | |
40 | void initTestCase(); |
|
40 | void initTestCase(); | |
41 | void cleanupTestCase(); |
|
41 | void cleanupTestCase(); | |
42 | void init(); |
|
42 | void init(); | |
43 | void cleanup(); |
|
43 | void cleanup(); | |
44 |
|
44 | |||
45 | private Q_SLOTS: |
|
45 | private Q_SLOTS: | |
46 | void qchartview_data(); |
|
46 | void qchartview_data(); | |
47 | void qchartview(); |
|
47 | void qchartview(); | |
48 | void chart_data(); |
|
48 | void chart_data(); | |
49 | void chart(); |
|
49 | void chart(); | |
50 | void rubberBand_data(); |
|
50 | void rubberBand_data(); | |
51 | void rubberBand(); |
|
51 | void rubberBand(); | |
52 |
|
52 | |||
53 | private: |
|
53 | private: | |
54 | QChartView* m_view; |
|
54 | QChartView* m_view; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | void tst_QChartView::initTestCase() |
|
57 | void tst_QChartView::initTestCase() | |
58 | { |
|
58 | { | |
59 | //test tracks mouse, give a while to user to relese it |
|
59 | //test tracks mouse, give a while to user to relese it | |
60 | QTest::qWait(1000); |
|
60 | QTest::qWait(1000); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void tst_QChartView::cleanupTestCase() |
|
63 | void tst_QChartView::cleanupTestCase() | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void tst_QChartView::init() |
|
67 | void tst_QChartView::init() | |
68 | { |
|
68 | { | |
69 | m_view = new QChartView(new QChart()); |
|
69 | m_view = new QChartView(new QChart()); | |
70 | m_view->chart()->legend()->setVisible(false); |
|
70 | m_view->chart()->legend()->setVisible(false); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void tst_QChartView::cleanup() |
|
73 | void tst_QChartView::cleanup() | |
74 | { |
|
74 | { | |
75 | delete m_view; |
|
75 | delete m_view; | |
76 | m_view =0; |
|
76 | m_view =0; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void tst_QChartView::qchartview_data() |
|
79 | void tst_QChartView::qchartview_data() | |
80 | { |
|
80 | { | |
81 |
|
81 | |||
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void tst_QChartView::qchartview() |
|
84 | void tst_QChartView::qchartview() | |
85 | { |
|
85 | { | |
86 | QVERIFY(m_view->chart()); |
|
86 | QVERIFY(m_view->chart()); | |
87 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
87 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); | |
88 | m_view->show(); |
|
88 | m_view->show(); | |
89 | QTest::qWaitForWindowShown(m_view); |
|
89 | QTest::qWaitForWindowShown(m_view); | |
90 |
|
90 | |||
91 | delete(new QChartView()); |
|
91 | delete(new QChartView()); | |
92 |
|
92 | |||
93 | QChartView view; |
|
93 | QChartView view; | |
94 | QVERIFY(view.chart()); |
|
94 | QVERIFY(view.chart()); | |
95 |
|
95 | |||
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_QChartView::chart_data() |
|
98 | void tst_QChartView::chart_data() | |
99 | { |
|
99 | { | |
100 |
|
100 | |||
101 | QTest::addColumn<QChart*>("chart"); |
|
101 | QTest::addColumn<QChart*>("chart"); | |
102 | QTest::newRow("qchart") << new QChart(); |
|
102 | QTest::newRow("qchart") << new QChart(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void tst_QChartView::chart() |
|
105 | void tst_QChartView::chart() | |
106 | { |
|
106 | { | |
107 | QFETCH(QChart*, chart); |
|
107 | QFETCH(QChart*, chart); | |
108 | QChartView* view = new QChartView(chart); |
|
108 | QChartView* view = new QChartView(chart); | |
109 | QCOMPARE(view->chart(), chart); |
|
109 | QCOMPARE(view->chart(), chart); | |
110 | delete view; |
|
110 | delete view; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void tst_QChartView::rubberBand_data() |
|
113 | void tst_QChartView::rubberBand_data() | |
114 | { |
|
114 | { | |
115 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
115 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); | |
116 | QTest::addColumn<int>("Xcount"); |
|
116 | QTest::addColumn<int>("Xcount"); | |
117 | QTest::addColumn<int>("Ycount"); |
|
117 | QTest::addColumn<int>("Ycount"); | |
118 |
|
118 | |||
119 | QTest::addColumn<int>("minX"); |
|
119 | QTest::addColumn<int>("minX"); | |
120 | QTest::addColumn<int>("maxX"); |
|
120 | QTest::addColumn<int>("maxX"); | |
121 | QTest::addColumn<int>("minY"); |
|
121 | QTest::addColumn<int>("minY"); | |
122 | QTest::addColumn<int>("maxY"); |
|
122 | QTest::addColumn<int>("maxY"); | |
123 |
|
123 | |||
124 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; |
|
124 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; | |
125 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; |
|
125 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; | |
126 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; |
|
126 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void tst_QChartView::rubberBand() |
|
129 | void tst_QChartView::rubberBand() | |
130 | { |
|
130 | { | |
131 | QFETCH(QChartView::RubberBands, rubberBand); |
|
131 | QFETCH(QChartView::RubberBands, rubberBand); | |
132 | QFETCH(int, Xcount); |
|
132 | QFETCH(int, Xcount); | |
133 | QFETCH(int, Ycount); |
|
133 | QFETCH(int, Ycount); | |
134 | QFETCH(int, minX); |
|
134 | QFETCH(int, minX); | |
135 | QFETCH(int, maxX); |
|
135 | QFETCH(int, maxX); | |
136 | QFETCH(int, minY); |
|
136 | QFETCH(int, minY); | |
137 | QFETCH(int, maxY); |
|
137 | QFETCH(int, maxY); | |
138 |
|
138 | |||
139 | m_view->setRubberBand(rubberBand); |
|
139 | m_view->setRubberBand(rubberBand); | |
140 | QRectF padding = m_view->chart()->margins(); |
|
140 | QRectF padding = m_view->chart()->margins(); | |
141 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
141 | QCOMPARE(m_view->rubberBand(), rubberBand); | |
142 |
|
142 | |||
143 | QLineSeries* line = new QLineSeries(); |
|
143 | QLineSeries* line = new QLineSeries(); | |
144 | *line << QPointF(0, 0) << QPointF(200, 200); |
|
144 | *line << QPointF(0, 0) << QPointF(200, 200); | |
145 |
|
145 | |||
146 | m_view->chart()->addSeries(line); |
|
146 | m_view->chart()->addSeries(line); | |
147 | m_view->chart()->createDefaultAxes(); |
|
147 | m_view->chart()->createDefaultAxes(); | |
148 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); |
|
148 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); | |
149 | m_view->show(); |
|
149 | m_view->show(); | |
150 |
|
150 | |||
151 | //this is hack since view does not get events otherwise |
|
151 | //this is hack since view does not get events otherwise | |
152 | m_view->setMouseTracking(true); |
|
152 | m_view->setMouseTracking(true); | |
153 |
|
153 | |||
154 | QAbstractAxis* axisY = m_view->chart()->axisY(); |
|
154 | QAbstractAxis* axisY = m_view->chart()->axisY(); | |
155 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
155 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); | |
156 | QAbstractAxis* axisX = m_view->chart()->axisX(); |
|
156 | QAbstractAxis* axisX = m_view->chart()->axisX(); | |
157 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
157 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); | |
158 |
|
158 | |||
159 | QTest::qWaitForWindowShown(m_view); |
|
159 | QTest::qWaitForWindowShown(m_view); | |
160 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
160 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); | |
161 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
161 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); | |
162 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
162 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); | |
163 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
163 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); | |
164 |
|
164 | |||
165 | TRY_COMPARE(spy0.count(), Xcount); |
|
165 | TRY_COMPARE(spy0.count(), Xcount); | |
166 | TRY_COMPARE(spy1.count(), Ycount); |
|
166 | TRY_COMPARE(spy1.count(), Ycount); | |
167 |
|
167 | |||
168 | //this is hack since view does not get events otherwise |
|
168 | //this is hack since view does not get events otherwise | |
169 | m_view->setMouseTracking(false); |
|
169 | m_view->setMouseTracking(false); | |
170 |
|
170 | |||
171 | QValueAxis* vaxisX = qobject_cast<QValueAxis*>(axisX); |
|
171 | QValueAxis* vaxisX = qobject_cast<QValueAxis*>(axisX); | |
172 | QValueAxis* vaxisY = qobject_cast<QValueAxis*>(axisY); |
|
172 | QValueAxis* vaxisY = qobject_cast<QValueAxis*>(axisY); | |
173 |
|
173 | |||
174 | QVERIFY(vaxisX->min() - minX < 1); |
|
174 | QVERIFY(vaxisX->min() - minX < 1); | |
175 | QVERIFY(vaxisX->max() - maxX < 1); |
|
175 | QVERIFY(vaxisX->max() - maxX < 1); | |
176 | QVERIFY(vaxisY->min() - minY < 1); |
|
176 | QVERIFY(vaxisY->min() - minY < 1); | |
177 | QVERIFY(vaxisY->max() - maxY < 1); |
|
177 | QVERIFY(vaxisY->max() - maxY < 1); | |
178 |
|
178 | |||
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | QTEST_MAIN(tst_QChartView) |
|
181 | QTEST_MAIN(tst_QChartView) | |
182 | #include "tst_qchartview.moc" |
|
182 | #include "tst_qchartview.moc" | |
183 |
|
183 |
@@ -1,5 +1,5 | |||||
1 | !include( ../auto.pri ) { |
|
1 | !include( ../auto.pri ) { | |
2 | error( "Couldn't find the auto.pri file!" ) |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
3 | } |
|
3 | } | |
4 | HEADERS += ../qabstractaxis/tst_qabstractaxis.h |
|
4 | HEADERS += ../qabstractaxis/tst_qabstractaxis.h | |
5 |
SOURCES += tst_qvalue |
|
5 | SOURCES += tst_qvalueaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp |
@@ -1,415 +1,415 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "../qabstractaxis/tst_qabstractaxis.h" |
|
21 | #include "../qabstractaxis/tst_qabstractaxis.h" | |
22 |
#include "qvalue |
|
22 | #include "qvalueaxis.h" | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 |
|
24 | |||
25 | class tst_QValueAxis: public tst_QAbstractAxis |
|
25 | class tst_QValueAxis: public tst_QAbstractAxis | |
26 | { |
|
26 | { | |
27 | Q_OBJECT |
|
27 | Q_OBJECT | |
28 |
|
28 | |||
29 | public slots: |
|
29 | public slots: | |
30 | void initTestCase(); |
|
30 | void initTestCase(); | |
31 | void cleanupTestCase(); |
|
31 | void cleanupTestCase(); | |
32 | void init(); |
|
32 | void init(); | |
33 | void cleanup(); |
|
33 | void cleanup(); | |
34 |
|
34 | |||
35 | private slots: |
|
35 | private slots: | |
36 |
void qvalue |
|
36 | void qvalueaxis_data(); | |
37 |
void qvalue |
|
37 | void qvalueaxis(); | |
38 | void max_raw_data(); |
|
38 | void max_raw_data(); | |
39 | void max_raw(); |
|
39 | void max_raw(); | |
40 | void max_data(); |
|
40 | void max_data(); | |
41 | void max(); |
|
41 | void max(); | |
42 | void max_animation_data(); |
|
42 | void max_animation_data(); | |
43 | void max_animation(); |
|
43 | void max_animation(); | |
44 | void min_raw_data(); |
|
44 | void min_raw_data(); | |
45 | void min_raw(); |
|
45 | void min_raw(); | |
46 | void min_data(); |
|
46 | void min_data(); | |
47 | void min(); |
|
47 | void min(); | |
48 | void min_animation_data(); |
|
48 | void min_animation_data(); | |
49 | void min_animation(); |
|
49 | void min_animation(); | |
50 | void niceNumbersEnabled_data(); |
|
50 | void niceNumbersEnabled_data(); | |
51 | void niceNumbersEnabled(); |
|
51 | void niceNumbersEnabled(); | |
52 | void range_raw_data(); |
|
52 | void range_raw_data(); | |
53 | void range_raw(); |
|
53 | void range_raw(); | |
54 | void range_data(); |
|
54 | void range_data(); | |
55 | void range(); |
|
55 | void range(); | |
56 | void range_animation_data(); |
|
56 | void range_animation_data(); | |
57 | void range_animation(); |
|
57 | void range_animation(); | |
58 | void ticksCount_data(); |
|
58 | void ticksCount_data(); | |
59 | void ticksCount(); |
|
59 | void ticksCount(); | |
60 | void noautoscale_data(); |
|
60 | void noautoscale_data(); | |
61 | void noautoscale(); |
|
61 | void noautoscale(); | |
62 | void autoscale_data(); |
|
62 | void autoscale_data(); | |
63 | void autoscale(); |
|
63 | void autoscale(); | |
64 |
|
64 | |||
65 | private: |
|
65 | private: | |
66 | QValueAxis* m_valuesaxis; |
|
66 | QValueAxis* m_valuesaxis; | |
67 | QLineSeries* m_series; |
|
67 | QLineSeries* m_series; | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | void tst_QValueAxis::initTestCase() |
|
70 | void tst_QValueAxis::initTestCase() | |
71 | { |
|
71 | { | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void tst_QValueAxis::cleanupTestCase() |
|
74 | void tst_QValueAxis::cleanupTestCase() | |
75 | { |
|
75 | { | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void tst_QValueAxis::init() |
|
78 | void tst_QValueAxis::init() | |
79 | { |
|
79 | { | |
80 | m_valuesaxis = new QValueAxis(); |
|
80 | m_valuesaxis = new QValueAxis(); | |
81 | m_series = new QLineSeries(); |
|
81 | m_series = new QLineSeries(); | |
82 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); |
|
82 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | |
83 | tst_QAbstractAxis::init(m_valuesaxis,m_series); |
|
83 | tst_QAbstractAxis::init(m_valuesaxis,m_series); | |
84 | m_chart->addSeries(m_series); |
|
84 | m_chart->addSeries(m_series); | |
85 | m_chart->createDefaultAxes(); |
|
85 | m_chart->createDefaultAxes(); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void tst_QValueAxis::cleanup() |
|
88 | void tst_QValueAxis::cleanup() | |
89 | { |
|
89 | { | |
90 | delete m_series; |
|
90 | delete m_series; | |
91 | delete m_valuesaxis; |
|
91 | delete m_valuesaxis; | |
92 | m_series = 0; |
|
92 | m_series = 0; | |
93 | m_valuesaxis = 0; |
|
93 | m_valuesaxis = 0; | |
94 | tst_QAbstractAxis::cleanup(); |
|
94 | tst_QAbstractAxis::cleanup(); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 |
void tst_QValueAxis::qvalue |
|
97 | void tst_QValueAxis::qvalueaxis_data() | |
98 | { |
|
98 | { | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 |
void tst_QValueAxis::qvalue |
|
101 | void tst_QValueAxis::qvalueaxis() | |
102 | { |
|
102 | { | |
103 | qabstractaxis(); |
|
103 | qabstractaxis(); | |
104 |
|
104 | |||
105 | QVERIFY(qFuzzyIsNull(m_valuesaxis->max())); |
|
105 | QVERIFY(qFuzzyIsNull(m_valuesaxis->max())); | |
106 | QVERIFY(qFuzzyIsNull(m_valuesaxis->min())); |
|
106 | QVERIFY(qFuzzyIsNull(m_valuesaxis->min())); | |
107 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); |
|
107 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); | |
108 | QCOMPARE(m_valuesaxis->ticksCount(), 5); |
|
108 | QCOMPARE(m_valuesaxis->ticksCount(), 5); | |
109 | QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues); |
|
109 | QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues); | |
110 |
|
110 | |||
111 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
111 | m_chart->setAxisX(m_valuesaxis, m_series); | |
112 | m_view->show(); |
|
112 | m_view->show(); | |
113 | QTest::qWaitForWindowShown(m_view); |
|
113 | QTest::qWaitForWindowShown(m_view); | |
114 |
|
114 | |||
115 | QVERIFY(!qFuzzyIsNull(m_valuesaxis->max())); |
|
115 | QVERIFY(!qFuzzyIsNull(m_valuesaxis->max())); | |
116 | QVERIFY(!qFuzzyIsNull(m_valuesaxis->min())); |
|
116 | QVERIFY(!qFuzzyIsNull(m_valuesaxis->min())); | |
117 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); |
|
117 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); | |
118 | QCOMPARE(m_valuesaxis->ticksCount(), 5); |
|
118 | QCOMPARE(m_valuesaxis->ticksCount(), 5); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void tst_QValueAxis::max_raw_data() |
|
121 | void tst_QValueAxis::max_raw_data() | |
122 | { |
|
122 | { | |
123 | QTest::addColumn<qreal>("max"); |
|
123 | QTest::addColumn<qreal>("max"); | |
124 | QTest::newRow("1.0") << 1.0; |
|
124 | QTest::newRow("1.0") << 1.0; | |
125 | QTest::newRow("50.0") << 50.0; |
|
125 | QTest::newRow("50.0") << 50.0; | |
126 | QTest::newRow("101.0") << 101.0; |
|
126 | QTest::newRow("101.0") << 101.0; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void tst_QValueAxis::max_raw() |
|
129 | void tst_QValueAxis::max_raw() | |
130 | { |
|
130 | { | |
131 | QFETCH(qreal, max); |
|
131 | QFETCH(qreal, max); | |
132 |
|
132 | |||
133 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
133 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
134 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
134 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
135 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
135 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
136 |
|
136 | |||
137 | m_valuesaxis->setMax(max); |
|
137 | m_valuesaxis->setMax(max); | |
138 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal"); |
|
138 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal"); | |
139 |
|
139 | |||
140 | QCOMPARE(spy0.count(), 1); |
|
140 | QCOMPARE(spy0.count(), 1); | |
141 | QCOMPARE(spy1.count(), 0); |
|
141 | QCOMPARE(spy1.count(), 0); | |
142 | QCOMPARE(spy2.count(), 1); |
|
142 | QCOMPARE(spy2.count(), 1); | |
143 |
|
143 | |||
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void tst_QValueAxis::max_data() |
|
146 | void tst_QValueAxis::max_data() | |
147 | { |
|
147 | { | |
148 | max_raw_data(); |
|
148 | max_raw_data(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void tst_QValueAxis::max() |
|
151 | void tst_QValueAxis::max() | |
152 | { |
|
152 | { | |
153 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
153 | m_chart->setAxisX(m_valuesaxis, m_series); | |
154 | m_view->show(); |
|
154 | m_view->show(); | |
155 | QTest::qWaitForWindowShown(m_view); |
|
155 | QTest::qWaitForWindowShown(m_view); | |
156 | max_raw(); |
|
156 | max_raw(); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | void tst_QValueAxis::max_animation_data() |
|
159 | void tst_QValueAxis::max_animation_data() | |
160 | { |
|
160 | { | |
161 | max_data(); |
|
161 | max_data(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void tst_QValueAxis::max_animation() |
|
164 | void tst_QValueAxis::max_animation() | |
165 | { |
|
165 | { | |
166 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
166 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
167 | max(); |
|
167 | max(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void tst_QValueAxis::min_raw_data() |
|
170 | void tst_QValueAxis::min_raw_data() | |
171 | { |
|
171 | { | |
172 | QTest::addColumn<qreal>("min"); |
|
172 | QTest::addColumn<qreal>("min"); | |
173 | QTest::newRow("-1.0") << -1.0; |
|
173 | QTest::newRow("-1.0") << -1.0; | |
174 | QTest::newRow("-50.0") << -50.0; |
|
174 | QTest::newRow("-50.0") << -50.0; | |
175 | QTest::newRow("-101.0") << -101.0; |
|
175 | QTest::newRow("-101.0") << -101.0; | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | void tst_QValueAxis::min_raw() |
|
178 | void tst_QValueAxis::min_raw() | |
179 | { |
|
179 | { | |
180 | QFETCH(qreal, min); |
|
180 | QFETCH(qreal, min); | |
181 |
|
181 | |||
182 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
182 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
183 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
183 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
184 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
184 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
185 |
|
185 | |||
186 | m_valuesaxis->setMin(min); |
|
186 | m_valuesaxis->setMin(min); | |
187 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal"); |
|
187 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal"); | |
188 |
|
188 | |||
189 | QCOMPARE(spy0.count(), 0); |
|
189 | QCOMPARE(spy0.count(), 0); | |
190 | QCOMPARE(spy1.count(), 1); |
|
190 | QCOMPARE(spy1.count(), 1); | |
191 | QCOMPARE(spy2.count(), 1); |
|
191 | QCOMPARE(spy2.count(), 1); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void tst_QValueAxis::min_data() |
|
194 | void tst_QValueAxis::min_data() | |
195 | { |
|
195 | { | |
196 | min_raw_data(); |
|
196 | min_raw_data(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void tst_QValueAxis::min() |
|
199 | void tst_QValueAxis::min() | |
200 | { |
|
200 | { | |
201 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
201 | m_chart->setAxisX(m_valuesaxis, m_series); | |
202 | m_view->show(); |
|
202 | m_view->show(); | |
203 | QTest::qWaitForWindowShown(m_view); |
|
203 | QTest::qWaitForWindowShown(m_view); | |
204 | min_raw(); |
|
204 | min_raw(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void tst_QValueAxis::min_animation_data() |
|
207 | void tst_QValueAxis::min_animation_data() | |
208 | { |
|
208 | { | |
209 | min_data(); |
|
209 | min_data(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void tst_QValueAxis::min_animation() |
|
212 | void tst_QValueAxis::min_animation() | |
213 | { |
|
213 | { | |
214 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
214 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
215 | min(); |
|
215 | min(); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | void tst_QValueAxis::niceNumbersEnabled_data() |
|
218 | void tst_QValueAxis::niceNumbersEnabled_data() | |
219 | { |
|
219 | { | |
220 | QTest::addColumn<bool>("niceNumbersEnabled"); |
|
220 | QTest::addColumn<bool>("niceNumbersEnabled"); | |
221 | QTest::addColumn<qreal>("min"); |
|
221 | QTest::addColumn<qreal>("min"); | |
222 | QTest::addColumn<qreal>("max"); |
|
222 | QTest::addColumn<qreal>("max"); | |
223 | QTest::addColumn<int>("ticks"); |
|
223 | QTest::addColumn<int>("ticks"); | |
224 | QTest::addColumn<qreal>("expectedMin"); |
|
224 | QTest::addColumn<qreal>("expectedMin"); | |
225 | QTest::addColumn<qreal>("expectedMax"); |
|
225 | QTest::addColumn<qreal>("expectedMax"); | |
226 | QTest::addColumn<int>("expectedTicks"); |
|
226 | QTest::addColumn<int>("expectedTicks"); | |
227 | QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6; |
|
227 | QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6; | |
228 | QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6; |
|
228 | QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6; | |
229 | QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5; |
|
229 | QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5; | |
230 | QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5; |
|
230 | QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5; | |
231 | QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6; |
|
231 | QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6; | |
232 | QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6; |
|
232 | QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void tst_QValueAxis::niceNumbersEnabled() |
|
235 | void tst_QValueAxis::niceNumbersEnabled() | |
236 | { |
|
236 | { | |
237 | QFETCH(bool, niceNumbersEnabled); |
|
237 | QFETCH(bool, niceNumbersEnabled); | |
238 | QFETCH(qreal, min); |
|
238 | QFETCH(qreal, min); | |
239 | QFETCH(qreal, max); |
|
239 | QFETCH(qreal, max); | |
240 | QFETCH(int, ticks); |
|
240 | QFETCH(int, ticks); | |
241 | QFETCH(qreal, expectedMin); |
|
241 | QFETCH(qreal, expectedMin); | |
242 | QFETCH(qreal, expectedMax); |
|
242 | QFETCH(qreal, expectedMax); | |
243 | QFETCH(int, expectedTicks); |
|
243 | QFETCH(int, expectedTicks); | |
244 |
|
244 | |||
245 | m_valuesaxis->setRange(min, max); |
|
245 | m_valuesaxis->setRange(min, max); | |
246 | m_valuesaxis->setTicksCount(ticks); |
|
246 | m_valuesaxis->setTicksCount(ticks); | |
247 |
|
247 | |||
248 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); |
|
248 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | |
249 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); |
|
249 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | |
250 |
|
250 | |||
251 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
251 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
252 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
252 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
253 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
253 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
254 |
|
254 | |||
255 | m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled); |
|
255 | m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled); | |
256 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled); |
|
256 | QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled); | |
257 |
|
257 | |||
258 | if(!qFuzzyIsNull(expectedMin - min)) |
|
258 | if(!qFuzzyIsNull(expectedMin - min)) | |
259 | QCOMPARE(spy1.count(), 1); |
|
259 | QCOMPARE(spy1.count(), 1); | |
260 | if(!qFuzzyIsNull(expectedMax - max)) |
|
260 | if(!qFuzzyIsNull(expectedMax - max)) | |
261 | QCOMPARE(spy0.count(), 1); |
|
261 | QCOMPARE(spy0.count(), 1); | |
262 | if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max))) |
|
262 | if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max))) | |
263 | QCOMPARE(spy2.count(), 1); |
|
263 | QCOMPARE(spy2.count(), 1); | |
264 |
|
264 | |||
265 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal"); |
|
265 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal"); | |
266 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal"); |
|
266 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal"); | |
267 | QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks); |
|
267 | QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks); | |
268 |
|
268 | |||
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | void tst_QValueAxis::range_raw_data() |
|
271 | void tst_QValueAxis::range_raw_data() | |
272 | { |
|
272 | { | |
273 | QTest::addColumn<qreal>("min"); |
|
273 | QTest::addColumn<qreal>("min"); | |
274 | QTest::addColumn<qreal>("max"); |
|
274 | QTest::addColumn<qreal>("max"); | |
275 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; |
|
275 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; | |
276 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; |
|
276 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; | |
277 | QTest::newRow("101.0") << 40.0 << 60.0; |
|
277 | QTest::newRow("101.0") << 40.0 << 60.0; | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | void tst_QValueAxis::range_raw() |
|
280 | void tst_QValueAxis::range_raw() | |
281 | { |
|
281 | { | |
282 | QFETCH(qreal, min); |
|
282 | QFETCH(qreal, min); | |
283 | QFETCH(qreal, max); |
|
283 | QFETCH(qreal, max); | |
284 |
|
284 | |||
285 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
285 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
286 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
286 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
287 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
287 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
288 |
|
288 | |||
289 | m_valuesaxis->setRange(min, max); |
|
289 | m_valuesaxis->setRange(min, max); | |
290 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); |
|
290 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | |
291 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); |
|
291 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | |
292 |
|
292 | |||
293 | QCOMPARE(spy0.count(), 1); |
|
293 | QCOMPARE(spy0.count(), 1); | |
294 | QCOMPARE(spy1.count(), 1); |
|
294 | QCOMPARE(spy1.count(), 1); | |
295 | QCOMPARE(spy2.count(), 1); |
|
295 | QCOMPARE(spy2.count(), 1); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | void tst_QValueAxis::range_data() |
|
298 | void tst_QValueAxis::range_data() | |
299 | { |
|
299 | { | |
300 | range_raw_data(); |
|
300 | range_raw_data(); | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | void tst_QValueAxis::range() |
|
303 | void tst_QValueAxis::range() | |
304 | { |
|
304 | { | |
305 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
305 | m_chart->setAxisX(m_valuesaxis, m_series); | |
306 | m_view->show(); |
|
306 | m_view->show(); | |
307 | QTest::qWaitForWindowShown(m_view); |
|
307 | QTest::qWaitForWindowShown(m_view); | |
308 | range_raw(); |
|
308 | range_raw(); | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | void tst_QValueAxis::range_animation_data() |
|
311 | void tst_QValueAxis::range_animation_data() | |
312 | { |
|
312 | { | |
313 | range_data(); |
|
313 | range_data(); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void tst_QValueAxis::range_animation() |
|
316 | void tst_QValueAxis::range_animation() | |
317 | { |
|
317 | { | |
318 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
318 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
319 | range(); |
|
319 | range(); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | void tst_QValueAxis::ticksCount_data() |
|
322 | void tst_QValueAxis::ticksCount_data() | |
323 | { |
|
323 | { | |
324 | QTest::addColumn<int>("ticksCount"); |
|
324 | QTest::addColumn<int>("ticksCount"); | |
325 | QTest::addColumn<int>("expectedCount"); |
|
325 | QTest::addColumn<int>("expectedCount"); | |
326 | QTest::newRow("0") << 2; |
|
326 | QTest::newRow("0") << 2; | |
327 | QTest::newRow("1") << 2; |
|
327 | QTest::newRow("1") << 2; | |
328 | QTest::newRow("2") << 2; |
|
328 | QTest::newRow("2") << 2; | |
329 | QTest::newRow("3") << 3; |
|
329 | QTest::newRow("3") << 3; | |
330 | QTest::newRow("-1") << 2; |
|
330 | QTest::newRow("-1") << 2; | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void tst_QValueAxis::ticksCount() |
|
333 | void tst_QValueAxis::ticksCount() | |
334 | { |
|
334 | { | |
335 | QFETCH(int, ticksCount); |
|
335 | QFETCH(int, ticksCount); | |
336 |
|
336 | |||
337 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
337 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
338 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
338 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
339 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
339 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
340 |
|
340 | |||
341 | m_valuesaxis->setTicksCount(ticksCount); |
|
341 | m_valuesaxis->setTicksCount(ticksCount); | |
342 | QCOMPARE(m_valuesaxis->ticksCount(), ticksCount); |
|
342 | QCOMPARE(m_valuesaxis->ticksCount(), ticksCount); | |
343 |
|
343 | |||
344 | QCOMPARE(spy0.count(), 0); |
|
344 | QCOMPARE(spy0.count(), 0); | |
345 | QCOMPARE(spy1.count(), 0); |
|
345 | QCOMPARE(spy1.count(), 0); | |
346 | QCOMPARE(spy2.count(), 0); |
|
346 | QCOMPARE(spy2.count(), 0); | |
347 |
|
347 | |||
348 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
348 | m_chart->setAxisX(m_valuesaxis, m_series); | |
349 | m_view->show(); |
|
349 | m_view->show(); | |
350 | QTest::qWaitForWindowShown(m_view); |
|
350 | QTest::qWaitForWindowShown(m_view); | |
351 |
|
351 | |||
352 | QCOMPARE(m_valuesaxis->ticksCount(), ticksCount); |
|
352 | QCOMPARE(m_valuesaxis->ticksCount(), ticksCount); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void tst_QValueAxis::noautoscale_data() |
|
355 | void tst_QValueAxis::noautoscale_data() | |
356 | { |
|
356 | { | |
357 | QTest::addColumn<qreal>("min"); |
|
357 | QTest::addColumn<qreal>("min"); | |
358 | QTest::addColumn<qreal>("max"); |
|
358 | QTest::addColumn<qreal>("max"); | |
359 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; |
|
359 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; | |
360 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; |
|
360 | QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; | |
361 | QTest::newRow("101.0") << 40.0 << 60.0; |
|
361 | QTest::newRow("101.0") << 40.0 << 60.0; | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void tst_QValueAxis::noautoscale() |
|
364 | void tst_QValueAxis::noautoscale() | |
365 | { |
|
365 | { | |
366 | QFETCH(qreal, min); |
|
366 | QFETCH(qreal, min); | |
367 | QFETCH(qreal, max); |
|
367 | QFETCH(qreal, max); | |
368 |
|
368 | |||
369 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
369 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
370 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
370 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
371 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
371 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
372 |
|
372 | |||
373 | m_valuesaxis->setRange(min, max); |
|
373 | m_valuesaxis->setRange(min, max); | |
374 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); |
|
374 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | |
375 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); |
|
375 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | |
376 |
|
376 | |||
377 | QCOMPARE(spy0.count(), 1); |
|
377 | QCOMPARE(spy0.count(), 1); | |
378 | QCOMPARE(spy1.count(), 1); |
|
378 | QCOMPARE(spy1.count(), 1); | |
379 | QCOMPARE(spy2.count(), 1); |
|
379 | QCOMPARE(spy2.count(), 1); | |
380 |
|
380 | |||
381 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
381 | m_chart->setAxisX(m_valuesaxis, m_series); | |
382 | m_view->show(); |
|
382 | m_view->show(); | |
383 | QTest::qWaitForWindowShown(m_view); |
|
383 | QTest::qWaitForWindowShown(m_view); | |
384 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); |
|
384 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | |
385 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); |
|
385 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void tst_QValueAxis::autoscale_data() |
|
388 | void tst_QValueAxis::autoscale_data() | |
389 | { |
|
389 | { | |
390 |
|
390 | |||
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void tst_QValueAxis::autoscale() |
|
393 | void tst_QValueAxis::autoscale() | |
394 | { |
|
394 | { | |
395 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); |
|
395 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | |
396 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); |
|
396 | QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | |
397 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); |
|
397 | QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | |
398 |
|
398 | |||
399 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal"); |
|
399 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal"); | |
400 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal"); |
|
400 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal"); | |
401 | m_chart->setAxisX(m_valuesaxis, m_series); |
|
401 | m_chart->setAxisX(m_valuesaxis, m_series); | |
402 |
|
402 | |||
403 | QCOMPARE(spy0.count(), 1); |
|
403 | QCOMPARE(spy0.count(), 1); | |
404 | QCOMPARE(spy1.count(), 1); |
|
404 | QCOMPARE(spy1.count(), 1); | |
405 | QCOMPARE(spy2.count(), 1); |
|
405 | QCOMPARE(spy2.count(), 1); | |
406 |
|
406 | |||
407 | m_view->show(); |
|
407 | m_view->show(); | |
408 | QTest::qWaitForWindowShown(m_view); |
|
408 | QTest::qWaitForWindowShown(m_view); | |
409 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal"); |
|
409 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal"); | |
410 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal"); |
|
410 | QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal"); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | QTEST_MAIN(tst_QValueAxis) |
|
413 | QTEST_MAIN(tst_QValueAxis) | |
414 |
#include "tst_qvalue |
|
414 | #include "tst_qvalueaxis.moc" | |
415 |
|
415 |
General Comments 0
You need to be logged in to leave comments.
Login now