@@ -1,130 +1,130 | |||||
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 | axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005", |
|
31 | axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005", | |
32 | "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"] |
|
32 | "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"] | |
33 |
|
33 | |||
34 | AreaSeries { |
|
34 | AreaSeries { | |
35 | name: "Russian" |
|
35 | name: "Russian" | |
36 | upperSeries: LineSeries { |
|
36 | upperSeries: LineSeries { | |
37 | XyPoint { x: 0; y: 1 } |
|
37 | XyPoint { x: 0; y: 1 } | |
38 | XyPoint { x: 1; y: 1 } |
|
38 | XyPoint { x: 1; y: 1 } | |
39 | XyPoint { x: 2; y: 1 } |
|
39 | XyPoint { x: 2; y: 1 } | |
40 | XyPoint { x: 3; y: 1 } |
|
40 | XyPoint { x: 3; y: 1 } | |
41 | XyPoint { x: 4; y: 1 } |
|
41 | XyPoint { x: 4; y: 1 } | |
42 | XyPoint { x: 5; y: 0 } |
|
42 | XyPoint { x: 5; y: 0 } | |
43 | XyPoint { x: 6; y: 1 } |
|
43 | XyPoint { x: 6; y: 1 } | |
44 | XyPoint { x: 7; y: 1 } |
|
44 | XyPoint { x: 7; y: 1 } | |
45 | XyPoint { x: 8; y: 4 } |
|
45 | XyPoint { x: 8; y: 4 } | |
46 | XyPoint { x: 9; y: 3 } |
|
46 | XyPoint { x: 9; y: 3 } | |
47 | XyPoint { x: 10; y: 2 } |
|
47 | XyPoint { x: 10; y: 2 } | |
48 | XyPoint { x: 11; y: 1 } |
|
48 | XyPoint { x: 11; y: 1 } | |
49 | } |
|
49 | } | |
50 | lowerSeries: LineSeries { |
|
50 | lowerSeries: LineSeries { | |
51 | XyPoint { x: 0; y: 0 } |
|
51 | XyPoint { x: 0; y: 0 } | |
52 | XyPoint { x: 1; y: 0 } |
|
52 | XyPoint { x: 1; y: 0 } | |
53 | XyPoint { x: 2; y: 0 } |
|
53 | XyPoint { x: 2; y: 0 } | |
54 | XyPoint { x: 3; y: 0 } |
|
54 | XyPoint { x: 3; y: 0 } | |
55 | XyPoint { x: 4; y: 0 } |
|
55 | XyPoint { x: 4; y: 0 } | |
56 | XyPoint { x: 5; y: 0 } |
|
56 | XyPoint { x: 5; y: 0 } | |
57 | XyPoint { x: 6; y: 0 } |
|
57 | XyPoint { x: 6; y: 0 } | |
58 | XyPoint { x: 7; y: 0 } |
|
58 | XyPoint { x: 7; y: 0 } | |
59 | XyPoint { x: 8; y: 0 } |
|
59 | XyPoint { x: 8; y: 0 } | |
60 | XyPoint { x: 9; y: 0 } |
|
60 | XyPoint { x: 9; y: 0 } | |
61 | XyPoint { x: 10; y: 0 } |
|
61 | XyPoint { x: 10; y: 0 } | |
62 | XyPoint { x: 11; y: 0 } |
|
62 | XyPoint { x: 11; y: 0 } | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | AreaSeries { |
|
66 | AreaSeries { | |
67 | name: "Swedish" |
|
67 | name: "Swedish" | |
68 | upperSeries: LineSeries { |
|
68 | upperSeries: LineSeries { | |
69 | XyPoint { x: 0; y: 1 } |
|
69 | XyPoint { x: 0; y: 1 } | |
70 | XyPoint { x: 1; y: 1 } |
|
70 | XyPoint { x: 1; y: 1 } | |
71 | XyPoint { x: 2; y: 3 } |
|
71 | XyPoint { x: 2; y: 3 } | |
72 | XyPoint { x: 3; y: 3 } |
|
72 | XyPoint { x: 3; y: 3 } | |
73 | XyPoint { x: 4; y: 2 } |
|
73 | XyPoint { x: 4; y: 2 } | |
74 | XyPoint { x: 5; y: 0 } |
|
74 | XyPoint { x: 5; y: 0 } | |
75 | XyPoint { x: 6; y: 2 } |
|
75 | XyPoint { x: 6; y: 2 } | |
76 | XyPoint { x: 7; y: 1 } |
|
76 | XyPoint { x: 7; y: 1 } | |
77 | XyPoint { x: 8; y: 2 } |
|
77 | XyPoint { x: 8; y: 2 } | |
78 | XyPoint { x: 9; y: 1 } |
|
78 | XyPoint { x: 9; y: 1 } | |
79 | XyPoint { x: 10; y: 3 } |
|
79 | XyPoint { x: 10; y: 3 } | |
80 | XyPoint { x: 11; y: 3 } |
|
80 | XyPoint { x: 11; y: 3 } | |
81 | } |
|
81 | } | |
82 | lowerSeries: LineSeries { |
|
82 | lowerSeries: LineSeries { | |
83 | XyPoint { x: 0; y: 0 } |
|
83 | XyPoint { x: 0; y: 0 } | |
84 | XyPoint { x: 1; y: 0 } |
|
84 | XyPoint { x: 1; y: 0 } | |
85 | XyPoint { x: 2; y: 0 } |
|
85 | XyPoint { x: 2; y: 0 } | |
86 | XyPoint { x: 3; y: 0 } |
|
86 | XyPoint { x: 3; y: 0 } | |
87 | XyPoint { x: 4; y: 0 } |
|
87 | XyPoint { x: 4; y: 0 } | |
88 | XyPoint { x: 5; y: 0 } |
|
88 | XyPoint { x: 5; y: 0 } | |
89 | XyPoint { x: 6; y: 0 } |
|
89 | XyPoint { x: 6; y: 0 } | |
90 | XyPoint { x: 7; y: 0 } |
|
90 | XyPoint { x: 7; y: 0 } | |
91 | XyPoint { x: 8; y: 0 } |
|
91 | XyPoint { x: 8; y: 0 } | |
92 | XyPoint { x: 9; y: 0 } |
|
92 | XyPoint { x: 9; y: 0 } | |
93 | XyPoint { x: 10; y: 0 } |
|
93 | XyPoint { x: 10; y: 0 } | |
94 | XyPoint { x: 11; y: 0 } |
|
94 | XyPoint { x: 11; y: 0 } | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | AreaSeries { |
|
98 | AreaSeries { | |
99 |
name: " |
|
99 | name: "Finnish" | |
100 | upperSeries: LineSeries { |
|
100 | upperSeries: LineSeries { | |
101 | XyPoint { x: 0; y: 0 } |
|
101 | XyPoint { x: 0; y: 0 } | |
102 | XyPoint { x: 1; y: 0 } |
|
102 | XyPoint { x: 1; y: 0 } | |
103 | XyPoint { x: 2; y: 0 } |
|
103 | XyPoint { x: 2; y: 0 } | |
104 | XyPoint { x: 3; y: 0 } |
|
104 | XyPoint { x: 3; y: 0 } | |
105 | XyPoint { x: 4; y: 0 } |
|
105 | XyPoint { x: 4; y: 0 } | |
106 | XyPoint { x: 5; y: 0 } |
|
106 | XyPoint { x: 5; y: 0 } | |
107 | XyPoint { x: 6; y: 1 } |
|
107 | XyPoint { x: 6; y: 1 } | |
108 | XyPoint { x: 7; y: 0 } |
|
108 | XyPoint { x: 7; y: 0 } | |
109 | XyPoint { x: 8; y: 0 } |
|
109 | XyPoint { x: 8; y: 0 } | |
110 | XyPoint { x: 9; y: 0 } |
|
110 | XyPoint { x: 9; y: 0 } | |
111 | XyPoint { x: 10; y: 0 } |
|
111 | XyPoint { x: 10; y: 0 } | |
112 | XyPoint { x: 11; y: 1 } |
|
112 | XyPoint { x: 11; y: 1 } | |
113 | } |
|
113 | } | |
114 | lowerSeries: LineSeries { |
|
114 | lowerSeries: LineSeries { | |
115 | XyPoint { x: 0; y: 0 } |
|
115 | XyPoint { x: 0; y: 0 } | |
116 | XyPoint { x: 1; y: 0 } |
|
116 | XyPoint { x: 1; y: 0 } | |
117 | XyPoint { x: 2; y: 0 } |
|
117 | XyPoint { x: 2; y: 0 } | |
118 | XyPoint { x: 3; y: 0 } |
|
118 | XyPoint { x: 3; y: 0 } | |
119 | XyPoint { x: 4; y: 0 } |
|
119 | XyPoint { x: 4; y: 0 } | |
120 | XyPoint { x: 5; y: 0 } |
|
120 | XyPoint { x: 5; y: 0 } | |
121 | XyPoint { x: 6; y: 0 } |
|
121 | XyPoint { x: 6; y: 0 } | |
122 | XyPoint { x: 7; y: 0 } |
|
122 | XyPoint { x: 7; y: 0 } | |
123 | XyPoint { x: 8; y: 0 } |
|
123 | XyPoint { x: 8; y: 0 } | |
124 | XyPoint { x: 9; y: 0 } |
|
124 | XyPoint { x: 9; y: 0 } | |
125 | XyPoint { x: 10; y: 0 } |
|
125 | XyPoint { x: 10; y: 0 } | |
126 | XyPoint { x: 11; y: 0 } |
|
126 | XyPoint { x: 11; y: 0 } | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 | } |
|
129 | } | |
130 | } |
|
130 | } |
@@ -1,43 +1,43 | |||||
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 | // TODO: labels defined by x-axis, not by bar series |
|
32 | // TODO: labels defined by x-axis, not by bar series | |
33 |
|
|
33 | axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] | |
34 |
|
|
34 | axisX.max: 10 | |
35 |
|
35 | |||
36 | BarSeries { |
|
36 | GroupedBarSeries { | |
37 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] |
|
37 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
38 | BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] } |
|
38 | BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] } | |
39 | BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
39 | BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
40 | BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
40 | BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] } | |
41 | } |
|
41 | } | |
42 | } |
|
42 | } | |
43 | } |
|
43 | } |
@@ -1,105 +1,147 | |||||
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 <QBarSet> |
|
23 | #include <QBarSet> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
27 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | |
28 | QBarSet("", parent) |
|
28 | QBarSet("", parent) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | QVariantList DeclarativeBarSet::values() |
|
32 | QVariantList DeclarativeBarSet::values() | |
33 | { |
|
33 | { | |
34 | QVariantList values; |
|
34 | QVariantList values; | |
35 | for (int i(0); i < count(); i++) |
|
35 | for (int i(0); i < count(); i++) | |
36 | values.append(QVariant(at(i))); |
|
36 | values.append(QVariant(at(i))); | |
37 | return values; |
|
37 | return values; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void DeclarativeBarSet::setValues(QVariantList values) |
|
40 | void DeclarativeBarSet::setValues(QVariantList values) | |
41 | { |
|
41 | { | |
42 | while (count()) |
|
42 | while (count()) | |
43 | remove(count() - 1); |
|
43 | remove(count() - 1); | |
44 |
|
44 | |||
45 | for (int i(0); i < values.count(); i++) { |
|
45 | for (int i(0); i < values.count(); i++) { | |
46 | if (values.at(i).canConvert(QVariant::Double)) |
|
46 | if (values.at(i).canConvert(QVariant::Double)) | |
47 | append(values[i].toDouble()); |
|
47 | append(values[i].toDouble()); | |
48 | } |
|
48 | } | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
51 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
52 | QGroupedBarSeries(parent) |
|
52 | QGroupedBarSeries(parent) | |
53 | { |
|
53 | { | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void DeclarativeBarSeries::classBegin() |
|
56 | void DeclarativeBarSeries::classBegin() | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void DeclarativeBarSeries::componentComplete() |
|
60 | void DeclarativeBarSeries::componentComplete() | |
61 | { |
|
61 | { | |
62 | foreach(QObject *child, children()) { |
|
62 | foreach(QObject *child, children()) { | |
63 | if (qobject_cast<QBarSet *>(child)) { |
|
63 | if (qobject_cast<QBarSet *>(child)) { | |
64 | QBarSeries::append(qobject_cast<QBarSet *>(child)); |
|
64 | QBarSeries::append(qobject_cast<QBarSet *>(child)); | |
65 | } |
|
65 | } | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | QDeclarativeListProperty<DeclarativeBarSet> DeclarativeBarSeries::initialBarSets() |
|
69 | QDeclarativeListProperty<DeclarativeBarSet> DeclarativeBarSeries::initialBarSets() | |
70 | { |
|
70 | { | |
71 | return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeBarSeries::appendInitialBarSets); |
|
71 | return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeBarSeries::appendInitialBarSets); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model) |
|
74 | bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model) | |
75 | { |
|
75 | { | |
76 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
76 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |
77 | bool value(false); |
|
77 | bool value(false); | |
78 | if (m) { |
|
78 | if (m) { | |
79 | setModel(m); |
|
79 | setModel(m); | |
80 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
80 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
81 | // setModelMapping(0, 1, 1, Qt::Vertical); |
|
81 | // setModelMapping(0, 1, 1, Qt::Vertical); | |
82 | } else { |
|
82 | } else { | |
83 | qWarning("DeclarativeBarSeries: Illegal model"); |
|
83 | qWarning("DeclarativeBarSeries: Illegal model"); | |
84 | } |
|
84 | } | |
85 | return value; |
|
85 | return value; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() |
|
88 | DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() | |
89 | { |
|
89 | { | |
90 | return qobject_cast<DeclarativeTableModel *>(model()); |
|
90 | return qobject_cast<DeclarativeTableModel *>(model()); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
|
93 | DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : | |
|
94 | QGroupedBarSeries(parent) | |||
|
95 | { | |||
|
96 | } | |||
|
97 | ||||
|
98 | void DeclarativeGroupedBarSeries::classBegin() | |||
|
99 | { | |||
|
100 | } | |||
|
101 | ||||
|
102 | void DeclarativeGroupedBarSeries::componentComplete() | |||
|
103 | { | |||
|
104 | foreach(QObject *child, children()) { | |||
|
105 | if (qobject_cast<QBarSet *>(child)) { | |||
|
106 | QBarSeries::append(qobject_cast<QBarSet *>(child)); | |||
|
107 | } | |||
|
108 | } | |||
|
109 | } | |||
|
110 | ||||
|
111 | QDeclarativeListProperty<DeclarativeBarSet> DeclarativeGroupedBarSeries::initialBarSets() | |||
|
112 | { | |||
|
113 | return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets); | |||
|
114 | } | |||
|
115 | ||||
|
116 | bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *model) | |||
|
117 | { | |||
|
118 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |||
|
119 | bool value(false); | |||
|
120 | if (m) { | |||
|
121 | setModel(m); | |||
|
122 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |||
|
123 | // setModelMapping(0, 1, 1, Qt::Vertical); | |||
|
124 | } else { | |||
|
125 | qWarning("DeclarativeGroupedBarSeries: Illegal model"); | |||
|
126 | } | |||
|
127 | return value; | |||
|
128 | } | |||
|
129 | ||||
|
130 | DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel() | |||
|
131 | { | |||
|
132 | return qobject_cast<DeclarativeTableModel *>(model()); | |||
|
133 | } | |||
|
134 | ||||
|
135 | void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories) | |||
94 | { |
|
136 | { | |
95 | setCategories(categories); |
|
137 | setCategories(categories); | |
96 | } |
|
138 | } | |
97 |
|
139 | |||
98 | QStringList DeclarativeBarSeries::barCategories() |
|
140 | QStringList DeclarativeGroupedBarSeries::barCategories() | |
99 | { |
|
141 | { | |
100 | return categories(); |
|
142 | return categories(); | |
101 | } |
|
143 | } | |
102 |
|
144 | |||
103 | #include "moc_declarativebarseries.cpp" |
|
145 | #include "moc_declarativebarseries.cpp" | |
104 |
|
146 | |||
105 | QTCOMMERCIALCHART_END_NAMESPACE |
|
147 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,75 +1,99 | |||||
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 "declarativemodel.h" | |
26 | #include <QDeclarativeItem> |
|
26 | #include <QDeclarativeItem> | |
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 | #include <QGroupedBarSeries> |
|
28 | #include <QGroupedBarSeries> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QChart; |
|
32 | class QChart; | |
33 |
|
33 | |||
34 | class DeclarativeBarSet : public QBarSet |
|
34 | class DeclarativeBarSet : public QBarSet | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
37 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |
38 | Q_PROPERTY(QString name READ name WRITE setName) |
|
38 | Q_PROPERTY(QString name READ name WRITE setName) | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 | explicit DeclarativeBarSet(QObject *parent = 0); |
|
41 | explicit DeclarativeBarSet(QObject *parent = 0); | |
42 | QVariantList values(); |
|
42 | QVariantList values(); | |
43 | void setValues(QVariantList values); |
|
43 | void setValues(QVariantList values); | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | class DeclarativeBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus |
|
46 | class DeclarativeBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 | Q_INTERFACES(QDeclarativeParserStatus) |
|
49 | Q_INTERFACES(QDeclarativeParserStatus) | |
50 | Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) |
|
50 | Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) | |
51 | Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) |
|
|||
52 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets) |
|
51 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets) | |
53 | Q_CLASSINFO("DefaultProperty", "initialBarSets") |
|
52 | Q_CLASSINFO("DefaultProperty", "initialBarSets") | |
54 |
|
53 | |||
55 | public: |
|
54 | public: | |
56 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); |
|
55 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); | |
57 | QDeclarativeListProperty<DeclarativeBarSet> initialBarSets(); |
|
56 | QDeclarativeListProperty<DeclarativeBarSet> initialBarSets(); | |
58 |
|
57 | |||
59 | public: // from QDeclarativeParserStatus |
|
58 | public: // from QDeclarativeParserStatus | |
60 | void classBegin(); |
|
59 | void classBegin(); | |
61 | void componentComplete(); |
|
60 | void componentComplete(); | |
62 |
|
61 | |||
63 | public: |
|
62 | public: | |
64 | bool setDeclarativeModel(DeclarativeTableModel *model); |
|
63 | bool setDeclarativeModel(DeclarativeTableModel *model); | |
65 | DeclarativeTableModel *declarativeModel(); |
|
64 | DeclarativeTableModel *declarativeModel(); | |
|
65 | ||||
|
66 | public Q_SLOTS: | |||
|
67 | static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> */*list*/, DeclarativeBarSet */*element*/) {} | |||
|
68 | }; | |||
|
69 | ||||
|
70 | class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus | |||
|
71 | { | |||
|
72 | Q_OBJECT | |||
|
73 | Q_INTERFACES(QDeclarativeParserStatus) | |||
|
74 | Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) | |||
|
75 | Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) | |||
|
76 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets) | |||
|
77 | Q_CLASSINFO("DefaultProperty", "initialBarSets") | |||
|
78 | ||||
|
79 | public: | |||
|
80 | explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); | |||
|
81 | QDeclarativeListProperty<DeclarativeBarSet> initialBarSets(); | |||
|
82 | ||||
|
83 | public: // from QDeclarativeParserStatus | |||
|
84 | void classBegin(); | |||
|
85 | void componentComplete(); | |||
|
86 | ||||
|
87 | public: | |||
66 | void setBarCategories(QStringList categories); |
|
88 | void setBarCategories(QStringList categories); | |
67 | QStringList barCategories(); |
|
89 | QStringList barCategories(); | |
|
90 | bool setDeclarativeModel(DeclarativeTableModel *model); | |||
|
91 | DeclarativeTableModel *declarativeModel(); | |||
68 |
|
92 | |||
69 | public Q_SLOTS: |
|
93 | public Q_SLOTS: | |
70 | static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> */*list*/, DeclarativeBarSet */*element*/) {} |
|
94 | static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> */*list*/, DeclarativeBarSet */*element*/) {} | |
71 | }; |
|
95 | }; | |
72 |
|
96 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
98 | |||
75 | #endif // DECLARATIVEBARSERIES_H |
|
99 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,50 +1,48 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativelineseries.h" |
|
21 | #include "declarativelineseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : |
|
28 | DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : | |
29 | QLineSeries(parent) |
|
29 | QLineSeries(parent) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren() |
|
33 | QDeclarativeListProperty<QObject> DeclarativeLineSeries::declarativeChildren() | |
34 | { |
|
34 | { | |
35 | return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren); |
|
35 | return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element) |
|
38 | void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element) | |
39 | { |
|
39 | { | |
40 | QXYSeries *series = qobject_cast<QXYSeries*>(list->object); |
|
40 | QXYSeries *series = qobject_cast<QXYSeries*>(list->object); | |
41 | DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element); |
|
41 | DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element); | |
42 |
if (series && point) |
|
42 | if (series && point) | |
43 | qDebug() << "DeclarativeScatterSeries::appendDeclarativeChildren:" << *point; |
|
|||
44 | series->append(*point); |
|
43 | series->append(*point); | |
45 | } |
|
44 | } | |
46 | } |
|
|||
47 |
|
45 | |||
48 | #include "moc_declarativelineseries.cpp" |
|
46 | #include "moc_declarativelineseries.cpp" | |
49 |
|
47 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,48 +1,47 | |||||
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 "declarativesplineseries.h" |
|
21 | #include "declarativesplineseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include <QChart> |
|
23 | #include <QChart> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : |
|
27 | DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : | |
28 | QSplineSeries(parent) |
|
28 | QSplineSeries(parent) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren() |
|
32 | QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren() | |
33 | { |
|
33 | { | |
34 | return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren); |
|
34 | return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element) |
|
37 | void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element) | |
38 | { |
|
38 | { | |
39 | QXYSeries *series = qobject_cast<QXYSeries*>(list->object); |
|
39 | QXYSeries *series = qobject_cast<QXYSeries*>(list->object); | |
40 | DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element); |
|
40 | DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element); | |
41 |
if (series && point) |
|
41 | if (series && point) | |
42 | qDebug() << "DeclarativeScatterSeries::appendDeclarativeChildren:" << *point; |
|
|||
43 | series->append(*point); |
|
42 | series->append(*point); | |
44 | } |
|
43 | } | |
45 | } |
|
44 | ||
46 | #include "moc_declarativesplineseries.cpp" |
|
45 | #include "moc_declarativesplineseries.cpp" | |
47 |
|
46 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,75 | |||||
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 "declarativemodel.h" |
|
33 | #include "declarativemodel.h" | |
34 | #include <QPieModelMapper> |
|
34 | #include <QPieModelMapper> | |
35 | #include <QXYModelMapper> |
|
35 | #include <QXYModelMapper> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
39 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 | public: |
|
42 | public: | |
43 | virtual void registerTypes(const char *uri) |
|
43 | virtual void registerTypes(const char *uri) | |
44 | { |
|
44 | { | |
45 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
45 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
46 |
|
46 | |||
47 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
47 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
48 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
|
48 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", | |
49 | QLatin1String("Trying to create uncreatable: Axis.")); |
|
49 | QLatin1String("Trying to create uncreatable: Axis.")); | |
50 | //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory"); |
|
|||
51 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); |
|
50 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); | |
52 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
51 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
53 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
52 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
54 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
53 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
55 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
54 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
56 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
55 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
|
56 | qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries"); | |||
57 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
57 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
58 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
58 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
59 | qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel"); |
|
59 | qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel"); | |
60 | qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement"); |
|
60 | qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement"); | |
61 | //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping"); |
|
|||
62 | //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper"); |
|
|||
63 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
61 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
64 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
62 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
65 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
63 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
66 |
QLatin1String("Trying to create uncreatable: |
|
64 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
67 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
65 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
68 | } |
|
66 | } | |
69 | }; |
|
67 | }; | |
70 |
|
68 | |||
71 | #include "plugin.moc" |
|
69 | #include "plugin.moc" | |
72 |
|
70 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
72 | |||
75 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
73 | QTCOMMERCIALCHART_USE_NAMESPACE | |
76 |
|
74 | |||
77 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
75 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,400 +1,397 | |||||
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 "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qchartview.h" |
|
24 | #include "qchartview.h" | |
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qaxis.h" |
|
26 | #include "qaxis.h" | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 |
|
28 | |||
29 | //series |
|
29 | //series | |
30 | #include "qbarset.h" |
|
30 | #include "qbarset.h" | |
31 | #include "qbarseries.h" |
|
31 | #include "qbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
32 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
33 | #include "qpercentbarseries.h" | |
34 | #include "qlineseries.h" |
|
34 | #include "qlineseries.h" | |
35 | #include "qareaseries.h" |
|
35 | #include "qareaseries.h" | |
36 | #include "qscatterseries.h" |
|
36 | #include "qscatterseries.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "qsplineseries.h" |
|
39 | #include "qsplineseries.h" | |
40 |
|
40 | |||
41 | //items |
|
41 | //items | |
42 | #include "chartaxis_p.h" |
|
42 | #include "chartaxis_p.h" | |
43 | #include "barchartitem_p.h" |
|
43 | #include "barchartitem_p.h" | |
44 | #include "stackedbarchartitem_p.h" |
|
44 | #include "stackedbarchartitem_p.h" | |
45 | #include "percentbarchartitem_p.h" |
|
45 | #include "percentbarchartitem_p.h" | |
46 | #include "linechartitem_p.h" |
|
46 | #include "linechartitem_p.h" | |
47 | #include "areachartitem_p.h" |
|
47 | #include "areachartitem_p.h" | |
48 | #include "scatterchartitem_p.h" |
|
48 | #include "scatterchartitem_p.h" | |
49 | #include "piechartitem_p.h" |
|
49 | #include "piechartitem_p.h" | |
50 | #include "splinechartitem_p.h" |
|
50 | #include "splinechartitem_p.h" | |
51 |
|
51 | |||
52 | //themes |
|
52 | //themes | |
53 | #include "chartthemesystem_p.h" |
|
53 | #include "chartthemesystem_p.h" | |
54 | #include "chartthemelight_p.h" |
|
54 | #include "chartthemelight_p.h" | |
55 | #include "chartthemebluecerulean_p.h" |
|
55 | #include "chartthemebluecerulean_p.h" | |
56 | #include "chartthemedark_p.h" |
|
56 | #include "chartthemedark_p.h" | |
57 | #include "chartthemebrownsand_p.h" |
|
57 | #include "chartthemebrownsand_p.h" | |
58 | #include "chartthemebluencs_p.h" |
|
58 | #include "chartthemebluencs_p.h" | |
59 | #include "chartthemehighcontrast_p.h" |
|
59 | #include "chartthemehighcontrast_p.h" | |
60 | #include "chartthemeblueicy_p.h" |
|
60 | #include "chartthemeblueicy_p.h" | |
61 |
|
61 | |||
62 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
62 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
63 |
|
63 | |||
64 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
64 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
65 | m_masterFont(QFont("arial", 14)), |
|
65 | m_masterFont(QFont("arial", 14)), | |
66 | m_labelFont(QFont("arial", 10)), |
|
66 | m_labelFont(QFont("arial", 10)), | |
67 | m_titleBrush(QColor(QRgb(0x000000))), |
|
67 | m_titleBrush(QColor(QRgb(0x000000))), | |
68 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
68 | m_axisLinePen(QPen(QRgb(0x000000))), | |
69 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
69 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
70 | m_backgroundShadesPen(Qt::NoPen), |
|
70 | m_backgroundShadesPen(Qt::NoPen), | |
71 | m_backgroundShadesBrush(Qt::NoBrush), |
|
71 | m_backgroundShadesBrush(Qt::NoBrush), | |
72 | m_backgroundShades(BackgroundShadesNone), |
|
72 | m_backgroundShades(BackgroundShadesNone), | |
73 | m_backgroundDropShadowEnabled(false), |
|
73 | m_backgroundDropShadowEnabled(false), | |
74 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
74 | m_gridLinePen(QPen(QRgb(0x000000))), | |
75 | m_force(false) |
|
75 | m_force(false) | |
76 | { |
|
76 | { | |
77 | m_id = id; |
|
77 | m_id = id; | |
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
83 | { |
|
83 | { | |
84 | switch(theme) { |
|
84 | switch(theme) { | |
85 | case QChart::ChartThemeLight: |
|
85 | case QChart::ChartThemeLight: | |
86 | return new ChartThemeLight(); |
|
86 | return new ChartThemeLight(); | |
87 | case QChart::ChartThemeBlueCerulean: |
|
87 | case QChart::ChartThemeBlueCerulean: | |
88 | return new ChartThemeBlueCerulean(); |
|
88 | return new ChartThemeBlueCerulean(); | |
89 | case QChart::ChartThemeDark: |
|
89 | case QChart::ChartThemeDark: | |
90 | return new ChartThemeDark(); |
|
90 | return new ChartThemeDark(); | |
91 | case QChart::ChartThemeBrownSand: |
|
91 | case QChart::ChartThemeBrownSand: | |
92 | return new ChartThemeBrownSand(); |
|
92 | return new ChartThemeBrownSand(); | |
93 | case QChart::ChartThemeBlueNcs: |
|
93 | case QChart::ChartThemeBlueNcs: | |
94 | return new ChartThemeBlueNcs(); |
|
94 | return new ChartThemeBlueNcs(); | |
95 | case QChart::ChartThemeHighContrast: |
|
95 | case QChart::ChartThemeHighContrast: | |
96 | return new ChartThemeHighContrast(); |
|
96 | return new ChartThemeHighContrast(); | |
97 | case QChart::ChartThemeBlueIcy: |
|
97 | case QChart::ChartThemeBlueIcy: | |
98 | return new ChartThemeBlueIcy(); |
|
98 | return new ChartThemeBlueIcy(); | |
99 | default: |
|
99 | default: | |
100 | return new ChartThemeSystem(); |
|
100 | return new ChartThemeSystem(); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartTheme::decorate(QChart *chart) |
|
104 | void ChartTheme::decorate(QChart *chart) | |
105 | { |
|
105 | { | |
106 | QBrush brush; |
|
106 | QBrush brush; | |
107 |
|
107 | |||
108 | if(brush == chart->backgroundBrush() || m_force) |
|
108 | if(brush == chart->backgroundBrush() || m_force) | |
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
110 | chart->setTitleFont(m_masterFont); |
|
110 | chart->setTitleFont(m_masterFont); | |
111 | chart->setTitleBrush(m_titleBrush); |
|
111 | chart->setTitleBrush(m_titleBrush); | |
112 | chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
112 | chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void ChartTheme::decorate(QLegend *legend) |
|
115 | void ChartTheme::decorate(QLegend *legend) | |
116 | { |
|
116 | { | |
117 | QPen pen; |
|
117 | QPen pen; | |
118 | QBrush brush; |
|
118 | QBrush brush; | |
119 |
|
119 | |||
120 | if (pen == legend->pen() || m_force){ |
|
120 | if (pen == legend->pen() || m_force){ | |
121 | legend->setPen(Qt::NoPen); |
|
121 | legend->setPen(Qt::NoPen); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | if (brush == legend->brush() || m_force) { |
|
124 | if (brush == legend->brush() || m_force) { | |
125 | legend->setBrush(m_chartBackgroundGradient); |
|
125 | legend->setBrush(m_chartBackgroundGradient); | |
126 | } |
|
126 | } | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
129 | void ChartTheme::decorate(QAreaSeries *series, int index) | |
130 | { |
|
130 | { | |
131 | QPen pen; |
|
131 | QPen pen; | |
132 | QBrush brush; |
|
132 | QBrush brush; | |
133 |
|
133 | |||
134 | if (pen == series->pen() || m_force){ |
|
134 | if (pen == series->pen() || m_force){ | |
135 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
135 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
136 | pen.setWidthF(2); |
|
136 | pen.setWidthF(2); | |
137 | series->setPen(pen); |
|
137 | series->setPen(pen); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | if (brush == series->brush() || m_force) { |
|
140 | if (brush == series->brush() || m_force) { | |
141 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
141 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
142 | series->setBrush(brush); |
|
142 | series->setBrush(brush); | |
143 | } |
|
143 | } | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | void ChartTheme::decorate(QLineSeries *series,int index) |
|
147 | void ChartTheme::decorate(QLineSeries *series,int index) | |
148 | { |
|
148 | { | |
149 | QPen pen; |
|
149 | QPen pen; | |
150 | if(pen == series->pen() || m_force ){ |
|
150 | if(pen == series->pen() || m_force ){ | |
151 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
151 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
152 | pen.setWidthF(2); |
|
152 | pen.setWidthF(2); | |
153 | series->setPen(pen); |
|
153 | series->setPen(pen); | |
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void ChartTheme::decorate(QBarSeries *series, int index) |
|
157 | void ChartTheme::decorate(QBarSeries *series, int index) | |
158 | { |
|
158 | { | |
159 | QBrush brush; |
|
159 | QBrush brush; | |
160 | QPen pen; |
|
160 | QPen pen; | |
161 | QList<QBarSet *> sets = series->barSets(); |
|
161 | QList<QBarSet *> sets = series->barSets(); | |
162 |
|
162 | |||
163 | qreal takeAtPos = 0.5; |
|
163 | qreal takeAtPos = 0.5; | |
164 | qreal step = 0.2; |
|
164 | qreal step = 0.2; | |
165 | if (sets.count() > 1 ) { |
|
165 | if (sets.count() > 1 ) { | |
166 | step = 1.0 / (qreal) sets.count(); |
|
166 | step = 1.0 / (qreal) sets.count(); | |
167 | if (sets.count() % m_seriesGradients.count()) |
|
167 | if (sets.count() % m_seriesGradients.count()) | |
168 | step *= m_seriesGradients.count(); |
|
168 | step *= m_seriesGradients.count(); | |
169 | else |
|
169 | else | |
170 | step *= (m_seriesGradients.count() - 1); |
|
170 | step *= (m_seriesGradients.count() - 1); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | for (int i(0); i < sets.count(); i++) { |
|
173 | for (int i(0); i < sets.count(); i++) { | |
174 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
174 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
175 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
175 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
176 | // There is no dedicated base color for each sets, generate more colors |
|
176 | // There is no dedicated base color for each sets, generate more colors | |
177 | takeAtPos += step; |
|
177 | takeAtPos += step; | |
178 | if (takeAtPos == 1.0) |
|
178 | if (takeAtPos == 1.0) | |
179 | takeAtPos += step; |
|
179 | takeAtPos += step; | |
180 | takeAtPos -= (int) takeAtPos; |
|
180 | takeAtPos -= (int) takeAtPos; | |
181 | } |
|
181 | } | |
182 | if (brush == sets.at(i)->brush() || m_force ) |
|
182 | if (brush == sets.at(i)->brush() || m_force ) | |
183 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
183 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
184 |
|
184 | |||
185 | // Pick label color from the opposite end of the gradient. |
|
185 | // Pick label color from the opposite end of the gradient. | |
186 | // 0.3 as a boundary seems to work well. |
|
186 | // 0.3 as a boundary seems to work well. | |
187 | if (takeAtPos < 0.3) |
|
187 | if (takeAtPos < 0.3) | |
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
189 | else |
|
189 | else | |
190 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
190 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
191 |
|
191 | |||
192 | if (pen == sets.at(i)->pen() || m_force) { |
|
192 | if (pen == sets.at(i)->pen() || m_force) { | |
193 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
193 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
194 | sets.at(i)->setPen(c); |
|
194 | sets.at(i)->setPen(c); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
199 | void ChartTheme::decorate(QScatterSeries *series, int index) | |
200 | { |
|
200 | { | |
201 | QPen pen; |
|
201 | QPen pen; | |
202 | QBrush brush; |
|
202 | QBrush brush; | |
203 |
|
203 | |||
204 | if (pen == series->pen() || m_force) { |
|
204 | if (pen == series->pen() || m_force) { | |
205 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
205 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
206 | pen.setWidthF(2); |
|
206 | pen.setWidthF(2); | |
207 | series->setPen(pen); |
|
207 | series->setPen(pen); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | if (brush == series->brush() || m_force) { |
|
210 | if (brush == series->brush() || m_force) { | |
211 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
211 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
212 | series->setBrush(brush); |
|
212 | series->setBrush(brush); | |
213 | } |
|
213 | } | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
216 | void ChartTheme::decorate(QPieSeries *series, int index) | |
217 | { |
|
217 | { | |
218 |
|
218 | |||
219 | for (int i(0); i < series->slices().count(); i++) { |
|
219 | for (int i(0); i < series->slices().count(); i++) { | |
220 |
|
220 | |||
221 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
221 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
222 |
|
222 | |||
223 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
223 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
224 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
224 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
225 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
225 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
226 |
|
226 | |||
227 | QPieSlice *s = series->slices().at(i); |
|
227 | QPieSlice *s = series->slices().at(i); | |
228 | PieSliceData data = PieSliceData::data(s); |
|
228 | PieSliceData data = PieSliceData::data(s); | |
229 |
|
229 | |||
230 | if (data.m_slicePen.isThemed() || m_force) { |
|
230 | if (data.m_slicePen.isThemed() || m_force) { | |
231 | data.m_slicePen = penColor; |
|
231 | data.m_slicePen = penColor; | |
232 | data.m_slicePen.setThemed(true); |
|
232 | data.m_slicePen.setThemed(true); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | if (data.m_sliceBrush.isThemed() || m_force) { |
|
235 | if (data.m_sliceBrush.isThemed() || m_force) { | |
236 | data.m_sliceBrush = brushColor; |
|
236 | data.m_sliceBrush = brushColor; | |
237 | data.m_sliceBrush.setThemed(true); |
|
237 | data.m_sliceBrush.setThemed(true); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | if (data.m_labelPen.isThemed() || m_force) { |
|
240 | if (data.m_labelPen.isThemed() || m_force) { | |
241 | data.m_labelPen = QPen(m_titleBrush.color()); |
|
241 | data.m_labelPen = QPen(m_titleBrush.color()); | |
242 | data.m_labelPen.setThemed(true); |
|
242 | data.m_labelPen.setThemed(true); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | if (data.m_labelFont.isThemed() || m_force) { |
|
245 | if (data.m_labelFont.isThemed() || m_force) { | |
246 | data.m_labelFont = m_labelFont; |
|
246 | data.m_labelFont = m_labelFont; | |
247 | data.m_labelFont.setThemed(true); |
|
247 | data.m_labelFont.setThemed(true); | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | if (PieSliceData::data(s) != data) { |
|
250 | if (PieSliceData::data(s) != data) { | |
251 | PieSliceData::data(s) = data; |
|
251 | PieSliceData::data(s) = data; | |
252 | emit PieSliceData::data(s).emitChangedSignal(s); |
|
252 | emit PieSliceData::data(s).emitChangedSignal(s); | |
253 | } |
|
253 | } | |
254 | } |
|
254 | } | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
257 | void ChartTheme::decorate(QSplineSeries *series, int index) | |
258 | { |
|
258 | { | |
259 | QPen pen; |
|
259 | QPen pen; | |
260 | if(pen == series->pen() || m_force){ |
|
260 | if(pen == series->pen() || m_force){ | |
261 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
261 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
262 | pen.setWidthF(2); |
|
262 | pen.setWidthF(2); | |
263 | series->setPen(pen); |
|
263 | series->setPen(pen); | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void ChartTheme::decorate(QAxis *axis,bool axisX) |
|
267 | void ChartTheme::decorate(QAxis *axis,bool axisX) | |
268 | { |
|
268 | { | |
269 | QPen pen; |
|
269 | QPen pen; | |
270 | QBrush brush; |
|
270 | QBrush brush; | |
271 | QFont font; |
|
271 | QFont font; | |
272 |
|
272 | |||
273 | if (axis->isAxisVisible()) { |
|
273 | if (axis->isAxisVisible()) { | |
274 |
|
274 | |||
275 | if(brush == axis->labelsBrush() || m_force){ |
|
275 | if(brush == axis->labelsBrush() || m_force){ | |
276 | axis->setLabelsBrush(m_axisLabelBrush); |
|
276 | axis->setLabelsBrush(m_axisLabelBrush); | |
277 | } |
|
277 | } | |
278 | if(pen == axis->labelsPen() || m_force){ |
|
278 | if(pen == axis->labelsPen() || m_force){ | |
279 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
279 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 |
|
282 | |||
283 | if (axis->shadesVisible() || m_force) { |
|
283 | if (axis->shadesVisible() || m_force) { | |
284 |
|
284 | |||
285 | if(brush == axis->shadesBrush() || m_force){ |
|
285 | if(brush == axis->shadesBrush() || m_force){ | |
286 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
286 | axis->setShadesBrush(m_backgroundShadesBrush); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | if(pen == axis->shadesPen() || m_force){ |
|
289 | if(pen == axis->shadesPen() || m_force){ | |
290 | axis->setShadesPen(m_backgroundShadesPen); |
|
290 | axis->setShadesPen(m_backgroundShadesPen); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | if( m_force && (m_backgroundShades == BackgroundShadesBoth |
|
293 | if( m_force && (m_backgroundShades == BackgroundShadesBoth | |
294 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
294 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
295 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
295 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
296 | axis->setShadesVisible(true); |
|
296 | axis->setShadesVisible(true); | |
297 |
|
297 | |||
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | if(pen == axis->axisPen() || m_force){ |
|
301 | if(pen == axis->axisPen() || m_force){ | |
302 | axis->setAxisPen(m_axisLinePen); |
|
302 | axis->setAxisPen(m_axisLinePen); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | if(pen == axis->gridLinePen() || m_force){ |
|
305 | if(pen == axis->gridLinePen() || m_force){ | |
306 | axis->setGridLinePen(m_gridLinePen); |
|
306 | axis->setGridLinePen(m_gridLinePen); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | if(font == axis->labelsFont() || m_force){ |
|
309 | if(font == axis->labelsFont() || m_force){ | |
310 | axis->setLabelsFont(m_labelFont); |
|
310 | axis->setLabelsFont(m_labelFont); | |
311 | } |
|
311 | } | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void ChartTheme::generateSeriesGradients() |
|
315 | void ChartTheme::generateSeriesGradients() | |
316 | { |
|
316 | { | |
317 | // Generate gradients in HSV color space |
|
317 | // Generate gradients in HSV color space | |
318 | foreach (const QColor& color, m_seriesColors) { |
|
318 | foreach (const QColor& color, m_seriesColors) { | |
319 | QLinearGradient g; |
|
319 | QLinearGradient g; | |
320 | qreal h = color.hsvHueF(); |
|
320 | qreal h = color.hsvHueF(); | |
321 | qreal s = color.hsvSaturationF(); |
|
321 | qreal s = color.hsvSaturationF(); | |
322 |
|
322 | |||
323 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
323 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
324 | // most themes. The rest of the gradients we can define manually in theme specific |
|
324 | // most themes. The rest of the gradients we can define manually in theme specific | |
325 | // implementation. |
|
325 | // implementation. | |
326 | QColor start = color; |
|
326 | QColor start = color; | |
327 | start.setHsvF(h, 0.0, 1.0); |
|
327 | start.setHsvF(h, 0.0, 1.0); | |
328 | g.setColorAt(0.0, start); |
|
328 | g.setColorAt(0.0, start); | |
329 |
|
329 | |||
330 | g.setColorAt(0.5, color); |
|
330 | g.setColorAt(0.5, color); | |
331 |
|
331 | |||
332 | QColor end = color; |
|
332 | QColor end = color; | |
333 | end.setHsvF(h, s, 0.25); |
|
333 | end.setHsvF(h, s, 0.25); | |
334 | g.setColorAt(1.0, end); |
|
334 | g.setColorAt(1.0, end); | |
335 |
|
335 | |||
336 | m_seriesGradients << g; |
|
336 | m_seriesGradients << g; | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 |
|
340 | |||
341 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
341 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
342 | { |
|
342 | { | |
343 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
343 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
344 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
344 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
345 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
345 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
346 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
346 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
347 | QColor c; |
|
347 | QColor c; | |
348 | c.setRgbF(r, g, b); |
|
348 | c.setRgbF(r, g, b); | |
349 | return c; |
|
349 | return c; | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
352 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
353 | { |
|
353 | { | |
354 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
354 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
355 |
|
355 | |||
356 | // another possibility: |
|
|||
357 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
|||
358 |
|
||||
359 | QGradientStops stops = gradient.stops(); |
|
356 | QGradientStops stops = gradient.stops(); | |
360 | int count = stops.count(); |
|
357 | int count = stops.count(); | |
361 |
|
358 | |||
362 | // find previous stop relative to position |
|
359 | // find previous stop relative to position | |
363 | QGradientStop prev = stops.first(); |
|
360 | QGradientStop prev = stops.first(); | |
364 | for (int i = 0; i < count; i++) { |
|
361 | for (int i = 0; i < count; i++) { | |
365 | QGradientStop stop = stops.at(i); |
|
362 | QGradientStop stop = stops.at(i); | |
366 | if (pos > stop.first) |
|
363 | if (pos > stop.first) | |
367 | prev = stop; |
|
364 | prev = stop; | |
368 |
|
365 | |||
369 | // given position is actually a stop position? |
|
366 | // given position is actually a stop position? | |
370 | if (pos == stop.first) { |
|
367 | if (pos == stop.first) { | |
371 | //qDebug() << "stop color" << pos; |
|
368 | //qDebug() << "stop color" << pos; | |
372 | return stop.second; |
|
369 | return stop.second; | |
373 | } |
|
370 | } | |
374 | } |
|
371 | } | |
375 |
|
372 | |||
376 | // find next stop relative to position |
|
373 | // find next stop relative to position | |
377 | QGradientStop next = stops.last(); |
|
374 | QGradientStop next = stops.last(); | |
378 | for (int i = count - 1; i >= 0; i--) { |
|
375 | for (int i = count - 1; i >= 0; i--) { | |
379 | QGradientStop stop = stops.at(i); |
|
376 | QGradientStop stop = stops.at(i); | |
380 | if (pos < stop.first) |
|
377 | if (pos < stop.first) | |
381 | next = stop; |
|
378 | next = stop; | |
382 | } |
|
379 | } | |
383 |
|
380 | |||
384 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
381 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
385 |
|
382 | |||
386 | qreal range = next.first - prev.first; |
|
383 | qreal range = next.first - prev.first; | |
387 | qreal posDelta = pos - prev.first; |
|
384 | qreal posDelta = pos - prev.first; | |
388 | qreal relativePos = posDelta / range; |
|
385 | qreal relativePos = posDelta / range; | |
389 |
|
386 | |||
390 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
387 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
391 |
|
388 | |||
392 | return colorAt(prev.second, next.second, relativePos); |
|
389 | return colorAt(prev.second, next.second, relativePos); | |
393 | } |
|
390 | } | |
394 |
|
391 | |||
395 | void ChartTheme::setForced(bool enabled) |
|
392 | void ChartTheme::setForced(bool enabled) | |
396 | { |
|
393 | { | |
397 | m_force=enabled; |
|
394 | m_force=enabled; | |
398 | } |
|
395 | } | |
399 |
|
396 | |||
400 | QTCOMMERCIALCHART_END_NAMESPACE |
|
397 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now