##// END OF EJS Templates
Refactor CategoriesAxis to BarCategoriesAxis part 1 of 2
Michal Klocek -
r1612:859a2158b75a
parent child
Show More
@@ -1,48 +1,48
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 //![1]
28 28 ChartView {
29 29 title: "Bar series"
30 30 anchors.fill: parent
31 31 legend.alignment: Qt.AlignBottom
32 CategoriesAxis {
32 BarCategoriesAxis {
33 33 id:myAxis
34 34 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ]
35 35 }
36 36 BarSeries {
37 37 id: mySeries
38 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
39 39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
40 40 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
41 41 }
42 42 Component.onCompleted: {
43 43 createDefaultAxes();
44 44 setAxisX(myAxis,mySeries);
45 45 }
46 46 }
47 47 //![1]
48 48 }
@@ -1,48 +1,48
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 //![1]
28 28 ChartView {
29 29 title: "Stacked Bar series"
30 30 anchors.fill: parent
31 31 legend.alignment: Qt.AlignBottom
32 CategoriesAxis {
32 BarCategoriesAxis {
33 33 id: myAxis;
34 34 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ]
35 35 }
36 36 StackedBarSeries {
37 37 id: mySeries;
38 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
39 39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
40 40 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
41 41 }
42 42 Component.onCompleted: {
43 43 createDefaultAxes();
44 44 setAxisX(myAxis,mySeries);
45 45 }
46 46 }
47 47 //![1]
48 48 }
@@ -1,49 +1,49
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 //![1]
28 28 ChartView {
29 29 title: "Percent Bar series"
30 30 anchors.fill: parent
31 31 legend.alignment: Qt.AlignBottom
32 CategoriesAxis {
32 BarCategoriesAxis {
33 33 id: myAxis
34 34 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ]
35 35 }
36 36 PercentBarSeries {
37 37 id: mySeries
38 38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
39 39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
40 40 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
41 41 }
42 42 Component.onCompleted: {
43 43 createDefaultAxes();
44 44 setAxisX(myAxis,mySeries);
45 45 }
46 46 }
47 47 //![1]
48 48 }
49 49
@@ -1,155 +1,155
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23 import QmlCustomModel 1.0
24 24
25 25 Rectangle {
26 26 anchors.fill: parent
27 27
28 28 //![1]
29 29 ChartView {
30 30 id: chartView
31 31 title: "Top-5 car brand shares in Finland"
32 32 anchors.fill: parent
33 33 animationOptions: ChartView.SeriesAnimations
34 34
35 CategoriesAxis {
35 BarCategoriesAxis {
36 36 id: categoryAxis
37 37 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ]
38 38 }
39 39 // ...
40 40 //![1]
41 41
42 42 //![2]
43 43 CustomModel {
44 44 id: customModel
45 45 verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"]
46 46 CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] }
47 47 CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] }
48 48 CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] }
49 49 CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] }
50 50 CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] }
51 51 CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] }
52 52 CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] }
53 53 }
54 54 //![2]
55 55
56 56 //![5]
57 57 BarSeries {
58 58 name: "Others"
59 59 barWidth: 0.9
60 60 visible: false
61 61 HBarModelMapper {
62 62 model: customModel
63 63 firstBarSetRow: 6
64 64 lastBarSetRow: 6
65 65 firstColumn: 2
66 66 }
67 67 }
68 68 //![5]
69 69
70 70 //![4]
71 71 LineSeries {
72 72 name: "Volkswagen"
73 73 visible: false
74 74 HXYModelMapper {
75 75 model: customModel
76 76 xRow: 0
77 77 yRow: 1
78 78 firstColumn: 2
79 79 }
80 80 }
81 81 //![4]
82 82
83 83 LineSeries {
84 84 name: "Toyota"
85 85 visible: false
86 86 HXYModelMapper {
87 87 model: customModel
88 88 xRow: 0
89 89 yRow: 2
90 90 firstColumn: 2
91 91 }
92 92 }
93 93
94 94 LineSeries {
95 95 name: "Ford"
96 96 visible: false
97 97 HXYModelMapper {
98 98 model: customModel
99 99 xRow: 0
100 100 yRow: 3
101 101 firstColumn: 2
102 102 }
103 103 }
104 104
105 105 LineSeries {
106 106 name: "Skoda"
107 107 visible: false
108 108 HXYModelMapper {
109 109 model: customModel
110 110 xRow: 0
111 111 yRow: 4
112 112 firstColumn: 2
113 113 }
114 114 }
115 115
116 116 LineSeries {
117 117 name: "Volvo"
118 118 visible: false
119 119 HXYModelMapper {
120 120 model: customModel
121 121 xRow: 0
122 122 yRow: 5
123 123 firstColumn: 2
124 124 }
125 125 }
126 126
127 127 //![3]
128 128 PieSeries {
129 129 id: pieSeries
130 130 size: 0.4
131 131 horizontalPosition: 0.7
132 132 verticalPosition: 0.4
133 133 onClicked: {
134 134 // Show the selection by exploding the slice
135 135 slice.exploded = !slice.exploded;
136 136
137 137 // Update the line series to show the yearly data for this slice
138 138 for (var i = 0; i < chartView.count; i++) {
139 139 if (chartView.series(i).name == slice.label) {
140 140 chartView.series(i).visible = slice.exploded;
141 141 }
142 142 }
143 143 }
144 144 }
145 145 //![3]
146 146
147 147 VPieModelMapper {
148 148 series: pieSeries
149 149 model: customModel
150 150 labelsColumn: 1
151 151 valuesColumn: 2
152 152 firstRow: 1
153 153 }
154 154 }
155 155 }
@@ -1,92 +1,92
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27 #include <QCategoriesAxis>
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 int main(int argc, char *argv[])
32 32 {
33 33 QApplication a(argc, argv);
34 34
35 35 //![1]
36 36 QBarSet *set0 = new QBarSet("Jane");
37 37 QBarSet *set1 = new QBarSet("John");
38 38 QBarSet *set2 = new QBarSet("Axel");
39 39 QBarSet *set3 = new QBarSet("Mary");
40 40 QBarSet *set4 = new QBarSet("Samantha");
41 41
42 42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 47 //![1]
48 48
49 49 //![2]
50 50 QBarSeries* series = new QBarSeries();
51 51 series->append(set0);
52 52 series->append(set1);
53 53 series->append(set2);
54 54 series->append(set3);
55 55 series->append(set4);
56 56
57 57 //![2]
58 58
59 59 //![3]
60 60 QChart* chart = new QChart();
61 61 chart->addSeries(series);
62 62 chart->setTitle("Barchart example");
63 63 chart->createDefaultAxes();
64 64 //![3]
65 65
66 66 //![4]
67 67 QStringList categories;
68 68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
69 QCategoriesAxis* axis = new QCategoriesAxis();
69 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
70 70 axis->append(categories);
71 71 chart->setAxisX(axis,series);
72 72 //![4]
73 73
74 74 //![5]
75 75 chart->legend()->setVisible(true);
76 76 chart->legend()->setAlignment(Qt::AlignBottom);
77 77 //![5]
78 78
79 79 //![6]
80 80 QChartView* chartView = new QChartView(chart);
81 81 chartView->setRenderHint(QPainter::Antialiasing);
82 82 //![6]
83 83
84 84 //![7]
85 85 QMainWindow window;
86 86 window.setCentralWidget(chartView);
87 87 window.resize(400, 300);
88 88 window.show();
89 89 //![7]
90 90
91 91 return a.exec();
92 92 }
@@ -1,112 +1,112
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "tablewidget.h"
22 22 #include "customtablemodel.h"
23 23 #include <QGridLayout>
24 24 #include <QTableView>
25 25 #include <QChart>
26 26 #include <QChartView>
27 27 #include <QLineSeries>
28 28 #include <QVXYModelMapper>
29 29 #include <QBarSeries>
30 30 #include <QBarSet>
31 31 #include <QVBarModelMapper>
32 32 #include <QHeaderView>
33 33 #include <QCategoriesAxis>
34 34
35 35 QTCOMMERCIALCHART_USE_NAMESPACE
36 36
37 37 TableWidget::TableWidget(QWidget *parent)
38 38 : QWidget(parent)
39 39 {
40 40 // create simple model for storing data
41 41 // user's table data model
42 42 //! [1]
43 43 CustomTableModel *model = new CustomTableModel;
44 44 //! [1]
45 45
46 46 //! [2]
47 47 // create table view and add model to it
48 48 QTableView *tableView = new QTableView;
49 49 tableView->setModel(model);
50 50 tableView->setMinimumWidth(300);
51 51 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
52 52 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
53 53 //! [2]
54 54
55 55 //! [3]
56 56 QChart *chart = new QChart;
57 57 chart->setAnimationOptions(QChart::AllAnimations);
58 58 //! [3]
59 59
60 60 // series 1
61 61 //! [4]
62 62 QBarSeries *series = new QBarSeries;
63 63
64 64 int first = 3;
65 65 int count = 5;
66 66 QVBarModelMapper *mapper = new QVBarModelMapper(this);
67 67 mapper->setFirstBarSetColumn(1);
68 68 mapper->setLastBarSetColumn(4);
69 69 mapper->setFirstRow(first);
70 70 mapper->setRowCount(count);
71 71 mapper->setSeries(series);
72 72 mapper->setModel(model);
73 73 chart->addSeries(series);
74 74 //! [4]
75 75
76 76 //! [5]
77 77 // for storing color hex from the series
78 78 QString seriesColorHex = "#000000";
79 79
80 80 // get the color of the series and use it for showing the mapped area
81 81 QList<QBarSet*> barsets = series->barSets();
82 82 for (int i = 0; i < barsets.count(); i++) {
83 83 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
84 84 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
85 85 }
86 86 //! [5]
87 87
88 88 //! [6]
89 89 QStringList categories;
90 90 categories << "April" << "May" << "June" << "July" << "August";
91 QCategoriesAxis* axis = new QCategoriesAxis();
91 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
92 92 axis->append(categories);
93 93 chart->createDefaultAxes();
94 94 chart->setAxisX(axis, series);
95 95 //! [6]
96 96
97 97 //! [7]
98 98 QChartView *chartView = new QChartView(chart);
99 99 chartView->setRenderHint(QPainter::Antialiasing);
100 100 chartView->setMinimumSize(640, 480);
101 101 //! [7]
102 102
103 103 //! [8]
104 104 // create main layout
105 105 QGridLayout* mainLayout = new QGridLayout;
106 106 mainLayout->addWidget(tableView, 1, 0);
107 107 mainLayout->addWidget(chartView, 1, 1);
108 108 mainLayout->setColumnStretch(1, 1);
109 109 mainLayout->setColumnStretch(0, 0);
110 110 setLayout(mainLayout);
111 111 //! [8]
112 112 }
@@ -1,92 +1,92
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QPercentBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27 #include <QCategoriesAxis>
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 int main(int argc, char *argv[])
32 32 {
33 33 QApplication a(argc, argv);
34 34
35 35 //![1]
36 36 QBarSet *set0 = new QBarSet("Jane");
37 37 QBarSet *set1 = new QBarSet("John");
38 38 QBarSet *set2 = new QBarSet("Axel");
39 39 QBarSet *set3 = new QBarSet("Mary");
40 40 QBarSet *set4 = new QBarSet("Samantha");
41 41
42 42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 47 //![1]
48 48
49 49 //![2]
50 50 QPercentBarSeries* series = new QPercentBarSeries();
51 51 series->append(set0);
52 52 series->append(set1);
53 53 series->append(set2);
54 54 series->append(set3);
55 55 series->append(set4);
56 56 //![2]
57 57
58 58 //![3]
59 59 QChart* chart = new QChart();
60 60 chart->addSeries(series);
61 61 chart->setTitle("Percentbarchart example");
62 62 //![3]
63 63
64 64 //![4]
65 65 QStringList categories;
66 66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 QCategoriesAxis* axis = new QCategoriesAxis();
67 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
68 68 axis->append(categories);
69 69 chart->createDefaultAxes();
70 70 chart->setAxisX(axis,series);
71 71 //![4]
72 72
73 73 //![5]
74 74 chart->legend()->setVisible(true);
75 75 chart->legend()->setAlignment(Qt::AlignBottom);
76 76 //![5]
77 77
78 78 //![6]
79 79 QChartView* chartView = new QChartView(chart);
80 80 chartView->setRenderHint(QPainter::Antialiasing);
81 81 //![6]
82 82
83 83 //![7]
84 84 QMainWindow window;
85 85 window.setCentralWidget(chartView);
86 86 window.resize(400, 300);
87 87 window.show();
88 88 //![7]
89 89
90 90 return a.exec();
91 91 }
92 92
@@ -1,92 +1,92
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QStackedBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27 #include <QCategoriesAxis>
28 28
29 29 QTCOMMERCIALCHART_USE_NAMESPACE
30 30
31 31 int main(int argc, char *argv[])
32 32 {
33 33 QApplication a(argc, argv);
34 34
35 35 //![1]
36 36 QBarSet *set0 = new QBarSet("Jane");
37 37 QBarSet *set1 = new QBarSet("John");
38 38 QBarSet *set2 = new QBarSet("Axel");
39 39 QBarSet *set3 = new QBarSet("Mary");
40 40 QBarSet *set4 = new QBarSet("Samantha");
41 41
42 42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 47 //![1]
48 48
49 49 //![2]
50 50 QStackedBarSeries* series = new QStackedBarSeries();
51 51 series->append(set0);
52 52 series->append(set1);
53 53 series->append(set2);
54 54 series->append(set3);
55 55 series->append(set4);
56 56 //![2]
57 57
58 58 //![3]
59 59 QChart* chart = new QChart();
60 60 chart->addSeries(series);
61 61 chart->setTitle("Stackedbarchart example");
62 62 chart->createDefaultAxes();
63 63 //![3]
64 64
65 65 //![4]
66 66 QStringList categories;
67 67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 QCategoriesAxis* axis = new QCategoriesAxis();
68 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
69 69 axis->append(categories);
70 70 chart->setAxisX(axis,series);
71 71 //![4]
72 72
73 73 //![5]
74 74 chart->legend()->setVisible(true);
75 75 chart->legend()->setAlignment(Qt::AlignBottom);
76 76 //![5]
77 77
78 78 //![6]
79 79 QChartView* chartView = new QChartView(chart);
80 80 chartView->setRenderHint(QPainter::Antialiasing);
81 81 //![6]
82 82
83 83 //![7]
84 84 QMainWindow window;
85 85 window.setCentralWidget(chartView);
86 86 window.resize(400, 300);
87 87 window.show();
88 88 //![7]
89 89
90 90 return a.exec();
91 91 }
92 92
@@ -1,59 +1,59
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "drilldownchart.h"
22 22 #include <QCategoriesAxis>
23 23
24 24 QTCOMMERCIALCHART_USE_NAMESPACE
25 25
26 26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 27 : QChart(parent, wFlags)
28 28 ,m_currentSeries(0)
29 29 {
30 30 }
31 31
32 32 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
33 33 {
34 34 if (m_currentSeries) {
35 35 removeSeries(m_currentSeries);
36 36 }
37 37
38 38 m_currentSeries = series;
39 39
40 40 // Reset axis
41 QCategoriesAxis* axis = new QCategoriesAxis();
41 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
42 42 axis->append(m_currentSeries->categories());
43 43
44 44 addSeries(series);
45 45
46 46 createDefaultAxes();
47 47 setAxisX(axis,series);
48 48
49 49 setTitle(series->name());
50 50 }
51 51
52 52 void DrilldownChart::handleClicked(int index, QBarSet *barset)
53 53 {
54 54 Q_UNUSED(barset)
55 55 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
56 56 changeSeries(series->drilldownSeries(index));
57 57 }
58 58
59 59 #include "moc_drilldownchart.cpp"
@@ -1,104 +1,104
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qabstractaxis.h"
25 25 #include "qvaluesaxis.h"
26 26 #include "qcategoriesaxis.h"
27 27 #include "declarativechart.h"
28 28 #include "declarativexypoint.h"
29 29 #include "declarativelineseries.h"
30 30 #include "declarativesplineseries.h"
31 31 #include "declarativeareaseries.h"
32 32 #include "declarativescatterseries.h"
33 33 #include "declarativebarseries.h"
34 34 #include "declarativepieseries.h"
35 35 #include <QVXYModelMapper>
36 36 #include <QHXYModelMapper>
37 37 #include <QHPieModelMapper>
38 38 #include <QVPieModelMapper>
39 39 #include <QHBarModelMapper>
40 40 #include <QVBarModelMapper>
41 41
42 42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43 43
44 44 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
45 45 {
46 46 Q_OBJECT
47 47 public:
48 48 virtual void registerTypes(const char *uri)
49 49 {
50 50 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
51 51
52 52 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
53 53 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
54 54 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
55 55 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
56 56 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
57 57 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
58 58 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
59 59 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
60 60 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
61 61 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
62 62 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
63 63 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
64 64 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
65 65 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
66 66 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
67 67 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
68 68 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
69 69 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
70 70 qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis");
71 qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis");
71 qmlRegisterType<QBarCategoriesAxis>(uri, 1, 0, "BarCategoriesAxis");
72 72
73 73 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
74 74 QLatin1String("Trying to create uncreatable: Legend."));
75 75 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
76 76 QLatin1String("Trying to create uncreatable: XYSeries."));
77 77 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
78 78 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
79 79 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
80 80 QLatin1String("Trying to create uncreatable: XYModelMapper."));
81 81 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
82 82 QLatin1String("Trying to create uncreatable: PieModelMapper."));
83 83 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
84 84 QLatin1String("Trying to create uncreatable: BarModelMapper."));
85 85 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
86 86 QLatin1String("Trying to create uncreatable: AbstractSeries."));
87 87 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
88 88 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
89 89 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
90 90 QLatin1String("Trying to create uncreatable: AbstractAxis."));
91 91 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
92 92 QLatin1String("Trying to create uncreatable: PieModelMapper."));
93 93 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
94 94 QLatin1String("Trying to create uncreatable: XYModelMapper."));
95 95 }
96 96 };
97 97
98 98 #include "plugin.moc"
99 99
100 100 QTCOMMERCIALCHART_END_NAMESPACE
101 101
102 102 QTCOMMERCIALCHART_USE_NAMESPACE
103 103
104 104 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,106 +1,106
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartcategoriesaxisx_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "chartpresenter_p.h"
24 24 #include "chartanimator_p.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QDebug>
27 27 #include <QFontMetrics>
28 28 #include <QCategoriesAxis>
29 29
30 30 static int label_padding = 5;
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 ChartCategoriesAxisX::ChartCategoriesAxisX(QCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
35 35 m_categoriesAxis(axis)
36 36 {
37 37
38 38 }
39 39
40 40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
41 41 {
42 42 }
43 43
44 44 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
45 45 {
46 46 Q_ASSERT(m_ticksCount>=2);
47 47
48 48 QVector<qreal> points;
49 49 points.resize(m_ticksCount);
50 50
51 51 // TODO: shift logic
52 52 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
53 53 for (int i = 0; i < m_ticksCount; ++i) {
54 54 int x = i * deltaX + m_rect.left();
55 55 points[i] = x;
56 56 }
57 57 return points;
58 58 }
59 59
60 60 void ChartCategoriesAxisX::updateGeometry()
61 61 {
62 62 const QVector<qreal>& layout = ChartAxis::layout();
63 63
64 64 m_minWidth = 0;
65 65 m_minHeight = 0;
66 66
67 67 if(layout.isEmpty()) return;
68 68
69 69 QStringList ticksList;
70 70
71 71 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
72 72
73 73 QList<QGraphicsItem *> lines = m_grid->childItems();
74 74 QList<QGraphicsItem *> labels = m_labels->childItems();
75 75 QList<QGraphicsItem *> shades = m_shades->childItems();
76 76 QList<QGraphicsItem *> axis = m_axis->childItems();
77 77
78 78 Q_ASSERT(labels.size() == ticksList.size());
79 79 Q_ASSERT(layout.size() == ticksList.size());
80 80
81 81 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
82 82 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
83 83
84 84 for (int i = 1; i < layout.size(); ++i) {
85 85 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
86 86 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
87 87 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i-1));
88 88
89 89 labelItem->setText(ticksList.at(i-1));
90 90 const QRectF& rect = labelItem->boundingRect();
91 91 QPointF center = rect.center();
92 92 labelItem->setTransformOriginPoint(center.x(), center.y());
93 93 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
94 94 m_minWidth+=rect.width();
95 95 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
96 96
97 97 if ((i+1)%2 && i>1) {
98 98 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
99 99 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
100 100 }
101 101 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
102 102 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
103 103 }
104 104 }
105 105
106 106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,59 +1,59
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTCATEGORIESAXISX_H
31 31 #define CHARTCATEGORIESAXISX_H
32 32
33 33 #include "chartaxis_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAbstractAxis;
38 38 class ChartPresenter;
39 class QCategoriesAxis;
39 class QBarCategoriesAxis;
40 40
41 41 class ChartCategoriesAxisX : public ChartAxis
42 42 {
43 43 public:
44 ChartCategoriesAxisX(QCategoriesAxis *axis, ChartPresenter *presenter);
44 ChartCategoriesAxisX(QBarCategoriesAxis *axis, ChartPresenter *presenter);
45 45 ~ChartCategoriesAxisX();
46 46
47 47 AxisType axisType() const { return X_AXIS;}
48 48
49 49 protected:
50 50 QVector<qreal> calculateLayout() const;
51 51 void updateGeometry();
52 52
53 53 private:
54 QCategoriesAxis *m_categoriesAxis;
54 QBarCategoriesAxis *m_categoriesAxis;
55 55 };
56 56
57 57 QTCOMMERCIALCHART_END_NAMESPACE
58 58
59 59 #endif /* CHARTCATEGORIESAXISX_H */
@@ -1,59 +1,59
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTCATEGORIESAXISY_H
31 31 #define CHARTCATEGORIESAXISY_H
32 32
33 33 #include "chartaxis_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAbstractAxis;
38 class QCategoriesAxis;
38 class QBarCategoriesAxis;
39 39 class ChartPresenter;
40 40
41 41 class ChartCategoriesAxisY : public ChartAxis
42 42 {
43 43 public:
44 44 ChartCategoriesAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
45 45 ~ChartCategoriesAxisY();
46 46
47 47 AxisType axisType() const { return Y_AXIS;}
48 48
49 49 protected:
50 50 QVector<qreal> calculateLayout() const;
51 51 void updateGeometry();
52 52
53 53 private:
54 QCategoriesAxis *m_categoriesAxis;
54 QBarCategoriesAxis *m_categoriesAxis;
55 55 };
56 56
57 57 QTCOMMERCIALCHART_END_NAMESPACE
58 58
59 59 #endif /* CHARTCATEGORIESAXISY_H */
@@ -1,297 +1,297
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qcategoriesaxis.h"
22 22 #include "qcategoriesaxis_p.h"
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 QCategoriesAxis::QCategoriesAxis(QObject *parent):
31 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
30 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
31 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
32 32 {
33 33 }
34 34
35 QCategoriesAxis::~QCategoriesAxis()
35 QBarCategoriesAxis::~QBarCategoriesAxis()
36 36 {
37 37 }
38 38
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
40 40 {
41 41
42 42 }
43 43
44 44 /*!
45 45 Appends \a categories to axis
46 46 */
47 void QCategoriesAxis::append(const QStringList &categories)
47 void QBarCategoriesAxis::append(const QStringList &categories)
48 48 {
49 Q_D(QCategoriesAxis);
49 Q_D(QBarCategoriesAxis);
50 50 if (d->m_categories.isEmpty()) {
51 51 d->m_categories.append(categories);
52 52 setRange(categories.first(),categories.last());
53 53 }else{
54 54 d->m_categories.append(categories);
55 55 }
56 56
57 57 emit categoriesChanged();
58 58 }
59 59
60 60 /*!
61 61 Appends \a category to axis
62 62 */
63 void QCategoriesAxis::append(const QString &category)
63 void QBarCategoriesAxis::append(const QString &category)
64 64 {
65 Q_D(QCategoriesAxis);
65 Q_D(QBarCategoriesAxis);
66 66 if (d->m_categories.isEmpty()) {
67 67 d->m_categories.append(category);
68 68 setRange(category,category);
69 69 }else{
70 70 d->m_categories.append(category);
71 71 }
72 72 emit categoriesChanged();
73 73 }
74 74
75 75 /*!
76 76 Removes \a category from axis
77 77 */
78 void QCategoriesAxis::remove(const QString &category)
78 void QBarCategoriesAxis::remove(const QString &category)
79 79 {
80 Q_D(QCategoriesAxis);
80 Q_D(QBarCategoriesAxis);
81 81 if (d->m_categories.contains(category)) {
82 82 d->m_categories.removeAt(d->m_categories.indexOf(category));
83 83 setRange(d->m_categories.first(),d->m_categories.last());
84 84 emit categoriesChanged();
85 85 }
86 86 }
87 87
88 88 /*!
89 89 Inserts \a category to axis at \a index
90 90 */
91 void QCategoriesAxis::insert(int index, const QString &category)
91 void QBarCategoriesAxis::insert(int index, const QString &category)
92 92 {
93 Q_D(QCategoriesAxis);
93 Q_D(QBarCategoriesAxis);
94 94 if (d->m_categories.isEmpty()) {
95 95 d->m_categories.insert(index,category);
96 96 setRange(category,category);
97 97 }else{
98 98
99 99 }
100 100 emit categoriesChanged();
101 101 }
102 102
103 103 /*!
104 104 Removes all categories.
105 105 */
106 void QCategoriesAxis::clear()
106 void QBarCategoriesAxis::clear()
107 107 {
108 Q_D(QCategoriesAxis);
108 Q_D(QBarCategoriesAxis);
109 109 d->m_categories.clear();
110 110 setRange(QString::null,QString::null);
111 111 emit categoriesChanged();
112 112 }
113 113
114 void QCategoriesAxis::setCategories(const QStringList &categories)
114 void QBarCategoriesAxis::setCategories(const QStringList &categories)
115 115 {
116 Q_D(QCategoriesAxis);
116 Q_D(QBarCategoriesAxis);
117 117 if(d->m_categories!=categories){
118 118 d->m_categories = categories;
119 119 setRange(categories.first(),categories.last());
120 120 emit categoriesChanged();
121 121 }
122 122 }
123 123
124 QStringList QCategoriesAxis::categories()
124 QStringList QBarCategoriesAxis::categories()
125 125 {
126 Q_D(QCategoriesAxis);
126 Q_D(QBarCategoriesAxis);
127 127 return d->m_categories;
128 128 }
129 129
130 130 /*!
131 131 Returns number of categories.
132 132 */
133 int QCategoriesAxis::count() const
133 int QBarCategoriesAxis::count() const
134 134 {
135 Q_D(const QCategoriesAxis);
135 Q_D(const QBarCategoriesAxis);
136 136 return d->m_categories.count();
137 137 }
138 138
139 139 /*!
140 140 Returns category at \a index. Index must be valid.
141 141 */
142 QString QCategoriesAxis::at(int index) const
142 QString QBarCategoriesAxis::at(int index) const
143 143 {
144 Q_D(const QCategoriesAxis);
144 Q_D(const QBarCategoriesAxis);
145 145 return d->m_categories.at(index);
146 146 }
147 147
148 148 /*!
149 149 Sets minimum category to \a min.
150 150 */
151 void QCategoriesAxis::setMin(const QString& min)
151 void QBarCategoriesAxis::setMin(const QString& min)
152 152 {
153 Q_D(QCategoriesAxis);
153 Q_D(QBarCategoriesAxis);
154 154 setRange(min,d->m_maxCategory);
155 155 }
156 156
157 157 /*!
158 158 Returns minimum category.
159 159 */
160 QString QCategoriesAxis::min() const
160 QString QBarCategoriesAxis::min() const
161 161 {
162 Q_D(const QCategoriesAxis);
162 Q_D(const QBarCategoriesAxis);
163 163 return d->m_minCategory;
164 164 }
165 165
166 166 /*!
167 167 Sets maximum category to \a max.
168 168 */
169 void QCategoriesAxis::setMax(const QString& max)
169 void QBarCategoriesAxis::setMax(const QString& max)
170 170 {
171 Q_D(QCategoriesAxis);
171 Q_D(QBarCategoriesAxis);
172 172 setRange(d->m_minCategory,max);
173 173 }
174 174
175 175 /*!
176 176 Returns maximum category
177 177 */
178 QString QCategoriesAxis::max() const
178 QString QBarCategoriesAxis::max() const
179 179 {
180 Q_D(const QCategoriesAxis);
180 Q_D(const QBarCategoriesAxis);
181 181 return d->m_maxCategory;
182 182 }
183 183
184 184 /*!
185 185 Sets range from \a minCategory to \a maxCategory
186 186 */
187 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
187 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
188 188 {
189 Q_D(QCategoriesAxis);
189 Q_D(QBarCategoriesAxis);
190 190
191 191 int minIndex = d->m_categories.indexOf(minCategory);
192 192 if (minIndex == -1) {
193 193 return;
194 194 }
195 195 int maxIndex = d->m_categories.indexOf(maxCategory);
196 196 if (maxIndex == -1) {
197 197 return;
198 198 }
199 199
200 200 if (maxIndex <= minIndex) {
201 201 // max must be greater than min
202 202 return;
203 203 }
204 204
205 205 bool changed = false;
206 206 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
207 207 d->m_minCategory = minCategory;
208 208 d->m_min = minIndex;
209 209 changed = true;
210 210 }
211 211
212 212 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
213 213 d->m_max = maxIndex;
214 214 d->m_maxCategory = maxCategory;
215 215 changed = true;
216 216 }
217 217
218 218 if ((changed)) {
219 219 d->emitRange();
220 220 emit categoriesChanged();
221 221 }
222 222 }
223 223
224 224 /*!
225 225 Returns the type of axis.
226 226 */
227 QAbstractAxis::AxisType QCategoriesAxis::type() const
227 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
228 228 {
229 229 return AxisTypeCategories;
230 230 }
231 231
232 232 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233 233
234 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
234 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
235 235 QAbstractAxisPrivate(q)
236 236 {
237 237
238 238 }
239 239
240 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
240 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
241 241 {
242 242
243 243 }
244 244
245 void QCategoriesAxisPrivate::setMin(const QVariant &min)
245 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
246 246 {
247 247 setRange(min,m_maxCategory);
248 248 }
249 249
250 void QCategoriesAxisPrivate::setMax(const QVariant &max)
250 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
251 251 {
252 252 setRange(m_minCategory,max);
253 253 }
254 254
255 void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
255 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
256 256 {
257 Q_Q(QCategoriesAxis);
257 Q_Q(QBarCategoriesAxis);
258 258 QString value1 = min.toString();
259 259 QString value2 = max.toString();
260 260 q->setRange(value1,value2);
261 261 }
262 262
263 int QCategoriesAxisPrivate::ticksCount() const
263 int QBarCategoriesAxisPrivate::ticksCount() const
264 264 {
265 265 return m_categories.count()+1;
266 266 }
267 267
268 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
268 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
269 269 {
270 270 m_min = min;
271 271 m_max = max;
272 272 m_ticksCount = count;
273 273 }
274 274
275 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
275 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
276 276 {
277 Q_Q( QCategoriesAxis);
277 Q_Q( QBarCategoriesAxis);
278 278 if(m_orientation == Qt::Vertical){
279 279 return new ChartCategoriesAxisY(q,presenter);
280 280 }else{
281 281 return new ChartCategoriesAxisX(q,presenter);
282 282 }
283 283 }
284 284
285 void QCategoriesAxisPrivate::emitRange()
285 void QBarCategoriesAxisPrivate::emitRange()
286 286 {
287 Q_Q( QCategoriesAxis);
287 Q_Q( QBarCategoriesAxis);
288 288 if(!q->signalsBlocked()) {
289 289 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
290 290 }
291 291 }
292 292
293 293
294 294 #include "moc_qcategoriesaxis.cpp"
295 295 #include "moc_qcategoriesaxis_p.cpp"
296 296
297 297 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,76 +1,76
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QCATEGORIESAXIS_H
22 22 #define QCATEGORIESAXIS_H
23 23
24 24 #include "qabstractaxis.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 class QCategoriesAxisPrivate;
28 class QBarCategoriesAxisPrivate;
29 29
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
36 36
37 37 public:
38 explicit QCategoriesAxis(QObject *parent = 0);
39 ~QCategoriesAxis();
38 explicit QBarCategoriesAxis(QObject *parent = 0);
39 ~QBarCategoriesAxis();
40 40
41 41 protected:
42 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
42 QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0);
43 43
44 44 public:
45 45 AxisType type() const;
46 46 void append(const QStringList &categories);
47 47 void append(const QString &category);
48 48 void remove(const QString &category);
49 49 void insert(int index, const QString &category);
50 50 void clear();
51 51 void setCategories(const QStringList &categories);
52 52 QStringList categories();
53 53 int count() const;
54 54 QString at(int index) const;
55 55
56 56 //range handling
57 57 void setMin(const QString& minCategory);
58 58 QString min() const;
59 59 void setMax(const QString& maxCategory);
60 60 QString max() const;
61 61 void setRange(const QString& minCategory, const QString& maxCategory);
62 62
63 63 Q_SIGNALS:
64 64 void categoriesChanged();
65 65 void minChanged(const QString &min);
66 66 void maxChanged(const QString &max);
67 67 void rangeChanged(const QString &min, const QString &max);
68 68
69 69 private:
70 Q_DECLARE_PRIVATE(QCategoriesAxis)
71 Q_DISABLE_COPY(QCategoriesAxis)
70 Q_DECLARE_PRIVATE(QBarCategoriesAxis)
71 Q_DISABLE_COPY(QBarCategoriesAxis)
72 72 };
73 73
74 74 QTCOMMERCIALCHART_END_NAMESPACE
75 75
76 76 #endif // QCATEGORIESAXIS_H
@@ -1,74 +1,74
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QCATEGORIESAXIS_P_H
31 31 #define QCATEGORIESAXIS_P_H
32 32
33 33 #include "qcategoriesaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
38 class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate
39 39 {
40 40 Q_OBJECT
41 41
42 42 public:
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
44 ~QCategoriesAxisPrivate();
43 QBarCategoriesAxisPrivate(QBarCategoriesAxis *q);
44 ~QBarCategoriesAxisPrivate();
45 45
46 46 public:
47 47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 48 void emitRange();
49 49
50 50 private:
51 51 //range handling
52 52 void setMin(const QVariant &min);
53 53 void setMax(const QVariant &max);
54 54 void setRange(const QVariant &min, const QVariant &max);
55 55 int ticksCount() const;
56 56
57 57 Q_SIGNALS:
58 58 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
59 59
60 60 public Q_SLOTS:
61 61 void handleAxisRangeChanged(qreal min, qreal max,int count);
62 62
63 63 private:
64 64 QStringList m_categories;
65 65 QString m_minCategory;
66 66 QString m_maxCategory;
67 67
68 68 private:
69 Q_DECLARE_PUBLIC(QCategoriesAxis)
69 Q_DECLARE_PUBLIC(QBarCategoriesAxis)
70 70 };
71 71
72 72 QTCOMMERCIALCHART_END_NAMESPACE
73 73
74 74 #endif // QCATEGORIESAXIS_P_H
@@ -1,743 +1,743
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qabstractbarseries.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "domain_p.h"
26 26 #include "legendmarker_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartanimator_p.h"
30 30 #include "qvaluesaxis.h"
31 31 #include "qcategoriesaxis.h"
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 35 /*!
36 36 \class QAbstractBarSeries
37 37 \brief Series for creating a bar chart
38 38 \mainclass
39 39
40 40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 43 shows the x-values.
44 44
45 45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 46 \image examples_barchart.png
47 47
48 48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 49 */
50 50 /*!
51 51 \qmlclass AbstractBarSeries QAbstractBarSeries
52 52 \inherits QAbstractSeries
53 53
54 54 The following QML shows how to create a simple bar chart:
55 55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56 56
57 57 \beginfloatleft
58 58 \image demos_qmlchart6.png
59 59 \endfloat
60 60 \clearfloat
61 61 */
62 62
63 63 /*!
64 64 \property QAbstractBarSeries::barWidth
65 65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
69 69 \sa QBarSeries
70 70 */
71 71 /*!
72 72 \qmlproperty real AbstractBarSeries::barWidth
73 73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
77 77 */
78 78
79 79 /*!
80 80 \property QAbstractBarSeries::count
81 81 Holds the number of sets in series.
82 82 */
83 83 /*!
84 84 \qmlproperty int AbstractBarSeries::count
85 85 Holds the number of sets in series.
86 86 */
87 87
88 88 /*!
89 89 \property QAbstractBarSeries::labelsVisible
90 90 Defines the visibility of the labels in series
91 91 */
92 92 /*!
93 93 \qmlproperty bool AbstractBarSeries::labelsVisible
94 94 Defines the visibility of the labels in series
95 95 */
96 96
97 97 /*!
98 98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 100 Clicked bar inside set is indexed by \a index
101 101 */
102 102 /*!
103 103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
104 104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 105 Clicked bar inside set is indexed by \a index
106 106 */
107 107
108 108 /*!
109 109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110 110
111 111 The signal is emitted if mouse is hovered on top of series.
112 112 Parameter \a barset is the pointer of barset, where hover happened.
113 113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 114 */
115 115 /*!
116 116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
117 117
118 118 The signal is emitted if mouse is hovered on top of series.
119 119 Parameter \a barset is the pointer of barset, where hover happened.
120 120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 121 */
122 122
123 123 /*!
124 124 \fn void QAbstractBarSeries::countChanged()
125 125 This signal is emitted when barset count has been changed, for example by append or remove.
126 126 */
127 127 /*!
128 128 \qmlsignal AbstractBarSeries::onCountChanged()
129 129 This signal is emitted when barset count has been changed, for example by append or remove.
130 130 */
131 131
132 132 /*!
133 133 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 134 This signal is emitted when labels visibility have changed.
135 135 \sa isLabelsVisible(), setLabelsVisible()
136 136 */
137 137
138 138 /*!
139 139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 140 This signal is emitted when \a sets have been added to the series.
141 141 \sa append(), insert()
142 142 */
143 143 /*!
144 144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
145 145 Emitted when \a barset has been added to the series.
146 146 */
147 147
148 148 /*!
149 149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 150 This signal is emitted when \a sets have been removed from the series.
151 151 \sa remove()
152 152 */
153 153 /*!
154 154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
155 155 Emitted when \a barset has been removed from the series.
156 156 */
157 157
158 158 /*!
159 159 \qmlmethod BarSet AbstractBarSeries::at(int index)
160 160 Returns bar set at \a index. Returns null if the index is not valid.
161 161 */
162 162
163 163 /*!
164 164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
165 165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
166 166 For example:
167 167 \code
168 168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 170 \endcode
171 171 */
172 172
173 173 /*!
174 174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
175 175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
176 176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 177 appended.
178 178 \sa AbstractBarSeries::append()
179 179 */
180 180
181 181 /*!
182 182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
183 183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 184 */
185 185
186 186 /*!
187 187 \qmlmethod AbstractBarSeries::clear()
188 188 Removes all barsets from the series.
189 189 */
190 190
191 191 /*!
192 192 Constructs empty QAbstractBarSeries.
193 193 QAbstractBarSeries is QObject which is a child of a \a parent.
194 194 */
195 195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
196 196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
197 197 {
198 198 }
199 199
200 200 /*!
201 201 Destructs abstractbarseries and owned barsets.
202 202 */
203 203 QAbstractBarSeries::~QAbstractBarSeries()
204 204 {
205 205 Q_D(QAbstractBarSeries);
206 206 if(d->m_dataset){
207 207 d->m_dataset->removeSeries(this);
208 208 }
209 209 }
210 210
211 211 /*!
212 212 \internal
213 213 */
214 214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
215 215 QAbstractSeries(d,parent)
216 216 {
217 217 }
218 218
219 219 /*!
220 220 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
221 221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
222 222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
223 223 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
224 224 */
225 225 void QAbstractBarSeries::setBarWidth(qreal width)
226 226 {
227 227 Q_D(QAbstractBarSeries);
228 228 d->setBarWidth(width);
229 229 }
230 230
231 231 /*!
232 232 Returns the width of the bars of the series.
233 233 \sa setBarWidth()
234 234 */
235 235 qreal QAbstractBarSeries::barWidth() const
236 236 {
237 237 Q_D(const QAbstractBarSeries);
238 238 return d->barWidth();
239 239 }
240 240
241 241 /*!
242 242 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.
243 243 Returns true, if appending succeeded.
244 244 */
245 245 bool QAbstractBarSeries::append(QBarSet *set)
246 246 {
247 247 Q_D(QAbstractBarSeries);
248 248 bool success = d->append(set);
249 249 if (success) {
250 250 QList<QBarSet*> sets;
251 251 sets.append(set);
252 252 emit barsetsAdded(sets);
253 253 emit countChanged();
254 254 }
255 255 return success;
256 256 }
257 257
258 258 /*!
259 259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
260 260 Returns true, if set was removed.
261 261 */
262 262 bool QAbstractBarSeries::remove(QBarSet *set)
263 263 {
264 264 Q_D(QAbstractBarSeries);
265 265 bool success = d->remove(set);
266 266 if (success) {
267 267 QList<QBarSet*> sets;
268 268 sets.append(set);
269 269 emit barsetsRemoved(sets);
270 270 emit countChanged();
271 271 }
272 272 return success;
273 273 }
274 274
275 275 /*!
276 276 Adds a list of barsets to series. Takes ownership of \a sets.
277 277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
278 278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
279 279 and function returns false.
280 280 */
281 281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
282 282 {
283 283 Q_D(QAbstractBarSeries);
284 284 bool success = d->append(sets);
285 285 if (success) {
286 286 emit barsetsAdded(sets);
287 287 emit countChanged();
288 288 }
289 289 return success;
290 290 }
291 291
292 292 /*!
293 293 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
294 294 Returns true, if inserting succeeded.
295 295
296 296 */
297 297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
298 298 {
299 299 Q_D(QAbstractBarSeries);
300 300 bool success = d->insert(index, set);
301 301 if (success) {
302 302 QList<QBarSet*> sets;
303 303 sets.append(set);
304 304 emit barsetsAdded(sets);
305 305 emit countChanged();
306 306 }
307 307 return success;
308 308 }
309 309
310 310 /*!
311 311 Removes all of the bar sets from the series
312 312 */
313 313 void QAbstractBarSeries::clear()
314 314 {
315 315 Q_D(QAbstractBarSeries);
316 316 QList<QBarSet *> sets = barSets();
317 317 bool success = d->remove(sets);
318 318 if (success) {
319 319 emit barsetsRemoved(sets);
320 320 emit countChanged();
321 321 }
322 322 }
323 323
324 324 /*!
325 325 Returns number of sets in series.
326 326 */
327 327 int QAbstractBarSeries::count() const
328 328 {
329 329 Q_D(const QAbstractBarSeries);
330 330 return d->m_barSets.count();
331 331 }
332 332
333 333 /*!
334 334 Returns a list of sets in series. Keeps ownership of sets.
335 335 */
336 336 QList<QBarSet*> QAbstractBarSeries::barSets() const
337 337 {
338 338 Q_D(const QAbstractBarSeries);
339 339 return d->m_barSets;
340 340 }
341 341
342 342 /*!
343 343 Sets the visibility of labels in series to \a visible
344 344 */
345 345 void QAbstractBarSeries::setLabelsVisible(bool visible)
346 346 {
347 347 Q_D(QAbstractBarSeries);
348 348 if (d->m_labelsVisible != visible) {
349 349 d->setLabelsVisible(visible);
350 350 emit labelsVisibleChanged();
351 351 }
352 352 }
353 353
354 354 /*!
355 355 Returns the visibility of labels
356 356 */
357 357 bool QAbstractBarSeries::isLabelsVisible() const
358 358 {
359 359 Q_D(const QAbstractBarSeries);
360 360 return d->m_labelsVisible;
361 361 }
362 362
363 363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364 364
365 365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
366 366 QAbstractSeriesPrivate(q),
367 367 m_barWidth(0.5), // Default value is 50% of category width
368 368 m_labelsVisible(false),
369 369 m_visible(true)
370 370 {
371 371 }
372 372
373 373 int QAbstractBarSeriesPrivate::categoryCount() const
374 374 {
375 375 // No categories defined. return count of longest set.
376 376 int count = 0;
377 377 for (int i=0; i<m_barSets.count(); i++) {
378 378 if (m_barSets.at(i)->count() > count) {
379 379 count = m_barSets.at(i)->count();
380 380 }
381 381 }
382 382
383 383 return count;
384 384 }
385 385
386 386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
387 387 {
388 388 if (width < 0.0) {
389 389 width = 0.0;
390 390 }
391 391 m_barWidth = width;
392 392 emit updatedBars();
393 393 }
394 394
395 395 qreal QAbstractBarSeriesPrivate::barWidth() const
396 396 {
397 397 return m_barWidth;
398 398 }
399 399
400 400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
401 401 {
402 402 return m_barSets.at(index);
403 403 }
404 404
405 405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
406 406 {
407 407 m_visible = visible;
408 408 emit updatedBars();
409 409 }
410 410
411 411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
412 412 {
413 413 m_labelsVisible = visible;
414 414 emit labelsVisibleChanged(visible);
415 415 }
416 416
417 417 qreal QAbstractBarSeriesPrivate::min()
418 418 {
419 419 if (m_barSets.count() <= 0) {
420 420 return 0;
421 421 }
422 422 qreal min = INT_MAX;
423 423
424 424 for (int i = 0; i < m_barSets.count(); i++) {
425 425 int categoryCount = m_barSets.at(i)->count();
426 426 for (int j = 0; j < categoryCount; j++) {
427 427 qreal temp = m_barSets.at(i)->at(j);
428 428 if (temp < min)
429 429 min = temp;
430 430 }
431 431 }
432 432 return min;
433 433 }
434 434
435 435 qreal QAbstractBarSeriesPrivate::max()
436 436 {
437 437 if (m_barSets.count() <= 0) {
438 438 return 0;
439 439 }
440 440 qreal max = INT_MIN;
441 441
442 442 for (int i = 0; i < m_barSets.count(); i++) {
443 443 int categoryCount = m_barSets.at(i)->count();
444 444 for (int j = 0; j < categoryCount; j++) {
445 445 qreal temp = m_barSets.at(i)->at(j);
446 446 if (temp > max)
447 447 max = temp;
448 448 }
449 449 }
450 450
451 451 return max;
452 452 }
453 453
454 454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
455 455 {
456 456 if ((set < 0) || (set >= m_barSets.count())) {
457 457 // No set, no value.
458 458 return 0;
459 459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
460 460 // No category, no value.
461 461 return 0;
462 462 }
463 463
464 464 return m_barSets.at(set)->at(category);
465 465 }
466 466
467 467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
468 468 {
469 469 if ((set < 0) || (set >= m_barSets.count())) {
470 470 // No set, no value.
471 471 return 0;
472 472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
473 473 // No category, no value.
474 474 return 0;
475 475 }
476 476
477 477 qreal value = m_barSets.at(set)->at(category);
478 478 qreal sum = categorySum(category);
479 479 if ( qFuzzyIsNull(sum) ) {
480 480 return 0;
481 481 }
482 482
483 483 return value / sum;
484 484 }
485 485
486 486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
487 487 {
488 488 qreal sum(0);
489 489 int count = m_barSets.count(); // Count sets
490 490 for (int set = 0; set < count; set++) {
491 491 if (category < m_barSets.at(set)->count())
492 492 sum += m_barSets.at(set)->at(category);
493 493 }
494 494 return sum;
495 495 }
496 496
497 497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
498 498 {
499 499 qreal sum(0);
500 500 int count = m_barSets.count(); // Count sets
501 501 for (int set = 0; set < count; set++) {
502 502 if (category < m_barSets.at(set)->count())
503 503 sum += qAbs(m_barSets.at(set)->at(category));
504 504 }
505 505 return sum;
506 506 }
507 507
508 508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
509 509 {
510 510 qreal max = INT_MIN;
511 511 int count = categoryCount();
512 512 for (int i = 0; i < count; i++) {
513 513 qreal sum = categorySum(i);
514 514 if (sum > max)
515 515 max = sum;
516 516 }
517 517 return max;
518 518 }
519 519
520 520 qreal QAbstractBarSeriesPrivate::minX()
521 521 {
522 522 if (m_barSets.count() <= 0) {
523 523 return 0;
524 524 }
525 525 qreal min = INT_MAX;
526 526
527 527 for (int i = 0; i < m_barSets.count(); i++) {
528 528 int categoryCount = m_barSets.at(i)->count();
529 529 for (int j = 0; j < categoryCount; j++) {
530 530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
531 531 if (temp < min)
532 532 min = temp;
533 533 }
534 534 }
535 535 return min;
536 536 }
537 537
538 538 qreal QAbstractBarSeriesPrivate::maxX()
539 539 {
540 540 if (m_barSets.count() <= 0) {
541 541 return 0;
542 542 }
543 543 qreal max = INT_MIN;
544 544
545 545 for (int i = 0; i < m_barSets.count(); i++) {
546 546 int categoryCount = m_barSets.at(i)->count();
547 547 for (int j = 0; j < categoryCount; j++) {
548 548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
549 549 if (temp > max)
550 550 max = temp;
551 551 }
552 552 }
553 553
554 554 return max;
555 555 }
556 556
557 557
558 558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
559 559 {
560 560 qreal minX(domain.minX());
561 561 qreal minY(domain.minY());
562 562 qreal maxX(domain.maxX());
563 563 qreal maxY(domain.maxY());
564 564 int tickXCount(domain.tickXCount());
565 565 int tickYCount(domain.tickYCount());
566 566
567 567 qreal seriesMinX = this->minX();
568 568 qreal seriesMaxX = this->maxX();
569 569 qreal y = max();
570 570 minX = qMin(minX, seriesMinX - 0.5);
571 571 minY = qMin(minY, y);
572 572 maxX = qMax(maxX, seriesMaxX + 0.5);
573 573 maxY = qMax(maxY, y);
574 574 tickXCount = categoryCount()+1;
575 575
576 576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
577 577 }
578 578
579 579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
580 580 {
581 581 Q_Q(QAbstractBarSeries);
582 582
583 583 BarChartItem* bar = new BarChartItem(q,presenter);
584 584 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
585 585 presenter->animator()->addAnimation(bar);
586 586 }
587 587 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
588 588 return bar;
589 589
590 590 }
591 591
592 592 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
593 593 {
594 594 Q_Q(QAbstractBarSeries);
595 595 QList<LegendMarker*> markers;
596 596 foreach(QBarSet* set, q->barSets()) {
597 597 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
598 598 markers << marker;
599 599 }
600 600
601 601 return markers;
602 602 }
603 603
604 604 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
605 605 {
606 606 Q_Q(QAbstractBarSeries);
607 607 if ((m_barSets.contains(set)) || (set == 0)) {
608 608 // Fail if set is already in list or set is null.
609 609 return false;
610 610 }
611 611 m_barSets.append(set);
612 612 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
613 613 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
614 614 emit restructuredBars(); // this notifies barchartitem
615 615 if (m_dataset) {
616 616 m_dataset->updateSeries(q); // this notifies legend
617 617 }
618 618 return true;
619 619 }
620 620
621 621 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
622 622 {
623 623 Q_Q(QAbstractBarSeries);
624 624 if (!m_barSets.contains(set)) {
625 625 // Fail if set is not in list
626 626 return false;
627 627 }
628 628 m_barSets.removeOne(set);
629 629 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
630 630 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
631 631 emit restructuredBars(); // this notifies barchartitem
632 632 if (m_dataset) {
633 633 m_dataset->updateSeries(q); // this notifies legend
634 634 }
635 635 return true;
636 636 }
637 637
638 638 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
639 639 {
640 640 Q_Q(QAbstractBarSeries);
641 641 foreach (QBarSet* set, sets) {
642 642 if ((set == 0) || (m_barSets.contains(set))) {
643 643 // Fail if any of the sets is null or is already appended.
644 644 return false;
645 645 }
646 646 if (sets.count(set) != 1) {
647 647 // Also fail if same set is more than once in given list.
648 648 return false;
649 649 }
650 650 }
651 651
652 652 foreach (QBarSet* set, sets) {
653 653 m_barSets.append(set);
654 654 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
655 655 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
656 656 }
657 657 emit restructuredBars(); // this notifies barchartitem
658 658 if (m_dataset) {
659 659 m_dataset->updateSeries(q); // this notifies legend
660 660 }
661 661 return true;
662 662 }
663 663
664 664 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
665 665 {
666 666 Q_Q(QAbstractBarSeries);
667 667 if (sets.count() == 0) {
668 668 return false;
669 669 }
670 670 foreach (QBarSet* set, sets) {
671 671 if ((set == 0) || (!m_barSets.contains(set))) {
672 672 // Fail if any of the sets is null or is not in series
673 673 return false;
674 674 }
675 675 if (sets.count(set) != 1) {
676 676 // Also fail if same set is more than once in given list.
677 677 return false;
678 678 }
679 679 }
680 680
681 681 foreach (QBarSet* set, sets) {
682 682 m_barSets.removeOne(set);
683 683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
684 684 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
685 685 }
686 686
687 687 emit restructuredBars(); // this notifies barchartitem
688 688 if (m_dataset) {
689 689 m_dataset->updateSeries(q); // this notifies legend
690 690 }
691 691 return true;
692 692 }
693 693
694 694 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
695 695 {
696 696 Q_Q(QAbstractBarSeries);
697 697 if ((m_barSets.contains(set)) || (set == 0)) {
698 698 // Fail if set is already in list or set is null.
699 699 return false;
700 700 }
701 701 m_barSets.insert(index, set);
702 702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
703 703 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
704 704 emit restructuredBars(); // this notifies barchartitem
705 705 if (m_dataset) {
706 706 m_dataset->updateSeries(q); // this notifies legend
707 707 }
708 708 return true;
709 709 }
710 710
711 711 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
712 712 {
713 713 if(axis->type()==QAbstractAxis::AxisTypeCategories)
714 714 {
715 QCategoriesAxis* cataxis = qobject_cast<QCategoriesAxis*>(axis);
715 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
716 716 Q_ASSERT(cataxis);
717 717 QStringList categories;
718 718 for (int i(1); i < categoryCount()+1; i++)
719 719 categories << QString::number(i);
720 720 cataxis->append(categories);
721 721 }
722 722 }
723 723
724 724 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
725 725 {
726 726 Q_UNUSED(axis)
727 727 }
728 728
729 729 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
730 730 {
731 731 return QAbstractAxis::AxisTypeCategories;
732 732 }
733 733
734 734 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
735 735 {
736 736 return QAbstractAxis::AxisTypeValues;
737 737 }
738 738
739 739 #include "moc_qabstractbarseries.cpp"
740 740 #include "moc_qabstractbarseries_p.cpp"
741 741
742 742
743 743 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,446 +1,446
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdataset_p.h"
22 22 #include "qchart.h"
23 23 #include "qvaluesaxis.h"
24 24 #include "qcategoriesaxis.h"
25 25 #include "qvaluesaxis_p.h"
26 26 #include "qabstractseries_p.h"
27 27 #include "qabstractbarseries.h"
28 28 #include "qstackedbarseries.h"
29 29 #include "qpercentbarseries.h"
30 30 #include "qpieseries.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
35 35 m_domainIndex(0)
36 36 {
37 37
38 38 }
39 39
40 40 ChartDataSet::~ChartDataSet()
41 41 {
42 42 removeAllSeries();
43 43 }
44 44
45 45 void ChartDataSet::addSeries(QAbstractSeries* series)
46 46 {
47 47 Domain* domain = m_seriesDomainMap.value(series);
48 48
49 49 if(domain) {
50 50 qWarning() << "Can not add series. Series already on the chart";
51 51 return;
52 52 }
53 53
54 54 series->setParent(this); // take ownership
55 55
56 56 domain = new Domain(series);
57 57
58 58 m_seriesDomainMap.insert(series,domain);
59 59
60 60 series->d_ptr->scaleDomain(*domain);
61 61
62 62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
63 63
64 64 int key=0;
65 65 while (i.hasNext()) {
66 66 i.next();
67 67 if(i.key()!=key) {
68 68 break;
69 69 }
70 70 key++;
71 71 }
72 72
73 73 m_indexSeriesMap.insert(key,series);
74 74
75 75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
76 76 series->d_ptr->m_dataset = this;
77 77
78 78 emit seriesAdded(series,domain);
79 79
80 80 }
81 81
82 82 void ChartDataSet::createDefaultAxes()
83 83 {
84 84
85 85 if(m_seriesDomainMap.isEmpty()) return;
86 86
87 87 QAbstractAxis::AxisTypes typeX(0);
88 88 QAbstractAxis::AxisTypes typeY(0);
89 89
90 90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
91 91 while (i.hasNext()) {
92 92 i.next();
93 93 removeAxes(i.key());
94 94 }
95 95
96 96 i.toFront();
97 97
98 98 while (i.hasNext()) {
99 99 i.next();
100 100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
101 101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
102 102 if(axisX) typeX&=axisX->type();
103 103 else typeX|=i.key()->d_ptr->defaultAxisXType();
104 104 if(axisY) typeY&=axisY->type();
105 105 else typeY|=i.key()->d_ptr->defaultAxisYType();
106 106 }
107 107
108 108
109 109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
110 110 {
111 111 i.toFront();
112 112 while (i.hasNext()) {
113 113 i.next();
114 114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
115 115 i.key()->d_ptr->initializeAxisX(axis);
116 116 addAxisX(axis,i.key());
117 117 emit axisAdded(axis,i.value());
118 118 }
119 119
120 120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
121 121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
122 122 i.toFront();
123 123 while (i.hasNext()) {
124 124 i.next();
125 125 i.key()->d_ptr->initializeAxisX(axis);
126 126 addAxisX(axis,i.key());
127 127 }
128 128 emit axisAdded(axis,i.value());
129 129
130 130 }
131 131
132 132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
133 133 {
134 134 i.toFront();
135 135 while (i.hasNext()) {
136 136 i.next();
137 137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
138 138 i.key()->d_ptr->initializeAxisY(axis);
139 139 addAxisY(axis,i.key());
140 140 emit axisAdded(axis,i.value());
141 141 }
142 142
143 143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
144 144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
145 145 i.toFront();
146 146 while (i.hasNext()) {
147 147 i.next();
148 148 i.key()->d_ptr->initializeAxisY(axis);
149 149 addAxisY(axis,i.key());
150 150 }
151 151 emit axisAdded(axis,i.value());
152 152
153 153 }
154 154 }
155 155
156 156
157 157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
158 158 {
159 159 QAbstractAxis* axis =0;
160 160
161 161 switch(type) {
162 162 case QAbstractAxis::AxisTypeValues:
163 163 axis = new QValuesAxis(this);
164 164 break;
165 165 case QAbstractAxis::AxisTypeCategories:
166 axis = new QCategoriesAxis(this);
166 axis = new QBarCategoriesAxis(this);
167 167 break;
168 168 default:
169 169 axis = 0;
170 170 break;
171 171 }
172 172
173 173 return axis;
174 174 }
175 175
176 176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
177 177 Domain* domain = m_seriesDomainMap.value(series);
178 178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
179 179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
180 180 axis->d_ptr->m_orientation=Qt::Horizontal;
181 181 m_seriesAxisXMap.insert(series,axis);
182 182 }
183 183
184 184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
185 185 Domain* domain = m_seriesDomainMap.value(series);
186 186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
187 187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
188 188 axis->d_ptr->m_orientation=Qt::Vertical;
189 189 m_seriesAxisYMap.insert(series,axis);
190 190 }
191 191
192 192 void ChartDataSet::removeSeries(QAbstractSeries* series)
193 193 {
194 194 Domain* domain = m_seriesDomainMap.take(series);
195 195
196 196 if(!domain) {
197 197 qWarning()<<"Can not remove series. Series not found on the chart.";
198 198 }
199 199
200 200 emit seriesRemoved(series);
201 201
202 202 delete domain;
203 203 domain = 0;
204 204
205 205 int key = seriesIndex(series);
206 206 Q_ASSERT(key!=-1);
207 207
208 208 m_indexSeriesMap.remove(key);
209 209
210 210 series->setParent(0);
211 211 series->d_ptr->m_chart = 0;
212 212 series->d_ptr->m_dataset = 0;
213 213
214 214 removeAxes(series);
215 215 }
216 216
217 217 void ChartDataSet::removeAxes(QAbstractSeries* series)
218 218 {
219 219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
220 220
221 221 if(axisX) {
222 222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
223 223 int x = axesX.indexOf(axisX);
224 224
225 225 if(x==-1) {
226 226 emit axisRemoved(axisX);
227 227 axisX->deleteLater();
228 228 }
229 229 }
230 230
231 231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
232 232
233 233 if(axisY) {
234 234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
235 235
236 236 int y = axesY.indexOf(axisY);
237 237
238 238 if(y==-1) {
239 239 emit axisRemoved(axisY);
240 240 axisY->deleteLater();
241 241 }
242 242 }
243 243 }
244 244
245 245 void ChartDataSet::removeAllSeries()
246 246 {
247 247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
248 248 foreach(QAbstractSeries *s , series) {
249 249 removeSeries(s);
250 250 }
251 251
252 252 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 253 Q_ASSERT(m_seriesAxisXMap.count()==0);
254 254 Q_ASSERT(m_seriesDomainMap.count()==0);
255 255
256 256 qDeleteAll(series);
257 257 }
258 258
259 259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
260 260 {
261 261 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
262 262
263 263 blockAxisSignals(true);
264 264
265 265 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
266 266
267 267 while (i.hasNext()) {
268 268 i.next();
269 269 i.value()->zoomIn(rect,size);
270 270 }
271 271
272 272 blockAxisSignals(false);
273 273
274 274 }
275 275
276 276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
277 277 {
278 278 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
279 279
280 280 blockAxisSignals(true);
281 281
282 282 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
283 283
284 284 while (i.hasNext()) {
285 285 i.next();
286 286 i.value()->zoomOut(rect,size);
287 287 }
288 288
289 289 blockAxisSignals(false);
290 290 }
291 291
292 292 void ChartDataSet::blockAxisSignals(bool enabled)
293 293 {
294 294 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
295 295
296 296 while (i.hasNext()) {
297 297 i.next();
298 298 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
299 299 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
300 300 if(axisX) axisX->blockSignals(enabled);
301 301 if(axisY) axisY->blockSignals(enabled);
302 302 }
303 303 }
304 304
305 305 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
306 306 {
307 307 int count=0;
308 308 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
309 309 while (i.hasNext()) {
310 310 i.next();
311 311 if(i.key()->type()==type) count++;
312 312 }
313 313 return count;
314 314 }
315 315
316 316 int ChartDataSet::seriesIndex(QAbstractSeries *series)
317 317 {
318 318 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
319 319 while (i.hasNext()) {
320 320 i.next();
321 321 if (i.value() == series)
322 322 return i.key();
323 323 }
324 324 return -1;
325 325 }
326 326
327 327 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
328 328 {
329 329 if(series == 0) return m_seriesAxisXMap.begin().value();
330 330 return m_seriesAxisXMap.value(series);
331 331 }
332 332
333 333 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
334 334 {
335 335 if(series == 0) return m_seriesAxisYMap.begin().value();
336 336 return m_seriesAxisYMap.value(series);
337 337 }
338 338
339 339 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
340 340 {
341 341 Q_ASSERT(axis);
342 342 Domain* domain = m_seriesDomainMap.value(series);
343 343
344 344 if(!domain) {
345 345 qWarning() << "Series not found on the chart.";
346 346 return;
347 347 }
348 348
349 349 if(axis->d_ptr->m_orientation==Qt::Vertical) {
350 350 qWarning()<<"Axis already defined as axis Y";
351 351 return;
352 352 }
353 353
354 354 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
355 355 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
356 356
357 357 if(oldAxis) {
358 358
359 359 int x = axesX.indexOf(oldAxis);
360 360 if(x==-1) {
361 361 emit axisRemoved(oldAxis);
362 362 oldAxis->deleteLater();
363 363 }
364 364 }
365 365
366 366 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
367 367 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
368 368
369 369 int x = axesX.indexOf(axis);
370 370 if(x==-1) {
371 371 axis->d_ptr->m_orientation=Qt::Horizontal;
372 372 emit axisAdded(axis,domain);
373 373 }
374 374
375 375 m_seriesAxisXMap.insert(series,axis);
376 376 axis->d_ptr->emitRange();
377 377 }
378 378
379 379 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
380 380 {
381 381 Q_ASSERT(axis);
382 382 Domain* domain = m_seriesDomainMap.value(series);
383 383
384 384 if(!domain) {
385 385 qWarning() << "Series not found on the chart.";
386 386 return;
387 387 }
388 388
389 389 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
390 390 qWarning()<<"Axis already defined as axis X";
391 391 return;
392 392 }
393 393
394 394 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
395 395 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
396 396
397 397 if(oldAxis) {
398 398 int y = axesY.indexOf(oldAxis);
399 399 if(y==-1) {
400 400 emit axisRemoved(oldAxis);
401 401 oldAxis->deleteLater();
402 402 }
403 403 }
404 404
405 405 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
406 406 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
407 407
408 408 int y = axesY.indexOf(axis);
409 409 if(y==-1) {
410 410 axis->d_ptr->m_orientation=Qt::Vertical;
411 411 emit axisAdded(axis,domain);
412 412 }
413 413
414 414 m_seriesAxisYMap.insert(series,axis);
415 415 axis->d_ptr->emitRange();
416 416 }
417 417
418 418 Domain* ChartDataSet::domain(QAbstractSeries *series) const
419 419 {
420 420 return m_seriesDomainMap.value(series);
421 421 }
422 422
423 423 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
424 424 {
425 425 blockAxisSignals(true);
426 426 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
427 427 while (i.hasNext()) {
428 428 i.next();
429 429 i.value()->move(dx,dy,size);
430 430 }
431 431 blockAxisSignals(false);
432 432 }
433 433
434 434 QList<QAbstractSeries*> ChartDataSet::series() const
435 435 {
436 436 return m_seriesAxisXMap.keys();
437 437 }
438 438
439 439 void ChartDataSet::updateSeries(QAbstractSeries *series)
440 440 {
441 441 emit seriesUpdated(series);
442 442 }
443 443
444 444 #include "moc_chartdataset_p.cpp"
445 445
446 446 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,357 +1,357
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "mainwidget.h"
22 22 #include "dataseriedialog.h"
23 23 #include "qchartview.h"
24 24 #include "qpieseries.h"
25 25 #include "qscatterseries.h"
26 26 #include "qlineseries.h"
27 27 #include <qareaseries.h>
28 28 #include <qsplineseries.h>
29 29 #include <qbarset.h>
30 30 #include <qbarseries.h>
31 31 #include <qstackedbarseries.h>
32 32 #include <qpercentbarseries.h>
33 33 #include <QPushButton>
34 34 #include <QComboBox>
35 35 #include <QSpinBox>
36 36 #include <QCheckBox>
37 37 #include <QGridLayout>
38 38 #include <QHBoxLayout>
39 39 #include <QLabel>
40 40 #include <QSpacerItem>
41 41 #include <QMessageBox>
42 42 #include <cmath>
43 43 #include <QDebug>
44 44 #include <QStandardItemModel>
45 45 #include <QCategoriesAxis>
46 46
47 47
48 48 QTCOMMERCIALCHART_USE_NAMESPACE
49 49
50 50 MainWidget::MainWidget(QWidget *parent) :
51 51 QWidget(parent),
52 52 m_addSerieDialog(0),
53 53 m_chart(0)
54 54 {
55 55 m_chart = new QChart();
56 56
57 57 // Grid layout for the controls for configuring the chart widget
58 58 QGridLayout *grid = new QGridLayout();
59 59 QPushButton *addSeriesButton = new QPushButton("Add series");
60 60 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
61 61 grid->addWidget(addSeriesButton, 0, 1);
62 62 initBackroundCombo(grid);
63 63 initScaleControls(grid);
64 64 initThemeCombo(grid);
65 65 initCheckboxes(grid);
66 66
67 67 // add row with empty label to make all the other rows static
68 68 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
69 69 grid->setRowStretch(grid->rowCount() - 1, 1);
70 70
71 71 // Create chart view with the chart
72 72 m_chartView = new QChartView(m_chart, this);
73 73 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
74 74
75 75 // Another grid layout as a main layout
76 76 QGridLayout *mainLayout = new QGridLayout();
77 77 mainLayout->addLayout(grid, 0, 0);
78 78 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
79 79 setLayout(mainLayout);
80 80 }
81 81
82 82 // Combo box for selecting the chart's background
83 83 void MainWidget::initBackroundCombo(QGridLayout *grid)
84 84 {
85 85 QComboBox *backgroundCombo = new QComboBox(this);
86 86 backgroundCombo->addItem("Color");
87 87 backgroundCombo->addItem("Gradient");
88 88 backgroundCombo->addItem("Image");
89 89 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
90 90 this, SLOT(backgroundChanged(int)));
91 91
92 92 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
93 93 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
94 94 }
95 95
96 96 // Scale related controls (auto-scale vs. manual min-max values)
97 97 void MainWidget::initScaleControls(QGridLayout *grid)
98 98 {
99 99 m_autoScaleCheck = new QCheckBox("Automatic scaling");
100 100 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
101 101 // Allow setting also non-sense values (like -2147483648 and 2147483647)
102 102 m_xMinSpin = new QSpinBox();
103 103 m_xMinSpin->setMinimum(INT_MIN);
104 104 m_xMinSpin->setMaximum(INT_MAX);
105 105 m_xMinSpin->setValue(0);
106 106 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
107 107 m_xMaxSpin = new QSpinBox();
108 108 m_xMaxSpin->setMinimum(INT_MIN);
109 109 m_xMaxSpin->setMaximum(INT_MAX);
110 110 m_xMaxSpin->setValue(10);
111 111 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
112 112 m_yMinSpin = new QSpinBox();
113 113 m_yMinSpin->setMinimum(INT_MIN);
114 114 m_yMinSpin->setMaximum(INT_MAX);
115 115 m_yMinSpin->setValue(0);
116 116 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
117 117 m_yMaxSpin = new QSpinBox();
118 118 m_yMaxSpin->setMinimum(INT_MIN);
119 119 m_yMaxSpin->setMaximum(INT_MAX);
120 120 m_yMaxSpin->setValue(10);
121 121 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
122 122
123 123 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
124 124 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
125 125 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
126 126 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
127 127 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
128 128 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
129 129 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
130 130 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
131 131 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
132 132
133 133 m_autoScaleCheck->setChecked(true);
134 134 }
135 135
136 136 // Combo box for selecting theme
137 137 void MainWidget::initThemeCombo(QGridLayout *grid)
138 138 {
139 139 QComboBox *chartTheme = new QComboBox();
140 140 chartTheme->addItem("Default");
141 141 chartTheme->addItem("Light");
142 142 chartTheme->addItem("Blue Cerulean");
143 143 chartTheme->addItem("Dark");
144 144 chartTheme->addItem("Brown Sand");
145 145 chartTheme->addItem("Blue NCS");
146 146 chartTheme->addItem("High Contrast");
147 147 chartTheme->addItem("Blue Icy");
148 148 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
149 149 this, SLOT(changeChartTheme(int)));
150 150 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
151 151 grid->addWidget(chartTheme, 8, 1);
152 152 }
153 153
154 154 // Different check boxes for customizing chart
155 155 void MainWidget::initCheckboxes(QGridLayout *grid)
156 156 {
157 157 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
158 158 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
159 159 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
160 160 zoomCheckBox->setChecked(true);
161 161 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
162 162
163 163 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
164 164 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
165 165 aliasCheckBox->setChecked(false);
166 166 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
167 167 }
168 168
169 169 void MainWidget::antiAliasToggled(bool enabled)
170 170 {
171 171 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
172 172 }
173 173
174 174 void MainWidget::addSeries()
175 175 {
176 176 if (!m_addSerieDialog) {
177 177 m_addSerieDialog = new DataSerieDialog(this);
178 178 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
179 179 this, SLOT(addSeries(QString,int,int,QString,bool)));
180 180 }
181 181 m_addSerieDialog->exec();
182 182 }
183 183
184 184 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
185 185 {
186 186 // TODO: dataCharacteristics
187 187 QList<RealList> testData;
188 188 for (int j(0); j < columnCount; j++) {
189 189 QList <qreal> newColumn;
190 190 for (int i(0); i < rowCount; i++) {
191 191 if (dataCharacteristics == "Sin") {
192 192 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
193 193 } else if (dataCharacteristics == "Sin + random") {
194 194 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
195 195 } else if (dataCharacteristics == "Random") {
196 196 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
197 197 } else if (dataCharacteristics == "Linear") {
198 198 //newColumn.append(i * (j + 1.0));
199 199 // TODO: temporary hack to make pie work; prevent zero values:
200 200 newColumn.append(i * (j + 1.0) + 0.1);
201 201 } else { // "constant"
202 202 newColumn.append((j + 1.0));
203 203 }
204 204 }
205 205 testData.append(newColumn);
206 206 }
207 207 return testData;
208 208 }
209 209
210 210 QStringList MainWidget::generateLabels(int count)
211 211 {
212 212 QStringList result;
213 213 for (int i(0); i < count; i++)
214 214 result.append("label" + QString::number(i));
215 215 return result;
216 216 }
217 217
218 218 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
219 219 {
220 220 qDebug() << "addSeries: " << seriesName
221 221 << " columnCount: " << columnCount
222 222 << " rowCount: " << rowCount
223 223 << " dataCharacteristics: " << dataCharacteristics
224 224 << " labels enabled: " << labelsEnabled;
225 225 m_defaultSeriesName = seriesName;
226 226
227 227 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
228 228
229 229 // Line series and scatter series use similar data
230 230 if (seriesName == "Line") {
231 231 for (int j(0); j < data.count(); j ++) {
232 232 QList<qreal> column = data.at(j);
233 233 QLineSeries *series = new QLineSeries();
234 234 series->setName("line" + QString::number(j));
235 235 for (int i(0); i < column.count(); i++)
236 236 series->append(i, column.at(i));
237 237 m_chart->addSeries(series);
238 238 }
239 239 } else if (seriesName == "Area") {
240 240 // TODO: lower series for the area?
241 241 for (int j(0); j < data.count(); j ++) {
242 242 QList<qreal> column = data.at(j);
243 243 QLineSeries *lineSeries = new QLineSeries();
244 244 for (int i(0); i < column.count(); i++)
245 245 lineSeries->append(i, column.at(i));
246 246 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
247 247 areaSeries->setName("area" + QString::number(j));
248 248 m_chart->addSeries(areaSeries);
249 249 }
250 250 } else if (seriesName == "Scatter") {
251 251 for (int j(0); j < data.count(); j++) {
252 252 QList<qreal> column = data.at(j);
253 253 QScatterSeries *series = new QScatterSeries();
254 254 series->setName("scatter" + QString::number(j));
255 255 for (int i(0); i < column.count(); i++)
256 256 series->append(i, column.at(i));
257 257 m_chart->addSeries(series);
258 258 }
259 259 } else if (seriesName == "Pie") {
260 260 QStringList labels = generateLabels(rowCount);
261 261 for (int j(0); j < data.count(); j++) {
262 262 QPieSeries *series = new QPieSeries();
263 263 QList<qreal> column = data.at(j);
264 264 for (int i(0); i < column.count(); i++)
265 265 series->append(labels.at(i), column.at(i));
266 266 m_chart->addSeries(series);
267 267 }
268 268 } else if (seriesName == "Bar"
269 269 || seriesName == "Stacked bar"
270 270 || seriesName == "Percent bar") {
271 271 QStringList category;
272 272 QStringList labels = generateLabels(rowCount);
273 273 foreach(QString label, labels)
274 274 category << label;
275 275 QAbstractBarSeries* series = 0;
276 276 if (seriesName == "Bar") {
277 277 series = new QBarSeries(this);
278 QCategoriesAxis* axis = new QCategoriesAxis();
278 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
279 279 axis->append(category);
280 280 m_chart->setAxisX(axis,series);
281 281 } else if (seriesName == "Stacked bar") {
282 282 series = new QStackedBarSeries(this);
283 QCategoriesAxis* axis = new QCategoriesAxis();
283 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
284 284 axis->append(category);
285 285 m_chart->setAxisX(axis,series);
286 286 } else {
287 287 series = new QPercentBarSeries(this);
288 QCategoriesAxis* axis = new QCategoriesAxis();
288 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
289 289 axis->append(category);
290 290 m_chart->setAxisX(axis,series);
291 291 }
292 292
293 293 for (int j(0); j < data.count(); j++) {
294 294 QList<qreal> column = data.at(j);
295 295 QBarSet *set = new QBarSet("set" + QString::number(j));
296 296 for (int i(0); i < column.count(); i++)
297 297 *set << column.at(i);
298 298 series->append(set);
299 299 }
300 300
301 301 m_chart->addSeries(series);
302 302 } else if (seriesName == "Spline") {
303 303 for (int j(0); j < data.count(); j ++) {
304 304 QList<qreal> column = data.at(j);
305 305 QSplineSeries *series = new QSplineSeries();
306 306 for (int i(0); i < column.count(); i++)
307 307 series->append(i, column.at(i));
308 308 m_chart->addSeries(series);
309 309 }
310 310 }
311 311 m_chart->createDefaultAxes();
312 312 }
313 313
314 314 void MainWidget::backgroundChanged(int itemIndex)
315 315 {
316 316 qDebug() << "backgroundChanged: " << itemIndex;
317 317 }
318 318
319 319 void MainWidget::autoScaleChanged(int value)
320 320 {
321 321 if (value) {
322 322 // TODO: enable auto scaling
323 323 } else {
324 324 // TODO: set scaling manually (and disable auto scaling)
325 325 }
326 326
327 327 m_xMinSpin->setEnabled(!value);
328 328 m_xMaxSpin->setEnabled(!value);
329 329 m_yMinSpin->setEnabled(!value);
330 330 m_yMaxSpin->setEnabled(!value);
331 331 }
332 332
333 333 void MainWidget::xMinChanged(int value)
334 334 {
335 335 qDebug() << "xMinChanged: " << value;
336 336 }
337 337
338 338 void MainWidget::xMaxChanged(int value)
339 339 {
340 340 qDebug() << "xMaxChanged: " << value;
341 341 }
342 342
343 343 void MainWidget::yMinChanged(int value)
344 344 {
345 345 qDebug() << "yMinChanged: " << value;
346 346 }
347 347
348 348 void MainWidget::yMaxChanged(int value)
349 349 {
350 350 qDebug() << "yMaxChanged: " << value;
351 351 }
352 352
353 353 void MainWidget::changeChartTheme(int themeIndex)
354 354 {
355 355 qDebug() << "changeChartTheme: " << themeIndex;
356 356 m_chart->setTheme((QChart::ChartTheme) themeIndex);
357 357 }
@@ -1,72 +1,72
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Grouped bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29
30 30 property variant series: mySeries
31 31
32 CategoriesAxis {
32 BarCategoriesAxis {
33 33 id:myAxis;
34 34 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] }
35 35
36 36 BarSeries {
37 37 id: mySeries
38 38 name: "bar"
39 39
40 40 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
41 41 onClicked: console.log("barset.onClicked: " + index);
42 42 onHovered: console.log("barset.onHovered: " + status);
43 43 onPenChanged: console.log("barset.onPenChanged: " + pen);
44 44 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
45 45 onLabelChanged: console.log("barset.onLabelChanged: " + label);
46 46 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
47 47 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
48 48 onColorChanged: console.log("barset.onColorChanged: " + color);
49 49 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
50 50 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
51 51 onCountChanged: console.log("barset.onCountChanged: " + count);
52 52 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
53 53 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
54 54 onValueChanged: console.log("barset.onValuesChanged: " + index);
55 55 }
56 56 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 57 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 58
59 59 onNameChanged: console.log("groupedBarSeries.onNameChanged: " + series.name);
60 60 onVisibleChanged: console.log("groupedBarSeries.onVisibleChanged: " + series.visible);
61 61 onClicked: console.log("groupedBarSeries.onClicked: " + barset + " " + index);
62 62 onHovered: console.log("groupedBarSeries.onHovered: " + barset + " " + status);
63 63 onLabelsVisibleChanged: console.log("groupedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 64 onCountChanged: console.log("groupedBarSeries.onCountChanged: " + count);
65 65 }
66 66
67 67 Component.onCompleted: {
68 68 createDefaultAxes();
69 69 setAxisX(myAxis,mySeries);
70 70 }
71 71
72 72 } No newline at end of file
@@ -1,71 +1,71
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Percent bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29
30 30 property variant series: mySeries
31 31
32 CategoriesAxis {
32 BarCategoriesAxis {
33 33 id: myAxis
34 34 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ]
35 35 }
36 36
37 37 PercentBarSeries {
38 38 id: mySeries
39 39 name: "bar"
40 40 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
41 41 onClicked: console.log("barset.onClicked: " + index);
42 42 onHovered: console.log("barset.onHovered: " + status);
43 43 onPenChanged: console.log("barset.onPenChanged: " + pen);
44 44 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
45 45 onLabelChanged: console.log("barset.onLabelChanged: " + label);
46 46 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
47 47 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
48 48 onColorChanged: console.log("barset.onColorChanged: " + color);
49 49 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
50 50 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
51 51 onCountChanged: console.log("barset.onCountChanged: " + count);
52 52 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
53 53 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
54 54 onValueChanged: console.log("barset.onValuesChanged: " + index);
55 55 }
56 56 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 57 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 58
59 59 onNameChanged: console.log("percentBarSeries.onNameChanged: " + series.name);
60 60 onVisibleChanged: console.log("percentBarSeries.onVisibleChanged: " + series.visible);
61 61 onClicked: console.log("percentBarSeries.onClicked: " + barset + " " + index);
62 62 onHovered: console.log("percentBarSeries.onHovered: " + barset + " " + status);
63 63 onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 64 onCountChanged: console.log("percentBarSeries.onCountChanged: " + count);
65 65 }
66 66
67 67 Component.onCompleted: {
68 68 createDefaultAxes();
69 69 setAxisX(myAxis,mySeries);
70 70 }
71 71 }
@@ -1,71 +1,71
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.0
23 23
24 24 ChartView {
25 25 title: "Stacked bar series"
26 26 anchors.fill: parent
27 27 theme: ChartView.ChartThemeLight
28 28 legend.alignment: Qt.AlignBottom
29 29
30 30 property variant series: mySeries
31 31
32 CategoriesAxis {
32 BarCategoriesAxis {
33 33 id: myAxis
34 34 categories: ["2007", "2008", "2009", "2010", "2011", "2012" ]
35 35 }
36 36
37 37 StackedBarSeries {
38 38 id: mySeries
39 39 name: "bar"
40 40 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6]
41 41 onClicked: console.log("barset.onClicked: " + index);
42 42 onHovered: console.log("barset.onHovered: " + status);
43 43 onPenChanged: console.log("barset.onPenChanged: " + pen);
44 44 onBrushChanged: console.log("barset.onBrushChanged: " + brush);
45 45 onLabelChanged: console.log("barset.onLabelChanged: " + label);
46 46 onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush);
47 47 onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont);
48 48 onColorChanged: console.log("barset.onColorChanged: " + color);
49 49 onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color);
50 50 onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color);
51 51 onCountChanged: console.log("barset.onCountChanged: " + count);
52 52 onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count);
53 53 onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count);
54 54 onValueChanged: console.log("barset.onValuesChanged: " + index);
55 55 }
56 56 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
57 57 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
58 58
59 59 onNameChanged: console.log("stackedBarSeries.onNameChanged: " + series.name);
60 60 onVisibleChanged: console.log("stackedBarSeries.onVisibleChanged: " + series.visible);
61 61 onClicked: console.log("stackedBarSeries.onClicked: " + barset + " " + index);
62 62 onHovered: console.log("stackedBarSeries.onHovered: " + barset + " " + status);
63 63 onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible);
64 64 onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count);
65 65 }
66 66
67 67 Component.onCompleted: {
68 68 createDefaultAxes();
69 69 setAxisX(myAxis,mySeries);
70 70 }
71 71 }
General Comments 0
You need to be logged in to leave comments. Login now