qsplineseries.cpp
167 lines
| 4.9 KiB
| text/x-c
|
CppLexer
|
r2845 | /****************************************************************************** | ||
|
r794 | ** | ||
|
r2845 | ** Copyright (C) 2015 The Qt Company Ltd. | ||
** Contact: http://www.qt.io/licensing/ | ||||
|
r794 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r794 | ** | ||
|
r2845 | ** $QT_BEGIN_LICENSE:COMM$ | ||
|
r794 | ** | ||
|
r2845 | ** Commercial License Usage | ||
** Licensees holding valid commercial Qt licenses may use this file in | ||||
** accordance with the commercial license agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and The Qt Company. For licensing terms | ||||
** and conditions see http://www.qt.io/terms-conditions. For further | ||||
** information use the contact form at http://www.qt.io/contact-us. | ||||
|
r794 | ** | ||
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
******************************************************************************/ | ||||
|
r794 | |||
|
r2714 | #include <QtCharts/QSplineSeries> | ||
#include <private/qsplineseries_p.h> | ||||
#include <private/splinechartitem_p.h> | ||||
#include <private/chartdataset_p.h> | ||||
#include <private/charttheme_p.h> | ||||
#include <private/splineanimation_p.h> | ||||
#include <private/qchart_p.h> | ||||
|
r295 | |||
|
r433 | /*! | ||
\class QSplineSeries | ||||
|
r2639 | \inmodule Qt Charts | ||
|
r433 | \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 | */ | ||
|
r2639 | /*! | ||
\qmltype SplineSeries | ||||
\instantiates QSplineSeries | ||||
|
r2712 | \inqmlmodule QtCharts | ||
|
r433 | |||
|
r2712 | \inherits XYSeries | ||
\brief The SplineSeries type is used for making spline charts. | ||||
|
r1491 | |||
|
r2712 | The following QML shows how to create a simple spline chart: | ||
\snippet qmlchart/qml/qmlchart/View3.qml 1 | ||||
\beginfloatleft | ||||
\image examples_qmlchart3.png | ||||
\endfloat | ||||
\clearfloat | ||||
|
r1491 | */ | ||
/*! | ||||
\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. | ||||
*/ | ||||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r401 | |||
|
r433 | /*! | ||
Constructs empty series object which is a child of \a parent. | ||||
|
r2494 | When series object is added to a 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(); | ||||
|
r2516 | if (forced || QChartPrivate::defaultPen() == m_pen) { | ||
QPen pen; | ||||
|
r2273 | pen.setColor(colors.at(index % colors.size())); | ||
pen.setWidthF(2); | ||||
q->setPen(pen); | ||||
} | ||||
|
r2689 | |||
if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { | ||||
QColor color = theme->labelBrush().color(); | ||||
q->setPointLabelsColor(color); | ||||
} | ||||
|
r2273 | } | ||
|
r2804 | void QSplineSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, | ||
int duration, QEasingCurve &curve) | ||||
|
r2273 | { | ||
SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); | ||||
Q_ASSERT(item); | ||||
|
r2555 | if (item->animation()) | ||
item->animation()->stopAndDestroyLater(); | ||||
if (options.testFlag(QChart::SeriesAnimations)) | ||||
|
r2804 | item->setAnimation(new SplineAnimation(item, duration, curve)); | ||
|
r2555 | else | ||
|
r2273 | item->setAnimation(0); | ||
|
r2804 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); | ||
|
r943 | } | ||
|
r401 | #include "moc_qsplineseries.cpp" | ||
|
r938 | #include "moc_qsplineseries_p.cpp" | ||
|
r401 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||