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