##// END OF EJS Templates
QSplineSeries documentation added
QSplineSeries documentation added

File last commit:

r431:575ceaee424c
r433:c8744ab348e4
Show More
splinepresenter.cpp
77 lines | 2.4 KiB | text/x-c | CppLexer
Marek Rosa
Spline initial
r295 #include "splinepresenter_p.h"
Marek Rosa
Spline working somewhat
r401 #include <QPainter>
Marek Rosa
Spline initial
r295
Marek Rosa
Spline working somewhat
r401 QTCOMMERCIALCHART_BEGIN_NAMESPACE
SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) :
Marek Rosa
Spline with problems
r419 LineChartItem(0, series, parent)//,m_boundingRect()
Marek Rosa
Spline initial
r295 {
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 //
Marek Rosa
Spline initial
r295 }
Marek Rosa
Spline working somewhat
r401
Marek Rosa
Spline with problems
r419 QPointF SplinePresenter::calculateGeometryControlPoint(int index) const
Marek Rosa
Spline working somewhat
r401 {
Marek Rosa
Spline with problems
r419 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
const qreal deltaX = m_size.width()/m_domain.spanX();
const qreal deltaY = m_size.height()/m_domain.spanY();
qreal x = (splineSeries->controlPoint(index).x() - m_domain.m_minX)* deltaX;
qreal y = (splineSeries->controlPoint(index).y() - m_domain.m_minY)*-deltaY + m_size.height();
return QPointF(x,y);
}
void SplinePresenter::applyGeometry(QVector<QPointF>& points)
{
Marek Rosa
Spline somewhat working
r423 if(points.size()==0) return;
QPainterPath splinePath;
const QPointF& point = points.at(0);
splinePath.moveTo(point);
QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
for (int i = 0; i < splineSeries->count() - 1; i++)
{
const QPointF& point = points.at(i + 1);
splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point);
}
prepareGeometryChange();
m_path = splinePath;
m_rect = splinePath.boundingRect();
Marek Rosa
Spline working somewhat
r401 }
Marek Rosa
Spline somewhat working
r423 void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
painter->save();
painter->setPen(m_pen);
painter->setClipRect(m_clipRect);
painter->drawPath(m_path);
QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
for (int i = 0; i < splineSeries->count() - 1; i++)
{
painter->setPen(Qt::red);
painter->drawEllipse(m_points[i], 4, 4);
painter->setPen(Qt::blue);
// painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i));
// painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1));
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4);
// painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4);
}
if (m_points.count() > 0)
{
painter->setPen(Qt::red);
painter->drawEllipse(m_points[m_points.count() - 1], 4, 4);
Marek Rosa
Spline somewhat working
r423 }
painter->restore();
}
Marek Rosa
Experimenting
r417
Marek Rosa
Spline working somewhat
r401 #include "moc_splinepresenter_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE