@@ -1,80 +1,80 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page qml.html |
|
2 | \page qml.html | |
3 | \title QtCommercial Charts QML API |
|
3 | \title QtCommercial Charts QML API | |
4 | \keyword Charts QML API |
|
4 | \keyword Charts QML API | |
5 |
|
5 | |||
6 | QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML |
|
6 | QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML | |
7 | applications. The following QML shows you to create a simple pie chart: |
|
7 | applications. The following QML shows you to create a simple pie chart: | |
8 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
8 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
9 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
9 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
10 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
10 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
11 |
|
11 | |||
12 | \raw HTML |
|
12 | \raw HTML | |
13 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
13 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> | |
14 | <tr> |
|
14 | <tr> | |
15 | <th class="titleheader" width="25%"> ChartView and it's properties </th> |
|
15 | <th class="titleheader" width="25%"> ChartView and it's properties </th> | |
16 | </tr> |
|
16 | </tr> | |
17 | <tr> |
|
17 | <tr> | |
18 | <td valign="top"> |
|
18 | <td valign="top"> | |
19 | <ul> |
|
19 | <ul> | |
20 | <li><a href="qml-chartview.html">ChartView</a></li> |
|
20 | <li><a href="qml-chartview.html">ChartView</a></li> | |
21 | <li><a href="qml-abstractaxis.html">AbstractAxis</a></li> |
|
21 | <li><a href="qml-abstractaxis.html">AbstractAxis</a></li> | |
22 |
<li><a href="qml-value |
|
22 | <li><a href="qml-valueaxis.html">ValueAxis</a></li> | |
23 |
<li><a href="qml-barcategor |
|
23 | <li><a href="qml-barcategoryaxis.html">BarCategoryAxis</a></li> | |
24 | <li><a href="qml-legend.html">Legend</a></li> |
|
24 | <li><a href="qml-legend.html">Legend</a></li> | |
25 | <li><a href="qml-abstractseries.html">AbstractSeries</a></li> |
|
25 | <li><a href="qml-abstractseries.html">AbstractSeries</a></li> | |
26 | </ul> |
|
26 | </ul> | |
27 | </td> |
|
27 | </td> | |
28 | </tr> |
|
28 | </tr> | |
29 | </table> |
|
29 | </table> | |
30 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
30 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> | |
31 | <tr> |
|
31 | <tr> | |
32 | <th class="titleheader" width="25%"> XY chart </th> |
|
32 | <th class="titleheader" width="25%"> XY chart </th> | |
33 | </tr> |
|
33 | </tr> | |
34 | <tr> |
|
34 | <tr> | |
35 | <td valign="top"> |
|
35 | <td valign="top"> | |
36 | <ul> |
|
36 | <ul> | |
37 | <li><a href="qml-xyseries.html">XYSeries</a></li> |
|
37 | <li><a href="qml-xyseries.html">XYSeries</a></li> | |
38 | <li><a href="qml-lineseries.html">LineSeries</a></li> |
|
38 | <li><a href="qml-lineseries.html">LineSeries</a></li> | |
39 | <li><a href="qml-areaseries.html">AreaSeries</a></li> |
|
39 | <li><a href="qml-areaseries.html">AreaSeries</a></li> | |
40 | <li><a href="qml-scatterseries.html">ScatterSeries</a></li> |
|
40 | <li><a href="qml-scatterseries.html">ScatterSeries</a></li> | |
41 | <li><a href="qml-splineseries.html">SplineSeries</a></li> |
|
41 | <li><a href="qml-splineseries.html">SplineSeries</a></li> | |
42 | <li><a href="qml-xypoint.html">XYPoint</a></li> |
|
42 | <li><a href="qml-xypoint.html">XYPoint</a></li> | |
43 | <li><a href="qml-hxymodelmapper.html">HXYModelMapper</a></li> |
|
43 | <li><a href="qml-hxymodelmapper.html">HXYModelMapper</a></li> | |
44 | <li><a href="qml-vxymodelmapper.html">VXYModelMapper</a></li> |
|
44 | <li><a href="qml-vxymodelmapper.html">VXYModelMapper</a></li> | |
45 | </ul> |
|
45 | </ul> | |
46 | </td> |
|
46 | </td> | |
47 | </tr> |
|
47 | </tr> | |
48 | </table> |
|
48 | </table> | |
49 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
49 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> | |
50 | <tr> |
|
50 | <tr> | |
51 | <th class="titleheader" width="25%"> Pie chart </th> |
|
51 | <th class="titleheader" width="25%"> Pie chart </th> | |
52 | <tr> |
|
52 | <tr> | |
53 | <td valign="top"> |
|
53 | <td valign="top"> | |
54 | <ul> |
|
54 | <ul> | |
55 | <li><a href="qml-pieseries.html">PieSeries</a></li> |
|
55 | <li><a href="qml-pieseries.html">PieSeries</a></li> | |
56 | <li><a href="qml-pieslice.html">PieSlice</a></li> |
|
56 | <li><a href="qml-pieslice.html">PieSlice</a></li> | |
57 | <li><a href="qml-hpiemodelmapper.html">HPieModelMapper</a></li> |
|
57 | <li><a href="qml-hpiemodelmapper.html">HPieModelMapper</a></li> | |
58 | <li><a href="qml-vpiemodelmapper.html">VPieModelMapper</a></li> |
|
58 | <li><a href="qml-vpiemodelmapper.html">VPieModelMapper</a></li> | |
59 | </ul> |
|
59 | </ul> | |
60 | </td> |
|
60 | </td> | |
61 | </tr> |
|
61 | </tr> | |
62 | </table> |
|
62 | </table> | |
63 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
63 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> | |
64 | <tr> |
|
64 | <tr> | |
65 | <th class="titleheader" width="25%"> Bar chart </th> |
|
65 | <th class="titleheader" width="25%"> Bar chart </th> | |
66 | <tr> |
|
66 | <tr> | |
67 | <td valign="top"> |
|
67 | <td valign="top"> | |
68 | <ul> |
|
68 | <ul> | |
69 | <li><a href="qml-barseries.html">BarSeries</a></li> |
|
69 | <li><a href="qml-barseries.html">BarSeries</a></li> | |
70 | <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li> |
|
70 | <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li> | |
71 | <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li> |
|
71 | <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li> | |
72 | <li><a href="qml-barset.html">BarSet</a></li> |
|
72 | <li><a href="qml-barset.html">BarSet</a></li> | |
73 | <li><a href="qml-hbarmodelmapper.html">HBarModelMapper</a></li> |
|
73 | <li><a href="qml-hbarmodelmapper.html">HBarModelMapper</a></li> | |
74 | <li><a href="qml-vbarmodelmapper.html">VBarModelMapper</a></li> |
|
74 | <li><a href="qml-vbarmodelmapper.html">VBarModelMapper</a></li> | |
75 | </ul> |
|
75 | </ul> | |
76 | </td> |
|
76 | </td> | |
77 | </tr> |
|
77 | </tr> | |
78 | </table> |
|
78 | </table> | |
79 | \endraw |
|
79 | \endraw | |
80 | */ |
|
80 | */ |
@@ -1,683 +1,683 | |||||
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 |
|
34 | |||
35 | #ifndef QT_ON_ARM |
|
35 | #ifndef QT_ON_ARM | |
36 | #include "qdatetimeaxis.h" |
|
36 | #include "qdatetimeaxis.h" | |
37 | #endif |
|
37 | #endif | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \qmlclass ChartView DeclarativeChart |
|
42 | \qmlclass ChartView DeclarativeChart | |
43 |
|
43 | |||
44 | ChartView element is the parent that is responsible for showing different chart series types. |
|
44 | ChartView element is the parent that is responsible for showing different chart series types. | |
45 |
|
45 | |||
46 | The following QML shows how to create a simple chart with one pie series: |
|
46 | The following QML shows how to create a simple chart with one pie series: | |
47 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
47 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
48 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
48 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
50 |
|
50 | |||
51 | \beginfloatleft |
|
51 | \beginfloatleft | |
52 | \image examples_qmlpiechart.png |
|
52 | \image examples_qmlpiechart.png | |
53 | \endfloat |
|
53 | \endfloat | |
54 | \clearfloat |
|
54 | \clearfloat | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \qmlproperty Theme ChartView::theme |
|
58 | \qmlproperty Theme ChartView::theme | |
59 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
59 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
60 | widths and chart background. |
|
60 | widths and chart background. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty Animation ChartView::animation |
|
64 | \qmlproperty Animation ChartView::animation | |
65 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
65 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
66 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
66 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \qmlproperty Font ChartView::titleFont |
|
70 | \qmlproperty Font ChartView::titleFont | |
71 | The title font of the chart |
|
71 | The title font of the chart | |
72 |
|
72 | |||
73 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
73 | See the \l {Font} {QML Font Element} for detailed documentation. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty string ChartView::title |
|
77 | \qmlproperty string ChartView::title | |
78 | The title of the chart, shown on top of the chart. |
|
78 | The title of the chart, shown on top of the chart. | |
79 | \sa ChartView::titleColor |
|
79 | \sa ChartView::titleColor | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty string ChartView::titleColor |
|
83 | \qmlproperty string ChartView::titleColor | |
84 | The color of the title text. |
|
84 | The color of the title text. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty Axis ChartView::axisX |
|
88 | \qmlproperty Axis ChartView::axisX | |
89 | The x-axis of the chart. |
|
89 | The x-axis of the chart. | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty Axis ChartView::axisY |
|
93 | \qmlproperty Axis ChartView::axisY | |
94 | The default y-axis of the chart. |
|
94 | The default y-axis of the chart. | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \qmlproperty Legend ChartView::legend |
|
98 | \qmlproperty Legend ChartView::legend | |
99 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
99 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
100 | */ |
|
100 | */ | |
101 |
|
101 | |||
102 | /*! |
|
102 | /*! | |
103 | \qmlproperty int ChartView::count |
|
103 | \qmlproperty int ChartView::count | |
104 | The count of series added to the chart. |
|
104 | The count of series added to the chart. | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty color ChartView::backgroundColor |
|
108 | \qmlproperty color ChartView::backgroundColor | |
109 | The color of the chart's background. By default background color is defined by chart theme. |
|
109 | The color of the chart's background. By default background color is defined by chart theme. | |
110 | \sa ChartView::theme |
|
110 | \sa ChartView::theme | |
111 | */ |
|
111 | */ | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | \qmlproperty bool ChartView::dropShadowEnabled |
|
114 | \qmlproperty bool ChartView::dropShadowEnabled | |
115 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
115 | The chart's border drop shadow. Set to true to enable drop shadow. | |
116 | */ |
|
116 | */ | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty real ChartView::topMargin |
|
119 | \qmlproperty real ChartView::topMargin | |
120 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin |
|
120 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin | |
121 | area of the chart view. Top margin area is also used by legend, if aligned to top. |
|
121 | area of the chart view. Top margin area is also used by legend, if aligned to top. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \qmlproperty real ChartView::bottomMargin |
|
125 | \qmlproperty real ChartView::bottomMargin | |
126 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by |
|
126 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by | |
127 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. |
|
127 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. | |
128 | */ |
|
128 | */ | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | \qmlproperty real ChartView::leftMargin |
|
131 | \qmlproperty real ChartView::leftMargin | |
132 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by |
|
132 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by | |
133 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. |
|
133 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. | |
134 | */ |
|
134 | */ | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | \qmlproperty real ChartView::rightMargin |
|
137 | \qmlproperty real ChartView::rightMargin | |
138 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used |
|
138 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used | |
139 | by legend (if aligned to right). |
|
139 | by legend (if aligned to right). | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
143 | \qmlmethod AbstractSeries ChartView::series(int index) | |
144 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
144 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
145 | the count property of the chart. |
|
145 | the count property of the chart. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
149 | \qmlmethod AbstractSeries ChartView::series(string name) | |
150 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
150 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
151 | */ |
|
151 | */ | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) |
|
154 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) | |
155 | Creates a series object of \a type to the chart. For example: |
|
155 | Creates a series object of \a type to the chart. For example: | |
156 | \code |
|
156 | \code | |
157 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); |
|
157 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); | |
158 | scatter.markerSize = 22; |
|
158 | scatter.markerSize = 22; | |
159 | scatter.append(1.1, 2.0); |
|
159 | scatter.append(1.1, 2.0); | |
160 | \endcode |
|
160 | \endcode | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
164 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) | |
165 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. |
|
165 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. | |
166 | */ |
|
166 | */ | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | \qmlmethod ChartView::zoomY(real factor) |
|
169 | \qmlmethod ChartView::zoomY(real factor) | |
170 | Zooms in by \a factor on the center of the chart. |
|
170 | Zooms in by \a factor on the center of the chart. | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
174 | \qmlmethod ChartView::scrollLeft(real pixels) | |
175 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
175 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
176 |
\sa ValueAxis::min, ValueAxis::max, BarCategor |
|
176 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \qmlmethod ChartView::scrollRight(real pixels) |
|
180 | \qmlmethod ChartView::scrollRight(real pixels) | |
181 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
181 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
182 |
\sa ValueAxis::min, ValueAxis::max, BarCategor |
|
182 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \qmlmethod ChartView::scrollUp(real pixels) |
|
186 | \qmlmethod ChartView::scrollUp(real pixels) | |
187 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
187 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
188 |
\sa ValueAxis::min, ValueAxis::max, BarCategor |
|
188 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \qmlmethod ChartView::scrollDown(real pixels) |
|
192 | \qmlmethod ChartView::scrollDown(real pixels) | |
193 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
193 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
194 |
\sa ValueAxis::min, ValueAxis::max, BarCategor |
|
194 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
195 | */ |
|
195 | */ | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | \qmlsignal ChartView::onTopMarginChanged(real margin) |
|
198 | \qmlsignal ChartView::onTopMarginChanged(real margin) | |
199 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
199 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
200 | related properties of the legend or chart title. |
|
200 | related properties of the legend or chart title. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \qmlsignal ChartView::onBottomMarginChanged(real margin) |
|
204 | \qmlsignal ChartView::onBottomMarginChanged(real margin) | |
205 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
205 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
206 | related properties of the legend or chart title. |
|
206 | related properties of the legend or chart title. | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \qmlsignal ChartView::onLeftMarginChanged(real margin) |
|
210 | \qmlsignal ChartView::onLeftMarginChanged(real margin) | |
211 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
211 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
212 | related properties of the legend or chart title. |
|
212 | related properties of the legend or chart title. | |
213 | */ |
|
213 | */ | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | \qmlsignal ChartView::onRightMarginChanged(real margin) |
|
216 | \qmlsignal ChartView::onRightMarginChanged(real margin) | |
217 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
217 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
218 | related properties of the legend or chart title. |
|
218 | related properties of the legend or chart title. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
221 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
222 | : QDeclarativeItem(parent), |
|
222 | : QDeclarativeItem(parent), | |
223 | m_chart(new QChart(this)) |
|
223 | m_chart(new QChart(this)) | |
224 | { |
|
224 | { | |
225 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
225 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
226 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
226 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
227 | m_chartMargins = m_chart->margins(); |
|
227 | m_chartMargins = m_chart->margins(); | |
228 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); |
|
228 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) |
|
231 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) | |
232 | { |
|
232 | { | |
233 | if (m_chartMargins.top() != newMargins.top()) |
|
233 | if (m_chartMargins.top() != newMargins.top()) | |
234 | topMarginChanged(m_chart->margins().top()); |
|
234 | topMarginChanged(m_chart->margins().top()); | |
235 | if (m_chartMargins.bottom() != newMargins.bottom()) |
|
235 | if (m_chartMargins.bottom() != newMargins.bottom()) | |
236 | bottomMarginChanged(m_chart->margins().bottom()); |
|
236 | bottomMarginChanged(m_chart->margins().bottom()); | |
237 | if (m_chartMargins.left() != newMargins.left()) |
|
237 | if (m_chartMargins.left() != newMargins.left()) | |
238 | leftMarginChanged(m_chart->margins().left()); |
|
238 | leftMarginChanged(m_chart->margins().left()); | |
239 | if (m_chartMargins.right() != newMargins.right()) |
|
239 | if (m_chartMargins.right() != newMargins.right()) | |
240 | rightMarginChanged(m_chart->margins().right()); |
|
240 | rightMarginChanged(m_chart->margins().right()); | |
241 |
|
241 | |||
242 | m_chartMargins = m_chart->margins(); |
|
242 | m_chartMargins = m_chart->margins(); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | DeclarativeChart::~DeclarativeChart() |
|
245 | DeclarativeChart::~DeclarativeChart() | |
246 | { |
|
246 | { | |
247 | delete m_chart; |
|
247 | delete m_chart; | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
250 | void DeclarativeChart::childEvent(QChildEvent *event) | |
251 | { |
|
251 | { | |
252 | if (event->type() == QEvent::ChildAdded) { |
|
252 | if (event->type() == QEvent::ChildAdded) { | |
253 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
253 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
254 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
254 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
255 | } |
|
255 | } | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | void DeclarativeChart::componentComplete() |
|
259 | void DeclarativeChart::componentComplete() | |
260 | { |
|
260 | { | |
261 | foreach(QObject *child, children()) { |
|
261 | foreach(QObject *child, children()) { | |
262 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
262 | if (qobject_cast<QAbstractSeries *>(child)) { | |
263 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
263 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
264 | if (qobject_cast<DeclarativeLineSeries *>(child)) { |
|
264 | if (qobject_cast<DeclarativeLineSeries *>(child)) { | |
265 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); |
|
265 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); | |
266 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
266 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
267 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
267 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
268 | setAxisX(s->axisX(), s); |
|
268 | setAxisX(s->axisX(), s); | |
269 | setAxisY(s->axisY(), s); |
|
269 | setAxisY(s->axisY(), s); | |
270 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { |
|
270 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { | |
271 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); |
|
271 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); | |
272 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
272 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
273 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
273 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
274 | setAxisX(s->axisX(), s); |
|
274 | setAxisX(s->axisX(), s); | |
275 | setAxisY(s->axisY(), s); |
|
275 | setAxisY(s->axisY(), s); | |
276 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { |
|
276 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { | |
277 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); |
|
277 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); | |
278 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
278 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
279 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
279 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
280 | setAxisX(s->axisX(), s); |
|
280 | setAxisX(s->axisX(), s); | |
281 | setAxisY(s->axisY(), s); |
|
281 | setAxisY(s->axisY(), s); | |
282 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { |
|
282 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { | |
283 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); |
|
283 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); | |
284 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
284 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
285 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
285 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
286 | setAxisX(s->axisX(), s); |
|
286 | setAxisX(s->axisX(), s); | |
287 | setAxisY(s->axisY(), s); |
|
287 | setAxisY(s->axisY(), s); | |
288 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { |
|
288 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { | |
289 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); |
|
289 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); | |
290 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
290 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
291 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
291 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
292 | setAxisX(s->axisX(), s); |
|
292 | setAxisX(s->axisX(), s); | |
293 | setAxisY(s->axisY(), s); |
|
293 | setAxisY(s->axisY(), s); | |
294 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { |
|
294 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { | |
295 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); |
|
295 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); | |
296 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
296 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
297 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
297 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
298 | setAxisX(s->axisX(), s); |
|
298 | setAxisX(s->axisX(), s); | |
299 | setAxisY(s->axisY(), s); |
|
299 | setAxisY(s->axisY(), s); | |
300 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { |
|
300 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { | |
301 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); |
|
301 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); | |
302 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
302 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
303 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
303 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
304 | setAxisX(s->axisX(), s); |
|
304 | setAxisX(s->axisX(), s); | |
305 | setAxisY(s->axisY(), s); |
|
305 | setAxisY(s->axisY(), s); | |
306 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { |
|
306 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { | |
307 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); |
|
307 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); | |
308 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
308 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
309 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
309 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
310 | setAxisX(s->axisX(), s); |
|
310 | setAxisX(s->axisX(), s); | |
311 | setAxisY(s->axisY(), s); |
|
311 | setAxisY(s->axisY(), s); | |
312 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { |
|
312 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { | |
313 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); |
|
313 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); | |
314 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
314 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
315 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
315 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
316 | setAxisX(s->axisX(), s); |
|
316 | setAxisX(s->axisX(), s); | |
317 | setAxisY(s->axisY(), s); |
|
317 | setAxisY(s->axisY(), s); | |
318 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { |
|
318 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { | |
319 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); |
|
319 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); | |
320 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); |
|
320 | connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); | |
321 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); |
|
321 | connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); | |
322 | setAxisX(s->axisX(), s); |
|
322 | setAxisX(s->axisX(), s); | |
323 | setAxisY(s->axisY(), s); |
|
323 | setAxisY(s->axisY(), s); | |
324 | } |
|
324 | } | |
325 | } else if(qobject_cast<QAbstractAxis *>(child)) { |
|
325 | } else if(qobject_cast<QAbstractAxis *>(child)) { | |
326 | // Do nothing, axes are set for the chart in the context of series |
|
326 | // Do nothing, axes are set for the chart in the context of series | |
327 | } |
|
327 | } | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | // Create the missing axes for the series that cannot be painted without axes |
|
330 | // Create the missing axes for the series that cannot be painted without axes | |
331 | foreach(QAbstractSeries *series, m_chart->series()) |
|
331 | foreach(QAbstractSeries *series, m_chart->series()) | |
332 | createDefaultAxes(series); |
|
332 | createDefaultAxes(series); | |
333 |
|
333 | |||
334 | QDeclarativeItem::componentComplete(); |
|
334 | QDeclarativeItem::componentComplete(); | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) |
|
337 | void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) | |
338 | { |
|
338 | { | |
339 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; |
|
339 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; | |
340 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { |
|
340 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { | |
341 | m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender())); |
|
341 | m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender())); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) |
|
345 | void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) | |
346 | { |
|
346 | { | |
347 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; |
|
347 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; | |
348 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { |
|
348 | if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) { | |
349 | m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender())); |
|
349 | m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender())); | |
350 | } |
|
350 | } | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
353 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
354 | { |
|
354 | { | |
355 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
355 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
356 | if (newGeometry.isValid()) { |
|
356 | if (newGeometry.isValid()) { | |
357 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
357 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
358 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
358 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
359 | } |
|
359 | } | |
360 | } |
|
360 | } | |
361 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
361 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
364 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
365 | { |
|
365 | { | |
366 | Q_UNUSED(option) |
|
366 | Q_UNUSED(option) | |
367 | Q_UNUSED(widget) |
|
367 | Q_UNUSED(widget) | |
368 |
|
368 | |||
369 | // TODO: optimized? |
|
369 | // TODO: optimized? | |
370 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
370 | painter->setRenderHint(QPainter::Antialiasing, true); | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
373 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
374 | { |
|
374 | { | |
375 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
375 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
376 | if (chartTheme != m_chart->theme()) |
|
376 | if (chartTheme != m_chart->theme()) | |
377 | m_chart->setTheme(chartTheme); |
|
377 | m_chart->setTheme(chartTheme); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
380 | DeclarativeChart::Theme DeclarativeChart::theme() | |
381 | { |
|
381 | { | |
382 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
382 | return (DeclarativeChart::Theme) m_chart->theme(); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
385 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
386 | { |
|
386 | { | |
387 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
387 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
388 | if (animationOptions != m_chart->animationOptions()) |
|
388 | if (animationOptions != m_chart->animationOptions()) | |
389 | m_chart->setAnimationOptions(animationOptions); |
|
389 | m_chart->setAnimationOptions(animationOptions); | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
392 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
393 | { |
|
393 | { | |
394 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
394 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
395 | return DeclarativeChart::AllAnimations; |
|
395 | return DeclarativeChart::AllAnimations; | |
396 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
396 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
397 | return DeclarativeChart::GridAxisAnimations; |
|
397 | return DeclarativeChart::GridAxisAnimations; | |
398 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
398 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
399 | return DeclarativeChart::SeriesAnimations; |
|
399 | return DeclarativeChart::SeriesAnimations; | |
400 | else |
|
400 | else | |
401 | return DeclarativeChart::NoAnimation; |
|
401 | return DeclarativeChart::NoAnimation; | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | void DeclarativeChart::setTitle(QString title) |
|
404 | void DeclarativeChart::setTitle(QString title) | |
405 | { |
|
405 | { | |
406 | if (title != m_chart->title()) |
|
406 | if (title != m_chart->title()) | |
407 | m_chart->setTitle(title); |
|
407 | m_chart->setTitle(title); | |
408 | } |
|
408 | } | |
409 | QString DeclarativeChart::title() |
|
409 | QString DeclarativeChart::title() | |
410 | { |
|
410 | { | |
411 | return m_chart->title(); |
|
411 | return m_chart->title(); | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
414 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
415 | { |
|
415 | { | |
416 | return m_chart->axisX(series); |
|
416 | return m_chart->axisX(series); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
419 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
420 | { |
|
420 | { | |
421 | return m_chart->axisY(series); |
|
421 | return m_chart->axisY(series); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | QLegend *DeclarativeChart::legend() |
|
424 | QLegend *DeclarativeChart::legend() | |
425 | { |
|
425 | { | |
426 | return m_chart->legend(); |
|
426 | return m_chart->legend(); | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | void DeclarativeChart::setTitleColor(QColor color) |
|
429 | void DeclarativeChart::setTitleColor(QColor color) | |
430 | { |
|
430 | { | |
431 | QBrush b = m_chart->titleBrush(); |
|
431 | QBrush b = m_chart->titleBrush(); | |
432 | if (color != b.color()) { |
|
432 | if (color != b.color()) { | |
433 | b.setColor(color); |
|
433 | b.setColor(color); | |
434 | m_chart->setTitleBrush(b); |
|
434 | m_chart->setTitleBrush(b); | |
435 | emit titleColorChanged(color); |
|
435 | emit titleColorChanged(color); | |
436 | } |
|
436 | } | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | QFont DeclarativeChart::titleFont() const |
|
439 | QFont DeclarativeChart::titleFont() const | |
440 | { |
|
440 | { | |
441 | return m_chart->titleFont(); |
|
441 | return m_chart->titleFont(); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
444 | void DeclarativeChart::setTitleFont(const QFont& font) | |
445 | { |
|
445 | { | |
446 | m_chart->setTitleFont(font); |
|
446 | m_chart->setTitleFont(font); | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | QColor DeclarativeChart::titleColor() |
|
449 | QColor DeclarativeChart::titleColor() | |
450 | { |
|
450 | { | |
451 | return m_chart->titleBrush().color(); |
|
451 | return m_chart->titleBrush().color(); | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
454 | void DeclarativeChart::setBackgroundColor(QColor color) | |
455 | { |
|
455 | { | |
456 | QBrush b = m_chart->backgroundBrush(); |
|
456 | QBrush b = m_chart->backgroundBrush(); | |
457 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
457 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
458 | b.setStyle(Qt::SolidPattern); |
|
458 | b.setStyle(Qt::SolidPattern); | |
459 | b.setColor(color); |
|
459 | b.setColor(color); | |
460 | m_chart->setBackgroundBrush(b); |
|
460 | m_chart->setBackgroundBrush(b); | |
461 | emit backgroundColorChanged(); |
|
461 | emit backgroundColorChanged(); | |
462 | } |
|
462 | } | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | QColor DeclarativeChart::backgroundColor() |
|
465 | QColor DeclarativeChart::backgroundColor() | |
466 | { |
|
466 | { | |
467 | return m_chart->backgroundBrush().color(); |
|
467 | return m_chart->backgroundBrush().color(); | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | int DeclarativeChart::count() |
|
470 | int DeclarativeChart::count() | |
471 | { |
|
471 | { | |
472 | return m_chart->series().count(); |
|
472 | return m_chart->series().count(); | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
475 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
476 | { |
|
476 | { | |
477 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
477 | if (enabled != m_chart->isDropShadowEnabled()) { | |
478 | m_chart->setDropShadowEnabled(enabled); |
|
478 | m_chart->setDropShadowEnabled(enabled); | |
479 | dropShadowEnabledChanged(enabled); |
|
479 | dropShadowEnabledChanged(enabled); | |
480 | } |
|
480 | } | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | bool DeclarativeChart::dropShadowEnabled() |
|
483 | bool DeclarativeChart::dropShadowEnabled() | |
484 | { |
|
484 | { | |
485 | return m_chart->isDropShadowEnabled(); |
|
485 | return m_chart->isDropShadowEnabled(); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | qreal DeclarativeChart::topMargin() |
|
488 | qreal DeclarativeChart::topMargin() | |
489 | { |
|
489 | { | |
490 | return m_chart->margins().top(); |
|
490 | return m_chart->margins().top(); | |
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | qreal DeclarativeChart::bottomMargin() |
|
493 | qreal DeclarativeChart::bottomMargin() | |
494 | { |
|
494 | { | |
495 | return m_chart->margins().bottom(); |
|
495 | return m_chart->margins().bottom(); | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | qreal DeclarativeChart::leftMargin() |
|
498 | qreal DeclarativeChart::leftMargin() | |
499 | { |
|
499 | { | |
500 | return m_chart->margins().left(); |
|
500 | return m_chart->margins().left(); | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | qreal DeclarativeChart::rightMargin() |
|
503 | qreal DeclarativeChart::rightMargin() | |
504 | { |
|
504 | { | |
505 | return m_chart->margins().right(); |
|
505 | return m_chart->margins().right(); | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | void DeclarativeChart::zoom(qreal factor) |
|
508 | void DeclarativeChart::zoom(qreal factor) | |
509 | { |
|
509 | { | |
510 | m_chart->zoom(factor); |
|
510 | m_chart->zoom(factor); | |
511 | } |
|
511 | } | |
512 |
|
512 | |||
513 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
513 | void DeclarativeChart::scrollLeft(qreal pixels) | |
514 | { |
|
514 | { | |
515 | m_chart->scroll(pixels, 0); |
|
515 | m_chart->scroll(pixels, 0); | |
516 | } |
|
516 | } | |
517 |
|
517 | |||
518 | void DeclarativeChart::scrollRight(qreal pixels) |
|
518 | void DeclarativeChart::scrollRight(qreal pixels) | |
519 | { |
|
519 | { | |
520 | m_chart->scroll(-pixels, 0); |
|
520 | m_chart->scroll(-pixels, 0); | |
521 | } |
|
521 | } | |
522 |
|
522 | |||
523 | void DeclarativeChart::scrollUp(qreal pixels) |
|
523 | void DeclarativeChart::scrollUp(qreal pixels) | |
524 | { |
|
524 | { | |
525 | m_chart->scroll(0, pixels); |
|
525 | m_chart->scroll(0, pixels); | |
526 | } |
|
526 | } | |
527 |
|
527 | |||
528 | void DeclarativeChart::scrollDown(qreal pixels) |
|
528 | void DeclarativeChart::scrollDown(qreal pixels) | |
529 | { |
|
529 | { | |
530 | m_chart->scroll(0, -pixels); |
|
530 | m_chart->scroll(0, -pixels); | |
531 | } |
|
531 | } | |
532 |
|
532 | |||
533 | QAbstractSeries *DeclarativeChart::series(int index) |
|
533 | QAbstractSeries *DeclarativeChart::series(int index) | |
534 | { |
|
534 | { | |
535 | if (index < m_chart->series().count()) { |
|
535 | if (index < m_chart->series().count()) { | |
536 | return m_chart->series().at(index); |
|
536 | return m_chart->series().at(index); | |
537 | } |
|
537 | } | |
538 | return 0; |
|
538 | return 0; | |
539 | } |
|
539 | } | |
540 |
|
540 | |||
541 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
541 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
542 | { |
|
542 | { | |
543 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
543 | foreach(QAbstractSeries *series, m_chart->series()) { | |
544 | if (series->name() == seriesName) |
|
544 | if (series->name() == seriesName) | |
545 | return series; |
|
545 | return series; | |
546 | } |
|
546 | } | |
547 | return 0; |
|
547 | return 0; | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
550 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
551 | { |
|
551 | { | |
552 | QAbstractSeries *series = 0; |
|
552 | QAbstractSeries *series = 0; | |
553 |
|
553 | |||
554 | switch (type) { |
|
554 | switch (type) { | |
555 | case DeclarativeChart::SeriesTypeLine: |
|
555 | case DeclarativeChart::SeriesTypeLine: | |
556 | series = new DeclarativeLineSeries(); |
|
556 | series = new DeclarativeLineSeries(); | |
557 | break; |
|
557 | break; | |
558 | case DeclarativeChart::SeriesTypeArea: |
|
558 | case DeclarativeChart::SeriesTypeArea: | |
559 | series = new DeclarativeAreaSeries(); |
|
559 | series = new DeclarativeAreaSeries(); | |
560 | break; |
|
560 | break; | |
561 | case DeclarativeChart::SeriesTypeStackedBar: |
|
561 | case DeclarativeChart::SeriesTypeStackedBar: | |
562 | series = new DeclarativeStackedBarSeries(); |
|
562 | series = new DeclarativeStackedBarSeries(); | |
563 | break; |
|
563 | break; | |
564 | case DeclarativeChart::SeriesTypePercentBar: |
|
564 | case DeclarativeChart::SeriesTypePercentBar: | |
565 | series = new DeclarativePercentBarSeries(); |
|
565 | series = new DeclarativePercentBarSeries(); | |
566 | break; |
|
566 | break; | |
567 | case DeclarativeChart::SeriesTypeBar: |
|
567 | case DeclarativeChart::SeriesTypeBar: | |
568 | series = new DeclarativeBarSeries(); |
|
568 | series = new DeclarativeBarSeries(); | |
569 | break; |
|
569 | break; | |
570 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
570 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
571 | series = new DeclarativeHorizontalBarSeries(); |
|
571 | series = new DeclarativeHorizontalBarSeries(); | |
572 | break; |
|
572 | break; | |
573 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
573 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
574 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
574 | series = new DeclarativeHorizontalPercentBarSeries(); | |
575 | break; |
|
575 | break; | |
576 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
576 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
577 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
577 | series = new DeclarativeHorizontalStackedBarSeries(); | |
578 | break; |
|
578 | break; | |
579 | case DeclarativeChart::SeriesTypePie: |
|
579 | case DeclarativeChart::SeriesTypePie: | |
580 | series = new DeclarativePieSeries(); |
|
580 | series = new DeclarativePieSeries(); | |
581 | break; |
|
581 | break; | |
582 | case DeclarativeChart::SeriesTypeScatter: |
|
582 | case DeclarativeChart::SeriesTypeScatter: | |
583 | series = new DeclarativeScatterSeries(); |
|
583 | series = new DeclarativeScatterSeries(); | |
584 | break; |
|
584 | break; | |
585 | case DeclarativeChart::SeriesTypeSpline: |
|
585 | case DeclarativeChart::SeriesTypeSpline: | |
586 | series = new DeclarativeSplineSeries(); |
|
586 | series = new DeclarativeSplineSeries(); | |
587 | break; |
|
587 | break; | |
588 | default: |
|
588 | default: | |
589 | qWarning() << "Illegal series type"; |
|
589 | qWarning() << "Illegal series type"; | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | if (series) { |
|
592 | if (series) { | |
593 | series->setName(name); |
|
593 | series->setName(name); | |
594 | m_chart->addSeries(series); |
|
594 | m_chart->addSeries(series); | |
595 | createDefaultAxes(series); |
|
595 | createDefaultAxes(series); | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 | return series; |
|
598 | return series; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
601 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
602 | { |
|
602 | { | |
603 | if (axis) |
|
603 | if (axis) | |
604 | m_chart->setAxisX(axis, series); |
|
604 | m_chart->setAxisX(axis, series); | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
607 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
608 | { |
|
608 | { | |
609 | if (axis) |
|
609 | if (axis) | |
610 | m_chart->setAxisY(axis, series); |
|
610 | m_chart->setAxisY(axis, series); | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | void DeclarativeChart::createDefaultAxes() |
|
613 | void DeclarativeChart::createDefaultAxes() | |
614 | { |
|
614 | { | |
615 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
615 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; | |
616 | } |
|
616 | } | |
617 |
|
617 | |||
618 | void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) |
|
618 | void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) | |
619 | { |
|
619 | { | |
620 | foreach (QAbstractSeries *s, m_chart->series()) { |
|
620 | foreach (QAbstractSeries *s, m_chart->series()) { | |
621 | // If there is already an x axis of the correct type, re-use it |
|
621 | // If there is already an x axis of the correct type, re-use it | |
622 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) |
|
622 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) | |
623 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
623 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) | |
624 | m_chart->setAxisX(m_chart->axisX(s), series); |
|
624 | m_chart->setAxisX(m_chart->axisX(s), series); | |
625 |
|
625 | |||
626 | // If there is already a y axis of the correct type, re-use it |
|
626 | // If there is already a y axis of the correct type, re-use it | |
627 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) |
|
627 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) | |
628 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) |
|
628 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) | |
629 | m_chart->setAxisY(m_chart->axisY(s), series); |
|
629 | m_chart->setAxisY(m_chart->axisY(s), series); | |
630 | } |
|
630 | } | |
631 |
|
631 | |||
632 | // If no x axis of correct type was found, create a new x axis based of default axis type |
|
632 | // If no x axis of correct type was found, create a new x axis based of default axis type | |
633 | if (!m_chart->axisX(series)) { |
|
633 | if (!m_chart->axisX(series)) { | |
634 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { |
|
634 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { | |
635 | case QAbstractAxis::AxisTypeValue: |
|
635 | case QAbstractAxis::AxisTypeValue: | |
636 | m_chart->setAxisX(new QValueAxis(this), series); |
|
636 | m_chart->setAxisX(new QValueAxis(this), series); | |
637 | break; |
|
637 | break; | |
638 | case QAbstractAxis::AxisTypeBarCategory: |
|
638 | case QAbstractAxis::AxisTypeBarCategory: | |
639 | m_chart->setAxisX(new QBarCategoryAxis(this), series); |
|
639 | m_chart->setAxisX(new QBarCategoryAxis(this), series); | |
640 | break; |
|
640 | break; | |
641 | case QAbstractAxis::AxisTypeCategory: |
|
641 | case QAbstractAxis::AxisTypeCategory: | |
642 | m_chart->setAxisX(new QCategoryAxis(this), series); |
|
642 | m_chart->setAxisX(new QCategoryAxis(this), series); | |
643 | break; |
|
643 | break; | |
644 | #ifndef QT_ON_ARM |
|
644 | #ifndef QT_ON_ARM | |
645 | case QAbstractAxis::AxisTypeDateTime: |
|
645 | case QAbstractAxis::AxisTypeDateTime: | |
646 | m_chart->setAxisX(new QDateTimeAxis(this), series); |
|
646 | m_chart->setAxisX(new QDateTimeAxis(this), series); | |
647 | break; |
|
647 | break; | |
648 | #endif |
|
648 | #endif | |
649 | default: |
|
649 | default: | |
650 | // Do nothing, assume AxisTypeNoAxis |
|
650 | // Do nothing, assume AxisTypeNoAxis | |
651 | break; |
|
651 | break; | |
652 | } |
|
652 | } | |
653 | } |
|
653 | } | |
654 |
|
654 | |||
655 | // If no y axis of correct type was found, create a new y axis based of default axis type |
|
655 | // If no y axis of correct type was found, create a new y axis based of default axis type | |
656 | if (!m_chart->axisY(series)) { |
|
656 | if (!m_chart->axisY(series)) { | |
657 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { |
|
657 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { | |
658 | case QAbstractAxis::AxisTypeValue: |
|
658 | case QAbstractAxis::AxisTypeValue: | |
659 | m_chart->setAxisY(new QValueAxis(this), series); |
|
659 | m_chart->setAxisY(new QValueAxis(this), series); | |
660 | break; |
|
660 | break; | |
661 | case QAbstractAxis::AxisTypeBarCategory: |
|
661 | case QAbstractAxis::AxisTypeBarCategory: | |
662 | m_chart->setAxisY(new QBarCategoryAxis(this), series); |
|
662 | m_chart->setAxisY(new QBarCategoryAxis(this), series); | |
663 | break; |
|
663 | break; | |
664 | case QAbstractAxis::AxisTypeCategory: |
|
664 | case QAbstractAxis::AxisTypeCategory: | |
665 | m_chart->setAxisY(new QCategoryAxis(this), series); |
|
665 | m_chart->setAxisY(new QCategoryAxis(this), series); | |
666 | break; |
|
666 | break; | |
667 | #ifndef QT_ON_ARM |
|
667 | #ifndef QT_ON_ARM | |
668 | case QAbstractAxis::AxisTypeDateTime: |
|
668 | case QAbstractAxis::AxisTypeDateTime: | |
669 | m_chart->setAxisY(new QDateTimeAxis(this), series); |
|
669 | m_chart->setAxisY(new QDateTimeAxis(this), series); | |
670 | break; |
|
670 | break; | |
671 | #endif |
|
671 | #endif | |
672 | default: |
|
672 | default: | |
673 | // Do nothing, assume AxisTypeNoAxis |
|
673 | // Do nothing, assume AxisTypeNoAxis | |
674 | break; |
|
674 | break; | |
675 | } |
|
675 | } | |
676 | } |
|
676 | } | |
677 |
|
677 | |||
678 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); |
|
678 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); | |
679 | } |
|
679 | } | |
680 |
|
680 | |||
681 | #include "moc_declarativechart.cpp" |
|
681 | #include "moc_declarativechart.cpp" | |
682 |
|
682 | |||
683 | QTCOMMERCIALCHART_END_NAMESPACE |
|
683 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,471 +1,472 | |||||
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 "qbarcategoryaxis.h" |
|
21 | #include "qbarcategoryaxis.h" | |
22 | #include "qbarcategoryaxis_p.h" |
|
22 | #include "qbarcategoryaxis_p.h" | |
23 | #include "chartbarcategoryaxisx_p.h" |
|
23 | #include "chartbarcategoryaxisx_p.h" | |
24 | #include "chartbarcategoryaxisy_p.h" |
|
24 | #include "chartbarcategoryaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QBarCategoryAxis |
|
31 | \class QBarCategoryAxis | |
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. |
|
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 |
BarCategor |
|
35 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 |
\qmlclass BarCategor |
|
41 | \qmlclass BarCategoryAxis QBarCategoryAxis | |
|
42 | \inherits AbstractAxis | |||
42 | \brief The Axis element is used for manipulating chart's axes. |
|
43 | \brief The Axis element is used for manipulating chart's axes. | |
43 |
|
44 | |||
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
46 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
46 |
|
47 | |||
47 |
To access BarCategor |
|
48 | To access BarCategoryAxis you can use ChartView API. For example: | |
48 | \code |
|
49 | \code | |
49 | ChartView { |
|
50 | ChartView { | |
50 |
BarCategor |
|
51 | BarCategoryAxis { | |
51 | id: categoryAxis |
|
52 | id: categoryAxis | |
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
53 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
53 | } |
|
54 | } | |
54 | // Add a few series... |
|
55 | // Add a few series... | |
55 | } |
|
56 | } | |
56 | \endcode |
|
57 | \endcode | |
57 | */ |
|
58 | */ | |
58 |
|
59 | |||
59 | /*! |
|
60 | /*! | |
60 | \property QBarCategoryAxis::categories |
|
61 | \property QBarCategoryAxis::categories | |
61 | Defines the categories of axis |
|
62 | Defines the categories of axis | |
62 | */ |
|
63 | */ | |
63 | /*! |
|
64 | /*! | |
64 |
\qmlproperty QStringList BarCategor |
|
65 | \qmlproperty QStringList BarCategoryAxis::categories | |
65 | Defines the categories of axis |
|
66 | Defines the categories of axis | |
66 | */ |
|
67 | */ | |
67 |
|
68 | |||
68 | /*! |
|
69 | /*! | |
69 | \property QBarCategoryAxis::min |
|
70 | \property QBarCategoryAxis::min | |
70 | Defines the minimum value on the axis. |
|
71 | Defines the minimum value on the axis. | |
71 | */ |
|
72 | */ | |
72 | /*! |
|
73 | /*! | |
73 |
\qmlproperty QString BarCategor |
|
74 | \qmlproperty QString BarCategoryAxis::min | |
74 | Defines the minimum value on the axis. |
|
75 | Defines the minimum value on the axis. | |
75 | */ |
|
76 | */ | |
76 |
|
77 | |||
77 | /*! |
|
78 | /*! | |
78 | \property QBarCategoryAxis::max |
|
79 | \property QBarCategoryAxis::max | |
79 | Defines the maximum value on the axis. |
|
80 | Defines the maximum value on the axis. | |
80 | */ |
|
81 | */ | |
81 | /*! |
|
82 | /*! | |
82 |
\qmlproperty QString BarCategor |
|
83 | \qmlproperty QString BarCategoryAxis::max | |
83 | Defines the maximum value on the axis. |
|
84 | Defines the maximum value on the axis. | |
84 | */ |
|
85 | */ | |
85 |
|
86 | |||
86 |
|
87 | |||
87 | /*! |
|
88 | /*! | |
88 | \fn void QBarCategoryAxis::categoriesChanged() |
|
89 | \fn void QBarCategoryAxis::categoriesChanged() | |
89 | Axis emits signal when the categories of the axis has changed. |
|
90 | Axis emits signal when the categories of the axis has changed. | |
90 | */ |
|
91 | */ | |
91 | /*! |
|
92 | /*! | |
92 | \fn void QBarCategoryAxis::minChanged(const QString &min) |
|
93 | \fn void QBarCategoryAxis::minChanged(const QString &min) | |
93 | Axis emits signal when \a min of axis has changed. |
|
94 | Axis emits signal when \a min of axis has changed. | |
94 | */ |
|
95 | */ | |
95 | /*! |
|
96 | /*! | |
96 |
\qmlsignal BarCategor |
|
97 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) | |
97 | Axis emits signal when \a min of axis has changed. |
|
98 | Axis emits signal when \a min of axis has changed. | |
98 | */ |
|
99 | */ | |
99 |
|
100 | |||
100 | /*! |
|
101 | /*! | |
101 | \fn void QBarCategoryAxis::maxChanged(const QString &max) |
|
102 | \fn void QBarCategoryAxis::maxChanged(const QString &max) | |
102 | Axis emits signal when \a max of axis has changed. |
|
103 | Axis emits signal when \a max of axis has changed. | |
103 | */ |
|
104 | */ | |
104 | /*! |
|
105 | /*! | |
105 |
\qmlsignal BarCategor |
|
106 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) | |
106 | Axis emits signal when \a max of axis has changed. |
|
107 | Axis emits signal when \a max of axis has changed. | |
107 | */ |
|
108 | */ | |
108 |
|
109 | |||
109 | /*! |
|
110 | /*! | |
110 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) |
|
111 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) | |
111 | Axis emits signal when \a min or \a max of axis has changed. |
|
112 | Axis emits signal when \a min or \a max of axis has changed. | |
112 | */ |
|
113 | */ | |
113 |
|
114 | |||
114 | /*! |
|
115 | /*! | |
115 | Constructs an axis object which is a child of \a parent. |
|
116 | Constructs an axis object which is a child of \a parent. | |
116 | */ |
|
117 | */ | |
117 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): |
|
118 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): | |
118 | QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent) |
|
119 | QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent) | |
119 | { |
|
120 | { | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | /*! |
|
123 | /*! | |
123 | Destroys the object |
|
124 | Destroys the object | |
124 | */ |
|
125 | */ | |
125 | QBarCategoryAxis::~QBarCategoryAxis() |
|
126 | QBarCategoryAxis::~QBarCategoryAxis() | |
126 | { |
|
127 | { | |
127 | Q_D(QBarCategoryAxis); |
|
128 | Q_D(QBarCategoryAxis); | |
128 | if(d->m_dataset){ |
|
129 | if(d->m_dataset){ | |
129 | d->m_dataset->removeAxis(this); |
|
130 | d->m_dataset->removeAxis(this); | |
130 | } |
|
131 | } | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | /*! |
|
134 | /*! | |
134 | \internal |
|
135 | \internal | |
135 | */ |
|
136 | */ | |
136 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
137 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) | |
137 | { |
|
138 | { | |
138 |
|
139 | |||
139 | } |
|
140 | } | |
140 |
|
141 | |||
141 | /*! |
|
142 | /*! | |
142 | Appends \a categories to axis |
|
143 | Appends \a categories to axis | |
143 | */ |
|
144 | */ | |
144 | void QBarCategoryAxis::append(const QStringList &categories) |
|
145 | void QBarCategoryAxis::append(const QStringList &categories) | |
145 | { |
|
146 | { | |
146 | if(categories.isEmpty()) return; |
|
147 | if(categories.isEmpty()) return; | |
147 |
|
148 | |||
148 | Q_D(QBarCategoryAxis); |
|
149 | Q_D(QBarCategoryAxis); | |
149 | if (d->m_categories.isEmpty()) { |
|
150 | if (d->m_categories.isEmpty()) { | |
150 | d->m_categories.append(categories); |
|
151 | d->m_categories.append(categories); | |
151 | setRange(categories.first(),categories.last()); |
|
152 | setRange(categories.first(),categories.last()); | |
152 | }else{ |
|
153 | }else{ | |
153 | d->m_categories.append(categories); |
|
154 | d->m_categories.append(categories); | |
154 | d->emitUpdated(); |
|
155 | d->emitUpdated(); | |
155 | } |
|
156 | } | |
156 | emit categoriesChanged(); |
|
157 | emit categoriesChanged(); | |
157 | } |
|
158 | } | |
158 |
|
159 | |||
159 | /*! |
|
160 | /*! | |
160 | Appends \a category to axis |
|
161 | Appends \a category to axis | |
161 | */ |
|
162 | */ | |
162 | void QBarCategoryAxis::append(const QString &category) |
|
163 | void QBarCategoryAxis::append(const QString &category) | |
163 | { |
|
164 | { | |
164 | Q_D(QBarCategoryAxis); |
|
165 | Q_D(QBarCategoryAxis); | |
165 | if (d->m_categories.isEmpty()) { |
|
166 | if (d->m_categories.isEmpty()) { | |
166 | d->m_categories.append(category); |
|
167 | d->m_categories.append(category); | |
167 | setRange(category,category); |
|
168 | setRange(category,category); | |
168 | }else{ |
|
169 | }else{ | |
169 | d->m_categories.append(category); |
|
170 | d->m_categories.append(category); | |
170 | d->emitUpdated(); |
|
171 | d->emitUpdated(); | |
171 | } |
|
172 | } | |
172 | emit categoriesChanged(); |
|
173 | emit categoriesChanged(); | |
173 | } |
|
174 | } | |
174 |
|
175 | |||
175 | /*! |
|
176 | /*! | |
176 | Removes \a category from axis |
|
177 | Removes \a category from axis | |
177 | */ |
|
178 | */ | |
178 | void QBarCategoryAxis::remove(const QString &category) |
|
179 | void QBarCategoryAxis::remove(const QString &category) | |
179 | { |
|
180 | { | |
180 | Q_D(QBarCategoryAxis); |
|
181 | Q_D(QBarCategoryAxis); | |
181 | if (d->m_categories.contains(category)) { |
|
182 | if (d->m_categories.contains(category)) { | |
182 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
183 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
183 | if(!d->m_categories.isEmpty()) |
|
184 | if(!d->m_categories.isEmpty()) | |
184 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
185 | setRange(d->m_categories.first(),d->m_categories.last()); | |
185 | else |
|
186 | else | |
186 | setRange(QString::null,QString::null); |
|
187 | setRange(QString::null,QString::null); | |
187 | emit categoriesChanged(); |
|
188 | emit categoriesChanged(); | |
188 | } |
|
189 | } | |
189 | } |
|
190 | } | |
190 |
|
191 | |||
191 | /*! |
|
192 | /*! | |
192 | Inserts \a category to axis at \a index |
|
193 | Inserts \a category to axis at \a index | |
193 | */ |
|
194 | */ | |
194 | void QBarCategoryAxis::insert(int index, const QString &category) |
|
195 | void QBarCategoryAxis::insert(int index, const QString &category) | |
195 | { |
|
196 | { | |
196 | Q_D(QBarCategoryAxis); |
|
197 | Q_D(QBarCategoryAxis); | |
197 | if (d->m_categories.isEmpty()) { |
|
198 | if (d->m_categories.isEmpty()) { | |
198 | d->m_categories.insert(index,category); |
|
199 | d->m_categories.insert(index,category); | |
199 | setRange(category,category); |
|
200 | setRange(category,category); | |
200 | }else{ |
|
201 | }else{ | |
201 | d->m_categories.insert(index,category); |
|
202 | d->m_categories.insert(index,category); | |
202 | d->emitUpdated(); |
|
203 | d->emitUpdated(); | |
203 | } |
|
204 | } | |
204 | emit categoriesChanged(); |
|
205 | emit categoriesChanged(); | |
205 | } |
|
206 | } | |
206 |
|
207 | |||
207 | /*! |
|
208 | /*! | |
208 | Replaces \a oldCategory with \a newCategory. |
|
209 | Replaces \a oldCategory with \a newCategory. | |
209 | If \a oldCategory does not exits on the axis nothing is done. |
|
210 | If \a oldCategory does not exits on the axis nothing is done. | |
210 | */ |
|
211 | */ | |
211 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) |
|
212 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) | |
212 | { |
|
213 | { | |
213 | Q_D(QBarCategoryAxis); |
|
214 | Q_D(QBarCategoryAxis); | |
214 | int pos = d->m_categories.indexOf(oldCategory); |
|
215 | int pos = d->m_categories.indexOf(oldCategory); | |
215 | if (pos != -1) { |
|
216 | if (pos != -1) { | |
216 | d->m_categories.replace(pos, newCategory); |
|
217 | d->m_categories.replace(pos, newCategory); | |
217 | d->emitUpdated(); |
|
218 | d->emitUpdated(); | |
218 | emit categoriesChanged(); |
|
219 | emit categoriesChanged(); | |
219 | } |
|
220 | } | |
220 | } |
|
221 | } | |
221 |
|
222 | |||
222 | /*! |
|
223 | /*! | |
223 | Removes all categories. |
|
224 | Removes all categories. | |
224 | */ |
|
225 | */ | |
225 | void QBarCategoryAxis::clear() |
|
226 | void QBarCategoryAxis::clear() | |
226 | { |
|
227 | { | |
227 | Q_D(QBarCategoryAxis); |
|
228 | Q_D(QBarCategoryAxis); | |
228 | d->m_categories.clear(); |
|
229 | d->m_categories.clear(); | |
229 | setRange(QString::null,QString::null); |
|
230 | setRange(QString::null,QString::null); | |
230 | emit categoriesChanged(); |
|
231 | emit categoriesChanged(); | |
231 | } |
|
232 | } | |
232 |
|
233 | |||
233 | void QBarCategoryAxis::setCategories(const QStringList &categories) |
|
234 | void QBarCategoryAxis::setCategories(const QStringList &categories) | |
234 | { |
|
235 | { | |
235 | Q_D(QBarCategoryAxis); |
|
236 | Q_D(QBarCategoryAxis); | |
236 | if(d->m_categories!=categories) { |
|
237 | if(d->m_categories!=categories) { | |
237 | d->m_categories = categories; |
|
238 | d->m_categories = categories; | |
238 | setRange(categories.first(),categories.last()); |
|
239 | setRange(categories.first(),categories.last()); | |
239 | emit categoriesChanged(); |
|
240 | emit categoriesChanged(); | |
240 | } |
|
241 | } | |
241 | } |
|
242 | } | |
242 |
|
243 | |||
243 | QStringList QBarCategoryAxis::categories() |
|
244 | QStringList QBarCategoryAxis::categories() | |
244 | { |
|
245 | { | |
245 | Q_D(QBarCategoryAxis); |
|
246 | Q_D(QBarCategoryAxis); | |
246 | return d->m_categories; |
|
247 | return d->m_categories; | |
247 | } |
|
248 | } | |
248 |
|
249 | |||
249 | /*! |
|
250 | /*! | |
250 | Returns number of categories. |
|
251 | Returns number of categories. | |
251 | */ |
|
252 | */ | |
252 | int QBarCategoryAxis::count() const |
|
253 | int QBarCategoryAxis::count() const | |
253 | { |
|
254 | { | |
254 | Q_D(const QBarCategoryAxis); |
|
255 | Q_D(const QBarCategoryAxis); | |
255 | return d->m_categories.count(); |
|
256 | return d->m_categories.count(); | |
256 | } |
|
257 | } | |
257 |
|
258 | |||
258 | /*! |
|
259 | /*! | |
259 | Returns category at \a index. Index must be valid. |
|
260 | Returns category at \a index. Index must be valid. | |
260 | */ |
|
261 | */ | |
261 | QString QBarCategoryAxis::at(int index) const |
|
262 | QString QBarCategoryAxis::at(int index) const | |
262 | { |
|
263 | { | |
263 | Q_D(const QBarCategoryAxis); |
|
264 | Q_D(const QBarCategoryAxis); | |
264 | return d->m_categories.at(index); |
|
265 | return d->m_categories.at(index); | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | /*! |
|
268 | /*! | |
268 | Sets minimum category to \a min. |
|
269 | Sets minimum category to \a min. | |
269 | */ |
|
270 | */ | |
270 | void QBarCategoryAxis::setMin(const QString& min) |
|
271 | void QBarCategoryAxis::setMin(const QString& min) | |
271 | { |
|
272 | { | |
272 | Q_D(QBarCategoryAxis); |
|
273 | Q_D(QBarCategoryAxis); | |
273 | setRange(min,d->m_maxCategory); |
|
274 | setRange(min,d->m_maxCategory); | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 | /*! |
|
277 | /*! | |
277 | Returns minimum category. |
|
278 | Returns minimum category. | |
278 | */ |
|
279 | */ | |
279 | QString QBarCategoryAxis::min() const |
|
280 | QString QBarCategoryAxis::min() const | |
280 | { |
|
281 | { | |
281 | Q_D(const QBarCategoryAxis); |
|
282 | Q_D(const QBarCategoryAxis); | |
282 | return d->m_minCategory; |
|
283 | return d->m_minCategory; | |
283 | } |
|
284 | } | |
284 |
|
285 | |||
285 | /*! |
|
286 | /*! | |
286 | Sets maximum category to \a max. |
|
287 | Sets maximum category to \a max. | |
287 | */ |
|
288 | */ | |
288 | void QBarCategoryAxis::setMax(const QString& max) |
|
289 | void QBarCategoryAxis::setMax(const QString& max) | |
289 | { |
|
290 | { | |
290 | Q_D(QBarCategoryAxis); |
|
291 | Q_D(QBarCategoryAxis); | |
291 | setRange(d->m_minCategory,max); |
|
292 | setRange(d->m_minCategory,max); | |
292 | } |
|
293 | } | |
293 |
|
294 | |||
294 | /*! |
|
295 | /*! | |
295 | Returns maximum category |
|
296 | Returns maximum category | |
296 | */ |
|
297 | */ | |
297 | QString QBarCategoryAxis::max() const |
|
298 | QString QBarCategoryAxis::max() const | |
298 | { |
|
299 | { | |
299 | Q_D(const QBarCategoryAxis); |
|
300 | Q_D(const QBarCategoryAxis); | |
300 | return d->m_maxCategory; |
|
301 | return d->m_maxCategory; | |
301 | } |
|
302 | } | |
302 |
|
303 | |||
303 | /*! |
|
304 | /*! | |
304 | Sets range from \a minCategory to \a maxCategory |
|
305 | Sets range from \a minCategory to \a maxCategory | |
305 | */ |
|
306 | */ | |
306 | void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
307 | void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
307 | { |
|
308 | { | |
308 | Q_D(QBarCategoryAxis); |
|
309 | Q_D(QBarCategoryAxis); | |
309 |
|
310 | |||
310 | bool changed = false; |
|
311 | bool changed = false; | |
311 |
|
312 | |||
312 | //special case |
|
313 | //special case | |
313 | if(minCategory.isNull() && maxCategory.isNull()){ |
|
314 | if(minCategory.isNull() && maxCategory.isNull()){ | |
314 | d->m_minCategory = minCategory; |
|
315 | d->m_minCategory = minCategory; | |
315 | d->m_maxCategory = maxCategory; |
|
316 | d->m_maxCategory = maxCategory; | |
316 | d->m_min = 0; |
|
317 | d->m_min = 0; | |
317 | d->m_max = 0; |
|
318 | d->m_max = 0; | |
318 | emit minChanged(minCategory); |
|
319 | emit minChanged(minCategory); | |
319 | emit maxChanged(maxCategory); |
|
320 | emit maxChanged(maxCategory); | |
320 | d->m_count=0; |
|
321 | d->m_count=0; | |
321 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
322 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
322 | d->emitUpdated(); |
|
323 | d->emitUpdated(); | |
323 | } |
|
324 | } | |
324 |
|
325 | |||
325 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; |
|
326 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; | |
326 |
|
327 | |||
327 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { |
|
328 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { | |
328 | d->m_minCategory = minCategory; |
|
329 | d->m_minCategory = minCategory; | |
329 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
330 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; | |
330 | changed = true; |
|
331 | changed = true; | |
331 | emit minChanged(minCategory); |
|
332 | emit minChanged(minCategory); | |
332 | } |
|
333 | } | |
333 |
|
334 | |||
334 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { |
|
335 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { | |
335 | d->m_maxCategory = maxCategory; |
|
336 | d->m_maxCategory = maxCategory; | |
336 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
337 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; | |
337 | changed = true; |
|
338 | changed = true; | |
338 | emit maxChanged(maxCategory); |
|
339 | emit maxChanged(maxCategory); | |
339 | } |
|
340 | } | |
340 |
|
341 | |||
341 | if (changed) { |
|
342 | if (changed) { | |
342 | d->m_count=d->m_max - d->m_min; |
|
343 | d->m_count=d->m_max - d->m_min; | |
343 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
344 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
344 | d->emitUpdated(); |
|
345 | d->emitUpdated(); | |
345 | } |
|
346 | } | |
346 | } |
|
347 | } | |
347 |
|
348 | |||
348 | /*! |
|
349 | /*! | |
349 | Returns the type of the axis |
|
350 | Returns the type of the axis | |
350 | */ |
|
351 | */ | |
351 | QAbstractAxis::AxisType QBarCategoryAxis::type() const |
|
352 | QAbstractAxis::AxisType QBarCategoryAxis::type() const | |
352 | { |
|
353 | { | |
353 | return AxisTypeBarCategory; |
|
354 | return AxisTypeBarCategory; | |
354 | } |
|
355 | } | |
355 |
|
356 | |||
356 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
357 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
357 |
|
358 | |||
358 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q): |
|
359 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q): | |
359 | QAbstractAxisPrivate(q), |
|
360 | QAbstractAxisPrivate(q), | |
360 | m_min(0.0), |
|
361 | m_min(0.0), | |
361 | m_max(0.0), |
|
362 | m_max(0.0), | |
362 | m_count(0) |
|
363 | m_count(0) | |
363 | { |
|
364 | { | |
364 |
|
365 | |||
365 | } |
|
366 | } | |
366 |
|
367 | |||
367 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() |
|
368 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() | |
368 | { |
|
369 | { | |
369 |
|
370 | |||
370 | } |
|
371 | } | |
371 |
|
372 | |||
372 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) |
|
373 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) | |
373 | { |
|
374 | { | |
374 | setRange(min,m_maxCategory); |
|
375 | setRange(min,m_maxCategory); | |
375 | } |
|
376 | } | |
376 |
|
377 | |||
377 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) |
|
378 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) | |
378 | { |
|
379 | { | |
379 | setRange(m_minCategory,max); |
|
380 | setRange(m_minCategory,max); | |
380 | } |
|
381 | } | |
381 |
|
382 | |||
382 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
383 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
383 | { |
|
384 | { | |
384 | Q_Q(QBarCategoryAxis); |
|
385 | Q_Q(QBarCategoryAxis); | |
385 | QString value1 = min.toString(); |
|
386 | QString value1 = min.toString(); | |
386 | QString value2 = max.toString(); |
|
387 | QString value2 = max.toString(); | |
387 | q->setRange(value1,value2); |
|
388 | q->setRange(value1,value2); | |
388 | } |
|
389 | } | |
389 |
|
390 | |||
390 | void QBarCategoryAxisPrivate::handleDomainUpdated() |
|
391 | void QBarCategoryAxisPrivate::handleDomainUpdated() | |
391 | { |
|
392 | { | |
392 | Q_Q(QBarCategoryAxis); |
|
393 | Q_Q(QBarCategoryAxis); | |
393 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
394 | Domain* domain = qobject_cast<Domain*>(sender()); | |
394 |
|
395 | |||
395 | if(m_orientation==Qt::Horizontal) { |
|
396 | if(m_orientation==Qt::Horizontal) { | |
396 | m_min = domain->minX(); |
|
397 | m_min = domain->minX(); | |
397 | m_max = domain->maxX(); |
|
398 | m_max = domain->maxX(); | |
398 | } |
|
399 | } | |
399 | else if(m_orientation==Qt::Vertical) { |
|
400 | else if(m_orientation==Qt::Vertical) { | |
400 | m_min = domain->minY(); |
|
401 | m_min = domain->minY(); | |
401 | m_max = domain->maxY(); |
|
402 | m_max = domain->maxY(); | |
402 | } |
|
403 | } | |
403 |
|
404 | |||
404 | bool changed = false; |
|
405 | bool changed = false; | |
405 |
|
406 | |||
406 | int min = m_min + 0.5; |
|
407 | int min = m_min + 0.5; | |
407 | if(min>=0 && min<m_categories.count()) { |
|
408 | if(min>=0 && min<m_categories.count()) { | |
408 | QString minCategory = m_categories.at(min); |
|
409 | QString minCategory = m_categories.at(min); | |
409 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { |
|
410 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { | |
410 | m_minCategory=minCategory; |
|
411 | m_minCategory=minCategory; | |
411 | changed=true; |
|
412 | changed=true; | |
412 | emit q->minChanged(minCategory); |
|
413 | emit q->minChanged(minCategory); | |
413 | } |
|
414 | } | |
414 | } |
|
415 | } | |
415 | int max = m_max - 0.5; |
|
416 | int max = m_max - 0.5; | |
416 | if(max>=0 && max<m_categories.count()) { |
|
417 | if(max>=0 && max<m_categories.count()) { | |
417 | QString maxCategory = m_categories.at(max); |
|
418 | QString maxCategory = m_categories.at(max); | |
418 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { |
|
419 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { | |
419 | m_maxCategory=maxCategory; |
|
420 | m_maxCategory=maxCategory; | |
420 | emit q->maxChanged(maxCategory); |
|
421 | emit q->maxChanged(maxCategory); | |
421 | } |
|
422 | } | |
422 | } |
|
423 | } | |
423 |
|
424 | |||
424 | if (changed) { |
|
425 | if (changed) { | |
425 | emit q->rangeChanged(m_minCategory,m_maxCategory); |
|
426 | emit q->rangeChanged(m_minCategory,m_maxCategory); | |
426 | } |
|
427 | } | |
427 | } |
|
428 | } | |
428 |
|
429 | |||
429 | ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
430 | ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) | |
430 | { |
|
431 | { | |
431 | Q_Q(QBarCategoryAxis); |
|
432 | Q_Q(QBarCategoryAxis); | |
432 | if(m_orientation == Qt::Vertical){ |
|
433 | if(m_orientation == Qt::Vertical){ | |
433 | return new ChartCategoriesAxisY(q,presenter); |
|
434 | return new ChartCategoriesAxisY(q,presenter); | |
434 | }else{ |
|
435 | }else{ | |
435 | return new ChartCategoriesAxisX(q,presenter); |
|
436 | return new ChartCategoriesAxisX(q,presenter); | |
436 | } |
|
437 | } | |
437 | } |
|
438 | } | |
438 |
|
439 | |||
439 | void QBarCategoryAxisPrivate::intializeDomain(Domain* domain) |
|
440 | void QBarCategoryAxisPrivate::intializeDomain(Domain* domain) | |
440 | { |
|
441 | { | |
441 |
|
442 | |||
442 | Q_Q(QBarCategoryAxis); |
|
443 | Q_Q(QBarCategoryAxis); | |
443 | if(m_max==m_min) { |
|
444 | if(m_max==m_min) { | |
444 | int min; |
|
445 | int min; | |
445 | int max; |
|
446 | int max; | |
446 | if(m_orientation==Qt::Vertical) { |
|
447 | if(m_orientation==Qt::Vertical) { | |
447 | min = domain->minY() + 0.5; |
|
448 | min = domain->minY() + 0.5; | |
448 | max = domain->maxY() - 0.5; |
|
449 | max = domain->maxY() - 0.5; | |
449 | } |
|
450 | } | |
450 | else { |
|
451 | else { | |
451 | min = domain->minX() + 0.5; |
|
452 | min = domain->minX() + 0.5; | |
452 | max = domain->maxX() - 0.5; |
|
453 | max = domain->maxX() - 0.5; | |
453 | } |
|
454 | } | |
454 |
|
455 | |||
455 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) |
|
456 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) | |
456 | q->setRange(m_categories.at(min),m_categories.at(max)); |
|
457 | q->setRange(m_categories.at(min),m_categories.at(max)); | |
457 | } |
|
458 | } | |
458 | else { |
|
459 | else { | |
459 | if(m_orientation==Qt::Vertical) { |
|
460 | if(m_orientation==Qt::Vertical) { | |
460 | domain->setRangeY(m_min, m_max); |
|
461 | domain->setRangeY(m_min, m_max); | |
461 | } |
|
462 | } | |
462 | else { |
|
463 | else { | |
463 | domain->setRangeX(m_min, m_max); |
|
464 | domain->setRangeX(m_min, m_max); | |
464 | } |
|
465 | } | |
465 | } |
|
466 | } | |
466 | } |
|
467 | } | |
467 |
|
468 | |||
468 | #include "moc_qbarcategoryaxis.cpp" |
|
469 | #include "moc_qbarcategoryaxis.cpp" | |
469 | #include "moc_qbarcategoryaxis_p.cpp" |
|
470 | #include "moc_qbarcategoryaxis_p.cpp" | |
470 |
|
471 | |||
471 | QTCOMMERCIALCHART_END_NAMESPACE |
|
472 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,261 +1,262 | |||||
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 "qcategoryaxis.h" |
|
21 | #include "qcategoryaxis.h" | |
22 | #include "qcategoryaxis_p.h" |
|
22 | #include "qcategoryaxis_p.h" | |
23 | #include "chartcategoryaxisx_p.h" |
|
23 | #include "chartcategoryaxisx_p.h" | |
24 | #include "chartcategoryaxisy_p.h" |
|
24 | #include "chartcategoryaxisy_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 | /*! |
|
29 | /*! | |
30 | \class QCategoryAxis |
|
30 | \class QCategoryAxis | |
31 | \brief The QCategoryAxis class allows putting a named ranges on the axis. |
|
31 | \brief The QCategoryAxis class allows putting a named ranges on the axis. | |
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | This class can be used when the underlying data needs to be given extra meaning. |
|
34 | This class can be used when the underlying data needs to be given extra meaning. | |
35 | Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely. |
|
35 | Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \qmlclass CategoryAxis QCategoryAxis |
|
39 | \qmlclass CategoryAxis QCategoryAxis | |
|
40 | \inherits AbstractAxis | |||
40 | \brief The QCategoryAxis class allows putting a named ranges on the axis. |
|
41 | \brief The QCategoryAxis class allows putting a named ranges on the axis. | |
41 | */ |
|
42 | */ | |
42 |
|
43 | |||
43 | /*! |
|
44 | /*! | |
44 | \property QCategoryAxis::startValue |
|
45 | \property QCategoryAxis::startValue | |
45 | Defines the low end of the first category on the axis. |
|
46 | Defines the low end of the first category on the axis. | |
46 | */ |
|
47 | */ | |
47 |
|
48 | |||
48 | /*! |
|
49 | /*! | |
49 | \qmlproperty int CategoryAxis::startValue |
|
50 | \qmlproperty int CategoryAxis::startValue | |
50 | Defines the low end of the first category on the axis. |
|
51 | Defines the low end of the first category on the axis. | |
51 | */ |
|
52 | */ | |
52 |
|
53 | |||
53 | /*! |
|
54 | /*! | |
54 | Constructs an axis object which is a child of \a parent. |
|
55 | Constructs an axis object which is a child of \a parent. | |
55 | */ |
|
56 | */ | |
56 | QCategoryAxis::QCategoryAxis(QObject *parent): |
|
57 | QCategoryAxis::QCategoryAxis(QObject *parent): | |
57 | QValueAxis(*new QCategoryAxisPrivate(this),parent) |
|
58 | QValueAxis(*new QCategoryAxisPrivate(this),parent) | |
58 | { |
|
59 | { | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | /*! |
|
62 | /*! | |
62 | Destroys the object |
|
63 | Destroys the object | |
63 | */ |
|
64 | */ | |
64 | QCategoryAxis::~QCategoryAxis() |
|
65 | QCategoryAxis::~QCategoryAxis() | |
65 | { |
|
66 | { | |
66 | // Q_D(QValueAxis); |
|
67 | // Q_D(QValueAxis); | |
67 | // if(d->m_dataset) { |
|
68 | // if(d->m_dataset) { | |
68 | // d->m_dataset->removeAxis(this); |
|
69 | // d->m_dataset->removeAxis(this); | |
69 | // } |
|
70 | // } | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | /*! |
|
73 | /*! | |
73 | \internal |
|
74 | \internal | |
74 | */ |
|
75 | */ | |
75 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent) |
|
76 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent) | |
76 | { |
|
77 | { | |
77 |
|
78 | |||
78 | } |
|
79 | } | |
79 |
|
80 | |||
80 | /*! |
|
81 | /*! | |
81 | Appends new category to the axis with an \a categoryLabel. |
|
82 | Appends new category to the axis with an \a categoryLabel. | |
82 | Category label has to be unique. |
|
83 | Category label has to be unique. | |
83 | Parameter \a categoryEndValue specifies the high end limit of the category. |
|
84 | Parameter \a categoryEndValue specifies the high end limit of the category. | |
84 | It has to be greater than the high end limit of the previous category. |
|
85 | It has to be greater than the high end limit of the previous category. | |
85 | Otherwise the method returns without adding a new category. |
|
86 | Otherwise the method returns without adding a new category. | |
86 | */ |
|
87 | */ | |
87 | void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue) |
|
88 | void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue) | |
88 | { |
|
89 | { | |
89 | Q_D(QCategoryAxis); |
|
90 | Q_D(QCategoryAxis); | |
90 |
|
91 | |||
91 | if (!d->m_categories.contains(categoryLabel)) |
|
92 | if (!d->m_categories.contains(categoryLabel)) | |
92 | { |
|
93 | { | |
93 | if(d->m_categories.isEmpty()){ |
|
94 | if(d->m_categories.isEmpty()){ | |
94 | Range range(d->m_categoryMinimum, categoryEndValue); |
|
95 | Range range(d->m_categoryMinimum, categoryEndValue); | |
95 | d->m_categoriesMap.insert(categoryLabel, range); |
|
96 | d->m_categoriesMap.insert(categoryLabel, range); | |
96 | d->m_categories.append(categoryLabel); |
|
97 | d->m_categories.append(categoryLabel); | |
97 | }else if (categoryEndValue > endValue(d->m_categories.last())){ |
|
98 | }else if (categoryEndValue > endValue(d->m_categories.last())){ | |
98 | Range previousRange = d->m_categoriesMap.value(d->m_categories.last()); |
|
99 | Range previousRange = d->m_categoriesMap.value(d->m_categories.last()); | |
99 | d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue)); |
|
100 | d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue)); | |
100 | d->m_categories.append(categoryLabel); |
|
101 | d->m_categories.append(categoryLabel); | |
101 | } |
|
102 | } | |
102 | } |
|
103 | } | |
103 | } |
|
104 | } | |
104 |
|
105 | |||
105 | /*! |
|
106 | /*! | |
106 | Sets \a min to be the low end limit of the first category on the axis. |
|
107 | Sets \a min to be the low end limit of the first category on the axis. | |
107 | If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range. |
|
108 | If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range. | |
108 | Otherwise nothing is done. |
|
109 | Otherwise nothing is done. | |
109 | */ |
|
110 | */ | |
110 | void QCategoryAxis::setStartValue(qreal min) |
|
111 | void QCategoryAxis::setStartValue(qreal min) | |
111 | { |
|
112 | { | |
112 | Q_D(QCategoryAxis); |
|
113 | Q_D(QCategoryAxis); | |
113 | if(d->m_categories.isEmpty()){ |
|
114 | if(d->m_categories.isEmpty()){ | |
114 | d->m_categoryMinimum = min; |
|
115 | d->m_categoryMinimum = min; | |
115 | }else{ |
|
116 | }else{ | |
116 | Range range = d->m_categoriesMap.value(d->m_categories.first()); |
|
117 | Range range = d->m_categoriesMap.value(d->m_categories.first()); | |
117 | if (min < range.second) |
|
118 | if (min < range.second) | |
118 | d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second)); |
|
119 | d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second)); | |
119 | } |
|
120 | } | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | /*! |
|
123 | /*! | |
123 | Returns the low end limit of the category specified by an \a categoryLabel |
|
124 | Returns the low end limit of the category specified by an \a categoryLabel | |
124 | */ |
|
125 | */ | |
125 | qreal QCategoryAxis::startValue(const QString& categoryLabel) const |
|
126 | qreal QCategoryAxis::startValue(const QString& categoryLabel) const | |
126 | { |
|
127 | { | |
127 | Q_D(const QCategoryAxis); |
|
128 | Q_D(const QCategoryAxis); | |
128 | if (categoryLabel == QString()) |
|
129 | if (categoryLabel == QString()) | |
129 | return d->m_categoryMinimum; |
|
130 | return d->m_categoryMinimum; | |
130 | else |
|
131 | else | |
131 | return d->m_categoriesMap.value(categoryLabel).first; |
|
132 | return d->m_categoriesMap.value(categoryLabel).first; | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | /*! |
|
135 | /*! | |
135 | Returns the high end limit of the interval specified by an \a categoryLabel |
|
136 | Returns the high end limit of the interval specified by an \a categoryLabel | |
136 | */ |
|
137 | */ | |
137 | qreal QCategoryAxis::endValue(const QString& categoryLabel) const |
|
138 | qreal QCategoryAxis::endValue(const QString& categoryLabel) const | |
138 | { |
|
139 | { | |
139 | Q_D(const QCategoryAxis); |
|
140 | Q_D(const QCategoryAxis); | |
140 | return d->m_categoriesMap.value(categoryLabel).second; |
|
141 | return d->m_categoriesMap.value(categoryLabel).second; | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | /*! |
|
144 | /*! | |
144 | Removes an interval specified by the \a categoryLabel from the axis |
|
145 | Removes an interval specified by the \a categoryLabel from the axis | |
145 | */ |
|
146 | */ | |
146 | void QCategoryAxis::remove(const QString &categoryLabel) |
|
147 | void QCategoryAxis::remove(const QString &categoryLabel) | |
147 | { |
|
148 | { | |
148 | Q_D(QCategoryAxis); |
|
149 | Q_D(QCategoryAxis); | |
149 | int labelIndex = d->m_categories.indexOf(categoryLabel); |
|
150 | int labelIndex = d->m_categories.indexOf(categoryLabel); | |
150 |
|
151 | |||
151 | // check if such label exists |
|
152 | // check if such label exists | |
152 | if (labelIndex != -1) { |
|
153 | if (labelIndex != -1) { | |
153 | d->m_categories.removeAt(labelIndex); |
|
154 | d->m_categories.removeAt(labelIndex); | |
154 | d->m_categoriesMap.remove(categoryLabel); |
|
155 | d->m_categoriesMap.remove(categoryLabel); | |
155 |
|
156 | |||
156 | // the range of the interval that follows (if exists) needs to be updated |
|
157 | // the range of the interval that follows (if exists) needs to be updated | |
157 | if (labelIndex < d->m_categories.count()) { |
|
158 | if (labelIndex < d->m_categories.count()) { | |
158 | QString label = d->m_categories.at(labelIndex); |
|
159 | QString label = d->m_categories.at(labelIndex); | |
159 | Range range = d->m_categoriesMap.value(label); |
|
160 | Range range = d->m_categoriesMap.value(label); | |
160 |
|
161 | |||
161 | // set the range |
|
162 | // set the range | |
162 | if (labelIndex == 0) { |
|
163 | if (labelIndex == 0) { | |
163 | range.first = d->m_categoryMinimum; |
|
164 | range.first = d->m_categoryMinimum; | |
164 | d->m_categoriesMap.insert(label, range); |
|
165 | d->m_categoriesMap.insert(label, range); | |
165 | } else { |
|
166 | } else { | |
166 | range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second; |
|
167 | range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second; | |
167 | d->m_categoriesMap.insert(label, range); |
|
168 | d->m_categoriesMap.insert(label, range); | |
168 | } |
|
169 | } | |
169 | } |
|
170 | } | |
170 | d->emitUpdated(); |
|
171 | d->emitUpdated(); | |
171 | } |
|
172 | } | |
172 | } |
|
173 | } | |
173 |
|
174 | |||
174 | /*! |
|
175 | /*! | |
175 | Replaces \a oldLabel of an existing category with a \a newLabel |
|
176 | Replaces \a oldLabel of an existing category with a \a newLabel | |
176 | If the old label does not exist the method returns without making any changes. |
|
177 | If the old label does not exist the method returns without making any changes. | |
177 | */ |
|
178 | */ | |
178 | void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel) |
|
179 | void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel) | |
179 | { |
|
180 | { | |
180 | Q_D(QCategoryAxis); |
|
181 | Q_D(QCategoryAxis); | |
181 | int labelIndex = d->m_categories.indexOf(oldLabel); |
|
182 | int labelIndex = d->m_categories.indexOf(oldLabel); | |
182 |
|
183 | |||
183 | // check if such label exists |
|
184 | // check if such label exists | |
184 | if (labelIndex != -1) { |
|
185 | if (labelIndex != -1) { | |
185 | d->m_categories.replace(labelIndex, newLabel); |
|
186 | d->m_categories.replace(labelIndex, newLabel); | |
186 | Range range = d->m_categoriesMap.value(oldLabel); |
|
187 | Range range = d->m_categoriesMap.value(oldLabel); | |
187 | d->m_categoriesMap.remove(oldLabel); |
|
188 | d->m_categoriesMap.remove(oldLabel); | |
188 | d->m_categoriesMap.insert(newLabel, range); |
|
189 | d->m_categoriesMap.insert(newLabel, range); | |
189 | d->emitUpdated(); |
|
190 | d->emitUpdated(); | |
190 | } |
|
191 | } | |
191 |
|
192 | |||
192 | } |
|
193 | } | |
193 |
|
194 | |||
194 | /*! |
|
195 | /*! | |
195 | Returns the list of the intervals labels |
|
196 | Returns the list of the intervals labels | |
196 | */ |
|
197 | */ | |
197 | QStringList QCategoryAxis::categoriesLabels() |
|
198 | QStringList QCategoryAxis::categoriesLabels() | |
198 | { |
|
199 | { | |
199 | Q_D(QCategoryAxis); |
|
200 | Q_D(QCategoryAxis); | |
200 | return d->m_categories; |
|
201 | return d->m_categories; | |
201 | } |
|
202 | } | |
202 |
|
203 | |||
203 | /*! |
|
204 | /*! | |
204 | Returns number of intervals. |
|
205 | Returns number of intervals. | |
205 | */ |
|
206 | */ | |
206 | int QCategoryAxis::count() const |
|
207 | int QCategoryAxis::count() const | |
207 | { |
|
208 | { | |
208 | Q_D(const QCategoryAxis); |
|
209 | Q_D(const QCategoryAxis); | |
209 | return d->m_categories.count(); |
|
210 | return d->m_categories.count(); | |
210 | } |
|
211 | } | |
211 |
|
212 | |||
212 | /*! |
|
213 | /*! | |
213 | Returns the type of the axis |
|
214 | Returns the type of the axis | |
214 | */ |
|
215 | */ | |
215 | QAbstractAxis::AxisType QCategoryAxis::type() const |
|
216 | QAbstractAxis::AxisType QCategoryAxis::type() const | |
216 | { |
|
217 | { | |
217 | return QAbstractAxis::AxisTypeCategory; |
|
218 | return QAbstractAxis::AxisTypeCategory; | |
218 | } |
|
219 | } | |
219 |
|
220 | |||
220 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
221 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
221 |
|
222 | |||
222 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q): |
|
223 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q): | |
223 | QValueAxisPrivate(q), |
|
224 | QValueAxisPrivate(q), | |
224 | m_categoryMinimum(0) |
|
225 | m_categoryMinimum(0) | |
225 | { |
|
226 | { | |
226 |
|
227 | |||
227 | } |
|
228 | } | |
228 |
|
229 | |||
229 | QCategoryAxisPrivate::~QCategoryAxisPrivate() |
|
230 | QCategoryAxisPrivate::~QCategoryAxisPrivate() | |
230 | { |
|
231 | { | |
231 |
|
232 | |||
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 | int QCategoryAxisPrivate::ticksCount() const |
|
235 | int QCategoryAxisPrivate::ticksCount() const | |
235 | { |
|
236 | { | |
236 | return m_categories.count() + 1; |
|
237 | return m_categories.count() + 1; | |
237 | } |
|
238 | } | |
238 |
|
239 | |||
239 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
240 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
240 | { |
|
241 | { | |
241 | Q_UNUSED(count); |
|
242 | Q_UNUSED(count); | |
242 | Q_UNUSED(min); |
|
243 | Q_UNUSED(min); | |
243 | Q_UNUSED(max); |
|
244 | Q_UNUSED(max); | |
244 | //m_min = min; |
|
245 | //m_min = min; | |
245 | //m_max = max; |
|
246 | //m_max = max; | |
246 | } |
|
247 | } | |
247 |
|
248 | |||
248 | ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
249 | ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter) | |
249 | { |
|
250 | { | |
250 | Q_Q(QCategoryAxis); |
|
251 | Q_Q(QCategoryAxis); | |
251 | if(m_orientation == Qt::Vertical){ |
|
252 | if(m_orientation == Qt::Vertical){ | |
252 | return new ChartCategoryAxisY(q,presenter); |
|
253 | return new ChartCategoryAxisY(q,presenter); | |
253 | }else{ |
|
254 | }else{ | |
254 | return new ChartCategoryAxisX(q,presenter); |
|
255 | return new ChartCategoryAxisX(q,presenter); | |
255 | } |
|
256 | } | |
256 | } |
|
257 | } | |
257 |
|
258 | |||
258 | #include "moc_qcategoryaxis.cpp" |
|
259 | #include "moc_qcategoryaxis.cpp" | |
259 | #include "moc_qcategoryaxis_p.cpp" |
|
260 | #include "moc_qcategoryaxis_p.cpp" | |
260 |
|
261 | |||
261 | QTCOMMERCIALCHART_END_NAMESPACE |
|
262 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,408 +1,409 | |||||
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 "qvalueaxis.h" |
|
21 | #include "qvalueaxis.h" | |
22 | #include "qvalueaxis_p.h" |
|
22 | #include "qvalueaxis_p.h" | |
23 | #include "chartvalueaxisx_p.h" |
|
23 | #include "chartvalueaxisx_p.h" | |
24 | #include "chartvalueaxisy_p.h" |
|
24 | #include "chartvalueaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 | /*! |
|
31 | /*! | |
32 | \class QValueAxis |
|
32 | \class QValueAxis | |
33 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
33 | \brief The QValueAxis class is used for manipulating chart's axis. | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
37 | Values of axis are drawn to position of ticks |
|
37 | Values of axis are drawn to position of ticks | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \qmlclass ValueAxis QValueAxis |
|
41 | \qmlclass ValueAxis QValueAxis | |
|
42 | \inherits AbstractAxis | |||
42 | \brief The ValueAxis element is used for manipulating chart's axes |
|
43 | \brief The ValueAxis element is used for manipulating chart's axes | |
43 |
|
44 | |||
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Values of axis are drawn to position of ticks |
|
46 | Values of axis are drawn to position of ticks | |
46 |
|
47 | |||
47 | To access Axes you can use ChartView API. For example: |
|
48 | To access Axes you can use ChartView API. For example: | |
48 | \code |
|
49 | \code | |
49 | ChartView { |
|
50 | ChartView { | |
50 | ValueAxis { |
|
51 | ValueAxis { | |
51 | id: xAxis |
|
52 | id: xAxis | |
52 | min: 0 |
|
53 | min: 0 | |
53 | max: 10 |
|
54 | max: 10 | |
54 | } |
|
55 | } | |
55 | // Add a few series... |
|
56 | // Add a few series... | |
56 | } |
|
57 | } | |
57 | \endcode |
|
58 | \endcode | |
58 | */ |
|
59 | */ | |
59 |
|
60 | |||
60 | /*! |
|
61 | /*! | |
61 | \property QValueAxis::min |
|
62 | \property QValueAxis::min | |
62 | Defines the minimum value on the axis. |
|
63 | Defines the minimum value on the axis. | |
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
64 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
64 | */ |
|
65 | */ | |
65 | /*! |
|
66 | /*! | |
66 | \qmlproperty real ValueAxis::min |
|
67 | \qmlproperty real ValueAxis::min | |
67 | Defines the minimum value on the axis. |
|
68 | Defines the minimum value on the axis. | |
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
69 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
69 | */ |
|
70 | */ | |
70 |
|
71 | |||
71 | /*! |
|
72 | /*! | |
72 | \property QValueAxis::max |
|
73 | \property QValueAxis::max | |
73 | Defines the maximum value on the axis. |
|
74 | Defines the maximum value on the axis. | |
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
75 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
75 | */ |
|
76 | */ | |
76 | /*! |
|
77 | /*! | |
77 | \qmlproperty real ValueAxis::max |
|
78 | \qmlproperty real ValueAxis::max | |
78 | Defines the maximum value on the axis. |
|
79 | Defines the maximum value on the axis. | |
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
80 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
80 | */ |
|
81 | */ | |
81 |
|
82 | |||
82 | /*! |
|
83 | /*! | |
83 | \property QValueAxis::labelFormat |
|
84 | \property QValueAxis::labelFormat | |
84 | Defines the label format for the axis. |
|
85 | Defines the label format for the axis. | |
85 | See QString::sprintf() for the details. |
|
86 | See QString::sprintf() for the details. | |
86 | */ |
|
87 | */ | |
87 | /*! |
|
88 | /*! | |
88 | \qmlproperty real ValueAxis::labelFormat |
|
89 | \qmlproperty real ValueAxis::labelFormat | |
89 | Defines the label format for the axis. |
|
90 | Defines the label format for the axis. | |
90 | See QString::sprintf() for the details. |
|
91 | See QString::sprintf() for the details. | |
91 | */ |
|
92 | */ | |
92 |
|
93 | |||
93 | /*! |
|
94 | /*! | |
94 | \fn void QValueAxis::minChanged(qreal min) |
|
95 | \fn void QValueAxis::minChanged(qreal min) | |
95 | Axis emits signal when \a min of axis has changed. |
|
96 | Axis emits signal when \a min of axis has changed. | |
96 | */ |
|
97 | */ | |
97 | /*! |
|
98 | /*! | |
98 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
99 | \qmlsignal ValueAxis::onMinChanged(real min) | |
99 | Axis emits signal when \a min of axis has changed. |
|
100 | Axis emits signal when \a min of axis has changed. | |
100 | */ |
|
101 | */ | |
101 |
|
102 | |||
102 | /*! |
|
103 | /*! | |
103 | \fn void QValueAxis::maxChanged(qreal max) |
|
104 | \fn void QValueAxis::maxChanged(qreal max) | |
104 | Axis emits signal when \a max of axis has changed. |
|
105 | Axis emits signal when \a max of axis has changed. | |
105 | */ |
|
106 | */ | |
106 | /*! |
|
107 | /*! | |
107 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
108 | \qmlsignal ValueAxis::onMaxChanged(real max) | |
108 | Axis emits signal when \a max of axis has changed. |
|
109 | Axis emits signal when \a max of axis has changed. | |
109 | */ |
|
110 | */ | |
110 |
|
111 | |||
111 | /*! |
|
112 | /*! | |
112 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
113 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) | |
113 | Axis emits signal when \a min or \a max of axis has changed. |
|
114 | Axis emits signal when \a min or \a max of axis has changed. | |
114 | */ |
|
115 | */ | |
115 |
|
116 | |||
116 | /*! |
|
117 | /*! | |
117 | \property QValueAxis::tickCount |
|
118 | \property QValueAxis::tickCount | |
118 | The number of tick marks for the axis. |
|
119 | The number of tick marks for the axis. | |
119 | */ |
|
120 | */ | |
120 |
|
121 | |||
121 | /*! |
|
122 | /*! | |
122 | \qmlproperty int ValueAxis::tickCount |
|
123 | \qmlproperty int ValueAxis::tickCount | |
123 | The number of tick marks for the axis. |
|
124 | The number of tick marks for the axis. | |
124 | */ |
|
125 | */ | |
125 |
|
126 | |||
126 | /*! |
|
127 | /*! | |
127 | \property QValueAxis::niceNumbersEnabled |
|
128 | \property QValueAxis::niceNumbersEnabled | |
128 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
129 | Whether the nice numbers algorithm is enabled or not for the axis. | |
129 | */ |
|
130 | */ | |
130 |
|
131 | |||
131 | /*! |
|
132 | /*! | |
132 | \qmlproperty bool ValueAxis::niceNumbersEnabled |
|
133 | \qmlproperty bool ValueAxis::niceNumbersEnabled | |
133 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
134 | Whether the nice numbers algorithm is enabled or not for the axis. | |
134 | */ |
|
135 | */ | |
135 |
|
136 | |||
136 | /*! |
|
137 | /*! | |
137 | Constructs an axis object which is a child of \a parent. |
|
138 | Constructs an axis object which is a child of \a parent. | |
138 | */ |
|
139 | */ | |
139 | QValueAxis::QValueAxis(QObject *parent) : |
|
140 | QValueAxis::QValueAxis(QObject *parent) : | |
140 | QAbstractAxis(*new QValueAxisPrivate(this),parent) |
|
141 | QAbstractAxis(*new QValueAxisPrivate(this),parent) | |
141 | { |
|
142 | { | |
142 |
|
143 | |||
143 | } |
|
144 | } | |
144 |
|
145 | |||
145 | /*! |
|
146 | /*! | |
146 | \internal |
|
147 | \internal | |
147 | */ |
|
148 | */ | |
148 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
149 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
149 | { |
|
150 | { | |
150 |
|
151 | |||
151 | } |
|
152 | } | |
152 |
|
153 | |||
153 | /*! |
|
154 | /*! | |
154 | Destroys the object |
|
155 | Destroys the object | |
155 | */ |
|
156 | */ | |
156 | QValueAxis::~QValueAxis() |
|
157 | QValueAxis::~QValueAxis() | |
157 | { |
|
158 | { | |
158 | Q_D(QValueAxis); |
|
159 | Q_D(QValueAxis); | |
159 | if(d->m_dataset) { |
|
160 | if(d->m_dataset) { | |
160 | d->m_dataset->removeAxis(this); |
|
161 | d->m_dataset->removeAxis(this); | |
161 | } |
|
162 | } | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | void QValueAxis::setMin(qreal min) |
|
165 | void QValueAxis::setMin(qreal min) | |
165 | { |
|
166 | { | |
166 | Q_D(QValueAxis); |
|
167 | Q_D(QValueAxis); | |
167 | setRange(min, qMax(d->m_max, min)); |
|
168 | setRange(min, qMax(d->m_max, min)); | |
168 | } |
|
169 | } | |
169 |
|
170 | |||
170 | qreal QValueAxis::min() const |
|
171 | qreal QValueAxis::min() const | |
171 | { |
|
172 | { | |
172 | Q_D(const QValueAxis); |
|
173 | Q_D(const QValueAxis); | |
173 | return d->m_min; |
|
174 | return d->m_min; | |
174 | } |
|
175 | } | |
175 |
|
176 | |||
176 | void QValueAxis::setMax(qreal max) |
|
177 | void QValueAxis::setMax(qreal max) | |
177 | { |
|
178 | { | |
178 | Q_D(QValueAxis); |
|
179 | Q_D(QValueAxis); | |
179 | setRange(qMin(d->m_min, max), max); |
|
180 | setRange(qMin(d->m_min, max), max); | |
180 | } |
|
181 | } | |
181 |
|
182 | |||
182 | qreal QValueAxis::max() const |
|
183 | qreal QValueAxis::max() const | |
183 | { |
|
184 | { | |
184 | Q_D(const QValueAxis); |
|
185 | Q_D(const QValueAxis); | |
185 | return d->m_max; |
|
186 | return d->m_max; | |
186 | } |
|
187 | } | |
187 |
|
188 | |||
188 | /*! |
|
189 | /*! | |
189 | Sets range from \a min to \a max on the axis. |
|
190 | Sets range from \a min to \a max on the axis. | |
190 | If min is greater than max then this function returns without making any changes. |
|
191 | If min is greater than max then this function returns without making any changes. | |
191 | */ |
|
192 | */ | |
192 | void QValueAxis::setRange(qreal min, qreal max) |
|
193 | void QValueAxis::setRange(qreal min, qreal max) | |
193 | { |
|
194 | { | |
194 | Q_D(QValueAxis); |
|
195 | Q_D(QValueAxis); | |
195 | bool changed = false; |
|
196 | bool changed = false; | |
196 |
|
197 | |||
197 | if (min > max) return; |
|
198 | if (min > max) return; | |
198 |
|
199 | |||
199 | if(d->m_niceNumbers) { |
|
200 | if(d->m_niceNumbers) { | |
200 | int ticks = d->m_tickCount; |
|
201 | int ticks = d->m_tickCount; | |
201 | d->looseNiceNumbers(min, max, ticks); |
|
202 | d->looseNiceNumbers(min, max, ticks); | |
202 | if(ticks!=d->m_tickCount) setTickCount(ticks); |
|
203 | if(ticks!=d->m_tickCount) setTickCount(ticks); | |
203 | } |
|
204 | } | |
204 |
|
205 | |||
205 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
206 | if (!qFuzzyIsNull(d->m_min - min)) { | |
206 | d->m_min = min; |
|
207 | d->m_min = min; | |
207 | changed = true; |
|
208 | changed = true; | |
208 | emit minChanged(min); |
|
209 | emit minChanged(min); | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
212 | if (!qFuzzyIsNull(d->m_max - max)) { | |
212 | d->m_max = max; |
|
213 | d->m_max = max; | |
213 | changed = true; |
|
214 | changed = true; | |
214 | emit maxChanged(max); |
|
215 | emit maxChanged(max); | |
215 | } |
|
216 | } | |
216 |
|
217 | |||
217 | if (changed) { |
|
218 | if (changed) { | |
218 | emit rangeChanged(min,max); |
|
219 | emit rangeChanged(min,max); | |
219 | d->emitUpdated(); |
|
220 | d->emitUpdated(); | |
220 | } |
|
221 | } | |
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | /*! |
|
224 | /*! | |
224 | Sets \a count for ticks on the axis. |
|
225 | Sets \a count for ticks on the axis. | |
225 | */ |
|
226 | */ | |
226 | void QValueAxis::setTickCount(int count) |
|
227 | void QValueAxis::setTickCount(int count) | |
227 | { |
|
228 | { | |
228 | Q_D(QValueAxis); |
|
229 | Q_D(QValueAxis); | |
229 | if (d->m_tickCount != count && count >=2) { |
|
230 | if (d->m_tickCount != count && count >=2) { | |
230 | d->m_tickCount = count; |
|
231 | d->m_tickCount = count; | |
231 | d->emitUpdated(); |
|
232 | d->emitUpdated(); | |
232 | } |
|
233 | } | |
233 | } |
|
234 | } | |
234 |
|
235 | |||
235 | /*! |
|
236 | /*! | |
236 | \fn int QValueAxis::tickCount() const |
|
237 | \fn int QValueAxis::tickCount() const | |
237 | Return number of ticks on the axis |
|
238 | Return number of ticks on the axis | |
238 | */ |
|
239 | */ | |
239 | int QValueAxis::tickCount() const |
|
240 | int QValueAxis::tickCount() const | |
240 | { |
|
241 | { | |
241 | Q_D(const QValueAxis); |
|
242 | Q_D(const QValueAxis); | |
242 | return d->m_tickCount; |
|
243 | return d->m_tickCount; | |
243 | } |
|
244 | } | |
244 |
|
245 | |||
245 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
246 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
246 | { |
|
247 | { | |
247 | Q_D(QValueAxis); |
|
248 | Q_D(QValueAxis); | |
248 | if (d->m_niceNumbers != enable){ |
|
249 | if (d->m_niceNumbers != enable){ | |
249 | d->m_niceNumbers = enable; |
|
250 | d->m_niceNumbers = enable; | |
250 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { |
|
251 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { | |
251 | setRange(d->m_min,d->m_max); |
|
252 | setRange(d->m_min,d->m_max); | |
252 | } |
|
253 | } | |
253 | } |
|
254 | } | |
254 | } |
|
255 | } | |
255 |
|
256 | |||
256 | bool QValueAxis::niceNumbersEnabled() const |
|
257 | bool QValueAxis::niceNumbersEnabled() const | |
257 | { |
|
258 | { | |
258 | Q_D(const QValueAxis); |
|
259 | Q_D(const QValueAxis); | |
259 | return d->m_niceNumbers; |
|
260 | return d->m_niceNumbers; | |
260 | } |
|
261 | } | |
261 |
|
262 | |||
262 | void QValueAxis::setLabelFormat(const QString &format) |
|
263 | void QValueAxis::setLabelFormat(const QString &format) | |
263 | { |
|
264 | { | |
264 | Q_D(QValueAxis); |
|
265 | Q_D(QValueAxis); | |
265 | d->m_format = format; |
|
266 | d->m_format = format; | |
266 | } |
|
267 | } | |
267 |
|
268 | |||
268 | QString QValueAxis::labelFormat() const |
|
269 | QString QValueAxis::labelFormat() const | |
269 | { |
|
270 | { | |
270 | Q_D(const QValueAxis); |
|
271 | Q_D(const QValueAxis); | |
271 | return d->m_format; |
|
272 | return d->m_format; | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | /*! |
|
275 | /*! | |
275 | Returns the type of the axis |
|
276 | Returns the type of the axis | |
276 | */ |
|
277 | */ | |
277 | QAbstractAxis::AxisType QValueAxis::type() const |
|
278 | QAbstractAxis::AxisType QValueAxis::type() const | |
278 | { |
|
279 | { | |
279 | return AxisTypeValue; |
|
280 | return AxisTypeValue; | |
280 | } |
|
281 | } | |
281 |
|
282 | |||
282 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
283 |
|
284 | |||
284 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): |
|
285 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): | |
285 | QAbstractAxisPrivate(q), |
|
286 | QAbstractAxisPrivate(q), | |
286 | m_min(0), |
|
287 | m_min(0), | |
287 | m_max(0), |
|
288 | m_max(0), | |
288 | m_tickCount(5), |
|
289 | m_tickCount(5), | |
289 | m_niceNumbers(false), |
|
290 | m_niceNumbers(false), | |
290 | m_format("%g") |
|
291 | m_format("%g") | |
291 | { |
|
292 | { | |
292 |
|
293 | |||
293 | } |
|
294 | } | |
294 |
|
295 | |||
295 | QValueAxisPrivate::~QValueAxisPrivate() |
|
296 | QValueAxisPrivate::~QValueAxisPrivate() | |
296 | { |
|
297 | { | |
297 |
|
298 | |||
298 | } |
|
299 | } | |
299 |
|
300 | |||
300 | void QValueAxisPrivate::handleDomainUpdated() |
|
301 | void QValueAxisPrivate::handleDomainUpdated() | |
301 | { |
|
302 | { | |
302 | Q_Q(QValueAxis); |
|
303 | Q_Q(QValueAxis); | |
303 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
304 | Domain* domain = qobject_cast<Domain*>(sender()); | |
304 | Q_ASSERT(domain); |
|
305 | Q_ASSERT(domain); | |
305 |
|
306 | |||
306 | if(orientation()==Qt::Horizontal){ |
|
307 | if(orientation()==Qt::Horizontal){ | |
307 | q->setRange(domain->minX(),domain->maxX()); |
|
308 | q->setRange(domain->minX(),domain->maxX()); | |
308 | }else if(orientation()==Qt::Vertical){ |
|
309 | }else if(orientation()==Qt::Vertical){ | |
309 | q->setRange(domain->minY(),domain->maxY()); |
|
310 | q->setRange(domain->minY(),domain->maxY()); | |
310 | } |
|
311 | } | |
311 | } |
|
312 | } | |
312 |
|
313 | |||
313 |
|
314 | |||
314 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
315 | void QValueAxisPrivate::setMin(const QVariant &min) | |
315 | { |
|
316 | { | |
316 | Q_Q(QValueAxis); |
|
317 | Q_Q(QValueAxis); | |
317 | bool ok; |
|
318 | bool ok; | |
318 | qreal value = min.toReal(&ok); |
|
319 | qreal value = min.toReal(&ok); | |
319 | if(ok) q->setMin(value); |
|
320 | if(ok) q->setMin(value); | |
320 | } |
|
321 | } | |
321 |
|
322 | |||
322 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
323 | void QValueAxisPrivate::setMax(const QVariant &max) | |
323 | { |
|
324 | { | |
324 |
|
325 | |||
325 | Q_Q(QValueAxis); |
|
326 | Q_Q(QValueAxis); | |
326 | bool ok; |
|
327 | bool ok; | |
327 | qreal value = max.toReal(&ok); |
|
328 | qreal value = max.toReal(&ok); | |
328 | if(ok) q->setMax(value); |
|
329 | if(ok) q->setMax(value); | |
329 | } |
|
330 | } | |
330 |
|
331 | |||
331 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
332 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
332 | { |
|
333 | { | |
333 | Q_Q(QValueAxis); |
|
334 | Q_Q(QValueAxis); | |
334 | bool ok1; |
|
335 | bool ok1; | |
335 | bool ok2; |
|
336 | bool ok2; | |
336 | qreal value1 = min.toReal(&ok1); |
|
337 | qreal value1 = min.toReal(&ok1); | |
337 | qreal value2 = max.toReal(&ok2); |
|
338 | qreal value2 = max.toReal(&ok2); | |
338 | if(ok1&&ok2) q->setRange(value1,value2); |
|
339 | if(ok1&&ok2) q->setRange(value1,value2); | |
339 | } |
|
340 | } | |
340 |
|
341 | |||
341 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
342 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) | |
342 | { |
|
343 | { | |
343 | Q_Q(QValueAxis); |
|
344 | Q_Q(QValueAxis); | |
344 | if(m_orientation == Qt::Vertical){ |
|
345 | if(m_orientation == Qt::Vertical){ | |
345 | return new ChartValueAxisY(q,presenter); |
|
346 | return new ChartValueAxisY(q,presenter); | |
346 | }else{ |
|
347 | }else{ | |
347 | return new ChartValueAxisX(q,presenter); |
|
348 | return new ChartValueAxisX(q,presenter); | |
348 | } |
|
349 | } | |
349 |
|
350 | |||
350 | } |
|
351 | } | |
351 |
|
352 | |||
352 | void QValueAxisPrivate::intializeDomain(Domain* domain) |
|
353 | void QValueAxisPrivate::intializeDomain(Domain* domain) | |
353 | { |
|
354 | { | |
354 | Q_Q(QValueAxis); |
|
355 | Q_Q(QValueAxis); | |
355 | if(qFuzzyCompare(m_max,m_min)) { |
|
356 | if(qFuzzyCompare(m_max,m_min)) { | |
356 | if(m_orientation==Qt::Vertical){ |
|
357 | if(m_orientation==Qt::Vertical){ | |
357 | q->setRange(domain->minY(),domain->maxY()); |
|
358 | q->setRange(domain->minY(),domain->maxY()); | |
358 | }else{ |
|
359 | }else{ | |
359 | q->setRange(domain->minX(), domain->maxX()); |
|
360 | q->setRange(domain->minX(), domain->maxX()); | |
360 | } |
|
361 | } | |
361 | } else { |
|
362 | } else { | |
362 | if(m_orientation==Qt::Vertical){ |
|
363 | if(m_orientation==Qt::Vertical){ | |
363 | domain->setRangeY(m_min, m_max); |
|
364 | domain->setRangeY(m_min, m_max); | |
364 | }else{ |
|
365 | }else{ | |
365 | domain->setRangeX(m_min, m_max); |
|
366 | domain->setRangeX(m_min, m_max); | |
366 | } |
|
367 | } | |
367 | } |
|
368 | } | |
368 | } |
|
369 | } | |
369 |
|
370 | |||
370 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
371 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |
371 |
|
372 | |||
372 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
373 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const | |
373 | { |
|
374 | { | |
374 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
375 | qreal range = niceNumber(max-min,true); //range with ceiling | |
375 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
376 | qreal step = niceNumber(range/(ticksCount-1),false); | |
376 | min = qFloor(min/step); |
|
377 | min = qFloor(min/step); | |
377 | max = qCeil(max/step); |
|
378 | max = qCeil(max/step); | |
378 | ticksCount = int(max-min) +1; |
|
379 | ticksCount = int(max-min) +1; | |
379 | min*=step; |
|
380 | min*=step; | |
380 | max*=step; |
|
381 | max*=step; | |
381 | } |
|
382 | } | |
382 |
|
383 | |||
383 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
384 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |
384 |
|
385 | |||
385 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const |
|
386 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const | |
386 | { |
|
387 | { | |
387 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
388 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |
388 | qreal q = x/z;//q<10 && q>=1; |
|
389 | qreal q = x/z;//q<10 && q>=1; | |
389 |
|
390 | |||
390 | if(ceiling) { |
|
391 | if(ceiling) { | |
391 | if(q <= 1.0) q=1; |
|
392 | if(q <= 1.0) q=1; | |
392 | else if(q <= 2.0) q=2; |
|
393 | else if(q <= 2.0) q=2; | |
393 | else if(q <= 5.0) q=5; |
|
394 | else if(q <= 5.0) q=5; | |
394 | else q=10; |
|
395 | else q=10; | |
395 | } |
|
396 | } | |
396 | else { |
|
397 | else { | |
397 | if(q < 1.5) q=1; |
|
398 | if(q < 1.5) q=1; | |
398 | else if(q < 3.0) q=2; |
|
399 | else if(q < 3.0) q=2; | |
399 | else if(q < 7.0) q=5; |
|
400 | else if(q < 7.0) q=5; | |
400 | else q=10; |
|
401 | else q=10; | |
401 | } |
|
402 | } | |
402 | return q*z; |
|
403 | return q*z; | |
403 | } |
|
404 | } | |
404 |
|
405 | |||
405 | #include "moc_qvalueaxis.cpp" |
|
406 | #include "moc_qvalueaxis.cpp" | |
406 | #include "moc_qvalueaxis_p.cpp" |
|
407 | #include "moc_qvalueaxis_p.cpp" | |
407 |
|
408 | |||
408 | QTCOMMERCIALCHART_END_NAMESPACE |
|
409 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now