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