declarativescatterseries.cpp
63 lines
| 2.0 KiB
| text/x-c
|
CppLexer
/ qmlplugin / declarativescatterseries.cpp
|
r196 | #include "declarativescatterseries.h" | ||
#include "declarativechart.h" | ||||
#include "qchart.h" | ||||
#include "qscatterseries.h" | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) : | ||||
QDeclarativeItem(parent), | ||||
m_chart(0), | ||||
|
r723 | m_series(0) | ||
|
r196 | { | ||
setFlag(QGraphicsItem::ItemHasNoContents, false); | ||||
} | ||||
|
r722 | DeclarativeScatterSeries::~DeclarativeScatterSeries() | ||
|
r196 | { | ||
} | ||||
|
r722 | void DeclarativeScatterSeries::componentComplete() | ||
|
r196 | { | ||
Q_ASSERT(!m_series); | ||||
DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | ||||
if (declarativeChart) { | ||||
|
r722 | m_chart = qobject_cast<QChart *>(declarativeChart->m_chart); | ||
qDebug() << "creating scatter series for chart: " << m_chart; | ||||
Q_ASSERT(m_chart); | ||||
|
r196 | |||
m_series = new QScatterSeries(); | ||||
|
r726 | for (int i(0); i < m_points.count(); i++) { | ||
DeclarativeXyPoint *element = m_points.at(i); | ||||
|
r196 | *m_series << QPointF(element->x(), element->y()); | ||
} | ||||
|
r722 | m_chart->addSeries(m_series); | ||
|
r196 | } | ||
} | ||||
|
r726 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points() | ||
|
r196 | { | ||
|
r722 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, | ||
|
r726 | &DeclarativeScatterSeries::appendPoints); | ||
|
r196 | } | ||
|
r726 | void DeclarativeScatterSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | ||
|
r722 | DeclarativeXyPoint *element) | ||
|
r196 | { | ||
DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object); | ||||
|
r726 | qDebug() << "appendPoints: " << series; | ||
qDebug() << "appendPoints: " << element; | ||||
qDebug() << "appendPoints: " << element->x(); | ||||
qDebug() << "appendPoints: " << element->y(); | ||||
qDebug() << "appendPoints: " << series->m_series; | ||||
|
r196 | if (series) { | ||
|
r726 | series->m_points.append(element); | ||
|
r196 | if (series->m_series) | ||
|
r358 | series->m_series->add(element->x(), element->y()); | ||
|
r196 | } | ||
} | ||||
#include "moc_declarativescatterseries.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||