##// END OF EJS Templates
Scatter API review: changed signal now private etc.
Scatter API review: changed signal now private etc.

File last commit:

r457:d397e4be0cff
r459:272f4a2e7431
Show More
splinepresenter.cpp
75 lines | 2.3 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) :
Michal Klocek
Refactor domain model...
r439 LineChartItem(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);
Michal Klocek
Refactor domain model...
r439 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
qreal x = (splineSeries->controlPoint(index).x() - m_minX)* deltaX;
qreal y = (splineSeries->controlPoint(index).y() - m_minY)*-deltaY + m_size.height();
Marek Rosa
Spline with problems
r419 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);
Marek Rosa
Spline chart example added
r434 // QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
for (int i = 0; i < points.size() - 1; i++)
Marek Rosa
Spline somewhat working
r423 {
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);
Marek Rosa
Spline series fix
r450 for (int i = 0; i < m_points.size() - 1; i++)
Marek Rosa
Spline somewhat working
r423 {
painter->setPen(Qt::red);
Marek Rosa
Spline chart example added
r434 painter->drawEllipse(m_points[i], 2, 2);
Marek Rosa
Spline somewhat working
r423
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);
Marek Rosa
Spline chart example added
r434 painter->drawEllipse(m_points[m_points.count() - 1], 2, 2);
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