xylinechartitem.cpp
67 lines
| 1.6 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r21 | #include "xylinechartitem_p.h" | ||
Michal Klocek
|
r67 | #include "axisitem_p.h" | ||
Michal Klocek
|
r21 | #include "qxychartseries.h" | ||
#include <QPainter> | ||||
#include <QStyleOptionGraphicsItem> | ||||
#include <QDebug> | ||||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Michal Klocek
|
r21 | |||
Michal Klocek
|
r67 | XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent):ChartItem(parent), | ||
m_series(series), | ||||
m_dirty(false) | ||||
Michal Klocek
|
r21 | { | ||
} | ||||
Michal Klocek
|
r67 | void XYLineChartItem::setSize(const QSize& size) | ||
Michal Klocek
|
r21 | { | ||
Michal Klocek
|
r67 | m_rect=QRect(0,0,size.width(),size.height()); | ||
m_dirty=true; | ||||
} | ||||
Michal Klocek
|
r25 | |||
Michal Klocek
|
r67 | void XYLineChartItem::setPlotDomain(const PlotDomain& data) | ||
{ | ||||
m_plotDomain=data; | ||||
m_dirty=true; | ||||
} | ||||
Michal Klocek
|
r25 | |||
Michal Klocek
|
r67 | QRectF XYLineChartItem::boundingRect() const | ||
{ | ||||
return m_polyline.boundingRect(); | ||||
} | ||||
Michal Klocek
|
r25 | |||
Michal Klocek
|
r67 | void XYLineChartItem::updateGeometry() | ||
{ | ||||
if (!m_rect.isValid()) return; | ||||
Michal Klocek
|
r25 | |||
Michal Klocek
|
r67 | const qreal deltaX = (m_rect.width()-1)/m_plotDomain.spanX(); | ||
const qreal deltaY = (m_rect.height()-1)/m_plotDomain.spanY(); | ||||
Michal Klocek
|
r25 | |||
Michal Klocek
|
r67 | m_polyline.clear(); | ||
m_polyline.resize(m_series->count()); | ||||
Michal Klocek
|
r25 | |||
Michal Klocek
|
r67 | for (int j = 0; j < m_series->count(); ++j) { | ||
qreal dx = m_series->x(j) - m_plotDomain.m_minX; | ||||
qreal dy = m_series->y(j) - m_plotDomain.m_minY; | ||||
qreal x = (dx * deltaX) + m_rect.left(); | ||||
qreal y = - (dy * deltaY) + m_rect.bottom(); | ||||
m_polyline[j] = QPointF(x, y); | ||||
} | ||||
Michal Klocek
|
r21 | |||
} | ||||
void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | ||||
{ | ||||
Michal Klocek
|
r67 | //TODO: remove it | ||
if (m_dirty) { | ||||
updateGeometry(); | ||||
m_dirty=false; | ||||
} | ||||
painter->setClipRect(m_rect.adjusted(+1, +1, -1, -1)); | ||||
Michal Klocek
|
r21 | painter->setPen(m_series->color()); | ||
painter->drawPolyline(m_polyline); | ||||
} | ||||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||