##// END OF EJS Templates
d
d

File last commit:

r722:3c81c15bc4ba
r722:3c81c15bc4ba
Show More
declarativescatterseries.cpp
108 lines | 3.2 KiB | text/x-c | CppLexer
/ qmlplugin / declarativescatterseries.cpp
Tero Ahola
Proposal for QML data API
r196 #include "declarativescatterseries.h"
#include "declarativechart.h"
Tero Ahola
d
r722 #include "declarativetablemodel.h"
Tero Ahola
Proposal for QML data API
r196 #include "qchart.h"
#include "qscatterseries.h"
QTCOMMERCIALCHART_BEGIN_NAMESPACE
DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) :
QDeclarativeItem(parent),
m_chart(0),
Tero Ahola
d
r722 m_series(0),
m_model(0),
m_xColumn(0),
m_yColumn(1)
Tero Ahola
Proposal for QML data API
r196 {
setFlag(QGraphicsItem::ItemHasNoContents, false);
}
Tero Ahola
d
r722 DeclarativeScatterSeries::~DeclarativeScatterSeries()
Tero Ahola
Proposal for QML data API
r196 {
}
Tero Ahola
d
r722 void DeclarativeScatterSeries::componentComplete()
Tero Ahola
Proposal for QML data API
r196 {
Q_ASSERT(!m_series);
DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
if (declarativeChart) {
Tero Ahola
d
r722 m_chart = qobject_cast<QChart *>(declarativeChart->m_chart);
qDebug() << "creating scatter series for chart: " << m_chart;
Q_ASSERT(m_chart);
Tero Ahola
Proposal for QML data API
r196
m_series = new QScatterSeries();
Tero Ahola
d
r722 // if (!m_model)
// m_model = new DeclarativeTableModel();
if (m_model) {
m_series->setModel(m_model);
m_series->setModelMapping(m_xColumn, m_yColumn);
}
Tero Ahola
Proposal for QML data API
r196 for (int i(0); i < m_data.count(); i++) {
Tero Ahola
d
r722 DeclarativeXyPoint *element = m_data.at(i);
Tero Ahola
Proposal for QML data API
r196 *m_series << QPointF(element->x(), element->y());
}
Tero Ahola
d
r722 m_chart->addSeries(m_series);
Tero Ahola
Proposal for QML data API
r196 }
}
Tero Ahola
d
r722 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::data()
Tero Ahola
Proposal for QML data API
r196 {
Tero Ahola
d
r722 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0,
Tero Ahola
Proposal for QML data API
r196 &DeclarativeScatterSeries::appendData);
}
Tero Ahola
d
r722 void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<DeclarativeXyPoint> *list,
DeclarativeXyPoint *element)
Tero Ahola
Proposal for QML data API
r196 {
DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object);
qDebug() << "appendData: " << series;
qDebug() << "appendData: " << element;
qDebug() << "appendData: " << element->x();
qDebug() << "appendData: " << element->y();
qDebug() << "appendData: " << series->m_series;
if (series) {
series->m_data.append(element);
if (series->m_series)
Tero Ahola
Fixing review findings in QScatterSeries
r358 series->m_series->add(element->x(), element->y());
Tero Ahola
Proposal for QML data API
r196 }
}
Tero Ahola
d
r722 DeclarativeTableModel *DeclarativeScatterSeries::model()
{
if (m_series)
return (DeclarativeTableModel *) m_series->model();
else
return m_model;
}
void DeclarativeScatterSeries::setModel(DeclarativeTableModel *model)
{
m_model = model;
if (m_chart && m_series) {
// Hack: remove and add the series to force an update for the chart range
m_chart->removeSeries(m_series);
m_series = new QScatterSeries();
m_series->setModel(m_model);
m_series->setModelMapping(m_xColumn, m_yColumn);
m_chart->addSeries(m_series);
}
}
void DeclarativeScatterSeries::setXColumn(int xColumn)
{
m_xColumn = xColumn;
if (m_series && m_series->model())
m_series->setModelMapping(m_xColumn, m_yColumn);
}
void DeclarativeScatterSeries::setYColumn(int yColumn)
{
m_yColumn = yColumn;
if (m_series && m_series->model())
m_series->setModelMapping(m_xColumn, m_yColumn);
}
Tero Ahola
Proposal for QML data API
r196 #include "moc_declarativescatterseries.cpp"
QTCOMMERCIALCHART_END_NAMESPACE