1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,40 | |||||
|
1 | /*! | |||
|
2 | \example examples/groupedbarchart | |||
|
3 | \title GroupedBarChart Example | |||
|
4 | \subtitle | |||
|
5 | ||||
|
6 | The example shows how to create simple bar chart. GroupedBarChart shows the data in sets as separate bars, which are grouped in categories. | |||
|
7 | ||||
|
8 | \image examples_groupedbarchart.png | |||
|
9 | ||||
|
10 | First we define categories. | |||
|
11 | ||||
|
12 | \snippet ../examples/groupedbarchart/main.cpp 1 | |||
|
13 | ||||
|
14 | Data that groupedbarchart visualizes, is defined by QBarSet instances. Here we create some sets and append data | |||
|
15 | we want to visualize to them. | |||
|
16 | ||||
|
17 | \snippet ../examples/groupedbarchart/main.cpp 2 | |||
|
18 | ||||
|
19 | To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating | |||
|
20 | the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets | |||
|
21 | are added to series here. | |||
|
22 | ||||
|
23 | \snippet ../examples/groupedbarchart/main.cpp 3 | |||
|
24 | ||||
|
25 | Then we create a chart and add the series to it. | |||
|
26 | ||||
|
27 | \snippet ../examples/groupedbarchart/main.cpp 4 | |||
|
28 | ||||
|
29 | And we also want to show the legend, so that the data is easier to read. | |||
|
30 | ||||
|
31 | \snippet ../examples/groupedbarchart/main.cpp 5 | |||
|
32 | ||||
|
33 | Finally we add the chart onto a view. | |||
|
34 | ||||
|
35 | \snippet ../examples/groupedbarchart/main.cpp 6 | |||
|
36 | ||||
|
37 | And it is ready to be shown in a window. | |||
|
38 | ||||
|
39 | \snippet ../examples/groupedbarchart/main.cpp 7 | |||
|
40 | */ |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -1,40 +1,34 | |||||
1 | /*! |
|
1 | /*! | |
2 | \example examples/barchart |
|
2 | \example examples/barchart | |
3 | \title BarChart Example |
|
3 | \title BarChart Example | |
4 | \subtitle |
|
4 | \subtitle | |
5 |
|
5 | |||
6 |
The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are |
|
6 | The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are drawn at the x-axis to the position defined by data. | |
7 |
|
7 | |||
8 | \image examples_barchart.png |
|
8 | \image examples_barchart.png | |
9 |
|
9 | |||
10 | First we define categories. |
|
10 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data | |
|
11 | we want to visualize to them. Note that first and third QPointF in each set have smaller intervals at their x coordinates. This will be reflected in the chart. | |||
11 |
|
12 | |||
12 | \snippet ../examples/barchart/main.cpp 1 |
|
13 | \snippet ../examples/barchart/main.cpp 1 | |
13 |
|
14 | |||
14 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data |
|
15 | To combine the sets to a chart, we need to create QBarSeries instance. Then we append our barsets to the series. | |
15 | we want to visualize to them. |
|
|||
16 |
|
16 | |||
17 | \snippet ../examples/barchart/main.cpp 2 |
|
17 | \snippet ../examples/barchart/main.cpp 2 | |
18 |
|
18 | |||
19 | To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating |
|
19 | Next we create a chart and add the series to it. | |
20 | the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets |
|
|||
21 | are added to series here. |
|
|||
22 |
|
20 | |||
23 | \snippet ../examples/barchart/main.cpp 3 |
|
21 | \snippet ../examples/barchart/main.cpp 3 | |
24 |
|
22 | |||
25 | Then we create a chart and add the series to it. |
|
23 | We want to have the legend displayed at the bottom of the chart. Also we turn on the nice numbers algorithm on for y-axis. | |
26 |
|
24 | |||
27 | \snippet ../examples/barchart/main.cpp 4 |
|
25 | \snippet ../examples/barchart/main.cpp 4 | |
28 |
|
26 | |||
29 | And we also want to show the legend, so that the data is easier to read. |
|
|||
30 |
|
||||
31 | \snippet ../examples/barchart/main.cpp 5 |
|
|||
32 |
|
||||
33 | Finally we add the chart onto a view. |
|
27 | Finally we add the chart onto a view. | |
34 |
|
28 | |||
35 |
\snippet ../examples/barchart/main.cpp |
|
29 | \snippet ../examples/barchart/main.cpp 5 | |
36 |
|
30 | |||
37 | And it is ready to be shown in a window. |
|
31 | And it is ready to be shown in a window. | |
38 |
|
32 | |||
39 |
\snippet ../examples/percentbarchart/main.cpp |
|
33 | \snippet ../examples/percentbarchart/main.cpp 6 | |
40 | */ |
|
34 | */ |
@@ -1,36 +1,37 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page examples.html |
|
2 | \page examples.html | |
3 | \title Examples |
|
3 | \title Examples | |
4 | \keyword Examples |
|
4 | \keyword Examples | |
5 |
|
5 | |||
6 | \raw HTML |
|
6 | \raw HTML | |
7 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
7 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> | |
8 | <tr> |
|
8 | <tr> | |
9 | <th class="titleheader" width="33%"> |
|
9 | <th class="titleheader" width="33%"> | |
10 | List of examples |
|
10 | List of examples | |
11 | </th> |
|
11 | </th> | |
12 | </tr> |
|
12 | </tr> | |
13 | <tr> |
|
13 | <tr> | |
14 | <td valign="top"> |
|
14 | <td valign="top"> | |
15 | <ul> |
|
15 | <ul> | |
16 | <li><a href="examples-areachart.html">Area chart</a></li> |
|
16 | <li><a href="examples-areachart.html">Area chart</a></li> | |
17 | <li><a href="examples-barchart.html">Bar chart</a></li> |
|
17 | <li><a href="examples-barchart.html">Bar chart</a></li> | |
18 | <li><a href="examples-customchart.html">Custom chart</a></li> |
|
18 | <li><a href="examples-customchart.html">Custom chart</a></li> | |
|
19 | <li><a href="examples-groupedbarchart.html">Grouped bar chart</a></li> | |||
19 | <li><a href="examples-linechart.html">Line chart</a></li> |
|
20 | <li><a href="examples-linechart.html">Line chart</a></li> | |
20 | <li><a href="examples-modeldata.html">Model data</a></li> |
|
21 | <li><a href="examples-modeldata.html">Model data</a></li> | |
21 | <li><a href="examples-percentbarchart.html">Percent bar chart</a></li> |
|
22 | <li><a href="examples-percentbarchart.html">Percent bar chart</a></li> | |
22 | <li><a href="examples-piechart.html">Pie chart</a></li> |
|
23 | <li><a href="examples-piechart.html">Pie chart</a></li> | |
23 | <li><a href="examples-piechartdrilldown.html">Pie chart drilldown</a></li> |
|
24 | <li><a href="examples-piechartdrilldown.html">Pie chart drilldown</a></li> | |
24 | <li><a href="examples-presenterchart.html">Presenter chart</a></li> |
|
25 | <li><a href="examples-presenterchart.html">Presenter chart</a></li> | |
25 | <li><a href="examples-scatterchart.html">Scatter chart</a></li> |
|
26 | <li><a href="examples-scatterchart.html">Scatter chart</a></li> | |
26 | <li><a href="examples-scatterinteractions.html">Scatter interactions</a></li> |
|
27 | <li><a href="examples-scatterinteractions.html">Scatter interactions</a></li> | |
27 | <li><a href="examples-splinechart.html">Spline chart</a></li> |
|
28 | <li><a href="examples-splinechart.html">Spline chart</a></li> | |
28 | <li><a href="examples-stackedbarchart.html">Stacked bar chart</a></li> |
|
29 | <li><a href="examples-stackedbarchart.html">Stacked bar chart</a></li> | |
29 | <li><a href="examples-stackedbarchartdrilldown.html">Stacked bar chart drilldown</a></li> |
|
30 | <li><a href="examples-stackedbarchartdrilldown.html">Stacked bar chart drilldown</a></li> | |
30 | <li><a href="examples-zoomlinechart.html">Zoom line</a></li> |
|
31 | <li><a href="examples-zoomlinechart.html">Zoom line</a></li> | |
31 | </ul> |
|
32 | </ul> | |
32 | </td> |
|
33 | </td> | |
33 | </tr> |
|
34 | </tr> | |
34 | </table> |
|
35 | </table> | |
35 | \endraw |
|
36 | \endraw | |
36 | */ |
|
37 | */ |
@@ -1,44 +1,45 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page index.html |
|
2 | \page index.html | |
3 | \keyword About |
|
3 | \keyword About | |
4 |
|
4 | |||
5 | \raw HTML |
|
5 | \raw HTML | |
6 | <div class="qchart"> |
|
6 | <div class="qchart"> | |
7 | <img src="images/qt_commercial_logo.png" alt="qtcommercial"/> |
|
7 | <img src="images/qt_commercial_logo.png" alt="qtcommercial"/> | |
8 |
|
8 | |||
9 | <p> |
|
9 | <p> | |
10 | QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart |
|
10 | QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart | |
11 | components which are available for Qt Commercial customers. It uses Qt Graphics View |
|
11 | components which are available for Qt Commercial customers. It uses Qt Graphics View | |
12 | Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can |
|
12 | Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can | |
13 | be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive |
|
13 | be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive | |
14 | graphs by selecting one of the charts themes. |
|
14 | graphs by selecting one of the charts themes. | |
15 | </p> |
|
15 | </p> | |
16 |
|
16 | |||
17 | <table> |
|
17 | <table> | |
18 | <tr> |
|
18 | <tr> | |
19 | <td><a href="examples-linechart.html"><img src="images/examples_linechart.png" width="440" alt="linechart" /></a></td> |
|
19 | <td><a href="examples-linechart.html"><img src="images/examples_linechart.png" width="440" alt="linechart" /></a></td> | |
20 | <td><a href="examples-areachart.html"><img src="images/examples_areachart.png" width="440" alt="areachart" /></a></td> |
|
20 | <td><a href="examples-areachart.html"><img src="images/examples_areachart.png" width="440" alt="areachart" /></a></td> | |
21 | </tr> |
|
21 | </tr> | |
22 | <tr> |
|
22 | <tr> | |
23 | <td><a href="examples-scatterchart.html"><img src="images/examples_scatterchart.png" width="440" alt="scatterchart" /></a></td> |
|
23 | <td><a href="examples-scatterchart.html"><img src="images/examples_scatterchart.png" width="440" alt="scatterchart" /></a></td> | |
24 | <td><a href="examples-barchart.html"><img src="images/examples_barchart.png" width="440" alt="barchart" /></a></td> |
|
24 | <td><a href="examples-barchart.html"><img src="images/examples_barchart.png" width="440" alt="barchart" /></a></td> | |
25 | </tr> |
|
25 | </tr> | |
26 | <tr> |
|
26 | <tr> | |
|
27 | <td><a href="examples-groupedbarchart.html"><img src="images/examples_groupedbarchart.png" width="440" alt="groupedbarcchart" /></a></td> | |||
27 | <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="440" alt="stackedbarchart" /></a></td> |
|
28 | <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="440" alt="stackedbarchart" /></a></td> | |
28 | <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="440" alt="percentbarcchart" /></a></td> |
|
|||
29 | </tr> |
|
29 | </tr> | |
30 | <tr> |
|
30 | <tr> | |
|
31 | <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="440" alt="percentbarcchart" /></a></td> | |||
31 | <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="440" alt="linechart" /></a></td> |
|
32 | <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="440" alt="linechart" /></a></td> | |
32 | <td><a href="examples-piechart.html"><img src="images/examples_piechart.png" width="440" alt="piechart" /></a></td> |
|
|||
33 | </tr> |
|
33 | </tr> | |
34 | <tr> |
|
34 | <tr> | |
35 | <td><a href="examples-customchart.html"><img src="images/examples_customchart.png" width="440" alt="customerchart" /></a></td> |
|
35 | <td><a href="examples-customchart.html"><img src="images/examples_customchart.png" width="440" alt="customerchart" /></a></td> | |
36 |
<td><a href="examples- |
|
36 | <td><a href="examples-piechart.html"><img src="images/examples_piechart.png" width="440" alt="piechart" /></a></td> | |
37 | </tr> |
|
37 | </tr> | |
38 | <tr> |
|
38 | <tr> | |
39 | <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width=440 alt="charttheme" /></a></td> |
|
39 | <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width=440 alt="charttheme" /></a></td> | |
|
40 | <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart2.png" width="440" alt="zoomlinechart" /></a></td> | |||
40 | </tr> |
|
41 | </tr> | |
41 | </table> |
|
42 | </table> | |
42 | </div> |
|
43 | </div> | |
43 | \endraw |
|
44 | \endraw | |
44 | */ |
|
45 | */ |
@@ -1,89 +1,82 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSeries> |
|
24 | #include <QBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
|||
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
|||
37 | //![1] |
|
|||
38 |
|
||||
39 | //![2] |
|
|||
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
35 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
36 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
37 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
38 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
39 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
40 | |||
46 | *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.4, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6); |
|
41 | *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.4, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6); | |
47 | *set1 << QPointF(0.1, 2) << QPointF(1.2, 3) << QPointF(2.45, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7); |
|
42 | *set1 << QPointF(0.1, 2) << QPointF(1.2, 3) << QPointF(2.45, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7); | |
48 | *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8); |
|
43 | *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8); | |
49 | *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9); |
|
44 | *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9); | |
50 | *set4 << QPointF(0.4, 5) << QPointF(1.8, 6) << QPointF(2.6, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10); |
|
45 | *set4 << QPointF(0.4, 5) << QPointF(1.8, 6) << QPointF(2.6, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10); | |
51 |
//![ |
|
46 | //![1] | |
52 |
|
47 | |||
53 |
//![ |
|
48 | //![2] | |
54 | QBarSeries* series = new QBarSeries(); |
|
49 | QBarSeries* series = new QBarSeries(); | |
55 | series->setCategories(categories); |
|
|||
56 | series->append(set0); |
|
50 | series->append(set0); | |
57 | series->append(set1); |
|
51 | series->append(set1); | |
58 | series->append(set2); |
|
52 | series->append(set2); | |
59 | series->append(set3); |
|
53 | series->append(set3); | |
60 | series->append(set4); |
|
54 | series->append(set4); | |
|
55 | //![2] | |||
61 |
|
56 | |||
62 | //![3] |
|
57 | //![3] | |
63 |
|
||||
64 | //![4] |
|
|||
65 | QChart* chart = new QChart(); |
|
58 | QChart* chart = new QChart(); | |
66 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
67 | chart->setTitle("Simple barchart example"); |
|
60 | chart->setTitle("Simple barchart example"); | |
68 |
//![ |
|
61 | //![3] | |
69 |
|
62 | |||
70 |
//![ |
|
63 | //![4] | |
71 | chart->legend()->setVisible(true); |
|
64 | chart->legend()->setVisible(true); | |
72 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
65 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
73 | chart->axisY()->setNiceNumbersEnabled(true); |
|
66 | chart->axisY()->setNiceNumbersEnabled(true); | |
74 |
//![ |
|
67 | //![4] | |
75 |
|
68 | |||
76 |
//![ |
|
69 | //![5] | |
77 | QChartView* chartView = new QChartView(chart); |
|
70 | QChartView* chartView = new QChartView(chart); | |
78 | chartView->setRenderHint(QPainter::Antialiasing); |
|
71 | chartView->setRenderHint(QPainter::Antialiasing); | |
79 |
//![ |
|
72 | //![5] | |
80 |
|
73 | |||
81 |
//![ |
|
74 | //![6] | |
82 | QMainWindow window; |
|
75 | QMainWindow window; | |
83 | window.setCentralWidget(chartView); |
|
76 | window.setCentralWidget(chartView); | |
84 | window.resize(400, 300); |
|
77 | window.resize(400, 300); | |
85 | window.show(); |
|
78 | window.show(); | |
86 |
//![ |
|
79 | //![6] | |
87 |
|
80 | |||
88 | return a.exec(); |
|
81 | return a.exec(); | |
89 | } |
|
82 | } |
@@ -1,608 +1,654 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | #include <QAbstractItemModel> |
|
31 | #include <QAbstractItemModel> | |
32 | #include <QModelIndex> |
|
32 | #include <QModelIndex> | |
33 | #include <QBarModelMapper> |
|
33 | #include <QBarModelMapper> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \class QBarSeries |
|
38 | \class QBarSeries | |
39 | \brief part of QtCommercial chart API. |
|
39 | \brief part of QtCommercial chart API. | |
40 | \mainclass |
|
40 | \mainclass | |
41 |
|
41 | |||
42 |
QBarSeries represents a series of data shown as bars. |
|
42 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
43 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
43 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
44 | by QStringList. |
|
44 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
|
45 | shows the x-values. | |||
45 |
|
46 | |||
46 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
47 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
47 | \image examples_barchart.png |
|
48 | \image examples_barchart.png | |
48 |
|
49 | |||
49 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
50 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
50 | */ |
|
51 | */ | |
51 |
|
52 | |||
52 | /*! |
|
53 | /*! | |
53 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
54 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) | |
54 |
|
55 | |||
55 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
56 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category | |
56 | contained by the series. |
|
57 | contained by the series. | |
57 | */ |
|
58 | */ | |
58 |
|
59 | |||
59 | /*! |
|
60 | /*! | |
60 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
61 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
61 |
|
62 | |||
62 | The signal is emitted if mouse is hovered on top of series. |
|
63 | The signal is emitted if mouse is hovered on top of series. | |
63 | Parameter \a barset is the pointer of barset, where hover happened. |
|
64 | Parameter \a barset is the pointer of barset, where hover happened. | |
64 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
65 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
65 | */ |
|
66 | */ | |
66 |
|
67 | |||
67 | /*! |
|
68 | /*! | |
68 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
69 | Constructs empty QBarSeries. | |
69 | QBarSeries is QObject which is a child of a \a parent. |
|
70 | QBarSeries is QObject which is a child of a \a parent. | |
70 | */ |
|
71 | */ | |
71 |
QBarSeries::QBarSeries( |
|
72 | QBarSeries::QBarSeries(QObject *parent) : | |
72 |
QAbstractSeries(*new QBarSeriesPrivate( |
|
73 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
73 | { |
|
74 | { | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | /*! |
|
77 | /*! | |
77 | Destructs barseries and owned barsets. |
|
78 | Destructs barseries and owned barsets. | |
78 | */ |
|
79 | */ | |
79 | QBarSeries::~QBarSeries() |
|
80 | QBarSeries::~QBarSeries() | |
80 | { |
|
81 | { | |
81 | // NOTE: d_ptr destroyed by QObject |
|
82 | // NOTE: d_ptr destroyed by QObject | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | /*! |
|
85 | /*! | |
85 | \internal |
|
86 | \internal | |
86 | */ |
|
87 | */ | |
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
88 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
88 | QAbstractSeries(d,parent) |
|
89 | QAbstractSeries(d,parent) | |
89 | { |
|
90 | { | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | /*! |
|
93 | /*! | |
93 | Returns the type of series. Derived classes override this. |
|
94 | Returns the type of series. Derived classes override this. | |
94 | */ |
|
95 | */ | |
95 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
96 | QAbstractSeries::SeriesType QBarSeries::type() const | |
96 | { |
|
97 | { | |
97 | return QAbstractSeries::SeriesTypeBar; |
|
98 | return QAbstractSeries::SeriesTypeBar; | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
|
101 | /*! | |||
|
102 | Sets the \a categories, which are used to to group the data. | |||
|
103 | */ | |||
100 | void QBarSeries::setCategories(QBarCategories categories) |
|
104 | void QBarSeries::setCategories(QBarCategories categories) | |
101 | { |
|
105 | { | |
102 | Q_D(QBarSeries); |
|
106 | Q_D(QBarSeries); | |
103 | d->setCategories(categories); |
|
107 | d->setCategories(categories); | |
104 | emit d->categoriesUpdated(); |
|
108 | emit d->categoriesUpdated(); | |
105 | } |
|
109 | } | |
106 |
|
110 | |||
107 | /*! |
|
111 | /*! | |
108 | Adds a set of bars to series. Takes ownership of \a set. |
|
112 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
|
113 | Returns true, if appending succeeded. | |||
|
114 | ||||
109 | */ |
|
115 | */ | |
110 | bool QBarSeries::append(QBarSet *set) |
|
116 | bool QBarSeries::append(QBarSet *set) | |
111 | { |
|
117 | { | |
112 | Q_D(QBarSeries); |
|
118 | Q_D(QBarSeries); | |
113 | if ((d->m_barSets.contains(set)) || (set == 0)) { |
|
119 | if ((d->m_barSets.contains(set)) || (set == 0)) { | |
114 | // Fail if set is already in list or set is null. |
|
120 | // Fail if set is already in list or set is null. | |
115 | return false; |
|
121 | return false; | |
116 | } |
|
122 | } | |
117 | d->m_barSets.append(set); |
|
123 | d->m_barSets.append(set); | |
118 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
124 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
119 | emit d->restructuredBars(); |
|
125 | emit d->restructuredBars(); | |
120 | return true; |
|
126 | return true; | |
121 | } |
|
127 | } | |
122 |
|
128 | |||
123 | /*! |
|
129 | /*! | |
124 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
130 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
|
131 | Returns true, if set was removed. | |||
125 | */ |
|
132 | */ | |
126 | bool QBarSeries::remove(QBarSet *set) |
|
133 | bool QBarSeries::remove(QBarSet *set) | |
127 | { |
|
134 | { | |
128 | Q_D(QBarSeries); |
|
135 | Q_D(QBarSeries); | |
129 | if (!d->m_barSets.contains(set)) { |
|
136 | if (!d->m_barSets.contains(set)) { | |
130 | // Fail if set is not in list |
|
137 | // Fail if set is not in list | |
131 | return false; |
|
138 | return false; | |
132 | } |
|
139 | } | |
133 | d->m_barSets.removeOne(set); |
|
140 | d->m_barSets.removeOne(set); | |
134 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
141 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
135 | emit d->restructuredBars(); |
|
142 | emit d->restructuredBars(); | |
136 | return true; |
|
143 | return true; | |
137 | } |
|
144 | } | |
138 |
|
145 | |||
139 | /*! |
|
146 | /*! | |
140 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
147 | Adds a list of barsets to series. Takes ownership of \a sets. | |
|
148 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |||
|
149 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |||
|
150 | and function returns false. | |||
141 | */ |
|
151 | */ | |
142 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
152 | bool QBarSeries::append(QList<QBarSet* > sets) | |
143 | { |
|
153 | { | |
144 | Q_D(QBarSeries); |
|
154 | Q_D(QBarSeries); | |
145 | foreach (QBarSet* set, sets) { |
|
155 | foreach (QBarSet* set, sets) { | |
146 | if ((set == 0) || (d->m_barSets.contains(set))) { |
|
156 | if ((set == 0) || (d->m_barSets.contains(set))) { | |
147 | // Fail if any of the sets is null or is already appended. |
|
157 | // Fail if any of the sets is null or is already appended. | |
148 | return false; |
|
158 | return false; | |
149 | } |
|
159 | } | |
150 | if (sets.count(set) != 1) { |
|
160 | if (sets.count(set) != 1) { | |
151 | // Also fail if same set is more than once in given list. |
|
161 | // Also fail if same set is more than once in given list. | |
152 | return false; |
|
162 | return false; | |
153 | } |
|
163 | } | |
154 | } |
|
164 | } | |
155 |
|
165 | |||
156 | foreach (QBarSet* set, sets) { |
|
166 | foreach (QBarSet* set, sets) { | |
157 | d->m_barSets.append(set); |
|
167 | d->m_barSets.append(set); | |
158 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
168 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
159 | } |
|
169 | } | |
160 | emit d->restructuredBars(); |
|
170 | emit d->restructuredBars(); | |
161 | return true; |
|
171 | return true; | |
162 | } |
|
172 | } | |
163 |
|
173 | |||
164 | /*! |
|
174 | /*! | |
165 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
175 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
166 | */ |
|
176 | */ | |
167 | bool QBarSeries::remove(QList<QBarSet* > sets) |
|
177 | bool QBarSeries::remove(QList<QBarSet* > sets) | |
168 | { |
|
178 | { | |
169 | Q_D(QBarSeries); |
|
179 | Q_D(QBarSeries); | |
170 |
|
180 | |||
171 | bool setsRemoved = false; |
|
181 | bool setsRemoved = false; | |
172 | foreach (QBarSet* set, sets) { |
|
182 | foreach (QBarSet* set, sets) { | |
173 | if (d->m_barSets.contains(set)) { |
|
183 | if (d->m_barSets.contains(set)) { | |
174 | d->m_barSets.removeOne(set); |
|
184 | d->m_barSets.removeOne(set); | |
175 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
185 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
176 | setsRemoved = true; |
|
186 | setsRemoved = true; | |
177 | } |
|
187 | } | |
178 | } |
|
188 | } | |
179 |
|
189 | |||
180 | if (setsRemoved) { |
|
190 | if (setsRemoved) { | |
181 | emit d->restructuredBars(); |
|
191 | emit d->restructuredBars(); | |
182 | } |
|
192 | } | |
183 | return setsRemoved; |
|
193 | return setsRemoved; | |
184 | } |
|
194 | } | |
185 |
|
195 | |||
186 | /*! |
|
196 | /*! | |
187 | Returns number of sets in series. |
|
197 | Returns number of sets in series. | |
188 | */ |
|
198 | */ | |
189 | int QBarSeries::barsetCount() const |
|
199 | int QBarSeries::barsetCount() const | |
190 | { |
|
200 | { | |
191 | Q_D(const QBarSeries); |
|
201 | Q_D(const QBarSeries); | |
192 | return d->m_barSets.count(); |
|
202 | return d->m_barSets.count(); | |
193 | } |
|
203 | } | |
194 |
|
204 | |||
195 | /*! |
|
205 | /*! | |
196 | Returns number of categories in series |
|
206 | Returns number of categories in series | |
197 | */ |
|
207 | */ | |
198 | int QBarSeries::categoryCount() const |
|
208 | int QBarSeries::categoryCount() const | |
199 | { |
|
209 | { | |
200 | Q_D(const QBarSeries); |
|
210 | Q_D(const QBarSeries); | |
201 |
return d-> |
|
211 | return d->categoryCount(); | |
202 | } |
|
212 | } | |
203 |
|
213 | |||
204 | /*! |
|
214 | /*! | |
205 | Returns a list of sets in series. Keeps ownership of sets. |
|
215 | Returns a list of sets in series. Keeps ownership of sets. | |
206 | */ |
|
216 | */ | |
207 | QList<QBarSet*> QBarSeries::barSets() const |
|
217 | QList<QBarSet*> QBarSeries::barSets() const | |
208 | { |
|
218 | { | |
209 | Q_D(const QBarSeries); |
|
219 | Q_D(const QBarSeries); | |
210 | return d->m_barSets; |
|
220 | return d->m_barSets; | |
211 | } |
|
221 | } | |
212 |
|
222 | |||
213 | /*! |
|
223 | /*! | |
214 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
224 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
215 | Sets the \a model to be used as a data source |
|
225 | Sets the \a model to be used as a data source | |
216 | */ |
|
226 | */ | |
217 | void QBarSeries::setModel(QAbstractItemModel *model) |
|
227 | void QBarSeries::setModel(QAbstractItemModel *model) | |
218 | { |
|
228 | { | |
219 | Q_D(QBarSeries); |
|
229 | Q_D(QBarSeries); | |
220 | // disconnect signals from old model |
|
230 | // disconnect signals from old model | |
221 | if(d->m_model) |
|
231 | if(d->m_model) | |
222 | { |
|
232 | { | |
223 | disconnect(d->m_model, 0, this, 0); |
|
233 | disconnect(d->m_model, 0, this, 0); | |
224 | } |
|
234 | } | |
225 |
|
235 | |||
226 | // set new model |
|
236 | // set new model | |
227 | if(model) |
|
237 | if(model) | |
228 | { |
|
238 | { | |
229 | d->m_model = model; |
|
239 | d->m_model = model; | |
230 |
|
240 | |||
231 | // connect the signals |
|
241 | // connect the signals | |
232 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
242 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
233 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
243 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
234 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
244 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
235 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
245 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
236 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
246 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
237 |
|
247 | |||
238 | if (d->m_mapper) |
|
248 | if (d->m_mapper) | |
239 | d->initializeDataFromModel(); |
|
249 | d->initializeDataFromModel(); | |
240 | } |
|
250 | } | |
241 | else |
|
251 | else | |
242 | { |
|
252 | { | |
243 | d->m_model = 0; |
|
253 | d->m_model = 0; | |
244 | } |
|
254 | } | |
245 | } |
|
255 | } | |
246 |
|
256 | |||
247 | void QBarSeries::setModelMapper(QBarModelMapper *mapper) |
|
257 | void QBarSeries::setModelMapper(QBarModelMapper *mapper) | |
248 | { |
|
258 | { | |
249 | Q_D(QBarSeries); |
|
259 | Q_D(QBarSeries); | |
250 | // disconnect signals from old mapper |
|
260 | // disconnect signals from old mapper | |
251 | if (d->m_mapper) { |
|
261 | if (d->m_mapper) { | |
252 | QObject::disconnect(d->m_mapper, 0, this, 0); |
|
262 | QObject::disconnect(d->m_mapper, 0, this, 0); | |
253 | } |
|
263 | } | |
254 |
|
264 | |||
255 | if (mapper) { |
|
265 | if (mapper) { | |
256 | d->m_mapper = mapper; |
|
266 | d->m_mapper = mapper; | |
257 | // connect the signal from the mapper |
|
267 | // connect the signal from the mapper | |
258 | connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializeDataFromModel())); |
|
268 | connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializeDataFromModel())); | |
259 |
|
269 | |||
260 | if (d->m_model) |
|
270 | if (d->m_model) | |
261 | d->initializeDataFromModel(); |
|
271 | d->initializeDataFromModel(); | |
262 | } else { |
|
272 | } else { | |
263 | d->m_mapper = 0; |
|
273 | d->m_mapper = 0; | |
264 | } |
|
274 | } | |
265 | } |
|
275 | } | |
266 |
|
276 | |||
267 | QBarModelMapper* QBarSeries::modelMapper() const |
|
277 | QBarModelMapper* QBarSeries::modelMapper() const | |
268 | { |
|
278 | { | |
269 | Q_D(const QBarSeries); |
|
279 | Q_D(const QBarSeries); | |
270 | return d->m_mapper; |
|
280 | return d->m_mapper; | |
271 | } |
|
281 | } | |
272 |
|
282 | |||
273 | /*! |
|
283 | /*! | |
274 | Returns the bar categories of the series. |
|
284 | Returns the bar categories of the series. | |
275 | */ |
|
285 | */ | |
276 | QBarCategories QBarSeries::categories() const |
|
286 | QBarCategories QBarSeries::categories() const | |
277 | { |
|
287 | { | |
278 | Q_D(const QBarSeries); |
|
288 | Q_D(const QBarSeries); | |
279 |
return d-> |
|
289 | return d->categories(); | |
280 | } |
|
290 | } | |
281 |
|
291 | |||
282 | /*! |
|
292 | /*! | |
283 | Sets the visibility of labels in series to \a visible |
|
293 | Sets the visibility of labels in series to \a visible | |
284 | */ |
|
294 | */ | |
285 | void QBarSeries::setLabelsVisible(bool visible) |
|
295 | void QBarSeries::setLabelsVisible(bool visible) | |
286 | { |
|
296 | { | |
287 | foreach (QBarSet* s, barSets()) { |
|
297 | foreach (QBarSet* s, barSets()) { | |
288 | s->setLabelsVisible(visible); |
|
298 | s->setLabelsVisible(visible); | |
289 | } |
|
299 | } | |
290 | } |
|
300 | } | |
291 |
|
301 | |||
292 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
302 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
293 |
|
303 | |||
294 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
304 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
295 | QAbstractSeriesPrivate(q), |
|
305 | QAbstractSeriesPrivate(q), | |
296 | m_barMargin(0.05), // Default value is 5% of category width |
|
306 | m_barMargin(0.05), // Default value is 5% of category width | |
297 | m_mapper(0) |
|
307 | m_mapper(0) | |
298 | // m_categories(categories), |
|
|||
299 | { |
|
308 | { | |
300 | } |
|
309 | } | |
301 |
|
310 | |||
302 | void QBarSeriesPrivate::setCategories(QBarCategories categories) |
|
311 | void QBarSeriesPrivate::setCategories(QBarCategories categories) | |
303 | { |
|
312 | { | |
304 | m_categories = categories; |
|
313 | m_categories = categories; | |
305 | } |
|
314 | } | |
306 |
|
315 | |||
|
316 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |||
|
317 | { | |||
|
318 | m_categories.insert(index, category); | |||
|
319 | emit categoriesUpdated(); | |||
|
320 | } | |||
|
321 | ||||
|
322 | void QBarSeriesPrivate::removeCategory(int index) | |||
|
323 | { | |||
|
324 | m_categories.removeAt(index); | |||
|
325 | emit categoriesUpdated(); | |||
|
326 | } | |||
|
327 | ||||
|
328 | int QBarSeriesPrivate::categoryCount() const | |||
|
329 | { | |||
|
330 | if (m_categories.count() > 0) { | |||
|
331 | return m_categories.count(); | |||
|
332 | } | |||
|
333 | ||||
|
334 | // No categories defined. return count of longest set. | |||
|
335 | int count = 0; | |||
|
336 | for (int i=0; i<m_barSets.count(); i++) { | |||
|
337 | if (m_barSets.at(i)->count() > count) { | |||
|
338 | count = m_barSets.at(i)->count(); | |||
|
339 | } | |||
|
340 | } | |||
|
341 | ||||
|
342 | return count; | |||
|
343 | } | |||
|
344 | ||||
|
345 | QBarCategories QBarSeriesPrivate::categories() const | |||
|
346 | { | |||
|
347 | if (m_categories.count() > 0) { | |||
|
348 | return m_categories; | |||
|
349 | } | |||
|
350 | ||||
|
351 | // No categories defined. retun list of indices. | |||
|
352 | QBarCategories categories; | |||
|
353 | ||||
|
354 | int count = categoryCount(); | |||
|
355 | for (int i = 0; i < count; i++) { | |||
|
356 | categories.append(QString::number(i)); | |||
|
357 | } | |||
|
358 | return categories; | |||
|
359 | } | |||
|
360 | ||||
307 | void QBarSeriesPrivate::setBarMargin(qreal margin) |
|
361 | void QBarSeriesPrivate::setBarMargin(qreal margin) | |
308 | { |
|
362 | { | |
309 | if (margin > 1.0) { |
|
363 | if (margin > 1.0) { | |
310 | margin = 1.0; |
|
364 | margin = 1.0; | |
311 | } else if (margin < 0.0) { |
|
365 | } else if (margin < 0.0) { | |
312 | margin = 0.0; |
|
366 | margin = 0.0; | |
313 | } |
|
367 | } | |
314 |
|
368 | |||
315 | m_barMargin = margin; |
|
369 | m_barMargin = margin; | |
316 | emit updatedBars(); |
|
370 | emit updatedBars(); | |
317 | } |
|
371 | } | |
318 |
|
372 | |||
319 | qreal QBarSeriesPrivate::barMargin() |
|
373 | qreal QBarSeriesPrivate::barMargin() | |
320 | { |
|
374 | { | |
321 | return m_barMargin; |
|
375 | return m_barMargin; | |
322 | } |
|
376 | } | |
323 |
|
377 | |||
324 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
378 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
325 | { |
|
379 | { | |
326 | return m_barSets.at(index); |
|
380 | return m_barSets.at(index); | |
327 | } |
|
381 | } | |
328 |
|
382 | |||
329 | QString QBarSeriesPrivate::categoryName(int category) |
|
383 | QString QBarSeriesPrivate::categoryName(int category) | |
330 | { |
|
384 | { | |
|
385 | if ((category > 0) && (category < m_categories.count())) { | |||
331 | return m_categories.at(category); |
|
386 | return m_categories.at(category); | |
332 | } |
|
387 | } | |
333 |
|
388 | |||
|
389 | return QString::number(category); | |||
|
390 | } | |||
|
391 | ||||
334 | qreal QBarSeriesPrivate::min() |
|
392 | qreal QBarSeriesPrivate::min() | |
335 | { |
|
393 | { | |
336 | if (m_barSets.count() <= 0) { |
|
394 | if (m_barSets.count() <= 0) { | |
337 | return 0; |
|
395 | return 0; | |
338 | } |
|
396 | } | |
339 | qreal min = INT_MAX; |
|
397 | qreal min = INT_MAX; | |
340 |
|
398 | |||
341 | for (int i = 0; i < m_barSets.count(); i++) { |
|
399 | for (int i = 0; i < m_barSets.count(); i++) { | |
342 | int categoryCount = m_barSets.at(i)->count(); |
|
400 | int categoryCount = m_barSets.at(i)->count(); | |
343 | for (int j = 0; j < categoryCount; j++) { |
|
401 | for (int j = 0; j < categoryCount; j++) { | |
344 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
402 | qreal temp = m_barSets.at(i)->at(j).y(); | |
345 | if (temp < min) |
|
403 | if (temp < min) | |
346 | min = temp; |
|
404 | min = temp; | |
347 | } |
|
405 | } | |
348 | } |
|
406 | } | |
349 | return min; |
|
407 | return min; | |
350 | } |
|
408 | } | |
351 |
|
409 | |||
352 | qreal QBarSeriesPrivate::max() |
|
410 | qreal QBarSeriesPrivate::max() | |
353 | { |
|
411 | { | |
354 | if (m_barSets.count() <= 0) { |
|
412 | if (m_barSets.count() <= 0) { | |
355 | return 0; |
|
413 | return 0; | |
356 | } |
|
414 | } | |
357 | qreal max = INT_MIN; |
|
415 | qreal max = INT_MIN; | |
358 |
|
416 | |||
359 | for (int i = 0; i < m_barSets.count(); i++) { |
|
417 | for (int i = 0; i < m_barSets.count(); i++) { | |
360 | int categoryCount = m_barSets.at(i)->count(); |
|
418 | int categoryCount = m_barSets.at(i)->count(); | |
361 | for (int j = 0; j < categoryCount; j++) { |
|
419 | for (int j = 0; j < categoryCount; j++) { | |
362 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
420 | qreal temp = m_barSets.at(i)->at(j).y(); | |
363 | if (temp > max) |
|
421 | if (temp > max) | |
364 | max = temp; |
|
422 | max = temp; | |
365 | } |
|
423 | } | |
366 | } |
|
424 | } | |
367 |
|
425 | |||
368 | return max; |
|
426 | return max; | |
369 | } |
|
427 | } | |
370 |
|
428 | |||
371 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
429 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
372 | { |
|
430 | { | |
373 | if ((set < 0) || (set >= m_barSets.count())) { |
|
431 | if ((set < 0) || (set >= m_barSets.count())) { | |
374 | // No set, no value. |
|
432 | // No set, no value. | |
375 | return 0; |
|
433 | return 0; | |
376 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
434 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
377 | // No category, no value. |
|
435 | // No category, no value. | |
378 | return 0; |
|
436 | return 0; | |
379 | } |
|
437 | } | |
380 |
|
438 | |||
381 | return m_barSets.at(set)->at(category).y(); |
|
439 | return m_barSets.at(set)->at(category).y(); | |
382 | } |
|
440 | } | |
383 |
|
441 | |||
384 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
442 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
385 | { |
|
443 | { | |
386 | if ((set < 0) || (set >= m_barSets.count())) { |
|
444 | if ((set < 0) || (set >= m_barSets.count())) { | |
387 | // No set, no value. |
|
445 | // No set, no value. | |
388 | return 0; |
|
446 | return 0; | |
389 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
447 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
390 | // No category, no value. |
|
448 | // No category, no value. | |
391 | return 0; |
|
449 | return 0; | |
392 | } |
|
450 | } | |
393 |
|
451 | |||
394 | qreal value = m_barSets.at(set)->at(category).y(); |
|
452 | qreal value = m_barSets.at(set)->at(category).y(); | |
395 | qreal sum = categorySum(category); |
|
453 | qreal sum = categorySum(category); | |
396 | if ( qFuzzyIsNull(sum) ) { |
|
454 | if ( qFuzzyIsNull(sum) ) { | |
397 | return 0; |
|
455 | return 0; | |
398 | } |
|
456 | } | |
399 |
|
457 | |||
400 | return value / sum; |
|
458 | return value / sum; | |
401 | } |
|
459 | } | |
402 |
|
460 | |||
403 | qreal QBarSeriesPrivate::categorySum(int category) |
|
461 | qreal QBarSeriesPrivate::categorySum(int category) | |
404 | { |
|
462 | { | |
405 | qreal sum(0); |
|
463 | qreal sum(0); | |
406 | int count = m_barSets.count(); // Count sets |
|
464 | int count = m_barSets.count(); // Count sets | |
407 | for (int set = 0; set < count; set++) { |
|
465 | for (int set = 0; set < count; set++) { | |
408 | if (category < m_barSets.at(set)->count()) |
|
466 | if (category < m_barSets.at(set)->count()) | |
409 | sum += m_barSets.at(set)->at(category).y(); |
|
467 | sum += m_barSets.at(set)->at(category).y(); | |
410 | } |
|
468 | } | |
411 | return sum; |
|
469 | return sum; | |
412 | } |
|
470 | } | |
413 |
|
471 | |||
414 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
472 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
415 | { |
|
473 | { | |
416 | qreal sum(0); |
|
474 | qreal sum(0); | |
417 | int count = m_barSets.count(); // Count sets |
|
475 | int count = m_barSets.count(); // Count sets | |
418 | for (int set = 0; set < count; set++) { |
|
476 | for (int set = 0; set < count; set++) { | |
419 | if (category < m_barSets.at(set)->count()) |
|
477 | if (category < m_barSets.at(set)->count()) | |
420 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
478 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
421 | } |
|
479 | } | |
422 | return sum; |
|
480 | return sum; | |
423 | } |
|
481 | } | |
424 |
|
482 | |||
425 | qreal QBarSeriesPrivate::maxCategorySum() |
|
483 | qreal QBarSeriesPrivate::maxCategorySum() | |
426 | { |
|
484 | { | |
427 | qreal max = INT_MIN; |
|
485 | qreal max = INT_MIN; | |
428 |
int count = |
|
486 | int count = categoryCount(); | |
429 | for (int i = 0; i < count; i++) { |
|
487 | for (int i = 0; i < count; i++) { | |
430 | qreal sum = categorySum(i); |
|
488 | qreal sum = categorySum(i); | |
431 | if (sum > max) |
|
489 | if (sum > max) | |
432 | max = sum; |
|
490 | max = sum; | |
433 | } |
|
491 | } | |
434 | return max; |
|
492 | return max; | |
435 | } |
|
493 | } | |
436 |
|
494 | |||
437 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
495 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
438 | { |
|
496 | { | |
439 | if (m_model == 0 || m_mapper == 0) |
|
497 | if (m_model == 0 || m_mapper == 0) | |
440 | return; |
|
498 | return; | |
441 |
|
499 | |||
442 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
500 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
443 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
501 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
444 | if (m_mapper->orientation() == Qt::Vertical) |
|
502 | if (m_mapper->orientation() == Qt::Vertical) | |
445 | { |
|
503 | { | |
446 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
504 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
447 | if ( row >= m_mapper->first() && (m_mapper->count() == - 1 || row < m_mapper->first() + m_mapper->count())) { |
|
505 | if ( row >= m_mapper->first() && (m_mapper->count() == - 1 || row < m_mapper->first() + m_mapper->count())) { | |
448 | if (column >= m_mapper->mapBarBottom() && column <= m_mapper->mapBarTop()) |
|
506 | if (column >= m_mapper->mapBarBottom() && column <= m_mapper->mapBarTop()) | |
449 | barsetAt(column - m_mapper->mapBarBottom())->replace(row - m_mapper->first(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
507 | barsetAt(column - m_mapper->mapBarBottom())->replace(row - m_mapper->first(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
450 | // if (column == m_mapper->mapCategories());// TODO: |
|
508 | // if (column == m_mapper->mapCategories());// TODO: | |
451 | } |
|
509 | } | |
452 | } |
|
510 | } | |
453 | else |
|
511 | else | |
454 | { |
|
512 | { | |
455 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
513 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
456 | if (column >= m_mapper->first() && (m_mapper->count() == - 1 || column < m_mapper->first() + m_mapper->count())) { |
|
514 | if (column >= m_mapper->first() && (m_mapper->count() == - 1 || column < m_mapper->first() + m_mapper->count())) { | |
457 | if (row >= m_mapper->mapBarBottom() && row <= m_mapper->mapBarTop()) |
|
515 | if (row >= m_mapper->mapBarBottom() && row <= m_mapper->mapBarTop()) | |
458 | barsetAt(row - m_mapper->mapBarBottom())->replace(column - m_mapper->first(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
516 | barsetAt(row - m_mapper->mapBarBottom())->replace(column - m_mapper->first(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
459 | // if (row == m_mapper->mapCategories());// TODO: |
|
517 | // if (row == m_mapper->mapCategories());// TODO: | |
460 | } |
|
518 | } | |
461 | } |
|
519 | } | |
462 | } |
|
520 | } | |
463 | } |
|
521 | } | |
464 | } |
|
522 | } | |
465 |
|
523 | |||
466 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
524 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
467 | { |
|
525 | { | |
468 | Q_UNUSED(parent); |
|
526 | Q_UNUSED(parent); | |
469 | Q_UNUSED(start); |
|
527 | Q_UNUSED(start); | |
470 | Q_UNUSED(end); |
|
528 | Q_UNUSED(end); | |
471 | initializeDataFromModel(); |
|
529 | initializeDataFromModel(); | |
472 | } |
|
530 | } | |
473 |
|
531 | |||
474 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
532 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
475 | { |
|
533 | { | |
476 | Q_UNUSED(parent); |
|
534 | Q_UNUSED(parent); | |
477 | Q_UNUSED(start); |
|
535 | Q_UNUSED(start); | |
478 | Q_UNUSED(end); |
|
536 | Q_UNUSED(end); | |
479 | initializeDataFromModel(); |
|
537 | initializeDataFromModel(); | |
480 | } |
|
538 | } | |
481 |
|
539 | |||
482 | void QBarSeriesPrivate::initializeDataFromModel() |
|
540 | void QBarSeriesPrivate::initializeDataFromModel() | |
483 | { |
|
541 | { | |
484 | Q_Q(QBarSeries); |
|
542 | Q_Q(QBarSeries); | |
485 |
|
543 | |||
486 | // create the initial bars |
|
544 | // create the initial bars | |
487 | m_categories.clear(); |
|
545 | m_categories.clear(); | |
488 | m_barSets.clear(); |
|
546 | m_barSets.clear(); | |
489 |
|
547 | |||
490 | if (m_model == 0 || m_mapper == 0) |
|
548 | if (m_model == 0 || m_mapper == 0) | |
491 | return; |
|
549 | return; | |
492 |
|
550 | |||
493 | // check if mappings are set |
|
551 | // check if mappings are set | |
494 | if (m_mapper->mapBarBottom() == -1 || m_mapper->mapBarTop() == -1 || m_mapper->mapCategories() == -1) |
|
552 | if (m_mapper->mapBarBottom() == -1 || m_mapper->mapBarTop() == -1 || m_mapper->mapCategories() == -1) | |
495 | return; |
|
553 | return; | |
496 |
|
554 | |||
497 | // emit restructuredBars(); |
|
555 | // emit restructuredBars(); | |
498 | if (m_mapper->orientation() == Qt::Vertical) { |
|
556 | if (m_mapper->orientation() == Qt::Vertical) { | |
499 | if (m_mapCategories >= m_model->columnCount()) |
|
557 | if (m_mapCategories >= m_model->columnCount()) | |
500 | return; |
|
558 | return; | |
501 | int rowCount = 0; |
|
559 | int rowCount = 0; | |
502 | if(m_mapper->count() == -1) |
|
560 | if(m_mapper->count() == -1) | |
503 | rowCount = m_model->rowCount() - m_mapper->first(); |
|
561 | rowCount = m_model->rowCount() - m_mapper->first(); | |
504 | else |
|
562 | else | |
505 | rowCount = qMin(m_mapper->count(), m_model->rowCount() - m_mapper->first()); |
|
563 | rowCount = qMin(m_mapper->count(), m_model->rowCount() - m_mapper->first()); | |
506 | for (int k = m_mapper->first(); k < m_mapper->first() + rowCount; k++) { |
|
564 | for (int k = m_mapper->first(); k < m_mapper->first() + rowCount; k++) { | |
507 | m_categories << m_model->data(m_model->index(k, m_mapper->mapCategories()), Qt::DisplayRole).toString(); |
|
565 | m_categories << m_model->data(m_model->index(k, m_mapper->mapCategories()), Qt::DisplayRole).toString(); | |
508 | } |
|
566 | } | |
509 |
|
567 | |||
510 | int lastAvailableBarSet = qMin(m_model->columnCount() - 1, m_mapper->mapBarTop()); |
|
568 | int lastAvailableBarSet = qMin(m_model->columnCount() - 1, m_mapper->mapBarTop()); | |
511 | for (int i = m_mapper->mapBarBottom(); i <= lastAvailableBarSet; i++) { |
|
569 | for (int i = m_mapper->mapBarBottom(); i <= lastAvailableBarSet; i++) { | |
512 | // for (int i = m_mapper->mapBarBottom(); i <= m_mapper->mapBarTop(); i++) { |
|
570 | // for (int i = m_mapper->mapBarBottom(); i <= m_mapper->mapBarTop(); i++) { | |
513 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
571 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
514 | for(int m = m_mapper->first(); m < m_mapper->first() + rowCount; m++) |
|
572 | for(int m = m_mapper->first(); m < m_mapper->first() + rowCount; m++) | |
515 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
573 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
516 | q->append(barSet); |
|
574 | q->append(barSet); | |
517 | } |
|
575 | } | |
518 | } else { |
|
576 | } else { | |
519 | if (m_mapCategories >= m_model->rowCount()) |
|
577 | if (m_mapCategories >= m_model->rowCount()) | |
520 | return; |
|
578 | return; | |
521 | int columnCount = 0; |
|
579 | int columnCount = 0; | |
522 | if(m_mapper->count() == -1) |
|
580 | if(m_mapper->count() == -1) | |
523 | columnCount = m_model->columnCount() - m_mapper->first(); |
|
581 | columnCount = m_model->columnCount() - m_mapper->first(); | |
524 | else |
|
582 | else | |
525 | columnCount = qMin(m_mapper->count(), m_model->columnCount() - m_mapper->first()); |
|
583 | columnCount = qMin(m_mapper->count(), m_model->columnCount() - m_mapper->first()); | |
526 | for (int k = m_mapper->first(); k < m_mapper->first() + columnCount; k++) { |
|
584 | for (int k = m_mapper->first(); k < m_mapper->first() + columnCount; k++) { | |
527 | m_categories << m_model->data(m_model->index(m_mapper->mapCategories(), k), Qt::DisplayRole).toString(); |
|
585 | m_categories << m_model->data(m_model->index(m_mapper->mapCategories(), k), Qt::DisplayRole).toString(); | |
528 | } |
|
586 | } | |
529 |
|
587 | |||
530 | int lastAvailableBarSet = qMin(m_model->rowCount() - 1, m_mapper->mapBarTop()); |
|
588 | int lastAvailableBarSet = qMin(m_model->rowCount() - 1, m_mapper->mapBarTop()); | |
531 | for (int i = m_mapper->mapBarBottom(); i <= lastAvailableBarSet; i++) { |
|
589 | for (int i = m_mapper->mapBarBottom(); i <= lastAvailableBarSet; i++) { | |
532 | // for (int i = m_mapper->mapBarBottom(); i <= m_mapper->mapBarTop(); i++) { |
|
590 | // for (int i = m_mapper->mapBarBottom(); i <= m_mapper->mapBarTop(); i++) { | |
533 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
591 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
534 | for(int m = m_mapper->first(); m < m_mapper->first() + columnCount; m++) |
|
592 | for(int m = m_mapper->first(); m < m_mapper->first() + columnCount; m++) | |
535 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
593 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
536 | q->append(barSet); |
|
594 | q->append(barSet); | |
537 | } |
|
595 | } | |
538 | } |
|
596 | } | |
539 | emit restructuredBars(); |
|
597 | emit restructuredBars(); | |
540 | // emit updatedBars(); |
|
598 | // emit updatedBars(); | |
541 | } |
|
599 | } | |
542 |
|
600 | |||
543 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
|||
544 | { |
|
|||
545 | m_categories.insert(index, category); |
|
|||
546 | emit categoriesUpdated(); |
|
|||
547 | } |
|
|||
548 |
|
||||
549 | void QBarSeriesPrivate::removeCategory(int index) |
|
|||
550 | { |
|
|||
551 | m_categories.removeAt(index); |
|
|||
552 | emit categoriesUpdated(); |
|
|||
553 | } |
|
|||
554 |
|
||||
555 | void QBarSeriesPrivate::barsetChanged() |
|
601 | void QBarSeriesPrivate::barsetChanged() | |
556 | { |
|
602 | { | |
557 | emit updatedBars(); |
|
603 | emit updatedBars(); | |
558 | } |
|
604 | } | |
559 |
|
605 | |||
560 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
606 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
561 | { |
|
607 | { | |
562 | qreal minX(domain.minX()); |
|
608 | qreal minX(domain.minX()); | |
563 | qreal minY(domain.minY()); |
|
609 | qreal minY(domain.minY()); | |
564 | qreal maxX(domain.maxX()); |
|
610 | qreal maxX(domain.maxX()); | |
565 | qreal maxY(domain.maxY()); |
|
611 | qreal maxY(domain.maxY()); | |
566 | int tickXCount(domain.tickXCount()); |
|
612 | int tickXCount(domain.tickXCount()); | |
567 | int tickYCount(domain.tickYCount()); |
|
613 | int tickYCount(domain.tickYCount()); | |
568 |
|
614 | |||
569 |
qreal x = |
|
615 | qreal x = categoryCount(); | |
570 | qreal y = max(); |
|
616 | qreal y = max(); | |
571 | minX = qMin(minX, x); |
|
617 | minX = qMin(minX, x); | |
572 | minY = qMin(minY, y); |
|
618 | minY = qMin(minY, y); | |
573 | maxX = qMax(maxX, x); |
|
619 | maxX = qMax(maxX, x); | |
574 | maxY = qMax(maxY, y); |
|
620 | maxY = qMax(maxY, y); | |
575 | tickXCount = x+1; |
|
621 | tickXCount = x+1; | |
576 |
|
622 | |||
577 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
623 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
578 | } |
|
624 | } | |
579 |
|
625 | |||
580 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
626 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
581 | { |
|
627 | { | |
582 | Q_Q(QBarSeries); |
|
628 | Q_Q(QBarSeries); | |
583 |
|
629 | |||
584 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
630 | BarChartItem* bar = new BarChartItem(q,presenter); | |
585 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
631 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
586 | presenter->animator()->addAnimation(bar); |
|
632 | presenter->animator()->addAnimation(bar); | |
587 | } |
|
633 | } | |
588 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
634 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
589 | return bar; |
|
635 | return bar; | |
590 |
|
636 | |||
591 | } |
|
637 | } | |
592 |
|
638 | |||
593 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
639 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
594 | { |
|
640 | { | |
595 | Q_Q(QBarSeries); |
|
641 | Q_Q(QBarSeries); | |
596 | QList<LegendMarker*> markers; |
|
642 | QList<LegendMarker*> markers; | |
597 | foreach(QBarSet* set, q->barSets()) { |
|
643 | foreach(QBarSet* set, q->barSets()) { | |
598 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
644 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
599 | markers << marker; |
|
645 | markers << marker; | |
600 | } |
|
646 | } | |
601 |
|
647 | |||
602 | return markers; |
|
648 | return markers; | |
603 | } |
|
649 | } | |
604 |
|
650 | |||
605 | #include "moc_qbarseries.cpp" |
|
651 | #include "moc_qbarseries.cpp" | |
606 | #include "moc_qbarseries_p.cpp" |
|
652 | #include "moc_qbarseries_p.cpp" | |
607 |
|
653 | |||
608 | QTCOMMERCIALCHART_END_NAMESPACE |
|
654 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,81 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | class QModelIndex; |
|
27 | class QModelIndex; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | typedef QStringList QBarCategories; |
|
31 | typedef QStringList QBarCategories; | |
32 |
|
32 | |||
33 | class QBarSet; |
|
33 | class QBarSet; | |
34 | class BarCategory; |
|
34 | class BarCategory; | |
35 | class QBarSeriesPrivate; |
|
35 | class QBarSeriesPrivate; | |
36 | class QBarModelMapper; |
|
36 | class QBarModelMapper; | |
37 |
|
37 | |||
38 | // Container for series |
|
38 | // Container for series | |
39 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
39 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 | public: |
|
42 | public: | |
43 | explicit QBarSeries(QObject *parent = 0); |
|
43 | explicit QBarSeries(QObject *parent = 0); | |
44 | virtual ~QBarSeries(); |
|
44 | virtual ~QBarSeries(); | |
45 |
|
45 | |||
46 | QAbstractSeries::SeriesType type() const; |
|
46 | QAbstractSeries::SeriesType type() const; | |
47 | void setCategories(QBarCategories categories); |
|
47 | void setCategories(QBarCategories categories); | |
48 |
|
48 | |||
49 |
bool append(QBarSet *set); |
|
49 | bool append(QBarSet *set); | |
50 | bool remove(QBarSet *set); // Releases ownership, doesn't delete set |
|
50 | bool remove(QBarSet *set); | |
51 | bool append(QList<QBarSet* > sets); |
|
51 | bool append(QList<QBarSet* > sets); | |
52 | bool remove(QList<QBarSet* > sets); |
|
52 | bool remove(QList<QBarSet* > sets); | |
53 | int barsetCount() const; |
|
53 | int barsetCount() const; | |
54 | int categoryCount() const; |
|
54 | int categoryCount() const; | |
55 | QList<QBarSet*> barSets() const; |
|
55 | QList<QBarSet*> barSets() const; | |
56 | QBarCategories categories() const; |
|
56 | QBarCategories categories() const; | |
57 |
|
57 | |||
58 | void setLabelsVisible(bool visible = true); |
|
58 | void setLabelsVisible(bool visible = true); | |
59 |
|
59 | |||
60 | void setModel(QAbstractItemModel *model); |
|
60 | void setModel(QAbstractItemModel *model); | |
61 | void setModelMapper(QBarModelMapper *mapper); |
|
61 | void setModelMapper(QBarModelMapper *mapper); | |
62 | QBarModelMapper* modelMapper() const; |
|
62 | QBarModelMapper* modelMapper() const; | |
63 |
|
63 | |||
64 | protected: |
|
64 | protected: | |
65 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
65 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); | |
66 |
|
66 | |||
67 | Q_SIGNALS: |
|
67 | Q_SIGNALS: | |
68 | void clicked(QBarSet *barset, QString category); |
|
68 | void clicked(QBarSet *barset, QString category); | |
69 | void hovered(QBarSet* barset, bool status); |
|
69 | void hovered(QBarSet* barset, bool status); | |
70 |
|
70 | |||
71 | protected: |
|
71 | protected: | |
72 | Q_DECLARE_PRIVATE(QBarSeries) |
|
72 | Q_DECLARE_PRIVATE(QBarSeries) | |
73 | friend class BarChartItem; |
|
73 | friend class BarChartItem; | |
74 | friend class PercentBarChartItem; |
|
74 | friend class PercentBarChartItem; | |
75 | friend class StackedBarChartItem; |
|
75 | friend class StackedBarChartItem; | |
76 | friend class GroupedBarChartItem; |
|
76 | friend class GroupedBarChartItem; | |
77 | }; |
|
77 | }; | |
78 |
|
78 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE | |
80 |
|
80 | |||
81 | #endif // BARSERIES_H |
|
81 | #endif // BARSERIES_H |
@@ -1,70 +1,72 | |||||
1 | #ifndef QBARSERIES_P_H |
|
1 | #ifndef QBARSERIES_P_H | |
2 | #define QBARSERIES_P_H |
|
2 | #define QBARSERIES_P_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qabstractseries_p.h" |
|
5 | #include "qabstractseries_p.h" | |
6 | #include <QStringList> |
|
6 | #include <QStringList> | |
7 | #include <QAbstractSeries> |
|
7 | #include <QAbstractSeries> | |
8 |
|
8 | |||
9 | class QModelIndex; |
|
9 | class QModelIndex; | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | class QBarModelMapper; |
|
13 | class QBarModelMapper; | |
14 |
|
14 | |||
15 | // Container for series |
|
15 | // Container for series | |
16 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
16 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | QBarSeriesPrivate(QBarSeries *parent); |
|
20 | QBarSeriesPrivate(QBarSeries *parent); | |
21 | void setCategories(QBarCategories categories); |
|
21 | void setCategories(QBarCategories categories); | |
|
22 | void insertCategory(int index, const QString category); | |||
|
23 | void removeCategory(int index); | |||
|
24 | int categoryCount() const; | |||
|
25 | QBarCategories categories() const; | |||
|
26 | ||||
22 | void setBarMargin(qreal margin); |
|
27 | void setBarMargin(qreal margin); | |
23 | qreal barMargin(); |
|
28 | qreal barMargin(); | |
24 |
|
29 | |||
25 | void scaleDomain(Domain& domain); |
|
30 | void scaleDomain(Domain& domain); | |
26 | Chart* createGraphics(ChartPresenter* presenter); |
|
31 | Chart* createGraphics(ChartPresenter* presenter); | |
27 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
32 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
28 |
|
33 | |||
29 | void insertCategory(int index, const QString category); |
|
|||
30 | void removeCategory(int index); |
|
|||
31 |
|
||||
32 | QBarSet* barsetAt(int index); |
|
34 | QBarSet* barsetAt(int index); | |
33 | QString categoryName(int category); |
|
35 | QString categoryName(int category); | |
34 | qreal min(); |
|
36 | qreal min(); | |
35 | qreal max(); |
|
37 | qreal max(); | |
36 | qreal valueAt(int set, int category); |
|
38 | qreal valueAt(int set, int category); | |
37 | qreal percentageAt(int set, int category); |
|
39 | qreal percentageAt(int set, int category); | |
38 | qreal categorySum(int category); |
|
40 | qreal categorySum(int category); | |
39 | qreal absoluteCategorySum(int category); |
|
41 | qreal absoluteCategorySum(int category); | |
40 | qreal maxCategorySum(); |
|
42 | qreal maxCategorySum(); | |
41 |
|
43 | |||
42 | Q_SIGNALS: |
|
44 | Q_SIGNALS: | |
43 | void clicked(QBarSet *barset, QString category); |
|
45 | void clicked(QBarSet *barset, QString category); | |
44 | void updatedBars(); |
|
46 | void updatedBars(); | |
45 | void restructuredBars(); |
|
47 | void restructuredBars(); | |
46 | void categoriesUpdated(); |
|
48 | void categoriesUpdated(); | |
47 |
|
49 | |||
48 | private Q_SLOTS: |
|
50 | private Q_SLOTS: | |
49 | // slots for updating bars when data in model changes |
|
51 | // slots for updating bars when data in model changes | |
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
52 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
51 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
53 | void modelDataAdded(QModelIndex parent, int start, int end); | |
52 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
54 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
53 | void initializeDataFromModel(); |
|
55 | void initializeDataFromModel(); | |
54 | void barsetChanged(); |
|
56 | void barsetChanged(); | |
55 |
|
57 | |||
56 | protected: |
|
58 | protected: | |
57 | QList<QBarSet *> m_barSets; |
|
59 | QList<QBarSet *> m_barSets; | |
58 | QBarCategories m_categories; |
|
60 | QBarCategories m_categories; | |
59 | qreal m_barMargin; |
|
61 | qreal m_barMargin; | |
60 | int m_mapCategories; |
|
62 | int m_mapCategories; | |
61 | int m_mapBarBottom; |
|
63 | int m_mapBarBottom; | |
62 | int m_mapBarTop; |
|
64 | int m_mapBarTop; | |
63 | QBarModelMapper *m_mapper; |
|
65 | QBarModelMapper *m_mapper; | |
64 | private: |
|
66 | private: | |
65 | Q_DECLARE_PUBLIC(QBarSeries) |
|
67 | Q_DECLARE_PUBLIC(QBarSeries) | |
66 | }; |
|
68 | }; | |
67 |
|
69 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
71 | |||
70 | #endif // QBARSERIESPRIVATE_P_H |
|
72 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,340 +1,363 | |||||
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 "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief part of QtCommercial chart API. |
|
28 | \brief part of QtCommercial chart API. | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \fn void QBarSet::clicked(QString category) |
|
41 | \fn void QBarSet::clicked(QString category) | |
42 | \brief signals that set has been clicked |
|
42 | \brief signals that set has been clicked | |
43 | Parameter \a category describes on which category was clicked |
|
43 | Parameter \a category describes on which category was clicked | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \fn void QBarSet::hovered(bool status) |
|
47 | \fn void QBarSet::hovered(bool status) | |
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. |
|
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. | |
49 |
|
49 | |||
50 | The signal is emitted if mouse is hovered on top of set |
|
50 | The signal is emitted if mouse is hovered on top of set | |
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
55 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
56 | */ |
|
56 | */ | |
57 | QBarSet::QBarSet(const QString name, QObject *parent) |
|
57 | QBarSet::QBarSet(const QString name, QObject *parent) | |
58 | : QObject(parent) |
|
58 | : QObject(parent) | |
59 | ,d_ptr(new QBarSetPrivate(name,this)) |
|
59 | ,d_ptr(new QBarSetPrivate(name,this)) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Destroys the barset |
|
64 | Destroys the barset | |
65 | */ |
|
65 | */ | |
66 | QBarSet::~QBarSet() |
|
66 | QBarSet::~QBarSet() | |
67 | { |
|
67 | { | |
68 | // NOTE: d_ptr destroyed by QObject |
|
68 | // NOTE: d_ptr destroyed by QObject | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Sets new \a name for set. |
|
72 | Sets new \a name for set. | |
73 | */ |
|
73 | */ | |
74 | void QBarSet::setName(const QString name) |
|
74 | void QBarSet::setName(const QString name) | |
75 | { |
|
75 | { | |
76 | d_ptr->m_name = name; |
|
76 | d_ptr->m_name = name; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Returns name of the set. |
|
80 | Returns name of the set. | |
81 | */ |
|
81 | */ | |
82 | QString QBarSet::name() const |
|
82 | QString QBarSet::name() const | |
83 | { |
|
83 | { | |
84 | return d_ptr->m_name; |
|
84 | return d_ptr->m_name; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
|
87 | /*! | |||
|
88 | Appends a point to set. Parameter \a value x coordinate defines the | |||
|
89 | position in x-axis and y coordinate defines the height of bar. | |||
|
90 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) | |||
|
91 | the x values are used or ignored. | |||
|
92 | */ | |||
87 | void QBarSet::append(const QPointF value) |
|
93 | void QBarSet::append(const QPointF value) | |
88 | { |
|
94 | { | |
89 | d_ptr->m_values.append(value); |
|
95 | d_ptr->m_values.append(value); | |
90 | emit d_ptr->restructuredBars(); |
|
96 | emit d_ptr->restructuredBars(); | |
91 | } |
|
97 | } | |
92 |
|
98 | |||
93 |
|
99 | /*! | ||
|
100 | Appends a list of \a points to set. Works like append with single point. | |||
|
101 | \sa append() | |||
|
102 | */ | |||
94 | void QBarSet::append(const QList<QPointF> values) |
|
103 | void QBarSet::append(const QList<QPointF> values) | |
95 | { |
|
104 | { | |
96 | for (int i=0; i<values.count(); i++) { |
|
105 | for (int i=0; i<values.count(); i++) { | |
97 | d_ptr->m_values.append(values.at(i)); |
|
106 | d_ptr->m_values.append(values.at(i)); | |
98 | } |
|
107 | } | |
99 | emit d_ptr->restructuredBars(); |
|
108 | emit d_ptr->restructuredBars(); | |
100 | } |
|
109 | } | |
101 |
|
110 | |||
102 | /*! |
|
111 | /*! | |
103 | Appends new value \a value to the end of set. |
|
112 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, | |
|
113 | with x coordinate being the index of appended value and y coordinate is the value. | |||
104 | */ |
|
114 | */ | |
105 | void QBarSet::append(const qreal value) |
|
115 | void QBarSet::append(const qreal value) | |
106 | { |
|
116 | { | |
107 | append(QPointF(d_ptr->m_values.count(), value)); |
|
117 | append(QPointF(d_ptr->m_values.count(), value)); | |
108 | // d_ptr->m_values.append(value); |
|
|||
109 | } |
|
118 | } | |
110 |
|
119 | |||
111 |
|
120 | /*! | ||
|
121 | Appends a list of reals to set. Works like append with single real value. The values in list | |||
|
122 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. | |||
|
123 | \sa append() | |||
|
124 | */ | |||
112 | void QBarSet::append(const QList<qreal> values) |
|
125 | void QBarSet::append(const QList<qreal> values) | |
113 | { |
|
126 | { | |
114 | int index = d_ptr->m_values.count(); |
|
127 | int index = d_ptr->m_values.count(); | |
115 | for (int i=0; i<values.count(); i++) { |
|
128 | for (int i=0; i<values.count(); i++) { | |
116 | d_ptr->m_values.append(QPointF(index,values.at(i))); |
|
129 | d_ptr->m_values.append(QPointF(index,values.at(i))); | |
117 | index++; |
|
130 | index++; | |
118 | } |
|
131 | } | |
119 | emit d_ptr->restructuredBars(); |
|
132 | emit d_ptr->restructuredBars(); | |
120 | } |
|
133 | } | |
121 |
|
134 | |||
122 | /*! |
|
135 | /*! | |
123 | Appends new value \a value to the end of set. |
|
136 | Convinience operator. Same as append, with real \a value. | |
|
137 | \sa append() | |||
124 | */ |
|
138 | */ | |
125 | QBarSet& QBarSet::operator << (const qreal &value) |
|
139 | QBarSet& QBarSet::operator << (const qreal &value) | |
126 | { |
|
140 | { | |
127 | append(value); |
|
141 | append(value); | |
128 | return *this; |
|
142 | return *this; | |
129 | } |
|
143 | } | |
130 |
|
144 | |||
|
145 | /*! | |||
|
146 | Convinience operator. Same as append, with QPointF \a value. | |||
|
147 | \sa append() | |||
|
148 | */ | |||
131 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
149 | QBarSet& QBarSet::operator << (const QPointF &value) | |
132 | { |
|
150 | { | |
133 | append(value); |
|
151 | append(value); | |
134 | return *this; |
|
152 | return *this; | |
135 | } |
|
153 | } | |
136 |
|
154 | |||
137 | /*! |
|
155 | /*! | |
138 | Inserts new \a value on the \a index position. |
|
156 | Inserts new \a value on the \a index position. | |
139 | The value that is currently at this postion is moved to postion index + 1 |
|
157 | The value that is currently at this postion is moved to postion index + 1 | |
140 | \sa remove() |
|
158 | \sa remove() | |
141 | */ |
|
159 | */ | |
142 | void QBarSet::insert(const int index, const qreal value) |
|
160 | void QBarSet::insert(const int index, const qreal value) | |
143 | { |
|
161 | { | |
144 | d_ptr->m_values.insert(index, QPointF(index, value)); |
|
162 | d_ptr->m_values.insert(index, QPointF(index, value)); | |
145 | // emit d_ptr->updatedBars(); |
|
163 | // emit d_ptr->updatedBars(); | |
146 | } |
|
164 | } | |
147 |
|
165 | |||
148 | /*! |
|
166 | /*! | |
149 | Removes the value specified by \a index |
|
167 | Removes the value specified by \a index | |
150 | \sa insert() |
|
168 | \sa insert() | |
151 | */ |
|
169 | */ | |
152 | void QBarSet::remove(const int index) |
|
170 | void QBarSet::remove(const int index) | |
153 | { |
|
171 | { | |
154 | d_ptr->m_values.removeAt(index); |
|
172 | d_ptr->m_values.removeAt(index); | |
155 | // emit d_ptr->updatedBars(); |
|
173 | // emit d_ptr->updatedBars(); | |
156 | } |
|
174 | } | |
157 |
|
175 | |||
158 | /*! |
|
176 | /*! | |
159 | Sets a new value \a value to set, indexed by \a index |
|
177 | Sets a new value \a value to set, indexed by \a index | |
160 | */ |
|
178 | */ | |
161 | void QBarSet::replace(const int index, const qreal value) |
|
179 | void QBarSet::replace(const int index, const qreal value) | |
162 | { |
|
180 | { | |
163 | d_ptr->m_values.replace(index,QPointF(index,value)); |
|
181 | d_ptr->m_values.replace(index,QPointF(index,value)); | |
164 | emit d_ptr->updatedBars(); |
|
182 | emit d_ptr->updatedBars(); | |
165 | } |
|
183 | } | |
166 |
|
184 | |||
167 | /*! |
|
185 | /*! | |
168 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF |
|
186 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. | |
|
187 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |||
|
188 | of the QPointF (if appended with QPointF append). | |||
|
189 | If the index is out of bounds QPointF(0, 0.0) is returned. | |||
169 | */ |
|
190 | */ | |
170 | QPointF QBarSet::at(const int index) const |
|
191 | QPointF QBarSet::at(const int index) const | |
171 | { |
|
192 | { | |
172 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
193 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
173 | return QPointF(index, 0.0); |
|
194 | return QPointF(index, 0.0); | |
174 | } |
|
195 | } | |
175 |
|
196 | |||
176 | return d_ptr->m_values.at(index); |
|
197 | return d_ptr->m_values.at(index); | |
177 | } |
|
198 | } | |
178 |
|
199 | |||
179 | /*! |
|
200 | /*! | |
180 | Returns value of set indexed by \a index |
|
201 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. | |
|
202 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |||
|
203 | of the QPointF (if appended with QPointF append). | |||
181 | */ |
|
204 | */ | |
182 | QPointF QBarSet::operator [](const int index) const |
|
205 | QPointF QBarSet::operator [](const int index) const | |
183 | { |
|
206 | { | |
184 | return d_ptr->m_values.at(index); |
|
207 | return d_ptr->m_values.at(index); | |
185 | } |
|
208 | } | |
186 |
|
209 | |||
187 | /*! |
|
210 | /*! | |
188 | Returns count of values in set. |
|
211 | Returns count of values in set. | |
189 | */ |
|
212 | */ | |
190 | int QBarSet::count() const |
|
213 | int QBarSet::count() const | |
191 | { |
|
214 | { | |
192 | return d_ptr->m_values.count(); |
|
215 | return d_ptr->m_values.count(); | |
193 | } |
|
216 | } | |
194 |
|
217 | |||
195 | /*! |
|
218 | /*! | |
196 | Returns sum of all values in barset. |
|
219 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. | |
197 | */ |
|
220 | */ | |
198 | qreal QBarSet::sum() const |
|
221 | qreal QBarSet::sum() const | |
199 | { |
|
222 | { | |
200 | qreal total(0); |
|
223 | qreal total(0); | |
201 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
224 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
202 | //total += d_ptr->m_values.at(i); |
|
225 | //total += d_ptr->m_values.at(i); | |
203 | total += d_ptr->m_values.at(i).y(); |
|
226 | total += d_ptr->m_values.at(i).y(); | |
204 | } |
|
227 | } | |
205 | return total; |
|
228 | return total; | |
206 | } |
|
229 | } | |
207 |
|
230 | |||
208 | /*! |
|
231 | /*! | |
209 | Sets pen for set. Bars of this set are drawn using \a pen |
|
232 | Sets pen for set. Bars of this set are drawn using \a pen | |
210 | */ |
|
233 | */ | |
211 | void QBarSet::setPen(const QPen &pen) |
|
234 | void QBarSet::setPen(const QPen &pen) | |
212 | { |
|
235 | { | |
213 | if(d_ptr->m_pen!=pen){ |
|
236 | if(d_ptr->m_pen!=pen){ | |
214 | d_ptr->m_pen = pen; |
|
237 | d_ptr->m_pen = pen; | |
215 | emit d_ptr->updatedBars(); |
|
238 | emit d_ptr->updatedBars(); | |
216 | } |
|
239 | } | |
217 | } |
|
240 | } | |
218 |
|
241 | |||
219 | /*! |
|
242 | /*! | |
220 | Returns pen of the set. |
|
243 | Returns pen of the set. | |
221 | */ |
|
244 | */ | |
222 | QPen QBarSet::pen() const |
|
245 | QPen QBarSet::pen() const | |
223 | { |
|
246 | { | |
224 | return d_ptr->m_pen; |
|
247 | return d_ptr->m_pen; | |
225 | } |
|
248 | } | |
226 |
|
249 | |||
227 | /*! |
|
250 | /*! | |
228 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
251 | Sets brush for the set. Bars of this set are drawn using \a brush | |
229 | */ |
|
252 | */ | |
230 | void QBarSet::setBrush(const QBrush &brush) |
|
253 | void QBarSet::setBrush(const QBrush &brush) | |
231 | { |
|
254 | { | |
232 | if(d_ptr->m_brush!=brush){ |
|
255 | if(d_ptr->m_brush!=brush){ | |
233 | d_ptr->m_brush = brush; |
|
256 | d_ptr->m_brush = brush; | |
234 | emit d_ptr->updatedBars(); |
|
257 | emit d_ptr->updatedBars(); | |
235 | } |
|
258 | } | |
236 | } |
|
259 | } | |
237 |
|
260 | |||
238 | /*! |
|
261 | /*! | |
239 | Returns brush of the set. |
|
262 | Returns brush of the set. | |
240 | */ |
|
263 | */ | |
241 | QBrush QBarSet::brush() const |
|
264 | QBrush QBarSet::brush() const | |
242 | { |
|
265 | { | |
243 | return d_ptr->m_brush; |
|
266 | return d_ptr->m_brush; | |
244 | } |
|
267 | } | |
245 |
|
268 | |||
246 | /*! |
|
269 | /*! | |
247 | Sets \a pen of the values that are drawn on top of this barset |
|
270 | Sets \a pen of the values that are drawn on top of this barset | |
248 | */ |
|
271 | */ | |
249 | void QBarSet::setLabelPen(const QPen &pen) |
|
272 | void QBarSet::setLabelPen(const QPen &pen) | |
250 | { |
|
273 | { | |
251 | if(d_ptr->m_labelPen!=pen){ |
|
274 | if(d_ptr->m_labelPen!=pen){ | |
252 | d_ptr->m_labelPen = pen; |
|
275 | d_ptr->m_labelPen = pen; | |
253 | emit d_ptr->updatedBars(); |
|
276 | emit d_ptr->updatedBars(); | |
254 | } |
|
277 | } | |
255 | } |
|
278 | } | |
256 |
|
279 | |||
257 | /*! |
|
280 | /*! | |
258 | Returns pen of the values that are drawn on top of this barset |
|
281 | Returns pen of the values that are drawn on top of this barset | |
259 | */ |
|
282 | */ | |
260 | QPen QBarSet::labelPen() const |
|
283 | QPen QBarSet::labelPen() const | |
261 | { |
|
284 | { | |
262 | return d_ptr->m_labelPen; |
|
285 | return d_ptr->m_labelPen; | |
263 | } |
|
286 | } | |
264 |
|
287 | |||
265 | /*! |
|
288 | /*! | |
266 | Sets \a brush of the values that are drawn on top of this barset |
|
289 | Sets \a brush of the values that are drawn on top of this barset | |
267 | */ |
|
290 | */ | |
268 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
291 | void QBarSet::setLabelBrush(const QBrush &brush) | |
269 | { |
|
292 | { | |
270 | if(d_ptr->m_labelBrush!=brush){ |
|
293 | if(d_ptr->m_labelBrush!=brush){ | |
271 | d_ptr->m_labelBrush = brush; |
|
294 | d_ptr->m_labelBrush = brush; | |
272 | emit d_ptr->updatedBars(); |
|
295 | emit d_ptr->updatedBars(); | |
273 | } |
|
296 | } | |
274 | } |
|
297 | } | |
275 |
|
298 | |||
276 | /*! |
|
299 | /*! | |
277 | Returns brush of the values that are drawn on top of this barset |
|
300 | Returns brush of the values that are drawn on top of this barset | |
278 | */ |
|
301 | */ | |
279 | QBrush QBarSet::labelBrush() const |
|
302 | QBrush QBarSet::labelBrush() const | |
280 | { |
|
303 | { | |
281 | return d_ptr->m_labelBrush; |
|
304 | return d_ptr->m_labelBrush; | |
282 | } |
|
305 | } | |
283 |
|
306 | |||
284 | /*! |
|
307 | /*! | |
285 | Sets the \a font for values that are drawn on top of this barset |
|
308 | Sets the \a font for values that are drawn on top of this barset | |
286 | */ |
|
309 | */ | |
287 | void QBarSet::setLabelFont(const QFont &font) |
|
310 | void QBarSet::setLabelFont(const QFont &font) | |
288 | { |
|
311 | { | |
289 | if(d_ptr->m_labelFont!=font) { |
|
312 | if(d_ptr->m_labelFont!=font) { | |
290 | d_ptr->m_labelFont = font; |
|
313 | d_ptr->m_labelFont = font; | |
291 | emit d_ptr->updatedBars(); |
|
314 | emit d_ptr->updatedBars(); | |
292 | } |
|
315 | } | |
293 |
|
316 | |||
294 | } |
|
317 | } | |
295 |
|
318 | |||
296 | /*! |
|
319 | /*! | |
297 | Returns the pen for values that are drawn on top of this set |
|
320 | Returns the pen for values that are drawn on top of this set | |
298 | */ |
|
321 | */ | |
299 | QFont QBarSet::labelFont() const |
|
322 | QFont QBarSet::labelFont() const | |
300 | { |
|
323 | { | |
301 | return d_ptr->m_labelFont; |
|
324 | return d_ptr->m_labelFont; | |
302 | } |
|
325 | } | |
303 |
|
326 | |||
304 | /*! |
|
327 | /*! | |
305 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
328 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
306 | */ |
|
329 | */ | |
307 |
|
330 | |||
308 | void QBarSet::setLabelsVisible(bool visible) |
|
331 | void QBarSet::setLabelsVisible(bool visible) | |
309 | { |
|
332 | { | |
310 | if(d_ptr->m_labelsVisible!=visible) { |
|
333 | if(d_ptr->m_labelsVisible!=visible) { | |
311 | d_ptr->m_labelsVisible = visible; |
|
334 | d_ptr->m_labelsVisible = visible; | |
312 | emit d_ptr->labelsVisibleChanged(visible); |
|
335 | emit d_ptr->labelsVisibleChanged(visible); | |
313 | } |
|
336 | } | |
314 | } |
|
337 | } | |
315 |
|
338 | |||
316 | /*! |
|
339 | /*! | |
317 | Returns the visibility of values |
|
340 | Returns the visibility of values | |
318 | */ |
|
341 | */ | |
319 | bool QBarSet::labelsVisible() const |
|
342 | bool QBarSet::labelsVisible() const | |
320 | { |
|
343 | { | |
321 | return d_ptr->m_labelsVisible; |
|
344 | return d_ptr->m_labelsVisible; | |
322 | } |
|
345 | } | |
323 |
|
346 | |||
324 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
347 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
325 |
|
348 | |||
326 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), |
|
349 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), | |
327 | q_ptr(parent), |
|
350 | q_ptr(parent), | |
328 | m_name(name), |
|
351 | m_name(name), | |
329 | m_labelsVisible(false) |
|
352 | m_labelsVisible(false) | |
330 | { |
|
353 | { | |
331 | } |
|
354 | } | |
332 |
|
355 | |||
333 | QBarSetPrivate::~QBarSetPrivate() |
|
356 | QBarSetPrivate::~QBarSetPrivate() | |
334 | { |
|
357 | { | |
335 | } |
|
358 | } | |
336 |
|
359 | |||
337 | #include "moc_qbarset.cpp" |
|
360 | #include "moc_qbarset.cpp" | |
338 | #include "moc_qbarset_p.cpp" |
|
361 | #include "moc_qbarset_p.cpp" | |
339 |
|
362 | |||
340 | QTCOMMERCIALCHART_END_NAMESPACE |
|
363 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,108 +1,108 | |||||
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 "qgroupedbarseries.h" |
|
21 | #include "qgroupedbarseries.h" | |
22 | #include "qgroupedbarseries_p.h" |
|
22 | #include "qgroupedbarseries_p.h" | |
23 | #include "groupedbarchartitem_p.h" |
|
23 | #include "groupedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QGroupedBarSeries |
|
31 | \class QGroupedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 |
QGroupedBarSeries represents a series of data shown as bars. |
|
35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | grouped next to each other. One QGroupedBarSeries can contain multiple QBarSet data sets. |
|
36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data | |
37 |
|
|
37 | from sets to categories, which are defined by a QStringList. | |
38 |
|
38 | |||
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
40 | \image examples_groupedbarchart.png |
|
40 | \image examples_groupedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn virtual QSeriesType QGroupedBarSeries::type() const |
|
46 | \fn virtual QSeriesType QGroupedBarSeries::type() const | |
47 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
48 | \sa QSeriesType |
|
48 | \sa QAbstractSeries, QSeriesType | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | Constructs empty QGroupedBarSeries. Parameter \a categories defines the categories for chart. |
|
52 | Constructs empty QGroupedBarSeries. | |
53 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
53 | QGroupedBarSeries is QObject which is a child of a \a parent. | |
54 | */ |
|
54 | */ | |
55 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
55 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |
56 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
56 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |
61 | { |
|
61 | { | |
62 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
62 | return QAbstractSeries::SeriesTypeGroupedBar; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
66 |
|
66 | |||
67 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(/*QBarCategories categories,*/ QGroupedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) |
|
67 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(/*QBarCategories categories,*/ QGroupedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |
73 | { |
|
73 | { | |
74 | qreal minX(domain.minX()); |
|
74 | qreal minX(domain.minX()); | |
75 | qreal minY(domain.minY()); |
|
75 | qreal minY(domain.minY()); | |
76 | qreal maxX(domain.maxX()); |
|
76 | qreal maxX(domain.maxX()); | |
77 | qreal maxY(domain.maxY()); |
|
77 | qreal maxY(domain.maxY()); | |
78 | int tickXCount(domain.tickXCount()); |
|
78 | int tickXCount(domain.tickXCount()); | |
79 | int tickYCount(domain.tickYCount()); |
|
79 | int tickYCount(domain.tickYCount()); | |
80 |
|
80 | |||
81 | qreal x = m_categories.count(); |
|
81 | qreal x = m_categories.count(); | |
82 | qreal y = maxCategorySum(); |
|
82 | qreal y = maxCategorySum(); | |
83 | minX = qMin(minX, x); |
|
83 | minX = qMin(minX, x); | |
84 | minY = qMin(minY, y); |
|
84 | minY = qMin(minY, y); | |
85 | maxX = qMax(maxX, x); |
|
85 | maxX = qMax(maxX, x); | |
86 | maxY = qMax(maxY, y); |
|
86 | maxY = qMax(maxY, y); | |
87 | tickXCount = x+1; |
|
87 | tickXCount = x+1; | |
88 |
|
88 | |||
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
94 | { |
|
94 | { | |
95 | Q_Q(QGroupedBarSeries); |
|
95 | Q_Q(QGroupedBarSeries); | |
96 |
|
96 | |||
97 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
97 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
99 | presenter->animator()->addAnimation(bar); |
|
99 | presenter->animator()->addAnimation(bar); | |
100 | } |
|
100 | } | |
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
102 | return bar; |
|
102 | return bar; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | #include "moc_qgroupedbarseries.cpp" |
|
105 | #include "moc_qgroupedbarseries.cpp" | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
108 |
@@ -1,109 +1,108 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 |
|
||||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
29 | |||
31 | /*! |
|
30 | /*! | |
32 | \class QPercentBarSeries |
|
31 | \class QPercentBarSeries | |
33 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
34 | \mainclass |
|
33 | \mainclass | |
35 |
|
34 | |||
36 |
QPercentBarSeries represents a series of data shown as bars. |
|
35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
37 | of all bars in category. One QPercentBarSeries can contain multiple QBarSet data sets. |
|
36 | as stacks, where each bar is shown as percentage of all bars in that category. | |
38 | QBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
39 |
|
38 | |||
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
41 | \image examples_percentbarchart.png |
|
40 | \image examples_percentbarchart.png | |
42 |
|
41 | |||
43 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
42 | \sa QBarSet, QStackedBarSeries, QBarSeries | |
44 | */ |
|
43 | */ | |
45 |
|
44 | |||
46 | /*! |
|
45 | /*! | |
47 | \fn virtual QSeriesType QPercentBarSeries::type() const |
|
46 | \fn virtual QSeriesType QPercentBarSeries::type() const | |
48 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
49 | \sa QAbstractSeries, QSeriesType |
|
48 | \sa QAbstractSeries, QSeriesType | |
50 | */ |
|
49 | */ | |
51 |
|
50 | |||
52 | /*! |
|
51 | /*! | |
53 | Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. |
|
52 | Constructs empty QPercentBarSeries. | |
54 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
53 | QPercentBarSeries is QObject which is a child of a \a parent. | |
55 | */ |
|
54 | */ | |
56 |
QPercentBarSeries::QPercentBarSeries( |
|
55 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
57 |
: QBarSeries(*new QPercentBarSeriesPrivate( |
|
56 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
58 | { |
|
57 | { | |
59 | } |
|
58 | } | |
60 |
|
59 | |||
61 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
62 | { |
|
61 | { | |
63 | return QAbstractSeries::SeriesTypePercentBar; |
|
62 | return QAbstractSeries::SeriesTypePercentBar; | |
64 | } |
|
63 | } | |
65 |
|
64 | |||
66 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
67 |
|
66 | |||
68 |
QPercentBarSeriesPrivate::QPercentBarSeriesPrivate( |
|
67 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) | |
69 | { |
|
68 | { | |
70 |
|
69 | |||
71 | } |
|
70 | } | |
72 |
|
71 | |||
73 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
74 | { |
|
73 | { | |
75 | Q_Q(QPercentBarSeries); |
|
74 | Q_Q(QPercentBarSeries); | |
76 | qreal minX(domain.minX()); |
|
75 | qreal minX(domain.minX()); | |
77 | qreal minY(domain.minY()); |
|
76 | qreal minY(domain.minY()); | |
78 | qreal maxX(domain.maxX()); |
|
77 | qreal maxX(domain.maxX()); | |
79 | qreal maxY(domain.maxY()); |
|
78 | qreal maxY(domain.maxY()); | |
80 | int tickXCount(domain.tickXCount()); |
|
79 | int tickXCount(domain.tickXCount()); | |
81 | int tickYCount(domain.tickYCount()); |
|
80 | int tickYCount(domain.tickYCount()); | |
82 |
|
81 | |||
83 | qreal x = q->categoryCount(); |
|
82 | qreal x = q->categoryCount(); | |
84 | minX = qMin(minX, x); |
|
83 | minX = qMin(minX, x); | |
85 | maxX = qMax(maxX, x); |
|
84 | maxX = qMax(maxX, x); | |
86 | minY = 0; |
|
85 | minY = 0; | |
87 | maxY = 100; |
|
86 | maxY = 100; | |
88 | tickXCount = x+1; |
|
87 | tickXCount = x+1; | |
89 |
|
88 | |||
90 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 |
|
92 | |||
94 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
95 | { |
|
94 | { | |
96 | Q_Q(QPercentBarSeries); |
|
95 | Q_Q(QPercentBarSeries); | |
97 |
|
96 | |||
98 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
97 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
99 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
100 | presenter->animator()->addAnimation(bar); |
|
99 | presenter->animator()->addAnimation(bar); | |
101 | } |
|
100 | } | |
102 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
103 | return bar; |
|
102 | return bar; | |
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 | #include "moc_qpercentbarseries.cpp" |
|
105 | #include "moc_qpercentbarseries.cpp" | |
107 |
|
106 | |||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
109 |
|
108 |
@@ -1,45 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef PERCENTBARSERIES_H |
|
21 | #ifndef PERCENTBARSERIES_H | |
22 | #define PERCENTBARSERIES_H |
|
22 | #define PERCENTBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QPercentBarSeriesPrivate; |
|
29 | class QPercentBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 |
explicit QPercentBarSeries( |
|
35 | explicit QPercentBarSeries(QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 | Q_DECLARE_PRIVATE(QPercentBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QPercentBarSeries) | |
40 | Q_DISABLE_COPY(QPercentBarSeries) |
|
40 | Q_DISABLE_COPY(QPercentBarSeries) | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 | #endif // PERCENTBARSERIES_H |
|
45 | #endif // PERCENTBARSERIES_H |
@@ -1,108 +1,108 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QStackedBarSeries |
|
31 | \class QStackedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 |
QStackedBarSeries represents a series of data shown as bars. |
|
35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | stacked on top of each other. One QStackedBarSeries can contain multiple QBarSet data sets. |
|
36 | as stacks, where bars in same category are stacked on top of each other. | |
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
38 |
|
38 | |||
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
40 | \image examples_stackedbarchart.png |
|
40 | \image examples_stackedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn virtual QSeriesType QStackedBarSeries::type() const |
|
46 | \fn virtual QSeriesType QStackedBarSeries::type() const | |
47 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
48 | \sa QSeriesType |
|
48 | \sa QAbstractSeries, QSeriesType | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. |
|
52 | Constructs empty QStackedBarSeries. | |
53 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
53 | QStackedBarSeries is QObject which is a child of a \a parent. | |
54 | */ |
|
54 | */ | |
55 |
QStackedBarSeries::QStackedBarSeries( |
|
55 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
56 |
: QBarSeries(*new QStackedBarSeriesPrivate( |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
61 | { |
|
61 | { | |
62 | return QAbstractSeries::SeriesTypeStackedBar; |
|
62 | return QAbstractSeries::SeriesTypeStackedBar; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
66 |
|
66 | |||
67 |
QStackedBarSeriesPrivate::QStackedBarSeriesPrivate( |
|
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
73 | { |
|
73 | { | |
74 | qreal minX(domain.minX()); |
|
74 | qreal minX(domain.minX()); | |
75 | qreal minY(domain.minY()); |
|
75 | qreal minY(domain.minY()); | |
76 | qreal maxX(domain.maxX()); |
|
76 | qreal maxX(domain.maxX()); | |
77 | qreal maxY(domain.maxY()); |
|
77 | qreal maxY(domain.maxY()); | |
78 | int tickXCount(domain.tickXCount()); |
|
78 | int tickXCount(domain.tickXCount()); | |
79 | int tickYCount(domain.tickYCount()); |
|
79 | int tickYCount(domain.tickYCount()); | |
80 |
|
80 | |||
81 | qreal x = m_categories.count(); |
|
81 | qreal x = m_categories.count(); | |
82 | qreal y = maxCategorySum(); |
|
82 | qreal y = maxCategorySum(); | |
83 | minX = qMin(minX, x); |
|
83 | minX = qMin(minX, x); | |
84 | minY = qMin(minY, y); |
|
84 | minY = qMin(minY, y); | |
85 | maxX = qMax(maxX, x); |
|
85 | maxX = qMax(maxX, x); | |
86 | maxY = qMax(maxY, y); |
|
86 | maxY = qMax(maxY, y); | |
87 | tickXCount = x+1; |
|
87 | tickXCount = x+1; | |
88 |
|
88 | |||
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
94 | { |
|
94 | { | |
95 | Q_Q(QStackedBarSeries); |
|
95 | Q_Q(QStackedBarSeries); | |
96 |
|
96 | |||
97 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
97 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
99 | presenter->animator()->addAnimation(bar); |
|
99 | presenter->animator()->addAnimation(bar); | |
100 | } |
|
100 | } | |
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
102 | return bar; |
|
102 | return bar; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | #include "moc_qstackedbarseries.cpp" |
|
105 | #include "moc_qstackedbarseries.cpp" | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
108 |
@@ -1,45 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef STACKEDBARSERIES_H |
|
21 | #ifndef STACKEDBARSERIES_H | |
22 | #define STACKEDBARSERIES_H |
|
22 | #define STACKEDBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QStackedBarSeriesPrivate; |
|
29 | class QStackedBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 |
explicit QStackedBarSeries( |
|
35 | explicit QStackedBarSeries(QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 | Q_DECLARE_PRIVATE(QStackedBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QStackedBarSeries) | |
40 | Q_DISABLE_COPY(QStackedBarSeries) |
|
40 | Q_DISABLE_COPY(QStackedBarSeries) | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 | #endif // STACKEDBARSERIES_H |
|
45 | #endif // STACKEDBARSERIES_H |
@@ -1,290 +1,291 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qaxis.h" |
|
22 | #include "qaxis.h" | |
23 | #include "qaxis_p.h" |
|
23 | #include "qaxis_p.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qstackedbarseries.h" |
|
26 | #include "qstackedbarseries.h" | |
27 | #include "qpercentbarseries.h" |
|
27 | #include "qpercentbarseries.h" | |
28 | #include "qpieseries.h" |
|
28 | #include "qpieseries.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
33 | m_axisX(new QAxis(this)), |
|
33 | m_axisX(new QAxis(this)), | |
34 | m_axisY(new QAxis(this)), |
|
34 | m_axisY(new QAxis(this)), | |
35 | m_domainIndex(0), |
|
35 | m_domainIndex(0), | |
36 | m_axisXInitialized(false), |
|
36 | m_axisXInitialized(false), | |
37 | m_axisYInitialized(false) |
|
37 | m_axisYInitialized(false) | |
38 | { |
|
38 | { | |
39 | //create main domain |
|
39 | //create main domain | |
40 | Domain* domain = new Domain(m_axisY); |
|
40 | Domain* domain = new Domain(m_axisY); | |
41 | m_axisDomainMap.insert(m_axisY,domain); |
|
41 | m_axisDomainMap.insert(m_axisY,domain); | |
42 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
42 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
43 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
43 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
44 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
44 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
45 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
45 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | ChartDataSet::~ChartDataSet() |
|
48 | ChartDataSet::~ChartDataSet() | |
49 | { |
|
49 | { | |
50 | removeAllSeries(); |
|
50 | removeAllSeries(); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) |
|
53 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) | |
54 | { |
|
54 | { | |
55 | if(axisY==0) axisY = m_axisY; |
|
55 | if(axisY==0) axisY = m_axisY; | |
56 |
|
56 | |||
57 | QAxis* axis = m_seriesAxisMap.value(series); |
|
57 | QAxis* axis = m_seriesAxisMap.value(series); | |
58 |
|
58 | |||
59 | if(axis) { |
|
59 | if(axis) { | |
60 | qWarning() << "Can not add series. Series already on the chart"; |
|
60 | qWarning() << "Can not add series. Series already on the chart"; | |
61 | return; |
|
61 | return; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | series->setParent(this); // take ownership |
|
64 | series->setParent(this); // take ownership | |
65 | axisY->setParent(this); // take ownership |
|
65 | axisY->setParent(this); // take ownership | |
66 |
|
66 | |||
67 | Domain* domain = m_axisDomainMap.value(axisY); |
|
67 | Domain* domain = m_axisDomainMap.value(axisY); | |
68 |
|
68 | |||
69 | if(!domain) { |
|
69 | if(!domain) { | |
70 | domain = new Domain(axisY); |
|
70 | domain = new Domain(axisY); | |
71 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
71 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
72 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); |
|
72 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); | |
73 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
73 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
74 | //initialize |
|
74 | //initialize | |
75 | m_axisDomainMap.insert(axisY,domain); |
|
75 | m_axisDomainMap.insert(axisY,domain); | |
76 | emit axisAdded(axisY,domain); |
|
76 | emit axisAdded(axisY,domain); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | if(!m_axisXInitialized){ |
|
79 | if(!m_axisXInitialized){ | |
80 | m_axisXInitialized=true; |
|
80 | m_axisXInitialized=true; | |
81 | emit axisAdded(m_axisX,domain); |
|
81 | emit axisAdded(m_axisX,domain); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | if(!m_axisYInitialized && axisY==m_axisY){ |
|
84 | if(!m_axisYInitialized && axisY==m_axisY){ | |
85 | m_axisYInitialized=true; |
|
85 | m_axisYInitialized=true; | |
86 | emit axisAdded(m_axisY,domain); |
|
86 | emit axisAdded(m_axisY,domain); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | series->d_ptr->scaleDomain(*domain); |
|
89 | series->d_ptr->scaleDomain(*domain); | |
90 |
|
90 | |||
|
91 | // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis | |||
91 | if(series->type() == QAbstractSeries::SeriesTypeGroupedBar |
|
92 | if(series->type() == QAbstractSeries::SeriesTypeGroupedBar | |
92 | || series->type() == QAbstractSeries::SeriesTypeStackedBar |
|
93 | || series->type() == QAbstractSeries::SeriesTypeStackedBar | |
93 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { |
|
94 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { | |
94 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
95 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
95 | setupCategories(barSeries); |
|
96 | setupCategories(barSeries); | |
96 | } |
|
97 | } | |
97 |
|
98 | |||
98 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { |
|
99 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { | |
99 | axisX()->hide(); |
|
100 | axisX()->hide(); | |
100 | this->axisY()->hide(); |
|
101 | this->axisY()->hide(); | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | m_seriesAxisMap.insert(series,axisY); |
|
104 | m_seriesAxisMap.insert(series,axisY); | |
104 |
|
105 | |||
105 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
106 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
106 |
|
107 | |||
107 | int key=0; |
|
108 | int key=0; | |
108 | while (i.hasNext()) { |
|
109 | while (i.hasNext()) { | |
109 | i.next(); |
|
110 | i.next(); | |
110 | if(i.key()!=key) { |
|
111 | if(i.key()!=key) { | |
111 | break; |
|
112 | break; | |
112 | } |
|
113 | } | |
113 | key++; |
|
114 | key++; | |
114 | } |
|
115 | } | |
115 |
|
116 | |||
116 | m_indexSeriesMap.insert(key,series); |
|
117 | m_indexSeriesMap.insert(key,series); | |
117 |
|
118 | |||
118 | series->d_ptr->m_dataset=this; |
|
119 | series->d_ptr->m_dataset=this; | |
119 |
|
120 | |||
120 | emit seriesAdded(series,domain); |
|
121 | emit seriesAdded(series,domain); | |
121 |
|
122 | |||
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) |
|
125 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) | |
125 | { |
|
126 | { | |
126 | QAxis* axis = m_seriesAxisMap.value(series); |
|
127 | QAxis* axis = m_seriesAxisMap.value(series); | |
127 |
|
128 | |||
128 | if(!axis){ |
|
129 | if(!axis){ | |
129 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
130 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
130 | return 0; |
|
131 | return 0; | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | emit seriesRemoved(series); |
|
134 | emit seriesRemoved(series); | |
134 |
|
135 | |||
135 | m_seriesAxisMap.remove(series); |
|
136 | m_seriesAxisMap.remove(series); | |
136 | int key = seriesIndex(series); |
|
137 | int key = seriesIndex(series); | |
137 | Q_ASSERT(key!=-1); |
|
138 | Q_ASSERT(key!=-1); | |
138 |
|
139 | |||
139 | m_indexSeriesMap.remove(key); |
|
140 | m_indexSeriesMap.remove(key); | |
140 | series->setParent(0); |
|
141 | series->setParent(0); | |
141 | series->d_ptr->m_dataset=0; |
|
142 | series->d_ptr->m_dataset=0; | |
142 |
|
143 | |||
143 | QList<QAxis*> axes = m_seriesAxisMap.values(); |
|
144 | QList<QAxis*> axes = m_seriesAxisMap.values(); | |
144 |
|
145 | |||
145 | int i = axes.indexOf(axis); |
|
146 | int i = axes.indexOf(axis); | |
146 |
|
147 | |||
147 | if(i==-1){ |
|
148 | if(i==-1){ | |
148 | Domain* domain = m_axisDomainMap.take(axis); |
|
149 | Domain* domain = m_axisDomainMap.take(axis); | |
149 | emit axisRemoved(axis); |
|
150 | emit axisRemoved(axis); | |
150 | if(axis!=m_axisY){ |
|
151 | if(axis!=m_axisY){ | |
151 | axis->setParent(0); |
|
152 | axis->setParent(0); | |
152 | delete domain; |
|
153 | delete domain; | |
153 | }else{ |
|
154 | }else{ | |
154 | m_axisYInitialized=false; |
|
155 | m_axisYInitialized=false; | |
155 | m_axisDomainMap.insert(m_axisY,domain); |
|
156 | m_axisDomainMap.insert(m_axisY,domain); | |
156 | } |
|
157 | } | |
157 | } |
|
158 | } | |
158 |
|
159 | |||
159 | if(m_seriesAxisMap.values().size()==0) |
|
160 | if(m_seriesAxisMap.values().size()==0) | |
160 | { |
|
161 | { | |
161 | m_axisXInitialized=false; |
|
162 | m_axisXInitialized=false; | |
162 | emit axisRemoved(axisX()); |
|
163 | emit axisRemoved(axisX()); | |
163 | } |
|
164 | } | |
164 |
|
165 | |||
165 | return axis; |
|
166 | return axis; | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | void ChartDataSet::removeAllSeries() |
|
169 | void ChartDataSet::removeAllSeries() | |
169 | { |
|
170 | { | |
170 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); |
|
171 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); | |
171 | QList<QAxis*> axes; |
|
172 | QList<QAxis*> axes; | |
172 | foreach(QAbstractSeries *s , series) { |
|
173 | foreach(QAbstractSeries *s , series) { | |
173 | QAxis* axis = removeSeries(s); |
|
174 | QAxis* axis = removeSeries(s); | |
174 | if(axis==axisY()) continue; |
|
175 | if(axis==axisY()) continue; | |
175 | int i = axes.indexOf(axis); |
|
176 | int i = axes.indexOf(axis); | |
176 | if(i==-1){ |
|
177 | if(i==-1){ | |
177 | axes<<axis; |
|
178 | axes<<axis; | |
178 | } |
|
179 | } | |
179 | } |
|
180 | } | |
180 |
|
181 | |||
181 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
182 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
182 | Q_ASSERT(m_axisDomainMap.count()==1); |
|
183 | Q_ASSERT(m_axisDomainMap.count()==1); | |
183 |
|
184 | |||
184 | qDeleteAll(series); |
|
185 | qDeleteAll(series); | |
185 | qDeleteAll(axes); |
|
186 | qDeleteAll(axes); | |
186 | } |
|
187 | } | |
187 |
|
188 | |||
188 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
189 | void ChartDataSet::setupCategories(QBarSeries* series) | |
189 | { |
|
190 | { | |
190 | QAxisCategories* categories = axisX()->categories(); |
|
191 | QAxisCategories* categories = axisX()->categories(); | |
191 | categories->clear(); |
|
192 | categories->clear(); | |
192 | categories->insert(series->categories()); |
|
193 | categories->insert(series->categories()); | |
193 | } |
|
194 | } | |
194 |
|
195 | |||
195 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
196 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
196 | { |
|
197 | { | |
197 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
198 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
198 | //main domain has to be the last one; |
|
199 | //main domain has to be the last one; | |
199 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
200 | Domain *domain = m_axisDomainMap.value(axisY()); | |
200 | Q_ASSERT(domain); |
|
201 | Q_ASSERT(domain); | |
201 | while (i.hasNext()) { |
|
202 | while (i.hasNext()) { | |
202 | i.next(); |
|
203 | i.next(); | |
203 | if(i.value()==domain) continue; |
|
204 | if(i.value()==domain) continue; | |
204 | i.value()->zoomIn(rect,size); |
|
205 | i.value()->zoomIn(rect,size); | |
205 | } |
|
206 | } | |
206 | domain->zoomIn(rect,size); |
|
207 | domain->zoomIn(rect,size); | |
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
210 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
210 | { |
|
211 | { | |
211 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
212 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
212 | //main domain has to be the last one; |
|
213 | //main domain has to be the last one; | |
213 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
214 | Domain *domain = m_axisDomainMap.value(axisY()); | |
214 | Q_ASSERT(domain); |
|
215 | Q_ASSERT(domain); | |
215 | while (i.hasNext()) { |
|
216 | while (i.hasNext()) { | |
216 | i.next(); |
|
217 | i.next(); | |
217 | if(i.value()==domain) continue; |
|
218 | if(i.value()==domain) continue; | |
218 | i.value()->zoomOut(rect,size); |
|
219 | i.value()->zoomOut(rect,size); | |
219 | } |
|
220 | } | |
220 | domain->zoomOut(rect,size); |
|
221 | domain->zoomOut(rect,size); | |
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
224 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
224 | { |
|
225 | { | |
225 | int count=0; |
|
226 | int count=0; | |
226 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); |
|
227 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); | |
227 | while (i.hasNext()) { |
|
228 | while (i.hasNext()) { | |
228 | i.next(); |
|
229 | i.next(); | |
229 | if(i.key()->type()==type) count++; |
|
230 | if(i.key()->type()==type) count++; | |
230 | } |
|
231 | } | |
231 | return count; |
|
232 | return count; | |
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
235 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
235 | { |
|
236 | { | |
236 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
237 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
237 | while (i.hasNext()) { |
|
238 | while (i.hasNext()) { | |
238 | i.next(); |
|
239 | i.next(); | |
239 | if (i.value() == series) |
|
240 | if (i.value() == series) | |
240 | return i.key(); |
|
241 | return i.key(); | |
241 | } |
|
242 | } | |
242 | return -1; |
|
243 | return -1; | |
243 | } |
|
244 | } | |
244 |
|
245 | |||
245 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
246 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
246 | { |
|
247 | { | |
247 | if(series == 0) return m_axisY; |
|
248 | if(series == 0) return m_axisY; | |
248 | return m_seriesAxisMap.value(series); |
|
249 | return m_seriesAxisMap.value(series); | |
249 | } |
|
250 | } | |
250 |
|
251 | |||
251 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
252 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
252 | { |
|
253 | { | |
253 | QAxis* axis = m_seriesAxisMap.value(series); |
|
254 | QAxis* axis = m_seriesAxisMap.value(series); | |
254 | if(axis){ |
|
255 | if(axis){ | |
255 | return m_axisDomainMap.value(axis); |
|
256 | return m_axisDomainMap.value(axis); | |
256 | }else |
|
257 | }else | |
257 | return 0; |
|
258 | return 0; | |
258 | } |
|
259 | } | |
259 |
|
260 | |||
260 | Domain* ChartDataSet::domain(QAxis* axis) const |
|
261 | Domain* ChartDataSet::domain(QAxis* axis) const | |
261 | { |
|
262 | { | |
262 | if(!axis || axis==axisX()) { |
|
263 | if(!axis || axis==axisX()) { | |
263 | return m_axisDomainMap.value(axisY()); |
|
264 | return m_axisDomainMap.value(axisY()); | |
264 | } |
|
265 | } | |
265 | else { |
|
266 | else { | |
266 | return m_axisDomainMap.value(axis); |
|
267 | return m_axisDomainMap.value(axis); | |
267 | } |
|
268 | } | |
268 | } |
|
269 | } | |
269 |
|
270 | |||
270 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
271 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) | |
271 | { |
|
272 | { | |
272 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); |
|
273 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); | |
273 | //main domain has to be the last one; |
|
274 | //main domain has to be the last one; | |
274 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
275 | Domain *domain = m_axisDomainMap.value(axisY()); | |
275 | while (i.hasNext()) { |
|
276 | while (i.hasNext()) { | |
276 | i.next(); |
|
277 | i.next(); | |
277 | if(i.value()==domain) continue; |
|
278 | if(i.value()==domain) continue; | |
278 | i.value()->move(dx,dy,size); |
|
279 | i.value()->move(dx,dy,size); | |
279 | } |
|
280 | } | |
280 | domain->move(dx,dy,size); |
|
281 | domain->move(dx,dy,size); | |
281 | } |
|
282 | } | |
282 |
|
283 | |||
283 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
284 | QList<QAbstractSeries*> ChartDataSet::series() const | |
284 | { |
|
285 | { | |
285 | return m_seriesAxisMap.keys(); |
|
286 | return m_seriesAxisMap.keys(); | |
286 | } |
|
287 | } | |
287 |
|
288 | |||
288 | #include "moc_chartdataset_p.cpp" |
|
289 | #include "moc_chartdataset_p.cpp" | |
289 |
|
290 | |||
290 | QTCOMMERCIALCHART_END_NAMESPACE |
|
291 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,138 +1,139 | |||||
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 "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QAbstractSeries |
|
28 | \class QAbstractSeries | |
29 | \brief Base class for all QtCommercial Chart series. |
|
29 | \brief Base class for all QtCommercial Chart series. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | Usually you use the series type specific inherited classes instead of the base class. |
|
32 | Usually you use the series type specific inherited classes instead of the base class. | |
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries, |
|
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries, | |
34 | QPercentBarSeries, QPieSeries |
|
34 | QPercentBarSeries, QPieSeries | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \enum QAbstractSeries::SeriesType |
|
38 | \enum QAbstractSeries::SeriesType | |
39 |
|
39 | |||
40 | The type of the series object. |
|
40 | The type of the series object. | |
41 |
|
41 | |||
42 | \value SeriesTypeLine |
|
42 | \value SeriesTypeLine | |
43 | \value SeriesTypeArea |
|
43 | \value SeriesTypeArea | |
44 | \value SeriesTypeBar |
|
44 | \value SeriesTypeBar | |
45 | \value SeriesTypeStackedBar |
|
45 | \value SeriesTypeStackedBar | |
46 | \value SeriesTypePercentBar |
|
46 | \value SeriesTypePercentBar | |
|
47 | \value SeriesTypeGroupedBar | |||
47 | \value SeriesTypePie |
|
48 | \value SeriesTypePie | |
48 | \value SeriesTypeScatter |
|
49 | \value SeriesTypeScatter | |
49 | \value SeriesTypeSpline |
|
50 | \value SeriesTypeSpline | |
50 | */ |
|
51 | */ | |
51 |
|
52 | |||
52 | /*! |
|
53 | /*! | |
53 | \fn QSeriesType QAbstractSeries::type() const |
|
54 | \fn QSeriesType QAbstractSeries::type() const | |
54 | \brief The type of the series. |
|
55 | \brief The type of the series. | |
55 | */ |
|
56 | */ | |
56 |
|
57 | |||
57 | /*! |
|
58 | /*! | |
58 | \fn bool QAbstractSeries::setModel(QAbstractItemModel *model) |
|
59 | \fn bool QAbstractSeries::setModel(QAbstractItemModel *model) | |
59 | \brief Use the \a model to provide data for the series. The model overrides possible user data |
|
60 | \brief Use the \a model to provide data for the series. The model overrides possible user data | |
60 | set with QChartSeries type specific data setters. For example if you call both |
|
61 | set with QChartSeries type specific data setters. For example if you call both | |
61 | QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is |
|
62 | QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is | |
62 | used by the series. Returns true if the model is valid for the series. |
|
63 | used by the series. Returns true if the model is valid for the series. | |
63 | */ |
|
64 | */ | |
64 |
|
65 | |||
65 | /*! |
|
66 | /*! | |
66 | \property QAbstractSeries::name |
|
67 | \property QAbstractSeries::name | |
67 | \brief name of the series property |
|
68 | \brief name of the series property | |
68 | */ |
|
69 | */ | |
69 |
|
70 | |||
70 | /*! |
|
71 | /*! | |
71 | \fn void QAbstractSeries::setName(const QString& name) |
|
72 | \fn void QAbstractSeries::setName(const QString& name) | |
72 | \brief Sets a \a name for the series. |
|
73 | \brief Sets a \a name for the series. | |
73 |
|
74 | |||
74 | The name of a series is shown in the legend for QXYSeries. |
|
75 | The name of a series is shown in the legend for QXYSeries. | |
75 | \sa QChart::setTitle() |
|
76 | \sa QChart::setTitle() | |
76 | \sa QPieSlice::setLabel() |
|
77 | \sa QPieSlice::setLabel() | |
77 | \sa QBarSet::setName() |
|
78 | \sa QBarSet::setName() | |
78 | */ |
|
79 | */ | |
79 |
|
80 | |||
80 | /*! |
|
81 | /*! | |
81 | \internal |
|
82 | \internal | |
82 | \brief Constructs ChartSeries object with \a parent. |
|
83 | \brief Constructs ChartSeries object with \a parent. | |
83 | */ |
|
84 | */ | |
84 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
85 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
85 | QObject(parent), |
|
86 | QObject(parent), | |
86 | d_ptr(&d) |
|
87 | d_ptr(&d) | |
87 | { |
|
88 | { | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | /*! |
|
91 | /*! | |
91 | \brief Virtual destructor for the chart series. |
|
92 | \brief Virtual destructor for the chart series. | |
92 | */ |
|
93 | */ | |
93 | QAbstractSeries::~QAbstractSeries() |
|
94 | QAbstractSeries::~QAbstractSeries() | |
94 | { |
|
95 | { | |
95 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
96 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); | |
96 | } |
|
97 | } | |
97 |
|
98 | |||
98 | /*! |
|
99 | /*! | |
99 | \brief Returns the pointer to the model that is used as the series data source |
|
100 | \brief Returns the pointer to the model that is used as the series data source | |
100 | */ |
|
101 | */ | |
101 | QAbstractItemModel* QAbstractSeries::model() const |
|
102 | QAbstractItemModel* QAbstractSeries::model() const | |
102 | { |
|
103 | { | |
103 | return d_ptr->m_model; |
|
104 | return d_ptr->m_model; | |
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 | void QAbstractSeries::setName(const QString& name) |
|
107 | void QAbstractSeries::setName(const QString& name) | |
107 | { |
|
108 | { | |
108 | d_ptr->m_name = name; |
|
109 | d_ptr->m_name = name; | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | /*! |
|
112 | /*! | |
112 | \brief Returns the name of the series. |
|
113 | \brief Returns the name of the series. | |
113 | \sa setName() |
|
114 | \sa setName() | |
114 | */ |
|
115 | */ | |
115 | QString QAbstractSeries::name() const |
|
116 | QString QAbstractSeries::name() const | |
116 | { |
|
117 | { | |
117 | return d_ptr->m_name; |
|
118 | return d_ptr->m_name; | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
121 |
|
122 | |||
122 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
123 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): | |
123 | q_ptr(q), |
|
124 | q_ptr(q), | |
124 | m_model(0), |
|
125 | m_model(0), | |
125 | m_dataset(0) |
|
126 | m_dataset(0) | |
126 | { |
|
127 | { | |
127 | } |
|
128 | } | |
128 |
|
129 | |||
129 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
130 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
130 | { |
|
131 | { | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | #include "moc_qabstractseries.cpp" |
|
134 | #include "moc_qabstractseries.cpp" | |
134 | #include "moc_qabstractseries_p.cpp" |
|
135 | #include "moc_qabstractseries_p.cpp" | |
135 |
|
136 | |||
136 | QTCOMMERCIALCHART_END_NAMESPACE |
|
137 | QTCOMMERCIALCHART_END_NAMESPACE | |
137 |
|
138 | |||
138 |
|
139 |
General Comments 0
You need to be logged in to leave comments.
Login now