##// END OF EJS Templates
Fix copy errors when running install in windows
Fix copy errors when running install in windows

File last commit:

r1002:f486aabc62ff
r1047:ce7e3633d562
Show More
qsplineseries.cpp
220 lines | 7.4 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** 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$
**
****************************************************************************/
Marek Rosa
Spline initial
r295 #include "qsplineseries.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qsplineseries_p.h"
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943 #include "splinechartitem_p.h"
#include "chartdataset_p.h"
#include "charttheme_p.h"
#include "chartanimator_p.h"
Marek Rosa
Spline initial
r295
Marek Rosa
QSplineSeries documentation added
r433 /*!
\class QSplineSeries
\brief Series type used to store data needed to draw a spline.
QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
Tero Ahola
Documentation fixes....
r995
\image examples_splinechart.png
Creating basic spline chart is simple:
\code
QSplineSeries* series = new QSplineSeries();
series->append(0, 6);
series->append(2, 4);
...
chart->addSeries(series);
\endcode
Marek Rosa
QSplineSeries documentation added
r433 */
/*!
\fn QSeriesType QSplineSeries::type() const
Returns the type of the series
*/
/*!
\fn QSeriesType QSplineSeries::controlPoint(int index) const
Returns the control point specified by \a index
*/
Marek Rosa
Spline working somewhat
r401 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Marek Rosa
QSplineSeries documentation added
r433 /*!
Constructs empty series object which is a child of \a parent.
Michal Klocek
Krazy reported errors...
r974 When series object is added to QChartView or QChart instance then the ownerships is transferred.
Marek Rosa
QSplineSeries documentation added
r433 */
Marek Rosa
Spline initial
r295 QSplineSeries::QSplineSeries(QObject *parent) :
Michal Klocek
Adds big fat pimpl to series classes...
r938 QLineSeries(*new QSplineSeriesPrivate(this),parent)
Marek Rosa
Spline initial
r295 {
}
Marek Rosa
Spline some more
r305
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 QAbstractSeries::QSeriesType QSplineSeries::type() const
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 return QAbstractSeries::SeriesTypeSpline;
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
QPointF QSplineSeries::controlPoint(int index) const
{
Q_D(const QSplineSeries);
return d->m_controlPoints[index];
}
Marek Rosa
Fixed broken spline series
r992 /*!
Tero Ahola
No errors anymore when generating docs, wohoo! For now.
r1002 Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used
as a data source for y coordinate. The \a orientation parameter specifies whether the data
is in columns or in rows.
\sa setModel()
Marek Rosa
Fixed broken spline series
r992 */
void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
{
Q_D(QSplineSeries);
QXYSeries::setModelMapping(modelX, modelY, orientation);
d->calculateControlPoints();
}
Michal Klocek
Adds big fat pimpl to series classes...
r938 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
{
QObject::connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
QObject::connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
QObject::connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
};
Marek Rosa
QSplineSeries documentation added
r433 /*!
\internal
Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
*/
Michal Klocek
Adds big fat pimpl to series classes...
r938 void QSplineSeriesPrivate::calculateControlPoints()
Marek Rosa
Spline working somewhat
r401 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 Q_Q(QSplineSeries);
Marek Rosa
Spline working somewhat
r401 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
Marek Rosa
QSplineSeries documentation added
r433 // CPOL License
Marek Rosa
Spline working somewhat
r401
Michal Klocek
Adds big fat pimpl to series classes...
r938 int n = q->count() - 1;
Marek Rosa
Spline working somewhat
r401 if (n == 1)
{ // Special case: Bezier curve should be a straight line.
// firstControlPoints = new Point[1];
// 3P1 = 2P0 + P3
Michal Klocek
Adds big fat pimpl to series classes...
r938 m_controlPoints.append(QPointF((2 * q->x(0) + q->x(1)) / 3, (2 * q->y(0) + q->y(1)) / 3));
Marek Rosa
Spline working somewhat
r401
// P2 = 2P1 P0
Michal Klocek
Adds big fat pimpl to series classes...
r938 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - q->x(0), 2 * m_controlPoints[0].y() - q->y(0)));
Marek Rosa
Spline working somewhat
r401 return;
Marek Rosa
Further changes
r318 }
Marek Rosa
Spline working somewhat
r401 // Calculate first Bezier control points
// Right hand side vector
// 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 |
//
QList<qreal> rhs;
Michal Klocek
Adds big fat pimpl to series classes...
r938 rhs.append(q->x(0) + 2 * q->x(1));
Marek Rosa
Spline working somewhat
r401
// Set right hand side X values
Marek Rosa
Fixed a bug with last two control points calculation
r429 for (int i = 1; i < n - 1; ++i)
Michal Klocek
Adds big fat pimpl to series classes...
r938 rhs.append(4 * q->x(i) + 2 * q->x(i + 1));
Marek Rosa
Spline working somewhat
r401
Michal Klocek
Adds big fat pimpl to series classes...
r938 rhs.append((8 * q->x(n - 1) + q->x(n)) / 2.0);
Marek Rosa
Spline working somewhat
r401 // Get first control points X-values
Marek Rosa
Table model data example
r519 QList<qreal> xControl = getFirstControlPoints(rhs);
Michal Klocek
Adds big fat pimpl to series classes...
r938 rhs[0] = q->y(0) + 2 * q->y(1);
Marek Rosa
Spline working somewhat
r401
// Set right hand side Y values
Marek Rosa
Fixed a bug with last two control points calculation
r429 for (int i = 1; i < n - 1; ++i)
Michal Klocek
Adds big fat pimpl to series classes...
r938 rhs[i] = 4 * q->y(i) + 2 * q->y(i + 1);
Marek Rosa
Spline working somewhat
r401
Michal Klocek
Adds big fat pimpl to series classes...
r938 rhs[n - 1] = (8 * q->y(n - 1) + q->y(n)) / 2.0;
Marek Rosa
Spline working somewhat
r401 // Get first control points Y-values
Marek Rosa
Table model data example
r519 QList<qreal> yControl = getFirstControlPoints(rhs);
Marek Rosa
Spline working somewhat
r401
// Fill output arrays.
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 for (int i = 0; i < n; ++i) {
Marek Rosa
Spline working somewhat
r401 // First control point
Marek Rosa
Table model data example
r519 m_controlPoints.append(QPointF(xControl[i], yControl[i]));
Marek Rosa
Spline working somewhat
r401 // Second control point
if (i < n - 1)
Michal Klocek
Adds big fat pimpl to series classes...
r938 m_controlPoints.append(QPointF(2 * q->x(i + 1) - xControl[i + 1], 2 * q->y(i + 1) - yControl[i + 1]));
Marek Rosa
Spline working somewhat
r401 else
Michal Klocek
Adds big fat pimpl to series classes...
r938 m_controlPoints.append(QPointF((q->x(n) + xControl[n - 1]) / 2, (q->y(n) + yControl[n - 1]) / 2));
Marek Rosa
Further changes
r318 }
Marek Rosa
Spline working somewhat
r401 }
Marek Rosa
QSplineSeries documentation added
r433 /*!
\internal
*/
Michal Klocek
Adds big fat pimpl to series classes...
r938 QList<qreal> QSplineSeriesPrivate::getFirstControlPoints(QList<qreal> rhs)
Marek Rosa
Spline working somewhat
r401 {
QList<qreal> x; // Solution vector.
QList<qreal> tmp; // Temp workspace.
qreal b = 2.0;
x.append(rhs[0] / b);
tmp.append(0);
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 for (int i = 1; i < rhs.size(); i++) {
// Decomposition and forward substitution.
Marek Rosa
Spline working somewhat
r401 tmp.append(1 / b);
b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
x.append((rhs[i] - x[i - 1]) / b);
}
for (int i = 1; i < rhs.size(); i++)
x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
return x;
}
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431
Marek Rosa
QSplineSeries documentation added
r433 /*!
\internal
Updates the control points, besed on currently avaiable knots.
*/
Michal Klocek
Adds big fat pimpl to series classes...
r938 void QSplineSeriesPrivate::updateControlPoints()
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 Q_Q(QSplineSeries);
if (q->count() > 1) {
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 m_controlPoints.clear();
calculateControlPoints();
}
}
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
{
Q_Q(QSplineSeries);
SplineChartItem* spline = new SplineChartItem(q,presenter);
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
presenter->animator()->addAnimation(spline);
}
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
return spline;
}
Marek Rosa
Spline working somewhat
r401 #include "moc_qsplineseries.cpp"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "moc_qsplineseries_p.cpp"
Marek Rosa
Spline working somewhat
r401
QTCOMMERCIALCHART_END_NAMESPACE