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