@@ -1,166 +1,166 | |||
|
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 <QGroupedBarSeries> |
|
26 | 26 | #include <QStackedBarSeries> |
|
27 | 27 | #include <QPercentBarSeries> |
|
28 | 28 | #include <QBarSet> |
|
29 | 29 | #include <QDeclarativeItem> |
|
30 | 30 | #include <QDeclarativeParserStatus> |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | class QChart; |
|
35 | 35 | |
|
36 | 36 | class DeclarativeBarSet : public QBarSet |
|
37 | 37 | { |
|
38 | 38 | Q_OBJECT |
|
39 | 39 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
40 | 40 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | explicit DeclarativeBarSet(QObject *parent = 0); |
|
44 | 44 | QVariantList values(); |
|
45 | 45 | void setValues(QVariantList values); |
|
46 | 46 | |
|
47 | 47 | public: // From QBarSet |
|
48 | 48 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } |
|
49 | 49 | Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); } |
|
50 |
Q_INVOKABLE |
|
|
50 | Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); } | |
|
51 | 51 | Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); } |
|
52 | 52 | Q_INVOKABLE void replace(int index, qreal x, qreal y) { QBarSet::replace(index, QPointF(x, y)); } |
|
53 | 53 | Q_INVOKABLE QPointF at(int index) { return QBarSet::at(index); } |
|
54 | 54 | |
|
55 | 55 | Q_SIGNALS: |
|
56 | 56 | void countChanged(int count); |
|
57 | 57 | |
|
58 | 58 | private Q_SLOTS: |
|
59 | 59 | void handleCountChanged(int index, int count); |
|
60 | 60 | }; |
|
61 | 61 | |
|
62 | 62 | class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus |
|
63 | 63 | { |
|
64 | 64 | Q_OBJECT |
|
65 | 65 | Q_INTERFACES(QDeclarativeParserStatus) |
|
66 | 66 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
67 | 67 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
68 | 68 | |
|
69 | 69 | public: |
|
70 | 70 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); |
|
71 | 71 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
72 | 72 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
73 | 73 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
74 | 74 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
75 | 75 | Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); } |
|
76 | 76 | Q_INVOKABLE void clear() { return QBarSeries::clear(); } |
|
77 | 77 | |
|
78 | 78 | public: // from QDeclarativeParserStatus |
|
79 | 79 | void classBegin(); |
|
80 | 80 | void componentComplete(); |
|
81 | 81 | |
|
82 | 82 | Q_SIGNALS: |
|
83 | 83 | void added(DeclarativeBarSet *barset); |
|
84 | 84 | void removed(DeclarativeBarSet *barset); |
|
85 | 85 | |
|
86 | 86 | public Q_SLOTS: |
|
87 | 87 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
88 | 88 | void handleAdded(QList<QBarSet* > barsets); |
|
89 | 89 | void handleRemoved(QList<QBarSet* > barsets); |
|
90 | 90 | }; |
|
91 | 91 | |
|
92 | 92 | class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus |
|
93 | 93 | { |
|
94 | 94 | Q_OBJECT |
|
95 | 95 | Q_INTERFACES(QDeclarativeParserStatus) |
|
96 | 96 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
97 | 97 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
98 | 98 | |
|
99 | 99 | public: |
|
100 | 100 | explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); |
|
101 | 101 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
102 | 102 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
103 | 103 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
104 | 104 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
105 | 105 | Q_INVOKABLE bool remove(QBarSet *barset) { return QGroupedBarSeries::remove(barset); } |
|
106 | 106 | Q_INVOKABLE void clear() { return QGroupedBarSeries::clear(); } |
|
107 | 107 | |
|
108 | 108 | public: // from QDeclarativeParserStatus |
|
109 | 109 | void classBegin(); |
|
110 | 110 | void componentComplete(); |
|
111 | 111 | |
|
112 | 112 | public Q_SLOTS: |
|
113 | 113 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
114 | 114 | }; |
|
115 | 115 | |
|
116 | 116 | class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus |
|
117 | 117 | { |
|
118 | 118 | Q_OBJECT |
|
119 | 119 | Q_INTERFACES(QDeclarativeParserStatus) |
|
120 | 120 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
121 | 121 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
122 | 122 | |
|
123 | 123 | public: |
|
124 | 124 | explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); |
|
125 | 125 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
126 | 126 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
127 | 127 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
128 | 128 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
129 | 129 | Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); } |
|
130 | 130 | Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); } |
|
131 | 131 | |
|
132 | 132 | public: // from QDeclarativeParserStatus |
|
133 | 133 | void classBegin(); |
|
134 | 134 | void componentComplete(); |
|
135 | 135 | |
|
136 | 136 | public Q_SLOTS: |
|
137 | 137 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
138 | 138 | }; |
|
139 | 139 | |
|
140 | 140 | class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus |
|
141 | 141 | { |
|
142 | 142 | Q_OBJECT |
|
143 | 143 | Q_INTERFACES(QDeclarativeParserStatus) |
|
144 | 144 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
145 | 145 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
146 | 146 | |
|
147 | 147 | public: |
|
148 | 148 | explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); |
|
149 | 149 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
150 | 150 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
151 | 151 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
152 | 152 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
153 | 153 | Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); } |
|
154 | 154 | Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); } |
|
155 | 155 | |
|
156 | 156 | public: // from QDeclarativeParserStatus |
|
157 | 157 | void classBegin(); |
|
158 | 158 | void componentComplete(); |
|
159 | 159 | |
|
160 | 160 | public Q_SLOTS: |
|
161 | 161 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
162 | 162 | }; |
|
163 | 163 | |
|
164 | 164 | QTCOMMERCIALCHART_END_NAMESPACE |
|
165 | 165 | |
|
166 | 166 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,643 +1,648 | |||
|
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 "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QBarSet |
|
28 | 28 | \brief Building block for different bar charts |
|
29 | 29 | |
|
30 | 30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | 31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | 32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | 33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | 34 | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarSet QBarSet |
|
41 | 41 | |
|
42 | 42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | 43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | 44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | 45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 | 46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QBarSet::label |
|
51 | 51 | Defines the label of the barSet. |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty string BarSet::label |
|
55 | 55 | Defines the label of the barSet. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::pen |
|
60 | 60 | \brief Defines the pen used by the barSet. |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarSet::brush |
|
65 | 65 | \brief Defines the brush used by the barSet. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarSet::labelBrush |
|
70 | 70 | \brief Defines the brush used by the barSet's label. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarSet::labelFont |
|
75 | 75 | \brief Defines the font used by the barSet's label. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \property QBarSet::color |
|
80 | 80 | The fill (brush) color of the bar set. |
|
81 | 81 | */ |
|
82 | 82 | /*! |
|
83 | 83 | \qmlproperty color BarSet::color |
|
84 | 84 | The fill (brush) color of the bar set. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QBarSet::borderColor |
|
89 | 89 | The line (pen) color of the bar set. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty color BarSet::borderColor |
|
93 | 93 | The line (pen) color of the bar set. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \property QBarSet::labelColor |
|
98 | 98 | The text (label) color of the bar set. |
|
99 | 99 | */ |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty color BarSet::labelColor |
|
102 | 102 | The text (label) color of the bar set. |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \fn void QBarSet::clicked(int index) |
|
107 | 107 | |
|
108 | 108 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
109 | 109 | Clicked bar inside set is indexed by \a index |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QBarSet::hovered(bool status) |
|
114 | 114 | |
|
115 | 115 | The signal is emitted if mouse is hovered on top of barset. |
|
116 | 116 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \fn void QBarSet::labelChanged() |
|
122 | 122 | This signal is emitted when the label of the barSet has changed. |
|
123 | 123 | \sa label |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \fn void QBarSet::penChanged() |
|
128 | 128 | This signal is emitted when the pen of the barSet has changed. |
|
129 | 129 | \sa pen |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QBarSet::brushChanged() |
|
134 | 134 | This signal is emitted when the brush of the barSet has changed. |
|
135 | 135 | \sa brush |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QBarSet::labelBrushChanged() |
|
140 | 140 | This signal is emitted when the brush of the barSet's label has changed. |
|
141 | 141 | \sa labelBrush |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \fn void QBarSet::labelFontChanged() |
|
146 | 146 | This signal is emitted when the font of the barSet's label has changed. |
|
147 | 147 | \sa labelBrush |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QBarSet::colorChanged(QColor) |
|
152 | 152 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
153 | 153 | */ |
|
154 | 154 | /*! |
|
155 | 155 | \qmlsignal BarSet::onColorChanged(color color) |
|
156 | 156 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | \fn void QBarSet::borderColorChanged(QColor) |
|
161 | 161 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
162 | 162 | */ |
|
163 | 163 | /*! |
|
164 | 164 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
165 | 165 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
166 | 166 | */ |
|
167 | 167 | |
|
168 | 168 | /*! |
|
169 | 169 | \fn void QBarSet::labelColorChanged(QColor) |
|
170 | 170 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
171 | 171 | */ |
|
172 | 172 | /*! |
|
173 | 173 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
174 | 174 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \fn void QBarSet::valuesAdded(int index, int count) |
|
179 | 179 | This signal is emitted when new values have been added to the set. |
|
180 | 180 | Parameter \a index indicates the position of the first inserted value. |
|
181 | 181 | Parameter \a count is the number of iserted values. |
|
182 | 182 | \sa append(), insert() |
|
183 | 183 | */ |
|
184 | 184 | /*! |
|
185 | 185 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
186 | 186 | This signal is emitted when new values have been added to the set. |
|
187 | 187 | Parameter \a index indicates the position of the first inserted value. |
|
188 | 188 | Parameter \a count is the number of iserted values. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
193 | 193 | This signal is emitted values have been removed from the set. |
|
194 | 194 | Parameter \a index indicates the position of the first removed value. |
|
195 | 195 | Parameter \a count is the number of removed values. |
|
196 | 196 | \sa remove() |
|
197 | 197 | */ |
|
198 | 198 | /*! |
|
199 | 199 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
200 | 200 | This signal is emitted values have been removed from the set. |
|
201 | 201 | Parameter \a index indicates the position of the first removed value. |
|
202 | 202 | Parameter \a count is the number of removed values. |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \fn void QBarSet::valueChanged(int index) |
|
207 | 207 | This signal is emitted values the value in the set has been modified. |
|
208 | 208 | Parameter \a index indicates the position of the modified value. |
|
209 | 209 | \sa at() |
|
210 | 210 | */ |
|
211 | 211 | /*! |
|
212 | 212 | \qmlsignal BarSet::onValueChanged(int index) |
|
213 | 213 | This signal is emitted values the value in the set has been modified. |
|
214 | 214 | Parameter \a index indicates the position of the modified value. |
|
215 | 215 | */ |
|
216 | 216 | |
|
217 | 217 | /*! |
|
218 | 218 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
219 | 219 | */ |
|
220 | 220 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
221 | 221 | : QObject(parent) |
|
222 | 222 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
223 | 223 | { |
|
224 | 224 | } |
|
225 | 225 | |
|
226 | 226 | /*! |
|
227 | 227 | Destroys the barset |
|
228 | 228 | */ |
|
229 | 229 | QBarSet::~QBarSet() |
|
230 | 230 | { |
|
231 | 231 | // NOTE: d_ptr destroyed by QObject |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | Sets new \a label for set. |
|
236 | 236 | */ |
|
237 | 237 | void QBarSet::setLabel(const QString label) |
|
238 | 238 | { |
|
239 | 239 | d_ptr->m_label = label; |
|
240 | 240 | emit labelChanged(); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | Returns label of the set. |
|
245 | 245 | */ |
|
246 | 246 | QString QBarSet::label() const |
|
247 | 247 | { |
|
248 | 248 | return d_ptr->m_label; |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | /*! |
|
252 | 252 | Appends a point to set. Parameter \a value x coordinate defines the |
|
253 | 253 | position in x-axis and y coordinate defines the height of bar. |
|
254 | 254 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) |
|
255 | 255 | the x values are used or ignored. |
|
256 | 256 | */ |
|
257 | 257 | void QBarSet::append(const QPointF value) |
|
258 | 258 | { |
|
259 | 259 | int index = d_ptr->m_values.count(); |
|
260 | 260 | d_ptr->append(value); |
|
261 | 261 | emit valuesAdded(index, 1); |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | /*! |
|
265 | 265 | Appends a list of \a values to set. Works like append with single point. |
|
266 | 266 | \sa append() |
|
267 | 267 | */ |
|
268 | 268 | void QBarSet::append(const QList<QPointF> &values) |
|
269 | 269 | { |
|
270 | 270 | int index = d_ptr->m_values.count(); |
|
271 | 271 | d_ptr->append(values); |
|
272 | 272 | emit valuesAdded(index, values.count()); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, |
|
277 | 277 | with x coordinate being the index of appended value and y coordinate is the value. |
|
278 | 278 | */ |
|
279 | 279 | void QBarSet::append(const qreal value) |
|
280 | 280 | { |
|
281 | 281 | // Convert to QPointF and use other append(QPointF) method. |
|
282 | 282 | append(QPointF(d_ptr->m_values.count(), value)); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | /*! |
|
286 | 286 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
287 | 287 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. |
|
288 | 288 | \sa append() |
|
289 | 289 | */ |
|
290 | 290 | void QBarSet::append(const QList<qreal> &values) |
|
291 | 291 | { |
|
292 | 292 | int index = d_ptr->m_values.count(); |
|
293 | 293 | d_ptr->append(values); |
|
294 | 294 | emit valuesAdded(index, values.count()); |
|
295 | 295 | } |
|
296 | 296 | |
|
297 | 297 | /*! |
|
298 | 298 | Convinience operator. Same as append, with real \a value. |
|
299 | 299 | \sa append() |
|
300 | 300 | */ |
|
301 | 301 | QBarSet& QBarSet::operator << (const qreal &value) |
|
302 | 302 | { |
|
303 | 303 | append(value); |
|
304 | 304 | return *this; |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | /*! |
|
308 | 308 | Convinience operator. Same as append, with QPointF \a value. |
|
309 | 309 | \sa append() |
|
310 | 310 | */ |
|
311 | 311 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
312 | 312 | { |
|
313 | 313 | append(value); |
|
314 | 314 | return *this; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Inserts new \a value on the \a index position. |
|
319 | 319 | The value that is currently at this postion is moved to postion index + 1 |
|
320 | 320 | \sa remove() |
|
321 | 321 | */ |
|
322 | 322 | void QBarSet::insert(const int index, const qreal value) |
|
323 | 323 | { |
|
324 | 324 | d_ptr->insert(index, value); |
|
325 | 325 | emit valuesAdded(index,1); |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | /*! |
|
329 | 329 | Inserts new \a value on the \a index position. |
|
330 | 330 | The value that is currently at this postion is moved to postion index + 1 |
|
331 | 331 | \sa remove() |
|
332 | 332 | */ |
|
333 | 333 | void QBarSet::insert(const int index, const QPointF value) |
|
334 | 334 | { |
|
335 | 335 | d_ptr->insert(index,value); |
|
336 | 336 | emit valuesAdded(index,1); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | /*! |
|
340 | 340 | Removes \a count number of values from the set starting at \a index. |
|
341 | Returns true if remove operation was succesfull. | |
|
342 | 341 | \sa insert() |
|
343 | 342 | */ |
|
344 |
|
|
|
343 | void QBarSet::remove(const int index, const int count) | |
|
345 | 344 | { |
|
346 |
|
|
|
347 | if (success) { | |
|
348 |
emit valuesRemoved(index, |
|
|
345 | int removedCount = d_ptr->remove(index,count); | |
|
346 | if (removedCount > 0) { | |
|
347 | emit valuesRemoved(index,removedCount); | |
|
349 | 348 | } |
|
350 |
return |
|
|
349 | return; | |
|
351 | 350 | } |
|
352 | 351 | |
|
353 | 352 | /*! |
|
354 | 353 | Sets a new value \a value to set, indexed by \a index |
|
355 | 354 | */ |
|
356 | 355 | void QBarSet::replace(const int index, const qreal value) |
|
357 | 356 | { |
|
358 | 357 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
359 | 358 | d_ptr->replace(index,value); |
|
360 | 359 | emit valueChanged(index); |
|
361 | 360 | } |
|
362 | 361 | } |
|
363 | 362 | |
|
364 | 363 | /*! |
|
365 | 364 | Sets a new value \a value to set, indexed by \a index |
|
366 | 365 | */ |
|
367 | 366 | void QBarSet::replace(const int index, const QPointF value) |
|
368 | 367 | { |
|
369 | 368 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
370 | 369 | d_ptr->replace(index,value); |
|
371 | 370 | emit valueChanged(index); |
|
372 | 371 | } |
|
373 | 372 | } |
|
374 | 373 | |
|
375 | 374 | /*! |
|
376 | 375 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. |
|
377 | 376 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
378 | 377 | of the QPointF (if appended with QPointF append). |
|
379 | 378 | If the index is out of bounds QPointF(0, 0.0) is returned. |
|
380 | 379 | */ |
|
381 | 380 | QPointF QBarSet::at(const int index) const |
|
382 | 381 | { |
|
383 | 382 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
384 | 383 | return QPointF(index, 0.0); |
|
385 | 384 | } |
|
386 | 385 | |
|
387 | 386 | return d_ptr->m_values.at(index); |
|
388 | 387 | } |
|
389 | 388 | |
|
390 | 389 | /*! |
|
391 | 390 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. |
|
392 | 391 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
393 | 392 | of the QPointF (if appended with QPointF append). |
|
394 | 393 | */ |
|
395 | 394 | QPointF QBarSet::operator [](const int index) const |
|
396 | 395 | { |
|
397 | 396 | return d_ptr->m_values.at(index); |
|
398 | 397 | } |
|
399 | 398 | |
|
400 | 399 | /*! |
|
401 | 400 | Returns count of values in set. |
|
402 | 401 | */ |
|
403 | 402 | int QBarSet::count() const |
|
404 | 403 | { |
|
405 | 404 | return d_ptr->m_values.count(); |
|
406 | 405 | } |
|
407 | 406 | |
|
408 | 407 | /*! |
|
409 | 408 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. |
|
410 | 409 | */ |
|
411 | 410 | qreal QBarSet::sum() const |
|
412 | 411 | { |
|
413 | 412 | qreal total(0); |
|
414 | 413 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
415 | 414 | //total += d_ptr->m_values.at(i); |
|
416 | 415 | total += d_ptr->m_values.at(i).y(); |
|
417 | 416 | } |
|
418 | 417 | return total; |
|
419 | 418 | } |
|
420 | 419 | |
|
421 | 420 | /*! |
|
422 | 421 | Sets pen for set. Bars of this set are drawn using \a pen |
|
423 | 422 | */ |
|
424 | 423 | void QBarSet::setPen(const QPen &pen) |
|
425 | 424 | { |
|
426 | 425 | if(d_ptr->m_pen!=pen){ |
|
427 | 426 | d_ptr->m_pen = pen; |
|
428 | 427 | emit d_ptr->updatedBars(); |
|
429 | 428 | emit penChanged(); |
|
430 | 429 | } |
|
431 | 430 | } |
|
432 | 431 | |
|
433 | 432 | /*! |
|
434 | 433 | Returns pen of the set. |
|
435 | 434 | */ |
|
436 | 435 | QPen QBarSet::pen() const |
|
437 | 436 | { |
|
438 | 437 | return d_ptr->m_pen; |
|
439 | 438 | } |
|
440 | 439 | |
|
441 | 440 | /*! |
|
442 | 441 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
443 | 442 | */ |
|
444 | 443 | void QBarSet::setBrush(const QBrush &brush) |
|
445 | 444 | { |
|
446 | 445 | if(d_ptr->m_brush!=brush){ |
|
447 | 446 | d_ptr->m_brush = brush; |
|
448 | 447 | emit d_ptr->updatedBars(); |
|
449 | 448 | emit brushChanged(); |
|
450 | 449 | } |
|
451 | 450 | } |
|
452 | 451 | |
|
453 | 452 | /*! |
|
454 | 453 | Returns brush of the set. |
|
455 | 454 | */ |
|
456 | 455 | QBrush QBarSet::brush() const |
|
457 | 456 | { |
|
458 | 457 | return d_ptr->m_brush; |
|
459 | 458 | } |
|
460 | 459 | |
|
461 | 460 | /*! |
|
462 | 461 | Sets \a brush of the values that are drawn on top of this barset |
|
463 | 462 | */ |
|
464 | 463 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
465 | 464 | { |
|
466 | 465 | if(d_ptr->m_labelBrush!=brush){ |
|
467 | 466 | d_ptr->m_labelBrush = brush; |
|
468 | 467 | emit d_ptr->updatedBars(); |
|
469 | 468 | emit labelBrushChanged(); |
|
470 | 469 | } |
|
471 | 470 | } |
|
472 | 471 | |
|
473 | 472 | /*! |
|
474 | 473 | Returns brush of the values that are drawn on top of this barset |
|
475 | 474 | */ |
|
476 | 475 | QBrush QBarSet::labelBrush() const |
|
477 | 476 | { |
|
478 | 477 | return d_ptr->m_labelBrush; |
|
479 | 478 | } |
|
480 | 479 | |
|
481 | 480 | /*! |
|
482 | 481 | Sets the \a font for values that are drawn on top of this barset |
|
483 | 482 | */ |
|
484 | 483 | void QBarSet::setLabelFont(const QFont &font) |
|
485 | 484 | { |
|
486 | 485 | if(d_ptr->m_labelFont!=font) { |
|
487 | 486 | d_ptr->m_labelFont = font; |
|
488 | 487 | emit d_ptr->updatedBars(); |
|
489 | 488 | emit labelFontChanged(); |
|
490 | 489 | } |
|
491 | 490 | |
|
492 | 491 | } |
|
493 | 492 | |
|
494 | 493 | /*! |
|
495 | 494 | Returns the pen for values that are drawn on top of this barset |
|
496 | 495 | */ |
|
497 | 496 | QFont QBarSet::labelFont() const |
|
498 | 497 | { |
|
499 | 498 | return d_ptr->m_labelFont; |
|
500 | 499 | } |
|
501 | 500 | |
|
502 | 501 | /*! |
|
503 | 502 | Returns the color of the brush of barset. |
|
504 | 503 | */ |
|
505 | 504 | QColor QBarSet::color() |
|
506 | 505 | { |
|
507 | 506 | return brush().color(); |
|
508 | 507 | } |
|
509 | 508 | |
|
510 | 509 | /*! |
|
511 | 510 | Sets the \a color of brush for this barset |
|
512 | 511 | */ |
|
513 | 512 | void QBarSet::setColor(QColor color) |
|
514 | 513 | { |
|
515 | 514 | QBrush b = brush(); |
|
516 | 515 | if (b.color() != color) { |
|
517 | 516 | b.setColor(color); |
|
518 | 517 | setBrush(b); |
|
519 | 518 | emit colorChanged(color); |
|
520 | 519 | } |
|
521 | 520 | } |
|
522 | 521 | |
|
523 | 522 | /*! |
|
524 | 523 | Returns the color of pen of this barset |
|
525 | 524 | */ |
|
526 | 525 | QColor QBarSet::borderColor() |
|
527 | 526 | { |
|
528 | 527 | return pen().color(); |
|
529 | 528 | } |
|
530 | 529 | |
|
531 | 530 | /*! |
|
532 | 531 | Sets the color of pen for this barset |
|
533 | 532 | */ |
|
534 | 533 | void QBarSet::setBorderColor(QColor color) |
|
535 | 534 | { |
|
536 | 535 | QPen p = pen(); |
|
537 | 536 | if (p.color() != color) { |
|
538 | 537 | p.setColor(color); |
|
539 | 538 | setPen(p); |
|
540 | 539 | emit borderColorChanged(color); |
|
541 | 540 | } |
|
542 | 541 | } |
|
543 | 542 | |
|
544 | 543 | /*! |
|
545 | 544 | Returns the color of labels of this barset |
|
546 | 545 | */ |
|
547 | 546 | QColor QBarSet::labelColor() |
|
548 | 547 | { |
|
549 | 548 | return labelBrush().color(); |
|
550 | 549 | } |
|
551 | 550 | |
|
552 | 551 | /*! |
|
553 | 552 | Sets the color of labels for this barset |
|
554 | 553 | */ |
|
555 | 554 | void QBarSet::setLabelColor(QColor color) |
|
556 | 555 | { |
|
557 | 556 | QBrush b = labelBrush(); |
|
558 | 557 | if (b.color() != color) { |
|
559 | 558 | b.setColor(color); |
|
560 | 559 | setLabelBrush(b); |
|
561 | 560 | emit labelColorChanged(color); |
|
562 | 561 | } |
|
563 | 562 | } |
|
564 | 563 | |
|
565 | 564 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
566 | 565 | |
|
567 | 566 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
568 | 567 | q_ptr(parent), |
|
569 | 568 | m_label(label) |
|
570 | 569 | { |
|
571 | 570 | } |
|
572 | 571 | |
|
573 | 572 | QBarSetPrivate::~QBarSetPrivate() |
|
574 | 573 | { |
|
575 | 574 | } |
|
576 | 575 | |
|
577 | 576 | void QBarSetPrivate::append(QPointF value) |
|
578 | 577 | { |
|
579 | 578 | m_values.append(value); |
|
580 | 579 | emit restructuredBars(); |
|
581 | 580 | } |
|
582 | 581 | |
|
583 | 582 | void QBarSetPrivate::append(QList<QPointF> values) |
|
584 | 583 | { |
|
585 | 584 | for (int i=0; i<values.count(); i++) { |
|
586 | 585 | m_values.append(values.at(i)); |
|
587 | 586 | } |
|
588 | 587 | emit restructuredBars(); |
|
589 | 588 | } |
|
590 | 589 | |
|
591 | 590 | void QBarSetPrivate::append(QList<qreal> values) |
|
592 | 591 | { |
|
593 | 592 | int index = m_values.count(); |
|
594 | 593 | for (int i=0; i<values.count(); i++) { |
|
595 | 594 | m_values.append(QPointF(index,values.at(i))); |
|
596 | 595 | index++; |
|
597 | 596 | } |
|
598 | 597 | emit restructuredBars(); |
|
599 | 598 | } |
|
600 | 599 | |
|
601 | 600 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
602 | 601 | { |
|
603 | 602 | m_values.insert(index, QPointF(index, value)); |
|
604 | 603 | emit restructuredBars(); |
|
605 | 604 | } |
|
606 | 605 | |
|
607 | 606 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
608 | 607 | { |
|
609 | 608 | m_values.insert(index, value); |
|
610 | 609 | emit restructuredBars(); |
|
611 | 610 | } |
|
612 | 611 | |
|
613 |
|
|
|
612 | int QBarSetPrivate::remove(const int index, const int count) | |
|
614 | 613 | { |
|
615 | if (index < 0 || (index + count) > m_values.count()) { | |
|
616 | // cant remove more values than there are | |
|
617 | return false; | |
|
614 | int removeCount = count; | |
|
615 | ||
|
616 | if ((index <0) || (m_values.count() == 0)) { | |
|
617 | // Invalid index or not values in list, remove nothing. | |
|
618 | return 0; | |
|
619 | } else if ((index + count) > m_values.count()) { | |
|
620 | // Trying to remove more items than list has. Limit amount to be removed. | |
|
621 | removeCount = m_values.count() - index; | |
|
618 | 622 | } |
|
619 | int c = count; | |
|
620 |
|
|
|
623 | ||
|
624 | int c = 0; | |
|
625 | while (c < removeCount) { | |
|
621 | 626 | m_values.removeAt(index); |
|
622 |
c |
|
|
627 | c++; | |
|
623 | 628 | } |
|
624 | 629 | emit restructuredBars(); |
|
625 |
return |
|
|
630 | return removeCount; | |
|
626 | 631 | } |
|
627 | 632 | |
|
628 | 633 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
629 | 634 | { |
|
630 | 635 | m_values.replace(index,QPointF(index,value)); |
|
631 | 636 | emit updatedBars(); |
|
632 | 637 | } |
|
633 | 638 | |
|
634 | 639 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
635 | 640 | { |
|
636 | 641 | m_values.replace(index,value); |
|
637 | 642 | emit updatedBars(); |
|
638 | 643 | } |
|
639 | 644 | |
|
640 | 645 | #include "moc_qbarset.cpp" |
|
641 | 646 | #include "moc_qbarset_p.cpp" |
|
642 | 647 | |
|
643 | 648 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,117 +1,117 | |||
|
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 QBARSET_H |
|
22 | 22 | #define QBARSET_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QBrush> |
|
27 | 27 | #include <QFont> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | class QBarSetPrivate; |
|
31 | 31 | |
|
32 | 32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
36 | 36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
37 | 37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
38 | 38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
39 | 39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
40 | 40 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
41 | 41 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
42 | 42 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 | 45 | explicit QBarSet(const QString label, QObject *parent = 0); |
|
46 | 46 | virtual ~QBarSet(); |
|
47 | 47 | |
|
48 | 48 | void setLabel(const QString label); |
|
49 | 49 | QString label() const; |
|
50 | 50 | |
|
51 | 51 | void append(const QPointF value); |
|
52 | 52 | void append(const QList<QPointF> &values); |
|
53 | 53 | void append(const qreal value); |
|
54 | 54 | void append(const QList<qreal> &values); |
|
55 | 55 | |
|
56 | 56 | QBarSet& operator << (const qreal &value); |
|
57 | 57 | QBarSet& operator << (const QPointF &value); |
|
58 | 58 | |
|
59 | 59 | void insert(const int index, const qreal value); |
|
60 | 60 | void insert(const int index, const QPointF value); |
|
61 |
|
|
|
61 | void remove(const int index, const int count = 1); | |
|
62 | 62 | void replace(const int index, const qreal value); |
|
63 | 63 | void replace(const int index, const QPointF value); |
|
64 | 64 | QPointF at(const int index) const; |
|
65 | 65 | QPointF operator [] (const int index) const; |
|
66 | 66 | int count() const; |
|
67 | 67 | qreal sum() const; |
|
68 | 68 | |
|
69 | 69 | void setPen(const QPen &pen); |
|
70 | 70 | QPen pen() const; |
|
71 | 71 | |
|
72 | 72 | void setBrush(const QBrush &brush); |
|
73 | 73 | QBrush brush() const; |
|
74 | 74 | |
|
75 | 75 | void setLabelBrush(const QBrush &brush); |
|
76 | 76 | QBrush labelBrush() const; |
|
77 | 77 | |
|
78 | 78 | void setLabelFont(const QFont &font); |
|
79 | 79 | QFont labelFont() const; |
|
80 | 80 | |
|
81 | 81 | QColor color(); |
|
82 | 82 | void setColor(QColor color); |
|
83 | 83 | |
|
84 | 84 | QColor borderColor(); |
|
85 | 85 | void setBorderColor(QColor color); |
|
86 | 86 | |
|
87 | 87 | QColor labelColor(); |
|
88 | 88 | void setLabelColor(QColor color); |
|
89 | 89 | |
|
90 | 90 | Q_SIGNALS: |
|
91 | 91 | void clicked(int index); |
|
92 | 92 | void hovered(bool status); |
|
93 | 93 | void penChanged(); |
|
94 | 94 | void brushChanged(); |
|
95 | 95 | void labelChanged(); |
|
96 | 96 | void labelBrushChanged(); |
|
97 | 97 | void labelFontChanged(); |
|
98 | 98 | void colorChanged(QColor color); |
|
99 | 99 | void borderColorChanged(QColor color); |
|
100 | 100 | void labelColorChanged(QColor color); |
|
101 | 101 | |
|
102 | 102 | void valuesAdded(int index, int count); |
|
103 | 103 | void valuesRemoved(int index, int count); |
|
104 | 104 | void valueChanged(int index); |
|
105 | 105 | |
|
106 | 106 | private: |
|
107 | 107 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
108 | 108 | Q_DISABLE_COPY(QBarSet) |
|
109 | 109 | friend class QBarSeries; |
|
110 | 110 | friend class BarLegendMarker; |
|
111 | 111 | friend class BarChartItem; |
|
112 | 112 | friend class QBarSeriesPrivate; |
|
113 | 113 | }; |
|
114 | 114 | |
|
115 | 115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | 116 | |
|
117 | 117 | #endif // QBARSET_H |
@@ -1,78 +1,78 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARSET_P_H |
|
31 | 31 | #define QBARSET_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qbarset.h" |
|
34 | 34 | #include <QMap> |
|
35 | 35 | #include <QPen> |
|
36 | 36 | #include <QBrush> |
|
37 | 37 | #include <QFont> |
|
38 | 38 | |
|
39 | 39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class QBarSetPrivate : public QObject |
|
42 | 42 | { |
|
43 | 43 | Q_OBJECT |
|
44 | 44 | |
|
45 | 45 | public: |
|
46 | 46 | QBarSetPrivate(const QString label, QBarSet *parent); |
|
47 | 47 | ~QBarSetPrivate(); |
|
48 | 48 | |
|
49 | 49 | void append(QPointF value); |
|
50 | 50 | void append(QList<QPointF> values); |
|
51 | 51 | void append(QList<qreal> values); |
|
52 | 52 | |
|
53 | 53 | void insert(const int index, const qreal value); |
|
54 | 54 | void insert(const int index, const QPointF value); |
|
55 |
|
|
|
55 | int remove(const int index, const int count); | |
|
56 | 56 | |
|
57 | 57 | void replace(const int index, const qreal value); |
|
58 | 58 | void replace(const int index, const QPointF value); |
|
59 | 59 | |
|
60 | 60 | Q_SIGNALS: |
|
61 | 61 | void restructuredBars(); |
|
62 | 62 | void updatedBars(); |
|
63 | 63 | |
|
64 | 64 | public: |
|
65 | 65 | QBarSet * const q_ptr; |
|
66 | 66 | QString m_label; |
|
67 | 67 | QList<QPointF> m_values; |
|
68 | 68 | QPen m_pen; |
|
69 | 69 | QBrush m_brush; |
|
70 | 70 | QBrush m_labelBrush; |
|
71 | 71 | QFont m_labelFont; |
|
72 | 72 | |
|
73 | 73 | friend class QBarSet; |
|
74 | 74 | }; |
|
75 | 75 | |
|
76 | 76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | 77 | |
|
78 | 78 | #endif // QBARSETPRIVATE_P_H |
@@ -1,453 +1,488 | |||
|
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 <QtTest/QtTest> |
|
22 | 22 | #include <qbarset.h> |
|
23 | 23 | #include <qgroupedbarseries.h> |
|
24 | 24 | #include <qchartview.h> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class tst_QBarSet : public QObject |
|
29 | 29 | { |
|
30 | 30 | Q_OBJECT |
|
31 | 31 | |
|
32 | 32 | public slots: |
|
33 | 33 | void initTestCase(); |
|
34 | 34 | void cleanupTestCase(); |
|
35 | 35 | void init(); |
|
36 | 36 | void cleanup(); |
|
37 | 37 | |
|
38 | 38 | private slots: |
|
39 | 39 | void qbarset_data(); |
|
40 | 40 | void qbarset(); |
|
41 | 41 | void label_data(); |
|
42 | 42 | void label(); |
|
43 | 43 | void append_data(); |
|
44 | 44 | void append(); |
|
45 | 45 | void appendOperator_data(); |
|
46 | 46 | void appendOperator(); |
|
47 | 47 | void insert_data(); |
|
48 | 48 | void insert(); |
|
49 | 49 | void remove_data(); |
|
50 | 50 | void remove(); |
|
51 | 51 | void replace_data(); |
|
52 | 52 | void replace(); |
|
53 | 53 | void at_data(); |
|
54 | 54 | void at(); |
|
55 | 55 | void atOperator_data(); |
|
56 | 56 | void atOperator(); |
|
57 | 57 | void count_data(); |
|
58 | 58 | void count(); |
|
59 | 59 | void sum_data(); |
|
60 | 60 | void sum(); |
|
61 | 61 | void customize(); |
|
62 | 62 | |
|
63 | 63 | private: |
|
64 | 64 | QBarSet* m_barset; |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | 67 | void tst_QBarSet::initTestCase() |
|
68 | 68 | { |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | void tst_QBarSet::cleanupTestCase() |
|
72 | 72 | { |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void tst_QBarSet::init() |
|
76 | 76 | { |
|
77 | 77 | m_barset = new QBarSet(QString("label")); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void tst_QBarSet::cleanup() |
|
81 | 81 | { |
|
82 | 82 | delete m_barset; |
|
83 | 83 | m_barset = 0; |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | void tst_QBarSet::qbarset_data() |
|
87 | 87 | { |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void tst_QBarSet::qbarset() |
|
91 | 91 | { |
|
92 | 92 | QBarSet barset(QString("label")); |
|
93 | 93 | QCOMPARE(barset.label(), QString("label")); |
|
94 | 94 | QCOMPARE(barset.count(), 0); |
|
95 | 95 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void tst_QBarSet::label_data() |
|
99 | 99 | { |
|
100 | 100 | QTest::addColumn<QString> ("label"); |
|
101 | 101 | QTest::addColumn<QString> ("result"); |
|
102 | 102 | QTest::newRow("label0") << QString("label0") << QString("label0"); |
|
103 | 103 | QTest::newRow("label1") << QString("label1") << QString("label1"); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | void tst_QBarSet::label() |
|
107 | 107 | { |
|
108 | 108 | QFETCH(QString, label); |
|
109 | 109 | QFETCH(QString, result); |
|
110 | 110 | |
|
111 | 111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); |
|
112 | 112 | m_barset->setLabel(label); |
|
113 | 113 | QCOMPARE(m_barset->label(), result); |
|
114 | 114 | QVERIFY(labelSpy.count() == 1); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void tst_QBarSet::append_data() |
|
118 | 118 | { |
|
119 | 119 | QTest::addColumn<int> ("count"); |
|
120 | 120 | QTest::newRow("0") << 0; |
|
121 | 121 | QTest::newRow("5") << 5; |
|
122 | 122 | QTest::newRow("100") << 100; |
|
123 | 123 | QTest::newRow("1000") << 1000; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void tst_QBarSet::append() |
|
127 | 127 | { |
|
128 | 128 | QFETCH(int, count); |
|
129 | 129 | |
|
130 | 130 | QCOMPARE(m_barset->count(), 0); |
|
131 | 131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
132 | 132 | |
|
133 | 133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); |
|
134 | 134 | |
|
135 | 135 | qreal sum(0.0); |
|
136 | 136 | qreal value(0.0); |
|
137 | 137 | |
|
138 | 138 | for (int i=0; i<count; i++) { |
|
139 | 139 | m_barset->append(value); |
|
140 | 140 | QCOMPARE(m_barset->at(i).y(), value); |
|
141 | 141 | sum += value; |
|
142 | 142 | value += 1.0; |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | QCOMPARE(m_barset->count(), count); |
|
146 | 146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
147 | 147 | |
|
148 | 148 | QCOMPARE(valueSpy.count(), count); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void tst_QBarSet::appendOperator_data() |
|
152 | 152 | { |
|
153 | 153 | append_data(); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void tst_QBarSet::appendOperator() |
|
157 | 157 | { |
|
158 | 158 | QFETCH(int, count); |
|
159 | 159 | |
|
160 | 160 | QCOMPARE(m_barset->count(), 0); |
|
161 | 161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
162 | 162 | |
|
163 | 163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
164 | 164 | |
|
165 | 165 | qreal sum(0.0); |
|
166 | 166 | qreal value(0.0); |
|
167 | 167 | |
|
168 | 168 | for (int i=0; i<count; i++) { |
|
169 | 169 | *m_barset << value; |
|
170 | 170 | QCOMPARE(m_barset->at(i).y(), value); |
|
171 | 171 | sum += value; |
|
172 | 172 | value += 1.0; |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | QCOMPARE(m_barset->count(), count); |
|
176 | 176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
177 | 177 | QCOMPARE(valueSpy.count(), count); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | void tst_QBarSet::insert_data() |
|
181 | 181 | { |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void tst_QBarSet::insert() |
|
185 | 185 | { |
|
186 | 186 | QCOMPARE(m_barset->count(), 0); |
|
187 | 187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
188 | 188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
189 | 189 | |
|
190 | 190 | m_barset->insert(0, 1.0); // 1.0 |
|
191 | 191 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
192 | 192 | QCOMPARE(m_barset->count(), 1); |
|
193 | 193 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
194 | 194 | |
|
195 | 195 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
196 | 196 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
197 | 197 | QCOMPARE(m_barset->at(1).y(), 1.0); |
|
198 | 198 | QCOMPARE(m_barset->count(), 2); |
|
199 | 199 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
200 | 200 | |
|
201 | 201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
202 | 202 | QCOMPARE(m_barset->at(1).y(), 3.0); |
|
203 | 203 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
204 | 204 | QCOMPARE(m_barset->at(2).y(), 1.0); |
|
205 | 205 | QCOMPARE(m_barset->count(), 3); |
|
206 | 206 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
207 | 207 | QCOMPARE(valueSpy.count(), 3); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | void tst_QBarSet::remove_data() |
|
211 | 211 | { |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | void tst_QBarSet::remove() |
|
215 | 215 | { |
|
216 | 216 | QCOMPARE(m_barset->count(), 0); |
|
217 | 217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
218 | 218 | |
|
219 | 219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); |
|
220 | 220 | |
|
221 | 221 | m_barset->append(1.0); |
|
222 | 222 | m_barset->append(2.0); |
|
223 | 223 | m_barset->append(3.0); |
|
224 | 224 | m_barset->append(4.0); |
|
225 | 225 | |
|
226 | 226 | QCOMPARE(m_barset->count(), 4); |
|
227 | 227 | QCOMPARE(m_barset->sum(), 10.0); |
|
228 | 228 | |
|
229 | 229 | // Remove middle |
|
230 | 230 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
231 | 231 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
232 | 232 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
233 | 233 | QCOMPARE(m_barset->at(2).y(), 4.0); |
|
234 | 234 | QCOMPARE(m_barset->count(), 3); |
|
235 | 235 | QCOMPARE(m_barset->sum(), 7.0); |
|
236 | QCOMPARE(valueSpy.count(), 1); | |
|
237 | ||
|
238 | QList<QVariant> valueSpyArg = valueSpy.takeFirst(); | |
|
239 | // Verify index of removed signal | |
|
240 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
|
241 | QVERIFY(valueSpyArg.at(0).toInt() == 2); | |
|
242 | // Verify count of removed signal | |
|
243 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
|
244 | QVERIFY(valueSpyArg.at(1).toInt() == 1); | |
|
236 | 245 | |
|
237 | 246 | // Remove first |
|
238 | 247 | m_barset->remove(0); // 2.0 4.0 |
|
239 | 248 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
240 | 249 | QCOMPARE(m_barset->at(1).y(), 4.0); |
|
241 | 250 | QCOMPARE(m_barset->count(), 2); |
|
242 | 251 | QCOMPARE(m_barset->sum(), 6.0); |
|
243 | 252 | |
|
253 | QCOMPARE(valueSpy.count(), 1); | |
|
254 | valueSpyArg = valueSpy.takeFirst(); | |
|
255 | // Verify index of removed signal | |
|
256 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
|
257 | QVERIFY(valueSpyArg.at(0).toInt() == 0); | |
|
258 | // Verify count of removed signal | |
|
259 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
|
260 | QVERIFY(valueSpyArg.at(1).toInt() == 1); | |
|
261 | ||
|
262 | ||
|
244 | 263 | // Illegal indexes |
|
245 | 264 | m_barset->remove(4); |
|
246 | 265 | QCOMPARE(m_barset->count(), 2); |
|
247 | 266 | QCOMPARE(m_barset->sum(), 6.0); |
|
248 | 267 | m_barset->remove(-1); |
|
249 | 268 | QCOMPARE(m_barset->count(), 2); |
|
250 | 269 | QCOMPARE(m_barset->sum(), 6.0); |
|
251 | 270 | |
|
252 | QCOMPARE(valueSpy.count(), 2); | |
|
271 | // nothing removed, no signals should be emitted | |
|
272 | QCOMPARE(valueSpy.count(), 0); | |
|
273 | ||
|
274 | // Remove more items than list has | |
|
275 | m_barset->remove(0,312); | |
|
276 | QCOMPARE(m_barset->count(), 0); | |
|
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
278 | ||
|
279 | QCOMPARE(valueSpy.count(), 1); | |
|
280 | valueSpyArg = valueSpy.takeFirst(); | |
|
281 | ||
|
282 | // Verify index of removed signal | |
|
283 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
|
284 | QVERIFY(valueSpyArg.at(0).toInt() == 0); | |
|
285 | // Verify count of removed signal (expect 2 values removed, because list had only 2 items) | |
|
286 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
|
287 | QVERIFY(valueSpyArg.at(1).toInt() == 2); | |
|
253 | 288 | } |
|
254 | 289 | |
|
255 | 290 | void tst_QBarSet::replace_data() |
|
256 | 291 | { |
|
257 | 292 | |
|
258 | 293 | } |
|
259 | 294 | |
|
260 | 295 | void tst_QBarSet::replace() |
|
261 | 296 | { |
|
262 | 297 | QCOMPARE(m_barset->count(), 0); |
|
263 | 298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
264 | 299 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); |
|
265 | 300 | |
|
266 | 301 | m_barset->append(1.0); |
|
267 | 302 | m_barset->append(2.0); |
|
268 | 303 | m_barset->append(3.0); |
|
269 | 304 | m_barset->append(4.0); |
|
270 | 305 | |
|
271 | 306 | QCOMPARE(m_barset->count(), 4); |
|
272 | 307 | QCOMPARE(m_barset->sum(), 10.0); |
|
273 | 308 | |
|
274 | 309 | // Replace first |
|
275 | 310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
276 | 311 | QCOMPARE(m_barset->count(), 4); |
|
277 | 312 | QCOMPARE(m_barset->sum(), 14.0); |
|
278 | 313 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
279 | 314 | |
|
280 | 315 | // Replace last |
|
281 | 316 | m_barset->replace(3, 6.0); |
|
282 | 317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
283 | 318 | QCOMPARE(m_barset->sum(), 16.0); |
|
284 | 319 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
285 | 320 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
286 | 321 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
287 | 322 | QCOMPARE(m_barset->at(3).y(), 6.0); |
|
288 | 323 | |
|
289 | 324 | // Illegal indexes |
|
290 | 325 | m_barset->replace(4, 6.0); |
|
291 | 326 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
292 | 327 | QCOMPARE(m_barset->sum(), 16.0); |
|
293 | 328 | m_barset->replace(-1, 6.0); |
|
294 | 329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
295 | 330 | QCOMPARE(m_barset->sum(), 16.0); |
|
296 | 331 | m_barset->replace(4, QPointF(1.0, 1.0)); |
|
297 | 332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
298 | 333 | QCOMPARE(m_barset->sum(), 16.0); |
|
299 | 334 | m_barset->replace(-1, QPointF(1.0, 1.0)); |
|
300 | 335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
301 | 336 | QCOMPARE(m_barset->sum(), 16.0); |
|
302 | 337 | |
|
303 | 338 | QVERIFY(valueSpy.count() == 2); |
|
304 | 339 | } |
|
305 | 340 | |
|
306 | 341 | void tst_QBarSet::at_data() |
|
307 | 342 | { |
|
308 | 343 | |
|
309 | 344 | } |
|
310 | 345 | |
|
311 | 346 | void tst_QBarSet::at() |
|
312 | 347 | { |
|
313 | 348 | QCOMPARE(m_barset->count(), 0); |
|
314 | 349 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
315 | 350 | |
|
316 | 351 | m_barset->append(1.0); |
|
317 | 352 | m_barset->append(2.0); |
|
318 | 353 | m_barset->append(3.0); |
|
319 | 354 | m_barset->append(4.0); |
|
320 | 355 | |
|
321 | 356 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
322 | 357 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
323 | 358 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
324 | 359 | QCOMPARE(m_barset->at(3).y(), 4.0); |
|
325 | 360 | } |
|
326 | 361 | |
|
327 | 362 | void tst_QBarSet::atOperator_data() |
|
328 | 363 | { |
|
329 | 364 | |
|
330 | 365 | } |
|
331 | 366 | |
|
332 | 367 | void tst_QBarSet::atOperator() |
|
333 | 368 | { |
|
334 | 369 | QCOMPARE(m_barset->count(), 0); |
|
335 | 370 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
336 | 371 | |
|
337 | 372 | m_barset->append(1.0); |
|
338 | 373 | m_barset->append(2.0); |
|
339 | 374 | m_barset->append(3.0); |
|
340 | 375 | m_barset->append(4.0); |
|
341 | 376 | |
|
342 | 377 | QCOMPARE(m_barset->operator [](0).y(), 1.0); |
|
343 | 378 | QCOMPARE(m_barset->operator [](1).y(), 2.0); |
|
344 | 379 | QCOMPARE(m_barset->operator [](2).y(), 3.0); |
|
345 | 380 | QCOMPARE(m_barset->operator [](3).y(), 4.0); |
|
346 | 381 | } |
|
347 | 382 | |
|
348 | 383 | void tst_QBarSet::count_data() |
|
349 | 384 | { |
|
350 | 385 | |
|
351 | 386 | } |
|
352 | 387 | |
|
353 | 388 | void tst_QBarSet::count() |
|
354 | 389 | { |
|
355 | 390 | QCOMPARE(m_barset->count(), 0); |
|
356 | 391 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
357 | 392 | |
|
358 | 393 | m_barset->append(1.0); |
|
359 | 394 | QCOMPARE(m_barset->count(),1); |
|
360 | 395 | m_barset->append(2.0); |
|
361 | 396 | QCOMPARE(m_barset->count(),2); |
|
362 | 397 | m_barset->append(3.0); |
|
363 | 398 | QCOMPARE(m_barset->count(),3); |
|
364 | 399 | m_barset->append(4.0); |
|
365 | 400 | QCOMPARE(m_barset->count(),4); |
|
366 | 401 | } |
|
367 | 402 | |
|
368 | 403 | void tst_QBarSet::sum_data() |
|
369 | 404 | { |
|
370 | 405 | |
|
371 | 406 | } |
|
372 | 407 | |
|
373 | 408 | void tst_QBarSet::sum() |
|
374 | 409 | { |
|
375 | 410 | QCOMPARE(m_barset->count(), 0); |
|
376 | 411 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
377 | 412 | |
|
378 | 413 | m_barset->append(1.0); |
|
379 | 414 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); |
|
380 | 415 | m_barset->append(2.0); |
|
381 | 416 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); |
|
382 | 417 | m_barset->append(3.0); |
|
383 | 418 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); |
|
384 | 419 | m_barset->append(4.0); |
|
385 | 420 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); |
|
386 | 421 | } |
|
387 | 422 | |
|
388 | 423 | void tst_QBarSet::customize() |
|
389 | 424 | { |
|
390 | 425 | // Create sets |
|
391 | 426 | QBarSet *set1 = new QBarSet("set1"); |
|
392 | 427 | QBarSet *set2 = new QBarSet("set2"); |
|
393 | 428 | |
|
394 | 429 | // Append set1 to series |
|
395 | 430 | QGroupedBarSeries *series = new QGroupedBarSeries(); |
|
396 | 431 | bool success = series->append(set1); |
|
397 | 432 | QVERIFY(success); |
|
398 | 433 | |
|
399 | 434 | // Add series to the chart |
|
400 | 435 | QChartView view(new QChart()); |
|
401 | 436 | view.resize(200, 200); |
|
402 | 437 | view.chart()->addSeries(series); |
|
403 | 438 | view.show(); |
|
404 | 439 | QTest::qWaitForWindowShown(&view); |
|
405 | 440 | |
|
406 | 441 | // Test adding data to the sets |
|
407 | 442 | *set1 << 1 << 2 << 1 << 3; |
|
408 | 443 | *set2 << 2 << 1 << 3 << 1; |
|
409 | 444 | |
|
410 | 445 | // Test pen |
|
411 | 446 | QVERIFY(set1->pen() != QPen()); |
|
412 | 447 | QVERIFY(set2->pen() == QPen()); |
|
413 | 448 | QPen pen(QColor(128,128,128,128)); |
|
414 | 449 | set1->setPen(pen); |
|
415 | 450 | QVERIFY(set1->pen() == pen); |
|
416 | 451 | QVERIFY(set2->pen() == QPen()); |
|
417 | 452 | |
|
418 | 453 | // Test brush |
|
419 | 454 | QVERIFY(set1->brush() != QBrush()); |
|
420 | 455 | QVERIFY(set2->brush() == QBrush()); |
|
421 | 456 | QBrush brush(QColor(128,128,128,128)); |
|
422 | 457 | set1->setBrush(brush); |
|
423 | 458 | QVERIFY(set1->brush() == brush); |
|
424 | 459 | QVERIFY(set2->brush() == QBrush()); |
|
425 | 460 | |
|
426 | 461 | // Test label brush |
|
427 | 462 | QVERIFY(set1->labelBrush() != QBrush()); |
|
428 | 463 | QVERIFY(set2->labelBrush() == QBrush()); |
|
429 | 464 | set1->setLabelBrush(brush); |
|
430 | 465 | QVERIFY(set1->labelBrush() == brush); |
|
431 | 466 | QVERIFY(set2->labelBrush() == QBrush()); |
|
432 | 467 | |
|
433 | 468 | // Test label font |
|
434 | 469 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the |
|
435 | 470 | // same for the set added to the series (depending on the QChart's theme configuration) |
|
436 | 471 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); |
|
437 | 472 | QVERIFY(set2->labelFont() == QFont()); |
|
438 | 473 | QFont font; |
|
439 | 474 | font.setBold(true); |
|
440 | 475 | font.setItalic(true); |
|
441 | 476 | set1->setLabelFont(font); |
|
442 | 477 | QVERIFY(set1->labelFont() == font); |
|
443 | 478 | QVERIFY(set2->labelFont() == QFont()); |
|
444 | 479 | |
|
445 | 480 | // Test adding data to the sets |
|
446 | 481 | *set1 << 1 << 2 << 1 << 3; |
|
447 | 482 | *set2 << 2 << 1 << 3 << 1; |
|
448 | 483 | } |
|
449 | 484 | |
|
450 | 485 | QTEST_MAIN(tst_QBarSet) |
|
451 | 486 | |
|
452 | 487 | #include "tst_qbarset.moc" |
|
453 | 488 |
General Comments 0
You need to be logged in to leave comments.
Login now