@@ -1,70 +1,72 | |||||
1 | include($QT_INSTALL_DOCS/global/macros.qdocconf) |
|
1 | include($QT_INSTALL_DOCS/global/macros.qdocconf) | |
2 | include($QT_INSTALL_DOCS/global/qt-cpp-defines.qdocconf) |
|
2 | include($QT_INSTALL_DOCS/global/qt-cpp-defines.qdocconf) | |
3 | include($QT_INSTALL_DOCS/global/compat.qdocconf) |
|
3 | include($QT_INSTALL_DOCS/global/compat.qdocconf) | |
4 | include($QT_INSTALL_DOCS/global/fileextensions.qdocconf) |
|
4 | include($QT_INSTALL_DOCS/global/fileextensions.qdocconf) | |
5 | include($QT_INSTALL_DOCS/global/qt-html-templates-offline.qdocconf) |
|
5 | include($QT_INSTALL_DOCS/global/qt-html-templates-offline.qdocconf) | |
6 |
|
6 | |||
7 | project = QtCharts |
|
7 | project = QtCharts | |
8 | description = Qt Charts Reference Documentation |
|
8 | description = Qt Charts Reference Documentation | |
9 | version = 2.0.0 |
|
9 | version = 2.0.0 | |
10 |
|
10 | |||
11 | sourcedirs += .. \ |
|
11 | sourcedirs += .. \ | |
12 | ../../chartsqml2 |
|
12 | ../../chartsqml2 | |
13 | headerdirs += .. \ |
|
13 | headerdirs += .. \ | |
14 | ../../chartsqml2 |
|
14 | ../../chartsqml2 | |
15 | exampledirs += ../../../examples/charts \ |
|
15 | exampledirs += ../../../examples/charts \ | |
16 | snippets |
|
16 | snippets | |
17 | imagedirs += images |
|
17 | imagedirs += images | |
18 | examplesinstallpath = charts |
|
18 | examplesinstallpath = charts | |
19 |
|
19 | |||
20 | sources.fileextensions = "*.cpp *.qdoc" |
|
20 | sources.fileextensions = "*.cpp *.qdoc" | |
21 |
|
21 | |||
22 | indexes += $QT_INSTALL_DOCS/qtcore/qtcore.index \ |
|
22 | indexes += $QT_INSTALL_DOCS/qtcore/qtcore.index \ | |
23 | $QT_INSTALL_DOCS/qtgui/qtgui.index \ |
|
23 | $QT_INSTALL_DOCS/qtgui/qtgui.index \ | |
24 | $QT_INSTALL_DOCS/qtqml/qtqml.index \ |
|
24 | $QT_INSTALL_DOCS/qtqml/qtqml.index \ | |
25 | $QT_INSTALL_DOCS/qtquick/qtquick.index \ |
|
25 | $QT_INSTALL_DOCS/qtquick/qtquick.index \ | |
26 | $QT_INSTALL_DOCS/qtmultimedia/qtmultimedia.index |
|
26 | $QT_INSTALL_DOCS/qtmultimedia/qtmultimedia.index | |
27 |
|
27 | |||
28 | Cpp.ignoretokens = Q_INVOKABLE \ |
|
28 | Cpp.ignoretokens = Q_INVOKABLE \ | |
29 | QT_CHARTS_EXPORT \ |
|
29 | QT_CHARTS_EXPORT \ | |
30 | QT_CHARTS_END_NAMESPACE \ |
|
30 | QT_CHARTS_END_NAMESPACE \ | |
31 | QT_CHARTS_BEGIN_NAMESPACE |
|
31 | QT_CHARTS_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | qhp.projects = QtCharts |
|
33 | qhp.projects = QtCharts | |
34 | qhp.QtCharts.file = qtcharts.qhp |
|
34 | qhp.QtCharts.file = qtcharts.qhp | |
35 | qhp.QtCharts.namespace = com.digia.qtcharts.200 |
|
35 | qhp.QtCharts.namespace = com.digia.qtcharts.200 | |
36 | qhp.QtCharts.virtualFolder = qtcharts |
|
36 | qhp.QtCharts.virtualFolder = qtcharts | |
37 | qhp.QtCharts.indexTitle = Qt Charts |
|
37 | qhp.QtCharts.indexTitle = Qt Charts | |
38 | qhp.QtCharts.indexRoot = |
|
38 | qhp.QtCharts.indexRoot = | |
39 |
|
39 | |||
40 | qhp.QtCharts.filterAttributes = qtcharts 2.0.0 qtrefdoc |
|
40 | qhp.QtCharts.filterAttributes = qtcharts 2.0.0 qtrefdoc | |
41 | qhp.QtCharts.customFilters.Qt.name = QtCharts 2.0.0 |
|
41 | qhp.QtCharts.customFilters.Qt.name = QtCharts 2.0.0 | |
42 | qhp.QtCharts.customFilters.Qt.filterAttributes = qtcharts 2.0.0 |
|
42 | qhp.QtCharts.customFilters.Qt.filterAttributes = qtcharts 2.0.0 | |
43 |
|
43 | |||
44 | qhp.QtCharts.subprojects = gettingstarted classes types examples |
|
44 | qhp.QtCharts.subprojects = gettingstarted classes types examples | |
45 |
|
45 | |||
46 | qhp.QtCharts.subprojects.gettingstarted.title = Getting Started |
|
46 | qhp.QtCharts.subprojects.gettingstarted.title = Getting Started | |
47 | qhp.QtCharts.subprojects.gettingstarted.indexTitle = Qt Charts Getting Started |
|
47 | qhp.QtCharts.subprojects.gettingstarted.indexTitle = Qt Charts Getting Started | |
48 | qhp.QtCharts.subprojects.gettingstarted.selectors = fake:page |
|
48 | qhp.QtCharts.subprojects.gettingstarted.selectors = fake:page | |
49 | qhp.QtCharts.subprojects.gettingstarted.sortPages = true |
|
49 | qhp.QtCharts.subprojects.gettingstarted.sortPages = true | |
50 |
|
50 | |||
51 | qhp.QtCharts.subprojects.classes.title = C++ Classes |
|
51 | qhp.QtCharts.subprojects.classes.title = C++ Classes | |
52 | qhp.QtCharts.subprojects.classes.indexTitle = Qt Charts C++ Classes |
|
52 | qhp.QtCharts.subprojects.classes.indexTitle = Qt Charts C++ Classes | |
53 | qhp.QtCharts.subprojects.classes.selectors = class |
|
53 | qhp.QtCharts.subprojects.classes.selectors = class | |
54 | qhp.QtCharts.subprojects.classes.sortPages = true |
|
54 | qhp.QtCharts.subprojects.classes.sortPages = true | |
55 |
|
55 | |||
56 | qhp.QtCharts.subprojects.types.title = QML Types |
|
56 | qhp.QtCharts.subprojects.types.title = QML Types | |
57 | qhp.QtCharts.subprojects.types.indexTitle = Qt Charts QML Types |
|
57 | qhp.QtCharts.subprojects.types.indexTitle = Qt Charts QML Types | |
58 | qhp.QtCharts.subprojects.types.selectors = qmlclass |
|
58 | qhp.QtCharts.subprojects.types.selectors = qmlclass | |
59 | qhp.QtCharts.subprojects.types.sortPages = true |
|
59 | qhp.QtCharts.subprojects.types.sortPages = true | |
60 |
|
60 | |||
61 | qhp.QtCharts.subprojects.examples.title = Examples |
|
61 | qhp.QtCharts.subprojects.examples.title = Examples | |
62 | qhp.QtCharts.subprojects.examples.indexTitle = Qt Charts Examples |
|
62 | qhp.QtCharts.subprojects.examples.indexTitle = Qt Charts Examples | |
63 | qhp.QtCharts.subprojects.examples.selectors = fake:example |
|
63 | qhp.QtCharts.subprojects.examples.selectors = fake:example | |
64 | qhp.QtCharts.subprojects.examples.sortPages = true |
|
64 | qhp.QtCharts.subprojects.examples.sortPages = true | |
65 |
|
65 | |||
66 | navigation.landingpage = Qt Charts |
|
66 | navigation.landingpage = Qt Charts | |
67 | navigation.cppclassespage = Qt Charts C++ Classes |
|
67 | navigation.cppclassespage = Qt Charts C++ Classes | |
68 | navigation.qmltypespage = Qt Charts QML Types |
|
68 | navigation.qmltypespage = Qt Charts QML Types | |
69 |
|
69 | |||
|
70 | depends = qtwidgets | |||
|
71 | ||||
70 | buildversion = Qt Charts $QT_VERSION Reference Documentation |
|
72 | buildversion = Qt Charts $QT_VERSION Reference Documentation |
@@ -1,630 +1,639 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.io |
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and Digia. |
|
12 | ** agreement between you and Digia. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | #include <QtCharts/QLegend> |
|
19 | #include <QtCharts/QLegend> | |
20 | #include <private/qlegend_p.h> |
|
20 | #include <private/qlegend_p.h> | |
21 | #include <QtCharts/QAbstractSeries> |
|
21 | #include <QtCharts/QAbstractSeries> | |
22 | #include <private/qabstractseries_p.h> |
|
22 | #include <private/qabstractseries_p.h> | |
23 | #include <private/qchart_p.h> |
|
23 | #include <private/qchart_p.h> | |
24 | #include <private/legendlayout_p.h> |
|
24 | #include <private/legendlayout_p.h> | |
25 | #include <private/chartpresenter_p.h> |
|
25 | #include <private/chartpresenter_p.h> | |
26 | #include <private/abstractchartlayout_p.h> |
|
26 | #include <private/abstractchartlayout_p.h> | |
27 | #include <QtCharts/QLegendMarker> |
|
27 | #include <QtCharts/QLegendMarker> | |
28 | #include <private/qlegendmarker_p.h> |
|
28 | #include <private/qlegendmarker_p.h> | |
29 | #include <private/legendmarkeritem_p.h> |
|
29 | #include <private/legendmarkeritem_p.h> | |
30 | #include <private/chartdataset_p.h> |
|
30 | #include <private/chartdataset_p.h> | |
31 | #include <QtGui/QPainter> |
|
31 | #include <QtGui/QPainter> | |
32 | #include <QtGui/QPen> |
|
32 | #include <QtGui/QPen> | |
33 | #include <QtWidgets/QGraphicsItemGroup> |
|
33 | #include <QtWidgets/QGraphicsItemGroup> | |
34 |
|
34 | |||
35 | QT_CHARTS_BEGIN_NAMESPACE |
|
35 | QT_CHARTS_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \class QLegend |
|
38 | \class QLegend | |
39 | \inmodule Qt Charts |
|
39 | \inmodule Qt Charts | |
|
40 | \inherits QGraphicsWidget | |||
40 | \brief Legend object. |
|
41 | \brief Legend object. | |
41 | \mainclass |
|
42 | \mainclass | |
42 |
|
43 | |||
43 | QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when |
|
44 | QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when | |
44 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
45 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
45 | handle the drawing manually. |
|
46 | handle the drawing manually. | |
46 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
47 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
47 |
|
48 | |||
48 | \image examples_percentbarchart_legend.png |
|
49 | \image examples_percentbarchart_legend.png | |
49 |
|
50 | |||
50 | \sa QChart |
|
51 | \sa QChart | |
51 | */ |
|
52 | */ | |
52 | /*! |
|
53 | /*! | |
53 | \qmltype Legend |
|
54 | \qmltype Legend | |
54 | \instantiates QLegend |
|
55 | \instantiates QLegend | |
55 | \inqmlmodule QtCharts |
|
56 | \inqmlmodule QtCharts | |
56 |
|
57 | |||
57 | \brief Legend is part of Qt Chart QML API. |
|
58 | \brief Legend is part of Qt Chart QML API. | |
58 |
|
59 | |||
59 |
Legend is a graphical object, whic |
|
60 | Legend is a graphical object, which displays legend of the chart. Legend state is updated by | |
60 | ChartView, when series have been changed. Legend is used via ChartView class. For example: |
|
61 | ChartView, when series have been changed. Legend is used via ChartView class. For example: | |
61 | \code |
|
62 | \code | |
62 | ChartView { |
|
63 | ChartView { | |
63 | legend.visible: true |
|
64 | legend.visible: true | |
64 | legend.alignment: Qt.AlignBottom |
|
65 | legend.alignment: Qt.AlignBottom | |
65 | // Add a few series... |
|
66 | // Add a few series... | |
66 | } |
|
67 | } | |
67 | \endcode |
|
68 | \endcode | |
68 |
|
69 | |||
69 | \image examples_percentbarchart_legend.png |
|
70 | \image examples_percentbarchart_legend.png | |
70 |
|
71 | |||
71 | Please note that there is no QML API available for modifying legend markers, unlike in the Qt |
|
72 | Please note that there is no QML API available for modifying legend markers, unlike in the Qt | |
72 | API of Charts. The use case of modifying markers can be implemented for example by creating your |
|
73 | API of Charts. The use case of modifying markers can be implemented for example by creating your | |
73 | own custom legend. For an example on how to do this, |
|
74 | own custom legend. For an example on how to do this, | |
74 | see \l {qmlcustomlegend}{Qml Custom Example} application. |
|
75 | see \l {qmlcustomlegend}{Qml Custom Example} application. | |
75 | */ |
|
76 | */ | |
76 |
|
77 | |||
77 | /*! |
|
78 | /*! | |
78 | \property QLegend::alignment |
|
79 | \property QLegend::alignment | |
79 | \brief The alignment of the legend. |
|
80 | \brief The alignment of the legend. | |
80 |
|
81 | |||
81 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
82 | Legend paints on the defined position in the chart. The following alignments are supported: | |
82 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
83 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
83 | */ |
|
84 | */ | |
84 | /*! |
|
85 | /*! | |
85 | \qmlproperty Qt.Alignment Legend::alignment |
|
86 | \qmlproperty Qt.Alignment Legend::alignment | |
86 | \brief The alignment of the legend. |
|
87 | \brief The alignment of the legend. | |
87 |
|
88 | |||
88 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
89 | Legend paints on the defined position in the chart. The following alignments are supported: | |
89 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
90 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
90 | */ |
|
91 | */ | |
91 |
|
92 | |||
92 | /*! |
|
93 | /*! | |
93 | \property QLegend::backgroundVisible |
|
94 | \property QLegend::backgroundVisible | |
94 | Whether the legend background is visible or not. |
|
95 | Whether the legend background is visible or not. | |
95 | */ |
|
96 | */ | |
96 | /*! |
|
97 | /*! | |
97 | \qmlproperty bool Legend::backgroundVisible |
|
98 | \qmlproperty bool Legend::backgroundVisible | |
98 | Whether the legend background is visible or not. |
|
99 | Whether the legend background is visible or not. | |
99 | */ |
|
100 | */ | |
100 |
|
101 | |||
101 | /*! |
|
102 | /*! | |
|
103 | \qmlproperty bool Legend::visible | |||
|
104 | \brief Whether the legend is visible or not. | |||
|
105 | ||||
|
106 | By default, this property is \c true. | |||
|
107 | \sa QGraphicsObject::visible | |||
|
108 | */ | |||
|
109 | ||||
|
110 | /*! | |||
102 | \property QLegend::color |
|
111 | \property QLegend::color | |
103 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
112 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
104 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
113 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
105 | */ |
|
114 | */ | |
106 | /*! |
|
115 | /*! | |
107 | \qmlproperty color Legend::color |
|
116 | \qmlproperty color Legend::color | |
108 | The color of the legend, i.e. the background (brush) color. |
|
117 | The color of the legend, i.e. the background (brush) color. | |
109 | */ |
|
118 | */ | |
110 |
|
119 | |||
111 | /*! |
|
120 | /*! | |
112 | \property QLegend::borderColor |
|
121 | \property QLegend::borderColor | |
113 | The border color of the legend, i.e. the line color. |
|
122 | The border color of the legend, i.e. the line color. | |
114 | */ |
|
123 | */ | |
115 | /*! |
|
124 | /*! | |
116 | \qmlproperty color Legend::borderColor |
|
125 | \qmlproperty color Legend::borderColor | |
117 | The border color of the legend, i.e. the line color. |
|
126 | The border color of the legend, i.e. the line color. | |
118 | */ |
|
127 | */ | |
119 |
|
128 | |||
120 | /*! |
|
129 | /*! | |
121 | \property QLegend::font |
|
130 | \property QLegend::font | |
122 | The font of markers used by legend. |
|
131 | The font of markers used by legend. | |
123 | */ |
|
132 | */ | |
124 | /*! |
|
133 | /*! | |
125 | \qmlproperty Font Legend::font |
|
134 | \qmlproperty Font Legend::font | |
126 | The font of markers used by legend. |
|
135 | The font of markers used by legend. | |
127 | */ |
|
136 | */ | |
128 |
|
137 | |||
129 | /*! |
|
138 | /*! | |
130 | \property QLegend::labelColor |
|
139 | \property QLegend::labelColor | |
131 | The color of brush used to draw labels. |
|
140 | The color of brush used to draw labels. | |
132 | */ |
|
141 | */ | |
133 | /*! |
|
142 | /*! | |
134 | \qmlproperty color Legend::labelColor |
|
143 | \qmlproperty color Legend::labelColor | |
135 | The color of brush used to draw labels. |
|
144 | The color of brush used to draw labels. | |
136 | */ |
|
145 | */ | |
137 |
|
146 | |||
138 | /*! |
|
147 | /*! | |
139 | \property QLegend::reverseMarkers |
|
148 | \property QLegend::reverseMarkers | |
140 | Whether reverse order is used for the markers in legend or not. False by default. |
|
149 | Whether reverse order is used for the markers in legend or not. False by default. | |
141 | */ |
|
150 | */ | |
142 | /*! |
|
151 | /*! | |
143 | \qmlproperty bool Legend::reverseMarkers |
|
152 | \qmlproperty bool Legend::reverseMarkers | |
144 | Whether reverse order is used for the markers in legend or not. False by default. |
|
153 | Whether reverse order is used for the markers in legend or not. False by default. | |
145 | */ |
|
154 | */ | |
146 |
|
155 | |||
147 | /*! |
|
156 | /*! | |
148 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
157 | \fn void QLegend::backgroundVisibleChanged(bool) | |
149 | The visibility of the legend background changed to \a visible. |
|
158 | The visibility of the legend background changed to \a visible. | |
150 | */ |
|
159 | */ | |
151 |
|
160 | |||
152 | /*! |
|
161 | /*! | |
153 | \fn void QLegend::colorChanged(QColor) |
|
162 | \fn void QLegend::colorChanged(QColor) | |
154 | The color of the legend background changed to \a color. |
|
163 | The color of the legend background changed to \a color. | |
155 | */ |
|
164 | */ | |
156 |
|
165 | |||
157 | /*! |
|
166 | /*! | |
158 | \fn void QLegend::borderColorChanged(QColor) |
|
167 | \fn void QLegend::borderColorChanged(QColor) | |
159 | The border color of the legend background changed to \a color. |
|
168 | The border color of the legend background changed to \a color. | |
160 | */ |
|
169 | */ | |
161 |
|
170 | |||
162 | /*! |
|
171 | /*! | |
163 | \fn void QLegend::fontChanged(QFont) |
|
172 | \fn void QLegend::fontChanged(QFont) | |
164 | The font of markers of the legend changed to \a font. |
|
173 | The font of markers of the legend changed to \a font. | |
165 | */ |
|
174 | */ | |
166 |
|
175 | |||
167 | /*! |
|
176 | /*! | |
168 | \fn void QLegend::labelColorChanged(QColor color) |
|
177 | \fn void QLegend::labelColorChanged(QColor color) | |
169 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
178 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
170 | */ |
|
179 | */ | |
171 |
|
180 | |||
172 | /*! |
|
181 | /*! | |
173 | \fn void QLegend::reverseMarkersChanged(bool) |
|
182 | \fn void QLegend::reverseMarkersChanged(bool) | |
174 | The use of reverse order for the markers in legend is changed to \a reverseMarkers. |
|
183 | The use of reverse order for the markers in legend is changed to \a reverseMarkers. | |
175 | */ |
|
184 | */ | |
176 |
|
185 | |||
177 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
186 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
178 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
187 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
179 | { |
|
188 | { | |
180 | setZValue(ChartPresenter::LegendZValue); |
|
189 | setZValue(ChartPresenter::LegendZValue); | |
181 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
190 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
182 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
191 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | |
183 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
192 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
184 | setLayout(d_ptr->m_layout); |
|
193 | setLayout(d_ptr->m_layout); | |
185 | } |
|
194 | } | |
186 |
|
195 | |||
187 | /*! |
|
196 | /*! | |
188 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
197 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
189 | */ |
|
198 | */ | |
190 | QLegend::~QLegend() |
|
199 | QLegend::~QLegend() | |
191 | { |
|
200 | { | |
192 | } |
|
201 | } | |
193 |
|
202 | |||
194 | /*! |
|
203 | /*! | |
195 | \internal |
|
204 | \internal | |
196 | */ |
|
205 | */ | |
197 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
206 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
198 | { |
|
207 | { | |
199 | Q_UNUSED(option) |
|
208 | Q_UNUSED(option) | |
200 | Q_UNUSED(widget) |
|
209 | Q_UNUSED(widget) | |
201 |
|
210 | |||
202 | if (!d_ptr->m_backgroundVisible) |
|
211 | if (!d_ptr->m_backgroundVisible) | |
203 | return; |
|
212 | return; | |
204 |
|
213 | |||
205 | painter->setOpacity(opacity()); |
|
214 | painter->setOpacity(opacity()); | |
206 | painter->setPen(d_ptr->m_pen); |
|
215 | painter->setPen(d_ptr->m_pen); | |
207 | painter->setBrush(d_ptr->m_brush); |
|
216 | painter->setBrush(d_ptr->m_brush); | |
208 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
217 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
209 | } |
|
218 | } | |
210 |
|
219 | |||
211 |
|
220 | |||
212 | /*! |
|
221 | /*! | |
213 | Sets the \a brush of legend. Brush affects the background of legend. |
|
222 | Sets the \a brush of legend. Brush affects the background of legend. | |
214 | */ |
|
223 | */ | |
215 | void QLegend::setBrush(const QBrush &brush) |
|
224 | void QLegend::setBrush(const QBrush &brush) | |
216 | { |
|
225 | { | |
217 | if (d_ptr->m_brush != brush) { |
|
226 | if (d_ptr->m_brush != brush) { | |
218 | d_ptr->m_brush = brush; |
|
227 | d_ptr->m_brush = brush; | |
219 | update(); |
|
228 | update(); | |
220 | emit colorChanged(brush.color()); |
|
229 | emit colorChanged(brush.color()); | |
221 | } |
|
230 | } | |
222 | } |
|
231 | } | |
223 |
|
232 | |||
224 | /*! |
|
233 | /*! | |
225 | Returns the brush used by legend. |
|
234 | Returns the brush used by legend. | |
226 | */ |
|
235 | */ | |
227 | QBrush QLegend::brush() const |
|
236 | QBrush QLegend::brush() const | |
228 | { |
|
237 | { | |
229 | return d_ptr->m_brush; |
|
238 | return d_ptr->m_brush; | |
230 | } |
|
239 | } | |
231 |
|
240 | |||
232 | void QLegend::setColor(QColor color) |
|
241 | void QLegend::setColor(QColor color) | |
233 | { |
|
242 | { | |
234 | QBrush b = d_ptr->m_brush; |
|
243 | QBrush b = d_ptr->m_brush; | |
235 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
244 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
236 | b.setStyle(Qt::SolidPattern); |
|
245 | b.setStyle(Qt::SolidPattern); | |
237 | b.setColor(color); |
|
246 | b.setColor(color); | |
238 | setBrush(b); |
|
247 | setBrush(b); | |
239 | } |
|
248 | } | |
240 | } |
|
249 | } | |
241 |
|
250 | |||
242 | QColor QLegend::color() |
|
251 | QColor QLegend::color() | |
243 | { |
|
252 | { | |
244 | return d_ptr->m_brush.color(); |
|
253 | return d_ptr->m_brush.color(); | |
245 | } |
|
254 | } | |
246 |
|
255 | |||
247 | /*! |
|
256 | /*! | |
248 | Sets the \a pen of legend. Pen affects the legend borders. |
|
257 | Sets the \a pen of legend. Pen affects the legend borders. | |
249 | */ |
|
258 | */ | |
250 | void QLegend::setPen(const QPen &pen) |
|
259 | void QLegend::setPen(const QPen &pen) | |
251 | { |
|
260 | { | |
252 | if (d_ptr->m_pen != pen) { |
|
261 | if (d_ptr->m_pen != pen) { | |
253 | d_ptr->m_pen = pen; |
|
262 | d_ptr->m_pen = pen; | |
254 | update(); |
|
263 | update(); | |
255 | emit borderColorChanged(pen.color()); |
|
264 | emit borderColorChanged(pen.color()); | |
256 | } |
|
265 | } | |
257 | } |
|
266 | } | |
258 |
|
267 | |||
259 | /*! |
|
268 | /*! | |
260 | Returns the pen used by legend. |
|
269 | Returns the pen used by legend. | |
261 | */ |
|
270 | */ | |
262 |
|
271 | |||
263 | QPen QLegend::pen() const |
|
272 | QPen QLegend::pen() const | |
264 | { |
|
273 | { | |
265 | return d_ptr->m_pen; |
|
274 | return d_ptr->m_pen; | |
266 | } |
|
275 | } | |
267 |
|
276 | |||
268 | void QLegend::setFont(const QFont &font) |
|
277 | void QLegend::setFont(const QFont &font) | |
269 | { |
|
278 | { | |
270 | if (d_ptr->m_font != font) { |
|
279 | if (d_ptr->m_font != font) { | |
271 | // Hide items to avoid flickering |
|
280 | // Hide items to avoid flickering | |
272 | d_ptr->items()->setVisible(false); |
|
281 | d_ptr->items()->setVisible(false); | |
273 | d_ptr->m_font = font; |
|
282 | d_ptr->m_font = font; | |
274 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
283 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
275 | marker->setFont(d_ptr->m_font); |
|
284 | marker->setFont(d_ptr->m_font); | |
276 | } |
|
285 | } | |
277 | layout()->invalidate(); |
|
286 | layout()->invalidate(); | |
278 | emit fontChanged(font); |
|
287 | emit fontChanged(font); | |
279 | } |
|
288 | } | |
280 | } |
|
289 | } | |
281 |
|
290 | |||
282 | QFont QLegend::font() const |
|
291 | QFont QLegend::font() const | |
283 | { |
|
292 | { | |
284 | return d_ptr->m_font; |
|
293 | return d_ptr->m_font; | |
285 | } |
|
294 | } | |
286 |
|
295 | |||
287 | void QLegend::setBorderColor(QColor color) |
|
296 | void QLegend::setBorderColor(QColor color) | |
288 | { |
|
297 | { | |
289 | QPen p = d_ptr->m_pen; |
|
298 | QPen p = d_ptr->m_pen; | |
290 | if (p.color() != color) { |
|
299 | if (p.color() != color) { | |
291 | p.setColor(color); |
|
300 | p.setColor(color); | |
292 | setPen(p); |
|
301 | setPen(p); | |
293 | } |
|
302 | } | |
294 | } |
|
303 | } | |
295 |
|
304 | |||
296 | QColor QLegend::borderColor() |
|
305 | QColor QLegend::borderColor() | |
297 | { |
|
306 | { | |
298 | return d_ptr->m_pen.color(); |
|
307 | return d_ptr->m_pen.color(); | |
299 | } |
|
308 | } | |
300 |
|
309 | |||
301 | /*! |
|
310 | /*! | |
302 | Set brush used to draw labels to \a brush. |
|
311 | Set brush used to draw labels to \a brush. | |
303 | */ |
|
312 | */ | |
304 | void QLegend::setLabelBrush(const QBrush &brush) |
|
313 | void QLegend::setLabelBrush(const QBrush &brush) | |
305 | { |
|
314 | { | |
306 | if (d_ptr->m_labelBrush != brush) { |
|
315 | if (d_ptr->m_labelBrush != brush) { | |
307 | d_ptr->m_labelBrush = brush; |
|
316 | d_ptr->m_labelBrush = brush; | |
308 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
317 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
309 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
318 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
310 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
319 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
311 | // instead of mapping it from label brush color |
|
320 | // instead of mapping it from label brush color | |
312 | marker->setPen(brush.color()); |
|
321 | marker->setPen(brush.color()); | |
313 | } |
|
322 | } | |
314 | emit labelColorChanged(brush.color()); |
|
323 | emit labelColorChanged(brush.color()); | |
315 | } |
|
324 | } | |
316 | } |
|
325 | } | |
317 |
|
326 | |||
318 | /*! |
|
327 | /*! | |
319 | Brush used to draw labels. |
|
328 | Brush used to draw labels. | |
320 | */ |
|
329 | */ | |
321 | QBrush QLegend::labelBrush() const |
|
330 | QBrush QLegend::labelBrush() const | |
322 | { |
|
331 | { | |
323 | return d_ptr->m_labelBrush; |
|
332 | return d_ptr->m_labelBrush; | |
324 | } |
|
333 | } | |
325 |
|
334 | |||
326 | void QLegend::setLabelColor(QColor color) |
|
335 | void QLegend::setLabelColor(QColor color) | |
327 | { |
|
336 | { | |
328 | QBrush b = d_ptr->m_labelBrush; |
|
337 | QBrush b = d_ptr->m_labelBrush; | |
329 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
338 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
330 | b.setStyle(Qt::SolidPattern); |
|
339 | b.setStyle(Qt::SolidPattern); | |
331 | b.setColor(color); |
|
340 | b.setColor(color); | |
332 | setLabelBrush(b); |
|
341 | setLabelBrush(b); | |
333 | } |
|
342 | } | |
334 | } |
|
343 | } | |
335 |
|
344 | |||
336 | QColor QLegend::labelColor() const |
|
345 | QColor QLegend::labelColor() const | |
337 | { |
|
346 | { | |
338 | return d_ptr->m_labelBrush.color(); |
|
347 | return d_ptr->m_labelBrush.color(); | |
339 | } |
|
348 | } | |
340 |
|
349 | |||
341 |
|
350 | |||
342 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
351 | void QLegend::setAlignment(Qt::Alignment alignment) | |
343 | { |
|
352 | { | |
344 | if (d_ptr->m_alignment != alignment) { |
|
353 | if (d_ptr->m_alignment != alignment) { | |
345 | d_ptr->m_alignment = alignment; |
|
354 | d_ptr->m_alignment = alignment; | |
346 | layout()->invalidate(); |
|
355 | layout()->invalidate(); | |
347 | } |
|
356 | } | |
348 | } |
|
357 | } | |
349 |
|
358 | |||
350 | Qt::Alignment QLegend::alignment() const |
|
359 | Qt::Alignment QLegend::alignment() const | |
351 | { |
|
360 | { | |
352 | return d_ptr->m_alignment; |
|
361 | return d_ptr->m_alignment; | |
353 | } |
|
362 | } | |
354 |
|
363 | |||
355 | /*! |
|
364 | /*! | |
356 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
365 | Detaches the legend from chart. Chart won't change layout of the legend. | |
357 | */ |
|
366 | */ | |
358 | void QLegend::detachFromChart() |
|
367 | void QLegend::detachFromChart() | |
359 | { |
|
368 | { | |
360 | d_ptr->m_attachedToChart = false; |
|
369 | d_ptr->m_attachedToChart = false; | |
361 | // layout()->invalidate(); |
|
370 | // layout()->invalidate(); | |
362 | d_ptr->m_chart->layout()->invalidate(); |
|
371 | d_ptr->m_chart->layout()->invalidate(); | |
363 | setParent(0); |
|
372 | setParent(0); | |
364 |
|
373 | |||
365 | } |
|
374 | } | |
366 |
|
375 | |||
367 | /*! |
|
376 | /*! | |
368 | Attaches the legend to chart. Chart may change layout of the legend. |
|
377 | Attaches the legend to chart. Chart may change layout of the legend. | |
369 | */ |
|
378 | */ | |
370 | void QLegend::attachToChart() |
|
379 | void QLegend::attachToChart() | |
371 | { |
|
380 | { | |
372 | d_ptr->m_attachedToChart = true; |
|
381 | d_ptr->m_attachedToChart = true; | |
373 | // layout()->invalidate(); |
|
382 | // layout()->invalidate(); | |
374 | d_ptr->m_chart->layout()->invalidate(); |
|
383 | d_ptr->m_chart->layout()->invalidate(); | |
375 | setParent(d_ptr->m_chart); |
|
384 | setParent(d_ptr->m_chart); | |
376 | } |
|
385 | } | |
377 |
|
386 | |||
378 | /*! |
|
387 | /*! | |
379 | Returns true, if legend is attached to chart. |
|
388 | Returns true, if legend is attached to chart. | |
380 | */ |
|
389 | */ | |
381 | bool QLegend::isAttachedToChart() |
|
390 | bool QLegend::isAttachedToChart() | |
382 | { |
|
391 | { | |
383 | return d_ptr->m_attachedToChart; |
|
392 | return d_ptr->m_attachedToChart; | |
384 | } |
|
393 | } | |
385 |
|
394 | |||
386 | /*! |
|
395 | /*! | |
387 | Sets the visibility of legend background to \a visible |
|
396 | Sets the visibility of legend background to \a visible | |
388 | */ |
|
397 | */ | |
389 | void QLegend::setBackgroundVisible(bool visible) |
|
398 | void QLegend::setBackgroundVisible(bool visible) | |
390 | { |
|
399 | { | |
391 | if (d_ptr->m_backgroundVisible != visible) { |
|
400 | if (d_ptr->m_backgroundVisible != visible) { | |
392 | d_ptr->m_backgroundVisible = visible; |
|
401 | d_ptr->m_backgroundVisible = visible; | |
393 | update(); |
|
402 | update(); | |
394 | emit backgroundVisibleChanged(visible); |
|
403 | emit backgroundVisibleChanged(visible); | |
395 | } |
|
404 | } | |
396 | } |
|
405 | } | |
397 |
|
406 | |||
398 | /*! |
|
407 | /*! | |
399 | Returns the visibility of legend background |
|
408 | Returns the visibility of legend background | |
400 | */ |
|
409 | */ | |
401 | bool QLegend::isBackgroundVisible() const |
|
410 | bool QLegend::isBackgroundVisible() const | |
402 | { |
|
411 | { | |
403 | return d_ptr->m_backgroundVisible; |
|
412 | return d_ptr->m_backgroundVisible; | |
404 | } |
|
413 | } | |
405 |
|
414 | |||
406 | /*! |
|
415 | /*! | |
407 | Returns the list of markers in legend. The list can be filtered with \a series parameter. |
|
416 | Returns the list of markers in legend. The list can be filtered with \a series parameter. | |
408 | If \a series is given, only markers related to that series are returned. |
|
417 | If \a series is given, only markers related to that series are returned. | |
409 | */ |
|
418 | */ | |
410 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const |
|
419 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const | |
411 | { |
|
420 | { | |
412 | return d_ptr->markers(series); |
|
421 | return d_ptr->markers(series); | |
413 | } |
|
422 | } | |
414 |
|
423 | |||
415 | bool QLegend::reverseMarkers() |
|
424 | bool QLegend::reverseMarkers() | |
416 | { |
|
425 | { | |
417 | return d_ptr->m_reverseMarkers; |
|
426 | return d_ptr->m_reverseMarkers; | |
418 | } |
|
427 | } | |
419 |
|
428 | |||
420 | void QLegend::setReverseMarkers(bool reverseMarkers) |
|
429 | void QLegend::setReverseMarkers(bool reverseMarkers) | |
421 | { |
|
430 | { | |
422 | if (d_ptr->m_reverseMarkers != reverseMarkers) { |
|
431 | if (d_ptr->m_reverseMarkers != reverseMarkers) { | |
423 | d_ptr->m_reverseMarkers = reverseMarkers; |
|
432 | d_ptr->m_reverseMarkers = reverseMarkers; | |
424 | layout()->invalidate(); |
|
433 | layout()->invalidate(); | |
425 | emit reverseMarkersChanged(reverseMarkers); |
|
434 | emit reverseMarkersChanged(reverseMarkers); | |
426 | } |
|
435 | } | |
427 | } |
|
436 | } | |
428 |
|
437 | |||
429 | /*! |
|
438 | /*! | |
430 | \internal \a event see QGraphicsWidget for details |
|
439 | \internal \a event see QGraphicsWidget for details | |
431 | */ |
|
440 | */ | |
432 | void QLegend::hideEvent(QHideEvent *event) |
|
441 | void QLegend::hideEvent(QHideEvent *event) | |
433 | { |
|
442 | { | |
434 | if (isAttachedToChart()) |
|
443 | if (isAttachedToChart()) | |
435 | d_ptr->m_presenter->layout()->invalidate(); |
|
444 | d_ptr->m_presenter->layout()->invalidate(); | |
436 | QGraphicsWidget::hideEvent(event); |
|
445 | QGraphicsWidget::hideEvent(event); | |
437 | } |
|
446 | } | |
438 | /*! |
|
447 | /*! | |
439 | \internal \a event see QGraphicsWidget for details |
|
448 | \internal \a event see QGraphicsWidget for details | |
440 | */ |
|
449 | */ | |
441 | void QLegend::showEvent(QShowEvent *event) |
|
450 | void QLegend::showEvent(QShowEvent *event) | |
442 | { |
|
451 | { | |
443 | if (isAttachedToChart()) |
|
452 | if (isAttachedToChart()) | |
444 | layout()->invalidate(); |
|
453 | layout()->invalidate(); | |
445 | QGraphicsWidget::showEvent(event); |
|
454 | QGraphicsWidget::showEvent(event); | |
446 | //layout activation will show the items |
|
455 | //layout activation will show the items | |
447 | } |
|
456 | } | |
448 |
|
457 | |||
449 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
458 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
450 |
|
459 | |||
451 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
460 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
452 | : q_ptr(q), |
|
461 | : q_ptr(q), | |
453 | m_presenter(presenter), |
|
462 | m_presenter(presenter), | |
454 | m_layout(new LegendLayout(q)), |
|
463 | m_layout(new LegendLayout(q)), | |
455 | m_chart(chart), |
|
464 | m_chart(chart), | |
456 | m_items(new QGraphicsItemGroup(q)), |
|
465 | m_items(new QGraphicsItemGroup(q)), | |
457 | m_alignment(Qt::AlignTop), |
|
466 | m_alignment(Qt::AlignTop), | |
458 | m_brush(QBrush()), |
|
467 | m_brush(QBrush()), | |
459 | m_pen(QPen()), |
|
468 | m_pen(QPen()), | |
460 | m_labelBrush(QBrush()), |
|
469 | m_labelBrush(QBrush()), | |
461 | m_diameter(5), |
|
470 | m_diameter(5), | |
462 | m_attachedToChart(true), |
|
471 | m_attachedToChart(true), | |
463 | m_backgroundVisible(false), |
|
472 | m_backgroundVisible(false), | |
464 | m_reverseMarkers(false) |
|
473 | m_reverseMarkers(false) | |
465 | { |
|
474 | { | |
466 | m_items->setHandlesChildEvents(false); |
|
475 | m_items->setHandlesChildEvents(false); | |
467 | } |
|
476 | } | |
468 |
|
477 | |||
469 | QLegendPrivate::~QLegendPrivate() |
|
478 | QLegendPrivate::~QLegendPrivate() | |
470 | { |
|
479 | { | |
471 |
|
480 | |||
472 | } |
|
481 | } | |
473 |
|
482 | |||
474 | void QLegendPrivate::setOffset(const QPointF &offset) |
|
483 | void QLegendPrivate::setOffset(const QPointF &offset) | |
475 | { |
|
484 | { | |
476 | m_layout->setOffset(offset.x(), offset.y()); |
|
485 | m_layout->setOffset(offset.x(), offset.y()); | |
477 | } |
|
486 | } | |
478 |
|
487 | |||
479 | QPointF QLegendPrivate::offset() const |
|
488 | QPointF QLegendPrivate::offset() const | |
480 | { |
|
489 | { | |
481 | return m_layout->offset(); |
|
490 | return m_layout->offset(); | |
482 | } |
|
491 | } | |
483 |
|
492 | |||
484 | int QLegendPrivate::roundness(qreal size) |
|
493 | int QLegendPrivate::roundness(qreal size) | |
485 | { |
|
494 | { | |
486 | return 100 * m_diameter / int(size); |
|
495 | return 100 * m_diameter / int(size); | |
487 | } |
|
496 | } | |
488 |
|
497 | |||
489 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) |
|
498 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) | |
490 | { |
|
499 | { | |
491 | // Return all markers |
|
500 | // Return all markers | |
492 | if (!series) { |
|
501 | if (!series) { | |
493 | return m_markers; |
|
502 | return m_markers; | |
494 | } |
|
503 | } | |
495 |
|
504 | |||
496 | // Create filtered list |
|
505 | // Create filtered list | |
497 | QList<QLegendMarker *> markers; |
|
506 | QList<QLegendMarker *> markers; | |
498 | foreach (QLegendMarker *marker, m_markers) { |
|
507 | foreach (QLegendMarker *marker, m_markers) { | |
499 | if (marker->series() == series) { |
|
508 | if (marker->series() == series) { | |
500 | markers.append(marker); |
|
509 | markers.append(marker); | |
501 | } |
|
510 | } | |
502 | } |
|
511 | } | |
503 | return markers; |
|
512 | return markers; | |
504 | } |
|
513 | } | |
505 |
|
514 | |||
506 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
515 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) | |
507 | { |
|
516 | { | |
508 | if (m_series.contains(series)) { |
|
517 | if (m_series.contains(series)) { | |
509 | return; |
|
518 | return; | |
510 | } |
|
519 | } | |
511 |
|
520 | |||
512 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
521 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
513 | decorateMarkers(newMarkers); |
|
522 | decorateMarkers(newMarkers); | |
514 | addMarkers(newMarkers); |
|
523 | addMarkers(newMarkers); | |
515 |
|
524 | |||
516 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
525 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
517 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
526 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
518 |
|
527 | |||
519 | m_series.append(series); |
|
528 | m_series.append(series); | |
520 | m_items->setVisible(false); |
|
529 | m_items->setVisible(false); | |
521 | m_layout->invalidate(); |
|
530 | m_layout->invalidate(); | |
522 | } |
|
531 | } | |
523 |
|
532 | |||
524 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
533 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
525 | { |
|
534 | { | |
526 | if (m_series.contains(series)) { |
|
535 | if (m_series.contains(series)) { | |
527 | m_series.removeOne(series); |
|
536 | m_series.removeOne(series); | |
528 | } |
|
537 | } | |
529 |
|
538 | |||
530 | // Find out, which markers to remove |
|
539 | // Find out, which markers to remove | |
531 | QList<QLegendMarker *> removed; |
|
540 | QList<QLegendMarker *> removed; | |
532 | foreach (QLegendMarker *m, m_markers) { |
|
541 | foreach (QLegendMarker *m, m_markers) { | |
533 | if (m->series() == series) { |
|
542 | if (m->series() == series) { | |
534 | removed << m; |
|
543 | removed << m; | |
535 | } |
|
544 | } | |
536 | } |
|
545 | } | |
537 | removeMarkers(removed); |
|
546 | removeMarkers(removed); | |
538 |
|
547 | |||
539 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
548 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
540 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
549 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
541 |
|
550 | |||
542 | m_layout->invalidate(); |
|
551 | m_layout->invalidate(); | |
543 | } |
|
552 | } | |
544 |
|
553 | |||
545 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
554 | void QLegendPrivate::handleSeriesVisibleChanged() | |
546 | { |
|
555 | { | |
547 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
556 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
548 | Q_ASSERT(series); |
|
557 | Q_ASSERT(series); | |
549 |
|
558 | |||
550 | foreach (QLegendMarker *marker, m_markers) { |
|
559 | foreach (QLegendMarker *marker, m_markers) { | |
551 | if (marker->series() == series) { |
|
560 | if (marker->series() == series) { | |
552 | marker->setVisible(series->isVisible()); |
|
561 | marker->setVisible(series->isVisible()); | |
553 | } |
|
562 | } | |
554 | } |
|
563 | } | |
555 |
|
564 | |||
556 | if (m_chart->isVisible()) |
|
565 | if (m_chart->isVisible()) | |
557 | m_layout->invalidate(); |
|
566 | m_layout->invalidate(); | |
558 | } |
|
567 | } | |
559 |
|
568 | |||
560 | void QLegendPrivate::handleCountChanged() |
|
569 | void QLegendPrivate::handleCountChanged() | |
561 | { |
|
570 | { | |
562 | // Here we handle the changes in marker count. |
|
571 | // Here we handle the changes in marker count. | |
563 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. |
|
572 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. | |
564 |
|
573 | |||
565 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
574 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); | |
566 | QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); |
|
575 | QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); | |
567 |
|
576 | |||
568 | // Find out removed markers and created markers |
|
577 | // Find out removed markers and created markers | |
569 | QList<QLegendMarker *> removedMarkers; |
|
578 | QList<QLegendMarker *> removedMarkers; | |
570 | foreach (QLegendMarker *oldMarker, m_markers) { |
|
579 | foreach (QLegendMarker *oldMarker, m_markers) { | |
571 | // we have marker, which is related to sender. |
|
580 | // we have marker, which is related to sender. | |
572 | if (oldMarker->series() == series->q_ptr) { |
|
581 | if (oldMarker->series() == series->q_ptr) { | |
573 | bool found = false; |
|
582 | bool found = false; | |
574 | foreach(QLegendMarker *newMarker, createdMarkers) { |
|
583 | foreach(QLegendMarker *newMarker, createdMarkers) { | |
575 | // New marker considered existing if: |
|
584 | // New marker considered existing if: | |
576 | // - d_ptr->relatedObject() is same for both markers. |
|
585 | // - d_ptr->relatedObject() is same for both markers. | |
577 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { |
|
586 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { | |
578 | // Delete the new marker, since we already have existing marker, that might be connected on user side. |
|
587 | // Delete the new marker, since we already have existing marker, that might be connected on user side. | |
579 | found = true; |
|
588 | found = true; | |
580 | createdMarkers.removeOne(newMarker); |
|
589 | createdMarkers.removeOne(newMarker); | |
581 | delete newMarker; |
|
590 | delete newMarker; | |
582 | } |
|
591 | } | |
583 | } |
|
592 | } | |
584 | if (!found) { |
|
593 | if (!found) { | |
585 | // No related object found for marker, add to removedMarkers list |
|
594 | // No related object found for marker, add to removedMarkers list | |
586 | removedMarkers << oldMarker; |
|
595 | removedMarkers << oldMarker; | |
587 | } |
|
596 | } | |
588 | } |
|
597 | } | |
589 | } |
|
598 | } | |
590 |
|
599 | |||
591 | removeMarkers(removedMarkers); |
|
600 | removeMarkers(removedMarkers); | |
592 | decorateMarkers(createdMarkers); |
|
601 | decorateMarkers(createdMarkers); | |
593 | addMarkers(createdMarkers); |
|
602 | addMarkers(createdMarkers); | |
594 |
|
603 | |||
595 | q_ptr->layout()->invalidate(); |
|
604 | q_ptr->layout()->invalidate(); | |
596 | } |
|
605 | } | |
597 |
|
606 | |||
598 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) |
|
607 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | |
599 | { |
|
608 | { | |
600 | foreach (QLegendMarker *marker, markers) { |
|
609 | foreach (QLegendMarker *marker, markers) { | |
601 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
610 | m_items->addToGroup(marker->d_ptr.data()->item()); | |
602 | m_markers << marker; |
|
611 | m_markers << marker; | |
603 | m_markerHash.insert(marker->d_ptr->item(), marker); |
|
612 | m_markerHash.insert(marker->d_ptr->item(), marker); | |
604 | } |
|
613 | } | |
605 | } |
|
614 | } | |
606 |
|
615 | |||
607 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) |
|
616 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) | |
608 | { |
|
617 | { | |
609 | foreach (QLegendMarker *marker, markers) { |
|
618 | foreach (QLegendMarker *marker, markers) { | |
610 | marker->d_ptr->item()->setVisible(false); |
|
619 | marker->d_ptr->item()->setVisible(false); | |
611 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
620 | m_items->removeFromGroup(marker->d_ptr->item()); | |
612 | m_markers.removeOne(marker); |
|
621 | m_markers.removeOne(marker); | |
613 | m_markerHash.remove(marker->d_ptr->item()); |
|
622 | m_markerHash.remove(marker->d_ptr->item()); | |
614 | delete marker; |
|
623 | delete marker; | |
615 | } |
|
624 | } | |
616 | } |
|
625 | } | |
617 |
|
626 | |||
618 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) |
|
627 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) | |
619 | { |
|
628 | { | |
620 | foreach (QLegendMarker *marker, markers) { |
|
629 | foreach (QLegendMarker *marker, markers) { | |
621 | marker->setFont(m_font); |
|
630 | marker->setFont(m_font); | |
622 | marker->setLabelBrush(m_labelBrush); |
|
631 | marker->setLabelBrush(m_labelBrush); | |
623 | } |
|
632 | } | |
624 | } |
|
633 | } | |
625 |
|
634 | |||
626 |
|
635 | |||
627 | #include "moc_qlegend.cpp" |
|
636 | #include "moc_qlegend.cpp" | |
628 | #include "moc_qlegend_p.cpp" |
|
637 | #include "moc_qlegend_p.cpp" | |
629 |
|
638 | |||
630 | QT_CHARTS_END_NAMESPACE |
|
639 | QT_CHARTS_END_NAMESPACE |
@@ -1,861 +1,862 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.io |
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and Digia. |
|
12 | ** agreement between you and Digia. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | #include <QtCharts/QXYSeries> |
|
19 | #include <QtCharts/QXYSeries> | |
20 | #include <private/qxyseries_p.h> |
|
20 | #include <private/qxyseries_p.h> | |
21 | #include <private/abstractdomain_p.h> |
|
21 | #include <private/abstractdomain_p.h> | |
22 | #include <QtCharts/QValueAxis> |
|
22 | #include <QtCharts/QValueAxis> | |
23 | #include <private/xychart_p.h> |
|
23 | #include <private/xychart_p.h> | |
24 | #include <QtCharts/QXYLegendMarker> |
|
24 | #include <QtCharts/QXYLegendMarker> | |
25 | #include <private/charthelpers_p.h> |
|
25 | #include <private/charthelpers_p.h> | |
26 | #include <private/qchart_p.h> |
|
26 | #include <private/qchart_p.h> | |
27 | #include <QtGui/QPainter> |
|
27 | #include <QtGui/QPainter> | |
28 |
|
28 | |||
29 | QT_CHARTS_BEGIN_NAMESPACE |
|
29 | QT_CHARTS_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QXYSeries |
|
32 | \class QXYSeries | |
33 | \inmodule Qt Charts |
|
33 | \inmodule Qt Charts | |
34 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
34 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmltype XYSeries |
|
37 | \qmltype XYSeries | |
38 | \instantiates QXYSeries |
|
38 | \instantiates QXYSeries | |
39 | \inqmlmodule QtCharts |
|
39 | \inqmlmodule QtCharts | |
40 |
|
40 | |||
41 | \inherits AbstractSeries |
|
41 | \inherits AbstractSeries | |
42 |
|
42 | |||
43 | \brief The XYSeries type is a base type for line, spline and scatter series. |
|
43 | \brief The XYSeries type is a base type for line, spline and scatter series. | |
44 |
|
44 | |||
45 | The XYSeries class is a base class for line, spline and scatter series. |
|
45 | The XYSeries class is a base class for line, spline and scatter series. | |
46 | The class cannot be instantiated directly. |
|
46 | The class cannot be instantiated directly. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \qmlproperty AbstractAxis XYSeries::axisX |
|
50 | \qmlproperty AbstractAxis XYSeries::axisX | |
51 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for |
|
51 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for | |
52 | the series. |
|
52 | the series. | |
53 | \sa axisXTop |
|
53 | \sa axisXTop | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \qmlproperty AbstractAxis XYSeries::axisY |
|
57 | \qmlproperty AbstractAxis XYSeries::axisY | |
58 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
58 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for | |
59 | the series. |
|
59 | the series. | |
60 | \sa axisYRight |
|
60 | \sa axisYRight | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty AbstractAxis XYSeries::axisXTop |
|
64 | \qmlproperty AbstractAxis XYSeries::axisXTop | |
65 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
65 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or | |
66 | axisXTop, but not both. |
|
66 | axisXTop, but not both. | |
67 | \sa axisX |
|
67 | \sa axisX | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty AbstractAxis XYSeries::axisYRight |
|
71 | \qmlproperty AbstractAxis XYSeries::axisYRight | |
72 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
72 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY | |
73 | or axisYRight, but not both. |
|
73 | or axisYRight, but not both. | |
74 | \sa axisY |
|
74 | \sa axisY | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \qmlproperty AbstractAxis XYSeries::axisAngular |
|
78 | \qmlproperty AbstractAxis XYSeries::axisAngular | |
79 | The angular axis used for the series, drawn around the polar chart view. |
|
79 | The angular axis used for the series, drawn around the polar chart view. | |
80 | \sa axisX |
|
80 | \sa axisX | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty AbstractAxis XYSeries::axisRadial |
|
84 | \qmlproperty AbstractAxis XYSeries::axisRadial | |
85 | The radial axis used for the series, drawn inside the polar chart view. |
|
85 | The radial axis used for the series, drawn inside the polar chart view. | |
86 | \sa axisY |
|
86 | \sa axisY | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QXYSeries::pointsVisible |
|
90 | \property QXYSeries::pointsVisible | |
91 | Controls if the data points are visible and should be drawn. |
|
91 | Controls if the data points are visible and should be drawn. | |
92 | */ |
|
92 | */ | |
93 | /*! |
|
93 | /*! | |
94 | \qmlproperty bool XYSeries::pointsVisible |
|
94 | \qmlproperty bool XYSeries::pointsVisible | |
95 | Controls if the data points are visible and should be drawn. |
|
95 | Controls if the data points are visible and should be drawn. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \fn QPen QXYSeries::pen() const |
|
99 | \fn QPen QXYSeries::pen() const | |
100 | \brief Returns pen used to draw points for series. |
|
100 | \brief Returns pen used to draw points for series. | |
101 | \sa setPen() |
|
101 | \sa setPen() | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \fn QBrush QXYSeries::brush() const |
|
105 | \fn QBrush QXYSeries::brush() const | |
106 | \brief Returns brush used to draw points for series. |
|
106 | \brief Returns brush used to draw points for series. | |
107 | \sa setBrush() |
|
107 | \sa setBrush() | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \property QXYSeries::color |
|
111 | \property QXYSeries::color | |
112 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
112 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
113 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
113 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
114 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
114 | \sa QXYSeries::pen(), QXYSeries::brush() | |
115 | */ |
|
115 | */ | |
116 | /*! |
|
116 | /*! | |
117 | \qmlproperty color XYSeries::color |
|
117 | \qmlproperty color XYSeries::color | |
118 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
118 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
119 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
119 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \property QXYSeries::pointLabelsFormat |
|
123 | \property QXYSeries::pointLabelsFormat | |
124 | The \a format used for showing labels with series points. |
|
124 | The \a format used for showing labels with series points. | |
125 |
|
125 | |||
126 | QXYSeries supports the following format tags: |
|
126 | QXYSeries supports the following format tags: | |
127 | \table |
|
127 | \table | |
128 | \row |
|
128 | \row | |
129 | \li @xPoint \li The x value of the data point |
|
129 | \li @xPoint \li The x value of the data point | |
130 | \row |
|
130 | \row | |
131 | \li @yPoint \li The y value of the data point |
|
131 | \li @yPoint \li The y value of the data point | |
132 | \endtable |
|
132 | \endtable | |
133 |
|
133 | |||
134 | For example, the following usage of the format tags would produce labels that have the data |
|
134 | For example, the following usage of the format tags would produce labels that have the data | |
135 | point (x, y) shown inside brackets separated by a comma: |
|
135 | point (x, y) shown inside brackets separated by a comma: | |
136 | \code |
|
136 | \code | |
137 | series->setPointLabelsFormat("(@xPoint, @yPoint)"); |
|
137 | series->setPointLabelsFormat("(@xPoint, @yPoint)"); | |
138 | \endcode |
|
138 | \endcode | |
139 |
|
139 | |||
140 | By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot |
|
140 | By default, the labels format is set to '@xPoint, @yPoint'. The labels are shown on the plot | |
141 | area, labels on the edge of the plot area are cut. If the points are close to each other the |
|
141 | area, labels on the edge of the plot area are cut. If the points are close to each other the | |
142 | labels may overlap. |
|
142 | labels may overlap. | |
143 |
|
143 | |||
144 | \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor |
|
144 | \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor | |
145 | */ |
|
145 | */ | |
146 | /*! |
|
146 | /*! | |
147 | \qmlproperty string XYSeries::pointLabelsFormat |
|
147 | \qmlproperty string XYSeries::pointLabelsFormat | |
148 | The \a format used for showing labels with series points. |
|
148 | The \a format used for showing labels with series points. | |
149 |
|
149 | |||
150 | \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor |
|
150 | \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor | |
151 | */ |
|
151 | */ | |
152 | /*! |
|
152 | /*! | |
153 | \fn void QXYSeries::pointLabelsFormatChanged(const QString &format) |
|
153 | \fn void QXYSeries::pointLabelsFormatChanged(const QString &format) | |
154 | Signal is emitted when the \a format of data point labels is changed. |
|
154 | Signal is emitted when the \a format of data point labels is changed. | |
155 | */ |
|
155 | */ | |
156 | /*! |
|
156 | /*! | |
157 | \qmlsignal XYSeries::onPointLabelsFormatChanged(string format) |
|
157 | \qmlsignal XYSeries::onPointLabelsFormatChanged(string format) | |
158 | Signal is emitted when the \a format of data point labels is changed. |
|
158 | Signal is emitted when the \a format of data point labels is changed. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \property QXYSeries::pointLabelsVisible |
|
162 | \property QXYSeries::pointLabelsVisible | |
163 | Defines the visibility for data point labels. False by default. |
|
163 | Defines the visibility for data point labels. False by default. | |
164 |
|
164 | |||
165 | \sa QXYSeries::pointLabelsFormat |
|
165 | \sa QXYSeries::pointLabelsFormat | |
166 | */ |
|
166 | */ | |
167 | /*! |
|
167 | /*! | |
168 | \qmlproperty bool XYSeries::pointLabelsVisible |
|
168 | \qmlproperty bool XYSeries::pointLabelsVisible | |
169 | Defines the visibility for data point labels. |
|
169 | Defines the visibility for data point labels. | |
170 |
|
170 | |||
171 | \sa pointLabelsFormat |
|
171 | \sa pointLabelsFormat | |
172 | */ |
|
172 | */ | |
173 | /*! |
|
173 | /*! | |
174 | \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible) |
|
174 | \fn void QXYSeries::pointLabelsVisibilityChanged(bool visible) | |
175 | The visibility of the data point labels is changed to \a visible. |
|
175 | The visibility of the data point labels is changed to \a visible. | |
176 | */ |
|
176 | */ | |
177 | /*! |
|
177 | /*! | |
178 | \qmlsignal XYSeries::onPointLabelsVisibilityChanged(bool visible) |
|
178 | \qmlsignal XYSeries::onPointLabelsVisibilityChanged(bool visible) | |
179 | The visibility of the data point labels is changed to \a visible. |
|
179 | The visibility of the data point labels is changed to \a visible. | |
180 | */ |
|
180 | */ | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | \property QXYSeries::pointLabelsFont |
|
183 | \property QXYSeries::pointLabelsFont | |
184 | Defines the font used for data point labels. |
|
184 | Defines the font used for data point labels. | |
185 |
|
185 | |||
186 | \sa QXYSeries::pointLabelsFormat |
|
186 | \sa QXYSeries::pointLabelsFormat | |
187 | */ |
|
187 | */ | |
188 | /*! |
|
188 | /*! | |
189 | \qmlproperty font XYSeries::pointLabelsFont |
|
189 | \qmlproperty font XYSeries::pointLabelsFont | |
190 | Defines the font used for data point labels. |
|
190 | Defines the font used for data point labels. | |
191 |
|
191 | |||
192 | \sa pointLabelsFormat |
|
192 | \sa pointLabelsFormat | |
193 | */ |
|
193 | */ | |
194 | /*! |
|
194 | /*! | |
195 | \fn void QXYSeries::pointLabelsFontChanged(const QFont &font); |
|
195 | \fn void QXYSeries::pointLabelsFontChanged(const QFont &font); | |
196 | The font used for data point labels is changed to \a font. |
|
196 | The font used for data point labels is changed to \a font. | |
197 | */ |
|
197 | */ | |
198 | /*! |
|
198 | /*! | |
199 | \qmlsignal XYSeries::onPointLabelsFontChanged(Font font) |
|
199 | \qmlsignal XYSeries::onPointLabelsFontChanged(Font font) | |
200 | The font used for data point labels is changed to \a font. |
|
200 | The font used for data point labels is changed to \a font. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \property QXYSeries::pointLabelsColor |
|
204 | \property QXYSeries::pointLabelsColor | |
205 | Defines the color used for data point labels. By default, the color is the color of the brush |
|
205 | Defines the color used for data point labels. By default, the color is the color of the brush | |
206 | defined in theme for labels. |
|
206 | defined in theme for labels. | |
207 |
|
207 | |||
208 | \sa QXYSeries::pointLabelsFormat |
|
208 | \sa QXYSeries::pointLabelsFormat | |
209 | */ |
|
209 | */ | |
210 | /*! |
|
210 | /*! | |
211 | \qmlproperty font XYSeries::pointLabelsColor |
|
211 | \qmlproperty font XYSeries::pointLabelsColor | |
212 | Defines the color used for data point labels. By default, the color is the color of the brush |
|
212 | Defines the color used for data point labels. By default, the color is the color of the brush | |
213 | defined in theme for labels. |
|
213 | defined in theme for labels. | |
214 |
|
214 | |||
215 | \sa pointLabelsFormat |
|
215 | \sa pointLabelsFormat | |
216 | */ |
|
216 | */ | |
217 | /*! |
|
217 | /*! | |
218 | \fn void QXYSeries::pointLabelsColorChanged(const QColor &color); |
|
218 | \fn void QXYSeries::pointLabelsColorChanged(const QColor &color); | |
219 | The color used for data point labels is changed to \a color. |
|
219 | The color used for data point labels is changed to \a color. | |
220 | */ |
|
220 | */ | |
221 | /*! |
|
221 | /*! | |
222 | \qmlsignal XYSeries::onPointLabelsColorChanged(Color color) |
|
222 | \qmlsignal XYSeries::onPointLabelsColorChanged(Color color) | |
223 | The color used for data point labels is changed to \a color. |
|
223 | The color used for data point labels is changed to \a color. | |
224 | */ |
|
224 | */ | |
225 |
|
225 | |||
226 | /*! |
|
226 | /*! | |
227 | \fn void QXYSeries::clicked(const QPointF& point) |
|
227 | \fn void QXYSeries::clicked(const QPointF& point) | |
228 | \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point |
|
228 | \brief Signal is emitted when user clicks the \a point on chart. The \a point is the point | |
229 | where the press was triggered. |
|
229 | where the press was triggered. | |
230 | \sa pressed, released, doubleClicked |
|
230 | \sa pressed, released, doubleClicked | |
231 | */ |
|
231 | */ | |
232 | /*! |
|
232 | /*! | |
233 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
233 | \qmlsignal XYSeries::onClicked(QPointF point) | |
234 | Signal is emitted when user clicks the \a point on chart. The \a point is the point where the |
|
234 | Signal is emitted when user clicks the \a point on chart. The \a point is the point where the | |
235 | press was triggered. For example: |
|
235 | press was triggered. For example: | |
236 | \code |
|
236 | \code | |
237 | LineSeries { |
|
237 | LineSeries { | |
238 | XYPoint { x: 0; y: 0 } |
|
238 | XYPoint { x: 0; y: 0 } | |
239 | XYPoint { x: 1.1; y: 2.1 } |
|
239 | XYPoint { x: 1.1; y: 2.1 } | |
240 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
240 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
241 | } |
|
241 | } | |
242 | \endcode |
|
242 | \endcode | |
243 | \sa onPressed, onReleased, onDoubleClicked |
|
243 | \sa onPressed, onReleased, onDoubleClicked | |
244 | */ |
|
244 | */ | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | \fn void QXYSeries::hovered(const QPointF &point, bool state) |
|
247 | \fn void QXYSeries::hovered(const QPointF &point, bool state) | |
248 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
248 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
249 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
249 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
250 | the series. |
|
250 | the series. | |
251 | */ |
|
251 | */ | |
252 | /*! |
|
252 | /*! | |
253 | \qmlsignal XYSeries::onHovered(point point, bool state) |
|
253 | \qmlsignal XYSeries::onHovered(point point, bool state) | |
254 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
254 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
255 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
255 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
256 | the series. |
|
256 | the series. | |
257 | */ |
|
257 | */ | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | \fn void QXYSeries::pressed(const QPointF& point) |
|
260 | \fn void QXYSeries::pressed(const QPointF& point) | |
261 | \brief Signal is emitted when user presses the \a point on chart. |
|
261 | \brief Signal is emitted when user presses the \a point on chart. | |
262 | \sa clicked, released, doubleClicked |
|
262 | \sa clicked, released, doubleClicked | |
263 | */ |
|
263 | */ | |
264 | /*! |
|
264 | /*! | |
265 | \qmlsignal XYSeries::onPressed(QPointF point) |
|
265 | \qmlsignal XYSeries::onPressed(QPointF point) | |
266 | Signal is emitted when user presses the \a point on chart. For example: |
|
266 | Signal is emitted when user presses the \a point on chart. For example: | |
267 | \code |
|
267 | \code | |
268 | LineSeries { |
|
268 | LineSeries { | |
269 | XYPoint { x: 0; y: 0 } |
|
269 | XYPoint { x: 0; y: 0 } | |
270 | XYPoint { x: 1.1; y: 2.1 } |
|
270 | XYPoint { x: 1.1; y: 2.1 } | |
271 | onPressed: console.log("onPressed: " + point.x + ", " + point.y); |
|
271 | onPressed: console.log("onPressed: " + point.x + ", " + point.y); | |
272 | } |
|
272 | } | |
273 | \endcode |
|
273 | \endcode | |
274 | \sa onClicked, onReleased, onDoubleClicked |
|
274 | \sa onClicked, onReleased, onDoubleClicked | |
275 | */ |
|
275 | */ | |
276 |
|
276 | |||
277 | /*! |
|
277 | /*! | |
278 | \fn void QXYSeries::released(const QPointF& point) |
|
278 | \fn void QXYSeries::released(const QPointF& point) | |
279 | \brief Signal is emitted when user releases a press that was triggered on a \a point on chart. |
|
279 | \brief Signal is emitted when user releases a press that was triggered on a \a point on chart. | |
280 | \sa pressed, clicked, doubleClicked |
|
280 | \sa pressed, clicked, doubleClicked | |
281 | */ |
|
281 | */ | |
282 | /*! |
|
282 | /*! | |
283 | \qmlsignal XYSeries::onReleased(QPointF point) |
|
283 | \qmlsignal XYSeries::onReleased(QPointF point) | |
284 | Signal is emitted when user releases a press that was triggered on a \a point on chart. |
|
284 | Signal is emitted when user releases a press that was triggered on a \a point on chart. | |
285 | For example: |
|
285 | For example: | |
286 | \code |
|
286 | \code | |
287 | LineSeries { |
|
287 | LineSeries { | |
288 | XYPoint { x: 0; y: 0 } |
|
288 | XYPoint { x: 0; y: 0 } | |
289 | XYPoint { x: 1.1; y: 2.1 } |
|
289 | XYPoint { x: 1.1; y: 2.1 } | |
290 | onReleased: console.log("onReleased: " + point.x + ", " + point.y); |
|
290 | onReleased: console.log("onReleased: " + point.x + ", " + point.y); | |
291 | } |
|
291 | } | |
292 | \endcode |
|
292 | \endcode | |
293 | \sa onPressed, onClicked, onDoubleClicked |
|
293 | \sa onPressed, onClicked, onDoubleClicked | |
294 | */ |
|
294 | */ | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | \fn void QXYSeries::doubleClicked(const QPointF& point) |
|
297 | \fn void QXYSeries::doubleClicked(const QPointF& point) | |
298 | \brief Signal is emitted when user doubleclicks the \a point on chart. The \a point is the |
|
298 | \brief Signal is emitted when user doubleclicks the \a point on chart. The \a point is the | |
299 | point where the first press was triggered. |
|
299 | point where the first press was triggered. | |
300 | \sa pressed, released, clicked |
|
300 | \sa pressed, released, clicked | |
301 | */ |
|
301 | */ | |
302 | /*! |
|
302 | /*! | |
303 | \qmlsignal XYSeries::onDoubleClicked(QPointF point) |
|
303 | \qmlsignal XYSeries::onDoubleClicked(QPointF point) | |
304 | Signal is emitted when user doubleclicks the \a point on chart. The \a point is the point where |
|
304 | Signal is emitted when user doubleclicks the \a point on chart. The \a point is the point where | |
305 | the first press was triggered. For example: |
|
305 | the first press was triggered. For example: | |
306 | \code |
|
306 | \code | |
307 | LineSeries { |
|
307 | LineSeries { | |
308 | XYPoint { x: 0; y: 0 } |
|
308 | XYPoint { x: 0; y: 0 } | |
309 | XYPoint { x: 1.1; y: 2.1 } |
|
309 | XYPoint { x: 1.1; y: 2.1 } | |
310 | onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y); |
|
310 | onDoubleClicked: console.log("onDoubleClicked: " + point.x + ", " + point.y); | |
311 | } |
|
311 | } | |
312 | \endcode |
|
312 | \endcode | |
313 | \sa onPressed, onReleased, onClicked |
|
313 | \sa onPressed, onReleased, onClicked | |
314 | */ |
|
314 | */ | |
315 |
|
315 | |||
316 | /*! |
|
316 | /*! | |
317 | \fn void QXYSeries::pointReplaced(int index) |
|
317 | \fn void QXYSeries::pointReplaced(int index) | |
318 | Signal is emitted when a point has been replaced at \a index. |
|
318 | Signal is emitted when a point has been replaced at \a index. | |
319 | \sa replace() |
|
319 | \sa replace() | |
320 | */ |
|
320 | */ | |
321 | /*! |
|
321 | /*! | |
322 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
322 | \qmlsignal XYSeries::onPointReplaced(int index) | |
323 | Signal is emitted when a point has been replaced at \a index. |
|
323 | Signal is emitted when a point has been replaced at \a index. | |
324 | */ |
|
324 | */ | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | \fn void QXYSeries::pointsReplaced() |
|
327 | \fn void QXYSeries::pointsReplaced() | |
328 | Signal is emitted when all points have been replaced with other points. |
|
328 | Signal is emitted when all points have been replaced with other points. | |
329 | \sa replace() |
|
329 | \sa replace() | |
330 | */ |
|
330 | */ | |
331 | /*! |
|
331 | /*! | |
332 | \qmlsignal XYSeries::onPointsReplaced() |
|
332 | \qmlsignal XYSeries::onPointsReplaced() | |
|
333 | Signal is emitted when all points have been replaced with other points. | |||
333 | */ |
|
334 | */ | |
334 |
|
335 | |||
335 | /*! |
|
336 | /*! | |
336 | \fn void QXYSeries::pointAdded(int index) |
|
337 | \fn void QXYSeries::pointAdded(int index) | |
337 | Signal is emitted when a point has been added at \a index. |
|
338 | Signal is emitted when a point has been added at \a index. | |
338 | \sa append(), insert() |
|
339 | \sa append(), insert() | |
339 | */ |
|
340 | */ | |
340 | /*! |
|
341 | /*! | |
341 | \qmlsignal XYSeries::onPointAdded(int index) |
|
342 | \qmlsignal XYSeries::onPointAdded(int index) | |
342 | Signal is emitted when a point has been added at \a index. |
|
343 | Signal is emitted when a point has been added at \a index. | |
343 | */ |
|
344 | */ | |
344 |
|
345 | |||
345 | /*! |
|
346 | /*! | |
346 | \fn void QXYSeries::pointRemoved(int index) |
|
347 | \fn void QXYSeries::pointRemoved(int index) | |
347 | Signal is emitted when a point has been removed from \a index. |
|
348 | Signal is emitted when a point has been removed from \a index. | |
348 | \sa remove() |
|
349 | \sa remove() | |
349 | */ |
|
350 | */ | |
350 |
|
351 | |||
351 | /*! |
|
352 | /*! | |
352 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
353 | \qmlsignal XYSeries::onPointRemoved(int index) | |
353 | Signal is emitted when a point has been removed from \a index. |
|
354 | Signal is emitted when a point has been removed from \a index. | |
354 | */ |
|
355 | */ | |
355 |
|
356 | |||
356 | /*! |
|
357 | /*! | |
357 | \fn void QXYSeries::colorChanged(QColor color) |
|
358 | \fn void QXYSeries::colorChanged(QColor color) | |
358 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
359 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
359 | */ |
|
360 | */ | |
360 | /*! |
|
361 | /*! | |
361 | \qmlsignal XYSeries::onColorChanged(color color) |
|
362 | \qmlsignal XYSeries::onColorChanged(color color) | |
362 | Signal is emitted when the line (pen) color has changed to \a color. |
|
363 | Signal is emitted when the line (pen) color has changed to \a color. | |
363 | */ |
|
364 | */ | |
364 |
|
365 | |||
365 | /*! |
|
366 | /*! | |
366 | \fn void QXYSeriesPrivate::updated() |
|
367 | \fn void QXYSeriesPrivate::updated() | |
367 | \brief \internal |
|
368 | \brief \internal | |
368 | */ |
|
369 | */ | |
369 |
|
370 | |||
370 | /*! |
|
371 | /*! | |
371 | \qmlmethod XYSeries::append(real x, real y) |
|
372 | \qmlmethod XYSeries::append(real x, real y) | |
372 | Append point (\a x, \a y) to the series |
|
373 | Append point (\a x, \a y) to the series | |
373 | */ |
|
374 | */ | |
374 |
|
375 | |||
375 | /*! |
|
376 | /*! | |
376 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
377 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
377 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
378 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
378 | exist. |
|
379 | exist. | |
379 | */ |
|
380 | */ | |
380 |
|
381 | |||
381 | /*! |
|
382 | /*! | |
382 | \qmlmethod XYSeries::remove(real x, real y) |
|
383 | \qmlmethod XYSeries::remove(real x, real y) | |
383 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
384 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
384 | */ |
|
385 | */ | |
385 |
|
386 | |||
386 | /*! |
|
387 | /*! | |
387 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
388 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
388 | 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 |
|
389 | 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 | |
389 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
390 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
390 | */ |
|
391 | */ | |
391 |
|
392 | |||
392 | /*! |
|
393 | /*! | |
393 | \qmlmethod QPointF XYSeries::at(int index) |
|
394 | \qmlmethod QPointF XYSeries::at(int index) | |
394 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
395 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
395 | */ |
|
396 | */ | |
396 |
|
397 | |||
397 | /*! |
|
398 | /*! | |
398 | \internal |
|
399 | \internal | |
399 |
|
400 | |||
400 | Constructs empty series object which is a child of \a parent. |
|
401 | Constructs empty series object which is a child of \a parent. | |
401 | When series object is added to QChart instance ownerships is transferred. |
|
402 | When series object is added to QChart instance ownerships is transferred. | |
402 | */ |
|
403 | */ | |
403 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) |
|
404 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) | |
404 | : QAbstractSeries(d, parent) |
|
405 | : QAbstractSeries(d, parent) | |
405 | { |
|
406 | { | |
406 | } |
|
407 | } | |
407 |
|
408 | |||
408 | /*! |
|
409 | /*! | |
409 | Destroys the object. Series added to QChart instances are owned by those, |
|
410 | Destroys the object. Series added to QChart instances are owned by those, | |
410 | and are destroyed when QChart instances are destroyed. |
|
411 | and are destroyed when QChart instances are destroyed. | |
411 | */ |
|
412 | */ | |
412 | QXYSeries::~QXYSeries() |
|
413 | QXYSeries::~QXYSeries() | |
413 | { |
|
414 | { | |
414 | } |
|
415 | } | |
415 |
|
416 | |||
416 | /*! |
|
417 | /*! | |
417 | Adds data point (\a x, \a y) to the series. |
|
418 | Adds data point (\a x, \a y) to the series. | |
418 | */ |
|
419 | */ | |
419 | void QXYSeries::append(qreal x, qreal y) |
|
420 | void QXYSeries::append(qreal x, qreal y) | |
420 | { |
|
421 | { | |
421 | append(QPointF(x, y)); |
|
422 | append(QPointF(x, y)); | |
422 | } |
|
423 | } | |
423 |
|
424 | |||
424 | /*! |
|
425 | /*! | |
425 | This is an overloaded function. |
|
426 | This is an overloaded function. | |
426 | Adds data \a point to the series. |
|
427 | Adds data \a point to the series. | |
427 | */ |
|
428 | */ | |
428 | void QXYSeries::append(const QPointF &point) |
|
429 | void QXYSeries::append(const QPointF &point) | |
429 | { |
|
430 | { | |
430 | Q_D(QXYSeries); |
|
431 | Q_D(QXYSeries); | |
431 |
|
432 | |||
432 | if (isValidValue(point)) { |
|
433 | if (isValidValue(point)) { | |
433 | d->m_points << point; |
|
434 | d->m_points << point; | |
434 | emit pointAdded(d->m_points.count() - 1); |
|
435 | emit pointAdded(d->m_points.count() - 1); | |
435 | } |
|
436 | } | |
436 | } |
|
437 | } | |
437 |
|
438 | |||
438 | /*! |
|
439 | /*! | |
439 | This is an overloaded function. |
|
440 | This is an overloaded function. | |
440 | Adds list of data \a points to the series. |
|
441 | Adds list of data \a points to the series. | |
441 | */ |
|
442 | */ | |
442 | void QXYSeries::append(const QList<QPointF> &points) |
|
443 | void QXYSeries::append(const QList<QPointF> &points) | |
443 | { |
|
444 | { | |
444 | foreach (const QPointF &point , points) |
|
445 | foreach (const QPointF &point , points) | |
445 | append(point); |
|
446 | append(point); | |
446 | } |
|
447 | } | |
447 |
|
448 | |||
448 | /*! |
|
449 | /*! | |
449 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). |
|
450 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). | |
450 | \sa QXYSeries::pointReplaced() |
|
451 | \sa QXYSeries::pointReplaced() | |
451 | */ |
|
452 | */ | |
452 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
|
453 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) | |
453 | { |
|
454 | { | |
454 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); |
|
455 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); | |
455 | } |
|
456 | } | |
456 |
|
457 | |||
457 | /*! |
|
458 | /*! | |
458 | Replaces \a oldPoint with \a newPoint. |
|
459 | Replaces \a oldPoint with \a newPoint. | |
459 | \sa QXYSeries::pointReplaced() |
|
460 | \sa QXYSeries::pointReplaced() | |
460 | */ |
|
461 | */ | |
461 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) |
|
462 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) | |
462 | { |
|
463 | { | |
463 | Q_D(QXYSeries); |
|
464 | Q_D(QXYSeries); | |
464 | int index = d->m_points.indexOf(oldPoint); |
|
465 | int index = d->m_points.indexOf(oldPoint); | |
465 | if (index == -1) |
|
466 | if (index == -1) | |
466 | return; |
|
467 | return; | |
467 | replace(index, newPoint); |
|
468 | replace(index, newPoint); | |
468 | } |
|
469 | } | |
469 |
|
470 | |||
470 | /*! |
|
471 | /*! | |
471 | Replaces the point at \a index with data point (\a newX, \a newY). |
|
472 | Replaces the point at \a index with data point (\a newX, \a newY). | |
472 | \sa QXYSeries::pointReplaced() |
|
473 | \sa QXYSeries::pointReplaced() | |
473 | */ |
|
474 | */ | |
474 | void QXYSeries::replace(int index, qreal newX, qreal newY) |
|
475 | void QXYSeries::replace(int index, qreal newX, qreal newY) | |
475 | { |
|
476 | { | |
476 | replace(index, QPointF(newX, newY)); |
|
477 | replace(index, QPointF(newX, newY)); | |
477 | } |
|
478 | } | |
478 |
|
479 | |||
479 | /*! |
|
480 | /*! | |
480 | Replaces the point at \a index with \a newPoint. |
|
481 | Replaces the point at \a index with \a newPoint. | |
481 | \sa QXYSeries::pointReplaced() |
|
482 | \sa QXYSeries::pointReplaced() | |
482 | */ |
|
483 | */ | |
483 | void QXYSeries::replace(int index, const QPointF &newPoint) |
|
484 | void QXYSeries::replace(int index, const QPointF &newPoint) | |
484 | { |
|
485 | { | |
485 | Q_D(QXYSeries); |
|
486 | Q_D(QXYSeries); | |
486 | if (isValidValue(newPoint)) { |
|
487 | if (isValidValue(newPoint)) { | |
487 | d->m_points[index] = newPoint; |
|
488 | d->m_points[index] = newPoint; | |
488 | emit pointReplaced(index); |
|
489 | emit pointReplaced(index); | |
489 | } |
|
490 | } | |
490 | } |
|
491 | } | |
491 |
|
492 | |||
492 | /*! |
|
493 | /*! | |
493 | Replaces the current points with \a points. |
|
494 | Replaces the current points with \a points. | |
494 | \note This is much faster than replacing data points one by one, |
|
495 | \note This is much faster than replacing data points one by one, | |
495 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
496 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() | |
496 | when the points have been replaced. |
|
497 | when the points have been replaced. | |
497 | \sa QXYSeries::pointsReplaced() |
|
498 | \sa QXYSeries::pointsReplaced() | |
498 | */ |
|
499 | */ | |
499 | void QXYSeries::replace(QList<QPointF> points) |
|
500 | void QXYSeries::replace(QList<QPointF> points) | |
500 | { |
|
501 | { | |
501 | Q_D(QXYSeries); |
|
502 | Q_D(QXYSeries); | |
502 | d->m_points = points.toVector(); |
|
503 | d->m_points = points.toVector(); | |
503 | emit pointsReplaced(); |
|
504 | emit pointsReplaced(); | |
504 | } |
|
505 | } | |
505 |
|
506 | |||
506 | /*! |
|
507 | /*! | |
507 | Removes the point (\a x, \a y) from the series. |
|
508 | Removes the point (\a x, \a y) from the series. | |
508 | */ |
|
509 | */ | |
509 | void QXYSeries::remove(qreal x, qreal y) |
|
510 | void QXYSeries::remove(qreal x, qreal y) | |
510 | { |
|
511 | { | |
511 | remove(QPointF(x, y)); |
|
512 | remove(QPointF(x, y)); | |
512 | } |
|
513 | } | |
513 |
|
514 | |||
514 | /*! |
|
515 | /*! | |
515 | Removes the \a point from the series. |
|
516 | Removes the \a point from the series. | |
516 | */ |
|
517 | */ | |
517 | void QXYSeries::remove(const QPointF &point) |
|
518 | void QXYSeries::remove(const QPointF &point) | |
518 | { |
|
519 | { | |
519 | Q_D(QXYSeries); |
|
520 | Q_D(QXYSeries); | |
520 | int index = d->m_points.indexOf(point); |
|
521 | int index = d->m_points.indexOf(point); | |
521 | if (index == -1) |
|
522 | if (index == -1) | |
522 | return; |
|
523 | return; | |
523 | remove(index); |
|
524 | remove(index); | |
524 | } |
|
525 | } | |
525 |
|
526 | |||
526 | /*! |
|
527 | /*! | |
527 | Removes the point at \a index from the series. |
|
528 | Removes the point at \a index from the series. | |
528 | */ |
|
529 | */ | |
529 | void QXYSeries::remove(int index) |
|
530 | void QXYSeries::remove(int index) | |
530 | { |
|
531 | { | |
531 | Q_D(QXYSeries); |
|
532 | Q_D(QXYSeries); | |
532 | d->m_points.remove(index); |
|
533 | d->m_points.remove(index); | |
533 | emit pointRemoved(index); |
|
534 | emit pointRemoved(index); | |
534 | } |
|
535 | } | |
535 |
|
536 | |||
536 | /*! |
|
537 | /*! | |
537 | Inserts a \a point in the series at \a index position. |
|
538 | Inserts a \a point in the series at \a index position. | |
538 | */ |
|
539 | */ | |
539 | void QXYSeries::insert(int index, const QPointF &point) |
|
540 | void QXYSeries::insert(int index, const QPointF &point) | |
540 | { |
|
541 | { | |
541 | Q_D(QXYSeries); |
|
542 | Q_D(QXYSeries); | |
542 | if (isValidValue(point)) { |
|
543 | if (isValidValue(point)) { | |
543 | d->m_points.insert(index, point); |
|
544 | d->m_points.insert(index, point); | |
544 | emit pointAdded(index); |
|
545 | emit pointAdded(index); | |
545 | } |
|
546 | } | |
546 | } |
|
547 | } | |
547 |
|
548 | |||
548 | /*! |
|
549 | /*! | |
549 | Removes all points from the series. |
|
550 | Removes all points from the series. | |
550 | */ |
|
551 | */ | |
551 | void QXYSeries::clear() |
|
552 | void QXYSeries::clear() | |
552 | { |
|
553 | { | |
553 | Q_D(QXYSeries); |
|
554 | Q_D(QXYSeries); | |
554 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
555 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
555 | remove(d->m_points.at(i)); |
|
556 | remove(d->m_points.at(i)); | |
556 | } |
|
557 | } | |
557 |
|
558 | |||
558 | /*! |
|
559 | /*! | |
559 | Returns list of points in the series. |
|
560 | Returns list of points in the series. | |
560 | */ |
|
561 | */ | |
561 | QList<QPointF> QXYSeries::points() const |
|
562 | QList<QPointF> QXYSeries::points() const | |
562 | { |
|
563 | { | |
563 | Q_D(const QXYSeries); |
|
564 | Q_D(const QXYSeries); | |
564 | return d->m_points.toList(); |
|
565 | return d->m_points.toList(); | |
565 | } |
|
566 | } | |
566 |
|
567 | |||
567 | /*! |
|
568 | /*! | |
568 | Returns point at \a index in internal points vector. |
|
569 | Returns point at \a index in internal points vector. | |
569 | */ |
|
570 | */ | |
570 | const QPointF &QXYSeries::at(int index) const |
|
571 | const QPointF &QXYSeries::at(int index) const | |
571 | { |
|
572 | { | |
572 | Q_D(const QXYSeries); |
|
573 | Q_D(const QXYSeries); | |
573 | return d->m_points.at(index); |
|
574 | return d->m_points.at(index); | |
574 | } |
|
575 | } | |
575 |
|
576 | |||
576 | /*! |
|
577 | /*! | |
577 | Returns number of data points within series. |
|
578 | Returns number of data points within series. | |
578 | */ |
|
579 | */ | |
579 | int QXYSeries::count() const |
|
580 | int QXYSeries::count() const | |
580 | { |
|
581 | { | |
581 | Q_D(const QXYSeries); |
|
582 | Q_D(const QXYSeries); | |
582 | return d->m_points.count(); |
|
583 | return d->m_points.count(); | |
583 | } |
|
584 | } | |
584 |
|
585 | |||
585 |
|
586 | |||
586 | /*! |
|
587 | /*! | |
587 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
588 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
588 | pen from chart theme is used. |
|
589 | pen from chart theme is used. | |
589 | \sa QChart::setTheme() |
|
590 | \sa QChart::setTheme() | |
590 | */ |
|
591 | */ | |
591 | void QXYSeries::setPen(const QPen &pen) |
|
592 | void QXYSeries::setPen(const QPen &pen) | |
592 | { |
|
593 | { | |
593 | Q_D(QXYSeries); |
|
594 | Q_D(QXYSeries); | |
594 | if (d->m_pen != pen) { |
|
595 | if (d->m_pen != pen) { | |
595 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
596 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
596 | d->m_pen = pen; |
|
597 | d->m_pen = pen; | |
597 | emit d->updated(); |
|
598 | emit d->updated(); | |
598 | if (emitColorChanged) |
|
599 | if (emitColorChanged) | |
599 | emit colorChanged(pen.color()); |
|
600 | emit colorChanged(pen.color()); | |
600 | } |
|
601 | } | |
601 | } |
|
602 | } | |
602 |
|
603 | |||
603 | QPen QXYSeries::pen() const |
|
604 | QPen QXYSeries::pen() const | |
604 | { |
|
605 | { | |
605 | Q_D(const QXYSeries); |
|
606 | Q_D(const QXYSeries); | |
606 | if (d->m_pen == QChartPrivate::defaultPen()) |
|
607 | if (d->m_pen == QChartPrivate::defaultPen()) | |
607 | return QPen(); |
|
608 | return QPen(); | |
608 | else |
|
609 | else | |
609 | return d->m_pen; |
|
610 | return d->m_pen; | |
610 | } |
|
611 | } | |
611 |
|
612 | |||
612 | /*! |
|
613 | /*! | |
613 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
614 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
614 | from chart theme setting is used. |
|
615 | from chart theme setting is used. | |
615 | \sa QChart::setTheme() |
|
616 | \sa QChart::setTheme() | |
616 | */ |
|
617 | */ | |
617 | void QXYSeries::setBrush(const QBrush &brush) |
|
618 | void QXYSeries::setBrush(const QBrush &brush) | |
618 | { |
|
619 | { | |
619 | Q_D(QXYSeries); |
|
620 | Q_D(QXYSeries); | |
620 | if (d->m_brush != brush) { |
|
621 | if (d->m_brush != brush) { | |
621 | d->m_brush = brush; |
|
622 | d->m_brush = brush; | |
622 | emit d->updated(); |
|
623 | emit d->updated(); | |
623 | } |
|
624 | } | |
624 | } |
|
625 | } | |
625 |
|
626 | |||
626 | QBrush QXYSeries::brush() const |
|
627 | QBrush QXYSeries::brush() const | |
627 | { |
|
628 | { | |
628 | Q_D(const QXYSeries); |
|
629 | Q_D(const QXYSeries); | |
629 | if (d->m_brush == QChartPrivate::defaultBrush()) |
|
630 | if (d->m_brush == QChartPrivate::defaultBrush()) | |
630 | return QBrush(); |
|
631 | return QBrush(); | |
631 | else |
|
632 | else | |
632 | return d->m_brush; |
|
633 | return d->m_brush; | |
633 | } |
|
634 | } | |
634 |
|
635 | |||
635 | void QXYSeries::setColor(const QColor &color) |
|
636 | void QXYSeries::setColor(const QColor &color) | |
636 | { |
|
637 | { | |
637 | QPen p = pen(); |
|
638 | QPen p = pen(); | |
638 | if (p.color() != color) { |
|
639 | if (p.color() != color) { | |
639 | p.setColor(color); |
|
640 | p.setColor(color); | |
640 | setPen(p); |
|
641 | setPen(p); | |
641 | } |
|
642 | } | |
642 | } |
|
643 | } | |
643 |
|
644 | |||
644 | QColor QXYSeries::color() const |
|
645 | QColor QXYSeries::color() const | |
645 | { |
|
646 | { | |
646 | return pen().color(); |
|
647 | return pen().color(); | |
647 | } |
|
648 | } | |
648 |
|
649 | |||
649 | void QXYSeries::setPointsVisible(bool visible) |
|
650 | void QXYSeries::setPointsVisible(bool visible) | |
650 | { |
|
651 | { | |
651 | Q_D(QXYSeries); |
|
652 | Q_D(QXYSeries); | |
652 | if (d->m_pointsVisible != visible) { |
|
653 | if (d->m_pointsVisible != visible) { | |
653 | d->m_pointsVisible = visible; |
|
654 | d->m_pointsVisible = visible; | |
654 | emit d->updated(); |
|
655 | emit d->updated(); | |
655 | } |
|
656 | } | |
656 | } |
|
657 | } | |
657 |
|
658 | |||
658 | bool QXYSeries::pointsVisible() const |
|
659 | bool QXYSeries::pointsVisible() const | |
659 | { |
|
660 | { | |
660 | Q_D(const QXYSeries); |
|
661 | Q_D(const QXYSeries); | |
661 | return d->m_pointsVisible; |
|
662 | return d->m_pointsVisible; | |
662 | } |
|
663 | } | |
663 |
|
664 | |||
664 | void QXYSeries::setPointLabelsFormat(const QString &format) |
|
665 | void QXYSeries::setPointLabelsFormat(const QString &format) | |
665 | { |
|
666 | { | |
666 | Q_D(QXYSeries); |
|
667 | Q_D(QXYSeries); | |
667 | if (d->m_pointLabelsFormat != format) { |
|
668 | if (d->m_pointLabelsFormat != format) { | |
668 | d->m_pointLabelsFormat = format; |
|
669 | d->m_pointLabelsFormat = format; | |
669 | emit pointLabelsFormatChanged(format); |
|
670 | emit pointLabelsFormatChanged(format); | |
670 | } |
|
671 | } | |
671 | } |
|
672 | } | |
672 |
|
673 | |||
673 | QString QXYSeries::pointLabelsFormat() const |
|
674 | QString QXYSeries::pointLabelsFormat() const | |
674 | { |
|
675 | { | |
675 | Q_D(const QXYSeries); |
|
676 | Q_D(const QXYSeries); | |
676 | return d->m_pointLabelsFormat; |
|
677 | return d->m_pointLabelsFormat; | |
677 | } |
|
678 | } | |
678 |
|
679 | |||
679 | void QXYSeries::setPointLabelsVisible(bool visible) |
|
680 | void QXYSeries::setPointLabelsVisible(bool visible) | |
680 | { |
|
681 | { | |
681 | Q_D(QXYSeries); |
|
682 | Q_D(QXYSeries); | |
682 | if (d->m_pointLabelsVisible != visible) { |
|
683 | if (d->m_pointLabelsVisible != visible) { | |
683 | d->m_pointLabelsVisible = visible; |
|
684 | d->m_pointLabelsVisible = visible; | |
684 | emit pointLabelsVisibilityChanged(visible); |
|
685 | emit pointLabelsVisibilityChanged(visible); | |
685 | } |
|
686 | } | |
686 | } |
|
687 | } | |
687 |
|
688 | |||
688 | bool QXYSeries::pointLabelsVisible() const |
|
689 | bool QXYSeries::pointLabelsVisible() const | |
689 | { |
|
690 | { | |
690 | Q_D(const QXYSeries); |
|
691 | Q_D(const QXYSeries); | |
691 | return d->m_pointLabelsVisible; |
|
692 | return d->m_pointLabelsVisible; | |
692 | } |
|
693 | } | |
693 |
|
694 | |||
694 | void QXYSeries::setPointLabelsFont(const QFont &font) |
|
695 | void QXYSeries::setPointLabelsFont(const QFont &font) | |
695 | { |
|
696 | { | |
696 | Q_D(QXYSeries); |
|
697 | Q_D(QXYSeries); | |
697 | if (d->m_pointLabelsFont != font) { |
|
698 | if (d->m_pointLabelsFont != font) { | |
698 | d->m_pointLabelsFont = font; |
|
699 | d->m_pointLabelsFont = font; | |
699 | emit pointLabelsFontChanged(font); |
|
700 | emit pointLabelsFontChanged(font); | |
700 | } |
|
701 | } | |
701 | } |
|
702 | } | |
702 |
|
703 | |||
703 | QFont QXYSeries::pointLabelsFont() const |
|
704 | QFont QXYSeries::pointLabelsFont() const | |
704 | { |
|
705 | { | |
705 | Q_D(const QXYSeries); |
|
706 | Q_D(const QXYSeries); | |
706 | return d->m_pointLabelsFont; |
|
707 | return d->m_pointLabelsFont; | |
707 | } |
|
708 | } | |
708 |
|
709 | |||
709 | void QXYSeries::setPointLabelsColor(const QColor &color) |
|
710 | void QXYSeries::setPointLabelsColor(const QColor &color) | |
710 | { |
|
711 | { | |
711 | Q_D(QXYSeries); |
|
712 | Q_D(QXYSeries); | |
712 | if (d->m_pointLabelsColor != color) { |
|
713 | if (d->m_pointLabelsColor != color) { | |
713 | d->m_pointLabelsColor = color; |
|
714 | d->m_pointLabelsColor = color; | |
714 | emit pointLabelsColorChanged(color); |
|
715 | emit pointLabelsColorChanged(color); | |
715 | } |
|
716 | } | |
716 | } |
|
717 | } | |
717 |
|
718 | |||
718 | QColor QXYSeries::pointLabelsColor() const |
|
719 | QColor QXYSeries::pointLabelsColor() const | |
719 | { |
|
720 | { | |
720 | Q_D(const QXYSeries); |
|
721 | Q_D(const QXYSeries); | |
721 | if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) |
|
722 | if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) | |
722 | return QPen().color(); |
|
723 | return QPen().color(); | |
723 | else |
|
724 | else | |
724 | return d->m_pointLabelsColor; |
|
725 | return d->m_pointLabelsColor; | |
725 | } |
|
726 | } | |
726 |
|
727 | |||
727 | /*! |
|
728 | /*! | |
728 | Stream operator for adding a data \a point to the series. |
|
729 | Stream operator for adding a data \a point to the series. | |
729 | \sa append() |
|
730 | \sa append() | |
730 | */ |
|
731 | */ | |
731 | QXYSeries &QXYSeries::operator<< (const QPointF &point) |
|
732 | QXYSeries &QXYSeries::operator<< (const QPointF &point) | |
732 | { |
|
733 | { | |
733 | append(point); |
|
734 | append(point); | |
734 | return *this; |
|
735 | return *this; | |
735 | } |
|
736 | } | |
736 |
|
737 | |||
737 |
|
738 | |||
738 | /*! |
|
739 | /*! | |
739 | Stream operator for adding a list of \a points to the series. |
|
740 | Stream operator for adding a list of \a points to the series. | |
740 | \sa append() |
|
741 | \sa append() | |
741 | */ |
|
742 | */ | |
742 |
|
743 | |||
743 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) |
|
744 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) | |
744 | { |
|
745 | { | |
745 | append(points); |
|
746 | append(points); | |
746 | return *this; |
|
747 | return *this; | |
747 | } |
|
748 | } | |
748 |
|
749 | |||
749 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
750 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
750 |
|
751 | |||
751 |
|
752 | |||
752 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) |
|
753 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) | |
753 | : QAbstractSeriesPrivate(q), |
|
754 | : QAbstractSeriesPrivate(q), | |
754 | m_pen(QChartPrivate::defaultPen()), |
|
755 | m_pen(QChartPrivate::defaultPen()), | |
755 | m_brush(QChartPrivate::defaultBrush()), |
|
756 | m_brush(QChartPrivate::defaultBrush()), | |
756 | m_pointsVisible(false), |
|
757 | m_pointsVisible(false), | |
757 | m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), |
|
758 | m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), | |
758 | m_pointLabelsVisible(false), |
|
759 | m_pointLabelsVisible(false), | |
759 | m_pointLabelsFont(QChartPrivate::defaultFont()), |
|
760 | m_pointLabelsFont(QChartPrivate::defaultFont()), | |
760 | m_pointLabelsColor(QChartPrivate::defaultPen().color()) |
|
761 | m_pointLabelsColor(QChartPrivate::defaultPen().color()) | |
761 | { |
|
762 | { | |
762 | } |
|
763 | } | |
763 |
|
764 | |||
764 | void QXYSeriesPrivate::initializeDomain() |
|
765 | void QXYSeriesPrivate::initializeDomain() | |
765 | { |
|
766 | { | |
766 | qreal minX(0); |
|
767 | qreal minX(0); | |
767 | qreal minY(0); |
|
768 | qreal minY(0); | |
768 | qreal maxX(1); |
|
769 | qreal maxX(1); | |
769 | qreal maxY(1); |
|
770 | qreal maxY(1); | |
770 |
|
771 | |||
771 | Q_Q(QXYSeries); |
|
772 | Q_Q(QXYSeries); | |
772 |
|
773 | |||
773 | const QList<QPointF>& points = q->points(); |
|
774 | const QList<QPointF>& points = q->points(); | |
774 |
|
775 | |||
775 | if (!points.isEmpty()) { |
|
776 | if (!points.isEmpty()) { | |
776 | minX = points[0].x(); |
|
777 | minX = points[0].x(); | |
777 | minY = points[0].y(); |
|
778 | minY = points[0].y(); | |
778 | maxX = minX; |
|
779 | maxX = minX; | |
779 | maxY = minY; |
|
780 | maxY = minY; | |
780 |
|
781 | |||
781 | for (int i = 0; i < points.count(); i++) { |
|
782 | for (int i = 0; i < points.count(); i++) { | |
782 | qreal x = points[i].x(); |
|
783 | qreal x = points[i].x(); | |
783 | qreal y = points[i].y(); |
|
784 | qreal y = points[i].y(); | |
784 | minX = qMin(minX, x); |
|
785 | minX = qMin(minX, x); | |
785 | minY = qMin(minY, y); |
|
786 | minY = qMin(minY, y); | |
786 | maxX = qMax(maxX, x); |
|
787 | maxX = qMax(maxX, x); | |
787 | maxY = qMax(maxY, y); |
|
788 | maxY = qMax(maxY, y); | |
788 | } |
|
789 | } | |
789 | } |
|
790 | } | |
790 |
|
791 | |||
791 | domain()->setRange(minX, maxX, minY, maxY); |
|
792 | domain()->setRange(minX, maxX, minY, maxY); | |
792 | } |
|
793 | } | |
793 |
|
794 | |||
794 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
795 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |
795 | { |
|
796 | { | |
796 | Q_Q(QXYSeries); |
|
797 | Q_Q(QXYSeries); | |
797 | QList<QLegendMarker*> list; |
|
798 | QList<QLegendMarker*> list; | |
798 | return list << new QXYLegendMarker(q,legend); |
|
799 | return list << new QXYLegendMarker(q,legend); | |
799 | } |
|
800 | } | |
800 |
|
801 | |||
801 | void QXYSeriesPrivate::initializeAxes() |
|
802 | void QXYSeriesPrivate::initializeAxes() | |
802 | { |
|
803 | { | |
803 |
|
804 | |||
804 | } |
|
805 | } | |
805 |
|
806 | |||
806 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
807 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
807 | { |
|
808 | { | |
808 | Q_UNUSED(orientation); |
|
809 | Q_UNUSED(orientation); | |
809 | return QAbstractAxis::AxisTypeValue; |
|
810 | return QAbstractAxis::AxisTypeValue; | |
810 | } |
|
811 | } | |
811 |
|
812 | |||
812 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
813 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
813 | { |
|
814 | { | |
814 | Q_UNUSED(orientation); |
|
815 | Q_UNUSED(orientation); | |
815 | return new QValueAxis; |
|
816 | return new QValueAxis; | |
816 | } |
|
817 | } | |
817 |
|
818 | |||
818 | void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options) |
|
819 | void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options) | |
819 | { |
|
820 | { | |
820 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
821 | XYChart *item = static_cast<XYChart *>(m_item.data()); | |
821 | Q_ASSERT(item); |
|
822 | Q_ASSERT(item); | |
822 | if (item->animation()) |
|
823 | if (item->animation()) | |
823 | item->animation()->stopAndDestroyLater(); |
|
824 | item->animation()->stopAndDestroyLater(); | |
824 |
|
825 | |||
825 | if (options.testFlag(QChart::SeriesAnimations)) |
|
826 | if (options.testFlag(QChart::SeriesAnimations)) | |
826 | item->setAnimation(new XYAnimation(item)); |
|
827 | item->setAnimation(new XYAnimation(item)); | |
827 | else |
|
828 | else | |
828 | item->setAnimation(0); |
|
829 | item->setAnimation(0); | |
829 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
830 | QAbstractSeriesPrivate::initializeAnimations(options); | |
830 | } |
|
831 | } | |
831 |
|
832 | |||
832 | void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector<QPointF> &points, |
|
833 | void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector<QPointF> &points, | |
833 | const int offset) |
|
834 | const int offset) | |
834 | { |
|
835 | { | |
835 | static const QString xPointTag(QLatin1String("@xPoint")); |
|
836 | static const QString xPointTag(QLatin1String("@xPoint")); | |
836 | static const QString yPointTag(QLatin1String("@yPoint")); |
|
837 | static const QString yPointTag(QLatin1String("@yPoint")); | |
837 | const int labelOffset = offset + 2; |
|
838 | const int labelOffset = offset + 2; | |
838 |
|
839 | |||
839 | painter->setFont(m_pointLabelsFont); |
|
840 | painter->setFont(m_pointLabelsFont); | |
840 | painter->setPen(QPen(m_pointLabelsColor)); |
|
841 | painter->setPen(QPen(m_pointLabelsColor)); | |
841 | QFontMetrics fm(painter->font()); |
|
842 | QFontMetrics fm(painter->font()); | |
842 |
|
843 | |||
843 | for (int i(0); i < points.size(); i++) { |
|
844 | for (int i(0); i < points.size(); i++) { | |
844 | QString pointLabel = m_pointLabelsFormat; |
|
845 | QString pointLabel = m_pointLabelsFormat; | |
845 | pointLabel.replace(xPointTag, presenter()->numberToString(points.at(i).x())); |
|
846 | pointLabel.replace(xPointTag, presenter()->numberToString(points.at(i).x())); | |
846 | pointLabel.replace(yPointTag, presenter()->numberToString(points.at(i).y())); |
|
847 | pointLabel.replace(yPointTag, presenter()->numberToString(points.at(i).y())); | |
847 |
|
848 | |||
848 | // Position text in relation to the point |
|
849 | // Position text in relation to the point | |
849 | int pointLabelWidth = fm.width(pointLabel); |
|
850 | int pointLabelWidth = fm.width(pointLabel); | |
850 | QPointF position(points.at(i)); |
|
851 | QPointF position(points.at(i)); | |
851 | position.setX(position.x() - pointLabelWidth / 2); |
|
852 | position.setX(position.x() - pointLabelWidth / 2); | |
852 | position.setY(position.y() - labelOffset); |
|
853 | position.setY(position.y() - labelOffset); | |
853 |
|
854 | |||
854 | painter->drawText(position, pointLabel); |
|
855 | painter->drawText(position, pointLabel); | |
855 | } |
|
856 | } | |
856 | } |
|
857 | } | |
857 |
|
858 | |||
858 | #include "moc_qxyseries.cpp" |
|
859 | #include "moc_qxyseries.cpp" | |
859 | #include "moc_qxyseries_p.cpp" |
|
860 | #include "moc_qxyseries_p.cpp" | |
860 |
|
861 | |||
861 | QT_CHARTS_END_NAMESPACE |
|
862 | QT_CHARTS_END_NAMESPACE |
@@ -1,1027 +1,1042 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.io |
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Charts module. |
|
7 | ** This file is part of the Qt Charts module. | |
8 | ** |
|
8 | ** | |
9 | ** Licensees holding valid commercial license for Qt may use this file in |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
10 | ** accordance with the Qt License Agreement provided with the Software |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
11 | ** or, alternatively, in accordance with the terms contained in a written |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
12 | ** agreement between you and Digia. |
|
12 | ** agreement between you and Digia. | |
13 | ** |
|
13 | ** | |
14 | ** If you have questions regarding the use of this file, please use |
|
14 | ** If you have questions regarding the use of this file, please use | |
15 | ** contact form at http://qt.io |
|
15 | ** contact form at http://qt.io | |
16 | ** |
|
16 | ** | |
17 | ****************************************************************************/ |
|
17 | ****************************************************************************/ | |
18 |
|
18 | |||
19 | #include "declarativechart.h" |
|
19 | #include "declarativechart.h" | |
20 | #include <QtGui/QPainter> |
|
20 | #include <QtGui/QPainter> | |
21 | #include "declarativelineseries.h" |
|
21 | #include "declarativelineseries.h" | |
22 | #include "declarativeareaseries.h" |
|
22 | #include "declarativeareaseries.h" | |
23 | #include "declarativebarseries.h" |
|
23 | #include "declarativebarseries.h" | |
24 | #include "declarativepieseries.h" |
|
24 | #include "declarativepieseries.h" | |
25 | #include "declarativesplineseries.h" |
|
25 | #include "declarativesplineseries.h" | |
26 | #include "declarativeboxplotseries.h" |
|
26 | #include "declarativeboxplotseries.h" | |
27 | #include "declarativescatterseries.h" |
|
27 | #include "declarativescatterseries.h" | |
28 | #include <QtCharts/QBarCategoryAxis> |
|
28 | #include <QtCharts/QBarCategoryAxis> | |
29 | #include <QtCharts/QValueAxis> |
|
29 | #include <QtCharts/QValueAxis> | |
30 | #include <QtCharts/QLogValueAxis> |
|
30 | #include <QtCharts/QLogValueAxis> | |
31 | #include <QtCharts/QCategoryAxis> |
|
31 | #include <QtCharts/QCategoryAxis> | |
32 | #include <private/qabstractseries_p.h> |
|
32 | #include <private/qabstractseries_p.h> | |
33 | #include "declarativemargins.h" |
|
33 | #include "declarativemargins.h" | |
34 | #include <private/chartdataset_p.h> |
|
34 | #include <private/chartdataset_p.h> | |
35 | #include "declarativeaxes.h" |
|
35 | #include "declarativeaxes.h" | |
36 | #include <private/qchart_p.h> |
|
36 | #include <private/qchart_p.h> | |
37 | #include <QtCharts/QPolarChart> |
|
37 | #include <QtCharts/QPolarChart> | |
38 |
|
38 | |||
39 | #ifndef QT_ON_ARM |
|
39 | #ifndef QT_ON_ARM | |
40 | #include <QtCharts/QDateTimeAxis> |
|
40 | #include <QtCharts/QDateTimeAxis> | |
41 | #endif |
|
41 | #endif | |
42 |
|
42 | |||
43 | #include <QtWidgets/QGraphicsSceneMouseEvent> |
|
43 | #include <QtWidgets/QGraphicsSceneMouseEvent> | |
44 | #include <QtWidgets/QGraphicsSceneHoverEvent> |
|
44 | #include <QtWidgets/QGraphicsSceneHoverEvent> | |
45 | #include <QtWidgets/QApplication> |
|
45 | #include <QtWidgets/QApplication> | |
46 | #include <QtCore/QTimer> |
|
46 | #include <QtCore/QTimer> | |
47 | #include <QtCore/QThread> |
|
47 | #include <QtCore/QThread> | |
48 |
|
48 | |||
49 | QT_CHARTS_BEGIN_NAMESPACE |
|
49 | QT_CHARTS_BEGIN_NAMESPACE | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \qmltype ChartView |
|
52 | \qmltype ChartView | |
53 | \instantiates DeclarativeChart |
|
53 | \instantiates DeclarativeChart | |
54 | \inqmlmodule QtCharts |
|
54 | \inqmlmodule QtCharts | |
55 |
|
55 | |||
56 | \brief Chart element. |
|
56 | \brief Chart element. | |
57 |
|
57 | |||
58 | ChartView element is the parent that is responsible for showing different chart series types. |
|
58 | ChartView element is the parent that is responsible for showing different chart series types. | |
59 |
|
59 | |||
60 | The following QML shows how to create a simple chart with one pie series: |
|
60 | The following QML shows how to create a simple chart with one pie series: | |
61 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
61 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 1 | |
62 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
62 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 2 | |
63 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
63 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 3 | |
64 |
|
64 | |||
65 | \beginfloatleft |
|
65 | \beginfloatleft | |
66 | \image examples_qmlpiechart.png |
|
66 | \image examples_qmlpiechart.png | |
67 | \endfloat |
|
67 | \endfloat | |
68 | \clearfloat |
|
68 | \clearfloat | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty Theme ChartView::theme |
|
72 | \qmlproperty Theme ChartView::theme | |
73 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
73 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
74 | widths and chart background. |
|
74 | widths and chart background. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \qmlproperty Animation ChartView::animationOptions |
|
78 | \qmlproperty Animation ChartView::animationOptions | |
79 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
79 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
80 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
80 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty Font ChartView::titleFont |
|
84 | \qmlproperty Font ChartView::titleFont | |
85 | The title font of the chart. |
|
85 | The title font of the chart. | |
86 |
|
86 | |||
87 | See the Qt documentation for more details of Font. |
|
87 | See the Qt documentation for more details of Font. | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \qmlproperty string ChartView::title |
|
91 | \qmlproperty string ChartView::title | |
92 | The title of the chart, shown on top of the chart. |
|
92 | The title of the chart, shown on top of the chart. | |
93 | \sa ChartView::titleColor |
|
93 | \sa ChartView::titleColor | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \qmlproperty color ChartView::titleColor |
|
97 | \qmlproperty color ChartView::titleColor | |
98 | The color of the title text. |
|
98 | The color of the title text. | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \qmlproperty Legend ChartView::legend |
|
102 | \qmlproperty Legend ChartView::legend | |
103 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
103 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
104 | */ |
|
104 | */ | |
105 |
|
105 | |||
106 | /*! |
|
106 | /*! | |
107 | \qmlproperty int ChartView::count |
|
107 | \qmlproperty int ChartView::count | |
108 | The count of series added to the chart. |
|
108 | The count of series added to the chart. | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \qmlproperty color ChartView::backgroundColor |
|
112 | \qmlproperty color ChartView::backgroundColor | |
113 | The color of the chart's background. By default background color is defined by chart theme. |
|
113 | The color of the chart's background. By default background color is defined by chart theme. | |
114 | \sa ChartView::theme |
|
114 | \sa ChartView::theme | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \qmlproperty real ChartView::backgroundRoundness |
|
118 | \qmlproperty real ChartView::backgroundRoundness | |
119 | The diameter of the rounding cirle at the corners of the chart background. |
|
119 | The diameter of the rounding cirle at the corners of the chart background. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \qmlproperty color ChartView::plotAreaColor |
|
123 | \qmlproperty color ChartView::plotAreaColor | |
124 | The color of the background of the chart's plot area. By default plot area background uses chart's |
|
124 | The color of the background of the chart's plot area. By default plot area background uses chart's | |
125 | background color. |
|
125 | background color. | |
126 | \sa ChartView::backgroundColor |
|
126 | \sa ChartView::backgroundColor | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
|
130 | \qmlproperty list<AbstractAxis> ChartView::axes | |||
|
131 | The axes of the ChartView. | |||
|
132 | */ | |||
|
133 | ||||
|
134 | /*! | |||
130 | \qmlproperty bool ChartView::dropShadowEnabled |
|
135 | \qmlproperty bool ChartView::dropShadowEnabled | |
131 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
136 | The chart's border drop shadow. Set to true to enable drop shadow. | |
132 | */ |
|
137 | */ | |
133 |
|
138 | |||
134 | /*! |
|
139 | /*! | |
135 | \qmlproperty rect ChartView::plotArea |
|
140 | \qmlproperty rect ChartView::plotArea | |
136 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
141 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the | |
137 | margins. |
|
142 | margins. | |
138 | \sa ChartView::margins |
|
143 | \sa ChartView::margins | |
139 | */ |
|
144 | */ | |
140 |
|
145 | |||
141 | /*! |
|
146 | /*! | |
142 | \qmlproperty Margins ChartView::margins |
|
147 | \qmlproperty Margins ChartView::margins | |
143 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
148 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
144 | area of ChartView is used for drawing title, axes and legend. |
|
149 | area of ChartView is used for drawing title, axes and legend. | |
145 | */ |
|
150 | */ | |
146 |
|
151 | |||
147 | /*! |
|
152 | /*! | |
148 | \qmlproperty bool ChartView::localizeNumbers |
|
153 | \qmlproperty bool ChartView::localizeNumbers | |
149 | \since QtCharts 2.0 |
|
154 | \since QtCharts 2.0 | |
150 | When \c{true}, all generated numbers appearing in various series and axis labels will be |
|
155 | When \c{true}, all generated numbers appearing in various series and axis labels will be | |
151 | localized using the default QLocale of the application, which defaults to the system locale. |
|
156 | localized using the default QLocale of the application, which defaults to the system locale. | |
152 | When \c{false}, the "C" locale is always used. |
|
157 | When \c{false}, the "C" locale is always used. | |
153 | Defaults to \c{false}. |
|
158 | Defaults to \c{false}. | |
154 |
|
159 | |||
155 | \sa locale |
|
160 | \sa locale | |
156 | */ |
|
161 | */ | |
157 |
|
162 | |||
158 | /*! |
|
163 | /*! | |
159 | \qmlproperty locale ChartView::locale |
|
164 | \qmlproperty locale ChartView::locale | |
160 | \since QtCharts 2.0 |
|
165 | \since QtCharts 2.0 | |
161 | Sets the locale used to format various chart labels when localizeNumbers is \c{true}. |
|
166 | Sets the locale used to format various chart labels when localizeNumbers is \c{true}. | |
162 | This also determines the locale used to format DateTimeAxis labels regardless of |
|
167 | This also determines the locale used to format DateTimeAxis labels regardless of | |
163 | localizeNumbers property. |
|
168 | localizeNumbers property. | |
164 | Defaults to application default locale at the time the chart is constructed. |
|
169 | Defaults to application default locale at the time the chart is constructed. | |
165 |
|
170 | |||
166 | \sa localizeNumbers |
|
171 | \sa localizeNumbers | |
167 | */ |
|
172 | */ | |
168 |
|
173 | |||
169 | /*! |
|
174 | /*! | |
170 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
175 | \qmlmethod AbstractSeries ChartView::series(int index) | |
171 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
176 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
172 | the count property of the chart. |
|
177 | the count property of the chart. | |
173 | */ |
|
178 | */ | |
174 |
|
179 | |||
175 | /*! |
|
180 | /*! | |
176 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
181 | \qmlmethod AbstractSeries ChartView::series(string name) | |
177 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
182 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
178 | */ |
|
183 | */ | |
179 |
|
184 | |||
180 | /*! |
|
185 | /*! | |
181 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
186 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) | |
182 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
187 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and | |
183 | optional axis \a axisY. For example: |
|
188 | optional axis \a axisY. For example: | |
184 | \code |
|
189 | \code | |
185 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
190 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes | |
186 | var myAxisX = chartView.axisX(lineSeries); |
|
191 | var myAxisX = chartView.axisX(lineSeries); | |
187 | var myAxisY = chartView.axisY(lineSeries); |
|
192 | var myAxisY = chartView.axisY(lineSeries); | |
188 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
193 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); | |
189 | \endcode |
|
194 | \endcode | |
190 | */ |
|
195 | */ | |
191 |
|
196 | |||
192 | /*! |
|
197 | /*! | |
193 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
198 | \qmlmethod ChartView::removeSeries(AbstractSeries series) | |
194 | Removes the \a series from the chart. The series object is also destroyed. |
|
199 | Removes the \a series from the chart. The series object is also destroyed. | |
195 | */ |
|
200 | */ | |
196 |
|
201 | |||
197 | /*! |
|
202 | /*! | |
198 | \qmlmethod ChartView::removeAllSeries() |
|
203 | \qmlmethod ChartView::removeAllSeries() | |
199 | Removes all series from the chart. All the series objects are also destroyed. |
|
204 | Removes all series from the chart. All the series objects are also destroyed. | |
200 | */ |
|
205 | */ | |
201 |
|
206 | |||
202 | /*! |
|
207 | /*! | |
203 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
208 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) | |
204 | The x-axis of the series. |
|
209 | The x-axis of the series. | |
205 | */ |
|
210 | */ | |
206 |
|
211 | |||
207 | /*! |
|
212 | /*! | |
|
213 | \qmlmethod ChartView::setAxisX(AbstractAxis axis, AbstractSeries series) | |||
|
214 | Set the x-axis of the series. | |||
|
215 | */ | |||
|
216 | ||||
|
217 | /*! | |||
208 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
218 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) | |
209 | The y-axis of the series. |
|
219 | The y-axis of the series. | |
210 | */ |
|
220 | */ | |
211 |
|
221 | |||
212 | /*! |
|
222 | /*! | |
213 | \qmlmethod ChartView::zoomY(real factor) |
|
223 | \qmlmethod ChartView::setAxisY(AbstractAxis axis, AbstractSeries series) | |
|
224 | Set the y-axis of the series. | |||
|
225 | */ | |||
|
226 | ||||
|
227 | /*! | |||
|
228 | \qmlmethod ChartView::zoom(real factor) | |||
214 | Zooms in by \a factor on the center of the chart. |
|
229 | Zooms in by \a factor on the center of the chart. | |
215 | */ |
|
230 | */ | |
216 |
|
231 | |||
217 | /*! |
|
232 | /*! | |
218 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
233 | \qmlmethod ChartView::scrollLeft(real pixels) | |
219 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
234 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
220 | */ |
|
235 | */ | |
221 |
|
236 | |||
222 | /*! |
|
237 | /*! | |
223 | \qmlmethod ChartView::scrollRight(real pixels) |
|
238 | \qmlmethod ChartView::scrollRight(real pixels) | |
224 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
239 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
225 | */ |
|
240 | */ | |
226 |
|
241 | |||
227 | /*! |
|
242 | /*! | |
228 | \qmlmethod ChartView::scrollUp(real pixels) |
|
243 | \qmlmethod ChartView::scrollUp(real pixels) | |
229 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
244 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
230 | */ |
|
245 | */ | |
231 |
|
246 | |||
232 | /*! |
|
247 | /*! | |
233 | \qmlmethod ChartView::scrollDown(real pixels) |
|
248 | \qmlmethod ChartView::scrollDown(real pixels) | |
234 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
249 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
235 | */ |
|
250 | */ | |
236 |
|
251 | |||
237 | /*! |
|
252 | /*! | |
238 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
253 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) | |
239 | The \a series has been added to the chart. |
|
254 | The \a series has been added to the chart. | |
240 | */ |
|
255 | */ | |
241 |
|
256 | |||
242 | /*! |
|
257 | /*! | |
243 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
258 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) | |
244 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
259 | The \a series has been removed from the chart. Please note that \a series is no longer a valid | |
245 | object after the signal handler has completed. |
|
260 | object after the signal handler has completed. | |
246 | */ |
|
261 | */ | |
247 |
|
262 | |||
248 | DeclarativeChart::DeclarativeChart(QQuickItem *parent) |
|
263 | DeclarativeChart::DeclarativeChart(QQuickItem *parent) | |
249 | : QQuickPaintedItem(parent) |
|
264 | : QQuickPaintedItem(parent) | |
250 | { |
|
265 | { | |
251 | initChart(QChart::ChartTypeCartesian); |
|
266 | initChart(QChart::ChartTypeCartesian); | |
252 | } |
|
267 | } | |
253 |
|
268 | |||
254 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent) |
|
269 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent) | |
255 | : QQuickPaintedItem(parent) |
|
270 | : QQuickPaintedItem(parent) | |
256 | { |
|
271 | { | |
257 | initChart(type); |
|
272 | initChart(type); | |
258 | } |
|
273 | } | |
259 |
|
274 | |||
260 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
275 | void DeclarativeChart::initChart(QChart::ChartType type) | |
261 | { |
|
276 | { | |
262 | m_currentSceneImage = 0; |
|
277 | m_currentSceneImage = 0; | |
263 | m_guiThreadId = QThread::currentThreadId(); |
|
278 | m_guiThreadId = QThread::currentThreadId(); | |
264 | m_paintThreadId = 0; |
|
279 | m_paintThreadId = 0; | |
265 | m_updatePending = false; |
|
280 | m_updatePending = false; | |
266 |
|
281 | |||
267 | if (type == QChart::ChartTypePolar) |
|
282 | if (type == QChart::ChartTypePolar) | |
268 | m_chart = new QPolarChart(); |
|
283 | m_chart = new QPolarChart(); | |
269 | else |
|
284 | else | |
270 | m_chart = new QChart(); |
|
285 | m_chart = new QChart(); | |
271 |
|
286 | |||
272 | m_scene = new QGraphicsScene(this); |
|
287 | m_scene = new QGraphicsScene(this); | |
273 | m_scene->addItem(m_chart); |
|
288 | m_scene->addItem(m_chart); | |
274 |
|
289 | |||
275 | setAntialiasing(QQuickItem::antialiasing()); |
|
290 | setAntialiasing(QQuickItem::antialiasing()); | |
276 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); |
|
291 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); | |
277 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
292 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); | |
278 |
|
293 | |||
279 | setAcceptedMouseButtons(Qt::AllButtons); |
|
294 | setAcceptedMouseButtons(Qt::AllButtons); | |
280 | setAcceptHoverEvents(true); |
|
295 | setAcceptHoverEvents(true); | |
281 |
|
296 | |||
282 | m_margins = new DeclarativeMargins(this); |
|
297 | m_margins = new DeclarativeMargins(this); | |
283 | m_margins->setTop(m_chart->margins().top()); |
|
298 | m_margins->setTop(m_chart->margins().top()); | |
284 | m_margins->setLeft(m_chart->margins().left()); |
|
299 | m_margins->setLeft(m_chart->margins().left()); | |
285 | m_margins->setRight(m_chart->margins().right()); |
|
300 | m_margins->setRight(m_chart->margins().right()); | |
286 | m_margins->setBottom(m_chart->margins().bottom()); |
|
301 | m_margins->setBottom(m_chart->margins().bottom()); | |
287 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), |
|
302 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), | |
288 | this, SLOT(changeMargins(int,int,int,int))); |
|
303 | this, SLOT(changeMargins(int,int,int,int))); | |
289 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), |
|
304 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), | |
290 | this, SLOT(changeMargins(int,int,int,int))); |
|
305 | this, SLOT(changeMargins(int,int,int,int))); | |
291 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), |
|
306 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), | |
292 | this, SLOT(changeMargins(int,int,int,int))); |
|
307 | this, SLOT(changeMargins(int,int,int,int))); | |
293 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), |
|
308 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), | |
294 | this, SLOT(changeMargins(int,int,int,int))); |
|
309 | this, SLOT(changeMargins(int,int,int,int))); | |
295 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
310 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
296 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
311 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
297 | connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged); |
|
312 | connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged); | |
298 | } |
|
313 | } | |
299 |
|
314 | |||
300 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
315 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) | |
301 | { |
|
316 | { | |
302 | emit seriesAdded(series); |
|
317 | emit seriesAdded(series); | |
303 | } |
|
318 | } | |
304 |
|
319 | |||
305 | void DeclarativeChart::changeMargins(int top, int bottom, int left, int right) |
|
320 | void DeclarativeChart::changeMargins(int top, int bottom, int left, int right) | |
306 | { |
|
321 | { | |
307 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
322 | m_chart->setMargins(QMargins(left, top, right, bottom)); | |
308 | emit marginsChanged(); |
|
323 | emit marginsChanged(); | |
309 | } |
|
324 | } | |
310 |
|
325 | |||
311 | DeclarativeChart::~DeclarativeChart() |
|
326 | DeclarativeChart::~DeclarativeChart() | |
312 | { |
|
327 | { | |
313 | delete m_chart; |
|
328 | delete m_chart; | |
314 | m_sceneImageLock.lock(); |
|
329 | m_sceneImageLock.lock(); | |
315 | delete m_currentSceneImage; |
|
330 | delete m_currentSceneImage; | |
316 | m_currentSceneImage = 0; |
|
331 | m_currentSceneImage = 0; | |
317 | m_sceneImageLock.unlock(); |
|
332 | m_sceneImageLock.unlock(); | |
318 | } |
|
333 | } | |
319 |
|
334 | |||
320 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
335 | void DeclarativeChart::childEvent(QChildEvent *event) | |
321 | { |
|
336 | { | |
322 | if (event->type() == QEvent::ChildAdded) { |
|
337 | if (event->type() == QEvent::ChildAdded) { | |
323 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
338 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
324 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
339 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
325 | } |
|
340 | } | |
326 | } |
|
341 | } | |
327 | } |
|
342 | } | |
328 |
|
343 | |||
329 | void DeclarativeChart::componentComplete() |
|
344 | void DeclarativeChart::componentComplete() | |
330 | { |
|
345 | { | |
331 | foreach (QObject *child, children()) { |
|
346 | foreach (QObject *child, children()) { | |
332 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
347 | if (qobject_cast<QAbstractSeries *>(child)) { | |
333 | // Add series to the chart |
|
348 | // Add series to the chart | |
334 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
349 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); | |
335 | m_chart->addSeries(series); |
|
350 | m_chart->addSeries(series); | |
336 |
|
351 | |||
337 | // Connect to axis changed signals (unless this is a pie series) |
|
352 | // Connect to axis changed signals (unless this is a pie series) | |
338 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
353 | if (!qobject_cast<DeclarativePieSeries *>(series)) { | |
339 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
354 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
340 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*))); |
|
355 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*))); | |
341 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
356 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
342 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
357 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); | |
343 | } |
|
358 | } | |
344 |
|
359 | |||
345 | initializeAxes(series); |
|
360 | initializeAxes(series); | |
346 | } |
|
361 | } | |
347 | } |
|
362 | } | |
348 |
|
363 | |||
349 | QQuickItem::componentComplete(); |
|
364 | QQuickItem::componentComplete(); | |
350 | } |
|
365 | } | |
351 |
|
366 | |||
352 | void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, |
|
367 | void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, | |
353 | Qt::Orientations orientation, |
|
368 | Qt::Orientations orientation, | |
354 | Qt::Alignment alignment) |
|
369 | Qt::Alignment alignment) | |
355 | { |
|
370 | { | |
356 | if (!series->attachedAxes().contains(axis)) { |
|
371 | if (!series->attachedAxes().contains(axis)) { | |
357 | // Remove & delete old axes that are not attached to any other series |
|
372 | // Remove & delete old axes that are not attached to any other series | |
358 | foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) { |
|
373 | foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) { | |
359 | bool otherAttachments = false; |
|
374 | bool otherAttachments = false; | |
360 | if (oldAxis != axis) { |
|
375 | if (oldAxis != axis) { | |
361 | foreach (QAbstractSeries *oldSeries, m_chart->series()) { |
|
376 | foreach (QAbstractSeries *oldSeries, m_chart->series()) { | |
362 | if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) { |
|
377 | if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) { | |
363 | otherAttachments = true; |
|
378 | otherAttachments = true; | |
364 | break; |
|
379 | break; | |
365 | } |
|
380 | } | |
366 | } |
|
381 | } | |
367 | if (!otherAttachments) { |
|
382 | if (!otherAttachments) { | |
368 | m_chart->removeAxis(oldAxis); |
|
383 | m_chart->removeAxis(oldAxis); | |
369 | delete oldAxis; |
|
384 | delete oldAxis; | |
370 | } |
|
385 | } | |
371 | } |
|
386 | } | |
372 | } |
|
387 | } | |
373 | if (!m_chart->axes(orientation).contains(axis)) |
|
388 | if (!m_chart->axes(orientation).contains(axis)) | |
374 | m_chart->addAxis(axis, alignment); |
|
389 | m_chart->addAxis(axis, alignment); | |
375 |
|
390 | |||
376 | series->attachAxis(axis); |
|
391 | series->attachAxis(axis); | |
377 | } |
|
392 | } | |
378 | } |
|
393 | } | |
379 |
|
394 | |||
380 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
395 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) | |
381 | { |
|
396 | { | |
382 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
397 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
383 | if (axis && s) { |
|
398 | if (axis && s) { | |
384 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignBottom); |
|
399 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignBottom); | |
385 | } else { |
|
400 | } else { | |
386 | qWarning() << "Trying to set axisX to null."; |
|
401 | qWarning() << "Trying to set axisX to null."; | |
387 | } |
|
402 | } | |
388 | } |
|
403 | } | |
389 |
|
404 | |||
390 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
405 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) | |
391 | { |
|
406 | { | |
392 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
407 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
393 | if (axis && s) { |
|
408 | if (axis && s) { | |
394 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignTop); |
|
409 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignTop); | |
395 | } else { |
|
410 | } else { | |
396 | qWarning() << "Trying to set axisXTop to null."; |
|
411 | qWarning() << "Trying to set axisXTop to null."; | |
397 | } |
|
412 | } | |
398 | } |
|
413 | } | |
399 |
|
414 | |||
400 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
415 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) | |
401 | { |
|
416 | { | |
402 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
417 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
403 | if (axis && s) { |
|
418 | if (axis && s) { | |
404 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignLeft); |
|
419 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignLeft); | |
405 | } else { |
|
420 | } else { | |
406 | qWarning() << "Trying to set axisY to null."; |
|
421 | qWarning() << "Trying to set axisY to null."; | |
407 | } |
|
422 | } | |
408 | } |
|
423 | } | |
409 |
|
424 | |||
410 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
425 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) | |
411 | { |
|
426 | { | |
412 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
427 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
413 | if (axis && s) { |
|
428 | if (axis && s) { | |
414 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignRight); |
|
429 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignRight); | |
415 | } else { |
|
430 | } else { | |
416 | qWarning() << "Trying to set axisYRight to null."; |
|
431 | qWarning() << "Trying to set axisYRight to null."; | |
417 | } |
|
432 | } | |
418 | } |
|
433 | } | |
419 |
|
434 | |||
420 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
435 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
421 | { |
|
436 | { | |
422 | if (newGeometry.isValid()) { |
|
437 | if (newGeometry.isValid()) { | |
423 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
438 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
424 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
439 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
425 | } |
|
440 | } | |
426 | } |
|
441 | } | |
427 | QQuickItem::geometryChanged(newGeometry, oldGeometry); |
|
442 | QQuickItem::geometryChanged(newGeometry, oldGeometry); | |
428 | } |
|
443 | } | |
429 |
|
444 | |||
430 | void DeclarativeChart::sceneChanged(QList<QRectF> region) |
|
445 | void DeclarativeChart::sceneChanged(QList<QRectF> region) | |
431 | { |
|
446 | { | |
432 | Q_UNUSED(region); |
|
447 | Q_UNUSED(region); | |
433 |
|
448 | |||
434 | if (m_guiThreadId == m_paintThreadId) { |
|
449 | if (m_guiThreadId == m_paintThreadId) { | |
435 | // Rendering in gui thread, no need for shenannigans, just update |
|
450 | // Rendering in gui thread, no need for shenannigans, just update | |
436 | update(); |
|
451 | update(); | |
437 | } else { |
|
452 | } else { | |
438 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread |
|
453 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread | |
439 | if (!m_updatePending) { |
|
454 | if (!m_updatePending) { | |
440 | m_updatePending = true; |
|
455 | m_updatePending = true; | |
441 | // Do async render to avoid some unnecessary renders. |
|
456 | // Do async render to avoid some unnecessary renders. | |
442 | QTimer::singleShot(0, this, SLOT(renderScene())); |
|
457 | QTimer::singleShot(0, this, SLOT(renderScene())); | |
443 | } |
|
458 | } | |
444 | } |
|
459 | } | |
445 | } |
|
460 | } | |
446 |
|
461 | |||
447 | void DeclarativeChart::renderScene() |
|
462 | void DeclarativeChart::renderScene() | |
448 | { |
|
463 | { | |
449 | m_updatePending = false; |
|
464 | m_updatePending = false; | |
450 | m_sceneImageLock.lock(); |
|
465 | m_sceneImageLock.lock(); | |
451 | delete m_currentSceneImage; |
|
466 | delete m_currentSceneImage; | |
452 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); |
|
467 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); | |
453 | m_currentSceneImage->fill(Qt::transparent); |
|
468 | m_currentSceneImage->fill(Qt::transparent); | |
454 | QPainter painter(m_currentSceneImage); |
|
469 | QPainter painter(m_currentSceneImage); | |
455 | if (antialiasing()) |
|
470 | if (antialiasing()) | |
456 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); |
|
471 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); | |
457 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); |
|
472 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); | |
458 | m_scene->render(&painter, renderRect, renderRect); |
|
473 | m_scene->render(&painter, renderRect, renderRect); | |
459 | m_sceneImageLock.unlock(); |
|
474 | m_sceneImageLock.unlock(); | |
460 |
|
475 | |||
461 | update(); |
|
476 | update(); | |
462 | } |
|
477 | } | |
463 |
|
478 | |||
464 | void DeclarativeChart::paint(QPainter *painter) |
|
479 | void DeclarativeChart::paint(QPainter *painter) | |
465 | { |
|
480 | { | |
466 | if (!m_paintThreadId) { |
|
481 | if (!m_paintThreadId) { | |
467 | m_paintThreadId = QThread::currentThreadId(); |
|
482 | m_paintThreadId = QThread::currentThreadId(); | |
468 | if (m_guiThreadId == m_paintThreadId) { |
|
483 | if (m_guiThreadId == m_paintThreadId) { | |
469 | // No need for scene image in single threaded rendering, so delete |
|
484 | // No need for scene image in single threaded rendering, so delete | |
470 | // the one that got made by default before the rendering type was |
|
485 | // the one that got made by default before the rendering type was | |
471 | // detected. |
|
486 | // detected. | |
472 | delete m_currentSceneImage; |
|
487 | delete m_currentSceneImage; | |
473 | m_currentSceneImage = 0; |
|
488 | m_currentSceneImage = 0; | |
474 | } |
|
489 | } | |
475 | } |
|
490 | } | |
476 |
|
491 | |||
477 | if (m_guiThreadId == m_paintThreadId) { |
|
492 | if (m_guiThreadId == m_paintThreadId) { | |
478 | QRectF renderRect(QPointF(0, 0), m_chart->size()); |
|
493 | QRectF renderRect(QPointF(0, 0), m_chart->size()); | |
479 | m_scene->render(painter, renderRect, renderRect); |
|
494 | m_scene->render(painter, renderRect, renderRect); | |
480 | } else { |
|
495 | } else { | |
481 | m_sceneImageLock.lock(); |
|
496 | m_sceneImageLock.lock(); | |
482 | if (m_currentSceneImage) { |
|
497 | if (m_currentSceneImage) { | |
483 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); |
|
498 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); | |
484 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); |
|
499 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); | |
485 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); |
|
500 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); | |
486 | } |
|
501 | } | |
487 | m_sceneImageLock.unlock(); |
|
502 | m_sceneImageLock.unlock(); | |
488 | } |
|
503 | } | |
489 | } |
|
504 | } | |
490 |
|
505 | |||
491 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
506 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) | |
492 | { |
|
507 | { | |
493 | m_mousePressScenePoint = event->pos(); |
|
508 | m_mousePressScenePoint = event->pos(); | |
494 | m_mousePressScreenPoint = event->globalPos(); |
|
509 | m_mousePressScreenPoint = event->globalPos(); | |
495 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
510 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; | |
496 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
511 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; | |
497 | m_mousePressButton = event->button(); |
|
512 | m_mousePressButton = event->button(); | |
498 | m_mousePressButtons = event->buttons(); |
|
513 | m_mousePressButtons = event->buttons(); | |
499 |
|
514 | |||
500 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); |
|
515 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); | |
501 | mouseEvent.setWidget(0); |
|
516 | mouseEvent.setWidget(0); | |
502 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
517 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
503 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
518 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
504 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
519 | mouseEvent.setScenePos(m_mousePressScenePoint); | |
505 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
520 | mouseEvent.setScreenPos(m_mousePressScreenPoint); | |
506 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
521 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
507 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
522 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
508 | mouseEvent.setButtons(m_mousePressButtons); |
|
523 | mouseEvent.setButtons(m_mousePressButtons); | |
509 | mouseEvent.setButton(m_mousePressButton); |
|
524 | mouseEvent.setButton(m_mousePressButton); | |
510 | mouseEvent.setModifiers(event->modifiers()); |
|
525 | mouseEvent.setModifiers(event->modifiers()); | |
511 | mouseEvent.setAccepted(false); |
|
526 | mouseEvent.setAccepted(false); | |
512 |
|
527 | |||
513 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
528 | QApplication::sendEvent(m_scene, &mouseEvent); | |
514 | } |
|
529 | } | |
515 |
|
530 | |||
516 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) |
|
531 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) | |
517 | { |
|
532 | { | |
518 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); |
|
533 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); | |
519 | mouseEvent.setWidget(0); |
|
534 | mouseEvent.setWidget(0); | |
520 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
535 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
521 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
536 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
522 | mouseEvent.setScenePos(event->pos()); |
|
537 | mouseEvent.setScenePos(event->pos()); | |
523 | mouseEvent.setScreenPos(event->globalPos()); |
|
538 | mouseEvent.setScreenPos(event->globalPos()); | |
524 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
539 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
525 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
540 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
526 | mouseEvent.setButtons(event->buttons()); |
|
541 | mouseEvent.setButtons(event->buttons()); | |
527 | mouseEvent.setButton(event->button()); |
|
542 | mouseEvent.setButton(event->button()); | |
528 | mouseEvent.setModifiers(event->modifiers()); |
|
543 | mouseEvent.setModifiers(event->modifiers()); | |
529 | mouseEvent.setAccepted(false); |
|
544 | mouseEvent.setAccepted(false); | |
530 |
|
545 | |||
531 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
546 | QApplication::sendEvent(m_scene, &mouseEvent); | |
532 |
|
547 | |||
533 | m_mousePressButtons = event->buttons(); |
|
548 | m_mousePressButtons = event->buttons(); | |
534 | m_mousePressButton = Qt::NoButton; |
|
549 | m_mousePressButton = Qt::NoButton; | |
535 | } |
|
550 | } | |
536 |
|
551 | |||
537 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) |
|
552 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) | |
538 | { |
|
553 | { | |
539 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. |
|
554 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. | |
540 | // QGraphicsScene generates hover events from mouse move events, so we don't need |
|
555 | // QGraphicsScene generates hover events from mouse move events, so we don't need | |
541 | // to pass hover events there. |
|
556 | // to pass hover events there. | |
542 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
557 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); | |
543 | mouseEvent.setWidget(0); |
|
558 | mouseEvent.setWidget(0); | |
544 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
559 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
545 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
560 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
546 | mouseEvent.setScenePos(event->pos()); |
|
561 | mouseEvent.setScenePos(event->pos()); | |
547 | // Hover events do not have global pos in them, and the screen position doesn't seem to |
|
562 | // Hover events do not have global pos in them, and the screen position doesn't seem to | |
548 | // matter anyway in this use case, so just pass event pos instead of trying to |
|
563 | // matter anyway in this use case, so just pass event pos instead of trying to | |
549 | // calculate the real screen position. |
|
564 | // calculate the real screen position. | |
550 | mouseEvent.setScreenPos(event->pos()); |
|
565 | mouseEvent.setScreenPos(event->pos()); | |
551 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
566 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
552 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
567 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
553 | mouseEvent.setButtons(m_mousePressButtons); |
|
568 | mouseEvent.setButtons(m_mousePressButtons); | |
554 | mouseEvent.setButton(m_mousePressButton); |
|
569 | mouseEvent.setButton(m_mousePressButton); | |
555 | mouseEvent.setModifiers(event->modifiers()); |
|
570 | mouseEvent.setModifiers(event->modifiers()); | |
556 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); |
|
571 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); | |
557 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); |
|
572 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); | |
558 | mouseEvent.setAccepted(false); |
|
573 | mouseEvent.setAccepted(false); | |
559 |
|
574 | |||
560 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
575 | QApplication::sendEvent(m_scene, &mouseEvent); | |
561 | } |
|
576 | } | |
562 |
|
577 | |||
563 | void DeclarativeChart::mouseDoubleClickEvent(QMouseEvent *event) |
|
578 | void DeclarativeChart::mouseDoubleClickEvent(QMouseEvent *event) | |
564 | { |
|
579 | { | |
565 | m_mousePressScenePoint = event->pos(); |
|
580 | m_mousePressScenePoint = event->pos(); | |
566 | m_mousePressScreenPoint = event->globalPos(); |
|
581 | m_mousePressScreenPoint = event->globalPos(); | |
567 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
582 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; | |
568 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
583 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; | |
569 | m_mousePressButton = event->button(); |
|
584 | m_mousePressButton = event->button(); | |
570 | m_mousePressButtons = event->buttons(); |
|
585 | m_mousePressButtons = event->buttons(); | |
571 |
|
586 | |||
572 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); |
|
587 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); | |
573 | mouseEvent.setWidget(0); |
|
588 | mouseEvent.setWidget(0); | |
574 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
589 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
575 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
590 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
576 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
591 | mouseEvent.setScenePos(m_mousePressScenePoint); | |
577 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
592 | mouseEvent.setScreenPos(m_mousePressScreenPoint); | |
578 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
593 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
579 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
594 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
580 | mouseEvent.setButtons(m_mousePressButtons); |
|
595 | mouseEvent.setButtons(m_mousePressButtons); | |
581 | mouseEvent.setButton(m_mousePressButton); |
|
596 | mouseEvent.setButton(m_mousePressButton); | |
582 | mouseEvent.setModifiers(event->modifiers()); |
|
597 | mouseEvent.setModifiers(event->modifiers()); | |
583 | mouseEvent.setAccepted(false); |
|
598 | mouseEvent.setAccepted(false); | |
584 |
|
599 | |||
585 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
600 | QApplication::sendEvent(m_scene, &mouseEvent); | |
586 | } |
|
601 | } | |
587 |
|
602 | |||
588 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
603 | void DeclarativeChart::handleAntialiasingChanged(bool enable) | |
589 | { |
|
604 | { | |
590 | setAntialiasing(enable); |
|
605 | setAntialiasing(enable); | |
591 | } |
|
606 | } | |
592 |
|
607 | |||
593 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
608 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
594 | { |
|
609 | { | |
595 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
610 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
596 | if (chartTheme != m_chart->theme()) |
|
611 | if (chartTheme != m_chart->theme()) | |
597 | m_chart->setTheme(chartTheme); |
|
612 | m_chart->setTheme(chartTheme); | |
598 | } |
|
613 | } | |
599 |
|
614 | |||
600 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
615 | DeclarativeChart::Theme DeclarativeChart::theme() | |
601 | { |
|
616 | { | |
602 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
617 | return (DeclarativeChart::Theme) m_chart->theme(); | |
603 | } |
|
618 | } | |
604 |
|
619 | |||
605 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
620 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
606 | { |
|
621 | { | |
607 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
622 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
608 | if (animationOptions != m_chart->animationOptions()) |
|
623 | if (animationOptions != m_chart->animationOptions()) | |
609 | m_chart->setAnimationOptions(animationOptions); |
|
624 | m_chart->setAnimationOptions(animationOptions); | |
610 | } |
|
625 | } | |
611 |
|
626 | |||
612 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
627 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
613 | { |
|
628 | { | |
614 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
629 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
615 | return DeclarativeChart::AllAnimations; |
|
630 | return DeclarativeChart::AllAnimations; | |
616 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
631 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
617 | return DeclarativeChart::GridAxisAnimations; |
|
632 | return DeclarativeChart::GridAxisAnimations; | |
618 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
633 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
619 | return DeclarativeChart::SeriesAnimations; |
|
634 | return DeclarativeChart::SeriesAnimations; | |
620 | else |
|
635 | else | |
621 | return DeclarativeChart::NoAnimation; |
|
636 | return DeclarativeChart::NoAnimation; | |
622 | } |
|
637 | } | |
623 |
|
638 | |||
624 | void DeclarativeChart::setTitle(QString title) |
|
639 | void DeclarativeChart::setTitle(QString title) | |
625 | { |
|
640 | { | |
626 | if (title != m_chart->title()) |
|
641 | if (title != m_chart->title()) | |
627 | m_chart->setTitle(title); |
|
642 | m_chart->setTitle(title); | |
628 | } |
|
643 | } | |
629 | QString DeclarativeChart::title() |
|
644 | QString DeclarativeChart::title() | |
630 | { |
|
645 | { | |
631 | return m_chart->title(); |
|
646 | return m_chart->title(); | |
632 | } |
|
647 | } | |
633 |
|
648 | |||
634 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
649 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
635 | { |
|
650 | { | |
636 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
651 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); | |
637 | if (axes.count()) |
|
652 | if (axes.count()) | |
638 | return axes[0]; |
|
653 | return axes[0]; | |
639 | return 0; |
|
654 | return 0; | |
640 | } |
|
655 | } | |
641 |
|
656 | |||
642 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
657 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
643 | { |
|
658 | { | |
644 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
659 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); | |
645 | if (axes.count()) |
|
660 | if (axes.count()) | |
646 | return axes[0]; |
|
661 | return axes[0]; | |
647 | return 0; |
|
662 | return 0; | |
648 | } |
|
663 | } | |
649 |
|
664 | |||
650 | QLegend *DeclarativeChart::legend() |
|
665 | QLegend *DeclarativeChart::legend() | |
651 | { |
|
666 | { | |
652 | return m_chart->legend(); |
|
667 | return m_chart->legend(); | |
653 | } |
|
668 | } | |
654 |
|
669 | |||
655 | void DeclarativeChart::setTitleColor(QColor color) |
|
670 | void DeclarativeChart::setTitleColor(QColor color) | |
656 | { |
|
671 | { | |
657 | QBrush b = m_chart->titleBrush(); |
|
672 | QBrush b = m_chart->titleBrush(); | |
658 | if (color != b.color()) { |
|
673 | if (color != b.color()) { | |
659 | b.setColor(color); |
|
674 | b.setColor(color); | |
660 | m_chart->setTitleBrush(b); |
|
675 | m_chart->setTitleBrush(b); | |
661 | emit titleColorChanged(color); |
|
676 | emit titleColorChanged(color); | |
662 | } |
|
677 | } | |
663 | } |
|
678 | } | |
664 |
|
679 | |||
665 | QFont DeclarativeChart::titleFont() const |
|
680 | QFont DeclarativeChart::titleFont() const | |
666 | { |
|
681 | { | |
667 | return m_chart->titleFont(); |
|
682 | return m_chart->titleFont(); | |
668 | } |
|
683 | } | |
669 |
|
684 | |||
670 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
685 | void DeclarativeChart::setTitleFont(const QFont &font) | |
671 | { |
|
686 | { | |
672 | m_chart->setTitleFont(font); |
|
687 | m_chart->setTitleFont(font); | |
673 | } |
|
688 | } | |
674 |
|
689 | |||
675 | QColor DeclarativeChart::titleColor() |
|
690 | QColor DeclarativeChart::titleColor() | |
676 | { |
|
691 | { | |
677 | return m_chart->titleBrush().color(); |
|
692 | return m_chart->titleBrush().color(); | |
678 | } |
|
693 | } | |
679 |
|
694 | |||
680 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
695 | void DeclarativeChart::setBackgroundColor(QColor color) | |
681 | { |
|
696 | { | |
682 | QBrush b = m_chart->backgroundBrush(); |
|
697 | QBrush b = m_chart->backgroundBrush(); | |
683 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
698 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
684 | b.setStyle(Qt::SolidPattern); |
|
699 | b.setStyle(Qt::SolidPattern); | |
685 | b.setColor(color); |
|
700 | b.setColor(color); | |
686 | m_chart->setBackgroundBrush(b); |
|
701 | m_chart->setBackgroundBrush(b); | |
687 | emit backgroundColorChanged(); |
|
702 | emit backgroundColorChanged(); | |
688 | } |
|
703 | } | |
689 | } |
|
704 | } | |
690 |
|
705 | |||
691 | QColor DeclarativeChart::backgroundColor() |
|
706 | QColor DeclarativeChart::backgroundColor() | |
692 | { |
|
707 | { | |
693 | return m_chart->backgroundBrush().color(); |
|
708 | return m_chart->backgroundBrush().color(); | |
694 | } |
|
709 | } | |
695 |
|
710 | |||
696 | void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color) |
|
711 | void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color) | |
697 | { |
|
712 | { | |
698 | QBrush b = m_chart->plotAreaBackgroundBrush(); |
|
713 | QBrush b = m_chart->plotAreaBackgroundBrush(); | |
699 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
714 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
700 | b.setStyle(Qt::SolidPattern); |
|
715 | b.setStyle(Qt::SolidPattern); | |
701 | b.setColor(color); |
|
716 | b.setColor(color); | |
702 | m_chart->setPlotAreaBackgroundBrush(b); |
|
717 | m_chart->setPlotAreaBackgroundBrush(b); | |
703 | m_chart->setPlotAreaBackgroundVisible(true); |
|
718 | m_chart->setPlotAreaBackgroundVisible(true); | |
704 | emit plotAreaColorChanged(); |
|
719 | emit plotAreaColorChanged(); | |
705 | } |
|
720 | } | |
706 | } |
|
721 | } | |
707 |
|
722 | |||
708 | QColor QtCharts::DeclarativeChart::plotAreaColor() |
|
723 | QColor QtCharts::DeclarativeChart::plotAreaColor() | |
709 | { |
|
724 | { | |
710 | return m_chart->plotAreaBackgroundBrush().color(); |
|
725 | return m_chart->plotAreaBackgroundBrush().color(); | |
711 | } |
|
726 | } | |
712 |
|
727 | |||
713 | void DeclarativeChart::setLocalizeNumbers(bool localize) |
|
728 | void DeclarativeChart::setLocalizeNumbers(bool localize) | |
714 | { |
|
729 | { | |
715 | if (m_chart->localizeNumbers() != localize) { |
|
730 | if (m_chart->localizeNumbers() != localize) { | |
716 | m_chart->setLocalizeNumbers(localize); |
|
731 | m_chart->setLocalizeNumbers(localize); | |
717 | emit localizeNumbersChanged(); |
|
732 | emit localizeNumbersChanged(); | |
718 | } |
|
733 | } | |
719 | } |
|
734 | } | |
720 |
|
735 | |||
721 | bool DeclarativeChart::localizeNumbers() const |
|
736 | bool DeclarativeChart::localizeNumbers() const | |
722 | { |
|
737 | { | |
723 | return m_chart->localizeNumbers(); |
|
738 | return m_chart->localizeNumbers(); | |
724 | } |
|
739 | } | |
725 |
|
740 | |||
726 | void QtCharts::DeclarativeChart::setLocale(const QLocale &locale) |
|
741 | void QtCharts::DeclarativeChart::setLocale(const QLocale &locale) | |
727 | { |
|
742 | { | |
728 | if (m_chart->locale() != locale) { |
|
743 | if (m_chart->locale() != locale) { | |
729 | m_chart->setLocale(locale); |
|
744 | m_chart->setLocale(locale); | |
730 | emit localeChanged(); |
|
745 | emit localeChanged(); | |
731 | } |
|
746 | } | |
732 | } |
|
747 | } | |
733 |
|
748 | |||
734 | QLocale QtCharts::DeclarativeChart::locale() const |
|
749 | QLocale QtCharts::DeclarativeChart::locale() const | |
735 | { |
|
750 | { | |
736 | return m_chart->locale(); |
|
751 | return m_chart->locale(); | |
737 | } |
|
752 | } | |
738 |
|
753 | |||
739 | int DeclarativeChart::count() |
|
754 | int DeclarativeChart::count() | |
740 | { |
|
755 | { | |
741 | return m_chart->series().count(); |
|
756 | return m_chart->series().count(); | |
742 | } |
|
757 | } | |
743 |
|
758 | |||
744 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
759 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
745 | { |
|
760 | { | |
746 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
761 | if (enabled != m_chart->isDropShadowEnabled()) { | |
747 | m_chart->setDropShadowEnabled(enabled); |
|
762 | m_chart->setDropShadowEnabled(enabled); | |
748 | dropShadowEnabledChanged(enabled); |
|
763 | dropShadowEnabledChanged(enabled); | |
749 | } |
|
764 | } | |
750 | } |
|
765 | } | |
751 |
|
766 | |||
752 | bool DeclarativeChart::dropShadowEnabled() |
|
767 | bool DeclarativeChart::dropShadowEnabled() | |
753 | { |
|
768 | { | |
754 | return m_chart->isDropShadowEnabled(); |
|
769 | return m_chart->isDropShadowEnabled(); | |
755 | } |
|
770 | } | |
756 |
|
771 | |||
757 | qreal DeclarativeChart::backgroundRoundness() const |
|
772 | qreal DeclarativeChart::backgroundRoundness() const | |
758 | { |
|
773 | { | |
759 | return m_chart->backgroundRoundness(); |
|
774 | return m_chart->backgroundRoundness(); | |
760 | } |
|
775 | } | |
761 |
|
776 | |||
762 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) |
|
777 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) | |
763 | { |
|
778 | { | |
764 | if (m_chart->backgroundRoundness() != diameter) { |
|
779 | if (m_chart->backgroundRoundness() != diameter) { | |
765 | m_chart->setBackgroundRoundness(diameter); |
|
780 | m_chart->setBackgroundRoundness(diameter); | |
766 | emit backgroundRoundnessChanged(diameter); |
|
781 | emit backgroundRoundnessChanged(diameter); | |
767 | } |
|
782 | } | |
768 | } |
|
783 | } | |
769 |
|
784 | |||
770 | void DeclarativeChart::zoom(qreal factor) |
|
785 | void DeclarativeChart::zoom(qreal factor) | |
771 | { |
|
786 | { | |
772 | m_chart->zoom(factor); |
|
787 | m_chart->zoom(factor); | |
773 | } |
|
788 | } | |
774 |
|
789 | |||
775 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
790 | void DeclarativeChart::scrollLeft(qreal pixels) | |
776 | { |
|
791 | { | |
777 | m_chart->scroll(-pixels, 0); |
|
792 | m_chart->scroll(-pixels, 0); | |
778 | } |
|
793 | } | |
779 |
|
794 | |||
780 | void DeclarativeChart::scrollRight(qreal pixels) |
|
795 | void DeclarativeChart::scrollRight(qreal pixels) | |
781 | { |
|
796 | { | |
782 | m_chart->scroll(pixels, 0); |
|
797 | m_chart->scroll(pixels, 0); | |
783 | } |
|
798 | } | |
784 |
|
799 | |||
785 | void DeclarativeChart::scrollUp(qreal pixels) |
|
800 | void DeclarativeChart::scrollUp(qreal pixels) | |
786 | { |
|
801 | { | |
787 | m_chart->scroll(0, pixels); |
|
802 | m_chart->scroll(0, pixels); | |
788 | } |
|
803 | } | |
789 |
|
804 | |||
790 | void DeclarativeChart::scrollDown(qreal pixels) |
|
805 | void DeclarativeChart::scrollDown(qreal pixels) | |
791 | { |
|
806 | { | |
792 | m_chart->scroll(0, -pixels); |
|
807 | m_chart->scroll(0, -pixels); | |
793 | } |
|
808 | } | |
794 |
|
809 | |||
795 | QQmlListProperty<QAbstractAxis> DeclarativeChart::axes() |
|
810 | QQmlListProperty<QAbstractAxis> DeclarativeChart::axes() | |
796 | { |
|
811 | { | |
797 | return QQmlListProperty<QAbstractAxis>(this, 0, |
|
812 | return QQmlListProperty<QAbstractAxis>(this, 0, | |
798 | &DeclarativeChart::axesAppendFunc, |
|
813 | &DeclarativeChart::axesAppendFunc, | |
799 | &DeclarativeChart::axesCountFunc, |
|
814 | &DeclarativeChart::axesCountFunc, | |
800 | &DeclarativeChart::axesAtFunc, |
|
815 | &DeclarativeChart::axesAtFunc, | |
801 | &DeclarativeChart::axesClearFunc); |
|
816 | &DeclarativeChart::axesClearFunc); | |
802 | } |
|
817 | } | |
803 |
|
818 | |||
804 | void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element) |
|
819 | void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element) | |
805 | { |
|
820 | { | |
806 | // Empty implementation |
|
821 | // Empty implementation | |
807 | Q_UNUSED(list); |
|
822 | Q_UNUSED(list); | |
808 | Q_UNUSED(element); |
|
823 | Q_UNUSED(element); | |
809 | } |
|
824 | } | |
810 |
|
825 | |||
811 | int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list) |
|
826 | int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list) | |
812 | { |
|
827 | { | |
813 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
828 | if (qobject_cast<DeclarativeChart *>(list->object)) { | |
814 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
829 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); | |
815 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); |
|
830 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); | |
816 | } |
|
831 | } | |
817 | return 0; |
|
832 | return 0; | |
818 | } |
|
833 | } | |
819 |
|
834 | |||
820 | QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index) |
|
835 | QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index) | |
821 | { |
|
836 | { | |
822 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
837 | if (qobject_cast<DeclarativeChart *>(list->object)) { | |
823 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
838 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); | |
824 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
839 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); | |
825 | return axes.at(index); |
|
840 | return axes.at(index); | |
826 | } |
|
841 | } | |
827 | return 0; |
|
842 | return 0; | |
828 | } |
|
843 | } | |
829 |
|
844 | |||
830 | void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list) |
|
845 | void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list) | |
831 | { |
|
846 | { | |
832 | // Empty implementation |
|
847 | // Empty implementation | |
833 | Q_UNUSED(list); |
|
848 | Q_UNUSED(list); | |
834 | } |
|
849 | } | |
835 |
|
850 | |||
836 |
|
851 | |||
837 | QAbstractSeries *DeclarativeChart::series(int index) |
|
852 | QAbstractSeries *DeclarativeChart::series(int index) | |
838 | { |
|
853 | { | |
839 | if (index < m_chart->series().count()) { |
|
854 | if (index < m_chart->series().count()) { | |
840 | return m_chart->series().at(index); |
|
855 | return m_chart->series().at(index); | |
841 | } |
|
856 | } | |
842 | return 0; |
|
857 | return 0; | |
843 | } |
|
858 | } | |
844 |
|
859 | |||
845 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
860 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
846 | { |
|
861 | { | |
847 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
862 | foreach (QAbstractSeries *series, m_chart->series()) { | |
848 | if (series->name() == seriesName) |
|
863 | if (series->name() == seriesName) | |
849 | return series; |
|
864 | return series; | |
850 | } |
|
865 | } | |
851 | return 0; |
|
866 | return 0; | |
852 | } |
|
867 | } | |
853 |
|
868 | |||
854 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
869 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) | |
855 | { |
|
870 | { | |
856 | QAbstractSeries *series = 0; |
|
871 | QAbstractSeries *series = 0; | |
857 |
|
872 | |||
858 | switch (type) { |
|
873 | switch (type) { | |
859 | case DeclarativeChart::SeriesTypeLine: |
|
874 | case DeclarativeChart::SeriesTypeLine: | |
860 | series = new DeclarativeLineSeries(); |
|
875 | series = new DeclarativeLineSeries(); | |
861 | break; |
|
876 | break; | |
862 | case DeclarativeChart::SeriesTypeArea: { |
|
877 | case DeclarativeChart::SeriesTypeArea: { | |
863 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
878 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); | |
864 | DeclarativeLineSeries *line = new DeclarativeLineSeries(); |
|
879 | DeclarativeLineSeries *line = new DeclarativeLineSeries(); | |
865 | line->setParent(area); |
|
880 | line->setParent(area); | |
866 | area->setUpperSeries(line); |
|
881 | area->setUpperSeries(line); | |
867 | series = area; |
|
882 | series = area; | |
868 | break; |
|
883 | break; | |
869 | } |
|
884 | } | |
870 | case DeclarativeChart::SeriesTypeStackedBar: |
|
885 | case DeclarativeChart::SeriesTypeStackedBar: | |
871 | series = new DeclarativeStackedBarSeries(); |
|
886 | series = new DeclarativeStackedBarSeries(); | |
872 | break; |
|
887 | break; | |
873 | case DeclarativeChart::SeriesTypePercentBar: |
|
888 | case DeclarativeChart::SeriesTypePercentBar: | |
874 | series = new DeclarativePercentBarSeries(); |
|
889 | series = new DeclarativePercentBarSeries(); | |
875 | break; |
|
890 | break; | |
876 | case DeclarativeChart::SeriesTypeBar: |
|
891 | case DeclarativeChart::SeriesTypeBar: | |
877 | series = new DeclarativeBarSeries(); |
|
892 | series = new DeclarativeBarSeries(); | |
878 | break; |
|
893 | break; | |
879 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
894 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
880 | series = new DeclarativeHorizontalBarSeries(); |
|
895 | series = new DeclarativeHorizontalBarSeries(); | |
881 | break; |
|
896 | break; | |
882 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
897 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
883 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
898 | series = new DeclarativeHorizontalPercentBarSeries(); | |
884 | break; |
|
899 | break; | |
885 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
900 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
886 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
901 | series = new DeclarativeHorizontalStackedBarSeries(); | |
887 | break; |
|
902 | break; | |
888 | case DeclarativeChart::SeriesTypeBoxPlot: |
|
903 | case DeclarativeChart::SeriesTypeBoxPlot: | |
889 | series = new DeclarativeBoxPlotSeries(); |
|
904 | series = new DeclarativeBoxPlotSeries(); | |
890 | break; |
|
905 | break; | |
891 | case DeclarativeChart::SeriesTypePie: |
|
906 | case DeclarativeChart::SeriesTypePie: | |
892 | series = new DeclarativePieSeries(); |
|
907 | series = new DeclarativePieSeries(); | |
893 | break; |
|
908 | break; | |
894 | case DeclarativeChart::SeriesTypeScatter: |
|
909 | case DeclarativeChart::SeriesTypeScatter: | |
895 | series = new DeclarativeScatterSeries(); |
|
910 | series = new DeclarativeScatterSeries(); | |
896 | break; |
|
911 | break; | |
897 | case DeclarativeChart::SeriesTypeSpline: |
|
912 | case DeclarativeChart::SeriesTypeSpline: | |
898 | series = new DeclarativeSplineSeries(); |
|
913 | series = new DeclarativeSplineSeries(); | |
899 | break; |
|
914 | break; | |
900 | default: |
|
915 | default: | |
901 | qWarning() << "Illegal series type"; |
|
916 | qWarning() << "Illegal series type"; | |
902 | } |
|
917 | } | |
903 |
|
918 | |||
904 | if (series) { |
|
919 | if (series) { | |
905 | // Connect to axis changed signals (unless this is a pie series) |
|
920 | // Connect to axis changed signals (unless this is a pie series) | |
906 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
921 | if (!qobject_cast<DeclarativePieSeries *>(series)) { | |
907 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
922 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
908 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
923 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
909 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
924 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
910 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
925 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); | |
911 | } |
|
926 | } | |
912 |
|
927 | |||
913 | series->setName(name); |
|
928 | series->setName(name); | |
914 | m_chart->addSeries(series); |
|
929 | m_chart->addSeries(series); | |
915 |
|
930 | |||
916 | if (!axisX || !axisY) |
|
931 | if (!axisX || !axisY) | |
917 | initializeAxes(series); |
|
932 | initializeAxes(series); | |
918 |
|
933 | |||
919 | if (axisX) |
|
934 | if (axisX) | |
920 | setAxisX(axisX, series); |
|
935 | setAxisX(axisX, series); | |
921 | if (axisY) |
|
936 | if (axisY) | |
922 | setAxisY(axisY, series); |
|
937 | setAxisY(axisY, series); | |
923 | } |
|
938 | } | |
924 |
|
939 | |||
925 | return series; |
|
940 | return series; | |
926 | } |
|
941 | } | |
927 |
|
942 | |||
928 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
943 | void DeclarativeChart::removeSeries(QAbstractSeries *series) | |
929 | { |
|
944 | { | |
930 | if (series) |
|
945 | if (series) | |
931 | m_chart->removeSeries(series); |
|
946 | m_chart->removeSeries(series); | |
932 | else |
|
947 | else | |
933 | qWarning("removeSeries: cannot remove null"); |
|
948 | qWarning("removeSeries: cannot remove null"); | |
934 | } |
|
949 | } | |
935 |
|
950 | |||
936 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
951 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
937 | { |
|
952 | { | |
938 | if (axis && series) |
|
953 | if (axis && series) | |
939 | seriesAxisAttachHelper(series, axis, Qt::Horizontal, Qt::AlignBottom); |
|
954 | seriesAxisAttachHelper(series, axis, Qt::Horizontal, Qt::AlignBottom); | |
940 | } |
|
955 | } | |
941 |
|
956 | |||
942 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
957 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
943 | { |
|
958 | { | |
944 | if (axis && series) |
|
959 | if (axis && series) | |
945 | seriesAxisAttachHelper(series, axis, Qt::Vertical, Qt::AlignLeft); |
|
960 | seriesAxisAttachHelper(series, axis, Qt::Vertical, Qt::AlignLeft); | |
946 | } |
|
961 | } | |
947 |
|
962 | |||
948 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
963 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) | |
949 | { |
|
964 | { | |
950 | if (!series) { |
|
965 | if (!series) { | |
951 | qWarning() << "No axis type defined for null series"; |
|
966 | qWarning() << "No axis type defined for null series"; | |
952 | return 0; |
|
967 | return 0; | |
953 | } |
|
968 | } | |
954 |
|
969 | |||
955 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
970 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { | |
956 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
971 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) | |
957 | return existingAxis; |
|
972 | return existingAxis; | |
958 | } |
|
973 | } | |
959 |
|
974 | |||
960 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
975 | switch (series->d_ptr->defaultAxisType(orientation)) { | |
961 | case QAbstractAxis::AxisTypeValue: |
|
976 | case QAbstractAxis::AxisTypeValue: | |
962 | return new QValueAxis(this); |
|
977 | return new QValueAxis(this); | |
963 | case QAbstractAxis::AxisTypeBarCategory: |
|
978 | case QAbstractAxis::AxisTypeBarCategory: | |
964 | return new QBarCategoryAxis(this); |
|
979 | return new QBarCategoryAxis(this); | |
965 | case QAbstractAxis::AxisTypeCategory: |
|
980 | case QAbstractAxis::AxisTypeCategory: | |
966 | return new QCategoryAxis(this); |
|
981 | return new QCategoryAxis(this); | |
967 | #ifndef QT_ON_ARM |
|
982 | #ifndef QT_ON_ARM | |
968 | case QAbstractAxis::AxisTypeDateTime: |
|
983 | case QAbstractAxis::AxisTypeDateTime: | |
969 | return new QDateTimeAxis(this); |
|
984 | return new QDateTimeAxis(this); | |
970 | #endif |
|
985 | #endif | |
971 | case QAbstractAxis::AxisTypeLogValue: |
|
986 | case QAbstractAxis::AxisTypeLogValue: | |
972 | return new QLogValueAxis(this); |
|
987 | return new QLogValueAxis(this); | |
973 | default: |
|
988 | default: | |
974 | // assume AxisTypeNoAxis |
|
989 | // assume AxisTypeNoAxis | |
975 | return 0; |
|
990 | return 0; | |
976 | } |
|
991 | } | |
977 | } |
|
992 | } | |
978 |
|
993 | |||
979 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
994 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) | |
980 | { |
|
995 | { | |
981 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
996 | if (qobject_cast<DeclarativeLineSeries *>(series)) | |
982 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
997 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); | |
983 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
998 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) | |
984 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
999 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); | |
985 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
1000 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) | |
986 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
1001 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); | |
987 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
1002 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) | |
988 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
1003 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); | |
989 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
1004 | else if (qobject_cast<DeclarativeBarSeries *>(series)) | |
990 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
1005 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); | |
991 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
1006 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) | |
992 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
1007 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); | |
993 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
1008 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) | |
994 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
1009 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); | |
995 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
1010 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) | |
996 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
1011 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); | |
997 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
1012 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) | |
998 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
1013 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); | |
999 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
1014 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) | |
1000 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
1015 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); | |
1001 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) |
|
1016 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) | |
1002 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); |
|
1017 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); | |
1003 | // else: do nothing |
|
1018 | // else: do nothing | |
1004 | } |
|
1019 | } | |
1005 |
|
1020 | |||
1006 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
1021 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) | |
1007 | { |
|
1022 | { | |
1008 | // Initialize axis X |
|
1023 | // Initialize axis X | |
1009 | if (axes->axisX()) |
|
1024 | if (axes->axisX()) | |
1010 | axes->emitAxisXChanged(); |
|
1025 | axes->emitAxisXChanged(); | |
1011 | else if (axes->axisXTop()) |
|
1026 | else if (axes->axisXTop()) | |
1012 | axes->emitAxisXTopChanged(); |
|
1027 | axes->emitAxisXTopChanged(); | |
1013 | else |
|
1028 | else | |
1014 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
1029 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); | |
1015 |
|
1030 | |||
1016 | // Initialize axis Y |
|
1031 | // Initialize axis Y | |
1017 | if (axes->axisY()) |
|
1032 | if (axes->axisY()) | |
1018 | axes->emitAxisYChanged(); |
|
1033 | axes->emitAxisYChanged(); | |
1019 | else if (axes->axisYRight()) |
|
1034 | else if (axes->axisYRight()) | |
1020 | axes->emitAxisYRightChanged(); |
|
1035 | axes->emitAxisYRightChanged(); | |
1021 | else |
|
1036 | else | |
1022 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
1037 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); | |
1023 | } |
|
1038 | } | |
1024 |
|
1039 | |||
1025 | #include "moc_declarativechart.cpp" |
|
1040 | #include "moc_declarativechart.cpp" | |
1026 |
|
1041 | |||
1027 | QT_CHARTS_END_NAMESPACE |
|
1042 | QT_CHARTS_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now