@@ -1,731 +1,730 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QDeclarativeEngine> |
|
23 | #include <QDeclarativeEngine> | |
24 | #include "declarativelineseries.h" |
|
24 | #include "declarativelineseries.h" | |
25 | #include "declarativeareaseries.h" |
|
25 | #include "declarativeareaseries.h" | |
26 | #include "declarativebarseries.h" |
|
26 | #include "declarativebarseries.h" | |
27 | #include "declarativepieseries.h" |
|
27 | #include "declarativepieseries.h" | |
28 | #include "declarativesplineseries.h" |
|
28 | #include "declarativesplineseries.h" | |
29 | #include "declarativescatterseries.h" |
|
29 | #include "declarativescatterseries.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 | #include "qvalueaxis.h" |
|
31 | #include "qvalueaxis.h" | |
32 | #include "qcategoryaxis.h" |
|
32 | #include "qcategoryaxis.h" | |
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 | #include "declarativemargins.h" |
|
34 | #include "declarativemargins.h" | |
35 | #include "chartdataset_p.h" |
|
35 | #include "chartdataset_p.h" | |
36 | #include "qchart_p.h" |
|
36 | #include "qchart_p.h" | |
37 |
|
37 | |||
38 | #ifndef QT_ON_ARM |
|
38 | #ifndef QT_ON_ARM | |
39 | #include "qdatetimeaxis.h" |
|
39 | #include "qdatetimeaxis.h" | |
40 | #endif |
|
40 | #endif | |
41 |
|
41 | |||
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 | \qmlclass ChartView DeclarativeChart |
|
45 | \qmlclass ChartView DeclarativeChart | |
46 |
|
46 | |||
47 | ChartView element is the parent that is responsible for showing different chart series types. |
|
47 | ChartView element is the parent that is responsible for showing different chart series types. | |
48 |
|
48 | |||
49 | The following QML shows how to create a simple chart with one pie series: |
|
49 | The following QML shows how to create a simple chart with one pie series: | |
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
51 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
51 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
52 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
52 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
53 |
|
53 | |||
54 | \beginfloatleft |
|
54 | \beginfloatleft | |
55 | \image examples_qmlpiechart.png |
|
55 | \image examples_qmlpiechart.png | |
56 | \endfloat |
|
56 | \endfloat | |
57 | \clearfloat |
|
57 | \clearfloat | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \qmlproperty Theme ChartView::theme |
|
61 | \qmlproperty Theme ChartView::theme | |
62 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
62 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
63 | widths and chart background. |
|
63 | widths and chart background. | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \qmlproperty Animation ChartView::animationOptions |
|
67 | \qmlproperty Animation ChartView::animationOptions | |
68 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
68 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
69 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
69 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \qmlproperty Font ChartView::titleFont |
|
73 | \qmlproperty Font ChartView::titleFont | |
74 | The title font of the chart |
|
74 | The title font of the chart | |
75 |
|
75 | |||
76 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
76 | See the \l {Font} {QML Font Element} for detailed documentation. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \qmlproperty string ChartView::title |
|
80 | \qmlproperty string ChartView::title | |
81 | The title of the chart, shown on top of the chart. |
|
81 | The title of the chart, shown on top of the chart. | |
82 | \sa ChartView::titleColor |
|
82 | \sa ChartView::titleColor | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty color ChartView::titleColor |
|
86 | \qmlproperty color ChartView::titleColor | |
87 | The color of the title text. |
|
87 | The color of the title text. | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \qmlproperty Legend ChartView::legend |
|
91 | \qmlproperty Legend ChartView::legend | |
92 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
92 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty int ChartView::count |
|
96 | \qmlproperty int ChartView::count | |
97 | The count of series added to the chart. |
|
97 | The count of series added to the chart. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \qmlproperty color ChartView::backgroundColor |
|
101 | \qmlproperty color ChartView::backgroundColor | |
102 | The color of the chart's background. By default background color is defined by chart theme. |
|
102 | The color of the chart's background. By default background color is defined by chart theme. | |
103 | \sa ChartView::theme |
|
103 | \sa ChartView::theme | |
104 | */ |
|
104 | */ | |
105 |
|
105 | |||
106 | /*! |
|
106 | /*! | |
107 | \qmlproperty bool ChartView::dropShadowEnabled |
|
107 | \qmlproperty bool ChartView::dropShadowEnabled | |
108 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
108 | The chart's border drop shadow. Set to true to enable drop shadow. | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \qmlproperty real ChartView::topMargin |
|
112 | \qmlproperty real ChartView::topMargin | |
113 | Deprecated. Use minimumMargins and plotArea instead. |
|
113 | Deprecated. Use minimumMargins and plotArea instead. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \qmlproperty real ChartView::bottomMargin |
|
117 | \qmlproperty real ChartView::bottomMargin | |
118 | Deprecated. Use minimumMargins and plotArea instead. |
|
118 | Deprecated. Use minimumMargins and plotArea instead. | |
119 | */ |
|
119 | */ | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty real ChartView::leftMargin |
|
122 | \qmlproperty real ChartView::leftMargin | |
123 | Deprecated. Use minimumMargins and plotArea instead. |
|
123 | Deprecated. Use minimumMargins and plotArea instead. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \qmlproperty real ChartView::rightMargin |
|
127 | \qmlproperty real ChartView::rightMargin | |
128 | Deprecated. Use minimumMargins and plotArea instead. |
|
128 | Deprecated. Use minimumMargins and plotArea instead. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \qmlproperty Margins ChartView::minimumMargins |
|
132 | \qmlproperty Margins ChartView::minimumMargins | |
133 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
133 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
134 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
134 | area of ChartView is used for drawing title, axes and legend. Please note that setting the | |
135 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
135 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView | |
136 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
136 | properties that affect it's layout. If you need to know the actual plotting area used at any | |
137 | given time, you can check ChartView::plotArea instead. |
|
137 | given time, you can check ChartView::plotArea instead. | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \qmlproperty rect ChartView::plotArea |
|
141 | \qmlproperty rect ChartView::plotArea | |
142 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
142 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the | |
143 | margins. |
|
143 | margins. | |
144 | \sa ChartView::minimumMargins |
|
144 | \sa ChartView::minimumMargins | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
148 | \qmlmethod AbstractSeries ChartView::series(int index) | |
149 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
149 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
150 | the count property of the chart. |
|
150 | the count property of the chart. | |
151 | */ |
|
151 | */ | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
154 | \qmlmethod AbstractSeries ChartView::series(string name) | |
155 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
155 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
159 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) | |
160 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
160 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and | |
161 | optional axis \a axisY. For example: |
|
161 | optional axis \a axisY. For example: | |
162 | \code |
|
162 | \code | |
163 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
163 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes | |
164 | var myAxisX = chartView.axisX(lineSeries); |
|
164 | var myAxisX = chartView.axisX(lineSeries); | |
165 | var myAxisY = chartView.axisY(lineSeries); |
|
165 | var myAxisY = chartView.axisY(lineSeries); | |
166 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
166 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); | |
167 | \endcode |
|
167 | \endcode | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
171 | \qmlmethod ChartView::removeSeries(AbstractSeries series) | |
172 | Removes the \a series from the chart. The series object is also destroyed. |
|
172 | Removes the \a series from the chart. The series object is also destroyed. | |
173 | */ |
|
173 | */ | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | \qmlmethod ChartView::removeAllSeries() |
|
176 | \qmlmethod ChartView::removeAllSeries() | |
177 | Removes all series from the chart. All the series objects are also destroyed. |
|
177 | Removes all series from the chart. All the series objects are also destroyed. | |
178 | */ |
|
178 | */ | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
181 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) | |
182 | The x-axis of the series. |
|
182 | The x-axis of the series. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
186 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) | |
187 | The y-axis of the series. |
|
187 | The y-axis of the series. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | \qmlmethod ChartView::zoomY(real factor) |
|
191 | \qmlmethod ChartView::zoomY(real factor) | |
192 | Zooms in by \a factor on the center of the chart. |
|
192 | Zooms in by \a factor on the center of the chart. | |
193 | */ |
|
193 | */ | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
196 | \qmlmethod ChartView::scrollLeft(real pixels) | |
197 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
197 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
198 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
198 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
199 | */ |
|
199 | */ | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | \qmlmethod ChartView::scrollRight(real pixels) |
|
202 | \qmlmethod ChartView::scrollRight(real pixels) | |
203 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
203 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
204 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
204 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
205 | */ |
|
205 | */ | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | \qmlmethod ChartView::scrollUp(real pixels) |
|
208 | \qmlmethod ChartView::scrollUp(real pixels) | |
209 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
209 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
210 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
210 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | \qmlmethod ChartView::scrollDown(real pixels) |
|
214 | \qmlmethod ChartView::scrollDown(real pixels) | |
215 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
215 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
216 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
216 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
217 | */ |
|
217 | */ | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
220 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) | |
221 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
221 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins | |
222 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
222 | or if you resize the chart, or if you modify font size related properties of the legend or chart | |
223 | title. |
|
223 | title. | |
224 | */ |
|
224 | */ | |
225 |
|
225 | |||
226 | /*! |
|
226 | /*! | |
227 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
227 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) | |
228 | The \a series has been added to the chart. |
|
228 | The \a series has been added to the chart. | |
229 | */ |
|
229 | */ | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
232 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) | |
233 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
233 | The \a series has been removed from the chart. Please note that \a series is no longer a valid | |
234 | object after the signal handler has completed. |
|
234 | object after the signal handler has completed. | |
235 | */ |
|
235 | */ | |
236 |
|
236 | |||
237 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
237 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
238 | : QDeclarativeItem(parent), |
|
238 | : QDeclarativeItem(parent), | |
239 | m_chart(new QChart(this)) |
|
239 | m_chart(new QChart(this)) | |
240 | { |
|
240 | { | |
241 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
241 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
242 | m_margins = new DeclarativeMargins(this); |
|
242 | m_margins = new DeclarativeMargins(this); | |
243 | m_margins->setTop(m_chart->margins().top()); |
|
243 | m_margins->setTop(m_chart->margins().top()); | |
244 | m_margins->setLeft(m_chart->margins().left()); |
|
244 | m_margins->setLeft(m_chart->margins().left()); | |
245 | m_margins->setRight(m_chart->margins().right()); |
|
245 | m_margins->setRight(m_chart->margins().right()); | |
246 | m_margins->setBottom(m_chart->margins().bottom()); |
|
246 | m_margins->setBottom(m_chart->margins().bottom()); | |
247 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
247 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
248 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
248 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
249 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
249 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
250 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
250 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
251 |
connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
251 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
252 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
252 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 |
void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series |
|
255 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) | |
256 | { |
|
256 | { | |
257 | Q_UNUSED(domain) |
|
|||
258 | emit seriesAdded(series); |
|
257 | emit seriesAdded(series); | |
259 | } |
|
258 | } | |
260 |
|
259 | |||
261 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
260 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) | |
262 | { |
|
261 | { | |
263 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
262 | m_chart->setMargins(QMargins(left, top, right, bottom)); | |
264 | emit minimumMarginsChanged(); |
|
263 | emit minimumMarginsChanged(); | |
265 | emit plotAreaChanged(m_chart->plotArea()); |
|
264 | emit plotAreaChanged(m_chart->plotArea()); | |
266 | } |
|
265 | } | |
267 |
|
266 | |||
268 | DeclarativeChart::~DeclarativeChart() |
|
267 | DeclarativeChart::~DeclarativeChart() | |
269 | { |
|
268 | { | |
270 | delete m_chart; |
|
269 | delete m_chart; | |
271 | } |
|
270 | } | |
272 |
|
271 | |||
273 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
272 | void DeclarativeChart::childEvent(QChildEvent *event) | |
274 | { |
|
273 | { | |
275 | if (event->type() == QEvent::ChildAdded) { |
|
274 | if (event->type() == QEvent::ChildAdded) { | |
276 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
275 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
277 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
276 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
278 | } |
|
277 | } | |
279 | } |
|
278 | } | |
280 | } |
|
279 | } | |
281 |
|
280 | |||
282 | void DeclarativeChart::componentComplete() |
|
281 | void DeclarativeChart::componentComplete() | |
283 | { |
|
282 | { | |
284 | foreach (QObject *child, children()) { |
|
283 | foreach (QObject *child, children()) { | |
285 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
284 | if (qobject_cast<QAbstractSeries *>(child)) { | |
286 | // Add series to the chart |
|
285 | // Add series to the chart | |
287 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
286 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); | |
288 | m_chart->addSeries(series); |
|
287 | m_chart->addSeries(series); | |
289 |
|
288 | |||
290 | // Set optional user defined axes for the series and connect axis related signals |
|
289 | // Set optional user defined axes for the series and connect axis related signals | |
291 | if (qobject_cast<DeclarativeLineSeries *>(child)) { |
|
290 | if (qobject_cast<DeclarativeLineSeries *>(child)) { | |
292 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); |
|
291 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); | |
293 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
292 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
294 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
293 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
295 | setAxisX(s->axisX(), s); |
|
294 | setAxisX(s->axisX(), s); | |
296 | setAxisY(s->axisY(), s); |
|
295 | setAxisY(s->axisY(), s); | |
297 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { |
|
296 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { | |
298 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); |
|
297 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); | |
299 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
298 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
300 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
299 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
301 | setAxisX(s->axisX(), s); |
|
300 | setAxisX(s->axisX(), s); | |
302 | setAxisY(s->axisY(), s); |
|
301 | setAxisY(s->axisY(), s); | |
303 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { |
|
302 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { | |
304 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); |
|
303 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); | |
305 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
304 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
306 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
305 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
307 | setAxisX(s->axisX(), s); |
|
306 | setAxisX(s->axisX(), s); | |
308 | setAxisY(s->axisY(), s); |
|
307 | setAxisY(s->axisY(), s); | |
309 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { |
|
308 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { | |
310 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); |
|
309 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); | |
311 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
310 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
312 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
311 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
313 | setAxisX(s->axisX(), s); |
|
312 | setAxisX(s->axisX(), s); | |
314 | setAxisY(s->axisY(), s); |
|
313 | setAxisY(s->axisY(), s); | |
315 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { |
|
314 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { | |
316 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); |
|
315 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); | |
317 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
316 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
318 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
317 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
319 | setAxisX(s->axisX(), s); |
|
318 | setAxisX(s->axisX(), s); | |
320 | setAxisY(s->axisY(), s); |
|
319 | setAxisY(s->axisY(), s); | |
321 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { |
|
320 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { | |
322 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); |
|
321 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); | |
323 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
322 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
324 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
323 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
325 | setAxisX(s->axisX(), s); |
|
324 | setAxisX(s->axisX(), s); | |
326 | setAxisY(s->axisY(), s); |
|
325 | setAxisY(s->axisY(), s); | |
327 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { |
|
326 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { | |
328 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); |
|
327 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); | |
329 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
328 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
330 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
329 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
331 | setAxisX(s->axisX(), s); |
|
330 | setAxisX(s->axisX(), s); | |
332 | setAxisY(s->axisY(), s); |
|
331 | setAxisY(s->axisY(), s); | |
333 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { |
|
332 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { | |
334 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); |
|
333 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); | |
335 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
334 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
336 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
335 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
337 | setAxisX(s->axisX(), s); |
|
336 | setAxisX(s->axisX(), s); | |
338 | setAxisY(s->axisY(), s); |
|
337 | setAxisY(s->axisY(), s); | |
339 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { |
|
338 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { | |
340 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); |
|
339 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); | |
341 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
340 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
342 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
341 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
343 | setAxisX(s->axisX(), s); |
|
342 | setAxisX(s->axisX(), s); | |
344 | setAxisY(s->axisY(), s); |
|
343 | setAxisY(s->axisY(), s); | |
345 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { |
|
344 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { | |
346 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); |
|
345 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); | |
347 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
346 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
348 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
347 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
349 | setAxisX(s->axisX(), s); |
|
348 | setAxisX(s->axisX(), s); | |
350 | setAxisY(s->axisY(), s); |
|
349 | setAxisY(s->axisY(), s); | |
351 | } |
|
350 | } | |
352 | } |
|
351 | } | |
353 | } |
|
352 | } | |
354 |
|
353 | |||
355 | // Create the missing axes for the series that cannot be painted without axes |
|
354 | // Create the missing axes for the series that cannot be painted without axes | |
356 | foreach (QAbstractSeries *chartSeries, m_chart->series()) |
|
355 | foreach (QAbstractSeries *chartSeries, m_chart->series()) | |
357 | createDefaultAxes(chartSeries); |
|
356 | createDefaultAxes(chartSeries); | |
358 |
|
357 | |||
359 | QDeclarativeItem::componentComplete(); |
|
358 | QDeclarativeItem::componentComplete(); | |
360 | } |
|
359 | } | |
361 |
|
360 | |||
362 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
361 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) | |
363 | { |
|
362 | { | |
364 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; |
|
363 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; | |
365 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
364 | if (axis && qobject_cast<QAbstractSeries *>(sender())) | |
366 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
365 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); | |
367 | else |
|
366 | else | |
368 | qWarning() << "Trying to set axisX to null."; |
|
367 | qWarning() << "Trying to set axisX to null."; | |
369 | } |
|
368 | } | |
370 |
|
369 | |||
371 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
370 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) | |
372 | { |
|
371 | { | |
373 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; |
|
372 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; | |
374 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
373 | if (axis && qobject_cast<QAbstractSeries *>(sender())) | |
375 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
374 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); | |
376 | else |
|
375 | else | |
377 | qWarning() << "Trying to set axisY to null."; |
|
376 | qWarning() << "Trying to set axisY to null."; | |
378 | } |
|
377 | } | |
379 |
|
378 | |||
380 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
379 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
381 | { |
|
380 | { | |
382 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
381 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
383 | if (newGeometry.isValid()) { |
|
382 | if (newGeometry.isValid()) { | |
384 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
383 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
385 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
384 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
386 | } |
|
385 | } | |
387 | } |
|
386 | } | |
388 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
387 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
389 |
|
388 | |||
390 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
389 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or | |
391 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
390 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is | |
392 | // to implement it here for the QML API purposes. |
|
391 | // to implement it here for the QML API purposes. | |
393 | emit plotAreaChanged(m_chart->plotArea()); |
|
392 | emit plotAreaChanged(m_chart->plotArea()); | |
394 | } |
|
393 | } | |
395 |
|
394 | |||
396 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
395 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
397 | { |
|
396 | { | |
398 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
397 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
399 | if (chartTheme != m_chart->theme()) |
|
398 | if (chartTheme != m_chart->theme()) | |
400 | m_chart->setTheme(chartTheme); |
|
399 | m_chart->setTheme(chartTheme); | |
401 | } |
|
400 | } | |
402 |
|
401 | |||
403 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
402 | DeclarativeChart::Theme DeclarativeChart::theme() | |
404 | { |
|
403 | { | |
405 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
404 | return (DeclarativeChart::Theme) m_chart->theme(); | |
406 | } |
|
405 | } | |
407 |
|
406 | |||
408 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
407 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
409 | { |
|
408 | { | |
410 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
409 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
411 | if (animationOptions != m_chart->animationOptions()) |
|
410 | if (animationOptions != m_chart->animationOptions()) | |
412 | m_chart->setAnimationOptions(animationOptions); |
|
411 | m_chart->setAnimationOptions(animationOptions); | |
413 | } |
|
412 | } | |
414 |
|
413 | |||
415 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
414 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
416 | { |
|
415 | { | |
417 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
416 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
418 | return DeclarativeChart::AllAnimations; |
|
417 | return DeclarativeChart::AllAnimations; | |
419 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
418 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
420 | return DeclarativeChart::GridAxisAnimations; |
|
419 | return DeclarativeChart::GridAxisAnimations; | |
421 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
420 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
422 | return DeclarativeChart::SeriesAnimations; |
|
421 | return DeclarativeChart::SeriesAnimations; | |
423 | else |
|
422 | else | |
424 | return DeclarativeChart::NoAnimation; |
|
423 | return DeclarativeChart::NoAnimation; | |
425 | } |
|
424 | } | |
426 |
|
425 | |||
427 | void DeclarativeChart::setTitle(QString title) |
|
426 | void DeclarativeChart::setTitle(QString title) | |
428 | { |
|
427 | { | |
429 | if (title != m_chart->title()) |
|
428 | if (title != m_chart->title()) | |
430 | m_chart->setTitle(title); |
|
429 | m_chart->setTitle(title); | |
431 | } |
|
430 | } | |
432 | QString DeclarativeChart::title() |
|
431 | QString DeclarativeChart::title() | |
433 | { |
|
432 | { | |
434 | return m_chart->title(); |
|
433 | return m_chart->title(); | |
435 | } |
|
434 | } | |
436 |
|
435 | |||
437 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
436 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
438 | { |
|
437 | { | |
439 | return m_chart->axisX(series); |
|
438 | return m_chart->axisX(series); | |
440 | } |
|
439 | } | |
441 |
|
440 | |||
442 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
441 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
443 | { |
|
442 | { | |
444 | return m_chart->axisY(series); |
|
443 | return m_chart->axisY(series); | |
445 | } |
|
444 | } | |
446 |
|
445 | |||
447 | QLegend *DeclarativeChart::legend() |
|
446 | QLegend *DeclarativeChart::legend() | |
448 | { |
|
447 | { | |
449 | return m_chart->legend(); |
|
448 | return m_chart->legend(); | |
450 | } |
|
449 | } | |
451 |
|
450 | |||
452 | void DeclarativeChart::setTitleColor(QColor color) |
|
451 | void DeclarativeChart::setTitleColor(QColor color) | |
453 | { |
|
452 | { | |
454 | QBrush b = m_chart->titleBrush(); |
|
453 | QBrush b = m_chart->titleBrush(); | |
455 | if (color != b.color()) { |
|
454 | if (color != b.color()) { | |
456 | b.setColor(color); |
|
455 | b.setColor(color); | |
457 | m_chart->setTitleBrush(b); |
|
456 | m_chart->setTitleBrush(b); | |
458 | emit titleColorChanged(color); |
|
457 | emit titleColorChanged(color); | |
459 | } |
|
458 | } | |
460 | } |
|
459 | } | |
461 |
|
460 | |||
462 | QFont DeclarativeChart::titleFont() const |
|
461 | QFont DeclarativeChart::titleFont() const | |
463 | { |
|
462 | { | |
464 | return m_chart->titleFont(); |
|
463 | return m_chart->titleFont(); | |
465 | } |
|
464 | } | |
466 |
|
465 | |||
467 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
466 | void DeclarativeChart::setTitleFont(const QFont &font) | |
468 | { |
|
467 | { | |
469 | m_chart->setTitleFont(font); |
|
468 | m_chart->setTitleFont(font); | |
470 | } |
|
469 | } | |
471 |
|
470 | |||
472 | QColor DeclarativeChart::titleColor() |
|
471 | QColor DeclarativeChart::titleColor() | |
473 | { |
|
472 | { | |
474 | return m_chart->titleBrush().color(); |
|
473 | return m_chart->titleBrush().color(); | |
475 | } |
|
474 | } | |
476 |
|
475 | |||
477 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
476 | void DeclarativeChart::setBackgroundColor(QColor color) | |
478 | { |
|
477 | { | |
479 | QBrush b = m_chart->backgroundBrush(); |
|
478 | QBrush b = m_chart->backgroundBrush(); | |
480 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
479 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
481 | b.setStyle(Qt::SolidPattern); |
|
480 | b.setStyle(Qt::SolidPattern); | |
482 | b.setColor(color); |
|
481 | b.setColor(color); | |
483 | m_chart->setBackgroundBrush(b); |
|
482 | m_chart->setBackgroundBrush(b); | |
484 | emit backgroundColorChanged(); |
|
483 | emit backgroundColorChanged(); | |
485 | } |
|
484 | } | |
486 | } |
|
485 | } | |
487 |
|
486 | |||
488 | QColor DeclarativeChart::backgroundColor() |
|
487 | QColor DeclarativeChart::backgroundColor() | |
489 | { |
|
488 | { | |
490 | return m_chart->backgroundBrush().color(); |
|
489 | return m_chart->backgroundBrush().color(); | |
491 | } |
|
490 | } | |
492 |
|
491 | |||
493 | int DeclarativeChart::count() |
|
492 | int DeclarativeChart::count() | |
494 | { |
|
493 | { | |
495 | return m_chart->series().count(); |
|
494 | return m_chart->series().count(); | |
496 | } |
|
495 | } | |
497 |
|
496 | |||
498 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
497 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
499 | { |
|
498 | { | |
500 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
499 | if (enabled != m_chart->isDropShadowEnabled()) { | |
501 | m_chart->setDropShadowEnabled(enabled); |
|
500 | m_chart->setDropShadowEnabled(enabled); | |
502 | dropShadowEnabledChanged(enabled); |
|
501 | dropShadowEnabledChanged(enabled); | |
503 | } |
|
502 | } | |
504 | } |
|
503 | } | |
505 |
|
504 | |||
506 | bool DeclarativeChart::dropShadowEnabled() |
|
505 | bool DeclarativeChart::dropShadowEnabled() | |
507 | { |
|
506 | { | |
508 | return m_chart->isDropShadowEnabled(); |
|
507 | return m_chart->isDropShadowEnabled(); | |
509 | } |
|
508 | } | |
510 |
|
509 | |||
511 | qreal DeclarativeChart::topMargin() |
|
510 | qreal DeclarativeChart::topMargin() | |
512 | { |
|
511 | { | |
513 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
512 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; | |
514 | return m_chart->plotArea().top(); |
|
513 | return m_chart->plotArea().top(); | |
515 | } |
|
514 | } | |
516 |
|
515 | |||
517 | qreal DeclarativeChart::bottomMargin() |
|
516 | qreal DeclarativeChart::bottomMargin() | |
518 | { |
|
517 | { | |
519 |
|
518 | |||
520 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
519 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; | |
521 | return m_chart->plotArea().bottom(); |
|
520 | return m_chart->plotArea().bottom(); | |
522 | } |
|
521 | } | |
523 |
|
522 | |||
524 | qreal DeclarativeChart::leftMargin() |
|
523 | qreal DeclarativeChart::leftMargin() | |
525 | { |
|
524 | { | |
526 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
525 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; | |
527 | return m_chart->plotArea().left(); |
|
526 | return m_chart->plotArea().left(); | |
528 | } |
|
527 | } | |
529 |
|
528 | |||
530 | qreal DeclarativeChart::rightMargin() |
|
529 | qreal DeclarativeChart::rightMargin() | |
531 | { |
|
530 | { | |
532 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
531 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; | |
533 | return m_chart->plotArea().right(); |
|
532 | return m_chart->plotArea().right(); | |
534 | } |
|
533 | } | |
535 |
|
534 | |||
536 | void DeclarativeChart::zoom(qreal factor) |
|
535 | void DeclarativeChart::zoom(qreal factor) | |
537 | { |
|
536 | { | |
538 | m_chart->zoom(factor); |
|
537 | m_chart->zoom(factor); | |
539 | } |
|
538 | } | |
540 |
|
539 | |||
541 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
540 | void DeclarativeChart::scrollLeft(qreal pixels) | |
542 | { |
|
541 | { | |
543 | m_chart->scroll(-pixels, 0); |
|
542 | m_chart->scroll(-pixels, 0); | |
544 | } |
|
543 | } | |
545 |
|
544 | |||
546 | void DeclarativeChart::scrollRight(qreal pixels) |
|
545 | void DeclarativeChart::scrollRight(qreal pixels) | |
547 | { |
|
546 | { | |
548 | m_chart->scroll(pixels, 0); |
|
547 | m_chart->scroll(pixels, 0); | |
549 | } |
|
548 | } | |
550 |
|
549 | |||
551 | void DeclarativeChart::scrollUp(qreal pixels) |
|
550 | void DeclarativeChart::scrollUp(qreal pixels) | |
552 | { |
|
551 | { | |
553 | m_chart->scroll(0, pixels); |
|
552 | m_chart->scroll(0, pixels); | |
554 | } |
|
553 | } | |
555 |
|
554 | |||
556 | void DeclarativeChart::scrollDown(qreal pixels) |
|
555 | void DeclarativeChart::scrollDown(qreal pixels) | |
557 | { |
|
556 | { | |
558 | m_chart->scroll(0, -pixels); |
|
557 | m_chart->scroll(0, -pixels); | |
559 | } |
|
558 | } | |
560 |
|
559 | |||
561 | QAbstractSeries *DeclarativeChart::series(int index) |
|
560 | QAbstractSeries *DeclarativeChart::series(int index) | |
562 | { |
|
561 | { | |
563 | if (index < m_chart->series().count()) { |
|
562 | if (index < m_chart->series().count()) { | |
564 | return m_chart->series().at(index); |
|
563 | return m_chart->series().at(index); | |
565 | } |
|
564 | } | |
566 | return 0; |
|
565 | return 0; | |
567 | } |
|
566 | } | |
568 |
|
567 | |||
569 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
568 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
570 | { |
|
569 | { | |
571 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
570 | foreach (QAbstractSeries *series, m_chart->series()) { | |
572 | if (series->name() == seriesName) |
|
571 | if (series->name() == seriesName) | |
573 | return series; |
|
572 | return series; | |
574 | } |
|
573 | } | |
575 | return 0; |
|
574 | return 0; | |
576 | } |
|
575 | } | |
577 |
|
576 | |||
578 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
577 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
579 | { |
|
578 | { | |
580 | return createSeries(type, name, 0, 0); |
|
579 | return createSeries(type, name, 0, 0); | |
581 | } |
|
580 | } | |
582 |
|
581 | |||
583 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
582 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) | |
584 | { |
|
583 | { | |
585 | QAbstractSeries *series = 0; |
|
584 | QAbstractSeries *series = 0; | |
586 |
|
585 | |||
587 | switch (type) { |
|
586 | switch (type) { | |
588 | case DeclarativeChart::SeriesTypeLine: |
|
587 | case DeclarativeChart::SeriesTypeLine: | |
589 | series = new DeclarativeLineSeries(); |
|
588 | series = new DeclarativeLineSeries(); | |
590 | break; |
|
589 | break; | |
591 | case DeclarativeChart::SeriesTypeArea: { |
|
590 | case DeclarativeChart::SeriesTypeArea: { | |
592 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
591 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); | |
593 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
592 | area->setUpperSeries(new DeclarativeLineSeries()); | |
594 | series = area; |
|
593 | series = area; | |
595 | break; |
|
594 | break; | |
596 | } |
|
595 | } | |
597 | case DeclarativeChart::SeriesTypeStackedBar: |
|
596 | case DeclarativeChart::SeriesTypeStackedBar: | |
598 | series = new DeclarativeStackedBarSeries(); |
|
597 | series = new DeclarativeStackedBarSeries(); | |
599 | break; |
|
598 | break; | |
600 | case DeclarativeChart::SeriesTypePercentBar: |
|
599 | case DeclarativeChart::SeriesTypePercentBar: | |
601 | series = new DeclarativePercentBarSeries(); |
|
600 | series = new DeclarativePercentBarSeries(); | |
602 | break; |
|
601 | break; | |
603 | case DeclarativeChart::SeriesTypeBar: |
|
602 | case DeclarativeChart::SeriesTypeBar: | |
604 | series = new DeclarativeBarSeries(); |
|
603 | series = new DeclarativeBarSeries(); | |
605 | break; |
|
604 | break; | |
606 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
605 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
607 | series = new DeclarativeHorizontalBarSeries(); |
|
606 | series = new DeclarativeHorizontalBarSeries(); | |
608 | break; |
|
607 | break; | |
609 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
608 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
610 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
609 | series = new DeclarativeHorizontalPercentBarSeries(); | |
611 | break; |
|
610 | break; | |
612 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
611 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
613 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
612 | series = new DeclarativeHorizontalStackedBarSeries(); | |
614 | break; |
|
613 | break; | |
615 | case DeclarativeChart::SeriesTypePie: |
|
614 | case DeclarativeChart::SeriesTypePie: | |
616 | series = new DeclarativePieSeries(); |
|
615 | series = new DeclarativePieSeries(); | |
617 | break; |
|
616 | break; | |
618 | case DeclarativeChart::SeriesTypeScatter: |
|
617 | case DeclarativeChart::SeriesTypeScatter: | |
619 | series = new DeclarativeScatterSeries(); |
|
618 | series = new DeclarativeScatterSeries(); | |
620 | break; |
|
619 | break; | |
621 | case DeclarativeChart::SeriesTypeSpline: |
|
620 | case DeclarativeChart::SeriesTypeSpline: | |
622 | series = new DeclarativeSplineSeries(); |
|
621 | series = new DeclarativeSplineSeries(); | |
623 | break; |
|
622 | break; | |
624 | default: |
|
623 | default: | |
625 | qWarning() << "Illegal series type"; |
|
624 | qWarning() << "Illegal series type"; | |
626 | } |
|
625 | } | |
627 |
|
626 | |||
628 | if (series) { |
|
627 | if (series) { | |
629 | series->setName(name); |
|
628 | series->setName(name); | |
630 | m_chart->addSeries(series); |
|
629 | m_chart->addSeries(series); | |
631 | // Set possible user defined axes |
|
630 | // Set possible user defined axes | |
632 | setAxisX(axisX, series); |
|
631 | setAxisX(axisX, series); | |
633 | setAxisY(axisY, series); |
|
632 | setAxisY(axisY, series); | |
634 | // Then create the missing axes |
|
633 | // Then create the missing axes | |
635 | createDefaultAxes(series); |
|
634 | createDefaultAxes(series); | |
636 | } |
|
635 | } | |
637 |
|
636 | |||
638 | return series; |
|
637 | return series; | |
639 | } |
|
638 | } | |
640 |
|
639 | |||
641 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
640 | void DeclarativeChart::removeSeries(QAbstractSeries *series) | |
642 | { |
|
641 | { | |
643 | if (series) |
|
642 | if (series) | |
644 | m_chart->removeSeries(series); |
|
643 | m_chart->removeSeries(series); | |
645 | else |
|
644 | else | |
646 | qWarning("removeSeries: cannot remove null"); |
|
645 | qWarning("removeSeries: cannot remove null"); | |
647 | } |
|
646 | } | |
648 |
|
647 | |||
649 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
648 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
650 | { |
|
649 | { | |
651 | if (axis) |
|
650 | if (axis) | |
652 | m_chart->setAxisX(axis, series); |
|
651 | m_chart->setAxisX(axis, series); | |
653 | } |
|
652 | } | |
654 |
|
653 | |||
655 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
654 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
656 | { |
|
655 | { | |
657 | if (axis) |
|
656 | if (axis) | |
658 | m_chart->setAxisY(axis, series); |
|
657 | m_chart->setAxisY(axis, series); | |
659 | } |
|
658 | } | |
660 |
|
659 | |||
661 | void DeclarativeChart::createDefaultAxes() |
|
660 | void DeclarativeChart::createDefaultAxes() | |
662 | { |
|
661 | { | |
663 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
662 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; | |
664 | } |
|
663 | } | |
665 |
|
664 | |||
666 | void DeclarativeChart::createDefaultAxes(QAbstractSeries *series) |
|
665 | void DeclarativeChart::createDefaultAxes(QAbstractSeries *series) | |
667 | { |
|
666 | { | |
668 | foreach (QAbstractSeries *s, m_chart->series()) { |
|
667 | foreach (QAbstractSeries *s, m_chart->series()) { | |
669 | // If there is already an x axis of the correct type, re-use it |
|
668 | // If there is already an x axis of the correct type, re-use it | |
670 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) |
|
669 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) | |
671 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
670 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) | |
672 | m_chart->setAxisX(m_chart->axisX(s), series); |
|
671 | m_chart->setAxisX(m_chart->axisX(s), series); | |
673 |
|
672 | |||
674 | // If there is already a y axis of the correct type, re-use it |
|
673 | // If there is already a y axis of the correct type, re-use it | |
675 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) |
|
674 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) | |
676 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) |
|
675 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) | |
677 | m_chart->setAxisY(m_chart->axisY(s), series); |
|
676 | m_chart->setAxisY(m_chart->axisY(s), series); | |
678 | } |
|
677 | } | |
679 |
|
678 | |||
680 | // If no x axis of correct type was found, create a new x axis based of default axis type |
|
679 | // If no x axis of correct type was found, create a new x axis based of default axis type | |
681 | if (!m_chart->axisX(series)) { |
|
680 | if (!m_chart->axisX(series)) { | |
682 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { |
|
681 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { | |
683 | case QAbstractAxis::AxisTypeValue: |
|
682 | case QAbstractAxis::AxisTypeValue: | |
684 | m_chart->setAxisX(new QValueAxis(this), series); |
|
683 | m_chart->setAxisX(new QValueAxis(this), series); | |
685 | break; |
|
684 | break; | |
686 | case QAbstractAxis::AxisTypeBarCategory: |
|
685 | case QAbstractAxis::AxisTypeBarCategory: | |
687 | m_chart->setAxisX(new QBarCategoryAxis(this), series); |
|
686 | m_chart->setAxisX(new QBarCategoryAxis(this), series); | |
688 | break; |
|
687 | break; | |
689 | case QAbstractAxis::AxisTypeCategory: |
|
688 | case QAbstractAxis::AxisTypeCategory: | |
690 | m_chart->setAxisX(new QCategoryAxis(this), series); |
|
689 | m_chart->setAxisX(new QCategoryAxis(this), series); | |
691 | break; |
|
690 | break; | |
692 | #ifndef QT_ON_ARM |
|
691 | #ifndef QT_ON_ARM | |
693 | case QAbstractAxis::AxisTypeDateTime: |
|
692 | case QAbstractAxis::AxisTypeDateTime: | |
694 | m_chart->setAxisX(new QDateTimeAxis(this), series); |
|
693 | m_chart->setAxisX(new QDateTimeAxis(this), series); | |
695 | break; |
|
694 | break; | |
696 | #endif |
|
695 | #endif | |
697 | default: |
|
696 | default: | |
698 | // Do nothing, assume AxisTypeNoAxis |
|
697 | // Do nothing, assume AxisTypeNoAxis | |
699 | break; |
|
698 | break; | |
700 | } |
|
699 | } | |
701 | } |
|
700 | } | |
702 |
|
701 | |||
703 | // If no y axis of correct type was found, create a new y axis based of default axis type |
|
702 | // If no y axis of correct type was found, create a new y axis based of default axis type | |
704 | if (!m_chart->axisY(series)) { |
|
703 | if (!m_chart->axisY(series)) { | |
705 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { |
|
704 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { | |
706 | case QAbstractAxis::AxisTypeValue: |
|
705 | case QAbstractAxis::AxisTypeValue: | |
707 | m_chart->setAxisY(new QValueAxis(this), series); |
|
706 | m_chart->setAxisY(new QValueAxis(this), series); | |
708 | break; |
|
707 | break; | |
709 | case QAbstractAxis::AxisTypeBarCategory: |
|
708 | case QAbstractAxis::AxisTypeBarCategory: | |
710 | m_chart->setAxisY(new QBarCategoryAxis(this), series); |
|
709 | m_chart->setAxisY(new QBarCategoryAxis(this), series); | |
711 | break; |
|
710 | break; | |
712 | case QAbstractAxis::AxisTypeCategory: |
|
711 | case QAbstractAxis::AxisTypeCategory: | |
713 | m_chart->setAxisY(new QCategoryAxis(this), series); |
|
712 | m_chart->setAxisY(new QCategoryAxis(this), series); | |
714 | break; |
|
713 | break; | |
715 | #ifndef QT_ON_ARM |
|
714 | #ifndef QT_ON_ARM | |
716 | case QAbstractAxis::AxisTypeDateTime: |
|
715 | case QAbstractAxis::AxisTypeDateTime: | |
717 | m_chart->setAxisY(new QDateTimeAxis(this), series); |
|
716 | m_chart->setAxisY(new QDateTimeAxis(this), series); | |
718 | break; |
|
717 | break; | |
719 | #endif |
|
718 | #endif | |
720 | default: |
|
719 | default: | |
721 | // Do nothing, assume AxisTypeNoAxis |
|
720 | // Do nothing, assume AxisTypeNoAxis | |
722 | break; |
|
721 | break; | |
723 | } |
|
722 | } | |
724 | } |
|
723 | } | |
725 |
|
724 | |||
726 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); |
|
725 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); | |
727 | } |
|
726 | } | |
728 |
|
727 | |||
729 | #include "moc_declarativechart.cpp" |
|
728 | #include "moc_declarativechart.cpp" | |
730 |
|
729 | |||
731 | QTCOMMERCIALCHART_END_NAMESPACE |
|
730 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,172 +1,172 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVECHART_H |
|
21 | #ifndef DECLARATIVECHART_H | |
22 | #define DECLARATIVECHART_H |
|
22 | #define DECLARATIVECHART_H | |
23 |
|
23 | |||
24 | #include <QtCore/QtGlobal> |
|
24 | #include <QtCore/QtGlobal> | |
25 | #include <QtDeclarative/QDeclarativeItem> |
|
25 | #include <QtDeclarative/QDeclarativeItem> | |
26 |
|
26 | |||
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class DeclarativeMargins; |
|
31 | class DeclarativeMargins; | |
32 | class AbstractDomain; |
|
32 | class AbstractDomain; | |
33 |
|
33 | |||
34 | class DeclarativeChart : public QDeclarativeItem |
|
34 | class DeclarativeChart : public QDeclarativeItem | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) | |
38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) | |
39 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
39 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
40 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
40 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
41 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
41 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
42 | Q_PROPERTY(QLegend *legend READ legend) |
|
42 | Q_PROPERTY(QLegend *legend READ legend) | |
43 | Q_PROPERTY(int count READ count) |
|
43 | Q_PROPERTY(int count READ count) | |
44 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
44 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) | |
45 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
45 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) | |
46 | Q_PROPERTY(qreal topMargin READ topMargin) |
|
46 | Q_PROPERTY(qreal topMargin READ topMargin) | |
47 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) |
|
47 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) | |
48 | Q_PROPERTY(qreal leftMargin READ leftMargin) |
|
48 | Q_PROPERTY(qreal leftMargin READ leftMargin) | |
49 | Q_PROPERTY(qreal rightMargin READ rightMargin) |
|
49 | Q_PROPERTY(qreal rightMargin READ rightMargin) | |
50 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) |
|
50 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) | |
51 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) |
|
51 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) | |
52 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) |
|
52 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) | |
53 | Q_ENUMS(Animation) |
|
53 | Q_ENUMS(Animation) | |
54 | Q_ENUMS(Theme) |
|
54 | Q_ENUMS(Theme) | |
55 | Q_ENUMS(SeriesType) |
|
55 | Q_ENUMS(SeriesType) | |
56 |
|
56 | |||
57 | public: |
|
57 | public: | |
58 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
58 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api | |
59 | enum Theme { |
|
59 | enum Theme { | |
60 | ChartThemeLight = 0, |
|
60 | ChartThemeLight = 0, | |
61 | ChartThemeBlueCerulean, |
|
61 | ChartThemeBlueCerulean, | |
62 | ChartThemeDark, |
|
62 | ChartThemeDark, | |
63 | ChartThemeBrownSand, |
|
63 | ChartThemeBrownSand, | |
64 | ChartThemeBlueNcs, |
|
64 | ChartThemeBlueNcs, | |
65 | ChartThemeHighContrast, |
|
65 | ChartThemeHighContrast, | |
66 | ChartThemeBlueIcy |
|
66 | ChartThemeBlueIcy | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | enum Animation { |
|
69 | enum Animation { | |
70 | NoAnimation = 0x0, |
|
70 | NoAnimation = 0x0, | |
71 | GridAxisAnimations = 0x1, |
|
71 | GridAxisAnimations = 0x1, | |
72 | SeriesAnimations = 0x2, |
|
72 | SeriesAnimations = 0x2, | |
73 | AllAnimations = 0x3 |
|
73 | AllAnimations = 0x3 | |
74 | }; |
|
74 | }; | |
75 |
|
75 | |||
76 | enum SeriesType { |
|
76 | enum SeriesType { | |
77 | SeriesTypeLine, |
|
77 | SeriesTypeLine, | |
78 | SeriesTypeArea, |
|
78 | SeriesTypeArea, | |
79 | SeriesTypeBar, |
|
79 | SeriesTypeBar, | |
80 | SeriesTypeStackedBar, |
|
80 | SeriesTypeStackedBar, | |
81 | SeriesTypePercentBar, |
|
81 | SeriesTypePercentBar, | |
82 | SeriesTypePie, |
|
82 | SeriesTypePie, | |
83 | SeriesTypeScatter, |
|
83 | SeriesTypeScatter, | |
84 | SeriesTypeSpline, |
|
84 | SeriesTypeSpline, | |
85 | SeriesTypeHorizontalBar, |
|
85 | SeriesTypeHorizontalBar, | |
86 | SeriesTypeHorizontalStackedBar, |
|
86 | SeriesTypeHorizontalStackedBar, | |
87 | SeriesTypeHorizontalPercentBar |
|
87 | SeriesTypeHorizontalPercentBar | |
88 | }; |
|
88 | }; | |
89 |
|
89 | |||
90 | public: |
|
90 | public: | |
91 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
91 | DeclarativeChart(QDeclarativeItem *parent = 0); | |
92 | ~DeclarativeChart(); |
|
92 | ~DeclarativeChart(); | |
93 |
|
93 | |||
94 | public: // From QDeclarativeItem/QGraphicsItem |
|
94 | public: // From QDeclarativeItem/QGraphicsItem | |
95 | void childEvent(QChildEvent *event); |
|
95 | void childEvent(QChildEvent *event); | |
96 | void componentComplete(); |
|
96 | void componentComplete(); | |
97 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
97 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
98 |
|
98 | |||
99 | public: |
|
99 | public: | |
100 | void setTheme(DeclarativeChart::Theme theme); |
|
100 | void setTheme(DeclarativeChart::Theme theme); | |
101 | DeclarativeChart::Theme theme(); |
|
101 | DeclarativeChart::Theme theme(); | |
102 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
102 | void setAnimationOptions(DeclarativeChart::Animation animations); | |
103 | DeclarativeChart::Animation animationOptions(); |
|
103 | DeclarativeChart::Animation animationOptions(); | |
104 | void setTitle(QString title); |
|
104 | void setTitle(QString title); | |
105 | QString title(); |
|
105 | QString title(); | |
106 | QLegend *legend(); |
|
106 | QLegend *legend(); | |
107 | QFont titleFont() const; |
|
107 | QFont titleFont() const; | |
108 | void setTitleFont(const QFont &font); |
|
108 | void setTitleFont(const QFont &font); | |
109 | void setTitleColor(QColor color); |
|
109 | void setTitleColor(QColor color); | |
110 | QColor titleColor(); |
|
110 | QColor titleColor(); | |
111 | void setBackgroundColor(QColor color); |
|
111 | void setBackgroundColor(QColor color); | |
112 | QColor backgroundColor(); |
|
112 | QColor backgroundColor(); | |
113 | int count(); |
|
113 | int count(); | |
114 | void setDropShadowEnabled(bool enabled); |
|
114 | void setDropShadowEnabled(bool enabled); | |
115 | bool dropShadowEnabled(); |
|
115 | bool dropShadowEnabled(); | |
116 | qreal topMargin(); |
|
116 | qreal topMargin(); | |
117 | qreal bottomMargin(); |
|
117 | qreal bottomMargin(); | |
118 | qreal leftMargin(); |
|
118 | qreal leftMargin(); | |
119 | qreal rightMargin(); |
|
119 | qreal rightMargin(); | |
120 | void createDefaultAxes(QAbstractSeries *series); |
|
120 | void createDefaultAxes(QAbstractSeries *series); | |
121 | //TODO this is deprecated: |
|
121 | //TODO this is deprecated: | |
122 | DeclarativeMargins *minimumMargins() { return m_margins; } |
|
122 | DeclarativeMargins *minimumMargins() { return m_margins; } | |
123 |
|
123 | |||
124 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } |
|
124 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } | |
125 | QRectF plotArea() { return m_chart->plotArea(); } |
|
125 | QRectF plotArea() { return m_chart->plotArea(); } | |
126 |
|
126 | |||
127 | public: |
|
127 | public: | |
128 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
128 | Q_INVOKABLE QAbstractSeries *series(int index); | |
129 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
129 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); | |
130 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
130 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); | |
131 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY); |
|
131 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY); | |
132 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); |
|
132 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); | |
133 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
133 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } | |
134 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
134 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
135 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
135 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
136 | Q_INVOKABLE void createDefaultAxes(); |
|
136 | Q_INVOKABLE void createDefaultAxes(); | |
137 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
137 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); | |
138 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
138 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); | |
139 | Q_INVOKABLE void zoom(qreal factor); |
|
139 | Q_INVOKABLE void zoom(qreal factor); | |
140 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
140 | Q_INVOKABLE void scrollLeft(qreal pixels); | |
141 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
141 | Q_INVOKABLE void scrollRight(qreal pixels); | |
142 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
142 | Q_INVOKABLE void scrollUp(qreal pixels); | |
143 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
143 | Q_INVOKABLE void scrollDown(qreal pixels); | |
144 |
|
144 | |||
145 | Q_SIGNALS: |
|
145 | Q_SIGNALS: | |
146 | void axisLabelsChanged(); |
|
146 | void axisLabelsChanged(); | |
147 | void titleColorChanged(QColor color); |
|
147 | void titleColorChanged(QColor color); | |
148 | void backgroundColorChanged(); |
|
148 | void backgroundColorChanged(); | |
149 | void dropShadowEnabledChanged(bool enabled); |
|
149 | void dropShadowEnabledChanged(bool enabled); | |
150 | void minimumMarginsChanged(); |
|
150 | void minimumMarginsChanged(); | |
151 | Q_REVISION(2) void marginsChanged(); |
|
151 | Q_REVISION(2) void marginsChanged(); | |
152 | void plotAreaChanged(QRectF plotArea); |
|
152 | void plotAreaChanged(QRectF plotArea); | |
153 | void seriesAdded(QAbstractSeries *series); |
|
153 | void seriesAdded(QAbstractSeries *series); | |
154 | void seriesRemoved(QAbstractSeries *series); |
|
154 | void seriesRemoved(QAbstractSeries *series); | |
155 |
|
155 | |||
156 | public Q_SLOTS: |
|
156 | public Q_SLOTS: | |
157 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
157 | void changeMinimumMargins(int top, int bottom, int left, int right); | |
158 | void handleAxisXSet(QAbstractAxis *axis); |
|
158 | void handleAxisXSet(QAbstractAxis *axis); | |
159 | void handleAxisYSet(QAbstractAxis *axis); |
|
159 | void handleAxisYSet(QAbstractAxis *axis); | |
160 |
void handleSeriesAdded(QAbstractSeries *series |
|
160 | void handleSeriesAdded(QAbstractSeries *series); | |
161 |
|
161 | |||
162 | private: |
|
162 | private: | |
163 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
163 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
164 | // multi inheritance, so we now have a QChart as a member instead |
|
164 | // multi inheritance, so we now have a QChart as a member instead | |
165 | QChart *m_chart; |
|
165 | QChart *m_chart; | |
166 | //QMargins m_chartMargins; |
|
166 | //QMargins m_chartMargins; | |
167 | DeclarativeMargins *m_margins; |
|
167 | DeclarativeMargins *m_margins; | |
168 | }; |
|
168 | }; | |
169 |
|
169 | |||
170 | QTCOMMERCIALCHART_END_NAMESPACE |
|
170 | QTCOMMERCIALCHART_END_NAMESPACE | |
171 |
|
171 | |||
172 | #endif // DECLARATIVECHART_H |
|
172 | #endif // DECLARATIVECHART_H |
@@ -1,497 +1,497 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartlayout_p.h" |
|
25 | #include "chartlayout_p.h" | |
26 | #include "abstractdomain_p.h" |
|
26 | #include "abstractdomain_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDateTime> |
|
28 | #include <QDateTime> | |
29 | #include <QValueAxis> |
|
29 | #include <QValueAxis> | |
30 | #include <QLogValueAxis> |
|
30 | #include <QLogValueAxis> | |
31 | #include <QGraphicsLayout> |
|
31 | #include <QGraphicsLayout> | |
32 | #include <QFontMetrics> |
|
32 | #include <QFontMetrics> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) |
|
36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | |
37 | : ChartElement(item), |
|
37 | : ChartElement(item), | |
38 | m_axis(axis), |
|
38 | m_axis(axis), | |
39 | m_labelsAngle(0), |
|
39 | m_labelsAngle(0), | |
40 | m_grid(new QGraphicsItemGroup(item)), |
|
40 | m_grid(new QGraphicsItemGroup(item)), | |
41 | m_arrow(new QGraphicsItemGroup(item)), |
|
41 | m_arrow(new QGraphicsItemGroup(item)), | |
42 | m_shades(new QGraphicsItemGroup(item)), |
|
42 | m_shades(new QGraphicsItemGroup(item)), | |
43 | m_labels(new QGraphicsItemGroup(item)), |
|
43 | m_labels(new QGraphicsItemGroup(item)), | |
44 | m_title(new QGraphicsSimpleTextItem(item)), |
|
44 | m_title(new QGraphicsSimpleTextItem(item)), | |
45 | m_animation(0), |
|
45 | m_animation(0), | |
46 | m_labelPadding(5), |
|
46 | m_labelPadding(5), | |
47 | m_intervalAxis(intervalAxis) |
|
47 | m_intervalAxis(intervalAxis) | |
48 | { |
|
48 | { | |
49 | Q_ASSERT(item); |
|
49 | Q_ASSERT(item); | |
50 | //initial initialization |
|
50 | //initial initialization | |
51 | m_arrow->setHandlesChildEvents(false); |
|
51 | m_arrow->setHandlesChildEvents(false); | |
52 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
52 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
53 | m_arrow->setVisible(m_axis->isLineVisible()); |
|
53 | m_arrow->setVisible(m_axis->isLineVisible()); | |
54 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
54 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
55 | m_labels->setVisible(m_axis->labelsVisible()); |
|
55 | m_labels->setVisible(m_axis->labelsVisible()); | |
56 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
56 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
57 | m_shades->setVisible(m_axis->shadesVisible()); |
|
57 | m_shades->setVisible(m_axis->shadesVisible()); | |
58 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
58 | m_grid->setZValue(ChartPresenter::GridZValue); | |
59 | m_grid->setVisible(m_axis->isGridLineVisible()); |
|
59 | m_grid->setVisible(m_axis->isGridLineVisible()); | |
60 | m_title->setZValue(ChartPresenter::GridZValue); |
|
60 | m_title->setZValue(ChartPresenter::GridZValue); | |
61 | connectSlots(); |
|
61 | connectSlots(); | |
62 |
|
62 | |||
63 | setFlag(QGraphicsItem::ItemHasNoContents,true); |
|
63 | setFlag(QGraphicsItem::ItemHasNoContents,true); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void ChartAxis::connectSlots() |
|
66 | void ChartAxis::connectSlots() | |
67 | { |
|
67 | { | |
68 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); |
|
68 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); | |
69 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); |
|
69 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); | |
70 | QObject::connect(m_axis,SIGNAL(gridLineVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); |
|
70 | QObject::connect(m_axis,SIGNAL(gridLineVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); | |
71 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); |
|
71 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); | |
72 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); |
|
72 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); | |
73 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); |
|
73 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); | |
74 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); |
|
74 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); | |
75 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); |
|
75 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); | |
76 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
76 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); | |
77 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); |
|
77 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); | |
78 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); |
|
78 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); | |
79 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); |
|
79 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); | |
80 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); |
|
80 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); | |
81 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); |
|
81 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); | |
82 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); |
|
82 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); | |
83 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); |
|
83 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); | |
84 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); |
|
84 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); | |
85 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); |
|
85 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | ChartAxis::~ChartAxis() |
|
88 | ChartAxis::~ChartAxis() | |
89 | { |
|
89 | { | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void ChartAxis::setAnimation(AxisAnimation *animation) |
|
92 | void ChartAxis::setAnimation(AxisAnimation *animation) | |
93 | { |
|
93 | { | |
94 | m_animation = animation; |
|
94 | m_animation = animation; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
97 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
98 | { |
|
98 | { | |
99 | m_layoutVector = layout; |
|
99 | m_layoutVector = layout; | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void ChartAxis::createItems(int count) |
|
102 | void ChartAxis::createItems(int count) | |
103 | { |
|
103 | { | |
104 |
if (m_arrow->child |
|
104 | if (m_arrow->childItems().size() == 0){ | |
105 | QGraphicsLineItem* arrow = new ArrowItem(this, this); |
|
105 | QGraphicsLineItem* arrow = new ArrowItem(this, this); | |
106 | arrow->setPen(m_axis->linePen()); |
|
106 | arrow->setPen(m_axis->linePen()); | |
107 | m_arrow->addToGroup(arrow); |
|
107 | m_arrow->addToGroup(arrow); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 |
if (m_intervalAxis && m_grid->child |
|
110 | if (m_intervalAxis && m_grid->childItems().size() == 0) { | |
111 | for (int i = 0 ; i < 2 ; i ++){ |
|
111 | for (int i = 0 ; i < 2 ; i ++){ | |
112 |
|
|
112 | QGraphicsLineItem* item = new QGraphicsLineItem(this); | |
113 |
|
|
113 | item->setPen(m_axis->gridLinePen()); | |
114 | m_grid->addToGroup(item); |
|
114 | m_grid->addToGroup(item); | |
115 | } |
|
115 | } | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | for (int i = 0; i < count; ++i) { |
|
118 | for (int i = 0; i < count; ++i) { | |
119 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); |
|
119 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); | |
120 | arrow->setPen(m_axis->linePen()); |
|
120 | arrow->setPen(m_axis->linePen()); | |
121 |
|
|
121 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); | |
122 |
|
|
122 | grid->setPen(m_axis->gridLinePen()); | |
123 |
|
|
123 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); | |
124 |
|
|
124 | label->setFont(m_axis->labelsFont()); | |
125 |
|
|
125 | label->setPen(m_axis->labelsPen()); | |
126 |
|
|
126 | label->setBrush(m_axis->labelsBrush()); | |
127 |
|
|
127 | m_arrow->addToGroup(arrow); | |
128 | m_grid->addToGroup(grid); |
|
128 | m_grid->addToGroup(grid); | |
129 | m_labels->addToGroup(label); |
|
129 | m_labels->addToGroup(label); | |
130 |
|
130 | |||
131 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ |
|
131 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ | |
132 |
|
|
132 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | |
133 |
|
|
133 | shades->setPen(m_axis->shadesPen()); | |
134 |
|
|
134 | shades->setBrush(m_axis->shadesBrush()); | |
135 | m_shades->addToGroup(shades); |
|
135 | m_shades->addToGroup(shades); | |
136 | } |
|
136 | } | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void ChartAxis::deleteItems(int count) |
|
141 | void ChartAxis::deleteItems(int count) | |
142 | { |
|
142 | { | |
143 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
143 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
144 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
144 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
145 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
145 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
146 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
146 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
147 |
|
147 | |||
148 | for (int i = 0; i < count; ++i) { |
|
148 | for (int i = 0; i < count; ++i) { | |
149 | if (lines.size() % 2 && lines.size() > 1) |
|
149 | if (lines.size() % 2 && lines.size() > 1) | |
150 | delete(shades.takeLast()); |
|
150 | delete(shades.takeLast()); | |
151 | delete(lines.takeLast()); |
|
151 | delete(lines.takeLast()); | |
152 | delete(labels.takeLast()); |
|
152 | delete(labels.takeLast()); | |
153 | delete(axis.takeLast()); |
|
153 | delete(axis.takeLast()); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
157 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
158 | { |
|
158 | { | |
159 | int diff = m_layoutVector.size() - layout.size(); |
|
159 | int diff = m_layoutVector.size() - layout.size(); | |
160 |
|
160 | |||
161 | if (diff > 0) |
|
161 | if (diff > 0) | |
162 | deleteItems(diff); |
|
162 | deleteItems(diff); | |
163 | else if (diff < 0) |
|
163 | else if (diff < 0) | |
164 | createItems(-diff); |
|
164 | createItems(-diff); | |
165 |
|
165 | |||
166 | if (m_animation) { |
|
166 | if (m_animation) { | |
167 | switch (presenter()->state()) { |
|
167 | switch (presenter()->state()) { | |
168 | case ChartPresenter::ZoomInState: |
|
168 | case ChartPresenter::ZoomInState: | |
169 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
169 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
170 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
170 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
171 | break; |
|
171 | break; | |
172 | case ChartPresenter::ZoomOutState: |
|
172 | case ChartPresenter::ZoomOutState: | |
173 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
173 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
174 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
174 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
175 | break; |
|
175 | break; | |
176 | case ChartPresenter::ScrollUpState: |
|
176 | case ChartPresenter::ScrollUpState: | |
177 | case ChartPresenter::ScrollLeftState: |
|
177 | case ChartPresenter::ScrollLeftState: | |
178 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
178 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
179 | break; |
|
179 | break; | |
180 | case ChartPresenter::ScrollDownState: |
|
180 | case ChartPresenter::ScrollDownState: | |
181 | case ChartPresenter::ScrollRightState: |
|
181 | case ChartPresenter::ScrollRightState: | |
182 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
182 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
183 | break; |
|
183 | break; | |
184 | case ChartPresenter::ShowState: |
|
184 | case ChartPresenter::ShowState: | |
185 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
185 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
186 | break; |
|
186 | break; | |
187 | } |
|
187 | } | |
188 | m_animation->setValues(m_layoutVector, layout); |
|
188 | m_animation->setValues(m_layoutVector, layout); | |
189 | presenter()->startAnimation(m_animation); |
|
189 | presenter()->startAnimation(m_animation); | |
190 | } else { |
|
190 | } else { | |
191 | setLayout(layout); |
|
191 | setLayout(layout); | |
192 | updateGeometry(); |
|
192 | updateGeometry(); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void ChartAxis::setLabelPadding(int padding) |
|
196 | void ChartAxis::setLabelPadding(int padding) | |
197 | { |
|
197 | { | |
198 | m_labelPadding = padding; |
|
198 | m_labelPadding = padding; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | bool ChartAxis::isEmpty() |
|
201 | bool ChartAxis::isEmpty() | |
202 | { |
|
202 | { | |
203 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); |
|
203 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
206 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |
207 | { |
|
207 | { | |
208 | m_gridRect = grid; |
|
208 | m_gridRect = grid; | |
209 | m_axisRect = axis; |
|
209 | m_axisRect = axis; | |
210 |
|
210 | |||
211 | if (isEmpty()) |
|
211 | if (isEmpty()) | |
212 | return; |
|
212 | return; | |
213 |
|
213 | |||
214 | QVector<qreal> layout = calculateLayout(); |
|
214 | QVector<qreal> layout = calculateLayout(); | |
215 | updateLayout(layout); |
|
215 | updateLayout(layout); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | qreal ChartAxis::min() const |
|
218 | qreal ChartAxis::min() const | |
219 | { |
|
219 | { | |
220 |
|
|
220 | return m_axis->d_ptr->min(); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | qreal ChartAxis::max() const |
|
223 | qreal ChartAxis::max() const | |
224 | { |
|
224 | { | |
225 |
|
|
225 | return m_axis->d_ptr->max(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | QFont ChartAxis::font() const |
|
228 | QFont ChartAxis::font() const | |
229 | { |
|
229 | { | |
230 |
|
|
230 | return m_axis->labelsFont(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | QFont ChartAxis::titleFont() const |
|
233 | QFont ChartAxis::titleFont() const | |
234 | { |
|
234 | { | |
235 |
|
|
235 | return m_axis->titleFont(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QString ChartAxis::titleText() const |
|
238 | QString ChartAxis::titleText() const | |
239 | { |
|
239 | { | |
240 |
|
|
240 | return m_axis->titleText(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | void ChartAxis::axisSelected() |
|
243 | void ChartAxis::axisSelected() | |
244 | { |
|
244 | { | |
245 |
|
|
245 | emit clicked(); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | Qt::Orientation ChartAxis::orientation() const |
|
248 | Qt::Orientation ChartAxis::orientation() const | |
249 | { |
|
249 | { | |
250 | return m_axis->orientation(); |
|
250 | return m_axis->orientation(); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | Qt::Alignment ChartAxis::alignment() const |
|
253 | Qt::Alignment ChartAxis::alignment() const | |
254 | { |
|
254 | { | |
255 | return m_axis->alignment(); |
|
255 | return m_axis->alignment(); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void ChartAxis::setLabels(const QStringList &labels) |
|
258 | void ChartAxis::setLabels(const QStringList &labels) | |
259 | { |
|
259 | { | |
260 | m_labelsList = labels; |
|
260 | m_labelsList = labels; | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
263 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
264 | { |
|
264 | { | |
265 | Q_UNUSED(which); |
|
265 | Q_UNUSED(which); | |
266 | Q_UNUSED(constraint); |
|
266 | Q_UNUSED(constraint); | |
267 | return QSizeF(); |
|
267 | return QSizeF(); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | //handlers |
|
270 | //handlers | |
271 |
|
271 | |||
272 | void ChartAxis::handleArrowVisibleChanged(bool visible) |
|
272 | void ChartAxis::handleArrowVisibleChanged(bool visible) | |
273 | { |
|
273 | { | |
274 | m_arrow->setVisible(visible); |
|
274 | m_arrow->setVisible(visible); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void ChartAxis::handleGridVisibleChanged(bool visible) |
|
277 | void ChartAxis::handleGridVisibleChanged(bool visible) | |
278 | { |
|
278 | { | |
279 | m_grid->setVisible(visible); |
|
279 | m_grid->setVisible(visible); | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void ChartAxis::handleLabelsVisibleChanged(bool visible) |
|
282 | void ChartAxis::handleLabelsVisibleChanged(bool visible) | |
283 | { |
|
283 | { | |
284 | m_labels->setVisible(visible); |
|
284 | m_labels->setVisible(visible); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | void ChartAxis::handleShadesVisibleChanged(bool visible) |
|
287 | void ChartAxis::handleShadesVisibleChanged(bool visible) | |
288 | { |
|
288 | { | |
289 | m_shades->setVisible(visible); |
|
289 | m_shades->setVisible(visible); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void ChartAxis::handleLabelsAngleChanged(int angle) |
|
292 | void ChartAxis::handleLabelsAngleChanged(int angle) | |
293 | { |
|
293 | { | |
294 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
294 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
295 | item->setRotation(angle); |
|
295 | item->setRotation(angle); | |
296 |
|
296 | |||
297 | m_labelsAngle = angle; |
|
297 | m_labelsAngle = angle; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) |
|
300 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) | |
301 | { |
|
301 | { | |
302 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
302 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
303 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
303 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) |
|
306 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) | |
307 | { |
|
307 | { | |
308 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
308 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
309 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); |
|
309 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void ChartAxis::handleLabelsFontChanged(const QFont &font) |
|
312 | void ChartAxis::handleLabelsFontChanged(const QFont &font) | |
313 | { |
|
313 | { | |
314 |
|
|
314 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
315 |
|
|
315 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
316 |
|
|
316 | QGraphicsLayoutItem::updateGeometry(); | |
317 |
|
|
317 | presenter()->layout()->invalidate(); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) |
|
320 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) | |
321 | { |
|
321 | { | |
322 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
322 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
323 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
323 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | void ChartAxis::handleShadesPenChanged(const QPen &pen) |
|
326 | void ChartAxis::handleShadesPenChanged(const QPen &pen) | |
327 | { |
|
327 | { | |
328 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
328 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
329 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
329 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void ChartAxis::handleArrowPenChanged(const QPen &pen) |
|
332 | void ChartAxis::handleArrowPenChanged(const QPen &pen) | |
333 | { |
|
333 | { | |
334 | foreach (QGraphicsItem *item , m_arrow->childItems()) |
|
334 | foreach (QGraphicsItem *item , m_arrow->childItems()) | |
335 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
335 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void ChartAxis::handleGridPenChanged(const QPen &pen) |
|
338 | void ChartAxis::handleGridPenChanged(const QPen &pen) | |
339 | { |
|
339 | { | |
340 | foreach (QGraphicsItem *item , m_grid->childItems()) |
|
340 | foreach (QGraphicsItem *item , m_grid->childItems()) | |
341 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
341 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | void ChartAxis::handleTitleTextChanged(const QString &title) |
|
344 | void ChartAxis::handleTitleTextChanged(const QString &title) | |
345 | { |
|
345 | { | |
346 |
|
|
346 | Q_UNUSED(title) | |
347 |
|
|
347 | QGraphicsLayoutItem::updateGeometry(); | |
348 |
|
|
348 | presenter()->layout()->invalidate(); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 |
|
351 | |||
352 | void ChartAxis::handleTitlePenChanged(const QPen &pen) |
|
352 | void ChartAxis::handleTitlePenChanged(const QPen &pen) | |
353 | { |
|
353 | { | |
354 | m_title->setPen(pen); |
|
354 | m_title->setPen(pen); | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) |
|
357 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) | |
358 | { |
|
358 | { | |
359 | m_title->setBrush(brush); |
|
359 | m_title->setBrush(brush); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void ChartAxis::handleTitleFontChanged(const QFont &font) |
|
362 | void ChartAxis::handleTitleFontChanged(const QFont &font) | |
363 | { |
|
363 | { | |
364 | if(m_title->font() != font){ |
|
364 | if(m_title->font() != font){ | |
365 | m_title->setFont(font); |
|
365 | m_title->setFont(font); | |
366 | QGraphicsLayoutItem::updateGeometry(); |
|
366 | QGraphicsLayoutItem::updateGeometry(); | |
367 | presenter()->layout()->invalidate(); |
|
367 | presenter()->layout()->invalidate(); | |
368 | } |
|
368 | } | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void ChartAxis::handleVisibleChanged(bool visible) |
|
371 | void ChartAxis::handleVisibleChanged(bool visible) | |
372 | { |
|
372 | { | |
373 |
|
|
373 | setVisible(visible); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | void ChartAxis::handleRangeChanged(qreal min, qreal max) |
|
376 | void ChartAxis::handleRangeChanged(qreal min, qreal max) | |
377 | { |
|
377 | { | |
378 |
|
|
378 | Q_UNUSED(min); | |
379 |
|
|
379 | Q_UNUSED(max); | |
380 |
|
380 | |||
381 |
|
|
381 | if (!isEmpty()) { | |
382 |
|
382 | |||
383 |
|
|
383 | QVector<qreal> layout = calculateLayout(); | |
384 |
|
|
384 | updateLayout(layout); | |
385 |
|
|
385 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
386 |
|
|
386 | QSizeF after = sizeHint(Qt::PreferredSize); | |
387 |
|
387 | |||
388 |
|
|
388 | if (before != after) { | |
389 |
|
|
389 | QGraphicsLayoutItem::updateGeometry(); | |
390 |
|
|
390 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
391 |
|
|
391 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
392 |
|
|
392 | //instead recalculate layout and use plotArea for extra space. | |
393 |
|
|
393 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
394 | } |
|
394 | } | |
395 | } |
|
395 | } | |
396 |
|
396 | |||
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | //helpers |
|
399 | //helpers | |
400 |
|
400 | |||
401 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) |
|
401 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) | |
402 | { |
|
402 | { | |
403 | //TODO: Q_ASSERT(m_max > m_min); |
|
403 | //TODO: Q_ASSERT(m_max > m_min); | |
404 | //TODO: Q_ASSERT(ticks > 1); |
|
404 | //TODO: Q_ASSERT(ticks > 1); | |
405 |
|
405 | |||
406 | QStringList labels; |
|
406 | QStringList labels; | |
407 |
|
407 | |||
408 | if(max <= min || ticks < 1){ |
|
408 | if(max <= min || ticks < 1){ | |
409 | return labels; |
|
409 | return labels; | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
412 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
413 | n++; |
|
413 | n++; | |
414 |
|
414 | |||
415 | if (format.isNull()) { |
|
415 | if (format.isNull()) { | |
416 | for (int i = 0; i < ticks; i++) { |
|
416 | for (int i = 0; i < ticks; i++) { | |
417 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
417 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
418 | labels << QString::number(value, 'f', n); |
|
418 | labels << QString::number(value, 'f', n); | |
419 | } |
|
419 | } | |
420 | } else { |
|
420 | } else { | |
421 | QByteArray array = format.toLatin1(); |
|
421 | QByteArray array = format.toLatin1(); | |
422 | for (int i = 0; i < ticks; i++) { |
|
422 | for (int i = 0; i < ticks; i++) { | |
423 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
423 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
424 | if (format.contains("d") |
|
424 | if (format.contains("d") | |
425 | || format.contains("i") |
|
425 | || format.contains("i") | |
426 | || format.contains("c")) |
|
426 | || format.contains("c")) | |
427 | labels << QString().sprintf(array, (qint64)value); |
|
427 | labels << QString().sprintf(array, (qint64)value); | |
428 | else if (format.contains("u") |
|
428 | else if (format.contains("u") | |
429 | || format.contains("o") |
|
429 | || format.contains("o") | |
430 | || format.contains("x", Qt::CaseInsensitive)) |
|
430 | || format.contains("x", Qt::CaseInsensitive)) | |
431 | labels << QString().sprintf(array, (quint64)value); |
|
431 | labels << QString().sprintf(array, (quint64)value); | |
432 | else if (format.contains("f", Qt::CaseInsensitive) |
|
432 | else if (format.contains("f", Qt::CaseInsensitive) | |
433 | || format.contains("e", Qt::CaseInsensitive) |
|
433 | || format.contains("e", Qt::CaseInsensitive) | |
434 | || format.contains("g", Qt::CaseInsensitive)) |
|
434 | || format.contains("g", Qt::CaseInsensitive)) | |
435 | labels << QString().sprintf(array, value); |
|
435 | labels << QString().sprintf(array, value); | |
436 | } |
|
436 | } | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | return labels; |
|
439 | return labels; | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) |
|
442 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) | |
443 | { |
|
443 | { | |
444 | // Q_ASSERT(m_max > m_min); |
|
444 | // Q_ASSERT(m_max > m_min); | |
445 | // Q_ASSERT(ticks > 1); |
|
445 | // Q_ASSERT(ticks > 1); | |
446 |
|
446 | |||
447 | QStringList labels; |
|
447 | QStringList labels; | |
448 |
|
448 | |||
449 | int n = 0; |
|
449 | int n = 0; | |
450 | if (ticks > 1) |
|
450 | if (ticks > 1) | |
451 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
451 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
452 | n++; |
|
452 | n++; | |
453 |
|
453 | |||
454 | int firstTick; |
|
454 | int firstTick; | |
455 | if (base > 1) |
|
455 | if (base > 1) | |
456 | firstTick = ceil(log10(min) / log10(base)); |
|
456 | firstTick = ceil(log10(min) / log10(base)); | |
457 | else |
|
457 | else | |
458 | firstTick = ceil(log10(max) / log10(base)); |
|
458 | firstTick = ceil(log10(max) / log10(base)); | |
459 |
|
459 | |||
460 | if (format.isNull()) { |
|
460 | if (format.isNull()) { | |
461 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
461 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
462 | qreal value = qPow(base, i); |
|
462 | qreal value = qPow(base, i); | |
463 | labels << QString::number(value, 'f', n); |
|
463 | labels << QString::number(value, 'f', n); | |
464 | } |
|
464 | } | |
465 | } else { |
|
465 | } else { | |
466 |
QByteArray array = format.to |
|
466 | QByteArray array = format.toLatin1(); | |
467 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
467 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
468 | qreal value = qPow(base, i); |
|
468 | qreal value = qPow(base, i); | |
469 | labels << QString().sprintf(array, value); |
|
469 | labels << QString().sprintf(array, value); | |
470 | } |
|
470 | } | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | return labels; |
|
473 | return labels; | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) |
|
476 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) | |
477 | { |
|
477 | { | |
478 | //TODO: Q_ASSERT(m_max > m_min); |
|
478 | //TODO: Q_ASSERT(m_max > m_min); | |
479 | //TODO: Q_ASSERT(ticks > 1); |
|
479 | //TODO: Q_ASSERT(ticks > 1); | |
480 | QStringList labels; |
|
480 | QStringList labels; | |
481 |
|
481 | |||
482 | if(max <= min || ticks < 1) { |
|
482 | if(max <= min || ticks < 1) { | |
483 | return labels; |
|
483 | return labels; | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
486 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |
487 | n++; |
|
487 | n++; | |
488 | for (int i = 0; i < ticks; i++) { |
|
488 | for (int i = 0; i < ticks; i++) { | |
489 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
489 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
490 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
490 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
491 | } |
|
491 | } | |
492 | return labels; |
|
492 | return labels; | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | #include "moc_chartaxis_p.cpp" |
|
495 | #include "moc_chartaxis_p.cpp" | |
496 |
|
496 | |||
497 | QTCOMMERCIALCHART_END_NAMESPACE |
|
497 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,925 +1,925 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "pieslicedata_p.h" |
|
25 | #include "pieslicedata_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qabstractaxis.h" |
|
28 | #include "qabstractaxis.h" | |
29 | #include "pieanimation_p.h" |
|
29 | #include "pieanimation_p.h" | |
30 |
|
30 | |||
31 | #include "qpielegendmarker.h" |
|
31 | #include "qpielegendmarker.h" | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QPieSeries |
|
36 | \class QPieSeries | |
37 | \brief Pie series API for QtCommercial Charts |
|
37 | \brief Pie series API for QtCommercial Charts | |
38 |
|
38 | |||
39 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
39 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
40 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
40 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
41 | The actual slice size is determined by that relative value. |
|
41 | The actual slice size is determined by that relative value. | |
42 |
|
42 | |||
43 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
43 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
44 | These relate to the actual chart rectangle. |
|
44 | These relate to the actual chart rectangle. | |
45 |
|
45 | |||
46 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
46 | By default the pie is defined as a full pie but it can also be a partial pie. | |
47 | This can be done by setting a starting angle and angle span to the series. |
|
47 | This can be done by setting a starting angle and angle span to the series. | |
48 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
48 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
49 |
|
49 | |||
50 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
50 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. | |
51 | \table 100% |
|
51 | \table 100% | |
52 | \row |
|
52 | \row | |
53 | \o \image examples_piechart.png |
|
53 | \o \image examples_piechart.png | |
54 | \o \image examples_donut.png |
|
54 | \o \image examples_donut.png | |
55 | \endtable |
|
55 | \endtable | |
56 | */ |
|
56 | */ | |
57 | /*! |
|
57 | /*! | |
58 | \qmlclass PieSeries QPieSeries |
|
58 | \qmlclass PieSeries QPieSeries | |
59 | \inherits AbstractSeries |
|
59 | \inherits AbstractSeries | |
60 |
|
60 | |||
61 | The following QML shows how to create a simple pie chart. |
|
61 | The following QML shows how to create a simple pie chart. | |
62 |
|
62 | |||
63 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
63 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
64 |
|
64 | |||
65 | \beginfloatleft |
|
65 | \beginfloatleft | |
66 | \image demos_qmlchart1.png |
|
66 | \image demos_qmlchart1.png | |
67 | \endfloat |
|
67 | \endfloat | |
68 | \clearfloat |
|
68 | \clearfloat | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QPieSeries::horizontalPosition |
|
72 | \property QPieSeries::horizontalPosition | |
73 | \brief Defines the horizontal position of the pie. |
|
73 | \brief Defines the horizontal position of the pie. | |
74 |
|
74 | |||
75 | The value is a relative value to the chart rectangle where: |
|
75 | The value is a relative value to the chart rectangle where: | |
76 |
|
76 | |||
77 | \list |
|
77 | \list | |
78 | \o 0.0 is the absolute left. |
|
78 | \o 0.0 is the absolute left. | |
79 | \o 1.0 is the absolute right. |
|
79 | \o 1.0 is the absolute right. | |
80 | \endlist |
|
80 | \endlist | |
81 | Default value is 0.5 (center). |
|
81 | Default value is 0.5 (center). | |
82 | \sa verticalPosition |
|
82 | \sa verticalPosition | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty real PieSeries::horizontalPosition |
|
86 | \qmlproperty real PieSeries::horizontalPosition | |
87 |
|
87 | |||
88 | Defines the horizontal position of the pie. |
|
88 | Defines the horizontal position of the pie. | |
89 |
|
89 | |||
90 | The value is a relative value to the chart rectangle where: |
|
90 | The value is a relative value to the chart rectangle where: | |
91 |
|
91 | |||
92 | \list |
|
92 | \list | |
93 | \o 0.0 is the absolute left. |
|
93 | \o 0.0 is the absolute left. | |
94 | \o 1.0 is the absolute right. |
|
94 | \o 1.0 is the absolute right. | |
95 | \endlist |
|
95 | \endlist | |
96 | Default value is 0.5 (center). |
|
96 | Default value is 0.5 (center). | |
97 | \sa verticalPosition |
|
97 | \sa verticalPosition | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \property QPieSeries::verticalPosition |
|
101 | \property QPieSeries::verticalPosition | |
102 | \brief Defines the vertical position of the pie. |
|
102 | \brief Defines the vertical position of the pie. | |
103 |
|
103 | |||
104 | The value is a relative value to the chart rectangle where: |
|
104 | The value is a relative value to the chart rectangle where: | |
105 |
|
105 | |||
106 | \list |
|
106 | \list | |
107 | \o 0.0 is the absolute top. |
|
107 | \o 0.0 is the absolute top. | |
108 | \o 1.0 is the absolute bottom. |
|
108 | \o 1.0 is the absolute bottom. | |
109 | \endlist |
|
109 | \endlist | |
110 | Default value is 0.5 (center). |
|
110 | Default value is 0.5 (center). | |
111 | \sa horizontalPosition |
|
111 | \sa horizontalPosition | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty real PieSeries::verticalPosition |
|
115 | \qmlproperty real PieSeries::verticalPosition | |
116 |
|
116 | |||
117 | Defines the vertical position of the pie. |
|
117 | Defines the vertical position of the pie. | |
118 |
|
118 | |||
119 | The value is a relative value to the chart rectangle where: |
|
119 | The value is a relative value to the chart rectangle where: | |
120 |
|
120 | |||
121 | \list |
|
121 | \list | |
122 | \o 0.0 is the absolute top. |
|
122 | \o 0.0 is the absolute top. | |
123 | \o 1.0 is the absolute bottom. |
|
123 | \o 1.0 is the absolute bottom. | |
124 | \endlist |
|
124 | \endlist | |
125 | Default value is 0.5 (center). |
|
125 | Default value is 0.5 (center). | |
126 | \sa horizontalPosition |
|
126 | \sa horizontalPosition | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \property QPieSeries::size |
|
130 | \property QPieSeries::size | |
131 | \brief Defines the pie size. |
|
131 | \brief Defines the pie size. | |
132 |
|
132 | |||
133 | The value is a relative value to the chart rectangle where: |
|
133 | The value is a relative value to the chart rectangle where: | |
134 |
|
134 | |||
135 | \list |
|
135 | \list | |
136 | \o 0.0 is the minimum size (pie not drawn). |
|
136 | \o 0.0 is the minimum size (pie not drawn). | |
137 | \o 1.0 is the maximum size that can fit the chart. |
|
137 | \o 1.0 is the maximum size that can fit the chart. | |
138 | \endlist |
|
138 | \endlist | |
139 |
|
139 | |||
140 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
140 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. | |
141 |
|
141 | |||
142 | Default value is 0.7. |
|
142 | Default value is 0.7. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \qmlproperty real PieSeries::size |
|
146 | \qmlproperty real PieSeries::size | |
147 |
|
147 | |||
148 | Defines the pie size. |
|
148 | Defines the pie size. | |
149 |
|
149 | |||
150 | The value is a relative value to the chart rectangle where: |
|
150 | The value is a relative value to the chart rectangle where: | |
151 |
|
151 | |||
152 | \list |
|
152 | \list | |
153 | \o 0.0 is the minimum size (pie not drawn). |
|
153 | \o 0.0 is the minimum size (pie not drawn). | |
154 | \o 1.0 is the maximum size that can fit the chart. |
|
154 | \o 1.0 is the maximum size that can fit the chart. | |
155 | \endlist |
|
155 | \endlist | |
156 |
|
156 | |||
157 | Default value is 0.7. |
|
157 | Default value is 0.7. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \property QPieSeries::holeSize |
|
161 | \property QPieSeries::holeSize | |
162 | \brief Defines the donut hole size. |
|
162 | \brief Defines the donut hole size. | |
163 |
|
163 | |||
164 | The value is a relative value to the chart rectangle where: |
|
164 | The value is a relative value to the chart rectangle where: | |
165 |
|
165 | |||
166 | \list |
|
166 | \list | |
167 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
167 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
168 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
168 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
169 | \endlist |
|
169 | \endlist | |
170 |
|
170 | |||
171 | The value is never greater then size property. |
|
171 | The value is never greater then size property. | |
172 | Default value is 0.0. |
|
172 | Default value is 0.0. | |
173 | */ |
|
173 | */ | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | \qmlproperty real PieSeries::holeSize |
|
176 | \qmlproperty real PieSeries::holeSize | |
177 |
|
177 | |||
178 | Defines the donut hole size. |
|
178 | Defines the donut hole size. | |
179 |
|
179 | |||
180 | The value is a relative value to the chart rectangle where: |
|
180 | The value is a relative value to the chart rectangle where: | |
181 |
|
181 | |||
182 | \list |
|
182 | \list | |
183 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
183 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
184 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
184 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
185 | \endlist |
|
185 | \endlist | |
186 |
|
186 | |||
187 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
187 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. | |
188 |
|
188 | |||
189 | Default value is 0.0. |
|
189 | Default value is 0.0. | |
190 | */ |
|
190 | */ | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \property QPieSeries::startAngle |
|
193 | \property QPieSeries::startAngle | |
194 | \brief Defines the starting angle of the pie. |
|
194 | \brief Defines the starting angle of the pie. | |
195 |
|
195 | |||
196 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
196 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
197 |
|
197 | |||
198 | Default is value is 0. |
|
198 | Default is value is 0. | |
199 | */ |
|
199 | */ | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | \qmlproperty real PieSeries::startAngle |
|
202 | \qmlproperty real PieSeries::startAngle | |
203 |
|
203 | |||
204 | Defines the starting angle of the pie. |
|
204 | Defines the starting angle of the pie. | |
205 |
|
205 | |||
206 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
206 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
207 |
|
207 | |||
208 | Default is value is 0. |
|
208 | Default is value is 0. | |
209 | */ |
|
209 | */ | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | \property QPieSeries::endAngle |
|
212 | \property QPieSeries::endAngle | |
213 | \brief Defines the ending angle of the pie. |
|
213 | \brief Defines the ending angle of the pie. | |
214 |
|
214 | |||
215 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
215 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
216 |
|
216 | |||
217 | Default is value is 360. |
|
217 | Default is value is 360. | |
218 | */ |
|
218 | */ | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | \qmlproperty real PieSeries::endAngle |
|
221 | \qmlproperty real PieSeries::endAngle | |
222 |
|
222 | |||
223 | Defines the ending angle of the pie. |
|
223 | Defines the ending angle of the pie. | |
224 |
|
224 | |||
225 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
225 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
226 |
|
226 | |||
227 | Default is value is 360. |
|
227 | Default is value is 360. | |
228 | */ |
|
228 | */ | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | \property QPieSeries::count |
|
231 | \property QPieSeries::count | |
232 |
|
232 | |||
233 | Number of slices in the series. |
|
233 | Number of slices in the series. | |
234 | */ |
|
234 | */ | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | \qmlproperty int PieSeries::count |
|
237 | \qmlproperty int PieSeries::count | |
238 |
|
238 | |||
239 | Number of slices in the series. |
|
239 | Number of slices in the series. | |
240 | */ |
|
240 | */ | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | \fn void QPieSeries::countChanged() |
|
243 | \fn void QPieSeries::countChanged() | |
244 | Emitted when the slice count has changed. |
|
244 | Emitted when the slice count has changed. | |
245 | \sa count |
|
245 | \sa count | |
246 | */ |
|
246 | */ | |
247 | /*! |
|
247 | /*! | |
248 | \qmlsignal PieSeries::onCountChanged() |
|
248 | \qmlsignal PieSeries::onCountChanged() | |
249 | Emitted when the slice count has changed. |
|
249 | Emitted when the slice count has changed. | |
250 | */ |
|
250 | */ | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | \property QPieSeries::sum |
|
253 | \property QPieSeries::sum | |
254 |
|
254 | |||
255 | Sum of all slices. |
|
255 | Sum of all slices. | |
256 |
|
256 | |||
257 | The series keeps track of the sum of all slices it holds. |
|
257 | The series keeps track of the sum of all slices it holds. | |
258 | */ |
|
258 | */ | |
259 |
|
259 | |||
260 | /*! |
|
260 | /*! | |
261 | \qmlproperty real PieSeries::sum |
|
261 | \qmlproperty real PieSeries::sum | |
262 |
|
262 | |||
263 | Sum of all slices. |
|
263 | Sum of all slices. | |
264 |
|
264 | |||
265 | The series keeps track of the sum of all slices it holds. |
|
265 | The series keeps track of the sum of all slices it holds. | |
266 | */ |
|
266 | */ | |
267 |
|
267 | |||
268 | /*! |
|
268 | /*! | |
269 | \fn void QPieSeries::sumChanged() |
|
269 | \fn void QPieSeries::sumChanged() | |
270 | Emitted when the sum of all slices has changed. |
|
270 | Emitted when the sum of all slices has changed. | |
271 | \sa sum |
|
271 | \sa sum | |
272 | */ |
|
272 | */ | |
273 | /*! |
|
273 | /*! | |
274 | \qmlsignal PieSeries::onSumChanged() |
|
274 | \qmlsignal PieSeries::onSumChanged() | |
275 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
275 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
276 | change value of a slice. |
|
276 | change value of a slice. | |
277 | */ |
|
277 | */ | |
278 |
|
278 | |||
279 | /*! |
|
279 | /*! | |
280 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
280 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
281 |
|
281 | |||
282 | This signal is emitted when \a slices have been added to the series. |
|
282 | This signal is emitted when \a slices have been added to the series. | |
283 |
|
283 | |||
284 | \sa append(), insert() |
|
284 | \sa append(), insert() | |
285 | */ |
|
285 | */ | |
286 | /*! |
|
286 | /*! | |
287 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
287 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
288 | Emitted when \a slice has been added to the series. |
|
288 | Emitted when \a slice has been added to the series. | |
289 | */ |
|
289 | */ | |
290 |
|
290 | |||
291 | /*! |
|
291 | /*! | |
292 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
292 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
293 | This signal is emitted when \a slices have been removed from the series. |
|
293 | This signal is emitted when \a slices have been removed from the series. | |
294 | \sa remove() |
|
294 | \sa remove() | |
295 | */ |
|
295 | */ | |
296 | /*! |
|
296 | /*! | |
297 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
297 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
298 | Emitted when \a slice has been removed from the series. |
|
298 | Emitted when \a slice has been removed from the series. | |
299 | */ |
|
299 | */ | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
302 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
303 | This signal is emitted when a \a slice has been clicked. |
|
303 | This signal is emitted when a \a slice has been clicked. | |
304 | \sa QPieSlice::clicked() |
|
304 | \sa QPieSlice::clicked() | |
305 | */ |
|
305 | */ | |
306 | /*! |
|
306 | /*! | |
307 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
307 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
308 | This signal is emitted when a \a slice has been clicked. |
|
308 | This signal is emitted when a \a slice has been clicked. | |
309 | */ |
|
309 | */ | |
310 |
|
310 | |||
311 | /*! |
|
311 | /*! | |
312 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
312 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
313 | This signal is emitted when user has hovered over or away from the \a slice. |
|
313 | This signal is emitted when user has hovered over or away from the \a slice. | |
314 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
314 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
315 | \sa QPieSlice::hovered() |
|
315 | \sa QPieSlice::hovered() | |
316 | */ |
|
316 | */ | |
317 | /*! |
|
317 | /*! | |
318 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
318 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
319 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
319 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
320 | over the slice and false when hover has moved away from the slice. |
|
320 | over the slice and false when hover has moved away from the slice. | |
321 | */ |
|
321 | */ | |
322 |
|
322 | |||
323 | /*! |
|
323 | /*! | |
324 | \qmlmethod PieSlice PieSeries::at(int index) |
|
324 | \qmlmethod PieSlice PieSeries::at(int index) | |
325 | Returns slice at \a index. Returns null if the index is not valid. |
|
325 | Returns slice at \a index. Returns null if the index is not valid. | |
326 | */ |
|
326 | */ | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | \qmlmethod PieSlice PieSeries::find(string label) |
|
329 | \qmlmethod PieSlice PieSeries::find(string label) | |
330 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
330 | Returns the first slice with \a label. Returns null if the index is not valid. | |
331 | */ |
|
331 | */ | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
334 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
335 | Adds a new slice with \a label and \a value to the pie. |
|
335 | Adds a new slice with \a label and \a value to the pie. | |
336 | */ |
|
336 | */ | |
337 |
|
337 | |||
338 | /*! |
|
338 | /*! | |
339 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
339 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
340 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
340 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. | |
341 | */ |
|
341 | */ | |
342 |
|
342 | |||
343 | /*! |
|
343 | /*! | |
344 | \qmlmethod PieSeries::clear() |
|
344 | \qmlmethod PieSeries::clear() | |
345 | Removes all slices from the pie. |
|
345 | Removes all slices from the pie. | |
346 | */ |
|
346 | */ | |
347 |
|
347 | |||
348 | /*! |
|
348 | /*! | |
349 | Constructs a series object which is a child of \a parent. |
|
349 | Constructs a series object which is a child of \a parent. | |
350 | */ |
|
350 | */ | |
351 | QPieSeries::QPieSeries(QObject *parent) |
|
351 | QPieSeries::QPieSeries(QObject *parent) | |
352 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
352 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) | |
353 | { |
|
353 | { | |
354 | Q_D(QPieSeries); |
|
354 | Q_D(QPieSeries); | |
355 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
355 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | /*! |
|
358 | /*! | |
359 | Destroys the series and its slices. |
|
359 | Destroys the series and its slices. | |
360 | */ |
|
360 | */ | |
361 | QPieSeries::~QPieSeries() |
|
361 | QPieSeries::~QPieSeries() | |
362 | { |
|
362 | { | |
363 | // NOTE: d_prt destroyed by QObject |
|
363 | // NOTE: d_prt destroyed by QObject | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | /*! |
|
366 | /*! | |
367 | Returns QChartSeries::SeriesTypePie. |
|
367 | Returns QChartSeries::SeriesTypePie. | |
368 | */ |
|
368 | */ | |
369 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
369 | QAbstractSeries::SeriesType QPieSeries::type() const | |
370 | { |
|
370 | { | |
371 | return QAbstractSeries::SeriesTypePie; |
|
371 | return QAbstractSeries::SeriesTypePie; | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | /*! |
|
374 | /*! | |
375 | Appends a single \a slice to the series. |
|
375 | Appends a single \a slice to the series. | |
376 | Slice ownership is passed to the series. |
|
376 | Slice ownership is passed to the series. | |
377 |
|
377 | |||
378 | Returns true if append was succesfull. |
|
378 | Returns true if append was succesfull. | |
379 | */ |
|
379 | */ | |
380 | bool QPieSeries::append(QPieSlice *slice) |
|
380 | bool QPieSeries::append(QPieSlice *slice) | |
381 | { |
|
381 | { | |
382 | return append(QList<QPieSlice *>() << slice); |
|
382 | return append(QList<QPieSlice *>() << slice); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | /*! |
|
385 | /*! | |
386 | Appends an array of \a slices to the series. |
|
386 | Appends an array of \a slices to the series. | |
387 | Slice ownership is passed to the series. |
|
387 | Slice ownership is passed to the series. | |
388 |
|
388 | |||
389 | Returns true if append was successful. |
|
389 | Returns true if append was successful. | |
390 | */ |
|
390 | */ | |
391 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
391 | bool QPieSeries::append(QList<QPieSlice *> slices) | |
392 | { |
|
392 | { | |
393 | Q_D(QPieSeries); |
|
393 | Q_D(QPieSeries); | |
394 |
|
394 | |||
395 | if (slices.count() == 0) |
|
395 | if (slices.count() == 0) | |
396 | return false; |
|
396 | return false; | |
397 |
|
397 | |||
398 | foreach (QPieSlice *s, slices) { |
|
398 | foreach (QPieSlice *s, slices) { | |
399 | if (!s || d->m_slices.contains(s)) |
|
399 | if (!s || d->m_slices.contains(s)) | |
400 | return false; |
|
400 | return false; | |
401 | if (s->series()) // already added to some series |
|
401 | if (s->series()) // already added to some series | |
402 | return false; |
|
402 | return false; | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | foreach (QPieSlice *s, slices) { |
|
405 | foreach (QPieSlice *s, slices) { | |
406 | s->setParent(this); |
|
406 | s->setParent(this); | |
407 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
407 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
408 | d->m_slices << s; |
|
408 | d->m_slices << s; | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | d->updateDerivativeData(); |
|
411 | d->updateDerivativeData(); | |
412 |
|
412 | |||
413 | foreach(QPieSlice * s, slices) { |
|
413 | foreach(QPieSlice * s, slices) { | |
414 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
414 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
415 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
415 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
416 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
416 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | emit added(slices); |
|
419 | emit added(slices); | |
420 | emit countChanged(); |
|
420 | emit countChanged(); | |
421 |
|
421 | |||
422 | return true; |
|
422 | return true; | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | Appends a single \a slice to the series and returns a reference to the series. |
|
426 | Appends a single \a slice to the series and returns a reference to the series. | |
427 | Slice ownership is passed to the series. |
|
427 | Slice ownership is passed to the series. | |
428 | */ |
|
428 | */ | |
429 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
429 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) | |
430 | { |
|
430 | { | |
431 | append(slice); |
|
431 | append(slice); | |
432 | return *this; |
|
432 | return *this; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 |
|
435 | |||
436 | /*! |
|
436 | /*! | |
437 | Appends a single slice to the series with give \a value and \a label. |
|
437 | Appends a single slice to the series with give \a value and \a label. | |
438 | Slice ownership is passed to the series. |
|
438 | Slice ownership is passed to the series. | |
439 | */ |
|
439 | */ | |
440 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
440 | QPieSlice *QPieSeries::append(QString label, qreal value) | |
441 | { |
|
441 | { | |
442 | QPieSlice *slice = new QPieSlice(label, value); |
|
442 | QPieSlice *slice = new QPieSlice(label, value); | |
443 | append(slice); |
|
443 | append(slice); | |
444 | return slice; |
|
444 | return slice; | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | /*! |
|
447 | /*! | |
448 | Inserts a single \a slice to the series before the slice at \a index position. |
|
448 | Inserts a single \a slice to the series before the slice at \a index position. | |
449 | Slice ownership is passed to the series. |
|
449 | Slice ownership is passed to the series. | |
450 |
|
450 | |||
451 | Returns true if insert was successful. |
|
451 | Returns true if insert was successful. | |
452 | */ |
|
452 | */ | |
453 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
453 | bool QPieSeries::insert(int index, QPieSlice *slice) | |
454 | { |
|
454 | { | |
455 | Q_D(QPieSeries); |
|
455 | Q_D(QPieSeries); | |
456 |
|
456 | |||
457 | if (index < 0 || index > d->m_slices.count()) |
|
457 | if (index < 0 || index > d->m_slices.count()) | |
458 | return false; |
|
458 | return false; | |
459 |
|
459 | |||
460 | if (!slice || d->m_slices.contains(slice)) |
|
460 | if (!slice || d->m_slices.contains(slice)) | |
461 | return false; |
|
461 | return false; | |
462 |
|
462 | |||
463 | if (slice->series()) // already added to some series |
|
463 | if (slice->series()) // already added to some series | |
464 | return false; |
|
464 | return false; | |
465 |
|
465 | |||
466 | slice->setParent(this); |
|
466 | slice->setParent(this); | |
467 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
467 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
468 | d->m_slices.insert(index, slice); |
|
468 | d->m_slices.insert(index, slice); | |
469 |
|
469 | |||
470 | d->updateDerivativeData(); |
|
470 | d->updateDerivativeData(); | |
471 |
|
471 | |||
472 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
472 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
473 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
473 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
474 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
474 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
475 |
|
475 | |||
476 | emit added(QList<QPieSlice *>() << slice); |
|
476 | emit added(QList<QPieSlice *>() << slice); | |
477 | emit countChanged(); |
|
477 | emit countChanged(); | |
478 |
|
478 | |||
479 | return true; |
|
479 | return true; | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | /*! |
|
482 | /*! | |
483 | Removes a single \a slice from the series and deletes the slice. |
|
483 | Removes a single \a slice from the series and deletes the slice. | |
484 |
|
484 | |||
485 | Do not reference the pointer after this call. |
|
485 | Do not reference the pointer after this call. | |
486 |
|
486 | |||
487 | Returns true if remove was successful. |
|
487 | Returns true if remove was successful. | |
488 | */ |
|
488 | */ | |
489 | bool QPieSeries::remove(QPieSlice *slice) |
|
489 | bool QPieSeries::remove(QPieSlice *slice) | |
490 | { |
|
490 | { | |
491 | Q_D(QPieSeries); |
|
491 | Q_D(QPieSeries); | |
492 |
|
492 | |||
493 | if (!d->m_slices.removeOne(slice)) |
|
493 | if (!d->m_slices.removeOne(slice)) | |
494 | return false; |
|
494 | return false; | |
495 |
|
495 | |||
496 | d->updateDerivativeData(); |
|
496 | d->updateDerivativeData(); | |
497 |
|
497 | |||
498 | emit removed(QList<QPieSlice *>() << slice); |
|
498 | emit removed(QList<QPieSlice *>() << slice); | |
499 | emit countChanged(); |
|
499 | emit countChanged(); | |
500 |
|
500 | |||
501 | delete slice; |
|
501 | delete slice; | |
502 | slice = 0; |
|
502 | slice = 0; | |
503 |
|
503 | |||
504 | return true; |
|
504 | return true; | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | /*! |
|
507 | /*! | |
508 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
508 | Takes a single \a slice from the series. Does not destroy the slice object. | |
509 |
|
509 | |||
510 | NOTE: The series remains as the slice's parent object. You must set the |
|
510 | NOTE: The series remains as the slice's parent object. You must set the | |
511 | parent object to take full ownership. |
|
511 | parent object to take full ownership. | |
512 |
|
512 | |||
513 | Returns true if take was successful. |
|
513 | Returns true if take was successful. | |
514 | */ |
|
514 | */ | |
515 | bool QPieSeries::take(QPieSlice *slice) |
|
515 | bool QPieSeries::take(QPieSlice *slice) | |
516 | { |
|
516 | { | |
517 | Q_D(QPieSeries); |
|
517 | Q_D(QPieSeries); | |
518 |
|
518 | |||
519 | if (!d->m_slices.removeOne(slice)) |
|
519 | if (!d->m_slices.removeOne(slice)) | |
520 | return false; |
|
520 | return false; | |
521 |
|
521 | |||
522 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
522 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; | |
523 | slice->disconnect(d); |
|
523 | slice->disconnect(d); | |
524 |
|
524 | |||
525 | d->updateDerivativeData(); |
|
525 | d->updateDerivativeData(); | |
526 |
|
526 | |||
527 | emit removed(QList<QPieSlice *>() << slice); |
|
527 | emit removed(QList<QPieSlice *>() << slice); | |
528 | emit countChanged(); |
|
528 | emit countChanged(); | |
529 |
|
529 | |||
530 | return true; |
|
530 | return true; | |
531 | } |
|
531 | } | |
532 |
|
532 | |||
533 | /*! |
|
533 | /*! | |
534 | Clears all slices from the series. |
|
534 | Clears all slices from the series. | |
535 | */ |
|
535 | */ | |
536 | void QPieSeries::clear() |
|
536 | void QPieSeries::clear() | |
537 | { |
|
537 | { | |
538 | Q_D(QPieSeries); |
|
538 | Q_D(QPieSeries); | |
539 | if (d->m_slices.count() == 0) |
|
539 | if (d->m_slices.count() == 0) | |
540 | return; |
|
540 | return; | |
541 |
|
541 | |||
542 | QList<QPieSlice *> slices = d->m_slices; |
|
542 | QList<QPieSlice *> slices = d->m_slices; | |
543 | foreach (QPieSlice *s, d->m_slices) |
|
543 | foreach (QPieSlice *s, d->m_slices) | |
544 | d->m_slices.removeOne(s); |
|
544 | d->m_slices.removeOne(s); | |
545 |
|
545 | |||
546 | d->updateDerivativeData(); |
|
546 | d->updateDerivativeData(); | |
547 |
|
547 | |||
548 | emit removed(slices); |
|
548 | emit removed(slices); | |
549 | emit countChanged(); |
|
549 | emit countChanged(); | |
550 |
|
550 | |||
551 | foreach (QPieSlice *s, slices) |
|
551 | foreach (QPieSlice *s, slices) | |
552 | delete s; |
|
552 | delete s; | |
553 | } |
|
553 | } | |
554 |
|
554 | |||
555 | /*! |
|
555 | /*! | |
556 | Returns a list of slices that belong to this series. |
|
556 | Returns a list of slices that belong to this series. | |
557 | */ |
|
557 | */ | |
558 | QList<QPieSlice *> QPieSeries::slices() const |
|
558 | QList<QPieSlice *> QPieSeries::slices() const | |
559 | { |
|
559 | { | |
560 | Q_D(const QPieSeries); |
|
560 | Q_D(const QPieSeries); | |
561 | return d->m_slices; |
|
561 | return d->m_slices; | |
562 | } |
|
562 | } | |
563 |
|
563 | |||
564 | /*! |
|
564 | /*! | |
565 | returns the number of the slices in this series. |
|
565 | returns the number of the slices in this series. | |
566 | */ |
|
566 | */ | |
567 | int QPieSeries::count() const |
|
567 | int QPieSeries::count() const | |
568 | { |
|
568 | { | |
569 | Q_D(const QPieSeries); |
|
569 | Q_D(const QPieSeries); | |
570 | return d->m_slices.count(); |
|
570 | return d->m_slices.count(); | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | /*! |
|
573 | /*! | |
574 | Returns true is the series is empty. |
|
574 | Returns true is the series is empty. | |
575 | */ |
|
575 | */ | |
576 | bool QPieSeries::isEmpty() const |
|
576 | bool QPieSeries::isEmpty() const | |
577 | { |
|
577 | { | |
578 | Q_D(const QPieSeries); |
|
578 | Q_D(const QPieSeries); | |
579 | return d->m_slices.isEmpty(); |
|
579 | return d->m_slices.isEmpty(); | |
580 | } |
|
580 | } | |
581 |
|
581 | |||
582 | /*! |
|
582 | /*! | |
583 | Returns the sum of all slice values in this series. |
|
583 | Returns the sum of all slice values in this series. | |
584 |
|
584 | |||
585 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
585 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
586 | */ |
|
586 | */ | |
587 | qreal QPieSeries::sum() const |
|
587 | qreal QPieSeries::sum() const | |
588 | { |
|
588 | { | |
589 | Q_D(const QPieSeries); |
|
589 | Q_D(const QPieSeries); | |
590 | return d->m_sum; |
|
590 | return d->m_sum; | |
591 | } |
|
591 | } | |
592 |
|
592 | |||
593 | void QPieSeries::setHoleSize(qreal holeSize) |
|
593 | void QPieSeries::setHoleSize(qreal holeSize) | |
594 | { |
|
594 | { | |
595 | Q_D(QPieSeries); |
|
595 | Q_D(QPieSeries); | |
596 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
596 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); | |
597 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
597 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); | |
598 | } |
|
598 | } | |
599 |
|
599 | |||
600 | qreal QPieSeries::holeSize() const |
|
600 | qreal QPieSeries::holeSize() const | |
601 | { |
|
601 | { | |
602 | Q_D(const QPieSeries); |
|
602 | Q_D(const QPieSeries); | |
603 | return d->m_holeRelativeSize; |
|
603 | return d->m_holeRelativeSize; | |
604 | } |
|
604 | } | |
605 |
|
605 | |||
606 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
606 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
607 | { |
|
607 | { | |
608 | Q_D(QPieSeries); |
|
608 | Q_D(QPieSeries); | |
609 |
|
609 | |||
610 | if (relativePosition < 0.0) |
|
610 | if (relativePosition < 0.0) | |
611 | relativePosition = 0.0; |
|
611 | relativePosition = 0.0; | |
612 | if (relativePosition > 1.0) |
|
612 | if (relativePosition > 1.0) | |
613 | relativePosition = 1.0; |
|
613 | relativePosition = 1.0; | |
614 |
|
614 | |||
615 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { |
|
615 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { | |
616 | d->m_pieRelativeHorPos = relativePosition; |
|
616 | d->m_pieRelativeHorPos = relativePosition; | |
617 | emit d->horizontalPositionChanged(); |
|
617 | emit d->horizontalPositionChanged(); | |
618 | } |
|
618 | } | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | qreal QPieSeries::horizontalPosition() const |
|
621 | qreal QPieSeries::horizontalPosition() const | |
622 | { |
|
622 | { | |
623 | Q_D(const QPieSeries); |
|
623 | Q_D(const QPieSeries); | |
624 | return d->m_pieRelativeHorPos; |
|
624 | return d->m_pieRelativeHorPos; | |
625 | } |
|
625 | } | |
626 |
|
626 | |||
627 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
627 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
628 | { |
|
628 | { | |
629 | Q_D(QPieSeries); |
|
629 | Q_D(QPieSeries); | |
630 |
|
630 | |||
631 | if (relativePosition < 0.0) |
|
631 | if (relativePosition < 0.0) | |
632 | relativePosition = 0.0; |
|
632 | relativePosition = 0.0; | |
633 | if (relativePosition > 1.0) |
|
633 | if (relativePosition > 1.0) | |
634 | relativePosition = 1.0; |
|
634 | relativePosition = 1.0; | |
635 |
|
635 | |||
636 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { |
|
636 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { | |
637 | d->m_pieRelativeVerPos = relativePosition; |
|
637 | d->m_pieRelativeVerPos = relativePosition; | |
638 | emit d->verticalPositionChanged(); |
|
638 | emit d->verticalPositionChanged(); | |
639 | } |
|
639 | } | |
640 | } |
|
640 | } | |
641 |
|
641 | |||
642 | qreal QPieSeries::verticalPosition() const |
|
642 | qreal QPieSeries::verticalPosition() const | |
643 | { |
|
643 | { | |
644 | Q_D(const QPieSeries); |
|
644 | Q_D(const QPieSeries); | |
645 | return d->m_pieRelativeVerPos; |
|
645 | return d->m_pieRelativeVerPos; | |
646 | } |
|
646 | } | |
647 |
|
647 | |||
648 | void QPieSeries::setPieSize(qreal relativeSize) |
|
648 | void QPieSeries::setPieSize(qreal relativeSize) | |
649 | { |
|
649 | { | |
650 | Q_D(QPieSeries); |
|
650 | Q_D(QPieSeries); | |
651 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
651 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); | |
652 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
652 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); | |
653 |
|
653 | |||
654 | } |
|
654 | } | |
655 |
|
655 | |||
656 | qreal QPieSeries::pieSize() const |
|
656 | qreal QPieSeries::pieSize() const | |
657 | { |
|
657 | { | |
658 | Q_D(const QPieSeries); |
|
658 | Q_D(const QPieSeries); | |
659 | return d->m_pieRelativeSize; |
|
659 | return d->m_pieRelativeSize; | |
660 | } |
|
660 | } | |
661 |
|
661 | |||
662 |
|
662 | |||
663 | void QPieSeries::setPieStartAngle(qreal angle) |
|
663 | void QPieSeries::setPieStartAngle(qreal angle) | |
664 | { |
|
664 | { | |
665 | Q_D(QPieSeries); |
|
665 | Q_D(QPieSeries); | |
666 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) |
|
666 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) | |
667 | return; |
|
667 | return; | |
668 | d->m_pieStartAngle = angle; |
|
668 | d->m_pieStartAngle = angle; | |
669 | d->updateDerivativeData(); |
|
669 | d->updateDerivativeData(); | |
670 | emit d->pieStartAngleChanged(); |
|
670 | emit d->pieStartAngleChanged(); | |
671 | } |
|
671 | } | |
672 |
|
672 | |||
673 | qreal QPieSeries::pieStartAngle() const |
|
673 | qreal QPieSeries::pieStartAngle() const | |
674 | { |
|
674 | { | |
675 | Q_D(const QPieSeries); |
|
675 | Q_D(const QPieSeries); | |
676 | return d->m_pieStartAngle; |
|
676 | return d->m_pieStartAngle; | |
677 | } |
|
677 | } | |
678 |
|
678 | |||
679 | /*! |
|
679 | /*! | |
680 | Sets the end angle of the pie. |
|
680 | Sets the end angle of the pie. | |
681 |
|
681 | |||
682 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
682 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
683 |
|
683 | |||
684 | \a angle must be greater than start angle. |
|
684 | \a angle must be greater than start angle. | |
685 |
|
685 | |||
686 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
686 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
687 | */ |
|
687 | */ | |
688 | void QPieSeries::setPieEndAngle(qreal angle) |
|
688 | void QPieSeries::setPieEndAngle(qreal angle) | |
689 | { |
|
689 | { | |
690 | Q_D(QPieSeries); |
|
690 | Q_D(QPieSeries); | |
691 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) |
|
691 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) | |
692 | return; |
|
692 | return; | |
693 | d->m_pieEndAngle = angle; |
|
693 | d->m_pieEndAngle = angle; | |
694 | d->updateDerivativeData(); |
|
694 | d->updateDerivativeData(); | |
695 | emit d->pieEndAngleChanged(); |
|
695 | emit d->pieEndAngleChanged(); | |
696 | } |
|
696 | } | |
697 |
|
697 | |||
698 | /*! |
|
698 | /*! | |
699 | Returns the end angle of the pie. |
|
699 | Returns the end angle of the pie. | |
700 |
|
700 | |||
701 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
701 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
702 |
|
702 | |||
703 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
703 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
704 | */ |
|
704 | */ | |
705 | qreal QPieSeries::pieEndAngle() const |
|
705 | qreal QPieSeries::pieEndAngle() const | |
706 | { |
|
706 | { | |
707 | Q_D(const QPieSeries); |
|
707 | Q_D(const QPieSeries); | |
708 | return d->m_pieEndAngle; |
|
708 | return d->m_pieEndAngle; | |
709 | } |
|
709 | } | |
710 |
|
710 | |||
711 | /*! |
|
711 | /*! | |
712 | Sets the all the slice labels \a visible or invisible. |
|
712 | Sets the all the slice labels \a visible or invisible. | |
713 |
|
713 | |||
714 | Note that this affects only the current slices in the series. |
|
714 | Note that this affects only the current slices in the series. | |
715 | If user adds a new slice the default label visibility is false. |
|
715 | If user adds a new slice the default label visibility is false. | |
716 |
|
716 | |||
717 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
717 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
718 | */ |
|
718 | */ | |
719 | void QPieSeries::setLabelsVisible(bool visible) |
|
719 | void QPieSeries::setLabelsVisible(bool visible) | |
720 | { |
|
720 | { | |
721 | Q_D(QPieSeries); |
|
721 | Q_D(QPieSeries); | |
722 | foreach (QPieSlice *s, d->m_slices) |
|
722 | foreach (QPieSlice *s, d->m_slices) | |
723 | s->setLabelVisible(visible); |
|
723 | s->setLabelVisible(visible); | |
724 | } |
|
724 | } | |
725 |
|
725 | |||
726 | /*! |
|
726 | /*! | |
727 | Sets the all the slice labels \a position |
|
727 | Sets the all the slice labels \a position | |
728 |
|
728 | |||
729 | Note that this affects only the current slices in the series. |
|
729 | Note that this affects only the current slices in the series. | |
730 | If user adds a new slice the default label position is LabelOutside |
|
730 | If user adds a new slice the default label position is LabelOutside | |
731 |
|
731 | |||
732 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
732 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() | |
733 | */ |
|
733 | */ | |
734 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
734 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) | |
735 | { |
|
735 | { | |
736 | Q_D(QPieSeries); |
|
736 | Q_D(QPieSeries); | |
737 | foreach (QPieSlice *s, d->m_slices) |
|
737 | foreach (QPieSlice *s, d->m_slices) | |
738 | s->setLabelPosition(position); |
|
738 | s->setLabelPosition(position); | |
739 | } |
|
739 | } | |
740 |
|
740 | |||
741 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
741 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
742 |
|
742 | |||
743 |
|
743 | |||
744 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
744 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
745 | QAbstractSeriesPrivate(parent), |
|
745 | QAbstractSeriesPrivate(parent), | |
746 | m_pieRelativeHorPos(0.5), |
|
746 | m_pieRelativeHorPos(0.5), | |
747 | m_pieRelativeVerPos(0.5), |
|
747 | m_pieRelativeVerPos(0.5), | |
748 | m_pieRelativeSize(0.7), |
|
748 | m_pieRelativeSize(0.7), | |
749 | m_pieStartAngle(0), |
|
749 | m_pieStartAngle(0), | |
750 | m_pieEndAngle(360), |
|
750 | m_pieEndAngle(360), | |
751 | m_sum(0), |
|
751 | m_sum(0), | |
752 | m_holeRelativeSize(0.0) |
|
752 | m_holeRelativeSize(0.0) | |
753 | { |
|
753 | { | |
754 | } |
|
754 | } | |
755 |
|
755 | |||
756 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
756 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
757 | { |
|
757 | { | |
758 | } |
|
758 | } | |
759 |
|
759 | |||
760 | void QPieSeriesPrivate::updateDerivativeData() |
|
760 | void QPieSeriesPrivate::updateDerivativeData() | |
761 | { |
|
761 | { | |
762 | // calculate sum of all slices |
|
762 | // calculate sum of all slices | |
763 | qreal sum = 0; |
|
763 | qreal sum = 0; | |
764 | foreach (QPieSlice *s, m_slices) |
|
764 | foreach (QPieSlice *s, m_slices) | |
765 | sum += s->value(); |
|
765 | sum += s->value(); | |
766 |
|
766 | |||
767 | if (!qFuzzyCompare(m_sum, sum)) { |
|
767 | if (!qFuzzyCompare(m_sum, sum)) { | |
768 | m_sum = sum; |
|
768 | m_sum = sum; | |
769 | emit q_func()->sumChanged(); |
|
769 | emit q_func()->sumChanged(); | |
770 | } |
|
770 | } | |
771 |
|
771 | |||
772 | // nothing to show.. |
|
772 | // nothing to show.. | |
773 | if (qFuzzyCompare(m_sum, 0)) |
|
773 | if (qFuzzyCompare(m_sum, 0)) | |
774 | return; |
|
774 | return; | |
775 |
|
775 | |||
776 | // update slice attributes |
|
776 | // update slice attributes | |
777 | qreal sliceAngle = m_pieStartAngle; |
|
777 | qreal sliceAngle = m_pieStartAngle; | |
778 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
778 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
779 | QVector<QPieSlice *> changed; |
|
779 | QVector<QPieSlice *> changed; | |
780 | foreach (QPieSlice *s, m_slices) { |
|
780 | foreach (QPieSlice *s, m_slices) { | |
781 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
781 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
782 | d->setPercentage(s->value() / m_sum); |
|
782 | d->setPercentage(s->value() / m_sum); | |
783 | d->setStartAngle(sliceAngle); |
|
783 | d->setStartAngle(sliceAngle); | |
784 | d->setAngleSpan(pieSpan * s->percentage()); |
|
784 | d->setAngleSpan(pieSpan * s->percentage()); | |
785 | sliceAngle += s->angleSpan(); |
|
785 | sliceAngle += s->angleSpan(); | |
786 | } |
|
786 | } | |
787 |
|
787 | |||
788 |
|
788 | |||
789 | emit calculatedDataChanged(); |
|
789 | emit calculatedDataChanged(); | |
790 | } |
|
790 | } | |
791 |
|
791 | |||
792 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
792 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) | |
793 | { |
|
793 | { | |
794 | bool changed = false; |
|
794 | bool changed = false; | |
795 |
|
795 | |||
796 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { |
|
796 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { | |
797 | m_holeRelativeSize = innerSize; |
|
797 | m_holeRelativeSize = innerSize; | |
798 | changed = true; |
|
798 | changed = true; | |
799 | } |
|
799 | } | |
800 |
|
800 | |||
801 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { |
|
801 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { | |
802 | m_pieRelativeSize = outerSize; |
|
802 | m_pieRelativeSize = outerSize; | |
803 | changed = true; |
|
803 | changed = true; | |
804 | } |
|
804 | } | |
805 |
|
805 | |||
806 | if (changed) |
|
806 | if (changed) | |
807 | emit pieSizeChanged(); |
|
807 | emit pieSizeChanged(); | |
808 | } |
|
808 | } | |
809 |
|
809 | |||
810 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
810 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
811 | { |
|
811 | { | |
812 | return series->d_func(); |
|
812 | return series->d_func(); | |
813 | } |
|
813 | } | |
814 |
|
814 | |||
815 | void QPieSeriesPrivate::sliceValueChanged() |
|
815 | void QPieSeriesPrivate::sliceValueChanged() | |
816 | { |
|
816 | { | |
817 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
817 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
818 | updateDerivativeData(); |
|
818 | updateDerivativeData(); | |
819 | } |
|
819 | } | |
820 |
|
820 | |||
821 | void QPieSeriesPrivate::sliceClicked() |
|
821 | void QPieSeriesPrivate::sliceClicked() | |
822 | { |
|
822 | { | |
823 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
823 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
824 | Q_ASSERT(m_slices.contains(slice)); |
|
824 | Q_ASSERT(m_slices.contains(slice)); | |
825 | Q_Q(QPieSeries); |
|
825 | Q_Q(QPieSeries); | |
826 | emit q->clicked(slice); |
|
826 | emit q->clicked(slice); | |
827 | } |
|
827 | } | |
828 |
|
828 | |||
829 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
829 | void QPieSeriesPrivate::sliceHovered(bool state) | |
830 | { |
|
830 | { | |
831 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
831 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
832 | Q_ASSERT(m_slices.contains(slice)); |
|
832 | Q_ASSERT(m_slices.contains(slice)); | |
833 | Q_Q(QPieSeries); |
|
833 | Q_Q(QPieSeries); | |
834 | emit q->hovered(slice, state); |
|
834 | emit q->hovered(slice, state); | |
835 | } |
|
835 | } | |
836 |
|
836 | |||
837 | void QPieSeriesPrivate::initializeDomain() |
|
837 | void QPieSeriesPrivate::initializeDomain() | |
838 | { |
|
838 | { | |
839 | // does not apply to pie |
|
839 | // does not apply to pie | |
840 | } |
|
840 | } | |
841 |
|
841 | |||
842 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
842 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
843 | { |
|
843 | { | |
844 | Q_Q(QPieSeries); |
|
844 | Q_Q(QPieSeries); | |
845 | PieChartItem *pie = new PieChartItem(q,parent); |
|
845 | PieChartItem *pie = new PieChartItem(q,parent); | |
846 | m_item.reset(pie); |
|
846 | m_item.reset(pie); | |
847 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
847 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
848 | } |
|
848 | } | |
849 |
|
849 | |||
850 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
850 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
851 | { |
|
851 | { | |
852 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
852 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); | |
853 | Q_ASSERT(item); |
|
853 | Q_ASSERT(item); | |
854 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
854 | if (options.testFlag(QChart::SeriesAnimations)) { | |
855 | item->setAnimation(new PieAnimation(item)); |
|
855 | item->setAnimation(new PieAnimation(item)); | |
856 | }else{ |
|
856 | }else{ | |
857 | item->setAnimation(0); |
|
857 | item->setAnimation(0); | |
858 | } |
|
858 | } | |
859 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
859 | QAbstractSeriesPrivate::initializeAnimations(options); | |
860 | } |
|
860 | } | |
861 |
|
861 | |||
862 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
862 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |
863 | { |
|
863 | { | |
864 | Q_Q(QPieSeries); |
|
864 | Q_Q(QPieSeries); | |
865 | QList<QLegendMarker*> markers; |
|
865 | QList<QLegendMarker*> markers; | |
866 | foreach(QPieSlice* slice, q->slices()) { |
|
866 | foreach(QPieSlice* slice, q->slices()) { | |
867 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); |
|
867 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); | |
868 | markers << marker; |
|
868 | markers << marker; | |
869 | } |
|
869 | } | |
870 | return markers; |
|
870 | return markers; | |
871 | } |
|
871 | } | |
872 |
|
872 | |||
873 | void QPieSeriesPrivate::initializeAxes() |
|
873 | void QPieSeriesPrivate::initializeAxes() | |
874 | { |
|
874 | { | |
875 |
|
875 | |||
876 | } |
|
876 | } | |
877 |
|
877 | |||
878 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
878 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
879 | { |
|
879 | { | |
880 | Q_UNUSED(orientation); |
|
880 | Q_UNUSED(orientation); | |
881 | return QAbstractAxis::AxisTypeNoAxis; |
|
881 | return QAbstractAxis::AxisTypeNoAxis; | |
882 | } |
|
882 | } | |
883 |
|
883 | |||
884 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
884 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
885 | { |
|
885 | { | |
886 | Q_UNUSED(orientation); |
|
886 | Q_UNUSED(orientation); | |
887 | return 0; |
|
887 | return 0; | |
888 | } |
|
888 | } | |
889 |
|
889 | |||
890 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
890 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
891 | { |
|
891 | { | |
892 | Q_Q(QPieSeries); |
|
892 | //Q_Q(QPieSeries); | |
893 | const QList<QColor>& colors = theme->seriesColors(); |
|
893 | //const QList<QColor>& colors = theme->seriesColors(); | |
894 | const QList<QGradient>& gradients = theme->seriesGradients(); |
|
894 | const QList<QGradient>& gradients = theme->seriesGradients(); | |
895 |
|
895 | |||
896 | for (int i(0); i < m_slices.count(); i++) { |
|
896 | for (int i(0); i < m_slices.count(); i++) { | |
897 |
|
897 | |||
898 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
898 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); | |
899 |
|
899 | |||
900 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
900 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
901 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); |
|
901 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); | |
902 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); |
|
902 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); | |
903 |
|
903 | |||
904 | QPieSlice *s = m_slices.at(i); |
|
904 | QPieSlice *s = m_slices.at(i); | |
905 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
905 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
906 |
|
906 | |||
907 | if (forced || d->m_data.m_slicePen.isThemed()) |
|
907 | if (forced || d->m_data.m_slicePen.isThemed()) | |
908 | d->setPen(penColor, true); |
|
908 | d->setPen(penColor, true); | |
909 |
|
909 | |||
910 | if (forced || d->m_data.m_sliceBrush.isThemed()) |
|
910 | if (forced || d->m_data.m_sliceBrush.isThemed()) | |
911 | d->setBrush(brushColor, true); |
|
911 | d->setBrush(brushColor, true); | |
912 |
|
912 | |||
913 | if (forced || d->m_data.m_labelBrush.isThemed()) |
|
913 | if (forced || d->m_data.m_labelBrush.isThemed()) | |
914 | d->setLabelBrush(theme->labelBrush().color(), true); |
|
914 | d->setLabelBrush(theme->labelBrush().color(), true); | |
915 |
|
915 | |||
916 | if (forced || d->m_data.m_labelFont.isThemed()) |
|
916 | if (forced || d->m_data.m_labelFont.isThemed()) | |
917 | d->setLabelFont(theme->labelFont(), true); |
|
917 | d->setLabelFont(theme->labelFont(), true); | |
918 | } |
|
918 | } | |
919 | } |
|
919 | } | |
920 |
|
920 | |||
921 |
|
921 | |||
922 | #include "moc_qpieseries.cpp" |
|
922 | #include "moc_qpieseries.cpp" | |
923 | #include "moc_qpieseries_p.cpp" |
|
923 | #include "moc_qpieseries_p.cpp" | |
924 |
|
924 | |||
925 | QTCOMMERCIALCHART_END_NAMESPACE |
|
925 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,148 +1,148 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QAbstractSeries> |
|
24 | #include <QAbstractSeries> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include <QGraphicsWidget> |
|
26 | #include <QGraphicsWidget> | |
27 | #include <QMargins> |
|
27 | #include <QMargins> | |
28 |
|
28 | |||
29 | class QGraphicsSceneResizeEvent; |
|
29 | class QGraphicsSceneResizeEvent; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 | class QAbstractAxis; |
|
34 | class QAbstractAxis; | |
35 | class QLegend; |
|
35 | class QLegend; | |
36 |
|
|
36 | class QChartPrivate; | |
37 |
|
37 | |||
38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) | |
42 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
42 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) | |
44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) | |
45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) | |
46 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
46 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) | |
47 | Q_ENUMS(ChartTheme) |
|
47 | Q_ENUMS(ChartTheme) | |
48 | Q_ENUMS(AnimationOption) |
|
48 | Q_ENUMS(AnimationOption) | |
49 |
|
49 | |||
50 | public: |
|
50 | public: | |
51 | enum ChartTheme { |
|
51 | enum ChartTheme { | |
52 | ChartThemeLight = 0, |
|
52 | ChartThemeLight = 0, | |
53 | ChartThemeBlueCerulean, |
|
53 | ChartThemeBlueCerulean, | |
54 | ChartThemeDark, |
|
54 | ChartThemeDark, | |
55 | ChartThemeBrownSand, |
|
55 | ChartThemeBrownSand, | |
56 | ChartThemeBlueNcs, |
|
56 | ChartThemeBlueNcs, | |
57 | ChartThemeHighContrast, |
|
57 | ChartThemeHighContrast, | |
58 | ChartThemeBlueIcy |
|
58 | ChartThemeBlueIcy | |
59 | }; |
|
59 | }; | |
60 |
|
60 | |||
61 | enum AnimationOption { |
|
61 | enum AnimationOption { | |
62 | NoAnimation = 0x0, |
|
62 | NoAnimation = 0x0, | |
63 | GridAxisAnimations = 0x1, |
|
63 | GridAxisAnimations = 0x1, | |
64 | SeriesAnimations = 0x2, |
|
64 | SeriesAnimations = 0x2, | |
65 | AllAnimations = 0x3 |
|
65 | AllAnimations = 0x3 | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
69 |
|
69 | |||
70 | public: |
|
70 | public: | |
71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
72 | ~QChart(); |
|
72 | ~QChart(); | |
73 |
|
73 | |||
74 | void addSeries(QAbstractSeries *series); |
|
74 | void addSeries(QAbstractSeries *series); | |
75 | void removeSeries(QAbstractSeries *series); |
|
75 | void removeSeries(QAbstractSeries *series); | |
76 | void removeAllSeries(); |
|
76 | void removeAllSeries(); | |
77 | QList<QAbstractSeries *> series() const; |
|
77 | QList<QAbstractSeries *> series() const; | |
78 |
|
78 | |||
79 | //depreciated shit//////////////////////////////////////////////////. |
|
79 | //depreciated shit//////////////////////////////////////////////////. | |
80 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
80 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
81 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
81 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
82 |
|
82 | |||
83 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
83 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; | |
84 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
84 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; | |
85 | ///////////////////////////////////////////////////////////////////// |
|
85 | ///////////////////////////////////////////////////////////////////// | |
86 |
|
86 | |||
87 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
87 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); | |
88 | void removeAxis(QAbstractAxis *axis); |
|
88 | void removeAxis(QAbstractAxis *axis); | |
89 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; |
|
89 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; | |
90 |
|
90 | |||
91 | void createDefaultAxes(); |
|
91 | void createDefaultAxes(); | |
92 |
|
92 | |||
93 | void setTheme(QChart::ChartTheme theme); |
|
93 | void setTheme(QChart::ChartTheme theme); | |
94 | QChart::ChartTheme theme() const; |
|
94 | QChart::ChartTheme theme() const; | |
95 |
|
95 | |||
96 | void setTitle(const QString &title); |
|
96 | void setTitle(const QString &title); | |
97 | QString title() const; |
|
97 | QString title() const; | |
98 | void setTitleFont(const QFont &font); |
|
98 | void setTitleFont(const QFont &font); | |
99 | QFont titleFont() const; |
|
99 | QFont titleFont() const; | |
100 | void setTitleBrush(const QBrush &brush); |
|
100 | void setTitleBrush(const QBrush &brush); | |
101 | QBrush titleBrush() const; |
|
101 | QBrush titleBrush() const; | |
102 |
|
102 | |||
103 | void setBackgroundBrush(const QBrush &brush); |
|
103 | void setBackgroundBrush(const QBrush &brush); | |
104 | QBrush backgroundBrush() const; |
|
104 | QBrush backgroundBrush() const; | |
105 | void setBackgroundPen(const QPen &pen); |
|
105 | void setBackgroundPen(const QPen &pen); | |
106 | QPen backgroundPen() const; |
|
106 | QPen backgroundPen() const; | |
107 | void setBackgroundVisible(bool visible = true); |
|
107 | void setBackgroundVisible(bool visible = true); | |
108 | bool isBackgroundVisible() const; |
|
108 | bool isBackgroundVisible() const; | |
109 |
|
109 | |||
110 | void setDropShadowEnabled(bool enabled = true); |
|
110 | void setDropShadowEnabled(bool enabled = true); | |
111 | bool isDropShadowEnabled() const; |
|
111 | bool isDropShadowEnabled() const; | |
112 | void setAnimationOptions(AnimationOptions options); |
|
112 | void setAnimationOptions(AnimationOptions options); | |
113 | AnimationOptions animationOptions() const; |
|
113 | AnimationOptions animationOptions() const; | |
114 |
|
114 | |||
115 | void zoomIn(); |
|
115 | void zoomIn(); | |
116 | void zoomOut(); |
|
116 | void zoomOut(); | |
117 |
|
117 | |||
118 | void zoomIn(const QRectF &rect); |
|
118 | void zoomIn(const QRectF &rect); | |
119 | void zoom(qreal factor); |
|
119 | void zoom(qreal factor); | |
120 |
|
120 | |||
121 | void scroll(qreal dx, qreal dy); |
|
121 | void scroll(qreal dx, qreal dy); | |
122 |
|
122 | |||
123 | QLegend *legend() const; |
|
123 | QLegend *legend() const; | |
124 |
|
124 | |||
125 | void setMinimumMargins(const QMargins& margins); |
|
125 | void setMinimumMargins(const QMargins& margins); | |
126 | QMargins minimumMargins() const; |
|
126 | QMargins minimumMargins() const; | |
127 |
|
127 | |||
128 | void setMargins(const QMargins &margins); |
|
128 | void setMargins(const QMargins &margins); | |
129 | QMargins margins() const; |
|
129 | QMargins margins() const; | |
130 |
|
130 | |||
131 | QRectF plotArea() const; |
|
131 | QRectF plotArea() const; | |
132 |
|
132 | |||
133 | protected: |
|
133 | protected: | |
134 | QScopedPointer<QChartPrivate> d_ptr; |
|
134 | QScopedPointer<QChartPrivate> d_ptr; | |
135 | friend class QLegend; |
|
135 | friend class QLegend; | |
136 | friend class DeclarativeChart; |
|
136 | friend class DeclarativeChart; | |
137 | friend class ChartDataSet; |
|
137 | friend class ChartDataSet; | |
138 | friend class ChartPresenter; |
|
138 | friend class ChartPresenter; | |
139 | friend class ChartThemeManager; |
|
139 | friend class ChartThemeManager; | |
140 | friend class QAbstractSeries; |
|
140 | friend class QAbstractSeries; | |
141 | Q_DISABLE_COPY(QChart) |
|
141 | Q_DISABLE_COPY(QChart) | |
142 | }; |
|
142 | }; | |
143 |
|
143 | |||
144 | QTCOMMERCIALCHART_END_NAMESPACE |
|
144 | QTCOMMERCIALCHART_END_NAMESPACE | |
145 |
|
145 | |||
146 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
146 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
147 |
|
147 | |||
148 | #endif // QCHART_H |
|
148 | #endif // QCHART_H |
@@ -1,177 +1,177 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMESYSTEM_P_H |
|
30 | #ifndef CHARTTHEMESYSTEM_P_H | |
31 | #define CHARTTHEMESYSTEM_P_H |
|
31 | #define CHARTTHEMESYSTEM_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 | #ifdef Q_OS_WIN |
|
34 | #ifdef Q_OS_WIN | |
35 | #include <windows.h> |
|
35 | #include <windows.h> | |
36 | #include <stdio.h> |
|
36 | #include <stdio.h> | |
37 | #endif |
|
37 | #endif | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartThemeSystem: public ChartTheme |
|
41 | class ChartThemeSystem: public ChartTheme | |
42 | { |
|
42 | { | |
43 | public: |
|
43 | public: | |
44 | // System theme not used at the moment (the user is not able to select this theme) |
|
44 | // System theme not used at the moment (the user is not able to select this theme) | |
45 | ChartThemeSystem() : ChartTheme(QChart::ChartThemeLight /*QChart::ChartThemeSystem*/) |
|
45 | ChartThemeSystem() : ChartTheme(QChart::ChartThemeLight /*QChart::ChartThemeSystem*/) | |
46 | { |
|
46 | { | |
47 | #ifdef Q_OS_WIN |
|
47 | #ifdef Q_OS_WIN | |
48 | // We could also use theme specific window frame color as a series base color (it would give more |
|
48 | // We could also use theme specific window frame color as a series base color (it would give more | |
49 | // variation to the base colors in addition to the blue and black used now) |
|
49 | // variation to the base colors in addition to the blue and black used now) | |
50 |
|
50 | |||
51 | // First series base color from COLOR_HIGHLIGHT |
|
51 | // First series base color from COLOR_HIGHLIGHT | |
52 | DWORD colorHighlight; |
|
52 | DWORD colorHighlight; | |
53 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); |
|
53 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); | |
54 | m_seriesColors.append(QColor(GetRValue(colorHighlight), |
|
54 | m_seriesColors.append(QColor(GetRValue(colorHighlight), | |
55 | GetGValue(colorHighlight), |
|
55 | GetGValue(colorHighlight), | |
56 | GetBValue(colorHighlight))); |
|
56 | GetBValue(colorHighlight))); | |
57 |
|
57 | |||
58 | // Second series base color from COLOR_WINDOWFRAME |
|
58 | // Second series base color from COLOR_WINDOWFRAME | |
59 | DWORD colorWindowFrame; |
|
59 | DWORD colorWindowFrame; | |
60 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); |
|
60 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); | |
61 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), |
|
61 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), | |
62 | GetGValue(colorWindowFrame), |
|
62 | GetGValue(colorWindowFrame), | |
63 | GetBValue(colorWindowFrame))); |
|
63 | GetBValue(colorWindowFrame))); | |
64 |
|
64 | |||
65 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / |
|
65 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / | |
66 | // COLOR_GRADIENTACTIVECAPTION gradient |
|
66 | // COLOR_GRADIENTACTIVECAPTION gradient | |
67 | DWORD colorGradientActiveCaptionLeft; |
|
67 | DWORD colorGradientActiveCaptionLeft; | |
68 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); |
|
68 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); | |
69 | DWORD colorGradientActiveCaptionRight; |
|
69 | DWORD colorGradientActiveCaptionRight; | |
70 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); |
|
70 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); | |
71 | QLinearGradient g; |
|
71 | QLinearGradient g; | |
72 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), |
|
72 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), | |
73 | GetGValue(colorGradientActiveCaptionLeft), |
|
73 | GetGValue(colorGradientActiveCaptionLeft), | |
74 | GetBValue(colorGradientActiveCaptionLeft)); |
|
74 | GetBValue(colorGradientActiveCaptionLeft)); | |
75 | g.setColorAt(0.0, start); |
|
75 | g.setColorAt(0.0, start); | |
76 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), |
|
76 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), | |
77 | GetGValue(colorGradientActiveCaptionRight), |
|
77 | GetGValue(colorGradientActiveCaptionRight), | |
78 | GetBValue(colorGradientActiveCaptionRight)); |
|
78 | GetBValue(colorGradientActiveCaptionRight)); | |
79 | g.setColorAt(1.0, end); |
|
79 | g.setColorAt(1.0, end); | |
80 | m_seriesColors.append(colorAt(g, 0.5)); |
|
80 | m_seriesColors.append(ChartThemeManager::colorAt(g, 0.5)); | |
81 |
|
81 | |||
82 | // Generate gradients from the base colors |
|
82 | // Generate gradients from the base colors | |
83 | generateSeriesGradients(); |
|
83 | ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
84 |
|
84 | |||
85 | // Background fill color from COLOR_WINDOW |
|
85 | // Background fill color from COLOR_WINDOW | |
86 | QLinearGradient backgroundGradient; |
|
86 | QLinearGradient backgroundGradient; | |
87 | DWORD colorWindow; |
|
87 | DWORD colorWindow; | |
88 | colorWindow = GetSysColor(COLOR_WINDOW); |
|
88 | colorWindow = GetSysColor(COLOR_WINDOW); | |
89 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), |
|
89 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), | |
90 | GetGValue(colorWindow), |
|
90 | GetGValue(colorWindow), | |
91 | GetBValue(colorWindow))); |
|
91 | GetBValue(colorWindow))); | |
92 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), |
|
92 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), | |
93 | GetGValue(colorWindow), |
|
93 | GetGValue(colorWindow), | |
94 | GetBValue(colorWindow))); |
|
94 | GetBValue(colorWindow))); | |
95 | // Axes and other |
|
95 | // Axes and other | |
96 | m_axisLinePen = QPen(0xd6d6d6); |
|
96 | m_axisLinePen = QPen(0xd6d6d6); | |
97 | m_axisLinePen.setWidth(1); |
|
97 | m_axisLinePen.setWidth(1); | |
98 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
98 | m_labelBrush = QBrush(QRgb(0x404044)); | |
99 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
99 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
100 | m_gridLinePen.setWidth(1); |
|
100 | m_gridLinePen.setWidth(1); | |
101 | m_backgroundShades = BackgroundShadesNone; |
|
101 | m_backgroundShades = BackgroundShadesNone; | |
102 |
|
102 | |||
103 | #elif defined(Q_OS_LINUX) |
|
103 | #elif defined(Q_OS_LINUX) | |
104 | // Using a hard coded theme for Linux system theme |
|
104 | // Using a hard coded theme for Linux system theme | |
105 | m_seriesColors << QRgb(0x60a6e6); |
|
105 | m_seriesColors << QRgb(0x60a6e6); | |
106 | m_seriesColors << QRgb(0x92ca66); |
|
106 | m_seriesColors << QRgb(0x92ca66); | |
107 | m_seriesColors << QRgb(0xeba85f); |
|
107 | m_seriesColors << QRgb(0xeba85f); | |
108 | m_seriesColors << QRgb(0xfc5751); |
|
108 | m_seriesColors << QRgb(0xfc5751); | |
109 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); |
|
109 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
110 |
|
110 | |||
111 | // Background |
|
111 | // Background | |
112 | QLinearGradient backgroundGradient; |
|
112 | QLinearGradient backgroundGradient; | |
113 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
113 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
114 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
114 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
115 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
115 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
116 | m_chartBackgroundGradient = backgroundGradient; |
|
116 | m_chartBackgroundGradient = backgroundGradient; | |
117 |
|
117 | |||
118 | // Axes and other |
|
118 | // Axes and other | |
119 | m_axisLinePen = QPen(0xd6d6d6); |
|
119 | m_axisLinePen = QPen(0xd6d6d6); | |
120 | m_axisLinePen.setWidth(1); |
|
120 | m_axisLinePen.setWidth(1); | |
121 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
121 | m_labelBrush = QBrush(QRgb(0x404044)); | |
122 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
122 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
123 | m_gridLinePen.setWidth(1); |
|
123 | m_gridLinePen.setWidth(1); | |
124 | m_backgroundShades = BackgroundShadesNone; |
|
124 | m_backgroundShades = BackgroundShadesNone; | |
125 |
|
125 | |||
126 | #elif defined(Q_OS_MAC) |
|
126 | #elif defined(Q_OS_MAC) | |
127 | // Using a hard coded theme for OSX system theme; the colors match the OSX 10.7 colors |
|
127 | // Using a hard coded theme for OSX system theme; the colors match the OSX 10.7 colors | |
128 | m_seriesColors << QRgb(0x60a6e6); |
|
128 | m_seriesColors << QRgb(0x60a6e6); | |
129 | m_seriesColors << QRgb(0x92ca66); |
|
129 | m_seriesColors << QRgb(0x92ca66); | |
130 | m_seriesColors << QRgb(0xeba85f); |
|
130 | m_seriesColors << QRgb(0xeba85f); | |
131 | m_seriesColors << QRgb(0xfc5751); |
|
131 | m_seriesColors << QRgb(0xfc5751); | |
132 | generateSeriesGradients(); |
|
132 | generateSeriesGradients(); | |
133 |
|
133 | |||
134 | // Background |
|
134 | // Background | |
135 | QLinearGradient backgroundGradient; |
|
135 | QLinearGradient backgroundGradient; | |
136 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
136 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
137 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
137 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
138 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
138 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
139 | m_chartBackgroundGradient = backgroundGradient; |
|
139 | m_chartBackgroundGradient = backgroundGradient; | |
140 |
|
140 | |||
141 | // Axes and other |
|
141 | // Axes and other | |
142 | m_axisLinePen = QPen(0xd6d6d6); |
|
142 | m_axisLinePen = QPen(0xd6d6d6); | |
143 | m_axisLinePen.setWidth(1); |
|
143 | m_axisLinePen.setWidth(1); | |
144 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
144 | m_labelBrush = QBrush(QRgb(0x404044)); | |
145 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
145 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
146 | m_gridLinePen.setWidth(1); |
|
146 | m_gridLinePen.setWidth(1); | |
147 | m_backgroundShades = BackgroundShadesNone; |
|
147 | m_backgroundShades = BackgroundShadesNone; | |
148 |
|
148 | |||
149 | #else |
|
149 | #else | |
150 | // Hard coded theme |
|
150 | // Hard coded theme | |
151 | m_seriesColors << QRgb(0x60a6e6); |
|
151 | m_seriesColors << QRgb(0x60a6e6); | |
152 | m_seriesColors << QRgb(0x92ca66); |
|
152 | m_seriesColors << QRgb(0x92ca66); | |
153 | m_seriesColors << QRgb(0xeba85f); |
|
153 | m_seriesColors << QRgb(0xeba85f); | |
154 | m_seriesColors << QRgb(0xfc5751); |
|
154 | m_seriesColors << QRgb(0xfc5751); | |
155 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); |
|
155 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
156 |
|
156 | |||
157 | // Background |
|
157 | // Background | |
158 | QLinearGradient backgroundGradient; |
|
158 | QLinearGradient backgroundGradient; | |
159 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
159 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
160 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
160 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
161 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
161 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
162 | m_chartBackgroundGradient = backgroundGradient; |
|
162 | m_chartBackgroundGradient = backgroundGradient; | |
163 |
|
163 | |||
164 | // Axes and other |
|
164 | // Axes and other | |
165 | m_axisLinePen = QPen(0xd6d6d6); |
|
165 | m_axisLinePen = QPen(0xd6d6d6); | |
166 | m_axisLinePen.setWidth(1); |
|
166 | m_axisLinePen.setWidth(1); | |
167 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
167 | m_labelBrush = QBrush(QRgb(0x404044)); | |
168 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
168 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
169 | m_gridLinePen.setWidth(1); |
|
169 | m_gridLinePen.setWidth(1); | |
170 | m_backgroundShades = BackgroundShadesNone; |
|
170 | m_backgroundShades = BackgroundShadesNone; | |
171 | #endif |
|
171 | #endif | |
172 | } |
|
172 | } | |
173 | }; |
|
173 | }; | |
174 |
|
174 | |||
175 | QTCOMMERCIALCHART_END_NAMESPACE |
|
175 | QTCOMMERCIALCHART_END_NAMESPACE | |
176 |
|
176 | |||
177 | #endif // CHARTTHEMESYSTEM_P_H |
|
177 | #endif // CHARTTHEMESYSTEM_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now