##// END OF EJS Templates
added stream operator to scatter series
Tero Ahola -
r180:6a67b4477dab
parent child
Show More
@@ -13,14 +13,15 int main(int argc, char *argv[])
13 13
14 14 // Create widget and scatter series
15 15 QChartView *chartWidget = new QChartView();
16 QScatterSeries *scatter =
17 qobject_cast<QScatterSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypeScatter));
18 Q_ASSERT(scatter);
16 QScatterSeries *scatter = new QScatterSeries();
19 17
20 18 // Add test data to the series
21 19 for (qreal i(0.0); i < 20; i += 0.5)
22 scatter->addData(QPointF(i + ((qreal)(rand() % 100)) / 100,
23 i + ((qreal)(rand() % 100)) / 100 ));
20 (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0,
21 i + (qreal)(rand() % 100) / 100.0);
22
23 // Add series to the chart widget
24 chartWidget->addSeries(scatter);
24 25
25 26 // Use the chart widget as the central widget
26 27 QMainWindow w;
@@ -23,12 +23,17 void DeclarativeSeries::setSeriesType(SeriesType type)
23 23 if (!m_series || type != m_seriesType) {
24 24 m_seriesType = type;
25 25 initSeries();
26 } else {
27 m_seriesType = type;
26 28 }
27 29 }
28 30
29 31 void DeclarativeSeries::setParentForSeries()
30 32 {
31 initSeries();
33 if (!m_series)
34 initSeries();
35 else if (m_series->type() != m_seriesType)
36 initSeries();
32 37 }
33 38
34 39 void DeclarativeSeries::initSeries()
@@ -20,17 +20,22 QScatterSeries::~QScatterSeries()
20 20 delete d;
21 21 }
22 22
23 // TODO: change to list of QPointFs?
24 //bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist)
25 void QScatterSeries::setData(QList<QPointF> data)
23 void QScatterSeries::addData(QPointF value)
26 24 {
27 d->m_data = data;
25 d->m_data.append(value);
26 emit changed();
27 }
28
29 QScatterSeries& QScatterSeries::operator << (const QPointF &value)
30 {
31 d->m_data.append(value);
28 32 emit changed();
33 return *this;
29 34 }
30 35
31 void QScatterSeries::addData(QPointF data)
36 void QScatterSeries::setData(QList<QPointF> data)
32 37 {
33 d->m_data.append(data);
38 d->m_data = data;
34 39 emit changed();
35 40 }
36 41
@@ -20,8 +20,9 public: // from QChartSeries
20 20 QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; }
21 21
22 22 public:
23 // TODO: the name of the function? addPoint? addData? addX?
24 void addData(QPointF data);
23 // TODO: the name of the function? addPoint? addData? addValue?
24 void addData(QPointF value);
25 QScatterSeries& operator << (const QPointF &value);
25 26
26 27 void setData(QList<QPointF> data);
27 28
@@ -227,11 +227,10 void MainWidget::addSeries(QString series, QString data)
227 227 // TODO: color of the series
228 228 QChartSeries *newSeries = 0;
229 229 if (series == "Scatter") {
230 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
231 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(newSeries);
232 Q_ASSERT(scatterSeries);
230 QScatterSeries *scatter = new QScatterSeries();
233 231 for (int i(0); i < x.count() && i < y.count(); i++)
234 scatterSeries->addData(QPointF(x.at(i), y.at(i)));
232 (*scatter) << QPointF(x.at(i), y.at(i));
233 m_chartWidget->addSeries(scatter);
235 234 } else if (series == "Pie") {
236 235 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
237 236 Q_ASSERT(newSeries->setData(y));
@@ -306,26 +305,28 void MainWidget::addSeries(QString series, QString data)
306 305
307 306 void MainWidget::setCurrentSeries(QChartSeries *series)
308 307 {
309 m_currentSeries = series;
310 switch (m_currentSeries->type()) {
311 case QChartSeries::SeriesTypeLine:
312 break;
313 case QChartSeries::SeriesTypeScatter:
314 break;
315 case QChartSeries::SeriesTypePie:
316 break;
317 case QChartSeries::SeriesTypeBar:
318 qDebug() << "setCurrentSeries (bar)";
319 break;
320 case QChartSeries::SeriesTypeStackedBar:
321 qDebug() << "setCurrentSeries (Stackedbar)";
322 break;
323 case QChartSeries::SeriesTypePercentBar:
324 qDebug() << "setCurrentSeries (Percentbar)";
325 break;
326 default:
327 Q_ASSERT(false);
328 break;
308 if (series) {
309 m_currentSeries = series;
310 switch (m_currentSeries->type()) {
311 case QChartSeries::SeriesTypeLine:
312 break;
313 case QChartSeries::SeriesTypeScatter:
314 break;
315 case QChartSeries::SeriesTypePie:
316 break;
317 case QChartSeries::SeriesTypeBar:
318 qDebug() << "setCurrentSeries (bar)";
319 break;
320 case QChartSeries::SeriesTypeStackedBar:
321 qDebug() << "setCurrentSeries (Stackedbar)";
322 break;
323 case QChartSeries::SeriesTypePercentBar:
324 qDebug() << "setCurrentSeries (Percentbar)";
325 break;
326 default:
327 Q_ASSERT(false);
328 break;
329 }
329 330 }
330 331 }
331 332
General Comments 0
You need to be logged in to leave comments. Login now