##// END OF EJS Templates
Theme modifications....
Theme modifications. Change-Id: If089f741da6ddc1ff0f3bb2de0d5f17e87d00330 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2432:53927f716a3d
r2479:e5122ae0e714
Show More
splinechartitem.cpp
276 lines | 8.3 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
Michal Klocek
Refactor xychartitem -> xychart
r1218 **
Miikka Heikkinen
Fixed the copyright year 2012 -> 2013
r2432 ** Copyright (C) 2013 Digia Plc
Michal Klocek
Refactor xychartitem -> xychart
r1218 ** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Jani Honkonen
Add license headers
r794
Marek Rosa
Renamed SplinePresenter to SplineChartItem
r460 #include "splinechartitem_p.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qsplineseries_p.h"
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 #include "chartpresenter_p.h"
Michal Klocek
Refactor animator...
r1735 #include "splineanimation_p.h"
Marek Rosa
Domains added
r2275 #include "abstractdomain_p.h"
Marek Rosa
Spline working somewhat
r401 #include <QPainter>
Michal Klocek
Refactor xychartitem -> xychart
r1218 #include <QGraphicsSceneMouseEvent>
Marek Rosa
Spline initial
r295
Marek Rosa
Spline working somewhat
r401 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors internals...
r2273 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem* item)
: XYChart(series,item),
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_series(series),
m_pointsVisible(false),
m_animation(0)
Marek Rosa
Spline initial
r295 {
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 setAcceptHoverEvents(true);
Michal Klocek
Fixes mouse handling in base class of chartseries
r1747 setZValue(ChartPresenter::SplineChartZValue);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
Tero Ahola
Visible property to abstract series
r1342 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
Tero Ahola
Added opacity property to QAbstractSeries
r2067 QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 handleUpdated();
Marek Rosa
Spline initial
r295 }
Michal Klocek
Refactor line spline to common xyline...
r465 QRectF SplineChartItem::boundingRect() const
{
return m_rect;
}
Marek Rosa
Spline initial
r295
Michal Klocek
Refactor line spline to common xyline...
r465 QPainterPath SplineChartItem::shape() const
{
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 QPainterPathStroker stroker;
return stroker.createStroke(m_path);
Michal Klocek
Refactor line spline to common xyline...
r465 }
Marek Rosa
Spline working somewhat
r401
Jani Honkonen
more coding style fixes for src-folder...
r2104 void SplineChartItem::setAnimation(SplineAnimation *animation)
Michal Klocek
Refactors animation handling for xyseries
r1217 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_animation = animation;
Michal Klocek
Refactor xychartitem -> xychart
r1218 XYChart::setAnimation(animation);
Michal Klocek
Refactors animation handling for xyseries
r1217 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 ChartAnimation *SplineChartItem::animation() const
Michal Klocek
Refactor animator...
r1735 {
return m_animation;
}
Michal Klocek
Refactors animation handling for xyseries
r1217 void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points)
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_controlPoints = points;
Michal Klocek
Refactors animation handling for xyseries
r1217 }
QVector<QPointF> SplineChartItem::controlGeometryPoints() const
{
return m_controlPoints;
}
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
Michal Klocek
Bugfixes for spline vector allocation issues
r1082 {
Michal Klocek
Improves spline interpolation...
r622 QVector<QPointF> controlPoints;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (newPoints.count() >= 2)
Marek Rosa
QSplineSeries calculateControlPoints moved to splinechartitem. This way we don't need to deal with controlPoints on logaritmic scale
r2372 controlPoints = calculateControlPoints(newPoints);
Michal Klocek
Improves spline interpolation...
r622
Tero Ahola
Minor: extra colons, commented out code
r1782 if (m_animation)
m_animation->setup(oldPoints, newPoints, m_controlPoints, controlPoints, index);
Michal Klocek
Improves spline interpolation...
r622
Tero Ahola
Minor: extra colons, commented out code
r1782 m_points = newPoints;
m_controlPoints = controlPoints;
Michal Klocek
Refactor spline animation handling...
r1770 setDirty(false);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_animation)
Michal Klocek
Refactors axis animation, line animations
r1241 presenter()->startAnimation(m_animation);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 else
Michal Klocek
Refactors animation handling for xyseries
r1217 updateGeometry();
Michal Klocek
Improves spline interpolation...
r622 }
Michal Klocek
Refactors animation handling for xyseries
r1217 void SplineChartItem::updateGeometry()
Tero Ahola
Work-around for a bug in Clang compiler
r946 {
Tero Ahola
Minor: extra colons, commented out code
r1782 const QVector<QPointF> &points = m_points;
const QVector<QPointF> &controlPoints = m_controlPoints;
Tero Ahola
Work-around for a bug in Clang compiler
r946
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if ((points.size() < 2) || (controlPoints.size() < 2)) {
prepareGeometryChange();
Marek Rosa
XYSeries model support refactored
r1085 m_path = QPainterPath();
Michal Klocek
adds QLineAnimation fixes
r1271 m_rect = QRect();
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 return;
}
Marek Rosa
Spline somewhat working
r423
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 Q_ASSERT(points.count() * 2 - 2 == controlPoints.count());
Michal Klocek
Improves spline interpolation...
r622
QPainterPath splinePath(points.at(0));
Marek Rosa
Spline somewhat working
r423
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 for (int i = 0; i < points.size() - 1; i++) {
Jani Honkonen
more coding style fixes for src-folder...
r2104 const QPointF &point = points.at(i + 1);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 splinePath.cubicTo(controlPoints[2 * i], controlPoints[2 * i + 1], point);
Marek Rosa
Spline somewhat working
r423 }
prepareGeometryChange();
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 // QPainterPathStroker stroker;
// stroker.setWidth(m_linePen.width() / 2.0);
// m_path = stroker.createStroke(splinePath);
Marek Rosa
Spline somewhat working
r423 m_path = splinePath;
m_rect = splinePath.boundingRect();
Michal Klocek
Refactors internals...
r2273
Michal Klocek
Refactor line spline to common xyline...
r465 }
Marek Rosa
QSplineSeries calculateControlPoints moved to splinechartitem. This way we don't need to deal with controlPoints on logaritmic scale
r2372 /*!
Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
*/
QVector<QPointF> SplineChartItem::calculateControlPoints(const QVector<QPointF> &points)
{
QVector<QPointF> controlPoints;
controlPoints.resize(points.count() * 2 - 2);
int n = points.count() - 1;
if (n == 1) {
//for n==1
controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
controlPoints[1].setX(2 * controlPoints[0].x() - points[0].x());
controlPoints[1].setY(2 * controlPoints[0].y() - points[0].y());
return controlPoints;
}
// Calculate first Bezier control points
// Set of equations for P0 to Pn points.
//
// | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
// | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
// | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
// | . . . . . . . . . . . . | | ... | | ... |
// | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
// | . . . . . . . . . . . . | | ... | | ... |
// | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
// | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
//
QVector<qreal> vector;
vector.resize(n);
vector[0] = points[0].x() + 2 * points[1].x();
for (int i = 1; i < n - 1; ++i)
vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
vector[n - 1] = (8 * points[n - 1].x() + points[n].x()) / 2.0;
QVector<qreal> xControl = firstControlPoints(vector);
vector[0] = points[0].y() + 2 * points[1].y();
for (int i = 1; i < n - 1; ++i)
vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
vector[n - 1] = (8 * points[n - 1].y() + points[n].y()) / 2.0;
QVector<qreal> yControl = firstControlPoints(vector);
for (int i = 0, j = 0; i < n; ++i, ++j) {
controlPoints[j].setX(xControl[i]);
controlPoints[j].setY(yControl[i]);
j++;
if (i < n - 1) {
controlPoints[j].setX(2 * points[i + 1].x() - xControl[i + 1]);
controlPoints[j].setY(2 * points[i + 1].y() - yControl[i + 1]);
} else {
controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
}
}
return controlPoints;
}
QVector<qreal> SplineChartItem::firstControlPoints(const QVector<qreal>& vector)
{
QVector<qreal> result;
int count = vector.count();
result.resize(count);
result[0] = vector[0] / 2.0;
QVector<qreal> temp;
temp.resize(count);
temp[0] = 0;
qreal b = 2.0;
for (int i = 1; i < count; i++) {
temp[i] = 1 / b;
b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
result[i] = (vector[i] - result[i - 1]) / b;
}
for (int i = 1; i < count; i++)
result[count - i - 1] -= temp[count - i] * result[count - i];
return result;
}
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 //handlers
void SplineChartItem::handleUpdated()
{
Tero Ahola
Fixed isVisible implementation in XY series
r1346 setVisible(m_series->isVisible());
Tero Ahola
Added opacity property to QAbstractSeries
r2067 setOpacity(m_series->opacity());
Michal Klocek
Adds visible points handling to spline
r580 m_pointsVisible = m_series->pointsVisible();
m_linePen = m_series->pen();
m_pointPen = m_series->pen();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_pointPen.setWidthF(2 * m_pointPen.width());
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 update();
}
//painter
Michal Klocek
Refactor line spline to common xyline...
r465
Marek Rosa
Renamed SplinePresenter to SplineChartItem
r460 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Marek Rosa
Spline somewhat working
r423 {
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(widget)
Q_UNUSED(option)
Tero Ahola
Fixed isVisible implementation in XY series
r1346
painter->save();
Michal Klocek
Refactors internals...
r2273 painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
Tero Ahola
Fixed isVisible implementation in XY series
r1346 painter->setPen(m_linePen);
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 // painter->setBrush(m_linePen.color());
Tero Ahola
Fixed isVisible implementation in XY series
r1346 painter->drawPath(m_path);
if (m_pointsVisible) {
painter->setPen(m_pointPen);
painter->drawPoints(geometryPoints());
Michal Klocek
Adds visible points handling to spline
r580 }
Tero Ahola
Fixed isVisible implementation in XY series
r1346 painter->restore();
Marek Rosa
Spline somewhat working
r423 }
Marek Rosa
Experimenting
r417
Michal Klocek
Refactor xychartitem -> xychart
r1218 void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Michal Klocek
Refactors internals...
r2273 emit XYChart::clicked(domain()->calculateDomainPoint(event->pos()));
Michal Klocek
Fixes mouse handling in base class of chartseries
r1747 QGraphicsItem::mousePressEvent(event);
Michal Klocek
Refactor xychartitem -> xychart
r1218 }
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 void SplineChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Michal Klocek
Refactors internals...
r2273 emit XYChart::hovered(domain()->calculateDomainPoint(event->pos()), true);
Marek Rosa
Negative values with log axis handled
r2356 QGraphicsItem::hoverEnterEvent(event);
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 }
void SplineChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Michal Klocek
Refactors internals...
r2273 emit XYChart::hovered(domain()->calculateDomainPoint(event->pos()), false);
Marek Rosa
Negative values with log axis handled
r2356 QGraphicsItem::hoverLeaveEvent(event);
Marek Rosa
Added hover support to splinechart and updated callout example
r2256 }
Marek Rosa
Renamed SplinePresenter to SplineChartItem
r460 #include "moc_splinechartitem_p.cpp"
Marek Rosa
Spline working somewhat
r401
QTCOMMERCIALCHART_END_NAMESPACE