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