qchart.cpp
114 lines
| 2.5 KiB
| text/x-c
|
CppLexer
/ src / qchart.cpp
Michal Klocek
|
r12 | #include "qchart.h" | ||
Michal Klocek
|
r21 | #include "qchartseries.h" | ||
#include "xylinechartitem_p.h" | ||||
Michal Klocek
|
r25 | #include "xyplotdomain_p.h" | ||
Michal Klocek
|
r21 | #include "axis_p.h" | ||
#include "xygrid_p.h" | ||||
#include <QDebug> | ||||
Michal Klocek
|
r12 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Michal Klocek
|
r12 | |||
Michal Klocek
|
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
|
r12 | QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), | ||
Michal Klocek
|
r28 | d_ptr(new QChartPrivate(this)) | ||
Michal Klocek
|
r12 | { | ||
Michal Klocek
|
r28 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | ||
Michal Klocek
|
r21 | // set axis | ||
Michal Klocek
|
r28 | Q_D(QChart); | ||
d->m_axisY->rotate(90); | ||||
Michal Klocek
|
r22 | |||
Michal Klocek
|
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
|
r21 | |||
Michal Klocek
|
r28 | d->m_plotDataList.clear(); | ||
d->m_plotDataList << data; | ||||
Michal Klocek
|
r21 | |||
Michal Klocek
|
r28 | d->m_grid->setZValue(10); | ||
d->m_grid->setXYPlotData(d->m_plotDataList.at(0)); | ||||
Michal Klocek
|
r12 | } | ||
QChart::~QChart(){} | ||||
Michal Klocek
|
r21 | QRectF QChart::boundingRect() const | ||
{ | ||||
Michal Klocek
|
r28 | Q_D(const QChart); | ||
return d->m_rect; | ||||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r12 | |||
Michal Klocek
|
r21 | void QChart::addSeries(QChartSeries* series) | ||
Michal Klocek
|
r12 | { | ||
Michal Klocek
|
r28 | Q_D(QChart); | ||
d->m_series<<series; | ||||
Michal Klocek
|
r21 | |||
switch(series->type()) | ||||
{ | ||||
Tero Ahola
|
r30 | case QChartSeries::SeriesTypeLine: { | ||
Michal Klocek
|
r21 | XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this); | ||
Michal Klocek
|
r28 | item->updateXYPlotData(d->m_plotDataList.at(0)); | ||
d->m_items<<item; | ||||
Michal Klocek
|
r21 | break; | ||
Michal Klocek
|
r12 | } | ||
Tero Ahola
|
r30 | case QChartSeries::SeriesTypeScatter: { | ||
break; | ||||
} | ||||
} | ||||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r28 | void QChart::setSize(const QSizeF& size) | ||
{ | ||||
Q_D(QChart); | ||||
Michal Klocek
|
r21 | //TODO refactor to setGeometry | ||
Michal Klocek
|
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; | ||||
Michal Klocek
|
r39 | foreach(QGraphicsItem* item , d->m_items) | ||
reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0)); | ||||
Michal Klocek
|
r21 | update(); | ||
Michal Klocek
|
r39 | |||
Michal Klocek
|
r12 | } | ||
Michal Klocek
|
r28 | int QChart::margin() const | ||
{ | ||||
Q_D(const QChart); | ||||
return d->m_marginSize; | ||||
} | ||||
Michal Klocek
|
r12 | void QChart::setMargin(int margin) | ||
{ | ||||
Michal Klocek
|
r28 | Q_D(QChart); | ||
d->m_marginSize = margin; | ||||
Michal Klocek
|
r12 | } | ||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||