qsplineseries.cpp
152 lines
| 4.3 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
** | ||||
|
r2432 | ** Copyright (C) 2013 Digia Plc | ||
|
r794 | ** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r295 | #include "qsplineseries.h" | ||
|
r938 | #include "qsplineseries_p.h" | ||
|
r943 | #include "splinechartitem_p.h" | ||
#include "chartdataset_p.h" | ||||
#include "charttheme_p.h" | ||||
|
r1735 | #include "splineanimation_p.h" | ||
|
r295 | |||
|
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. | ||||
|
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 | ||||
|
r433 | */ | ||
/*! | ||||
|
r1491 | \qmlclass SplineSeries QSplineSeries | ||
\inherits XYSeries | ||||
The following QML shows how to create a simple spline chart: | ||||
\snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1 | ||||
\beginfloatleft | ||||
\image demos_qmlchart3.png | ||||
\endfloat | ||||
\clearfloat | ||||
*/ | ||||
/*! | ||||
\fn QSeriesType QSplineSeries::type() const | ||||
Returns the type of the series | ||||
*/ | ||||
|
r433 | |||
|
r1904 | /*! | ||
\qmlproperty real SplineSeries::width | ||||
The width of the line. By default the width is 2.0. | ||||
*/ | ||||
/*! | ||||
\qmlproperty Qt::PenStyle SplineSeries::style | ||||
Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine, | ||||
Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API. | ||||
By default the style is Qt.SolidLine. | ||||
*/ | ||||
/*! | ||||
\qmlproperty Qt::PenCapStyle SplineSeries::capStyle | ||||
Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By | ||||
default the cap style is Qt.SquareCap. | ||||
*/ | ||||
|
r401 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
r433 | /*! | ||
Constructs empty series object which is a child of \a parent. | ||||
|
r974 | When series object is added to QChartView or QChart instance then the ownerships is transferred. | ||
|
r433 | */ | ||
|
r2097 | QSplineSeries::QSplineSeries(QObject *parent) | ||
: QLineSeries(*new QSplineSeriesPrivate(this), parent) | ||||
|
r295 | { | ||
} | ||||
|
r305 | |||
|
r1351 | /*! | ||
Destroys the object. | ||||
*/ | ||||
|
r1082 | QSplineSeries::~QSplineSeries() | ||
{ | ||||
Q_D(QSplineSeries); | ||||
|
r2273 | if (d->m_chart) | ||
d->m_chart->removeSeries(this); | ||||
|
r1082 | } | ||
|
r1107 | QAbstractSeries::SeriesType QSplineSeries::type() const | ||
|
r938 | { | ||
|
r988 | return QAbstractSeries::SeriesTypeSpline; | ||
|
r938 | } | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
|
r2104 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q) | ||
|
r2097 | : QLineSeriesPrivate(q) | ||
|
r938 | { | ||
|
r1309 | } | ||
|
r938 | |||
|
r2273 | void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | ||
|
r943 | { | ||
Q_Q(QSplineSeries); | ||||
|
r2273 | SplineChartItem *spline = new SplineChartItem(q,parent); | ||
m_item.reset(spline); | ||||
QAbstractSeriesPrivate::initializeGraphics(parent); | ||||
} | ||||
void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | ||||
{ | ||||
Q_Q(QSplineSeries); | ||||
const QList<QColor> colors = theme->seriesColors(); | ||||
QPen pen; | ||||
if (forced || pen == m_pen) { | ||||
pen.setColor(colors.at(index % colors.size())); | ||||
pen.setWidthF(2); | ||||
q->setPen(pen); | ||||
} | ||||
} | ||||
void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | ||||
{ | ||||
SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); | ||||
Q_ASSERT(item); | ||||
if (options.testFlag(QChart::SeriesAnimations)) { | ||||
item->setAnimation(new SplineAnimation(item)); | ||||
}else{ | ||||
item->setAnimation(0); | ||||
} | ||||
QAbstractSeriesPrivate::initializeAnimations(options); | ||||
|
r943 | } | ||
|
r401 | #include "moc_qsplineseries.cpp" | ||
|
r938 | #include "moc_qsplineseries_p.cpp" | ||
|
r401 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||