##// END OF EJS Templates
Add missing export macro to qchartaxis
Add missing export macro to qchartaxis

File last commit:

r158:dd283485728c
r178:1b3b2dbc131b
Show More
declarativeseries.cpp
96 lines | 2.8 KiB | text/x-c | CppLexer
/ qmlplugin / declarativeseries.cpp
Tero Ahola
Proof-of-concept for QML api...
r120 #include "declarativeseries.h"
#include "declarativechart.h"
Michal Klocek
Fix previous broken commit
r145 #include <qlinechartseries.h>
Tero Ahola
Proof-of-concept for QML api...
r120 #include <cmath>
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) :
QDeclarativeItem(parent),
m_seriesType(SeriesTypeInvalid), // TODO: default type?
m_chart(0),
m_series(0)
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
connect(this, SIGNAL(parentChanged()),
this, SLOT(setParentForSeries()));
}
void DeclarativeSeries::setSeriesType(SeriesType type)
{
if (!m_series || type != m_seriesType) {
m_seriesType = type;
initSeries();
}
}
void DeclarativeSeries::setParentForSeries()
{
initSeries();
}
void DeclarativeSeries::initSeries()
{
DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
if (declarativeChart && m_seriesType != SeriesTypeInvalid) {
delete m_series;
m_series = 0;
QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
qDebug() << "creating series for chart: " << chart;
Q_ASSERT(chart);
switch (m_seriesType) {
case SeriesTypeLine: {
Tero Ahola
Integrated scatter again. Missing functionality....
r158 m_series = new QLineChartSeries(this);
Tero Ahola
Proof-of-concept for QML api...
r120 for (qreal i(0.0); i < 100.0; i += 1.0)
Michal Klocek
Fix previous broken commit
r145 ((QLineChartSeries *)m_series)->add(i, i);
Tero Ahola
Proof-of-concept for QML api...
r120 chart->addSeries(m_series);
break;
}
case SeriesTypeBar:
// fallthrough; bar and scatter use the same test data
case SeriesTypeScatter: {
m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType);
QList<qreal> datax;
QList<qreal> datay;
for (qreal i = 0; i < 100; i += 0.1) {
datax.append(i + (rand() % 5));
datay.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
}
Q_ASSERT(m_series->setData(datax, datay));
break;
}
case SeriesTypeStackedBar:
break;
case SeriesTypePercentBar:
break;
case SeriesTypePie: {
m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType);
QList<qreal> data;
data << 1.0;
data << 12.0;
data << 4.0;
Q_ASSERT(m_series->setData(data));
break;
}
default:
break;
}
}
}
QVariant DeclarativeSeries::itemChange(GraphicsItemChange change,
const QVariant &value)
{
// For debugging purposes only:
// qDebug() << QString::number(change) << " : " << value.toString();
return QGraphicsItem::itemChange(change, value);
}
#include "moc_declarativeseries.cpp"
QTCOMMERCIALCHART_END_NAMESPACE