##// END OF EJS Templates
Added declarative model for bar series
Tero Ahola -
r1162:e5feb9c12a84
parent child
Show More
@@ -1,111 +1,138
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 property int __explodedIndex: -1
26
27
27 ChartView {
28 ChartView {
28 id: chart
29 id: chart
29 title: "Top-5 car brand shares in Finland"
30 title: "Top-5 car brand shares in Finland"
30 anchors.top: parent.top
31 anchors.top: parent.top
31 anchors.bottom: button.top
32 anchors.bottom: button.top
32 anchors.left: parent.left
33 anchors.left: parent.left
33 anchors.right: parent.right
34 anchors.right: parent.right
34 theme: ChartView.ChartThemeLight
35 theme: ChartView.ChartThemeLight
35 legend: ChartView.LegendBottom
36 legend: ChartView.LegendBottom
36 animationOptions: ChartView.SeriesAnimations
37 animationOptions: ChartView.SeriesAnimations
37
38
38 PieSeries {
39 PieSeries {
40 id: pieSeries
39 model: PieModel {
41 model: PieModel {
40 id: pieModel
42 id: pieModel
41 PieSlice { label: "Volkswagen"; value: 13.5 }
43 // TODO: initializing properties does not work at the moment, see DeclarativePieModel::append
44 // TODO: explode range, color, border color, border thickness, font, ..
45 PieSlice { exploded: true; label: "Volkswagen"; value: 13.5 }
42 PieSlice { label: "Toyota"; value: 10.9 }
46 PieSlice { label: "Toyota"; value: 10.9 }
43 PieSlice { label: "Ford"; value: 8.6 }
47 PieSlice { label: "Ford"; value: 8.6 }
44 PieSlice { label: "Skoda"; value: 8.2 }
48 PieSlice { label: "Skoda"; value: 8.2 }
45 PieSlice { label: "Volvo"; value: 6.8 }
49 PieSlice { label: "Volvo"; value: 6.8 }
46 }
50 }
47 }
51 }
48 }
52 }
49
53
54 Timer {
55 repeat: true
56 interval: 2000
57 running: true
58 onTriggered: {
59 changeSliceExploded(__explodedIndex);
60 __explodedIndex = (__explodedIndex + 1) % pieModel.count;
61 changeSliceExploded(__explodedIndex);
62 }
63 }
64
65 function changeSliceExploded(index) {
66 if (index >= 0 && index < pieModel.count) {
67 pieSeries.slice(index).exploded = !pieSeries.slice(index).exploded;
68 }
69 }
70
50 Rectangle {
71 Rectangle {
51 id: button
72 id: button
52 anchors.bottom: parent.bottom
73 anchors.bottom: parent.bottom
53 anchors.bottomMargin: 10
74 anchors.bottomMargin: 10
54 anchors.horizontalCenter: parent.horizontalCenter
75 anchors.horizontalCenter: parent.horizontalCenter
55 height: 40
76 height: 40
56 width: 100
77 width: 100
57 color: "orange"
78 color: "orange"
58 radius: 5
79 radius: 5
59 Text {
80 Text {
60 id: buttonText
81 id: buttonText
61 anchors.centerIn: parent
82 anchors.centerIn: parent
62 text: button.state == "" ? "Show others" : "Hide others"
83 text: button.state == "" ? "Show others" : "Hide others"
63 }
84 }
64 MouseArea {
85 MouseArea {
65 anchors.fill: parent
86 anchors.fill: parent
66 onClicked: {
87 onClicked: {
67 if (button.state == "") {
88 if (button.state == "") {
68 // The share of "others" was enabled -> append the data into the model
89 // The share of "others" was enabled -> append the data into the model
69 // TODO: this should also be doable by redefining the range inside the model
90 // TODO: this should also be doable by redefining the range inside the model
70 button.state = "show";
91 button.state = "show";
71 pieModel.append(["Others", 52.0]);
92 pieModel.append(["Others", 52.0]);
72 } else {
93 } else {
73 // The share of "others" was disabled -> remove the data from the model
94 // The share of "others" was disabled -> remove the data from the model
74 // TODO: this should also be doable by redefining the range inside the model
95 // TODO: this should also be doable by redefining the range inside the model
75 button.state = "";
96 button.state = "";
76 pieModel.removeRow(pieModel.count - 1);
97 pieModel.removeRow(pieModel.count - 1);
98 // TODO: removeAll("label") ?
77 }
99 }
78 }
100 }
79 }
101 }
80 }
102 }
81
103
82
104
83 // TODO: Optional syntax for defining models for different series. Is this really needed?
105 // TODO: Optional syntax for defining models for different series. Is this really needed?
84 // ChartModel {
106 // ChartModel {
85 // id: chartModel
107 // id: chartModel
86 // ChartElement { column1: "Volkswagen"; column2: 13.5; column3: 1.2 }
108 // ChartElement { column1: "Volkswagen"; column2: 13.5; column3: 1.2 }
87 // ChartElement { column1: "Toyota"; column2: 10.9; column3: 2.5 }
109 // ChartElement { column1: "Toyota"; column2: 10.9; column3: 2.5 }
88 // }
110 // }
89 // // column3 not used by pie series
111 // // column3 not used by pie series
90 // PieSeries {
112 // PieSeries {
91 // model: chartModel
113 // model: chartModel
92 // mappings: [ {"column1":"label"}, {"column2":"value"} ]
114 // modelMapping: PieMapping {
115 // labels: 0 // undefined by default
116 // values: 1 // undefined by default
117 // first: 0 // 0 by default
118 // count: 10 // "Undefined" by default
119 // orientation: PieMapping.Vertical // Vertical by default
120 // }
93 // }
121 // }
94
122
95
96 // TODO: show how to use data from a list model in a chart view
123 // TODO: show how to use data from a list model in a chart view
97 // i.e. copy the data into a chart model
124 // i.e. copy the data into a chart model
98 // ListModel {
125 // ListModel {
99 // id: listModel
126 // id: listModel
100 // ListElement {
127 // ListElement {
101 // label: "Volkswagen"
128 // label: "Volkswagen"
102 // value: 13.5
129 // value: 13.5
103 // }
130 // }
104 // ListElement {
131 // ListElement {
105 // label: "Toyota"
132 // label: "Toyota"
106 // value: 10.9
133 // value: 10.9
107 // }
134 // }
108 // // and so on...
135 // // and so on...
109 // }
136 // }
110
137
111 }
138 }
@@ -1,115 +1,128
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 ChartView {
27 ChartView {
28 title: "NHL All-Star Team Players"
28 title: "NHL All-Star Team Players"
29 anchors.fill: parent
29 anchors.fill: parent
30 theme: ChartView.ChartThemeHighContrast
30 theme: ChartView.ChartThemeHighContrast
31 legend: ChartView.LegendTop
31 legend: ChartView.LegendTop
32 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
32 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
34
34
35 AreaSeries {
35 AreaSeries {
36 name: "Russian"
36 name: "Russian"
37 upperModel: russianModel
37 upperModel: russianModel
38 lowerModel: zerosModel
38 lowerModel: zerosModel
39 }
39 }
40 AreaSeries {
40 AreaSeries {
41 name: "Swedish"
41 name: "Swedish"
42 upperModel: swedishModel
42 upperModel: swedishModel
43 lowerModel: zerosModel
43 lowerModel: zerosModel
44 }
44 }
45 AreaSeries {
45 AreaSeries {
46 name: "Finnish"
46 name: "Finnish"
47 upperModel: finnishModel
47 upperModel: finnishModel
48 lowerModel: zerosModel
48 lowerModel: zerosModel
49 }
49 }
50 }
50 }
51
51
52 // TODO: optional implementation with generic ChartModel
53 // AreaSeries {
54 // model: chartModel
55 // modelMapping: XyMapping {
56 // xValues: 0 // undefined by default
57 // yValues: 1 // undefined by default
58 // first: 0 // 0 by default
59 // count: 10 // "Undefined" by default
60 // orientation: XyMapping.Vertical // Vertical by default
61 // }
62 // }
63
64
52 XYModel {
65 XYModel {
53 id: zerosModel
66 id: zerosModel
54 XyPoint { x: 0; y: 0 }
67 XyPoint { x: 0; y: 0 }
55 XyPoint { x: 1; y: 0 }
68 XyPoint { x: 1; y: 0 }
56 XyPoint { x: 2; y: 0 }
69 XyPoint { x: 2; y: 0 }
57 XyPoint { x: 3; y: 0 }
70 XyPoint { x: 3; y: 0 }
58 XyPoint { x: 4; y: 0 }
71 XyPoint { x: 4; y: 0 }
59 XyPoint { x: 5; y: 0 }
72 XyPoint { x: 5; y: 0 }
60 XyPoint { x: 6; y: 0 }
73 XyPoint { x: 6; y: 0 }
61 XyPoint { x: 7; y: 0 }
74 XyPoint { x: 7; y: 0 }
62 XyPoint { x: 8; y: 0 }
75 XyPoint { x: 8; y: 0 }
63 XyPoint { x: 9; y: 0 }
76 XyPoint { x: 9; y: 0 }
64 XyPoint { x: 10; y: 0 }
77 XyPoint { x: 10; y: 0 }
65 XyPoint { x: 11; y: 0 }
78 XyPoint { x: 11; y: 0 }
66 }
79 }
67
80
68 XYModel {
81 XYModel {
69 id: russianModel
82 id: russianModel
70 XyPoint { x: 0; y: 1 }
83 XyPoint { x: 0; y: 1 }
71 XyPoint { x: 1; y: 1 }
84 XyPoint { x: 1; y: 1 }
72 XyPoint { x: 2; y: 1 }
85 XyPoint { x: 2; y: 1 }
73 XyPoint { x: 3; y: 1 }
86 XyPoint { x: 3; y: 1 }
74 XyPoint { x: 4; y: 1 }
87 XyPoint { x: 4; y: 1 }
75 XyPoint { x: 5; y: 0 }
88 XyPoint { x: 5; y: 0 }
76 XyPoint { x: 6; y: 1 }
89 XyPoint { x: 6; y: 1 }
77 XyPoint { x: 7; y: 1 }
90 XyPoint { x: 7; y: 1 }
78 XyPoint { x: 8; y: 4 }
91 XyPoint { x: 8; y: 4 }
79 XyPoint { x: 9; y: 3 }
92 XyPoint { x: 9; y: 3 }
80 XyPoint { x: 10; y: 2 }
93 XyPoint { x: 10; y: 2 }
81 XyPoint { x: 11; y: 1 }
94 XyPoint { x: 11; y: 1 }
82 }
95 }
83
96
84 XYModel {
97 XYModel {
85 id: swedishModel
98 id: swedishModel
86 XyPoint { x: 0; y: 1 }
99 XyPoint { x: 0; y: 1 }
87 XyPoint { x: 1; y: 1 }
100 XyPoint { x: 1; y: 1 }
88 XyPoint { x: 2; y: 3 }
101 XyPoint { x: 2; y: 3 }
89 XyPoint { x: 3; y: 3 }
102 XyPoint { x: 3; y: 3 }
90 XyPoint { x: 4; y: 2 }
103 XyPoint { x: 4; y: 2 }
91 XyPoint { x: 5; y: 0 }
104 XyPoint { x: 5; y: 0 }
92 XyPoint { x: 6; y: 2 }
105 XyPoint { x: 6; y: 2 }
93 XyPoint { x: 7; y: 1 }
106 XyPoint { x: 7; y: 1 }
94 XyPoint { x: 8; y: 2 }
107 XyPoint { x: 8; y: 2 }
95 XyPoint { x: 9; y: 1 }
108 XyPoint { x: 9; y: 1 }
96 XyPoint { x: 10; y: 3 }
109 XyPoint { x: 10; y: 3 }
97 XyPoint { x: 11; y: 3 }
110 XyPoint { x: 11; y: 3 }
98 }
111 }
99
112
100 XYModel {
113 XYModel {
101 id: finnishModel
114 id: finnishModel
102 XyPoint { x: 0; y: 0 }
115 XyPoint { x: 0; y: 0 }
103 XyPoint { x: 1; y: 0 }
116 XyPoint { x: 1; y: 0 }
104 XyPoint { x: 2; y: 0 }
117 XyPoint { x: 2; y: 0 }
105 XyPoint { x: 3; y: 0 }
118 XyPoint { x: 3; y: 0 }
106 XyPoint { x: 4; y: 0 }
119 XyPoint { x: 4; y: 0 }
107 XyPoint { x: 5; y: 0 }
120 XyPoint { x: 5; y: 0 }
108 XyPoint { x: 6; y: 1 }
121 XyPoint { x: 6; y: 1 }
109 XyPoint { x: 7; y: 0 }
122 XyPoint { x: 7; y: 0 }
110 XyPoint { x: 8; y: 0 }
123 XyPoint { x: 8; y: 0 }
111 XyPoint { x: 9; y: 0 }
124 XyPoint { x: 9; y: 0 }
112 XyPoint { x: 10; y: 0 }
125 XyPoint { x: 10; y: 0 }
113 XyPoint { x: 11; y: 1 }
126 XyPoint { x: 11; y: 1 }
114 }
127 }
115 }
128 }
@@ -1,38 +1,78
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 ChartView {
27 ChartView {
28 title: "Bar series"
28 title: "Bar series"
29 anchors.fill: parent
29 anchors.fill: parent
30 theme: ChartView.ChartThemeLight
30 theme: ChartView.ChartThemeLight
31 legend: ChartView.LegendBottom
31 legend: ChartView.LegendBottom
32 // axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"]
33 axisX.max: 10
32
34
33 BarSeries {
35 BarSeries {
34 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
36 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
35 // data implementation missing
37 model: barModel
36 }
38 }
39
40
41 // // TODO: optional syntax with ChartModel base model API
42 // BarSeries {
43 // model: chartModel
44 // modelMapping: BarSeriesMapping {
45 // // Giving "undefined" x mapping value means that the indexes are used as x-values
46 // setIndexes: [BarSeriesMapping.Undefined, 0,
47 // BarSeriesMapping.Undefined, 1,
48 // BarSeriesMapping.Undefined, 2] // defaults to []
49 //// setValues: [
50 //// BarSetMapping {x: BarSetMapping.Undefined; y: 0},
51 //// BarSetMapping {x: BarSetMapping.Undefined; y: 1},
52 //// BarSetMapping {x: BarSetMapping.Undefined; y: 2}
53 //// ]
54 // orientation: BarSeriesMapping.Vertical // defaults to Vertical
55 // startIndex: 0 // defaults to 0
56 // count: BarSeriesMapping.Undefined // defaults to "Undefined"
57 // }
58 // }
59 }
60
61 // ChartModel {
62 // id: chartModel
63 // }
64
65 BarModel {
66 id: barModel
67 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
68 BarSet { name: "Bub"; values: [5, 1, 2, 4, 1, 7] }
69 BarSet { name: "Bib"; values: [3, 5, 8, 13, 5, 8] }
37 }
70 }
71
72 // TODO
73 // Component.onCompleted: {
74 // bobBars.append(1.2);
75 // bobBars.append(1.5);
76 // bobBars.append([1.5, 1.4, 1.9]);
77 // }
38 }
78 }
@@ -1,81 +1,97
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 "declarativebarseries.h"
21 #include "declarativebarseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include <QBarSet>
24 #include "qbarseries.h"
25 #include "qbarset.h"
26
24
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
26
29 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
27 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
30 QDeclarativeItem(parent)
28 QBarSet("", parent)
31 {
29 {
32 setFlag(QGraphicsItem::ItemHasNoContents, false);
33 }
30 }
34
31
35 void DeclarativeBarSeries::componentComplete()
32 QVariantList DeclarativeBarSet::values()
36 {
33 {
34 QVariantList values;
35 for (int i(0); i < count(); i++)
36 values.append(QVariant(at(i)));
37 return values;
37 }
38 }
38
39
39 void DeclarativeBarSeries::setBarCategories(QStringList categories)
40 void DeclarativeBarSet::setValues(QVariantList values)
40 {
41 {
41 m_categories = categories;
42 while (count())
43 remove(count() - 1);
42
44
43 if (m_series) {
45 for (int i(0); i < values.count(); i++) {
44 delete m_series;
46 if (values.at(i).canConvert(QVariant::Double))
45 m_series = 0;
47 append(values[i].toDouble());
46 }
48 }
49 }
47
50
48 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
51 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
49 if (declarativeChart) {
52 QBarSeries(parent)
50 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
53 {
51 Q_ASSERT(chart);
54 }
52
55
53 // m_series = new QBarSeries(m_categories);
56 void DeclarativeBarSeries::classBegin()
54 m_series = new QBarSeries();
57 {
55 m_series->setCategories(m_categories);
58 }
56
59
57 // TODO: use data from model
60 void DeclarativeBarSeries::componentComplete()
58 QBarSet *set0 = new QBarSet("Bub");
61 {
59 QBarSet *set1 = new QBarSet("Bob");
62 if (model())
60 QBarSet *set2 = new QBarSet("Guybrush");
63 setModelMapping(0, 1, 1, Qt::Vertical);
64 }
61
65
62 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
66 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeBarModel *model)
63 *set1 << 5 << 1 << 2 << 4 << 1 << 7;
67 {
64 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
68 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
69 bool value(false);
70 if (m) {
71 value = setModel(m);
72 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
73 setModelMapping(0, 1, 1, Qt::Vertical);
74 } else {
75 qWarning("DeclarativeBarSeries: Illegal model");
76 }
77 return value;
78 }
65
79
66 m_series->appendBarSet(set0);
80 DeclarativeBarModel *DeclarativeBarSeries::declarativeModel()
67 m_series->appendBarSet(set1);
81 {
68 m_series->appendBarSet(set2);
82 return qobject_cast<DeclarativeBarModel *>(model());
83 }
69
84
70 chart->addSeries(m_series);
85 void DeclarativeBarSeries::setBarCategories(QStringList categories)
71 }
86 {
87 setCategories(categories);
72 }
88 }
73
89
74 QStringList DeclarativeBarSeries::barCategories()
90 QStringList DeclarativeBarSeries::barCategories()
75 {
91 {
76 return m_categories;
92 return categories();
77 }
93 }
78
94
79 #include "moc_declarativebarseries.cpp"
95 #include "moc_declarativebarseries.cpp"
80
96
81 QTCOMMERCIALCHART_END_NAMESPACE
97 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,59 +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 DECLARATIVEBARSERIES_H
21 #ifndef DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativemodel.h"
25 #include <QDeclarativeItem>
26 #include <QDeclarativeItem>
27 #include <QDeclarativeParserStatus>
28 #include <QBarSeries>
26
29
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
31
29 class QChart;
32 class QChart;
30 class QBarSeries;
33 class QBarSeries;
31
34
32 class DeclarativeBarSeries : public QDeclarativeItem
35 class DeclarativeBarSet : public QBarSet
33 {
36 {
34 Q_OBJECT
37 Q_OBJECT
38 Q_PROPERTY(QVariantList values READ values WRITE setValues)
39 Q_PROPERTY(QString name READ name WRITE setName)
40
41 public:
42 explicit DeclarativeBarSet(QObject *parent = 0);
43 QVariantList values();
44 void setValues(QVariantList values);
45 };
46
47 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
48 {
49 Q_OBJECT
50 Q_INTERFACES(QDeclarativeParserStatus)
51 Q_PROPERTY(DeclarativeBarModel *model READ declarativeModel WRITE setDeclarativeModel)
35 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
52 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
36
53
37 public:
54 public:
38 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
55 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
39
56
40 public: // from QDeclarativeParserStatus
57 public: // from QDeclarativeParserStatus
58 void classBegin();
41 void componentComplete();
59 void componentComplete();
42
60
43 public:
61 public:
62 bool setDeclarativeModel(DeclarativeBarModel *model);
63 DeclarativeBarModel *declarativeModel();
44 void setBarCategories(QStringList categories);
64 void setBarCategories(QStringList categories);
45 QStringList barCategories();
65 QStringList barCategories();
46
66
47 Q_SIGNALS:
67 Q_SIGNALS:
48
68
49 public Q_SLOTS:
69 public Q_SLOTS:
50
70
51 public:
71 public:
52 QChart *m_chart;
53 QBarSeries *m_series;
54 QStringList m_categories;
55 };
72 };
56
73
57 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
58
75
59 #endif // DECLARATIVEBARSERIES_H
76 #endif // DECLARATIVEBARSERIES_H
@@ -1,138 +1,177
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 "declarativemodel.h"
21 #include "declarativemodel.h"
22 #include <qdeclarativelist.h>
22 #include <qdeclarativelist.h>
23 #include <QDebug>
23 #include <QDebug>
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 ////////////// Table model (base) ///////////////////
28
29 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
30 ChartTableModel(parent)
31 {
32 }
33
34 void DeclarativeTableModel::classBegin()
35 {
36 }
37
38 void DeclarativeTableModel::componentComplete()
39 {
40 foreach (QObject *child, children())
41 appendToModel(child);
42 }
43
44 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
45 {
46 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
47 }
48
49 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
50 QObject *child)
51 {
52 // childs are added in componentComplete instead
53 Q_UNUSED(list)
54 Q_UNUSED(child)
55 }
56
57 void DeclarativeTableModel::appendToModel(QObject *object)
58 {
59 if (qobject_cast<DeclarativeBarModel *>(this)) {
60 DeclarativeBarModel *model = qobject_cast<DeclarativeBarModel *>(this);
61 model->append(qobject_cast<QBarSet *>(object));
62 } else if (qobject_cast<DeclarativePieModel *>(this)) {
63 DeclarativePieModel *model = qobject_cast<DeclarativePieModel *>(this);
64 model->append(qobject_cast<QPieSlice *>(object));
65 } else if (qobject_cast<DeclarativeXyModel *>(this)) {
66 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(this);
67 model->append(qobject_cast<DeclarativeXyPoint *>(object));
68 }
69 }
70
27 ////////////// XY model ///////////////////////
71 ////////////// XY model ///////////////////////
28
72
29 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
73 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
30 ChartTableModel(parent)
74 DeclarativeTableModel(parent)
31 {
75 {
32 }
76 }
33
77
34 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
78 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
35 {
79 {
36 // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y();
80 // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y();
37 insertRow(rowCount());
81 insertRow(rowCount());
38 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
82 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
39 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
83 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
40 setData(xModelIndex, point->x());
84 setData(xModelIndex, point->x());
41 setData(yModelIndex, point->y());
85 setData(yModelIndex, point->y());
42 dataChanged(xModelIndex, yModelIndex);
86 dataChanged(xModelIndex, yModelIndex);
43 }
87 }
44
88
45 void DeclarativeXyModel::append(QVariantList points)
89 void DeclarativeXyModel::append(QVariantList points)
46 {
90 {
47 qreal x = 0.0;
91 qreal x = 0.0;
48 for (int i(0); i < points.count(); i++) {
92 for (int i(0); i < points.count(); i++) {
49 if (i % 2) {
93 if (i % 2) {
50 bool ok(false);
94 bool ok(false);
51 qreal y = points.at(i).toReal(&ok);
95 qreal y = points.at(i).toReal(&ok);
52 if (ok) {
96 if (ok) {
53 DeclarativeXyPoint *point= new DeclarativeXyPoint();
97 DeclarativeXyPoint *point= new DeclarativeXyPoint();
54 point->setX(x);
98 point->setX(x);
55 point->setY(y);
99 point->setY(y);
56 append(point);
100 append(point);
57 } else {
101 } else {
58 qWarning() << "Illegal y value";
102 qWarning() << "Illegal y value";
59 }
103 }
60 } else {
104 } else {
61 bool ok(false);
105 bool ok(false);
62 x = points.at(i).toReal(&ok);
106 x = points.at(i).toReal(&ok);
63 if (!ok) {
107 if (!ok) {
64 qWarning() << "Illegal x value";
108 qWarning() << "Illegal x value";
65 }
109 }
66 }
110 }
67 }
111 }
68 }
112 }
69
113
70 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXyModel::points()
71 {
72 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXyModel::appendPoint);
73 }
74
75 void DeclarativeXyModel::appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
76 DeclarativeXyPoint *point)
77 {
78 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(list->object);
79 if (model)
80 model->append(point);
81 else
82 qWarning() << "Illegal point item";
83 }
84
85 ////////////// Pie model ///////////////////////
114 ////////////// Pie model ///////////////////////
86
115
87 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
116 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
88 ChartTableModel(parent)
117 DeclarativeTableModel(parent)
89 {
118 {
90 }
119 }
91
120
92 void DeclarativePieModel::append(QPieSlice* slice)
121 void DeclarativePieModel::append(QPieSlice* slice)
93 {
122 {
94 // qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
123 // qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
95 insertRow(rowCount());
124 insertRow(rowCount());
96
125
97 setData(createIndex(rowCount() - 1, 0), slice->value());
126 setData(createIndex(rowCount() - 1, 0), slice->value());
98 setData(createIndex(rowCount() - 1, 1), slice->label());
127 setData(createIndex(rowCount() - 1, 1), slice->label());
99 }
128 }
100
129
101 void DeclarativePieModel::append(QVariantList slices)
130 void DeclarativePieModel::append(QVariantList slices)
102 {
131 {
103 // qDebug() << "append:" << slices;
132 // qDebug() << "append:" << slices;
104 QString label = "";
133 QString label = "";
105 for (int i(0); i < slices.count(); i++) {
134 for (int i(0); i < slices.count(); i++) {
106 if (i % 2) {
135 if (i % 2) {
107 bool ok(false);
136 bool ok(false);
108 qreal value = slices.at(i).toReal(&ok);
137 qreal value = slices.at(i).toReal(&ok);
109 if (ok) {
138 if (ok) {
110 QPieSlice *slice = new QPieSlice(value, label);
139 QPieSlice *slice = new QPieSlice(value, label);
111 append(slice);
140 append(slice);
141 // TODO: how to copy the properties to the newly added slice?
142 // (DeclarativePieModel::append only copies the label and value to the model)
143 // QPieSlice *addedSlice = append(slice);
144 // addedSlice->setExploded(slice->isExploded());
112 } else {
145 } else {
113 qWarning() << "Illegal slice item";
146 qWarning() << "Illegal slice item";
114 }
147 }
115 } else {
148 } else {
116 label = slices.at(i).toString();
149 label = slices.at(i).toString();
117 }
150 }
118 }
151 }
119 }
152 }
120
153
121 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
154 ////////////// Bar model ///////////////////////
155
156 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
157 DeclarativeTableModel(parent)
122 {
158 {
123 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
124 }
159 }
125
160
126 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
161 void DeclarativeBarModel::append(QBarSet* barSet)
127 QPieSlice *slice)
128 {
162 {
129 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
163 insertColumn(columnCount());
130 if (pieModel)
164 for (int i(0); i < barSet->count(); i++) {
131 pieModel->append(slice);
165 if (rowCount() < (i + 1))
132 else
166 insertRow(rowCount());
133 qWarning() << "Illegal slice item";
167 setData(createIndex(i, columnCount() - 1), barSet->at(i));
168 // insertRow(rowCount());
169 // setData(createIndex(rowCount() - 1, 0), );
170 // setData(createIndex(rowCount() - 1, 1), barSet->at(i));
171 }
172 // TODO: setModelMapping(0, 1, columnCount(), Qt::Vertical);
134 }
173 }
135
174
136 #include "moc_declarativemodel.cpp"
175 #include "moc_declarativemodel.cpp"
137
176
138 QTCOMMERCIALCHART_END_NAMESPACE
177 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,94
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 DECLARATIVEMODEL_H
21 #ifndef DECLARATIVEMODEL_H
22 #define DECLARATIVEMODEL_H
22 #define DECLARATIVEMODEL_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
26 #include "qpieslice.h"
26 #include <QPieSlice>
27 #include "../src/charttablemodel.h" // TODO
27 #include "../src/charttablemodel.h" // TODO
28 #include <QBarSet>
28 #include <QDeclarativeListProperty>
29 #include <QDeclarativeListProperty>
29 #include <QVariant>
30 #include <QVariant>
31 #include <QDeclarativeParserStatus>
30
32
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
34
33 class DeclarativeXyModel : public ChartTableModel
35 class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus
36 {
37 Q_OBJECT
38 Q_INTERFACES(QDeclarativeParserStatus)
39 Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren)
40 Q_CLASSINFO("DefaultProperty", "modelChildren")
41
42 public:
43 explicit DeclarativeTableModel(QObject *parent = 0);
44 QDeclarativeListProperty<QObject> modelChildren();
45
46 public: // from QDeclarativeParserStatus
47 void classBegin();
48 void componentComplete();
49
50 public Q_SLOTS:
51 static void appendModelChild(QDeclarativeListProperty<QObject> *list,
52 QObject *element);
53 private:
54 void appendToModel(QObject *object);
55 };
56
57 class DeclarativeXyModel : public DeclarativeTableModel
34 {
58 {
35 Q_OBJECT
59 Q_OBJECT
36 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
37 Q_CLASSINFO("DefaultProperty", "points")
38
60
39 public:
61 public:
40 explicit DeclarativeXyModel(QObject *parent = 0);
62 explicit DeclarativeXyModel(QObject *parent = 0);
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42
63
43 public Q_SLOTS:
64 public Q_SLOTS:
44 void append(DeclarativeXyPoint* point);
65 void append(DeclarativeXyPoint* point);
45 void append(QVariantList points);
66 void append(QVariantList points);
46 static void appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
47 DeclarativeXyPoint *element);
48 };
67 };
49
68
50
69 class DeclarativePieModel : public DeclarativeTableModel
51 class DeclarativePieModel : public ChartTableModel
52 {
70 {
53 Q_OBJECT
71 Q_OBJECT
54 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
55 Q_CLASSINFO("DefaultProperty", "slices")
56
72
57 public:
73 public:
58 explicit DeclarativePieModel(QObject *parent = 0);
74 explicit DeclarativePieModel(QObject *parent = 0);
59 QDeclarativeListProperty<QPieSlice> slices();
60
75
61 public Q_SLOTS:
76 public Q_SLOTS:
62 void append(QPieSlice* slice);
77 void append(QPieSlice* slice);
63 void append(QVariantList slices);
78 void append(QVariantList slices);
64 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
79 };
65 QPieSlice *element);
80
81 class DeclarativeBarModel : public DeclarativeTableModel
82 {
83 Q_OBJECT
84
85 public:
86 explicit DeclarativeBarModel(QObject *parent = 0);
87
88 public Q_SLOTS:
89 void append(QBarSet* barSet);
66 };
90 };
67
91
68 QTCOMMERCIALCHART_END_NAMESPACE
92 QTCOMMERCIALCHART_END_NAMESPACE
69
93
70 #endif // DECLARATIVEMODEL_H
94 #endif // DECLARATIVEMODEL_H
@@ -1,53 +1,62
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 "declarativepieseries.h"
21 #include "declarativepieseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include <qdeclarativelist.h>
24 #include <qdeclarativelist.h>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
28 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
29 QPieSeries(parent)
29 QPieSeries(parent)
30 {
30 {
31 }
31 }
32
32
33 QPieSlice *DeclarativePieSeries::slice(int index)
34 {
35 QList<QPieSlice*> sliceList = slices();
36 if (index < sliceList.count())
37 return sliceList[index];
38
39 return 0;
40 }
41
33 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
42 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
34 {
43 {
35 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
44 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
36 bool value(false);
45 bool value(false);
37 if (m) {
46 if (m) {
38 value = QPieSeries::setModel(m);
47 value = QPieSeries::setModel(m);
39 setModelMapping(0, 1, Qt::Vertical);
48 setModelMapping(0, 1, Qt::Vertical);
40 } else {
49 } else {
41 qWarning("DeclarativePieSeries: Illegal model");
50 qWarning("DeclarativePieSeries: Illegal model");
42 }
51 }
43 return value;
52 return value;
44 }
53 }
45
54
46 DeclarativePieModel *DeclarativePieSeries::pieModel()
55 DeclarativePieModel *DeclarativePieSeries::pieModel()
47 {
56 {
48 return qobject_cast<DeclarativePieModel *>(model());
57 return qobject_cast<DeclarativePieModel *>(model());
49 }
58 }
50
59
51 #include "moc_declarativepieseries.cpp"
60 #include "moc_declarativepieseries.cpp"
52
61
53 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,56
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 DECLARATIVEPIESERIES_H
21 #ifndef DECLARATIVEPIESERIES_H
22 #define DECLARATIVEPIESERIES_H
22 #define DECLARATIVEPIESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qpieslice.h"
25 #include "qpieslice.h"
26 #include "qpieseries.h"
26 #include "qpieseries.h"
27 #include <QDeclarativeListProperty>
27 #include <QDeclarativeListProperty>
28 #include <QAbstractItemModel>
28 #include <QAbstractItemModel>
29 #include <QVariant>
29 #include <QVariant>
30 #include "declarativemodel.h"
30 #include "declarativemodel.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 class QChart;
34 class QChart;
35
35
36 class DeclarativePieSeries : public QPieSeries
36 class DeclarativePieSeries : public QPieSeries
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_PROPERTY(DeclarativePieModel *model READ pieModel WRITE setPieModel)
39 Q_PROPERTY(DeclarativePieModel *model READ pieModel WRITE setPieModel)
40
40
41 public:
41 public:
42 explicit DeclarativePieSeries(QObject *parent = 0);
42 explicit DeclarativePieSeries(QObject *parent = 0);
43
43
44 public:
45 Q_INVOKABLE QPieSlice *slice(int index);
46
44 public Q_SLOTS:
47 public Q_SLOTS:
45
48
46 public:
49 public:
47 bool setPieModel(DeclarativePieModel *model);
50 bool setPieModel(DeclarativePieModel *model);
48 DeclarativePieModel *pieModel();
51 DeclarativePieModel *pieModel();
49 };
52 };
50
53
51 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
52
55
53 #endif // DECLARATIVEPIESERIES_H
56 #endif // DECLARATIVEPIESERIES_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 //#include "DeclarativeXySeries.h"
21 //#include "DeclarativeXySeries.h"
22 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include "declarativechart.h"
24 #include "declarativechart.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeXySeries::DeclarativeXySeries()
28 DeclarativeXySeries::DeclarativeXySeries()
29 {
29 {
30 }
30 }
31
31
32 DeclarativeXySeries::~DeclarativeXySeries()
32 DeclarativeXySeries::~DeclarativeXySeries()
33 {
33 {
34 }
34 }
35
35
36 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model)
36 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model)
37 {
37 {
38 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
38 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
39 bool value(false);
39 bool value(false);
40 if (m) {
40 if (m) {
41 // All the inherited objects must be of type QXYSeries, so it is safe to cast
41 // All the inherited objects must be of type QXYSeries, so it is safe to cast
42 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
42 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
43 series->setModel(m);
43 value = series->setModel(m);
44 series->setModelMapping(0, 1, Qt::Vertical);
44 series->setModelMapping(0, 1, Qt::Vertical);
45 } else {
45 } else {
46 qWarning("DeclarativeXySeries: Illegal model");
46 qWarning("DeclarativeXySeries: Illegal model");
47 }
47 }
48 return value;
48 return value;
49 }
49 }
50
50
51 DeclarativeXyModel *DeclarativeXySeries::declarativeModel()
51 DeclarativeXyModel *DeclarativeXySeries::declarativeModel()
52 {
52 {
53 // All the inherited objects must be of type QXYSeries, so it is safe to cast
53 // All the inherited objects must be of type QXYSeries, so it is safe to cast
54 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
54 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
55 Q_ASSERT(series);
55 Q_ASSERT(series);
56 return qobject_cast<DeclarativeXyModel *>(series->model());
56 return qobject_cast<DeclarativeXyModel *>(series->model());
57 }
57 }
58
58
59 QTCOMMERCIALCHART_END_NAMESPACE
59 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,69
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 "qaxiscategories.h"
24 #include "qaxiscategories.h"
25 #include "declarativechart.h"
25 #include "declarativechart.h"
26 #include "declarativexypoint.h"
26 #include "declarativexypoint.h"
27 #include "declarativelineseries.h"
27 #include "declarativelineseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.h"
29 #include "declarativeareaseries.h"
29 #include "declarativeareaseries.h"
30 #include "declarativescatterseries.h"
30 #include "declarativescatterseries.h"
31 #include "declarativebarseries.h"
31 #include "declarativebarseries.h"
32 #include "declarativepieseries.h"
32 #include "declarativepieseries.h"
33 //#include "declarativepiemodel.h"
34
33
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
35
37 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
36 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
38 {
37 {
39 Q_OBJECT
38 Q_OBJECT
40 public:
39 public:
41 virtual void registerTypes(const char *uri)
40 virtual void registerTypes(const char *uri)
42 {
41 {
43 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
42 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
44
43
45 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
44 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
46 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
45 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
47 QLatin1String("Trying to create uncreatable type: Axis."));
46 QLatin1String("Trying to create uncreatable type: Axis."));
48 //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory");
47 //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory");
49 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
48 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
50 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
49 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
51 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
50 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
52 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
51 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
53 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
52 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
54 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
53 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
55 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
54 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
56 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
55 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
57 // TODO: a declarative model for each type
58 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
56 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
59 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
57 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
58 qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel");
59 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
60 }
60 }
61 };
61 };
62
62
63 #include "plugin.moc"
63 #include "plugin.moc"
64
64
65 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
66
66
67 QTCOMMERCIALCHART_USE_NAMESPACE
67 QTCOMMERCIALCHART_USE_NAMESPACE
68
68
69 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
69 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,303 +1,306
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QBarSet
27 \class QBarSet
28 \brief part of QtCommercial chart API.
28 \brief part of QtCommercial chart API.
29
29
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 First value of set is assumed to belong to first category, second to second category and so on.
31 First value of set is assumed to belong to first category, second to second category and so on.
32 If set has fewer values than there are categories, then the missing values are assumed to be
32 If set has fewer values than there are categories, then the missing values are assumed to be
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39
39
40 /*!
40 /*!
41 \fn void QBarSet::clicked(QString category)
41 \fn void QBarSet::clicked(QString category)
42 \brief signals that set has been clicked
42 \brief signals that set has been clicked
43 Parameter \a category describes on which category was clicked
43 Parameter \a category describes on which category was clicked
44 */
44 */
45
45
46 /*!
46 /*!
47 \fn void QBarSet::hovered(bool status)
47 \fn void QBarSet::hovered(bool status)
48 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
48 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
49
49
50 The signal is emitted if mouse is hovered on top of set
50 The signal is emitted if mouse is hovered on top of set
51 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
51 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
52 */
52 */
53
53
54 /*!
54 /*!
55 Constructs QBarSet with a name of \a name and with parent of \a parent
55 Constructs QBarSet with a name of \a name and with parent of \a parent
56 */
56 */
57 QBarSet::QBarSet(const QString name, QObject *parent)
57 QBarSet::QBarSet(const QString name, QObject *parent)
58 : QObject(parent)
58 : QObject(parent)
59 ,d_ptr(new QBarSetPrivate(name,this))
59 ,d_ptr(new QBarSetPrivate(name,this))
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Destroys the barset
64 Destroys the barset
65 */
65 */
66 QBarSet::~QBarSet()
66 QBarSet::~QBarSet()
67 {
67 {
68 // NOTE: d_ptr destroyed by QObject
68 // NOTE: d_ptr destroyed by QObject
69 }
69 }
70
70
71 /*!
71 /*!
72 Sets new \a name for set.
72 Sets new \a name for set.
73 */
73 */
74 void QBarSet::setName(const QString name)
74 void QBarSet::setName(const QString name)
75 {
75 {
76 d_ptr->m_name = name;
76 d_ptr->m_name = name;
77 }
77 }
78
78
79 /*!
79 /*!
80 Returns name of the set.
80 Returns name of the set.
81 */
81 */
82 QString QBarSet::name() const
82 QString QBarSet::name() const
83 {
83 {
84 return d_ptr->m_name;
84 return d_ptr->m_name;
85 }
85 }
86
86
87 /*!
87 /*!
88 Appends new value \a value to the end of set.
88 Appends new value \a value to the end of set.
89 */
89 */
90 void QBarSet::append(const qreal value)
90 void QBarSet::append(const qreal value)
91 {
91 {
92 d_ptr->m_values.append(value);
92 d_ptr->m_values.append(value);
93 emit d_ptr->restructuredBars();
93 emit d_ptr->restructuredBars();
94 }
94 }
95
95
96 /*!
96 /*!
97 Appends new value \a value to the end of set.
97 Appends new value \a value to the end of set.
98 */
98 */
99 QBarSet& QBarSet::operator << (const qreal &value)
99 QBarSet& QBarSet::operator << (const qreal &value)
100 {
100 {
101 append(value);
101 append(value);
102 return *this;
102 return *this;
103 }
103 }
104
104
105 /*!
105 /*!
106 Inserts new \a value on the \a index position.
106 Inserts new \a value on the \a index position.
107 The value that is currently at this postion is moved to postion index + 1
107 The value that is currently at this postion is moved to postion index + 1
108 \sa remove()
108 \sa remove()
109 */
109 */
110 void QBarSet::insert(const int index, const qreal value)
110 void QBarSet::insert(const int index, const qreal value)
111 {
111 {
112 d_ptr->m_values.insert(index, value);
112 d_ptr->m_values.insert(index, value);
113 // emit d_ptr->updatedBars();
113 // emit d_ptr->updatedBars();
114 }
114 }
115
115
116 /*!
116 /*!
117 Removes the value specified by \a index
117 Removes the value specified by \a index
118 \sa insert()
118 \sa insert()
119 */
119 */
120 void QBarSet::remove(const int index)
120 void QBarSet::remove(const int index)
121 {
121 {
122 d_ptr->m_values.removeAt(index);
122 d_ptr->m_values.removeAt(index);
123 // emit d_ptr->updatedBars();
123 // emit d_ptr->updatedBars();
124 }
124 }
125
125
126 /*!
126 /*!
127 Sets a new value \a value to set, indexed by \a index
127 Sets a new value \a value to set, indexed by \a index
128 */
128 */
129 void QBarSet::replace(const int index, const qreal value)
129 void QBarSet::replace(const int index, const qreal value)
130 {
130 {
131 d_ptr->m_values.replace(index,value);
131 d_ptr->m_values.replace(index,value);
132 emit d_ptr->updatedBars();
132 emit d_ptr->updatedBars();
133 }
133 }
134
134
135 /*!
135 /*!
136 Returns value of set indexed by \a index
136 Returns value of set indexed by \a index
137 */
137 */
138 qreal QBarSet::at(const int index) const
138 qreal QBarSet::at(const int index) const
139 {
139 {
140 if (index < 0 || index >= d_ptr->m_values.count())
141 return 0.0;
142
140 return d_ptr->m_values.at(index);
143 return d_ptr->m_values.at(index);
141 }
144 }
142
145
143 /*!
146 /*!
144 Returns value of set indexed by \a index
147 Returns value of set indexed by \a index
145 */
148 */
146 qreal QBarSet::operator [] (int index) const
149 qreal QBarSet::operator [] (int index) const
147 {
150 {
148 return d_ptr->m_values.at(index);
151 return d_ptr->m_values.at(index);
149 }
152 }
150
153
151 /*!
154 /*!
152 Returns count of values in set.
155 Returns count of values in set.
153 */
156 */
154 int QBarSet::count() const
157 int QBarSet::count() const
155 {
158 {
156 return d_ptr->m_values.count();
159 return d_ptr->m_values.count();
157 }
160 }
158
161
159 /*!
162 /*!
160 Returns sum of all values in barset.
163 Returns sum of all values in barset.
161 */
164 */
162 qreal QBarSet::sum() const
165 qreal QBarSet::sum() const
163 {
166 {
164 qreal total(0);
167 qreal total(0);
165 for (int i=0; i < d_ptr->m_values.count(); i++) {
168 for (int i=0; i < d_ptr->m_values.count(); i++) {
166 total += d_ptr->m_values.at(i);
169 total += d_ptr->m_values.at(i);
167 }
170 }
168 return total;
171 return total;
169 }
172 }
170
173
171 /*!
174 /*!
172 Sets pen for set. Bars of this set are drawn using \a pen
175 Sets pen for set. Bars of this set are drawn using \a pen
173 */
176 */
174 void QBarSet::setPen(const QPen &pen)
177 void QBarSet::setPen(const QPen &pen)
175 {
178 {
176 if(d_ptr->m_pen!=pen){
179 if(d_ptr->m_pen!=pen){
177 d_ptr->m_pen = pen;
180 d_ptr->m_pen = pen;
178 emit d_ptr->updatedBars();
181 emit d_ptr->updatedBars();
179 }
182 }
180 }
183 }
181
184
182 /*!
185 /*!
183 Returns pen of the set.
186 Returns pen of the set.
184 */
187 */
185 QPen QBarSet::pen() const
188 QPen QBarSet::pen() const
186 {
189 {
187 return d_ptr->m_pen;
190 return d_ptr->m_pen;
188 }
191 }
189
192
190 /*!
193 /*!
191 Sets brush for the set. Bars of this set are drawn using \a brush
194 Sets brush for the set. Bars of this set are drawn using \a brush
192 */
195 */
193 void QBarSet::setBrush(const QBrush &brush)
196 void QBarSet::setBrush(const QBrush &brush)
194 {
197 {
195 if(d_ptr->m_brush!=brush){
198 if(d_ptr->m_brush!=brush){
196 d_ptr->m_brush = brush;
199 d_ptr->m_brush = brush;
197 emit d_ptr->updatedBars();
200 emit d_ptr->updatedBars();
198 }
201 }
199 }
202 }
200
203
201 /*!
204 /*!
202 Returns brush of the set.
205 Returns brush of the set.
203 */
206 */
204 QBrush QBarSet::brush() const
207 QBrush QBarSet::brush() const
205 {
208 {
206 return d_ptr->m_brush;
209 return d_ptr->m_brush;
207 }
210 }
208
211
209 /*!
212 /*!
210 Sets \a pen of the values that are drawn on top of this barset
213 Sets \a pen of the values that are drawn on top of this barset
211 */
214 */
212 void QBarSet::setLabelPen(const QPen &pen)
215 void QBarSet::setLabelPen(const QPen &pen)
213 {
216 {
214 if(d_ptr->m_labelPen!=pen){
217 if(d_ptr->m_labelPen!=pen){
215 d_ptr->m_labelPen = pen;
218 d_ptr->m_labelPen = pen;
216 emit d_ptr->updatedBars();
219 emit d_ptr->updatedBars();
217 }
220 }
218 }
221 }
219
222
220 /*!
223 /*!
221 Returns pen of the values that are drawn on top of this barset
224 Returns pen of the values that are drawn on top of this barset
222 */
225 */
223 QPen QBarSet::labelPen() const
226 QPen QBarSet::labelPen() const
224 {
227 {
225 return d_ptr->m_labelPen;
228 return d_ptr->m_labelPen;
226 }
229 }
227
230
228 /*!
231 /*!
229 Sets \a brush of the values that are drawn on top of this barset
232 Sets \a brush of the values that are drawn on top of this barset
230 */
233 */
231 void QBarSet::setLabelBrush(const QBrush &brush)
234 void QBarSet::setLabelBrush(const QBrush &brush)
232 {
235 {
233 if(d_ptr->m_labelBrush!=brush){
236 if(d_ptr->m_labelBrush!=brush){
234 d_ptr->m_labelBrush = brush;
237 d_ptr->m_labelBrush = brush;
235 emit d_ptr->updatedBars();
238 emit d_ptr->updatedBars();
236 }
239 }
237 }
240 }
238
241
239 /*!
242 /*!
240 Returns brush of the values that are drawn on top of this barset
243 Returns brush of the values that are drawn on top of this barset
241 */
244 */
242 QBrush QBarSet::labelBrush() const
245 QBrush QBarSet::labelBrush() const
243 {
246 {
244 return d_ptr->m_labelBrush;
247 return d_ptr->m_labelBrush;
245 }
248 }
246
249
247 /*!
250 /*!
248 Sets the \a font for values that are drawn on top of this barset
251 Sets the \a font for values that are drawn on top of this barset
249 */
252 */
250 void QBarSet::setLabelFont(const QFont &font)
253 void QBarSet::setLabelFont(const QFont &font)
251 {
254 {
252 if(d_ptr->m_labelFont!=font) {
255 if(d_ptr->m_labelFont!=font) {
253 d_ptr->m_labelFont = font;
256 d_ptr->m_labelFont = font;
254 emit d_ptr->updatedBars();
257 emit d_ptr->updatedBars();
255 }
258 }
256
259
257 }
260 }
258
261
259 /*!
262 /*!
260 Returns the pen for values that are drawn on top of this set
263 Returns the pen for values that are drawn on top of this set
261 */
264 */
262 QFont QBarSet::labelFont() const
265 QFont QBarSet::labelFont() const
263 {
266 {
264 return d_ptr->m_labelFont;
267 return d_ptr->m_labelFont;
265 }
268 }
266
269
267 /*!
270 /*!
268 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
271 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
269 */
272 */
270
273
271 void QBarSet::setLabelsVisible(bool visible)
274 void QBarSet::setLabelsVisible(bool visible)
272 {
275 {
273 if(d_ptr->m_labelsVisible!=visible) {
276 if(d_ptr->m_labelsVisible!=visible) {
274 d_ptr->m_labelsVisible = visible;
277 d_ptr->m_labelsVisible = visible;
275 emit d_ptr->labelsVisibleChanged(visible);
278 emit d_ptr->labelsVisibleChanged(visible);
276 }
279 }
277 }
280 }
278
281
279 /*!
282 /*!
280 Returns the visibility of values
283 Returns the visibility of values
281 */
284 */
282 bool QBarSet::labelsVisible() const
285 bool QBarSet::labelsVisible() const
283 {
286 {
284 return d_ptr->m_labelsVisible;
287 return d_ptr->m_labelsVisible;
285 }
288 }
286
289
287 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
290 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
288
291
289 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
292 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
290 q_ptr(parent),
293 q_ptr(parent),
291 m_name(name),
294 m_name(name),
292 m_labelsVisible(false)
295 m_labelsVisible(false)
293 {
296 {
294 }
297 }
295
298
296 QBarSetPrivate::~QBarSetPrivate()
299 QBarSetPrivate::~QBarSetPrivate()
297 {
300 {
298 }
301 }
299
302
300 #include "moc_qbarset.cpp"
303 #include "moc_qbarset.cpp"
301 #include "moc_qbarset_p.cpp"
304 #include "moc_qbarset_p.cpp"
302
305
303 QTCOMMERCIALCHART_END_NAMESPACE
306 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,96 +1,97
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 QBARSET_H
21 #ifndef QBARSET_H
22 #define QBARSET_H
22 #define QBARSET_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QBrush>
26 #include <QBrush>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QBarSetPrivate;
30 class QBarSetPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QString name READ name WRITE setName)
35
36
36 public:
37 public:
37 explicit QBarSet(const QString name, QObject *parent = 0);
38 explicit QBarSet(const QString name, QObject *parent = 0);
38 virtual ~QBarSet();
39 virtual ~QBarSet();
39
40
40 void setName(const QString name);
41 void setName(const QString name);
41 QString name() const;
42 QString name() const;
42
43
43 // TODO:
44 // TODO:
44 // void append(const QPointF value); // Appends bar with x-value
45 // void append(const QPointF value); // Appends bar with x-value
45 // void append(const QList<QPointF> value); // Same with list
46 // void append(const QList<QPointF> value); // Same with list
46 void append(const qreal value); // TODO: change so, that count becomes x-value
47 void append(const qreal value); // TODO: change so, that count becomes x-value
47
48
48 // TODO:
49 // TODO:
49 // void append(const QList<qreal> values); // Append list of values. Using index as x-value
50 // void append(const QList<qreal> values); // Append list of values. Using index as x-value
50
51
51 QBarSet& operator << (const qreal &value); // TODO: change implementations so, that count becomes x-value
52 QBarSet& operator << (const qreal &value); // TODO: change implementations so, that count becomes x-value
52 // TODO:
53 // TODO:
53 // QBarSet& operator << (const QPointF &value); // Appends bar with x-value
54 // QBarSet& operator << (const QPointF &value); // Appends bar with x-value
54
55
55 void insert(const int index, const qreal value); // TODO: internal reindexing (what happens, if there are points with real x values?)
56 void insert(const int index, const qreal value); // TODO: internal reindexing (what happens, if there are points with real x values?)
56 void remove(const int index); // TODO: internal reindexing (what happens, if there are points with real x values?)
57 void remove(const int index); // TODO: internal reindexing (what happens, if there are points with real x values?)
57 void replace(const int index, const qreal value);
58 void replace(const int index, const qreal value);
58 qreal at(const int index) const;
59 qreal at(const int index) const;
59 qreal operator [] (int index) const;
60 qreal operator [] (int index) const;
60 int count() const;
61 int count() const;
61 qreal sum() const;
62 qreal sum() const;
62
63
63 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
64 QPen pen() const;
65 QPen pen() const;
65
66
66 void setBrush(const QBrush &brush);
67 void setBrush(const QBrush &brush);
67 QBrush brush() const;
68 QBrush brush() const;
68
69
69 void setLabelPen(const QPen &pen);
70 void setLabelPen(const QPen &pen);
70 QPen labelPen() const;
71 QPen labelPen() const;
71
72
72 void setLabelBrush(const QBrush &brush);
73 void setLabelBrush(const QBrush &brush);
73 QBrush labelBrush() const;
74 QBrush labelBrush() const;
74
75
75 void setLabelFont(const QFont &font);
76 void setLabelFont(const QFont &font);
76 QFont labelFont() const;
77 QFont labelFont() const;
77
78
78 void setLabelsVisible(bool visible = true);
79 void setLabelsVisible(bool visible = true);
79 bool labelsVisible() const;
80 bool labelsVisible() const;
80
81
81 Q_SIGNALS:
82 Q_SIGNALS:
82 void clicked(QString category);
83 void clicked(QString category);
83 void hovered(bool status);
84 void hovered(bool status);
84
85
85 private:
86 private:
86 QScopedPointer<QBarSetPrivate> d_ptr;
87 QScopedPointer<QBarSetPrivate> d_ptr;
87 Q_DISABLE_COPY(QBarSet)
88 Q_DISABLE_COPY(QBarSet)
88 friend class QBarSeries;
89 friend class QBarSeries;
89 friend class BarLegendMarker;
90 friend class BarLegendMarker;
90 friend class BarChartItem;
91 friend class BarChartItem;
91 friend class QBarSeriesPrivate;
92 friend class QBarSeriesPrivate;
92 };
93 };
93
94
94 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
95
96
96 #endif // QBARSET_H
97 #endif // QBARSET_H
@@ -1,141 +1,140
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 "charttablemodel.h"
21 #include "charttablemodel.h"
22 #include <QVector>
22 #include <QVector>
23 #include <QTime>
23 #include <QTime>
24 #include <QRect>
24 #include <QRect>
25 #include <QColor>
25 #include <QColor>
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 ChartTableModel::ChartTableModel(QObject *parent) :
29 ChartTableModel::ChartTableModel(QObject *parent) :
30 QAbstractTableModel(parent)
30 QAbstractTableModel(parent)
31 {
31 {
32 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
32 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
33
33
34 m_columnCount = 2;
34 m_columnCount = 2;
35 m_rowCount = 0;
35 m_rowCount = 0;
36
36
37 // m_data
37 // m_data
38 for (int i = 0; i < m_rowCount; i++) {
38 for (int i = 0; i < m_rowCount; i++) {
39 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
39 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
40 for (int k = 0; k < dataVec->size(); k++) {
40 for (int k = 0; k < dataVec->size(); k++) {
41 if (k%2 == 0)
41 if (k%2 == 0)
42 dataVec->replace(k, i * 50 + qrand()%20);
42 dataVec->replace(k, i * 50 + qrand()%20);
43 else
43 else
44 dataVec->replace(k, qrand()%100);
44 dataVec->replace(k, qrand()%100);
45 }
45 }
46 m_data.append(dataVec);
46 m_data.append(dataVec);
47 }
47 }
48 }
48 }
49
49
50 int ChartTableModel::rowCount(const QModelIndex & parent) const
50 int ChartTableModel::rowCount(const QModelIndex & parent) const
51 {
51 {
52 Q_UNUSED(parent)
52 Q_UNUSED(parent)
53 return m_data.count();
53 return m_data.count();
54 }
54 }
55
55
56 int ChartTableModel::columnCount(const QModelIndex & parent) const
56 int ChartTableModel::columnCount(const QModelIndex & parent) const
57 {
57 {
58 Q_UNUSED(parent)
58 Q_UNUSED(parent)
59 return m_columnCount;
59 return m_columnCount;
60 }
60 }
61
61
62 QVariant ChartTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
62 QVariant ChartTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
63 {
63 {
64 if (role != Qt::DisplayRole)
64 if (role != Qt::DisplayRole)
65 return QVariant();
65 return QVariant();
66
66
67 if (orientation == Qt::Horizontal)
67 if (orientation == Qt::Horizontal) {
68 {
68 if (section % 2 == 0)
69 if (section%2 == 0)
70 return "x";
69 return "x";
71 else
70 else
72 return "y";
71 return "y";
73 }
72 } else {
74 else
75 return QString("%1").arg(section + 1);
73 return QString("%1").arg(section + 1);
74 }
76 }
75 }
77
76
78 QVariant ChartTableModel::data(const QModelIndex &index, int role) const
77 QVariant ChartTableModel::data(const QModelIndex &index, int role) const
79 {
78 {
80 if (role == Qt::DisplayRole) {
79 if (role == Qt::DisplayRole) {
81 return m_data[index.row()]->at(index.column());
80 return m_data[index.row()]->at(index.column());
82 } else if (role == Qt::EditRole) {
81 } else if (role == Qt::EditRole) {
83 return m_data[index.row()]->at(index.column());
82 return m_data[index.row()]->at(index.column());
84 }
83 }
85 return QVariant();
84 return QVariant();
86 }
85 }
87
86
88 bool ChartTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
87 bool ChartTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
89 {
88 {
90 if (index.isValid() && role == Qt::EditRole) {
89 if (index.isValid() && role == Qt::EditRole) {
91 m_data[index.row()]->replace(index.column(), value);
90 m_data[index.row()]->replace(index.column(), value);
92 emit dataChanged(index, index);
91 emit dataChanged(index, index);
93 return true;
92 return true;
94 }
93 }
95 return false;
94 return false;
96 }
95 }
97
96
98 void ChartTableModel::insertRow(int row, const QModelIndex &parent)
97 void ChartTableModel::insertRow(int row, const QModelIndex &parent)
99 {
98 {
100 Q_UNUSED(parent)
99 Q_UNUSED(parent)
101
100
102 beginInsertRows(QModelIndex(), row, row);
101 beginInsertRows(QModelIndex(), row, row);
103 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
102 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
104 m_data.insert(row, dataVec);
103 m_data.insert(row, dataVec);
105 endInsertRows();
104 endInsertRows();
106 }
105 }
107
106
108 //bool ChartTableModel::removeRow(int row, const QModelIndex &parent)
107 //bool ChartTableModel::removeRow(int row, const QModelIndex &parent)
109 //{
108 //{
110 // Q_UNUSED(parent)
109 // Q_UNUSED(parent)
111 // Q_ASSERT(row >= 0 && row < rowCount);
110 // Q_ASSERT(row >= 0 && row < rowCount);
112
111
113 // beginRemoveRows(parent, row, row);
112 // beginRemoveRows(parent, row, row);
114 // m_data.removeAt(row);
113 // m_data.removeAt(row);
115 // endRemoveRows();
114 // endRemoveRows();
116 // return true;
115 // return true;
117 //}
116 //}
118
117
119 bool ChartTableModel::removeRow(int row, const QModelIndex &parent)
118 bool ChartTableModel::removeRow(int row, const QModelIndex &parent)
120 {
119 {
121 return QAbstractTableModel::removeRow(row, parent);
120 return QAbstractTableModel::removeRow(row, parent);
122 }
121 }
123
122
124 bool ChartTableModel::removeRows(int row, int count, const QModelIndex &parent)
123 bool ChartTableModel::removeRows(int row, int count, const QModelIndex &parent)
125 {
124 {
126 beginRemoveRows(parent, row, row + count - 1);
125 beginRemoveRows(parent, row, row + count - 1);
127 bool removed(false);
126 bool removed(false);
128 for (int i(row); i < (row + count); i++) {
127 for (int i(row); i < (row + count); i++) {
129 m_data.removeAt(i);
128 m_data.removeAt(i);
130 removed = true;
129 removed = true;
131 }
130 }
132 endRemoveRows();
131 endRemoveRows();
133 return removed;
132 return removed;
134 }
133 }
135
134
136 Qt::ItemFlags ChartTableModel::flags ( const QModelIndex & index ) const
135 Qt::ItemFlags ChartTableModel::flags ( const QModelIndex & index ) const
137 {
136 {
138 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
137 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
139 }
138 }
140
139
141 #include "moc_charttablemodel.cpp"
140 #include "moc_charttablemodel.cpp"
@@ -1,84 +1,85
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 QPIESLICE_H
21 #ifndef QPIESLICE_H
22 #define QPIESLICE_H
22 #define QPIESLICE_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include <QFont>
28 #include <QFont>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 class PieSliceData;
31 class PieSliceData;
32
32
33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed)
36 Q_PROPERTY(QString label READ label WRITE setLabel)
37 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed)
37 Q_PROPERTY(qreal value READ value WRITE setValue)
38 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
38
39
39 public:
40 public:
40 explicit QPieSlice(QObject *parent = 0);
41 explicit QPieSlice(QObject *parent = 0);
41 QPieSlice(qreal value, QString label, QObject *parent = 0);
42 QPieSlice(qreal value, QString label, QObject *parent = 0);
42 virtual ~QPieSlice();
43 virtual ~QPieSlice();
43
44
44 void setValue(qreal value);
45 void setValue(qreal value);
45 qreal value() const;
46 qreal value() const;
46 void setLabel(QString label);
47 void setLabel(QString label);
47 QString label() const;
48 QString label() const;
48 void setLabelVisible(bool visible = true);
49 void setLabelVisible(bool visible = true);
49 bool isLabelVisible() const;
50 bool isLabelVisible() const;
50 void setExploded(bool exploded = true);
51 void setExploded(bool exploded = true);
51 bool isExploded() const;
52 bool isExploded() const;
52
53
53 void setPen(const QPen &pen);
54 void setPen(const QPen &pen);
54 QPen pen() const;
55 QPen pen() const;
55 void setBrush(const QBrush &brush);
56 void setBrush(const QBrush &brush);
56 QBrush brush() const;
57 QBrush brush() const;
57 void setLabelPen(const QPen &pen);
58 void setLabelPen(const QPen &pen);
58 QPen labelPen() const;
59 QPen labelPen() const;
59 void setLabelFont(const QFont &font);
60 void setLabelFont(const QFont &font);
60 QFont labelFont() const;
61 QFont labelFont() const;
61
62
62 void setLabelArmLengthFactor(qreal factor);
63 void setLabelArmLengthFactor(qreal factor);
63 qreal labelArmLengthFactor() const;
64 qreal labelArmLengthFactor() const;
64 void setExplodeDistanceFactor(qreal factor);
65 void setExplodeDistanceFactor(qreal factor);
65 qreal explodeDistanceFactor() const;
66 qreal explodeDistanceFactor() const;
66
67
67 qreal percentage() const;
68 qreal percentage() const;
68 qreal startAngle() const;
69 qreal startAngle() const;
69 qreal endAngle() const;
70 qreal endAngle() const;
70
71
71 Q_SIGNALS:
72 Q_SIGNALS:
72 void clicked();
73 void clicked();
73 void hovered(bool state);
74 void hovered(bool state);
74 void changed();
75 void changed();
75
76
76 private:
77 private:
77 friend class PieSliceData;
78 friend class PieSliceData;
78 PieSliceData * const d;
79 PieSliceData * const d;
79 Q_DISABLE_COPY(QPieSlice)
80 Q_DISABLE_COPY(QPieSlice)
80 };
81 };
81
82
82 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
83
84
84 #endif // QPIESLICE_H
85 #endif // QPIESLICE_H
General Comments 0
You need to be logged in to leave comments. Login now