##// END OF EJS Templates
Fix documentation appearance...
Titta Heikkala -
r2750:0968736234d9
parent child
Show More
@@ -1,343 +1,331
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 #include <QtCharts/QCategoryAxis>
20 20 #include <private/qcategoryaxis_p.h>
21 21 #include <private/chartcategoryaxisx_p.h>
22 22 #include <private/chartcategoryaxisy_p.h>
23 23 #include <private/polarchartcategoryaxisangular_p.h>
24 24 #include <private/polarchartcategoryaxisradial_p.h>
25 25 #include <QtCharts/QChart>
26 26 #include <QtCore/QtMath>
27 27 #include <QtCore/QDebug>
28 28
29 29 QT_CHARTS_BEGIN_NAMESPACE
30 30 /*!
31 31 \class QCategoryAxis
32 32 \inmodule Qt Charts
33 33 \brief The QCategoryAxis class allows putting a named ranges on the axis.
34 34 \mainclass
35 35
36 36 This class can be used when the underlying data needs to be given extra meaning.
37 37 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
38 38
39 39 Example code on how to use QCategoryAxis:
40 \table
41 \row
42 \li \br
43 \br
44 \code
45 QChartView *chartView = new QChartView;
46 QLineSeries *series = new QLineSeries;
47 // ...
48 chartView->chart()->addSeries(series);
49
50 QCategoryAxis *axisY = new QCategoryAxis;
51 axisY->setMin(0);
52 axisY->setMax(52);
53 axisY->setStartValue(15);
54 axisY->append("First", 20);
55 axisY->append("Second", 37);
56 axisY->append("Third", 52);
57 chartView->chart()->setAxisY(axisY, series);
58 \endcode
59 \li \br
60 \inlineimage api_category_axis.png
61 \endtable
40 \image api_category_axis.png
41 \code
42 QChartView *chartView = new QChartView;
43 QLineSeries *series = new QLineSeries;
44 // ...
45 chartView->chart()->addSeries(series);
46
47 QCategoryAxis *axisY = new QCategoryAxis;
48 axisY->setMin(0);
49 axisY->setMax(52);
50 axisY->setStartValue(15);
51 axisY->append("First", 20);
52 axisY->append("Second", 37);
53 axisY->append("Third", 52);
54 chartView->chart()->setAxisY(axisY, series);
55 \endcode
62 56 */
63 57 /*!
64 58 \qmltype CategoryAxis
65 59 \instantiates QCategoryAxis
66 60 \inqmlmodule QtCharts
67 61
68 62 \inherits AbstractAxis
69 63 \brief CategoryAxis allows putting a named ranges on the axis.
70 64
71 65 For example:
72 \table
73 \row
74 \li \br
75 \br
76 \br
77 \snippet qmlaxes/qml/qmlaxes/View3.qml 1
78 \li \inlineimage examples_qmlaxes3.png
79 \endtable
66 \image examples_qmlaxes3.png
67 \snippet qmlaxes/qml/qmlaxes/View3.qml 1
80 68 */
81 69
82 70 /*!
83 71 \property QCategoryAxis::startValue
84 72 Defines the low end of the first category on the axis.
85 73 */
86 74 /*!
87 75 \qmlproperty int CategoryAxis::startValue
88 76 Defines the low end of the first category on the axis.
89 77 */
90 78
91 79 /*!
92 80 \property QCategoryAxis::count
93 81 The count of categories.
94 82 */
95 83 /*!
96 84 \qmlproperty int CategoryAxis::count
97 85 The count of categories.
98 86 */
99 87
100 88 /*!
101 89 \property QCategoryAxis::categoriesLabels
102 90 The category labels as a string list.
103 91 */
104 92 /*!
105 93 \qmlproperty StringList CategoryAxis::categoriesLabels
106 94 The category labels as a list of strings.
107 95 */
108 96
109 97 /*!
110 98 \fn void QCategoryAxis::categoriesChanged()
111 99 Axis emits signal when the categories of the axis have changed.
112 100 */
113 101
114 102
115 103 /*!
116 104 Constructs an axis object which is a child of \a parent.
117 105 */
118 106 QCategoryAxis::QCategoryAxis(QObject *parent):
119 107 QValueAxis(*new QCategoryAxisPrivate(this), parent)
120 108 {
121 109 }
122 110
123 111 /*!
124 112 Destroys the object
125 113 */
126 114 QCategoryAxis::~QCategoryAxis()
127 115 {
128 116 Q_D(QCategoryAxis);
129 117 if (d->m_chart)
130 118 d->m_chart->removeAxis(this);
131 119 }
132 120
133 121 /*!
134 122 \internal
135 123 */
136 124 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent): QValueAxis(d, parent)
137 125 {
138 126
139 127 }
140 128
141 129 /*!
142 130 \qmlmethod CategoryAxis::append(string label, real endValue)
143 131 Appends new category to the axis with an \a label. Category label has to be unique.
144 132 Parameter \a endValue specifies the high end limit of the category.
145 133 It has to be greater than the high end limit of the previous category.
146 134 Otherwise the method returns without adding a new category.
147 135 */
148 136 /*!
149 137 Appends new category to the axis with an \a categoryLabel.
150 138 Category label has to be unique.
151 139 Parameter \a categoryEndValue specifies the high end limit of the category.
152 140 It has to be greater than the high end limit of the previous category.
153 141 Otherwise the method returns without adding a new category.
154 142 */
155 143 void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue)
156 144 {
157 145 Q_D(QCategoryAxis);
158 146
159 147 if (!d->m_categories.contains(categoryLabel)) {
160 148 if (d->m_categories.isEmpty()) {
161 149 Range range(d->m_categoryMinimum, categoryEndValue);
162 150 d->m_categoriesMap.insert(categoryLabel, range);
163 151 d->m_categories.append(categoryLabel);
164 152 emit categoriesChanged();
165 153 } else if (categoryEndValue > endValue(d->m_categories.last())) {
166 154 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
167 155 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
168 156 d->m_categories.append(categoryLabel);
169 157 emit categoriesChanged();
170 158 }
171 159 }
172 160 }
173 161
174 162 /*!
175 163 Sets \a min to be the low end limit of the first category on the axis.
176 164 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.
177 165 Otherwise nothing is done.
178 166 */
179 167 void QCategoryAxis::setStartValue(qreal min)
180 168 {
181 169 Q_D(QCategoryAxis);
182 170 if (d->m_categories.isEmpty()) {
183 171 d->m_categoryMinimum = min;
184 172 emit categoriesChanged();
185 173 } else {
186 174 Range range = d->m_categoriesMap.value(d->m_categories.first());
187 175 if (min < range.second) {
188 176 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
189 177 emit categoriesChanged();
190 178 }
191 179 }
192 180 }
193 181
194 182 /*!
195 183 Returns the low end limit of the category specified by an \a categoryLabel
196 184 */
197 185 qreal QCategoryAxis::startValue(const QString &categoryLabel) const
198 186 {
199 187 Q_D(const QCategoryAxis);
200 188 if (categoryLabel.isEmpty())
201 189 return d->m_categoryMinimum;
202 190 return d->m_categoriesMap.value(categoryLabel).first;
203 191 }
204 192
205 193 /*!
206 194 Returns the high end limit of the interval specified by an \a categoryLabel
207 195 */
208 196 qreal QCategoryAxis::endValue(const QString &categoryLabel) const
209 197 {
210 198 Q_D(const QCategoryAxis);
211 199 return d->m_categoriesMap.value(categoryLabel).second;
212 200 }
213 201
214 202 /*!
215 203 \qmlmethod CategoryAxis::remove(string label)
216 204 Removes a category specified by the \a label from the axis
217 205 */
218 206 /*!
219 207 Removes an interval specified by the \a categoryLabel from the axis
220 208 */
221 209 void QCategoryAxis::remove(const QString &categoryLabel)
222 210 {
223 211 Q_D(QCategoryAxis);
224 212 int labelIndex = d->m_categories.indexOf(categoryLabel);
225 213
226 214 // check if such label exists
227 215 if (labelIndex != -1) {
228 216 d->m_categories.removeAt(labelIndex);
229 217 d->m_categoriesMap.remove(categoryLabel);
230 218
231 219 // the range of the interval that follows (if exists) needs to be updated
232 220 if (labelIndex < d->m_categories.count()) {
233 221 QString label = d->m_categories.at(labelIndex);
234 222 Range range = d->m_categoriesMap.value(label);
235 223
236 224 // set the range
237 225 if (labelIndex == 0) {
238 226 range.first = d->m_categoryMinimum;
239 227 d->m_categoriesMap.insert(label, range);
240 228 } else {
241 229 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
242 230 d->m_categoriesMap.insert(label, range);
243 231 }
244 232 }
245 233 emit categoriesChanged();
246 234 }
247 235 }
248 236
249 237 /*!
250 238 \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel)
251 239 Replaces \a oldLabel of an existing category with a \a newLabel.
252 240 If the old label does not exist the method returns without making any changes.
253 241 */
254 242 /*!
255 243 Replaces \a oldLabel of an existing category with a \a newLabel
256 244 If the old label does not exist the method returns without making any changes.
257 245 */
258 246 void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabel)
259 247 {
260 248 Q_D(QCategoryAxis);
261 249 int labelIndex = d->m_categories.indexOf(oldLabel);
262 250
263 251 // check if such label exists
264 252 if (labelIndex != -1) {
265 253 d->m_categories.replace(labelIndex, newLabel);
266 254 Range range = d->m_categoriesMap.value(oldLabel);
267 255 d->m_categoriesMap.remove(oldLabel);
268 256 d->m_categoriesMap.insert(newLabel, range);
269 257 emit categoriesChanged();
270 258 }
271 259 }
272 260
273 261 /*!
274 262 Returns the list of the intervals labels
275 263 */
276 264 QStringList QCategoryAxis::categoriesLabels()
277 265 {
278 266 Q_D(QCategoryAxis);
279 267 return d->m_categories;
280 268 }
281 269
282 270 /*!
283 271 Returns number of intervals.
284 272 */
285 273 int QCategoryAxis::count() const
286 274 {
287 275 Q_D(const QCategoryAxis);
288 276 return d->m_categories.count();
289 277 }
290 278
291 279 /*!
292 280 Returns the type of the axis
293 281 */
294 282 QAbstractAxis::AxisType QCategoryAxis::type() const
295 283 {
296 284 return QAbstractAxis::AxisTypeCategory;
297 285 }
298 286
299 287 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
300 288
301 289 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis *q)
302 290 : QValueAxisPrivate(q),
303 291 m_categoryMinimum(0)
304 292 {
305 293
306 294 }
307 295
308 296 QCategoryAxisPrivate::~QCategoryAxisPrivate()
309 297 {
310 298
311 299 }
312 300
313 301 int QCategoryAxisPrivate::ticksCount() const
314 302 {
315 303 return m_categories.count() + 1;
316 304 }
317 305
318 306 void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem *parent)
319 307 {
320 308 Q_Q(QCategoryAxis);
321 309 ChartAxisElement *axis(0);
322 310 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
323 311 if (orientation() == Qt::Vertical)
324 312 axis = new ChartCategoryAxisY(q,parent);
325 313 else if (orientation() == Qt::Horizontal)
326 314 axis = new ChartCategoryAxisX(q,parent);
327 315 }
328 316
329 317 if (m_chart->chartType() == QChart::ChartTypePolar) {
330 318 if (orientation() == Qt::Vertical)
331 319 axis = new PolarChartCategoryAxisRadial(q, parent);
332 320 if (orientation() == Qt::Horizontal)
333 321 axis = new PolarChartCategoryAxisAngular(q, parent);
334 322 }
335 323
336 324 m_item.reset(axis);
337 325 QAbstractAxisPrivate::initializeGraphics(parent);
338 326 }
339 327
340 328 #include "moc_qcategoryaxis.cpp"
341 329 #include "moc_qcategoryaxis_p.cpp"
342 330
343 331 QT_CHARTS_END_NAMESPACE
@@ -1,26 +1,26
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example audio
21 \title Audio example
21 \title Audio Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows the drawing of dynamic data (microphone input).
25 25 \image examples_audio.png
26 26 */
@@ -1,76 +1,76
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example barmodelmapper
21 \title BarModelMapper example
21 \title BarModelMapper Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to use QAbstractItemModel derived model as the data for the bar
25 25 series.
26 26
27 27 \image examples_barmodelmapper.png
28 28
29 29 Let's start by creating an instance of CustomTableModel class.
30 30 The CustomTableModel class is derived from QAbstractTableModel, and it was created for the purpose of this example.
31 31 The constructor of this class populates the model's internal data store with the data required for our chart example.
32 32
33 33 \snippet barmodelmapper/tablewidget.cpp 1
34 34
35 35 We now have a model with data that we would like to display both on the chart and in a QTableView.
36 36 First, we create QTableView and tell it to use the model as a data source. To have the data presented nicely, the minimum width of the table view is set and its headers resize mode changed to stretch.
37 37
38 38 \snippet barmodelmapper/tablewidget.cpp 2
39 39
40 40 Now we need a QChart instance to display the same data on the chart.
41 41 We also enable animations. It makes it easier to see how a modification to the model's data affects the chart.
42 42
43 43 \snippet barmodelmapper/tablewidget.cpp 3
44 44
45 45 The first line of the code below creates new bar series. Variables firstRow and rowCount are used to define a custom model mapping.
46 46 Custom mapping allows to take only part of the data from the model. In this case data from 5 rows starting with the row with the index 3.
47 47 The following three lines create an instance of the QVBarModelMapper class and specify that the data for the bar sets should be taken from the model's columns with indexes from 1 to 4 (inclusive).
48 48 To create a connection between the series and the model we set both of those objects to QVBarModelMapper.
49 49
50 50 Finally the series is added to the chart.
51 51
52 52 \snippet barmodelmapper/tablewidget.cpp 4
53 53
54 54 To show in QTableView which data corresponds with which bar set, this example uses table coloring.
55 55 When series is added to the chart, it is assigned a color based on the currently selected theme.
56 56 Code below extracts that color from the series and uses it to create colored QTableView.
57 57 Coloring of the view is not a part of the QChart functionality.
58 58
59 59 \snippet barmodelmapper/tablewidget.cpp 5
60 60
61 61 We would like to have categories placed on the chart's axis that describe what the data means.
62 62 Next snippet shows how to do that.
63 63
64 64 \snippet barmodelmapper/tablewidget.cpp 6
65 65
66 66 To avoid setting up the QGraphicsScene we use the QChartView class that does it for us. The QChart object pointer is used as a parameter of the QChartView constructor.
67 67 To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set.
68 68
69 69 \snippet barmodelmapper/tablewidget.cpp 7
70 70
71 71 Finally, we place both widgets in a layout and use the layout as the application layout.
72 72
73 73 \snippet barmodelmapper/tablewidget.cpp 8
74 74
75 75 The application is ready. Try modifying the data in the table view and see how it affects the chart.
76 76 */
@@ -1,33 +1,33
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example callout
21 \title Callout example
21 \title Callout Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to draw an additional element (a callout) on top of the chart.
25 25 \image examples_callout.png
26 26
27 27 QChart class provides two methods that map between the scene coordinates and the series domain
28 28 (defined by the axes ranges).
29 29
30 30 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
31 31
32 32 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
33 33 */
@@ -1,33 +1,33
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example chartthemes
21 \title Chart themes example
21 \title Chart Themes Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief The example shows the look and feel of the different built-in themes.
25 25
26 26 This example shows the look and feel of the different built-in themes for all supported chart
27 27 types. In order to give the result a more harmonious look, the background palette of the
28 28 application is customized to the theme selected.
29 29
30 30 \image examples_chartthemes_light.png
31 31 \image examples_chartthemes_brown_sand.png
32 32 \image examples_chartthemes_blue_cerulean.png
33 33 */
@@ -1,63 +1,63
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example donutbreakdown
21 \title Donut chart breakdown example
21 \title Donut Chart Breakdown Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to use create a donut breakdown chart using QPieSeries API.
25 25 \image examples_donutbreakdown.png
26 26
27 27 Let's start by defining some data for the chart.
28 28
29 29 \snippet donutbreakdown/main.cpp 1
30 30
31 31 Then we create a chart where we add the data. Note that this is our own chart derived from QChart.
32 32
33 33 \snippet donutbreakdown/main.cpp 2
34 34
35 35 Our own chart works in such a way that we create a main series in the constructor we create a main series,
36 36 which aggregates the data provided by the breakdown series. This is the piechart in the center.
37 37
38 38 \snippet donutbreakdown/donutbreakdownchart.cpp 1
39 39
40 40 When a breakdown series is added the data is used to create a slice in the main series and the
41 41 breakdown series itself is used to create a segment of a donut positioned so that it is aligned
42 42 with the corresponding slice in the main series.
43 43
44 44 \snippet donutbreakdown/donutbreakdownchart.cpp 2
45 45
46 46 Here's how the start and end angles for the donut segments are calculated.
47 47
48 48 \snippet donutbreakdown/donutbreakdownchart.cpp 3
49 49
50 50 The legend markers are customized to show the breakdown percentage. The markers for the main level slices are hidden.
51 51
52 52 \snippet donutbreakdown/donutbreakdownchart.cpp 4
53 53
54 54 Instead the main level slices show the percentage on the label.
55 55
56 56 \snippet donutbreakdown/mainslice.cpp 1
57 57 \snippet donutbreakdown/mainslice.cpp 2
58 58
59 59 Now that we have our chart defined, we can finally create a QChartView and show the chart.
60 60
61 61 \snippet donutbreakdown/main.cpp 3
62 62
63 63 */
@@ -1,28 +1,28
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example dynamicspline
21 \title Dynamic spline example
21 \title Dynamic Spline Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to draw dynamic data.
25 25
26 26 \image examples_dynamicspline1.png
27 27 \image examples_dynamicspline2.png
28 28 */
@@ -1,58 +1,55
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example legend
21 21 \title Legend Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to detach the legend from the chart and how to attach it back.
25 25
26 26 By default the chart draws the legend inside the same view with the chart. In some cases the
27 27 user may want to draw the legend to somewhere else. To make this possible the legend can be
28 28 detached from the chart. Detaching means that the chart doesn't draw the legend or try to
29 29 change its layout. Detached legend can then be drawn wherever the user wishes, for example,
30 30 in a different graphics scene. The behavior of the legend can be inspected by running the
31 31 legend example.
32 32 In the example we use the bar series where we add or remove the bar sets. The legend reflects
33 33 the changes in series. The legend can be detached or attached back to the chart and its
34 34 alignment can be modified.
35 35 When the legend is detached, it can be resized and positioned freely.
36 36
37 \table
38 \row
39 \li \inlineimage examples_legend_detach.png
40 \li \inlineimage examples_legend_detach2.png
41 \endtable
37 \image examples_legend_detach.png
38 \image examples_legend_detach2.png
42 39
43 40 Here we turn the legend visible and set its alignment to the bottom of the chart.
44 41
45 42 \snippet legend/mainwidget.cpp 1
46 43
47 44 This snippet shows how to detach the legend from the chart. After detaching, we turn its background to visible and set a different color to it. This makes it easier to see how the items inside the legend are arranged in detached mode.
48 45
49 46 \snippet legend/mainwidget.cpp 2
50 47
51 48 Here we attach the legend back to the chart. The background is turned invisible.
52 49
53 50 \snippet legend/mainwidget.cpp 3
54 51
55 52 This shows how we set the detached legend dimensions. After setting the new values, we call update to show changes on screen.
56 53
57 54 \snippet legend/mainwidget.cpp 4
58 55 */
@@ -1,68 +1,68
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example nesteddonuts
21 \title Nested donuts example
21 \title Nested Donuts Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to create a nested donuts chart using the QPieSeries API.
25 25 \image examples_nesteddonuts.png
26 26
27 27 Let's start by creating a QChartView instance and enabling the Antialiasing on it. A QChart object is then obtained from the QChartView instance.
28 28 The legend is disabled and the title of the chart is set. Last line enables the animations of the chart.
29 29
30 30 \snippet nesteddonuts/widget.cpp 1
31 31
32 32 Three variables are defined that will be used to define the donut chart. Min and max size define the relative size of the whole donut.
33 33 minSize is the relative inner size of the smallest donut. maxSize is the relative outer size of the biggest donut.
34 34
35 35 \snippet nesteddonuts/widget.cpp 2
36 36
37 37 The following block of code defines the individual donuts and their slices. First a new QPieSeries object is created.
38 38 The number of slices in each donut is randomized.
39 39 The internal for loop creates the slices with a random value and label same as the value.
40 40 Next the label of the slice is set to be visible and its color is set to white.
41 41 To make the example more interesting the hovered signal of the slice is connected to widget's slot, of which the inner workings are explained later.
42 42 Finally the slice is added to the donut. The donut's size is adjusted to achieve the nesting of the donuts.
43 43 Then the donut is added to the widget's list of donuts and to the chart.
44 44
45 45 \snippet nesteddonuts/widget.cpp 3
46 46
47 47 Finally the widget is placed in a layout used by the application.
48 48
49 49 \snippet nesteddonuts/widget.cpp 4
50 50
51 51 To make the example more interesting the donuts are rotated randomly every 1.25 sec.
52 52
53 53 \snippet nesteddonuts/widget.cpp 5
54 54
55 55 The widget's updatedRotation slot is defined below.
56 56 It goes through all of the donuts and modifies their current rotation by a random value.
57 57
58 58 \snippet nesteddonuts/widget.cpp 6
59 59
60 60 The earlier mentioned explodeSlice slot code is provided below.
61 61 If the slice is set to exploded, then stop the timer that controls the donuts rotation.
62 62 Then the slice's start and end angles are obtained from the slice.
63 63 To highlight the selected slice all the other donuts that lie outward from the one that contains the selected slice
64 64 have their start and end angles modified so that they wouldn't "block" the way for the hightlighted slice.
65 65 If the slice is no longer selected return to the original state.
66 66
67 67 \snippet nesteddonuts/widget.cpp 7
68 68 */
@@ -1,26 +1,26
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example piechartcustomization
21 \title Pie chart customization example
21 \title Pie Chart Customization Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how the look and feel of a pie chart can be customized.
25 25 \image piechart_customization.png
26 26 */
@@ -1,50 +1,41
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example qmlaxes
21 21 \title Qml Axes
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This is a demonstration of how to use axes in your QML application.
25 25
26 \table
27 \row
28 \li \br
29 We begin with a chart that has a line series and a scatter series with random
30 data. Both series use the same axes.
31 \br
32 \br
33 \snippet qmlaxes/qml/qmlaxes/View1.qml 1
34 \li \inlineimage examples_qmlaxes1.png
35 \row
36 \li \br
37 The next example shows a chart with some accurate historical data that makes us to use a DateTimeAxis.
38 \br
39 \br
40 \snippet qmlaxes/qml/qmlaxes/View2.qml 1
41 \li \inlineimage examples_qmlaxes2.png
42 \row
43 \li \br
44 And the final example with a chart that uses a CategoryAxis to make the data easier to understand.
45 \br
46 \br
47 \snippet qmlaxes/qml/qmlaxes/View3.qml 1
48 \li \inlineimage examples_qmlaxes3.png
49 \endtable
26 We begin with a chart that has a line series and a scatter series with random
27 data. Both series use the same axes.
28
29 \image examples_qmlaxes1.png
30 \snippet qmlaxes/qml/qmlaxes/View1.qml 1
31
32 The next example shows a chart with some accurate historical data that makes us to use a DateTimeAxis.
33
34 \image examples_qmlaxes2.png
35 \snippet qmlaxes/qml/qmlaxes/View2.qml 1
36
37 And the final example with a chart that uses a CategoryAxis to make the data easier to understand.
38
39 \image examples_qmlaxes3.png
40 \snippet qmlaxes/qml/qmlaxes/View3.qml 1
50 41 */
@@ -1,143 +1,82
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example qmlchart
21 \title Qml charts example
21 \title Qml Charts Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This basic demonstration shows how to use the different chart types by using qml.
25 25
26 26 Creating each chart type begins with the creation of a ChartView.
27 27
28 \table
29 \row
30 \li \br
31 To create a pie, we use the PieSeries API together with a few PieSlices:
32 \br
33 \br
34 \snippet qmlchart/qml/qmlchart/View1.qml 1
35 \li \inlineimage examples_qmlchart1.png
36 \endtable
37
38 \table
39 \row
40 \li \br
41 To create a chart with a line series:
42 \br
43 \br
44 \snippet qmlchart/qml/qmlchart/View2.qml 1
45 \li \inlineimage examples_qmlchart2.png
46 \endtable
47
48 \table
49 \row
50 \li \br
51 And spline series:
52 \br
53 \br
54 \snippet qmlchart/qml/qmlchart/View3.qml 1
55 \li \inlineimage examples_qmlchart3.png
56 \endtable
57
58 \table
59 \row
60 \li \br
61 Then we create a chart that illustrates the NHL All-Star player selections by using
62 three area series:
63 \br
64 \br
65 \snippet qmlchart/qml/qmlchart/View4.qml 1
66 \dots
67 \li \inlineimage examples_qmlchart4.png
68 \endtable
69
70 \table
71 \row
72 \li \br
73 Then a couple of scatter series:
74 \br
75 \br
76 \snippet qmlchart/qml/qmlchart/View5.qml 1
77 \dots
78 \li \inlineimage examples_qmlchart5.png
79 \endtable
28 To create a pie, we use the PieSeries API together with a few PieSlices:
29
30 \image examples_qmlchart1.png
31 \snippet qmlchart/qml/qmlchart/View1.qml 1
32
33 To create a chart with a line series:
34
35 \image examples_qmlchart2.png
36 \snippet qmlchart/qml/qmlchart/View2.qml 1
37
38 And spline series:
39
40 \image examples_qmlchart3.png
41 \snippet qmlchart/qml/qmlchart/View3.qml 1
42
43 Then we create a chart that illustrates the NHL All-Star player selections by using
44 three area series:
45
46 \image examples_qmlchart4.png
47 \snippet qmlchart/qml/qmlchart/View4.qml 1
48 \dots
49
50 Then a couple of scatter series:
51
52 \image examples_qmlchart5.png
53 \snippet qmlchart/qml/qmlchart/View5.qml 1
54 \dots
80 55
81 56 And a few different bar series:
82 \table
83 \row
84 \li \br
85 \br
86 \br
87 \snippet qmlchart/qml/qmlchart/View6.qml 1
88 \li \inlineimage examples_qmlchart6.png
89 \endtable
90 \table
91 \row
92 \li \br
93 \br
94 \br
95 \snippet qmlchart/qml/qmlchart/View7.qml 1
96 \li \inlineimage examples_qmlchart7.png
97 \endtable
98 \table
99 \row
100 \li \br
101 \br
102 \br
103 \snippet qmlchart/qml/qmlchart/View8.qml 1
104 \li \inlineimage examples_qmlchart8.png
105 \endtable
106 \table
107 \row
108 \li \br
109 \br
110 \br
111 \snippet qmlchart/qml/qmlchart/View9.qml 1
112 \li \inlineimage examples_qmlchart9.png
113 \endtable
114 \table
115 \row
116 \li \br
117 \br
118 \br
119 \snippet qmlchart/qml/qmlchart/View10.qml 1
120 \li \inlineimage examples_qmlchart10.png
121 \endtable
122 \table
123 \row
124 \li \br
125 \br
126 \br
127 \snippet qmlchart/qml/qmlchart/View11.qml 1
128 \li \inlineimage examples_qmlchart11.png
129 \endtable
130
131 \table
132 \row
133 \li \br
134 And finally an example demonstrating how to create a donut chart with two pie
135 series:
136 \br
137 \br
138 \snippet qmlchart/qml/qmlchart/View12.qml 1
139 \li \inlineimage examples_qmlchart12.png
140 \endtable
57
58 \image examples_qmlchart6.png
59 \snippet qmlchart/qml/qmlchart/View6.qml 1
60
61 \image examples_qmlchart7.png
62 \snippet qmlchart/qml/qmlchart/View7.qml 1
63
64 \image examples_qmlchart8.png
65 \snippet qmlchart/qml/qmlchart/View8.qml 1
66
67 \image examples_qmlchart9.png
68 \snippet qmlchart/qml/qmlchart/View9.qml 1
69
70 \image examples_qmlchart10.png
71 \snippet qmlchart/qml/qmlchart/View10.qml 1
72
73 \image examples_qmlchart11.png
74 \snippet qmlchart/qml/qmlchart/View11.qml 1
75
76 And finally an example demonstrating how to create a donut chart with two pie series:
77
78 \image examples_qmlchart12.png
79 \snippet qmlchart/qml/qmlchart/View12.qml 1
141 80
142 81 Additionally, antialiasing is set with the qml property in Qt Quick 2.
143 82 */
@@ -1,61 +1,49
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example qmlcustomlegend
21 21 \title Qml Custom Legend
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows you how to create your own custom legend.
25 25
26 26 This application shows you how to create your own custom legend instead of using the
27 27 built-in legend of ChartView API.
28 28
29 \table
30 \row
31 \li \br
32 The main view of the application shows a stacked area chart. This is how one of
33 \br
34 the stacked areas is created. See ChartViewStacked.qml and AnimatedAreaSeries.qml.
35 \br
36 \br
37 \snippet qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml 1
38 \li \inlineimage examples_qmlcustomlegend1.png
39 \row
40 \li \br
41 Hovering with mouse on top of the legend will highlight the hovered series.
42 \br
43 (see CustomLegend.qml).
44 \br
45 \br
46 \snippet qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 1
47 \snippet qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 2
48 \dots
49 \snippet qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 3
50 \li \inlineimage examples_qmlcustomlegend2.png
51 \row
52 \li \br
53 You can also select one of the stacked areas for a closer look as a line series by
54 \br
55 a mouse click (see ChartViewHighlighted.qml).
56 \br
57 \br
58 \snippet qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml 1
59 \li \inlineimage examples_qmlcustomlegend3.png
60 \endtable
29 The main view of the application shows a stacked area chart. This is how one of
30 the stacked areas is created. See ChartViewStacked.qml and AnimatedAreaSeries.qml.
31
32 \image examples_qmlcustomlegend1.png
33 \snippet qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml 1
34
35 Hovering with mouse on top of the legend will highlight the hovered series.
36 (see CustomLegend.qml).
37
38 \image examples_qmlcustomlegend2.png
39 \snippet qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 1
40 \snippet qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 2
41 \dots
42 \snippet qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 3
43
44 You can also select one of the stacked areas for a closer look as a line series by
45 a mouse click (see ChartViewHighlighted.qml).
46
47 \image examples_qmlcustomlegend3.png
48 \snippet qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml 1
61 49 */
@@ -1,53 +1,43
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example qmlpolarchart
21 21 \title Qml Polar Chart
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This is a demonstration on how to use a polar chart in your QML application.
25 25
26 \table
27 \row
28 \li \br
29 We begin with a chart that has a spline series and a scatter series with random
30 data. Both series use the same axes.
31 \br
32 \br
33 \snippet qmlpolarchart/qml/qmlpolarchart/View1.qml 1
34 \li \inlineimage examples_qmlpolarchart1.png
35 \row
36 \li \br
37 The next example shows a chart with some accurate historical data for which we need
38 to use a DateTimeAxis
39 and a AreaSeries.
40 \br
41 \br
42 \snippet qmlpolarchart/qml/qmlpolarchart/View2.qml 1
43 \li \inlineimage examples_qmlpolarchart2.png
44 \row
45 \li \br
46 And the final example with a chart that uses a CategoryAxis to make the data easier
47 to understand.
48 \br
49 \br
50 \snippet qmlpolarchart/qml/qmlpolarchart/View3.qml 1
51 \li \inlineimage examples_qmlpolarchart3.png
52 \endtable
26 We begin with a chart that has a spline series and a scatter series with random
27 data. Both series use the same axes.
28
29 \image examples_qmlpolarchart1.png
30 \snippet qmlpolarchart/qml/qmlpolarchart/View1.qml 1
31
32 The next example shows a chart with some accurate historical data for which we need
33 to use a DateTimeAxis and a AreaSeries.
34
35 \image examples_qmlpolarchart2.png
36 \snippet qmlpolarchart/qml/qmlpolarchart/View2.qml 1
37
38 And the final example with a chart that uses a CategoryAxis to make the data easier
39 to understand.
40
41 \image examples_qmlpolarchart3.png
42 \snippet qmlpolarchart/qml/qmlpolarchart/View3.qml 1
53 43 */
@@ -1,28 +1,28
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example scatterinteractions
21 \title ScatterInteractions Example
21 \title Scatter Interactions Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief This example shows how to create a simple scatter chart and how to interact with the
25 25 chart.
26 26
27 27 \image examples_scatterinteractions.png
28 28 */
@@ -1,64 +1,64
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \example temperaturerecords
21 \title Temperature records example
21 \title Temperature Records Example
22 22 \ingroup qtcharts_examples
23 23
24 24 \brief The example shows how to create a bar chart with negative bars.
25 25
26 26 For our example we use temperature data.
27 27
28 28 \image examples_temperaturerecords.png
29 29
30 30 First we create two barsets and append the data to them. One set represents the minimum temperatures and another the maximum temperatures.
31 31
32 32 \snippet temperaturerecords/main.cpp 1
33 33
34 34 We create the series and append the barsets to it. The series takes ownership of the barsets.
35 35
36 36 \snippet temperaturerecords/main.cpp 2
37 37
38 38 Here we create the chart object and add the series to it. We set the title for the chart with setTitle, and then turn on animations of the series by calling
39 39 setAnimationOptions(QChart::SeriesAnimations)
40 40
41 41 \snippet temperaturerecords/main.cpp 3
42 42
43 43 To have categories displayed on an axis, we need to create a QBarCategoryAxis. Here we create a category axis with a list of categories and
44 44 set it to be the x-axis of the chart. The chart takes ownership of the axis. For y-axis we use the default axis, which is created and scaled to the series data
45 45 by calling createDefaultAxes of the chart. We change the range for the y-axis, since this gives nicer result than with autoscaling.
46 46
47 47 Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will override the category axis.
48 48
49 49 \snippet temperaturerecords/main.cpp 4
50 50
51 51 We also want to show the legend. To do so, we get the legend pointer from the chart and set it to visible. We also place the legend to the bottom
52 52 of the chart by setting its alignment to Qt::AlignBottom.
53 53
54 54 \snippet temperaturerecords/main.cpp 5
55 55
56 56 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
57 57
58 58 \snippet temperaturerecords/main.cpp 6
59 59
60 60 Chart is ready to be shown. We set the chart to be the central widget of the window.
61 61 We also set the size for the chart window and show it.
62 62
63 63 \snippet temperaturerecords/main.cpp 7
64 64 */
@@ -1,61 +1,60
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \title Qt Charts
21 21 \page index.html
22 22 \keyword About
23 23
24 Qt Charts is a part of the Qt Enterprise addons package. It provides a set of easy to use chart
25 components which are available for Qt customers. It uses the Qt Graphics View
24 Qt Charts module provides a set of easy to use chart components. It uses the Qt Graphics View
26 25 Framework, therefore charts can be easily integrated to modern user interfaces. Qt Charts can
27 26 be used as QWidgets, QGraphicsWidget, or QML types. Users can easily create impressive
28 27 graphs by selecting one of the charts themes.
29 28
30 29 \section1 Getting Started
31 30
32 31 To import Qt Charts QML types, add the following import statement to your \c .qml file:
33 32
34 33 \snippet doc_src_qmlcharts.cpp 0
35 34
36 35 If you intend to use Qt Charts C++ classes in your application, use the
37 36 following include and using directives:
38 37
39 38 \snippet doc_src_qtcharts.cpp 0
40 39
41 40 \note If you are only using a few classes from this module, we recommend including only those
42 41 specific classes instead of the whole module.
43 42
44 43 To link against the Qt Charts module, add this line to your \c qmake project file:
45 44
46 45 \snippet doc_src_qtcharts.pro 0
47 46
48 47 See the \l{Qt Charts Getting Started}{Getting started} page for further information on
49 48 how to use Qt Charts in your application.
50 49
51 50 \section1 References
52 51 \list
53 52 \li \l{Qt Charts C++ Classes}
54 53 \li \l{Qt Charts QML Types}
55 54 \endlist
56 55
57 56 Qt Charts comes with the following examples:
58 57
59 58 \annotatedlist qtcharts_examples
60 59
61 60 */
@@ -1,200 +1,194
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 /*!
20 20 \module Qt Charts
21 21 \title Qt Charts C++ Classes
22 22 \ingroup modules
23 23
24 24 \brief C++ classes for the Qt Charts API.
25 25
26 26 Charts API is built on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using the QChart class. However
27 27 there is also the convenience class QChartView, which is QWidget based. These enable us to quickly use Qt Charts as a normal Qt widget.
28 28
29 29 Each chart type is represented by the QAbstractSeries derived class. To create charts, the users have to use an instance of the related
30 30 series class and add it to a QChart instance.
31 31 \code
32 32 QLineSeries* series = new QLineSeries();
33 33 series->add(0, 6);
34 34 series->add(2, 4);
35 35 ...
36 36 chartView->chart()->addSeries(series);
37 37 chartView->chart()->createDefaultAxes();
38 38 \endcode
39 39 */
40 40
41 41 /*!
42 42 \qmlmodule QtCharts 2.0
43 43 \title Qt Charts QML Types
44 44 \ingroup qmlmodules
45 45
46 46 \brief QML types for the Qt Charts API.
47 47
48 48 The Qt Charts QML API is an intuitive and simple way to show charts in your QML
49 49 applications.
50 50
51 \table
52 \row
53 \li \br
54 Use the following QML to create a simple pie chart:
55 \br
56 \br
57 \snippet qmlpiechart/qml/qmlpiechart/main.qml 1
58 \snippet qmlpiechart/qml/qmlpiechart/main.qml 2
59 \snippet qmlpiechart/qml/qmlpiechart/main.qml 3
60 \li \inlineimage examples_qmlpiechart.png
61 \endtable
51 Use the following QML to create a simple pie chart:
52 \image examples_qmlpiechart.png
53 \snippet qmlpiechart/qml/qmlpiechart/main.qml 1
54 \snippet qmlpiechart/qml/qmlpiechart/main.qml 2
55 \snippet qmlpiechart/qml/qmlpiechart/main.qml 3
62 56
63 57 \note Since Qt Creator 3.0 the project created with Qt Quick Application wizard based on
64 58 Qt Quick 2 template uses QGuiApplication by default. As Qt Charts utilizes Qt Graphics View
65 59 Framework for drawing, QApplication must be used. The project created with the wizard is
66 60 usable with Qt Charts after the QGuiApplication is replaced with QApplication.
67 61
68 62 \section1 QML Types
69 63 */
70 64
71 65 /*!
72 66 \group charts_examples
73 67 \ingroup all-examples
74 68 \title Qt Charts Examples
75 69
76 70 \brief Examples for the Qt Charts.
77 71
78 72 For some code examples, see one of the Qt Charts examples:
79 73
80 74 \section1 Examples
81 75
82 76 \annotatedlist qtcharts_examples
83 77 */
84 78
85 79 /*!
86 80 \group qtcharts_getting_started
87 81 \title Qt Charts Getting Started
88 82
89 83 \section1 Installing the Qt Charts module
90 84
91 85 Use the \c {Package Manager} in \c {Maintenance Tool} or the \c {Online installer} to install
92 86 the Qt Charts module. The module can be found under \c {Qt Enterprise Add-Ons} in the
93 87 package manager.
94 88
95 89 After installation Qt Charts documentation and examples are available in Qt Creator.
96 90 Examples can be found on the examples page of Qt Creator by selecting the Qt Charts
97 91 component from the drop-down menu.
98 92
99 93 The source code is installed into the QtCharts folder under EnterpriseAddOns.
100 94
101 95 \section1 Building Qt Charts
102 96
103 97 To build the Qt Charts module from source code yourself, set up a command prompt with
104 98 an environment for building Qt applications, navigate to the directory containing
105 99 \c {qtcharts.pro}, and configure the project with qmake:
106 100 \code
107 101 qmake
108 102 \endcode
109 103
110 104 After running qmake, build the project with make:
111 105 \table
112 106 \header
113 107 \li OS \li Make command
114 108 \row
115 109 \li Linux \li make
116 110 \row
117 111 \li Windows (MinGw) \li mingw32-make
118 112 \row
119 113 \li Windows (MSVC) \li nmake
120 114 \row
121 115 \li OSX \li make
122 116 \endtable
123 117
124 118 The above generates the default makefiles for your configuration, which is typically
125 119 the release build if you are using precompiled binary Qt distribution. To build both debug
126 120 and release, or one specifically, use one of the following qmake lines instead.
127 121
128 122 For debug builds:
129 123 \code
130 124 qmake CONFIG+=debug
131 125 make
132 126 \endcode
133 127 or
134 128 \code
135 129 qmake CONFIG+=debug_and_release
136 130 make debug
137 131 \endcode
138 132
139 133 For release builds:
140 134 \code
141 135 qmake CONFIG+=release
142 136 make
143 137 \endcode
144 138 or
145 139 \code
146 140 qmake CONFIG+=debug_and_release
147 141 make release
148 142 \endcode
149 143
150 144 For both builds (Windows/OS X only):
151 145 \code
152 146 qmake CONFIG+="debug_and_release build_all"
153 147 make
154 148 \endcode
155 149
156 150 After building, install the module to your Qt directory:
157 151 \code
158 152 make install
159 153 \endcode
160 154
161 155 If you want to uninstall the module:
162 156 \code
163 157 make uninstall
164 158 \endcode
165 159
166 160 To build a statically linked version of the Qt Charts module, give the following commands:
167 161
168 162 \snippet doc_src_qtcharts.cpp 1
169 163
170 164 \section1 Running examples
171 165
172 166 Qt Charts examples are found under the \c examples subdirectory. To build and run a single
173 167 example, in this case qmlpolarchart, navigate to the example directory and enter the following
174 168 commands:
175 169
176 170 \snippet doc_src_qtcharts.cpp 2
177 171
178 172 \note On some platforms, such as Windows, the executable can be generated under debug or
179 173 release folders, depending on your build.
180 174
181 175 \section1 Creating a simple application
182 176
183 177 To create a simple application, start by creating a new Qt Gui Application project in Qt
184 178 Creator and add this line to the \c .pro file of the project:
185 179
186 180 \snippet doc_src_qtcharts.pro 0
187 181
188 182 In the \c main.cpp file, include the module headers and declare namespace usage:
189 183
190 184 \snippet doc_src_qtcharts.cpp 0
191 185
192 186 \note Since Qt Creator 3.0 the project created with Qt Quick Application wizard based on
193 187 Qt Quick 2 template uses QGuiApplication by default. As Qt Charts utilizes Qt Graphics View
194 188 Framework for drawing, QApplication must be used. The project created with the wizard is
195 189 usable with Qt Charts after the QGuiApplication is replaced with QApplication.
196 190
197 191 For further code examples, see one of the Qt Charts examples:
198 192
199 193 \annotatedlist qtcharts_examples
200 194 */
@@ -1,1005 +1,1002
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2014 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.io
6 6 **
7 7 ** This file is part of the Qt Charts module.
8 8 **
9 9 ** Licensees holding valid commercial license for Qt may use this file in
10 10 ** accordance with the Qt License Agreement provided with the Software
11 11 ** or, alternatively, in accordance with the terms contained in a written
12 12 ** agreement between you and Digia.
13 13 **
14 14 ** If you have questions regarding the use of this file, please use
15 15 ** contact form at http://qt.io
16 16 **
17 17 ****************************************************************************/
18 18
19 19 #include <QtCharts/QPieSeries>
20 20 #include <private/qpieseries_p.h>
21 21 #include <QtCharts/QPieSlice>
22 22 #include <private/qpieslice_p.h>
23 23 #include <private/pieslicedata_p.h>
24 24 #include <private/chartdataset_p.h>
25 25 #include <private/charttheme_p.h>
26 26 #include <QtCharts/QAbstractAxis>
27 27 #include <private/pieanimation_p.h>
28 28 #include <private/charthelpers_p.h>
29 29
30 30 #include <QtCharts/QPieLegendMarker>
31 31
32 32 QT_CHARTS_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QPieSeries
36 36 \inmodule Qt Charts
37 37 \brief Pie series API for Qt Charts.
38 38
39 39 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
40 40 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
41 41 The actual slice size is determined by that relative value.
42 42
43 43 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0.
44 44 These relate to the actual chart rectangle.
45 45
46 46 By default the pie is defined as a full pie but it can also be a partial pie.
47 47 This can be done by setting a starting angle and angle span to the series.
48 48 Full pie is 360 degrees where 0 is at 12 a'clock.
49 49
50 50 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
51 \table 100%
52 \row
53 \li \image examples_piechart.png
54 \li \image examples_donutchart.png
55 \endtable
51 \image examples_piechart.png
52 \image examples_donutchart.png
56 53 */
57 54 /*!
58 55 \qmltype PieSeries
59 56 \instantiates QPieSeries
60 57 \inqmlmodule QtCharts
61 58
62 59 \inherits AbstractSeries
63 60
64 61 \brief The PieSeries type is used for making pie charts.
65 62
66 63 The following QML shows how to create a simple pie chart.
67 64
68 65 \snippet qmlchart/qml/qmlchart/View1.qml 1
69 66
70 67 \beginfloatleft
71 68 \image examples_qmlchart1.png
72 69 \endfloat
73 70 \clearfloat
74 71 */
75 72
76 73 /*!
77 74 \property QPieSeries::horizontalPosition
78 75 \brief Defines the horizontal position of the pie.
79 76
80 77 The value is a relative value to the chart rectangle where:
81 78
82 79 \list
83 80 \li 0.0 is the absolute left.
84 81 \li 1.0 is the absolute right.
85 82 \endlist
86 83 Default value is 0.5 (center).
87 84 \sa verticalPosition
88 85 */
89 86
90 87 /*!
91 88 \qmlproperty real PieSeries::horizontalPosition
92 89
93 90 Defines the horizontal position of the pie.
94 91
95 92 The value is a relative value to the chart rectangle where:
96 93
97 94 \list
98 95 \li 0.0 is the absolute left.
99 96 \li 1.0 is the absolute right.
100 97 \endlist
101 98 Default value is 0.5 (center).
102 99 \sa verticalPosition
103 100 */
104 101
105 102 /*!
106 103 \property QPieSeries::verticalPosition
107 104 \brief Defines the vertical position of the pie.
108 105
109 106 The value is a relative value to the chart rectangle where:
110 107
111 108 \list
112 109 \li 0.0 is the absolute top.
113 110 \li 1.0 is the absolute bottom.
114 111 \endlist
115 112 Default value is 0.5 (center).
116 113 \sa horizontalPosition
117 114 */
118 115
119 116 /*!
120 117 \qmlproperty real PieSeries::verticalPosition
121 118
122 119 Defines the vertical position of the pie.
123 120
124 121 The value is a relative value to the chart rectangle where:
125 122
126 123 \list
127 124 \li 0.0 is the absolute top.
128 125 \li 1.0 is the absolute bottom.
129 126 \endlist
130 127 Default value is 0.5 (center).
131 128 \sa horizontalPosition
132 129 */
133 130
134 131 /*!
135 132 \property QPieSeries::size
136 133 \brief Defines the pie size.
137 134
138 135 The value is a relative value to the chart rectangle where:
139 136
140 137 \list
141 138 \li 0.0 is the minimum size (pie not drawn).
142 139 \li 1.0 is the maximum size that can fit the chart.
143 140 \endlist
144 141
145 142 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
146 143
147 144 Default value is 0.7.
148 145 */
149 146
150 147 /*!
151 148 \qmlproperty real PieSeries::size
152 149
153 150 Defines the pie size.
154 151
155 152 The value is a relative value to the chart rectangle where:
156 153
157 154 \list
158 155 \li 0.0 is the minimum size (pie not drawn).
159 156 \li 1.0 is the maximum size that can fit the chart.
160 157 \endlist
161 158
162 159 Default value is 0.7.
163 160 */
164 161
165 162 /*!
166 163 \property QPieSeries::holeSize
167 164 \brief Defines the donut hole size.
168 165
169 166 The value is a relative value to the chart rectangle where:
170 167
171 168 \list
172 169 \li 0.0 is the minimum size (full pie drawn, without any hole inside).
173 170 \li 1.0 is the maximum size that can fit the chart. (donut has no width)
174 171 \endlist
175 172
176 173 The value is never greater then size property.
177 174 Default value is 0.0.
178 175 */
179 176
180 177 /*!
181 178 \qmlproperty real PieSeries::holeSize
182 179
183 180 Defines the donut hole size.
184 181
185 182 The value is a relative value to the chart rectangle where:
186 183
187 184 \list
188 185 \li 0.0 is the minimum size (full pie drawn, without any hole inside).
189 186 \li 1.0 is the maximum size that can fit the chart. (donut has no width)
190 187 \endlist
191 188
192 189 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
193 190
194 191 Default value is 0.0.
195 192 */
196 193
197 194 /*!
198 195 \property QPieSeries::startAngle
199 196 \brief Defines the starting angle of the pie.
200 197
201 198 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
202 199
203 200 Default is value is 0.
204 201 */
205 202
206 203 /*!
207 204 \qmlproperty real PieSeries::startAngle
208 205
209 206 Defines the starting angle of the pie.
210 207
211 208 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
212 209
213 210 Default is value is 0.
214 211 */
215 212
216 213 /*!
217 214 \property QPieSeries::endAngle
218 215 \brief Defines the ending angle of the pie.
219 216
220 217 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
221 218
222 219 Default is value is 360.
223 220 */
224 221
225 222 /*!
226 223 \qmlproperty real PieSeries::endAngle
227 224
228 225 Defines the ending angle of the pie.
229 226
230 227 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
231 228
232 229 Default is value is 360.
233 230 */
234 231
235 232 /*!
236 233 \property QPieSeries::count
237 234
238 235 Number of slices in the series.
239 236 */
240 237
241 238 /*!
242 239 \qmlproperty int PieSeries::count
243 240
244 241 Number of slices in the series.
245 242 */
246 243
247 244 /*!
248 245 \fn void QPieSeries::countChanged()
249 246 Emitted when the slice count has changed.
250 247 \sa count
251 248 */
252 249 /*!
253 250 \qmlsignal PieSeries::onCountChanged()
254 251 Emitted when the slice count has changed.
255 252 */
256 253
257 254 /*!
258 255 \property QPieSeries::sum
259 256
260 257 Sum of all slices.
261 258
262 259 The series keeps track of the sum of all slices it holds.
263 260 */
264 261
265 262 /*!
266 263 \qmlproperty real PieSeries::sum
267 264
268 265 Sum of all slices.
269 266
270 267 The series keeps track of the sum of all slices it holds.
271 268 */
272 269
273 270 /*!
274 271 \fn void QPieSeries::sumChanged()
275 272 Emitted when the sum of all slices has changed.
276 273 \sa sum
277 274 */
278 275 /*!
279 276 \qmlsignal PieSeries::onSumChanged()
280 277 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
281 278 change value of a slice.
282 279 */
283 280
284 281 /*!
285 282 \fn void QPieSeries::added(QList<QPieSlice*> slices)
286 283
287 284 This signal is emitted when \a slices have been added to the series.
288 285
289 286 \sa append(), insert()
290 287 */
291 288 /*!
292 289 \qmlsignal PieSeries::onAdded(PieSlice slice)
293 290 Emitted when \a slice has been added to the series.
294 291 */
295 292
296 293 /*!
297 294 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
298 295 This signal is emitted when \a slices have been removed from the series.
299 296 \sa remove()
300 297 */
301 298 /*!
302 299 \qmlsignal PieSeries::onRemoved(PieSlice slice)
303 300 Emitted when \a slice has been removed from the series.
304 301 */
305 302
306 303 /*!
307 304 \fn void QPieSeries::clicked(QPieSlice *slice)
308 305 This signal is emitted when a \a slice has been clicked.
309 306 \sa QPieSlice::clicked()
310 307 */
311 308 /*!
312 309 \qmlsignal PieSeries::onClicked(PieSlice slice)
313 310 This signal is emitted when a \a slice has been clicked.
314 311 */
315 312
316 313 /*!
317 314 \fn void QPieSeries::pressed(QPieSlice *slice)
318 315 This signal is emitted when a \a slice has been pressed.
319 316 \sa QPieSlice::pressed()
320 317 */
321 318 /*!
322 319 \qmlsignal PieSeries::onPressed(PieSlice slice)
323 320 This signal is emitted when a \a slice has been pressed.
324 321 */
325 322
326 323 /*!
327 324 \fn void QPieSeries::released(QPieSlice *slice)
328 325 This signal is emitted when a \a slice has been released.
329 326 \sa QPieSlice::released()
330 327 */
331 328 /*!
332 329 \qmlsignal PieSeries::onReleased(PieSlice slice)
333 330 This signal is emitted when a \a slice has been released.
334 331 */
335 332
336 333 /*!
337 334 \fn void QPieSeries::doubleClicked(QPieSlice *slice)
338 335 This signal is emitted when a \a slice has been doubleClicked.
339 336 \sa QPieSlice::doubleClicked()
340 337 */
341 338 /*!
342 339 \qmlsignal PieSeries::onDoubleClicked(PieSlice slice)
343 340 This signal is emitted when a \a slice has been doubleClicked.
344 341 */
345 342
346 343 /*!
347 344 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
348 345 This signal is emitted when user has hovered over or away from the \a slice.
349 346 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
350 347 \sa QPieSlice::hovered()
351 348 */
352 349 /*!
353 350 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
354 351 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
355 352 over the slice and false when hover has moved away from the slice.
356 353 */
357 354
358 355 /*!
359 356 \qmlmethod PieSlice PieSeries::at(int index)
360 357 Returns slice at \a index. Returns null if the index is not valid.
361 358 */
362 359
363 360 /*!
364 361 \qmlmethod PieSlice PieSeries::find(string label)
365 362 Returns the first slice with \a label. Returns null if the index is not valid.
366 363 */
367 364
368 365 /*!
369 366 \qmlmethod PieSlice PieSeries::append(string label, real value)
370 367 Adds a new slice with \a label and \a value to the pie.
371 368 */
372 369
373 370 /*!
374 371 \qmlmethod bool PieSeries::remove(PieSlice slice)
375 372 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
376 373 */
377 374
378 375 /*!
379 376 \qmlmethod PieSeries::clear()
380 377 Removes all slices from the pie.
381 378 */
382 379
383 380 /*!
384 381 Constructs a series object which is a child of \a parent.
385 382 */
386 383 QPieSeries::QPieSeries(QObject *parent)
387 384 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
388 385 {
389 386 Q_D(QPieSeries);
390 387 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
391 388 }
392 389
393 390 /*!
394 391 Destroys the series and its slices.
395 392 */
396 393 QPieSeries::~QPieSeries()
397 394 {
398 395 // NOTE: d_prt destroyed by QObject
399 396 clear();
400 397 }
401 398
402 399 /*!
403 400 Returns QAbstractSeries::SeriesTypePie.
404 401 */
405 402 QAbstractSeries::SeriesType QPieSeries::type() const
406 403 {
407 404 return QAbstractSeries::SeriesTypePie;
408 405 }
409 406
410 407 /*!
411 408 Appends a single \a slice to the series.
412 409 Slice ownership is passed to the series.
413 410
414 411 Returns true if append was succesfull.
415 412 */
416 413 bool QPieSeries::append(QPieSlice *slice)
417 414 {
418 415 return append(QList<QPieSlice *>() << slice);
419 416 }
420 417
421 418 /*!
422 419 Appends an array of \a slices to the series.
423 420 Slice ownership is passed to the series.
424 421
425 422 Returns true if append was successful.
426 423 */
427 424 bool QPieSeries::append(QList<QPieSlice *> slices)
428 425 {
429 426 Q_D(QPieSeries);
430 427
431 428 if (slices.count() == 0)
432 429 return false;
433 430
434 431 foreach (QPieSlice *s, slices) {
435 432 if (!s || d->m_slices.contains(s))
436 433 return false;
437 434 if (s->series()) // already added to some series
438 435 return false;
439 436 if (!isValidValue(s->value()))
440 437 return false;
441 438 }
442 439
443 440 foreach (QPieSlice *s, slices) {
444 441 s->setParent(this);
445 442 QPieSlicePrivate::fromSlice(s)->m_series = this;
446 443 d->m_slices << s;
447 444 }
448 445
449 446 d->updateDerivativeData();
450 447
451 448 foreach(QPieSlice * s, slices) {
452 449 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
453 450 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
454 451 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
455 452 connect(s, SIGNAL(pressed()), d, SLOT(slicePressed()));
456 453 connect(s, SIGNAL(released()), d, SLOT(sliceReleased()));
457 454 connect(s, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
458 455 }
459 456
460 457 emit added(slices);
461 458 emit countChanged();
462 459
463 460 return true;
464 461 }
465 462
466 463 /*!
467 464 Appends a single \a slice to the series and returns a reference to the series.
468 465 Slice ownership is passed to the series.
469 466 */
470 467 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
471 468 {
472 469 append(slice);
473 470 return *this;
474 471 }
475 472
476 473
477 474 /*!
478 475 Appends a single slice to the series with give \a value and \a label.
479 476 Slice ownership is passed to the series.
480 477 Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series.
481 478 */
482 479 QPieSlice *QPieSeries::append(QString label, qreal value)
483 480 {
484 481 if (isValidValue(value)) {
485 482 QPieSlice *slice = new QPieSlice(label, value);
486 483 append(slice);
487 484 return slice;
488 485 } else {
489 486 return 0;
490 487 }
491 488 }
492 489
493 490 /*!
494 491 Inserts a single \a slice to the series before the slice at \a index position.
495 492 Slice ownership is passed to the series.
496 493
497 494 Returns true if insert was successful.
498 495 */
499 496 bool QPieSeries::insert(int index, QPieSlice *slice)
500 497 {
501 498 Q_D(QPieSeries);
502 499
503 500 if (index < 0 || index > d->m_slices.count())
504 501 return false;
505 502
506 503 if (!slice || d->m_slices.contains(slice))
507 504 return false;
508 505
509 506 if (slice->series()) // already added to some series
510 507 return false;
511 508
512 509 if (!isValidValue(slice->value()))
513 510 return false;
514 511
515 512 slice->setParent(this);
516 513 QPieSlicePrivate::fromSlice(slice)->m_series = this;
517 514 d->m_slices.insert(index, slice);
518 515
519 516 d->updateDerivativeData();
520 517
521 518 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
522 519 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
523 520 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
524 521 connect(slice, SIGNAL(pressed()), d, SLOT(slicePressed()));
525 522 connect(slice, SIGNAL(released()), d, SLOT(sliceReleased()));
526 523 connect(slice, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
527 524
528 525 emit added(QList<QPieSlice *>() << slice);
529 526 emit countChanged();
530 527
531 528 return true;
532 529 }
533 530
534 531 /*!
535 532 Removes a single \a slice from the series and deletes the slice.
536 533
537 534 Do not reference the pointer after this call.
538 535
539 536 Returns true if remove was successful.
540 537 */
541 538 bool QPieSeries::remove(QPieSlice *slice)
542 539 {
543 540 Q_D(QPieSeries);
544 541
545 542 if (!d->m_slices.removeOne(slice))
546 543 return false;
547 544
548 545 d->updateDerivativeData();
549 546
550 547 emit removed(QList<QPieSlice *>() << slice);
551 548 emit countChanged();
552 549
553 550 delete slice;
554 551 slice = 0;
555 552
556 553 return true;
557 554 }
558 555
559 556 /*!
560 557 Takes a single \a slice from the series. Does not destroy the slice object.
561 558
562 559 \note The series remains as the slice's parent object. You must set the
563 560 parent object to take full ownership.
564 561
565 562 Returns true if take was successful.
566 563 */
567 564 bool QPieSeries::take(QPieSlice *slice)
568 565 {
569 566 Q_D(QPieSeries);
570 567
571 568 if (!d->m_slices.removeOne(slice))
572 569 return false;
573 570
574 571 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
575 572 slice->disconnect(d);
576 573
577 574 d->updateDerivativeData();
578 575
579 576 emit removed(QList<QPieSlice *>() << slice);
580 577 emit countChanged();
581 578
582 579 return true;
583 580 }
584 581
585 582 /*!
586 583 Clears all slices from the series.
587 584 */
588 585 void QPieSeries::clear()
589 586 {
590 587 Q_D(QPieSeries);
591 588 if (d->m_slices.count() == 0)
592 589 return;
593 590
594 591 QList<QPieSlice *> slices = d->m_slices;
595 592 foreach (QPieSlice *s, d->m_slices)
596 593 d->m_slices.removeOne(s);
597 594
598 595 d->updateDerivativeData();
599 596
600 597 emit removed(slices);
601 598 emit countChanged();
602 599
603 600 foreach (QPieSlice *s, slices)
604 601 delete s;
605 602 }
606 603
607 604 /*!
608 605 Returns a list of slices that belong to this series.
609 606 */
610 607 QList<QPieSlice *> QPieSeries::slices() const
611 608 {
612 609 Q_D(const QPieSeries);
613 610 return d->m_slices;
614 611 }
615 612
616 613 /*!
617 614 returns the number of the slices in this series.
618 615 */
619 616 int QPieSeries::count() const
620 617 {
621 618 Q_D(const QPieSeries);
622 619 return d->m_slices.count();
623 620 }
624 621
625 622 /*!
626 623 Returns true is the series is empty.
627 624 */
628 625 bool QPieSeries::isEmpty() const
629 626 {
630 627 Q_D(const QPieSeries);
631 628 return d->m_slices.isEmpty();
632 629 }
633 630
634 631 /*!
635 632 Returns the sum of all slice values in this series.
636 633
637 634 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
638 635 */
639 636 qreal QPieSeries::sum() const
640 637 {
641 638 Q_D(const QPieSeries);
642 639 return d->m_sum;
643 640 }
644 641
645 642 void QPieSeries::setHoleSize(qreal holeSize)
646 643 {
647 644 Q_D(QPieSeries);
648 645 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
649 646 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
650 647 }
651 648
652 649 qreal QPieSeries::holeSize() const
653 650 {
654 651 Q_D(const QPieSeries);
655 652 return d->m_holeRelativeSize;
656 653 }
657 654
658 655 void QPieSeries::setHorizontalPosition(qreal relativePosition)
659 656 {
660 657 Q_D(QPieSeries);
661 658
662 659 if (relativePosition < 0.0)
663 660 relativePosition = 0.0;
664 661 if (relativePosition > 1.0)
665 662 relativePosition = 1.0;
666 663
667 664 if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) {
668 665 d->m_pieRelativeHorPos = relativePosition;
669 666 emit d->horizontalPositionChanged();
670 667 }
671 668 }
672 669
673 670 qreal QPieSeries::horizontalPosition() const
674 671 {
675 672 Q_D(const QPieSeries);
676 673 return d->m_pieRelativeHorPos;
677 674 }
678 675
679 676 void QPieSeries::setVerticalPosition(qreal relativePosition)
680 677 {
681 678 Q_D(QPieSeries);
682 679
683 680 if (relativePosition < 0.0)
684 681 relativePosition = 0.0;
685 682 if (relativePosition > 1.0)
686 683 relativePosition = 1.0;
687 684
688 685 if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) {
689 686 d->m_pieRelativeVerPos = relativePosition;
690 687 emit d->verticalPositionChanged();
691 688 }
692 689 }
693 690
694 691 qreal QPieSeries::verticalPosition() const
695 692 {
696 693 Q_D(const QPieSeries);
697 694 return d->m_pieRelativeVerPos;
698 695 }
699 696
700 697 void QPieSeries::setPieSize(qreal relativeSize)
701 698 {
702 699 Q_D(QPieSeries);
703 700 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
704 701 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
705 702
706 703 }
707 704
708 705 qreal QPieSeries::pieSize() const
709 706 {
710 707 Q_D(const QPieSeries);
711 708 return d->m_pieRelativeSize;
712 709 }
713 710
714 711
715 712 void QPieSeries::setPieStartAngle(qreal angle)
716 713 {
717 714 Q_D(QPieSeries);
718 715 if (qFuzzyCompare(d->m_pieStartAngle, angle))
719 716 return;
720 717 d->m_pieStartAngle = angle;
721 718 d->updateDerivativeData();
722 719 emit d->pieStartAngleChanged();
723 720 }
724 721
725 722 qreal QPieSeries::pieStartAngle() const
726 723 {
727 724 Q_D(const QPieSeries);
728 725 return d->m_pieStartAngle;
729 726 }
730 727
731 728 /*!
732 729 Sets the end angle of the pie.
733 730
734 731 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
735 732
736 733 \a angle must be greater than start angle.
737 734
738 735 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
739 736 */
740 737 void QPieSeries::setPieEndAngle(qreal angle)
741 738 {
742 739 Q_D(QPieSeries);
743 740 if (qFuzzyCompare(d->m_pieEndAngle, angle))
744 741 return;
745 742 d->m_pieEndAngle = angle;
746 743 d->updateDerivativeData();
747 744 emit d->pieEndAngleChanged();
748 745 }
749 746
750 747 /*!
751 748 Returns the end angle of the pie.
752 749
753 750 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
754 751
755 752 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
756 753 */
757 754 qreal QPieSeries::pieEndAngle() const
758 755 {
759 756 Q_D(const QPieSeries);
760 757 return d->m_pieEndAngle;
761 758 }
762 759
763 760 /*!
764 761 Sets the all the slice labels \a visible or invisible.
765 762
766 763 Note that this affects only the current slices in the series.
767 764 If user adds a new slice the default label visibility is false.
768 765
769 766 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
770 767 */
771 768 void QPieSeries::setLabelsVisible(bool visible)
772 769 {
773 770 Q_D(QPieSeries);
774 771 foreach (QPieSlice *s, d->m_slices)
775 772 s->setLabelVisible(visible);
776 773 }
777 774
778 775 /*!
779 776 Sets the all the slice labels \a position
780 777
781 778 Note that this affects only the current slices in the series.
782 779 If user adds a new slice the default label position is LabelOutside
783 780
784 781 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
785 782 */
786 783 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
787 784 {
788 785 Q_D(QPieSeries);
789 786 foreach (QPieSlice *s, d->m_slices)
790 787 s->setLabelPosition(position);
791 788 }
792 789
793 790 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
794 791
795 792
796 793 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
797 794 QAbstractSeriesPrivate(parent),
798 795 m_pieRelativeHorPos(0.5),
799 796 m_pieRelativeVerPos(0.5),
800 797 m_pieRelativeSize(0.7),
801 798 m_pieStartAngle(0),
802 799 m_pieEndAngle(360),
803 800 m_sum(0),
804 801 m_holeRelativeSize(0.0)
805 802 {
806 803 }
807 804
808 805 QPieSeriesPrivate::~QPieSeriesPrivate()
809 806 {
810 807 }
811 808
812 809 void QPieSeriesPrivate::updateDerivativeData()
813 810 {
814 811 // calculate sum of all slices
815 812 qreal sum = 0;
816 813 foreach (QPieSlice *s, m_slices)
817 814 sum += s->value();
818 815
819 816 if (!qFuzzyCompare(m_sum, sum)) {
820 817 m_sum = sum;
821 818 emit q_func()->sumChanged();
822 819 }
823 820
824 821 // nothing to show..
825 822 if (qFuzzyCompare(m_sum, 0))
826 823 return;
827 824
828 825 // update slice attributes
829 826 qreal sliceAngle = m_pieStartAngle;
830 827 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
831 828 QVector<QPieSlice *> changed;
832 829 foreach (QPieSlice *s, m_slices) {
833 830 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
834 831 d->setPercentage(s->value() / m_sum);
835 832 d->setStartAngle(sliceAngle);
836 833 d->setAngleSpan(pieSpan * s->percentage());
837 834 sliceAngle += s->angleSpan();
838 835 }
839 836
840 837
841 838 emit calculatedDataChanged();
842 839 }
843 840
844 841 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
845 842 {
846 843 bool changed = false;
847 844
848 845 if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) {
849 846 m_holeRelativeSize = innerSize;
850 847 changed = true;
851 848 }
852 849
853 850 if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) {
854 851 m_pieRelativeSize = outerSize;
855 852 changed = true;
856 853 }
857 854
858 855 if (changed)
859 856 emit pieSizeChanged();
860 857 }
861 858
862 859 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
863 860 {
864 861 return series->d_func();
865 862 }
866 863
867 864 void QPieSeriesPrivate::sliceValueChanged()
868 865 {
869 866 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
870 867 updateDerivativeData();
871 868 }
872 869
873 870 void QPieSeriesPrivate::sliceClicked()
874 871 {
875 872 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
876 873 Q_ASSERT(m_slices.contains(slice));
877 874 Q_Q(QPieSeries);
878 875 emit q->clicked(slice);
879 876 }
880 877
881 878 void QPieSeriesPrivate::sliceHovered(bool state)
882 879 {
883 880 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
884 881 if (!m_slices.isEmpty()) {
885 882 Q_ASSERT(m_slices.contains(slice));
886 883 Q_Q(QPieSeries);
887 884 emit q->hovered(slice, state);
888 885 }
889 886 }
890 887
891 888 void QPieSeriesPrivate::slicePressed()
892 889 {
893 890 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
894 891 Q_ASSERT(m_slices.contains(slice));
895 892 Q_Q(QPieSeries);
896 893 emit q->pressed(slice);
897 894 }
898 895
899 896 void QPieSeriesPrivate::sliceReleased()
900 897 {
901 898 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
902 899 Q_ASSERT(m_slices.contains(slice));
903 900 Q_Q(QPieSeries);
904 901 emit q->released(slice);
905 902 }
906 903
907 904 void QPieSeriesPrivate::sliceDoubleClicked()
908 905 {
909 906 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
910 907 Q_ASSERT(m_slices.contains(slice));
911 908 Q_Q(QPieSeries);
912 909 emit q->doubleClicked(slice);
913 910 }
914 911
915 912 void QPieSeriesPrivate::initializeDomain()
916 913 {
917 914 // does not apply to pie
918 915 }
919 916
920 917 void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
921 918 {
922 919 Q_Q(QPieSeries);
923 920 PieChartItem *pie = new PieChartItem(q,parent);
924 921 m_item.reset(pie);
925 922 QAbstractSeriesPrivate::initializeGraphics(parent);
926 923 }
927 924
928 925 void QPieSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options)
929 926 {
930 927 PieChartItem *item = static_cast<PieChartItem *>(m_item.data());
931 928 Q_ASSERT(item);
932 929 if (item->animation())
933 930 item->animation()->stopAndDestroyLater();
934 931
935 932 if (options.testFlag(QChart::SeriesAnimations))
936 933 item->setAnimation(new PieAnimation(item));
937 934 else
938 935 item->setAnimation(0);
939 936 QAbstractSeriesPrivate::initializeAnimations(options);
940 937 }
941 938
942 939 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
943 940 {
944 941 Q_Q(QPieSeries);
945 942 QList<QLegendMarker*> markers;
946 943 foreach(QPieSlice* slice, q->slices()) {
947 944 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
948 945 markers << marker;
949 946 }
950 947 return markers;
951 948 }
952 949
953 950 void QPieSeriesPrivate::initializeAxes()
954 951 {
955 952
956 953 }
957 954
958 955 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
959 956 {
960 957 Q_UNUSED(orientation);
961 958 return QAbstractAxis::AxisTypeNoAxis;
962 959 }
963 960
964 961 QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
965 962 {
966 963 Q_UNUSED(orientation);
967 964 return 0;
968 965 }
969 966
970 967 void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
971 968 {
972 969 //Q_Q(QPieSeries);
973 970 //const QList<QColor>& colors = theme->seriesColors();
974 971 const QList<QGradient>& gradients = theme->seriesGradients();
975 972
976 973 for (int i(0); i < m_slices.count(); i++) {
977 974
978 975 QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
979 976
980 977 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
981 978 qreal pos = (qreal)(i + 1) / (qreal) m_slices.count();
982 979 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos);
983 980
984 981 QPieSlice *s = m_slices.at(i);
985 982 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
986 983
987 984 if (forced || d->m_data.m_slicePen.isThemed())
988 985 d->setPen(penColor, true);
989 986
990 987 if (forced || d->m_data.m_sliceBrush.isThemed())
991 988 d->setBrush(brushColor, true);
992 989
993 990 if (forced || d->m_data.m_labelBrush.isThemed())
994 991 d->setLabelBrush(theme->labelBrush().color(), true);
995 992
996 993 if (forced || d->m_data.m_labelFont.isThemed())
997 994 d->setLabelFont(theme->labelFont(), true);
998 995 }
999 996 }
1000 997
1001 998
1002 999 #include "moc_qpieseries.cpp"
1003 1000 #include "moc_qpieseries_p.cpp"
1004 1001
1005 1002 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now