@@ -25,6 +25,15 Rectangle { | |||||
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 | property int __explodedIndex: -1 |
|
26 | property int __explodedIndex: -1 | |
27 |
|
27 | |||
|
28 | ChartModel { | |||
|
29 | id: chartModel | |||
|
30 | ChartModelRow { values: ["Volkswagen", 13.5] } | |||
|
31 | ChartModelRow { values: ["Toyota", 10.9] } | |||
|
32 | ChartModelRow { values: ["Ford", 8.6] } | |||
|
33 | ChartModelRow { values: ["Skoda", 8.2] } | |||
|
34 | ChartModelRow { values: ["Volvo", 6.8] } | |||
|
35 | } | |||
|
36 | ||||
28 | ChartView { |
|
37 | ChartView { | |
29 | id: chart |
|
38 | id: chart | |
30 | title: "Top-5 car brand shares in Finland" |
|
39 | title: "Top-5 car brand shares in Finland" | |
@@ -38,33 +47,34 Rectangle { | |||||
38 |
|
47 | |||
39 | PieSeries { |
|
48 | PieSeries { | |
40 | id: pieSeries |
|
49 | id: pieSeries | |
41 |
model: |
|
50 | model: chartModel | |
42 | id: pieModel |
|
51 | modelMapper.mapLabels: 0 | |
43 | // TODO: initializing properties does not work at the moment, see DeclarativePieModel::append |
|
52 | modelMapper.mapValues: 1 | |
44 | // TODO: explode range, color, border color, border thickness, font, .. |
|
53 | modelMapper.first: 0 | |
45 | PieSlice { exploded: true; label: "Volkswagen"; value: 13.5 } |
|
54 | modelMapper.count: -1 // "Undefined" = -1 by default | |
46 | PieSlice { label: "Toyota"; value: 10.9 } |
|
55 | modelMapper.orientation: PieModelMapper.Vertical | |
47 | PieSlice { label: "Ford"; value: 8.6 } |
|
56 | ||
48 | PieSlice { label: "Skoda"; value: 8.2 } |
|
57 | // TODO: PieSlice to append the data directly into the mapped columns | |
49 |
|
|
58 | //PieSlice { label: "Toyota"; value: 10.9 } | |
50 | } |
|
|||
51 | } |
|
59 | } | |
52 | } |
|
60 | } | |
53 |
|
61 | |||
|
62 | Component.onCompleted: { | |||
|
63 | chartModel.append(["Others", 52.0]); | |||
|
64 | } | |||
|
65 | ||||
54 | Timer { |
|
66 | Timer { | |
55 | repeat: true |
|
67 | repeat: true | |
56 | interval: 2000 |
|
68 | interval: 2000 | |
57 | running: true |
|
69 | running: true | |
58 | onTriggered: { |
|
70 | onTriggered: { | |
59 | changeSliceExploded(__explodedIndex); |
|
71 | // Set all slices as not exploded | |
60 | __explodedIndex = (__explodedIndex + 1) % pieModel.count; |
|
72 | for (var i = 0; i < pieSeries.count; i++) | |
61 | changeSliceExploded(__explodedIndex); |
|
73 | pieSeries.slice(i).exploded = false; | |
62 | } |
|
|||
63 | } |
|
|||
64 |
|
74 | |||
65 | function changeSliceExploded(index) { |
|
75 | // Explode one of the slices | |
66 | if (index >= 0 && index < pieModel.count) { |
|
76 | __explodedIndex = (__explodedIndex + 1) % pieSeries.count; | |
67 |
pieSeries.slice( |
|
77 | pieSeries.slice(__explodedIndex).exploded = true; | |
68 | } |
|
78 | } | |
69 | } |
|
79 | } | |
70 |
|
80 | |||
@@ -80,46 +90,24 Rectangle { | |||||
80 | Text { |
|
90 | Text { | |
81 | id: buttonText |
|
91 | id: buttonText | |
82 | anchors.centerIn: parent |
|
92 | anchors.centerIn: parent | |
83 |
text: |
|
93 | text: "Hide others" | |
84 | } |
|
94 | } | |
85 | MouseArea { |
|
95 | MouseArea { | |
86 | anchors.fill: parent |
|
96 | anchors.fill: parent | |
87 | onClicked: { |
|
97 | onClicked: { | |
88 |
if (button. |
|
98 | if (buttonText.text == "Show others") { | |
89 | // The share of "others" was enabled -> append the data into the model |
|
99 | pieSeries.modelMapper.count = -1; | |
90 | // TODO: this should also be doable by redefining the range inside the model |
|
100 | buttonText.text = "Hide others"; | |
91 | button.state = "show"; |
|
|||
92 | pieModel.append(["Others", 52.0]); |
|
|||
93 | } else { |
|
101 | } else { | |
94 | // The share of "others" was disabled -> remove the data from the model |
|
102 | pieSeries.modelMapper.count = 5; | |
95 | // TODO: this should also be doable by redefining the range inside the model |
|
103 | buttonText.text = "Show others"; | |
96 | button.state = ""; |
|
104 | //pieModel.removeRow(pieModel.count - 1); | |
97 | pieModel.removeRow(pieModel.count - 1); |
|
|||
98 | // TODO: removeAll("label") ? |
|
105 | // TODO: removeAll("label") ? | |
99 | } |
|
106 | } | |
100 | } |
|
107 | } | |
101 | } |
|
108 | } | |
102 | } |
|
109 | } | |
103 |
|
110 | |||
104 |
|
||||
105 | // TODO: Optional syntax for defining models for different series. Is this really needed? |
|
|||
106 | // ChartModel { |
|
|||
107 | // id: chartModel |
|
|||
108 | // ChartElement { column1: "Volkswagen"; column2: 13.5; column3: 1.2 } |
|
|||
109 | // ChartElement { column1: "Toyota"; column2: 10.9; column3: 2.5 } |
|
|||
110 | // } |
|
|||
111 | // // column3 not used by pie series |
|
|||
112 | // PieSeries { |
|
|||
113 | // model: chartModel |
|
|||
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 | // } |
|
|||
121 | // } |
|
|||
122 |
|
||||
123 | // TODO: show how to use data from a list model in a chart view |
|
111 | // TODO: show how to use data from a list model in a chart view | |
124 | // i.e. copy the data into a chart model |
|
112 | // i.e. copy the data into a chart model | |
125 | // ListModel { |
|
113 | // ListModel { |
@@ -32,27 +32,31 Rectangle { | |||||
32 |
|
32 | |||
33 | LineSeries { |
|
33 | LineSeries { | |
34 | name: "Line" |
|
34 | name: "Line" | |
35 |
model: |
|
35 | model: chartModel | |
36 | XyPoint { x: 0.0; y: 0.0 } |
|
36 | modelMapper.mapX: 0 | |
37 | XyPoint { x: 1.1; y: 2.1 } |
|
37 | modelMapper.mapY: 1 | |
38 | XyPoint { x: 1.9; y: 3.3 } |
|
38 | modelMapper.first: 0 | |
39 | XyPoint { x: 2.9; y: 4.9 } |
|
39 | modelMapper.count: -1 | |
40 | XyPoint { x: 3.2; y: 3.0 } |
|
40 | modelMapper.orientation: XYModelMapper.Vertical | |
41 | XyPoint { x: 4.0; y: 3.3 } |
|
|||
42 | } |
|
|||
43 | } |
|
41 | } | |
44 |
|
42 | |||
45 | SplineSeries { |
|
43 | SplineSeries { | |
46 | name: "Spline" |
|
44 | name: "Spline" | |
47 |
model: |
|
45 | model: chartModel | |
48 | XyPoint { x: 0.0; y: 0.3 } |
|
46 | modelMapper.mapX: 0 | |
49 | XyPoint { x: 1.1; y: 3.2 } |
|
47 | modelMapper.mapY: 2 | |
50 | XyPoint { x: 1.7; y: 2.4 } |
|
|||
51 | XyPoint { x: 2.1; y: 2.1 } |
|
|||
52 | XyPoint { x: 2.9; y: 2.6 } |
|
|||
53 | XyPoint { x: 3.4; y: 2.3 } |
|
|||
54 | XyPoint { x: 4.1; y: 3.1 } |
|
|||
55 | } |
|
|||
56 | } |
|
48 | } | |
57 | } |
|
49 | } | |
|
50 | ||||
|
51 | ChartModel { | |||
|
52 | id: chartModel | |||
|
53 | ChartModelRow { values: [0.0, 0.0, 0.3] } | |||
|
54 | ChartModelRow { values: [1.1, 2.1, 3.2] } | |||
|
55 | ChartModelRow { values: [1.9, 3.3, 2.4] } | |||
|
56 | ChartModelRow { values: [2.1, 2.1, 2.1] } | |||
|
57 | ChartModelRow { values: [2.9, 4.9, 2.6] } | |||
|
58 | ChartModelRow { values: [3.4, 3.0, 2.3] } | |||
|
59 | ChartModelRow { values: [4.1, 3.3, 3.1] } | |||
|
60 | } | |||
|
61 | ||||
58 | } |
|
62 | } |
@@ -34,95 +34,46 Rectangle { | |||||
34 |
|
34 | |||
35 | AreaSeries { |
|
35 | AreaSeries { | |
36 | name: "Russian" |
|
36 | name: "Russian" | |
37 |
upperModel: |
|
37 | upperModel: chartModel | |
38 |
|
|
38 | upperModelMapper.mapX: 0 | |
|
39 | upperModelMapper.mapY: 2 | |||
|
40 | lowerModel: chartModel | |||
|
41 | lowerModelMapper.mapX: 0 | |||
|
42 | lowerModelMapper.mapY: 1 | |||
39 | } |
|
43 | } | |
40 | AreaSeries { |
|
44 | AreaSeries { | |
41 | name: "Swedish" |
|
45 | name: "Swedish" | |
42 |
upperModel: |
|
46 | upperModel: chartModel | |
43 |
|
|
47 | upperModelMapper.mapX: 0 | |
|
48 | upperModelMapper.mapY: 3 | |||
|
49 | lowerModel: chartModel | |||
|
50 | lowerModelMapper.mapX: 0 | |||
|
51 | lowerModelMapper.mapY: 1 | |||
44 | } |
|
52 | } | |
45 | AreaSeries { |
|
53 | AreaSeries { | |
46 | name: "Finnish" |
|
54 | name: "Finnish" | |
47 |
upperModel: |
|
55 | upperModel: chartModel | |
48 |
|
|
56 | upperModelMapper.mapX: 0 | |
|
57 | upperModelMapper.mapY: 4 | |||
|
58 | lowerModel: chartModel | |||
|
59 | lowerModelMapper.mapX: 0 | |||
|
60 | lowerModelMapper.mapY: 1 | |||
49 | } |
|
61 | } | |
50 | } |
|
62 | } | |
51 |
|
63 | |||
52 | // TODO: optional implementation with generic ChartModel |
|
64 | ChartModel { | |
53 | // AreaSeries { |
|
65 | id: chartModel | |
54 | // model: chartModel |
|
66 | ChartModelRow { values: [0, 0, 1, 1, 0] } | |
55 | // modelMapping: XyMapping { |
|
67 | ChartModelRow { values: [1, 0, 1, 1, 0] } | |
56 | // xValues: 0 // undefined by default |
|
68 | ChartModelRow { values: [2, 0, 1, 3, 0] } | |
57 | // yValues: 1 // undefined by default |
|
69 | ChartModelRow { values: [3, 0, 1, 3, 0] } | |
58 | // first: 0 // 0 by default |
|
70 | ChartModelRow { values: [4, 0, 1, 2, 0] } | |
59 | // count: 10 // "Undefined" by default |
|
71 | ChartModelRow { values: [5, 0, 0, 0, 0] } | |
60 | // orientation: XyMapping.Vertical // Vertical by default |
|
72 | ChartModelRow { values: [6, 0, 1, 2, 1] } | |
61 | // } |
|
73 | ChartModelRow { values: [7, 0, 1, 1, 0] } | |
62 | // } |
|
74 | ChartModelRow { values: [8, 0, 4, 2, 0] } | |
63 |
|
75 | ChartModelRow { values: [9, 0, 3, 1, 0] } | ||
64 |
|
76 | ChartModelRow { values: [10, 0, 2, 3, 0] } | ||
65 | XYModel { |
|
77 | ChartModelRow { values: [11, 0, 1, 3, 1] } | |
66 | id: zerosModel |
|
|||
67 | XyPoint { x: 0; y: 0 } |
|
|||
68 | XyPoint { x: 1; y: 0 } |
|
|||
69 | XyPoint { x: 2; y: 0 } |
|
|||
70 | XyPoint { x: 3; y: 0 } |
|
|||
71 | XyPoint { x: 4; y: 0 } |
|
|||
72 | XyPoint { x: 5; y: 0 } |
|
|||
73 | XyPoint { x: 6; y: 0 } |
|
|||
74 | XyPoint { x: 7; y: 0 } |
|
|||
75 | XyPoint { x: 8; y: 0 } |
|
|||
76 | XyPoint { x: 9; y: 0 } |
|
|||
77 | XyPoint { x: 10; y: 0 } |
|
|||
78 | XyPoint { x: 11; y: 0 } |
|
|||
79 | } |
|
|||
80 |
|
||||
81 | XYModel { |
|
|||
82 | id: russianModel |
|
|||
83 | XyPoint { x: 0; y: 1 } |
|
|||
84 | XyPoint { x: 1; y: 1 } |
|
|||
85 | XyPoint { x: 2; y: 1 } |
|
|||
86 | XyPoint { x: 3; y: 1 } |
|
|||
87 | XyPoint { x: 4; y: 1 } |
|
|||
88 | XyPoint { x: 5; y: 0 } |
|
|||
89 | XyPoint { x: 6; y: 1 } |
|
|||
90 | XyPoint { x: 7; y: 1 } |
|
|||
91 | XyPoint { x: 8; y: 4 } |
|
|||
92 | XyPoint { x: 9; y: 3 } |
|
|||
93 | XyPoint { x: 10; y: 2 } |
|
|||
94 | XyPoint { x: 11; y: 1 } |
|
|||
95 | } |
|
|||
96 |
|
||||
97 | XYModel { |
|
|||
98 | id: swedishModel |
|
|||
99 | XyPoint { x: 0; y: 1 } |
|
|||
100 | XyPoint { x: 1; y: 1 } |
|
|||
101 | XyPoint { x: 2; y: 3 } |
|
|||
102 | XyPoint { x: 3; y: 3 } |
|
|||
103 | XyPoint { x: 4; y: 2 } |
|
|||
104 | XyPoint { x: 5; y: 0 } |
|
|||
105 | XyPoint { x: 6; y: 2 } |
|
|||
106 | XyPoint { x: 7; y: 1 } |
|
|||
107 | XyPoint { x: 8; y: 2 } |
|
|||
108 | XyPoint { x: 9; y: 1 } |
|
|||
109 | XyPoint { x: 10; y: 3 } |
|
|||
110 | XyPoint { x: 11; y: 3 } |
|
|||
111 | } |
|
|||
112 |
|
||||
113 | XYModel { |
|
|||
114 | id: finnishModel |
|
|||
115 | XyPoint { x: 0; y: 0 } |
|
|||
116 | XyPoint { x: 1; y: 0 } |
|
|||
117 | XyPoint { x: 2; y: 0 } |
|
|||
118 | XyPoint { x: 3; y: 0 } |
|
|||
119 | XyPoint { x: 4; y: 0 } |
|
|||
120 | XyPoint { x: 5; y: 0 } |
|
|||
121 | XyPoint { x: 6; y: 1 } |
|
|||
122 | XyPoint { x: 7; y: 0 } |
|
|||
123 | XyPoint { x: 8; y: 0 } |
|
|||
124 | XyPoint { x: 9; y: 0 } |
|
|||
125 | XyPoint { x: 10; y: 0 } |
|
|||
126 | XyPoint { x: 11; y: 1 } |
|
|||
127 | } |
|
78 | } | |
128 | } |
|
79 | } |
@@ -32,7 +32,7 Rectangle { | |||||
32 | ScatterSeries { |
|
32 | ScatterSeries { | |
33 | id: scatter1 |
|
33 | id: scatter1 | |
34 | name: "Scatter1" |
|
34 | name: "Scatter1" | |
35 |
model: |
|
35 | model: ChartModel { | |
36 | XyPoint { x: 1.5; y: 1.5 } |
|
36 | XyPoint { x: 1.5; y: 1.5 } | |
37 | XyPoint { x: 1.5; y: 1.6 } |
|
37 | XyPoint { x: 1.5; y: 1.6 } | |
38 | XyPoint { x: 1.57; y: 1.55 } |
|
38 | XyPoint { x: 1.57; y: 1.55 } | |
@@ -44,7 +44,7 Rectangle { | |||||
44 | } |
|
44 | } | |
45 | ScatterSeries { |
|
45 | ScatterSeries { | |
46 | name: "Scatter2" |
|
46 | name: "Scatter2" | |
47 |
model: |
|
47 | model: ChartModel { | |
48 | XyPoint { x: 2.0; y: 2.0 } |
|
48 | XyPoint { x: 2.0; y: 2.0 } | |
49 | XyPoint { x: 2.0; y: 2.1 } |
|
49 | XyPoint { x: 2.0; y: 2.1 } | |
50 | XyPoint { x: 2.07; y: 2.05 } |
|
50 | XyPoint { x: 2.07; y: 2.05 } |
@@ -69,11 +69,11 Rectangle { | |||||
69 | // id: chartModel |
|
69 | // id: chartModel | |
70 | // } |
|
70 | // } | |
71 |
|
71 | |||
72 |
|
|
72 | ChartModel { | |
73 | id: maxModel |
|
73 | id: maxModel | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 |
|
|
76 | ChartModel { | |
77 | id: minModel |
|
77 | id: minModel | |
78 | } |
|
78 | } | |
79 |
|
79 |
@@ -28,48 +28,65 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
28 | DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : |
|
28 | DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : | |
29 | QAreaSeries(new QLineSeries(parent), new QLineSeries(parent)) |
|
29 | QAreaSeries(new QLineSeries(parent), new QLineSeries(parent)) | |
30 | { |
|
30 | { | |
|
31 | QXYModelMapper *upperMapper = new QXYModelMapper(upperSeries()); | |||
|
32 | upperMapper->setMapX(0); | |||
|
33 | upperMapper->setMapY(1); | |||
|
34 | upperMapper->setFirst(0); | |||
|
35 | upperMapper->setCount(-1); | |||
|
36 | upperMapper->setOrientation(Qt::Vertical); | |||
|
37 | upperSeries()->setModelMapper(upperMapper); | |||
|
38 | ||||
|
39 | QXYModelMapper *lowerMapper = new QXYModelMapper(lowerSeries()); | |||
|
40 | lowerMapper->setMapX(2); | |||
|
41 | lowerMapper->setMapY(3); | |||
|
42 | lowerMapper->setFirst(0); | |||
|
43 | lowerMapper->setCount(-1); | |||
|
44 | lowerMapper->setOrientation(Qt::Vertical); | |||
|
45 | lowerSeries()->setModelMapper(lowerMapper); | |||
31 | } |
|
46 | } | |
32 |
|
47 | |||
33 |
bool DeclarativeAreaSeries::setDeclarativeUpperModel(Declarative |
|
48 | bool DeclarativeAreaSeries::setDeclarativeUpperModel(DeclarativeTableModel *model) | |
34 | { |
|
49 | { | |
35 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
50 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |
36 | bool value(false); |
|
51 | bool value(false); | |
37 | if (m) { |
|
52 | if (m) { | |
38 | upperSeries()->setModel(m); |
|
53 | upperSeries()->setModel(m); | |
39 | QXYModelMapper *mapper = new QXYModelMapper; |
|
|||
40 | mapper->setMapX(0); |
|
|||
41 | mapper->setMapY(1); |
|
|||
42 | upperSeries()->setModelMapper(mapper); |
|
|||
43 | } else { |
|
54 | } else { | |
44 | qWarning("DeclarativeAreaSeries: Illegal model"); |
|
55 | qWarning("DeclarativeAreaSeries: Illegal model"); | |
45 | } |
|
56 | } | |
46 | return value; |
|
57 | return value; | |
47 | } |
|
58 | } | |
48 |
|
59 | |||
49 |
Declarative |
|
60 | DeclarativeTableModel *DeclarativeAreaSeries::declarativeUpperModel() | |
50 | { |
|
61 | { | |
51 |
return qobject_cast<Declarative |
|
62 | return qobject_cast<DeclarativeTableModel *>(upperSeries()->model()); | |
52 | } |
|
63 | } | |
53 |
|
64 | |||
54 |
bool DeclarativeAreaSeries::setDeclarativeLowerModel(Declarative |
|
65 | bool DeclarativeAreaSeries::setDeclarativeLowerModel(DeclarativeTableModel *model) | |
55 | { |
|
66 | { | |
56 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
67 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |
57 | bool value(false); |
|
68 | bool value(false); | |
58 | if (m) { |
|
69 | if (m) { | |
59 | lowerSeries()->setModel(m); |
|
70 | lowerSeries()->setModel(m); | |
60 | QXYModelMapper *mapper = new QXYModelMapper; |
|
|||
61 | mapper->setMapX(0); |
|
|||
62 | mapper->setMapY(1); |
|
|||
63 | lowerSeries()->setModelMapper(mapper); |
|
|||
64 | } else { |
|
71 | } else { | |
65 | qWarning("DeclarativeAreaSeries: Illegal model"); |
|
72 | qWarning("DeclarativeAreaSeries: Illegal model"); | |
66 | } |
|
73 | } | |
67 | return value; |
|
74 | return value; | |
68 | } |
|
75 | } | |
69 |
|
76 | |||
70 |
Declarative |
|
77 | DeclarativeTableModel *DeclarativeAreaSeries::declarativeLowerModel() | |
|
78 | { | |||
|
79 | return qobject_cast<DeclarativeTableModel *>(lowerSeries()->model()); | |||
|
80 | } | |||
|
81 | ||||
|
82 | QXYModelMapper* DeclarativeAreaSeries::upperModelMapper() const | |||
|
83 | { | |||
|
84 | return upperSeries()->modelMapper(); | |||
|
85 | } | |||
|
86 | ||||
|
87 | QXYModelMapper* DeclarativeAreaSeries::lowerModelMapper() const | |||
71 | { |
|
88 | { | |
72 |
return |
|
89 | return lowerSeries()->modelMapper(); | |
73 | } |
|
90 | } | |
74 |
|
91 | |||
75 | #include "moc_declarativeareaseries.cpp" |
|
92 | #include "moc_declarativeareaseries.cpp" |
@@ -24,24 +24,27 | |||||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qareaseries.h" |
|
25 | #include "qareaseries.h" | |
26 | #include "declarativelineseries.h" |
|
26 | #include "declarativelineseries.h" | |
27 | #include "declarativexyseries.h" |
|
|||
28 |
|
27 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
29 | |||
31 |
class DeclarativeAreaSeries : public QAreaSeries |
|
30 | class DeclarativeAreaSeries : public QAreaSeries | |
32 | { |
|
31 | { | |
33 | Q_OBJECT |
|
32 | Q_OBJECT | |
34 |
Q_PROPERTY(Declarative |
|
33 | Q_PROPERTY(DeclarativeTableModel *upperModel READ declarativeUpperModel WRITE setDeclarativeUpperModel) | |
35 |
Q_PROPERTY(Declarative |
|
34 | Q_PROPERTY(DeclarativeTableModel *lowerModel READ declarativeLowerModel WRITE setDeclarativeLowerModel) | |
|
35 | Q_PROPERTY(QXYModelMapper *upperModelMapper READ upperModelMapper) | |||
|
36 | Q_PROPERTY(QXYModelMapper *lowerModelMapper READ lowerModelMapper) | |||
36 |
|
37 | |||
37 | public: |
|
38 | public: | |
38 | explicit DeclarativeAreaSeries(QObject *parent = 0); |
|
39 | explicit DeclarativeAreaSeries(QObject *parent = 0); | |
39 |
|
40 | |||
40 | public: |
|
41 | public: | |
41 |
bool setDeclarativeUpperModel(Declarative |
|
42 | bool setDeclarativeUpperModel(DeclarativeTableModel *model); | |
42 |
Declarative |
|
43 | DeclarativeTableModel *declarativeUpperModel(); | |
43 |
bool setDeclarativeLowerModel(Declarative |
|
44 | bool setDeclarativeLowerModel(DeclarativeTableModel *model); | |
44 |
Declarative |
|
45 | DeclarativeTableModel *declarativeLowerModel(); | |
|
46 | QXYModelMapper* upperModelMapper() const; | |||
|
47 | QXYModelMapper* lowerModelMapper() const; | |||
45 | }; |
|
48 | }; | |
46 |
|
49 | |||
47 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -31,7 +31,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
31 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries |
|
31 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
Q_PROPERTY(Declarative |
|
34 | Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeLineSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeLineSeries(QObject *parent = 0); |
@@ -24,7 +24,25 | |||||
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | ////////////// Table model (base) /////////////////// |
|
27 | ||
|
28 | ////////////// Table model row /////////////////// | |||
|
29 | ||||
|
30 | DeclarativeTableModelRow::DeclarativeTableModelRow(QObject *parent) | |||
|
31 | : QObject(parent) | |||
|
32 | { | |||
|
33 | } | |||
|
34 | ||||
|
35 | QVariantList DeclarativeTableModelRow::values() | |||
|
36 | { | |||
|
37 | return m_values; | |||
|
38 | } | |||
|
39 | ||||
|
40 | void DeclarativeTableModelRow::setValues(QVariantList values) | |||
|
41 | { | |||
|
42 | m_values = values; | |||
|
43 | } | |||
|
44 | ||||
|
45 | ////////////// Table model /////////////////// | |||
28 |
|
46 | |||
29 | DeclarativeTableModel::DeclarativeTableModel(QObject *parent) : |
|
47 | DeclarativeTableModel::DeclarativeTableModel(QObject *parent) : | |
30 | ChartTableModel(parent) |
|
48 | ChartTableModel(parent) | |
@@ -54,39 +72,45 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> * | |||||
54 | Q_UNUSED(child) |
|
72 | Q_UNUSED(child) | |
55 | } |
|
73 | } | |
56 |
|
74 | |||
57 |
void DeclarativeTableModel::append |
|
75 | void DeclarativeTableModel::append(QVariantList values) | |
58 | { |
|
76 | { | |
59 | if (qobject_cast<DeclarativeBarModel *>(this)) { |
|
77 | // qDebug() << "DeclarativeTableModel::append:" << values; | |
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 |
|
78 | |||
71 | ////////////// XY model /////////////////////// |
|
79 | while (columnCount() < values.count()) | |
|
80 | insertColumn(columnCount()); | |||
72 |
|
81 | |||
73 | DeclarativeXyModel::DeclarativeXyModel(QObject *parent) : |
|
82 | insertRow(rowCount()); | |
74 | DeclarativeTableModel(parent) |
|
83 | ||
75 | { |
|
84 | QModelIndex beginIndex = QModelIndex(); | |
|
85 | QModelIndex endIndex = QModelIndex(); | |||
|
86 | for (int i(0); i < values.count(); i++) { | |||
|
87 | QModelIndex modelIndex = createIndex(rowCount() - 1, i); | |||
|
88 | if (i == 0) | |||
|
89 | beginIndex = modelIndex; | |||
|
90 | if (i == (values.count() - 1)) | |||
|
91 | endIndex = modelIndex; | |||
|
92 | setData(modelIndex, values.at(i)); | |||
|
93 | } | |||
|
94 | dataChanged(beginIndex, endIndex); | |||
76 | } |
|
95 | } | |
77 |
|
96 | |||
78 |
void Declarative |
|
97 | void DeclarativeTableModel::appendToModel(QObject *object) | |
79 | { |
|
98 | { | |
80 | // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y(); |
|
99 | if (qobject_cast<QBarSet *>(object)) { | |
81 | insertRow(rowCount()); |
|
100 | DeclarativeBarModel *model = qobject_cast<DeclarativeBarModel *>(this); | |
82 | QModelIndex xModelIndex = createIndex(rowCount() - 1, 0); |
|
101 | Q_ASSERT(model); | |
83 | QModelIndex yModelIndex = createIndex(rowCount() - 1, 1); |
|
102 | model->append(qobject_cast<QBarSet *>(object)); | |
84 | setData(xModelIndex, point->x()); |
|
103 | } else if (qobject_cast<QPieSlice *>(object)) { | |
85 | setData(yModelIndex, point->y()); |
|
104 | // TODO | |
86 | dataChanged(xModelIndex, yModelIndex); |
|
105 | } else if (qobject_cast<DeclarativeXyPoint *>(object)) { | |
|
106 | // TODO | |||
|
107 | appendPoint(qobject_cast<DeclarativeXyPoint *>(object)); | |||
|
108 | } else if (qobject_cast<DeclarativeTableModel *>(this)) { | |||
|
109 | append(qobject_cast<DeclarativeTableModelRow *>(object)->values()); | |||
|
110 | } | |||
87 | } |
|
111 | } | |
88 |
|
112 | |||
89 |
void Declarative |
|
113 | void DeclarativeTableModel::appendPoints(QVariantList points) | |
90 | { |
|
114 | { | |
91 | qreal x = 0.0; |
|
115 | qreal x = 0.0; | |
92 | for (int i(0); i < points.count(); i++) { |
|
116 | for (int i(0); i < points.count(); i++) { | |
@@ -97,7 +121,7 void DeclarativeXyModel::append(QVariantList points) | |||||
97 | DeclarativeXyPoint *point= new DeclarativeXyPoint(); |
|
121 | DeclarativeXyPoint *point= new DeclarativeXyPoint(); | |
98 | point->setX(x); |
|
122 | point->setX(x); | |
99 | point->setY(y); |
|
123 | point->setY(y); | |
100 | append(point); |
|
124 | appendPoint(point); | |
101 | } else { |
|
125 | } else { | |
102 | qWarning() << "Illegal y value"; |
|
126 | qWarning() << "Illegal y value"; | |
103 | } |
|
127 | } | |
@@ -111,44 +135,15 void DeclarativeXyModel::append(QVariantList points) | |||||
111 | } |
|
135 | } | |
112 | } |
|
136 | } | |
113 |
|
137 | |||
114 | ////////////// Pie model /////////////////////// |
|
138 | void DeclarativeTableModel::appendPoint(DeclarativeXyPoint* point) | |
115 |
|
||||
116 | DeclarativePieModel::DeclarativePieModel(QObject *parent) : |
|
|||
117 | DeclarativeTableModel(parent) |
|
|||
118 | { |
|
139 | { | |
119 | } |
|
140 | // qDebug() << "DeclarativeTableModel::append:" << point->x() << " " << point->y(); | |
120 |
|
||||
121 | void DeclarativePieModel::append(QPieSlice* slice) |
|
|||
122 | { |
|
|||
123 | // qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value(); |
|
|||
124 | insertRow(rowCount()); |
|
141 | insertRow(rowCount()); | |
125 |
|
142 | QModelIndex xModelIndex = createIndex(rowCount() - 1, 0); | ||
126 | setData(createIndex(rowCount() - 1, 0), slice->value()); |
|
143 | QModelIndex yModelIndex = createIndex(rowCount() - 1, 1); | |
127 | setData(createIndex(rowCount() - 1, 1), slice->label()); |
|
144 | setData(xModelIndex, point->x()); | |
128 | } |
|
145 | setData(yModelIndex, point->y()); | |
129 |
|
146 | dataChanged(xModelIndex, yModelIndex); | ||
130 | void DeclarativePieModel::append(QVariantList slices) |
|
|||
131 | { |
|
|||
132 | // qDebug() << "append:" << slices; |
|
|||
133 | QString label = ""; |
|
|||
134 | for (int i(0); i < slices.count(); i++) { |
|
|||
135 | if (i % 2) { |
|
|||
136 | bool ok(false); |
|
|||
137 | qreal value = slices.at(i).toReal(&ok); |
|
|||
138 | if (ok) { |
|
|||
139 | QPieSlice *slice = new QPieSlice(value, label); |
|
|||
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()); |
|
|||
145 | } else { |
|
|||
146 | qWarning() << "Illegal slice item"; |
|
|||
147 | } |
|
|||
148 | } else { |
|
|||
149 | label = slices.at(i).toString(); |
|
|||
150 | } |
|
|||
151 | } |
|
|||
152 | } |
|
147 | } | |
153 |
|
148 | |||
154 | ////////////// Bar model /////////////////////// |
|
149 | ////////////// Bar model /////////////////////// |
@@ -32,6 +32,19 | |||||
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
|
35 | class DeclarativeTableModelRow : public QObject | |||
|
36 | { | |||
|
37 | Q_OBJECT | |||
|
38 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |||
|
39 | ||||
|
40 | public: | |||
|
41 | explicit DeclarativeTableModelRow(QObject *parent = 0); | |||
|
42 | QVariantList values(); | |||
|
43 | void setValues(QVariantList values); | |||
|
44 | private: | |||
|
45 | QVariantList m_values; | |||
|
46 | }; | |||
|
47 | ||||
35 | class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus |
|
48 | class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus | |
36 | { |
|
49 | { | |
37 | Q_OBJECT |
|
50 | Q_OBJECT | |
@@ -48,36 +61,15 public: // from QDeclarativeParserStatus | |||||
48 | void componentComplete(); |
|
61 | void componentComplete(); | |
49 |
|
62 | |||
50 | public Q_SLOTS: |
|
63 | public Q_SLOTS: | |
|
64 | void append(QVariantList slices); | |||
|
65 | void appendPoints(QVariantList points); | |||
|
66 | void appendPoint(DeclarativeXyPoint* point); | |||
51 | static void appendModelChild(QDeclarativeListProperty<QObject> *list, |
|
67 | static void appendModelChild(QDeclarativeListProperty<QObject> *list, | |
52 | QObject *element); |
|
68 | QObject *element); | |
53 | private: |
|
69 | private: | |
54 | void appendToModel(QObject *object); |
|
70 | void appendToModel(QObject *object); | |
55 | }; |
|
71 | }; | |
56 |
|
72 | |||
57 | class DeclarativeXyModel : public DeclarativeTableModel |
|
|||
58 | { |
|
|||
59 | Q_OBJECT |
|
|||
60 |
|
||||
61 | public: |
|
|||
62 | explicit DeclarativeXyModel(QObject *parent = 0); |
|
|||
63 |
|
||||
64 | public Q_SLOTS: |
|
|||
65 | void append(DeclarativeXyPoint* point); |
|
|||
66 | void append(QVariantList points); |
|
|||
67 | }; |
|
|||
68 |
|
||||
69 | class DeclarativePieModel : public DeclarativeTableModel |
|
|||
70 | { |
|
|||
71 | Q_OBJECT |
|
|||
72 |
|
||||
73 | public: |
|
|||
74 | explicit DeclarativePieModel(QObject *parent = 0); |
|
|||
75 |
|
||||
76 | public Q_SLOTS: |
|
|||
77 | void append(QPieSlice* slice); |
|
|||
78 | void append(QVariantList slices); |
|
|||
79 | }; |
|
|||
80 |
|
||||
81 | class DeclarativeBarModel : public DeclarativeTableModel |
|
73 | class DeclarativeBarModel : public DeclarativeTableModel | |
82 | { |
|
74 | { | |
83 | Q_OBJECT |
|
75 | Q_OBJECT |
@@ -29,6 +29,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
29 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
29 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : | |
30 | QPieSeries(parent) |
|
30 | QPieSeries(parent) | |
31 | { |
|
31 | { | |
|
32 | // TODO: set default model on init? | |||
|
33 | // setModel(new DeclarativeTableModel()); | |||
|
34 | ||||
|
35 | // Set default mapper parameters to allow easy to use PieSeries api | |||
|
36 | QPieModelMapper *mapper = new QPieModelMapper(); | |||
|
37 | mapper->setMapLabels(0); | |||
|
38 | mapper->setMapValues(1); | |||
|
39 | mapper->setOrientation(Qt::Vertical); | |||
|
40 | mapper->setFirst(0); | |||
|
41 | mapper->setCount(-1); | |||
|
42 | setModelMapper(mapper); | |||
32 | } |
|
43 | } | |
33 |
|
44 | |||
34 | QPieSlice *DeclarativePieSeries::slice(int index) |
|
45 | QPieSlice *DeclarativePieSeries::slice(int index) | |
@@ -40,24 +51,19 QPieSlice *DeclarativePieSeries::slice(int index) | |||||
40 | return 0; |
|
51 | return 0; | |
41 | } |
|
52 | } | |
42 |
|
53 | |||
43 |
|
54 | void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) | ||
44 | void DeclarativePieSeries::setPieModel(DeclarativePieModel *model) |
|
|||
45 | { |
|
55 | { | |
46 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
56 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |
47 | if (m) { |
|
57 | if (m) { | |
48 | QPieSeries::setModel(m); |
|
58 | QPieSeries::setModel(m); | |
49 | QPieModelMapper *mapper = new QPieModelMapper; |
|
|||
50 | mapper->setMapValues(0); |
|
|||
51 | mapper->setMapLabels(1); |
|
|||
52 | QPieSeries::setModelMapper(mapper); |
|
|||
53 | } else { |
|
59 | } else { | |
54 | qWarning("DeclarativePieSeries: Illegal model"); |
|
60 | qWarning("DeclarativePieSeries: Illegal model"); | |
55 | } |
|
61 | } | |
56 | } |
|
62 | } | |
57 |
|
63 | |||
58 |
Declarative |
|
64 | DeclarativeTableModel *DeclarativePieSeries::pieModel() | |
59 | { |
|
65 | { | |
60 |
return qobject_cast<Declarative |
|
66 | return qobject_cast<DeclarativeTableModel *>(model()); | |
61 | } |
|
67 | } | |
62 |
|
68 | |||
63 | #include "moc_declarativepieseries.cpp" |
|
69 | #include "moc_declarativepieseries.cpp" |
@@ -36,7 +36,7 class QChart; | |||||
36 | class DeclarativePieSeries : public QPieSeries |
|
36 | class DeclarativePieSeries : public QPieSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 |
Q_PROPERTY(Declarative |
|
39 | Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel) | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 | explicit DeclarativePieSeries(QObject *parent = 0); |
|
42 | explicit DeclarativePieSeries(QObject *parent = 0); | |
@@ -44,11 +44,9 public: | |||||
44 | public: |
|
44 | public: | |
45 | Q_INVOKABLE QPieSlice *slice(int index); |
|
45 | Q_INVOKABLE QPieSlice *slice(int index); | |
46 |
|
46 | |||
47 | public Q_SLOTS: |
|
|||
48 |
|
||||
49 | public: |
|
47 | public: | |
50 |
void setPieModel(Declarative |
|
48 | void setPieModel(DeclarativeTableModel *model); | |
51 |
Declarative |
|
49 | DeclarativeTableModel *pieModel(); | |
52 | }; |
|
50 | }; | |
53 |
|
51 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -31,7 +31,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
31 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries |
|
31 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
Q_PROPERTY(Declarative |
|
34 | Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
@@ -20,7 +20,7 | |||||
20 |
|
20 | |||
21 | #include "declarativesplineseries.h" |
|
21 | #include "declarativesplineseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 |
#include |
|
23 | #include <QChart> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 |
@@ -31,7 +31,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
31 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries |
|
31 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
Q_PROPERTY(Declarative |
|
34 | Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
@@ -20,21 +20,30 | |||||
20 |
|
20 | |||
21 | //#include "DeclarativeXySeries.h" |
|
21 | //#include "DeclarativeXySeries.h" | |
22 | #include "declarativexyseries.h" |
|
22 | #include "declarativexyseries.h" | |
23 |
#include |
|
23 | #include <QXYSeries> | |
24 |
#include |
|
24 | #include <QXYModelMapper> | |
25 | #include "declarativechart.h" |
|
25 | #include "declarativechart.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | DeclarativeXySeries::DeclarativeXySeries() |
|
29 | DeclarativeXySeries::DeclarativeXySeries() | |
30 | { |
|
30 | { | |
|
31 | // All the inherited objects must be of type QXYSeries, so it is safe to cast | |||
|
32 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |||
|
33 | QXYModelMapper *mapper = new QXYModelMapper(series); | |||
|
34 | mapper->setMapX(0); | |||
|
35 | mapper->setMapY(1); | |||
|
36 | mapper->setFirst(0); | |||
|
37 | mapper->setCount(-1); | |||
|
38 | mapper->setOrientation(Qt::Vertical); | |||
|
39 | series->setModelMapper(mapper); | |||
31 | } |
|
40 | } | |
32 |
|
41 | |||
33 | DeclarativeXySeries::~DeclarativeXySeries() |
|
42 | DeclarativeXySeries::~DeclarativeXySeries() | |
34 | { |
|
43 | { | |
35 | } |
|
44 | } | |
36 |
|
45 | |||
37 |
bool DeclarativeXySeries::setDeclarativeModel(Declarative |
|
46 | bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model) | |
38 | { |
|
47 | { | |
39 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
48 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |
40 | bool value(false); |
|
49 | bool value(false); | |
@@ -42,22 +51,21 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model) | |||||
42 | // All the inherited objects must be of type QXYSeries, so it is safe to cast |
|
51 | // All the inherited objects must be of type QXYSeries, so it is safe to cast | |
43 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); |
|
52 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
44 | series->setModel(m); |
|
53 | series->setModel(m); | |
45 | QXYModelMapper *mapper = new QXYModelMapper; |
|
54 | // QXYModelMapper *mapper = new QXYModelMapper; | |
46 | mapper->setMapX(0); |
|
55 | // mapper->setMapX(0); | |
47 | mapper->setMapY(1); |
|
56 | // mapper->setMapY(1); | |
48 | series->setModelMapper(mapper); |
|
57 | // series->setModelMapper(mapper); | |
49 | } else { |
|
58 | } else { | |
50 | qWarning("DeclarativeXySeries: Illegal model"); |
|
59 | qWarning("DeclarativeXySeries: Illegal model"); | |
51 | } |
|
60 | } | |
52 | return value; |
|
61 | return value; | |
53 | } |
|
62 | } | |
54 |
|
63 | |||
55 |
Declarative |
|
64 | DeclarativeTableModel *DeclarativeXySeries::declarativeModel() | |
56 | { |
|
65 | { | |
57 | // All the inherited objects must be of type QXYSeries, so it is safe to cast |
|
66 | // All the inherited objects must be of type QXYSeries, so it is safe to cast | |
58 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); |
|
67 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
59 | Q_ASSERT(series); |
|
68 | return qobject_cast<DeclarativeTableModel *>(series->model()); | |
60 | return qobject_cast<DeclarativeXyModel *>(series->model()); |
|
|||
61 | } |
|
69 | } | |
62 |
|
70 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,8 +39,8 public: | |||||
39 | ~DeclarativeXySeries(); |
|
39 | ~DeclarativeXySeries(); | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 |
bool setDeclarativeModel(Declarative |
|
42 | bool setDeclarativeModel(DeclarativeTableModel *model); | |
43 |
Declarative |
|
43 | DeclarativeTableModel *declarativeModel(); | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
46 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -30,6 +30,9 | |||||
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 "declarativemodel.h" | |||
|
34 | #include <QPieModelMapper> | |||
|
35 | #include <QXYModelMapper> | |||
33 |
|
36 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
38 | |||
@@ -43,7 +46,7 public: | |||||
43 |
|
46 | |||
44 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
47 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
45 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
|
48 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", | |
46 |
QLatin1String("Trying to create uncreatable |
|
49 | QLatin1String("Trying to create uncreatable: Axis.")); | |
47 | //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory"); |
|
50 | //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory"); | |
48 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); |
|
51 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); | |
49 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
52 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
@@ -53,8 +56,15 public: | |||||
53 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
56 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
54 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
57 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
55 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
58 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
56 |
qmlRegisterType<Declarative |
|
59 | qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel"); | |
57 |
qmlRegisterType<Declarative |
|
60 | qmlRegisterType<DeclarativeTableModelRow>(uri, 1, 0, "ChartModelRow"); | |
|
61 | //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping"); | |||
|
62 | //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper"); | |||
|
63 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |||
|
64 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |||
|
65 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |||
|
66 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |||
|
67 | ||||
58 | qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel"); |
|
68 | qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel"); | |
59 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
69 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
60 | } |
|
70 | } |
@@ -94,11 +94,16 bool ChartTableModel::setData(const QModelIndex &index, const QVariant &value, i | |||||
94 | return false; |
|
94 | return false; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 |
void ChartTableModel::insert |
|
97 | void ChartTableModel::insertColumn(int column, const QModelIndex &parent) | |
98 | { |
|
98 | { | |
99 | Q_UNUSED(parent) |
|
99 | beginInsertColumns(parent, column, column); | |
|
100 | m_columnCount++; | |||
|
101 | endInsertColumns(); | |||
|
102 | } | |||
100 |
|
103 | |||
101 | beginInsertRows(QModelIndex(), row, row); |
|
104 | void ChartTableModel::insertRow(int row, const QModelIndex &parent) | |
|
105 | { | |||
|
106 | beginInsertRows(parent, row, row); | |||
102 | QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount); |
|
107 | QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount); | |
103 | m_data.insert(row, dataVec); |
|
108 | m_data.insert(row, dataVec); | |
104 | endInsertRows(); |
|
109 | endInsertRows(); |
@@ -42,6 +42,7 public: | |||||
42 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
42 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
43 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
|
43 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); | |
44 | Qt::ItemFlags flags ( const QModelIndex & index ) const; |
|
44 | Qt::ItemFlags flags ( const QModelIndex & index ) const; | |
|
45 | void insertColumn(int column, const QModelIndex &parent = QModelIndex()); | |||
45 | void insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
46 | void insertRow(int row, const QModelIndex &parent = QModelIndex()); | |
46 | /*Q_INVOKABLE*/ //bool removeRow(int row, const QModelIndex &parent = QModelIndex()); |
|
47 | /*Q_INVOKABLE*/ //bool removeRow(int row, const QModelIndex &parent = QModelIndex()); | |
47 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); |
|
48 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); |
@@ -9,9 +9,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
9 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject |
|
9 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject | |
10 | { |
|
10 | { | |
11 | Q_OBJECT |
|
11 | Q_OBJECT | |
|
12 | Q_PROPERTY(int mapValues READ mapValues WRITE setMapValues) | |||
|
13 | Q_PROPERTY(int mapLabels READ mapLabels WRITE setMapLabels) | |||
|
14 | Q_PROPERTY(int first READ first WRITE setFirst) | |||
|
15 | Q_PROPERTY(int count READ count WRITE setCount) | |||
|
16 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) | |||
|
17 | Q_ENUMS(Qt::Orientation) | |||
|
18 | ||||
12 | public: |
|
19 | public: | |
13 | explicit QPieModelMapper(QObject *parent = 0); |
|
20 | explicit QPieModelMapper(QObject *parent = 0); | |
14 |
|
21 | |||
15 | int first() const; |
|
22 | int first() const; | |
16 | void setFirst(int first); |
|
23 | void setFirst(int first); | |
17 |
|
24 |
@@ -36,6 +36,8 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries | |||||
36 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) |
|
36 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) | |
37 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) |
|
37 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) | |
38 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) |
|
38 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) | |
|
39 | Q_PROPERTY(int count READ count) | |||
|
40 | Q_PROPERTY(QPieModelMapper *modelMapper READ modelMapper) | |||
39 |
|
41 | |||
40 | public: |
|
42 | public: | |
41 | explicit QPieSeries(QObject *parent = 0); |
|
43 | explicit QPieSeries(QObject *parent = 0); |
@@ -3,13 +3,18 | |||||
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <Qt> |
|
|||
7 |
|
6 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
8 | |||
10 | class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject |
|
9 | class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject | |
11 | { |
|
10 | { | |
12 | Q_OBJECT |
|
11 | Q_OBJECT | |
|
12 | Q_PROPERTY(int mapX READ mapX WRITE setMapX) | |||
|
13 | Q_PROPERTY(int mapY READ mapY WRITE setMapY) | |||
|
14 | Q_PROPERTY(int first READ first WRITE setFirst) | |||
|
15 | Q_PROPERTY(int count READ count WRITE setCount) | |||
|
16 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) | |||
|
17 | Q_ENUMS(Qt::Orientation) | |||
13 |
|
18 | |||
14 | public: |
|
19 | public: | |
15 | explicit QXYModelMapper(QObject *parent = 0); |
|
20 | explicit QXYModelMapper(QObject *parent = 0); |
@@ -36,6 +36,8 class QXYModelMapper; | |||||
36 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries |
|
36 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
|
39 | Q_PROPERTY(QXYModelMapper *modelMapper READ modelMapper) | |||
|
40 | ||||
39 | protected: |
|
41 | protected: | |
40 | explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0); |
|
42 | explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0); | |
41 | ~QXYSeries(); |
|
43 | ~QXYSeries(); |
General Comments 0
You need to be logged in to leave comments.
Login now