@@ -1,85 +1,86 | |||||
1 | #include "DeclarativeXySeries.h" |
|
1 | //#include "DeclarativeXySeries.h" | |
|
2 | #include "declarativexyseries.h" | |||
2 | #include "declarativechart.h" |
|
3 | #include "declarativechart.h" | |
3 | #include "qchart.h" |
|
4 | #include "qchart.h" | |
4 | #include "qxyseries.h" |
|
5 | #include "qxyseries.h" | |
5 | #include "qareaseries.h" |
|
6 | #include "qareaseries.h" | |
6 | #include "qsplineseries.h" |
|
7 | #include "qsplineseries.h" | |
7 | #include "qscatterseries.h" |
|
8 | #include "qscatterseries.h" | |
8 |
|
9 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
11 | |||
11 | DeclarativeXySeries::DeclarativeXySeries(QSeries::QSeriesType type, QDeclarativeItem *parent) : |
|
12 | DeclarativeXySeries::DeclarativeXySeries(QSeries::QSeriesType type, QDeclarativeItem *parent) : | |
12 | QDeclarativeItem(parent), |
|
13 | QDeclarativeItem(parent), | |
13 | m_seriesType(type), |
|
14 | m_seriesType(type), | |
14 | m_chart(0), |
|
15 | m_chart(0), | |
15 | m_series(0) |
|
16 | m_series(0) | |
16 | { |
|
17 | { | |
17 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
18 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
18 | } |
|
19 | } | |
19 |
|
20 | |||
20 | DeclarativeXySeries::~DeclarativeXySeries() |
|
21 | DeclarativeXySeries::~DeclarativeXySeries() | |
21 | { |
|
22 | { | |
22 | } |
|
23 | } | |
23 |
|
24 | |||
24 | void DeclarativeXySeries::componentComplete() |
|
25 | void DeclarativeXySeries::componentComplete() | |
25 | { |
|
26 | { | |
26 | Q_ASSERT(!m_series); |
|
27 | Q_ASSERT(!m_series); | |
27 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
28 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
28 |
|
29 | |||
29 | if (declarativeChart) { |
|
30 | if (declarativeChart) { | |
30 | m_chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
31 | m_chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
31 | Q_ASSERT(m_chart); |
|
32 | Q_ASSERT(m_chart); | |
32 |
|
33 | |||
33 | switch (m_seriesType) { |
|
34 | switch (m_seriesType) { | |
34 | case QSeries::SeriesTypeLine: |
|
35 | case QSeries::SeriesTypeLine: | |
35 | qDebug() << "creating line series for chart: " << m_chart; |
|
36 | qDebug() << "creating line series for chart: " << m_chart; | |
36 | m_series = new QLineSeries(); |
|
37 | m_series = new QLineSeries(); | |
37 | break; |
|
38 | break; | |
38 | case QSeries::SeriesTypeArea: |
|
39 | case QSeries::SeriesTypeArea: | |
39 | qDebug() << "TODO: creating area series for chart: " << m_chart; |
|
40 | qDebug() << "TODO: creating area series for chart: " << m_chart; | |
40 | // m_series = new QAreaSeries(); |
|
41 | // m_series = new QAreaSeries(); | |
41 | break; |
|
42 | break; | |
42 | case QSeries::SeriesTypeSpline: |
|
43 | case QSeries::SeriesTypeSpline: | |
43 | qDebug() << "creating spline series for chart: " << m_chart; |
|
44 | qDebug() << "creating spline series for chart: " << m_chart; | |
44 | m_series = new QSplineSeries(); |
|
45 | m_series = new QSplineSeries(); | |
45 | break; |
|
46 | break; | |
46 | case QSeries::SeriesTypeScatter: |
|
47 | case QSeries::SeriesTypeScatter: | |
47 | qDebug() << "creating scatter series for chart: " << m_chart; |
|
48 | qDebug() << "creating scatter series for chart: " << m_chart; | |
48 | m_series = new QScatterSeries(); |
|
49 | m_series = new QScatterSeries(); | |
49 | break; |
|
50 | break; | |
50 | default: |
|
51 | default: | |
51 | Q_ASSERT(false); |
|
52 | Q_ASSERT(false); | |
52 | } |
|
53 | } | |
53 |
|
54 | |||
54 | for (int i(0); i < m_points.count(); i++) { |
|
55 | for (int i(0); i < m_points.count(); i++) { | |
55 | DeclarativeXyPoint *element = m_points.at(i); |
|
56 | DeclarativeXyPoint *element = m_points.at(i); | |
56 | m_series->add(element->x(), element->y()); |
|
57 | m_series->add(element->x(), element->y()); | |
57 | } |
|
58 | } | |
58 | m_chart->addSeries(m_series); |
|
59 | m_chart->addSeries(m_series); | |
59 | } |
|
60 | } | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXySeries::points() |
|
63 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXySeries::points() | |
63 | { |
|
64 | { | |
64 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
65 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
68 | void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
68 | DeclarativeXyPoint *element) |
|
69 | DeclarativeXyPoint *element) | |
69 | { |
|
70 | { | |
70 | DeclarativeXySeries *series = qobject_cast<DeclarativeXySeries *>(list->object); |
|
71 | DeclarativeXySeries *series = qobject_cast<DeclarativeXySeries *>(list->object); | |
71 | qDebug() << "appendPoints: " << series; |
|
72 | qDebug() << "appendPoints: " << series; | |
72 | qDebug() << "appendPoints: " << element; |
|
73 | qDebug() << "appendPoints: " << element; | |
73 | qDebug() << "appendPoints: " << element->x(); |
|
74 | qDebug() << "appendPoints: " << element->x(); | |
74 | qDebug() << "appendPoints: " << element->y(); |
|
75 | qDebug() << "appendPoints: " << element->y(); | |
75 | qDebug() << "appendPoints: " << series->m_series; |
|
76 | qDebug() << "appendPoints: " << series->m_series; | |
76 | if (series) { |
|
77 | if (series) { | |
77 | series->m_points.append(element); |
|
78 | series->m_points.append(element); | |
78 | if (series->m_series) |
|
79 | if (series->m_series) | |
79 | series->m_series->add(element->x(), element->y()); |
|
80 | series->m_series->add(element->x(), element->y()); | |
80 | } |
|
81 | } | |
81 | } |
|
82 | } | |
82 |
|
83 | |||
83 | #include "moc_declarativexyseries.cpp" |
|
84 | #include "moc_declarativexyseries.cpp" | |
84 |
|
85 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now