##// END OF EJS Templates
QML methods of series: several fixes and documentation
Tero Ahola -
r1521:dbd0ff0f2ce9
parent child
Show More
@@ -20,6 +20,7
20 <li><a href="qml-chartview.html">ChartView</a></li>
20 <li><a href="qml-chartview.html">ChartView</a></li>
21 <li><a href="qml-axis.html">Axis</a></li>
21 <li><a href="qml-axis.html">Axis</a></li>
22 <li><a href="qml-legend.html">Legend</a></li>
22 <li><a href="qml-legend.html">Legend</a></li>
23 <li><a href="qml-abstractseries.html">AbstractSeries</a></li>
23 </ul>
24 </ul>
24 </td>
25 </td>
25 </tr>
26 </tr>
@@ -31,6 +32,7
31 <tr>
32 <tr>
32 <td valign="top">
33 <td valign="top">
33 <ul>
34 <ul>
35 <li><a href="qml-xyseries.html">XYSeries</a></li>
34 <li><a href="qml-lineseries.html">LineSeries</a></li>
36 <li><a href="qml-lineseries.html">LineSeries</a></li>
35 <li><a href="qml-areaseries.html">AreaSeries</a></li>
37 <li><a href="qml-areaseries.html">AreaSeries</a></li>
36 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
38 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
@@ -126,10 +126,16 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
126
126
127 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
127 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
128 {
128 {
129 int insertIndex = index;
130 if (insertIndex < 0)
131 insertIndex = 0;
132 else if (insertIndex > count())
133 insertIndex = count();
134
129 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
135 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
130 barset->setLabel(label);
136 barset->setLabel(label);
131 barset->setValues(values);
137 barset->setValues(values);
132 if (QBarSeries::insert(index, barset))
138 if (QBarSeries::insert(insertIndex, barset))
133 return barset;
139 return barset;
134 delete barset;
140 delete barset;
135 return 0;
141 return 0;
@@ -107,9 +107,58 QTCOMMERCIALCHART_BEGIN_NAMESPACE
107 */
107 */
108
108
109 /*!
109 /*!
110 \qmlmethod AbstractSeries ChartView::series(int index)
111 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
112 the count property of the chart.
113 */
114
115 /*!
116 \qmlmethod AbstractSeries ChartView::series(string name)
117 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
118 */
119
120 /*!
121 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
122 Creates a series object of \a type to the chart. For example:
123 \code
124 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
125 scatter.markerSize = 22;
126 scatter.append(1.1, 2.0);
127 \endcode
128 */
129
130 /*!
110 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
131 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
111 The y-axis of the series. This is the same as the default y-axis of the chart, unless you have
132 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
112 explicitly defined the series to have a non-default y-axis.
133 */
134
135 /*!
136 \qmlmethod ChartView::zoomY(real factor)
137 Zooms in by \a factor on the center of the chart.
138 */
139
140 /*!
141 \qmlmethod ChartView::scrollLeft(real pixels)
142 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
143 \sa Axis::min, Axis::max
144 */
145
146 /*!
147 \qmlmethod ChartView::scrollRight(real pixels)
148 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
149 \sa Axis::min, Axis::max
150 */
151
152 /*!
153 \qmlmethod ChartView::scrollUp(real pixels)
154 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
155 \sa Axis::min, Axis::max
156 */
157
158 /*!
159 \qmlmethod ChartView::scrollDown(real pixels)
160 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
161 \sa Axis::min, Axis::max
113 */
162 */
114
163
115 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
164 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
@@ -100,7 +100,6 public:
100 void setTitle(QString title);
100 void setTitle(QString title);
101 QString title();
101 QString title();
102 QAxis *axisX();
102 QAxis *axisX();
103 Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0);
104 QLegend *legend();
103 QLegend *legend();
105 QVariantList axisXLabels();
104 QVariantList axisXLabels();
106 void setAxisXLabels(QVariantList list);
105 void setAxisXLabels(QVariantList list);
@@ -113,14 +112,17 public:
113 int count();
112 int count();
114 void setDropShadowEnabled(bool enabled);
113 void setDropShadowEnabled(bool enabled);
115 bool dropShadowEnabled();
114 bool dropShadowEnabled();
115
116 public:
117 Q_INVOKABLE QAbstractSeries *series(int index);
118 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
119 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
120 Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0);
116 Q_INVOKABLE void zoom(qreal factor);
121 Q_INVOKABLE void zoom(qreal factor);
117 Q_INVOKABLE void scrollLeft(qreal pixels);
122 Q_INVOKABLE void scrollLeft(qreal pixels);
118 Q_INVOKABLE void scrollRight(qreal pixels);
123 Q_INVOKABLE void scrollRight(qreal pixels);
119 Q_INVOKABLE void scrollUp(qreal pixels);
124 Q_INVOKABLE void scrollUp(qreal pixels);
120 Q_INVOKABLE void scrollDown(qreal pixels);
125 Q_INVOKABLE void scrollDown(qreal pixels);
121 Q_INVOKABLE QAbstractSeries *series(int index);
122 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
123 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
124
126
125 Q_SIGNALS:
127 Q_SIGNALS:
126 void axisLabelsChanged();
128 void axisLabelsChanged();
@@ -47,13 +47,13 public: // from QDeclarativeParserStatus
47 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void classBegin() { DeclarativeXySeries::classBegin(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
49
49
50 public: // from QLineSeries
50 public:
51 Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); }
51 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QLineSeries::replace(oldX, oldY, newX, newY); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { QLineSeries::insert(index, QPointF(x, y)); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
55 Q_INVOKABLE void clear() { QLineSeries::clear(); }
55 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
56 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
56 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
57
57
58 Q_SIGNALS:
58 Q_SIGNALS:
59 void countChanged(int count);
59 void countChanged(int count);
@@ -46,13 +46,13 public: // from QDeclarativeParserStatus
46 void classBegin() { DeclarativeXySeries::classBegin(); }
46 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void componentComplete() { DeclarativeXySeries::componentComplete(); }
47 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48
48
49 public: // from QScatterSeries
49 public:
50 Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); }
50 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
51 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QScatterSeries::replace(oldX, oldY, newX, newY); }
51 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
52 Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); }
52 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
53 Q_INVOKABLE void clear() { QScatterSeries::clear(); }
53 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { QScatterSeries::insert(index, QPointF(x, y)); }
54 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
55 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
55 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
56
56
57 Q_SIGNALS:
57 Q_SIGNALS:
58 void countChanged(int count);
58 void countChanged(int count);
@@ -47,13 +47,13 public: // from QDeclarativeParserStatus
47 void classBegin() { DeclarativeXySeries::classBegin(); }
47 void classBegin() { DeclarativeXySeries::classBegin(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
48 void componentComplete() { DeclarativeXySeries::componentComplete(); }
49
49
50 public: // from QSplineSeries
50 public:
51 Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); }
51 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QSplineSeries::replace(oldX, oldY, newX, newY); }
52 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); }
53 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
54 Q_INVOKABLE void clear() { QSplineSeries::clear(); }
54 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
55 Q_INVOKABLE void insert(int index, qreal x, qreal y) { QSplineSeries::insert(index, QPointF(x, y)); }
55 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
56 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
56 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
57
57
58 Q_SIGNALS:
58 Q_SIGNALS:
59 void countChanged(int count);
59 void countChanged(int count);
@@ -59,19 +59,48 void DeclarativeXySeries::componentComplete()
59 }
59 }
60 }
60 }
61
61
62 DeclarativeXyPoint *DeclarativeXySeries::at(int index)
62 void DeclarativeXySeries::append(qreal x, qreal y)
63 {
63 {
64 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
64 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
65 Q_ASSERT(series);
65 Q_ASSERT(series);
66 if (index < series->count()) {
66 series->append(x, y);
67 QPointF point = series->points().at(index);
68 DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series);
69 xyPoint->setX(point.x());
70 xyPoint->setY(point.y());
71 return xyPoint;
72 }
73 return 0;
74 }
67 }
75
68
69 void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
70 {
71 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
72 Q_ASSERT(series);
73 series->replace(oldX, oldY, newX, newY);
74 }
75
76 void DeclarativeXySeries::remove(qreal x, qreal y)
77 {
78 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
79 Q_ASSERT(series);
80 series->remove(x, y);
81 }
82
83 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
84 {
85 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
86 Q_ASSERT(series);
87 series->insert(index, QPointF(x, y));
88 }
89
90 void DeclarativeXySeries::clear()
91 {
92 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
93 Q_ASSERT(series);
94 series->clear();
95 }
96
97 QPointF DeclarativeXySeries::at(int index)
98 {
99 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
100 Q_ASSERT(series);
101 if (index >= 0 || index < series->count())
102 return series->points().at(index);
103 return QPointF(0, 0);
104 }
76
105
77 QTCOMMERCIALCHART_END_NAMESPACE
106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -41,7 +41,13 public:
41 void classBegin();
41 void classBegin();
42 void componentComplete();
42 void componentComplete();
43 virtual QXYSeries *xySeries() = 0;
43 virtual QXYSeries *xySeries() = 0;
44 DeclarativeXyPoint *at(int index);
44
45 void append(qreal x, qreal y);
46 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
47 void remove(qreal x, qreal y);
48 void insert(int index, qreal x, qreal y);
49 void clear();
50 QPointF at(int index);
45 };
51 };
46
52
47 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -47,14 +47,15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 */
47 */
48 /*!
48 /*!
49 \qmlclass BarSeries QBarSeries
49 \qmlclass BarSeries QBarSeries
50 \inherits AbstractSeries
51
52 The following QML shows how to create a simple bar chart:
53 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
50
54
51 \beginfloatleft
55 \beginfloatleft
52 \image demos_qmlchart6.png
56 \image demos_qmlchart6.png
53 \endfloat
57 \endfloat
54 \clearfloat
58 \clearfloat
55
56 The following QML shows how to create a simple bar chart:
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
58 */
59 */
59
60
60 /*!
61 /*!
@@ -155,6 +156,39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
155 */
156 */
156
157
157 /*!
158 /*!
159 \qmlmethod BarSet BarSeries::at(int index)
160 Returns bar set at \a index. Returns null if the index is not valid.
161 */
162
163 /*!
164 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XyPoints.
166 For example:
167 \code
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 \endcode
171 */
172
173 /*!
174 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XyPoints.
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 appended.
178 \sa BarSeries::append()
179 */
180
181 /*!
182 \qmlmethod bool BarSeries::remove(BarSet barset)
183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 */
185
186 /*!
187 \qmlmethod BarSeries::clear()
188 Removes all barsets from the series.
189 */
190
191 /*!
158 Constructs empty QBarSeries.
192 Constructs empty QBarSeries.
159 QBarSeries is QObject which is a child of a \a parent.
193 QBarSeries is QObject which is a child of a \a parent.
160 */
194 */
@@ -50,6 +50,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 */
50 */
51 /*!
51 /*!
52 \qmlclass PieSeries QPieSeries
52 \qmlclass PieSeries QPieSeries
53 \inherits AbstractSeries
53
54
54 The following QML shows how to create a simple pie chart.
55 The following QML shows how to create a simple pie chart.
55
56
@@ -271,6 +272,31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
271 */
272 */
272
273
273 /*!
274 /*!
275 \qmlmethod PieSlice PieSeries::at(int index)
276 Returns slice at \a index. Returns null if the index is not valid.
277 */
278
279 /*!
280 \qmlmethod PieSlice PieSeries::find(string label)
281 Returns the first slice with \a label. Returns null if the index is not valid.
282 */
283
284 /*!
285 \qmlmethod PieSlice PieSeries::append(string label, real value)
286 Adds a new slice with \a label and \a value to the pie.
287 */
288
289 /*!
290 \qmlmethod bool PieSeries::remove(PieSlice slice)
291 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
292 */
293
294 /*!
295 \qmlmethod PieSeries::clear()
296 Removes all slices from the pie.
297 */
298
299 /*!
274 Constructs a series object which is a child of \a parent.
300 Constructs a series object which is a child of \a parent.
275 */
301 */
276 QPieSeries::QPieSeries(QObject *parent) :
302 QPieSeries::QPieSeries(QObject *parent) :
@@ -33,6 +33,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
34 QPercentBarSeries, QPieSeries
34 QPercentBarSeries, QPieSeries
35 */
35 */
36 /*!
37 \qmlclass AbstractSeries
38 AbstractSeries is the base class for all series.
39 The class cannot be instantiated by the user.
40 */
36
41
37 /*!
42 /*!
38 \enum QAbstractSeries::SeriesType
43 \enum QAbstractSeries::SeriesType
@@ -54,18 +59,27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
54 \property QAbstractSeries::type
59 \property QAbstractSeries::type
55 The type of the series.
60 The type of the series.
56 */
61 */
62 /*!
63 \qmlproperty ChartView.SeriesType AbstractSeries::type
64 The type of the series.
65 */
57
66
58 /*!
67 /*!
59 \property QAbstractSeries::name
68 \property QAbstractSeries::name
60 \brief name of the series property
69 \brief name of the series property. The name is shown in legend for QXYSeries.
70 */
71 /*!
72 \qmlproperty string AbstractSeries::name
73 Name of the series. The name is shown in legend for QXYSeries.
61 */
74 */
62
75
63 /*!
76 /*!
64 \fn void QAbstractSeries::nameChanged()
77 \fn void QAbstractSeries::nameChanged()
65
66 This signal is emitted when the series name changes.
78 This signal is emitted when the series name changes.
67
79 */
68 \sa name
80 /*!
81 \qmlsignal AbstractSeries::nameChanged()
82 This signal is emitted when the series name changes.
69 */
83 */
70
84
71 /*!
85 /*!
@@ -96,14 +110,6 QAbstractSeries::~QAbstractSeries()
96 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
110 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
97 }
111 }
98
112
99 /*!
100 \brief Sets a \a name for the series.
101
102 The name of a series is shown in the legend for QXYSeries.
103 \sa QChart::setTitle()
104 \sa QPieSlice::setLabel()
105 \sa QBarSet::setName()
106 */
107 void QAbstractSeries::setName(const QString& name)
113 void QAbstractSeries::setName(const QString& name)
108 {
114 {
109 if (name != d_ptr->m_name) {
115 if (name != d_ptr->m_name) {
@@ -112,10 +118,6 void QAbstractSeries::setName(const QString& name)
112 }
118 }
113 }
119 }
114
120
115 /*!
116 \brief Returns the name of the series.
117 \sa setName()
118 */
119 QString QAbstractSeries::name() const
121 QString QAbstractSeries::name() const
120 {
122 {
121 return d_ptr->m_name;
123 return d_ptr->m_name;
@@ -31,7 +31,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 */
31 */
32 /*!
32 /*!
33 \qmlclass XYSeries
33 \qmlclass XYSeries
34 \brief The XYSeries class is a base class for line, spline and scatter series.
34 \inherits AbstractSeries
35 The XYSeries class is a base class for line, spline and scatter series.
35
36
36 The class cannot be instantiated directly.
37 The class cannot be instantiated directly.
37 */
38 */
@@ -130,7 +131,30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
130 */
131 */
131
132
132 /*!
133 /*!
133 \qmlmethod XyPoint XYSeries::at(int index)
134 \qmlmethod XYSeries::append(real x, real y)
135 Append point (\a x, \a y) to the series
136 */
137
138 /*!
139 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
140 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
141 exist.
142 */
143
144 /*!
145 \qmlmethod XYSeries::remove(real x, real y)
146 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
147 */
148
149 /*!
150 \qmlmethod XYSeries::insert(int index, real x, real y)
151 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
152 points. If index is the same as or bigger than count, the point is appended to the list of points.
153 */
154
155 /*!
156 \qmlmethod QPointF XYSeries::at(int index)
157 Returns point at \a index. Returns (0, 0) if the index is not valid.
134 */
158 */
135
159
136 /*!
160 /*!
@@ -44,6 +44,25 void tst_QXYSeries::cleanup()
44 m_series = 0;
44 m_series = 0;
45 }
45 }
46
46
47 void tst_QXYSeries::seriesName()
48 {
49 QSignalSpy nameSpy(m_series, SIGNAL(nameChanged()));
50 QCOMPARE(m_series->name(), QString());
51 m_series->setName("seriesname");
52 QCOMPARE(m_series->name(), QString("seriesname"));
53 TRY_COMPARE(nameSpy.count(), 1);
54 }
55
56 void tst_QXYSeries::seriesVisible()
57 {
58 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
59 QCOMPARE(m_series->isVisible(), true);
60 m_series->setVisible(false);
61 QCOMPARE(m_series->isVisible(), false);
62 m_series->setVisible(true);
63 TRY_COMPARE(visibleSpy.count(), 2);
64 }
65
47 void tst_QXYSeries::append_data()
66 void tst_QXYSeries::append_data()
48 {
67 {
49 QTest::addColumn< QList<QPointF> >("points");
68 QTest::addColumn< QList<QPointF> >("points");
@@ -61,8 +80,10 void tst_QXYSeries::append_raw()
61 {
80 {
62 QFETCH(QList<QPointF>, points);
81 QFETCH(QList<QPointF>, points);
63 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
82 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
83 QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int)));
64 m_series->append(points);
84 m_series->append(points);
65 TRY_COMPARE(spy0.count(), 0);
85 TRY_COMPARE(spy0.count(), 0);
86 TRY_COMPARE(addedSpy.count(), points.count());
66 QCOMPARE(m_series->points(), points);
87 QCOMPARE(m_series->points(), points);
67 }
88 }
68
89
@@ -233,13 +254,18 void tst_QXYSeries::replace_raw_data()
233 void tst_QXYSeries::replace_raw()
254 void tst_QXYSeries::replace_raw()
234 {
255 {
235 QFETCH(QList<QPointF>, points);
256 QFETCH(QList<QPointF>, points);
236 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
257 QSignalSpy replacedSpy(m_series, SIGNAL(pointReplaced(int)));
237 m_series->append(points);
258 m_series->append(points);
238 TRY_COMPARE(spy0.count(), 0);
259 TRY_COMPARE(replacedSpy.count(), 0);
239 QCOMPARE(m_series->points(), points);
260 QCOMPARE(m_series->points(), points);
240
261
241 foreach(const QPointF& point,points)
262 foreach(const QPointF& point, points)
242 m_series->replace(point.x(),point.y(),point.x(),0);
263 m_series->replace(point.x(),point.y(),point.x(),0);
264 TRY_COMPARE(replacedSpy.count(), points.count());
265
266 // Replace a point that does not exist
267 m_series->replace(-123, 999, 0, 0);
268 TRY_COMPARE(replacedSpy.count(), points.count());
243
269
244 QList<QPointF> newPoints = m_series->points();
270 QList<QPointF> newPoints = m_series->points();
245
271
@@ -276,6 +302,27 void tst_QXYSeries::replace_chart_animation()
276 replace_chart();
302 replace_chart();
277 }
303 }
278
304
305 void tst_QXYSeries::insert_data()
306 {
307 append_data();
308 }
309
310 void tst_QXYSeries::insert()
311 {
312 QFETCH(QList<QPointF>, points);
313 m_series->append(points);
314
315 QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int)));
316
317 m_series->insert(0, QPointF(5, 5));
318 TRY_COMPARE(addedSpy.count(), 1);
319 QCOMPARE(m_series->points().count(), points.count() + 1);
320
321 m_series->insert(m_series->count(), QPointF(6, 6));
322 TRY_COMPARE(addedSpy.count(), 2);
323 QCOMPARE(m_series->points().count(), points.count() + 2);
324 }
325
279 void tst_QXYSeries::oper_data()
326 void tst_QXYSeries::oper_data()
280 {
327 {
281 append_data();
328 append_data();
@@ -40,6 +40,8 public slots:
40 virtual void cleanup();
40 virtual void cleanup();
41
41
42 private slots:
42 private slots:
43 void seriesName();
44 void seriesVisible();
43 void oper_data();
45 void oper_data();
44 void oper();
46 void oper();
45 void pen_data();
47 void pen_data();
@@ -74,6 +76,8 private slots:
74 void replace_chart();
76 void replace_chart();
75 void replace_chart_animation_data();
77 void replace_chart_animation_data();
76 void replace_chart_animation();
78 void replace_chart_animation();
79 void insert_data();
80 void insert();
77 void changedSignals();
81 void changedSignals();
78 protected:
82 protected:
79 void append_data();
83 void append_data();
@@ -57,7 +57,7 Flow {
57 }
57 }
58 Button {
58 Button {
59 text: "insert point"
59 text: "insert point"
60 onClicked: series.insert(0, series.count - 1, series.count - 1);
60 onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2);
61 }
61 }
62 Button {
62 Button {
63 text: "clear"
63 text: "clear"
@@ -69,7 +69,7 Flow {
69 }
69 }
70 Button {
70 Button {
71 text: "insert point"
71 text: "insert point"
72 onClicked: series.insert(0, series.count - 1, series.count - 1);
72 onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2);
73 }
73 }
74 Button {
74 Button {
75 text: "clear"
75 text: "clear"
General Comments 0
You need to be logged in to leave comments. Login now