##// END OF EJS Templates
Integrated scatter type series...
Integrated scatter type series Also added an implementation for creating series graphic items with a simple class derived from QChartSeries.

File last commit:

r42:5fcd249308db
r42:5fcd249308db
Show More
qchart.cpp
140 lines | 3.3 KiB | text/x-c | CppLexer
Michal Klocek
adds missing files form previous commit
r12 #include "qchart.h"
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "qchartseries.h"
Tero Ahola
Integrated scatter type series...
r42 #include "qscatterseries.h"
#include "qscatterseries_p.h"
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "xylinechartitem_p.h"
Michal Klocek
Refactor xyplotdata...
r25 #include "xyplotdomain_p.h"
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "axis_p.h"
#include "xygrid_p.h"
Tero Ahola
Integrated scatter type series...
r42 #include <QGraphicsScene>
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include <QDebug>
Michal Klocek
adds missing files form previous commit
r12
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
adds missing files form previous commit
r12
Michal Klocek
Adds pimpl to qchart class
r28 class QChartPrivate
{
public:
QChartPrivate(QChart* parent):
m_axisX(new Axis(parent)),
m_axisY(new Axis(parent)),
m_grid(new XYGrid(parent)),
m_plotDataIndex(0),
m_marginSize(0){}
Axis* m_axisX;
Axis* m_axisY;
XYGrid* m_grid;
QRect m_rect;
QList<const QChartSeries*> m_series;
QList<XYPlotDomain> m_plotDataList;
QList<QGraphicsItem*> m_items;
int m_plotDataIndex;
int m_marginSize;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Michal Klocek
adds missing files form previous commit
r12 QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent),
Michal Klocek
Adds pimpl to qchart class
r28 d_ptr(new QChartPrivate(this))
Michal Klocek
adds missing files form previous commit
r12 {
Michal Klocek
Adds pimpl to qchart class
r28 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
Michal Klocek
Refactor current draft to fit int current design specs...
r21 // set axis
Michal Klocek
Adds pimpl to qchart class
r28 Q_D(QChart);
d->m_axisY->rotate(90);
Michal Klocek
Fix private header dependency...
r22
Michal Klocek
Adds pimpl to qchart class
r28 //TODO hardcoded values , to removed soon
XYPlotDomain data;
data.m_minX = 0.0;
data.m_maxX = 100.0;
data.m_minY = 0.0;
data.m_maxY = 100.0;
data.m_ticksX=4;
data.m_ticksY=4;
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Michal Klocek
Adds pimpl to qchart class
r28 d->m_plotDataList.clear();
d->m_plotDataList << data;
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Michal Klocek
Adds pimpl to qchart class
r28 d->m_grid->setZValue(10);
d->m_grid->setXYPlotData(d->m_plotDataList.at(0));
Michal Klocek
adds missing files form previous commit
r12 }
QChart::~QChart(){}
Michal Klocek
Refactor current draft to fit int current design specs...
r21 QRectF QChart::boundingRect() const
{
Michal Klocek
Adds pimpl to qchart class
r28 Q_D(const QChart);
return d->m_rect;
Michal Klocek
Refactor current draft to fit int current design specs...
r21 }
Michal Klocek
adds missing files form previous commit
r12
Michal Klocek
Refactor current draft to fit int current design specs...
r21 void QChart::addSeries(QChartSeries* series)
Michal Klocek
adds missing files form previous commit
r12 {
Michal Klocek
Adds pimpl to qchart class
r28 Q_D(QChart);
d->m_series<<series;
Michal Klocek
Refactor current draft to fit int current design specs...
r21
switch(series->type())
{
Tero Ahola
Renamed to QtCommercialChart
r30 case QChartSeries::SeriesTypeLine: {
Michal Klocek
Refactor current draft to fit int current design specs...
r21 XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this);
Michal Klocek
Adds pimpl to qchart class
r28 item->updateXYPlotData(d->m_plotDataList.at(0));
d->m_items<<item;
Michal Klocek
Refactor current draft to fit int current design specs...
r21 break;
Michal Klocek
adds missing files form previous commit
r12 }
Tero Ahola
Renamed to QtCommercialChart
r30 case QChartSeries::SeriesTypeScatter: {
break;
}
}
Michal Klocek
Refactor current draft to fit int current design specs...
r21 }
Tero Ahola
Integrated scatter type series...
r42 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
{
Q_D(QChart);
// TODO: support also other types
Q_ASSERT(type == QChartSeries::SeriesTypeScatter);
QChartSeries *series = 0;
switch (type) {
case QChartSeries::SeriesTypeScatter: {
QScatterSeries *scatterSeries = new QScatterSeries(x, y, this);
d->m_items.append(scatterSeries->d);
scene()->addItem(scatterSeries->d);
//series = qobject_cast<QChartSeries *>(scatterSeries);
break;
}
default:
break;
}
return series;
}
Michal Klocek
Adds pimpl to qchart class
r28 void QChart::setSize(const QSizeF& size)
{
Q_D(QChart);
Michal Klocek
Refactor current draft to fit int current design specs...
r21 //TODO refactor to setGeometry
Michal Klocek
Adds pimpl to qchart class
r28 d->m_rect = QRect(QPoint(0,0),size.toSize());
d->m_rect.adjust(margin(),margin(),-margin(),-margin());
d->m_grid->setPos(d->m_rect.topLeft());
d->m_grid->setSize(d->m_rect.size());
d->m_plotDataList[0].m_viewportRect = d->m_rect;
Tero Ahola
Integrated scatter type series...
r42 // TODO: line chart items would need to be updated separately as they don't support update
// via paint method
Michal Klocek
Revert "Integrated scatter series"...
r39 foreach(QGraphicsItem* item , d->m_items)
Tero Ahola
Integrated scatter type series...
r42 reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0));
Michal Klocek
Refactor current draft to fit int current design specs...
r21 update();
Michal Klocek
adds missing files form previous commit
r12 }
Michal Klocek
Adds pimpl to qchart class
r28 int QChart::margin() const
{
Q_D(const QChart);
return d->m_marginSize;
}
Michal Klocek
adds missing files form previous commit
r12 void QChart::setMargin(int margin)
{
Michal Klocek
Adds pimpl to qchart class
r28 Q_D(QChart);
d->m_marginSize = margin;
Michal Klocek
adds missing files form previous commit
r12 }
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_END_NAMESPACE