qsplineseries.cpp
175 lines
| 5.4 KiB
| text/x-c
|
CppLexer
Miikka Heikkinen
|
r2854 | /**************************************************************************** | ||
Jani Honkonen
|
r794 | ** | ||
Miikka Heikkinen
|
r2854 | ** Copyright (C) 2016 The Qt Company Ltd. | ||
** Contact: https://www.qt.io/licensing/ | ||||
Jani Honkonen
|
r794 | ** | ||
Miikka Heikkinen
|
r2854 | ** This file is part of the Qt Charts module of the Qt Toolkit. | ||
Jani Honkonen
|
r794 | ** | ||
Miikka Heikkinen
|
r2854 | ** $QT_BEGIN_LICENSE:GPL$ | ||
Titta Heikkala
|
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 | ||||
Miikka Heikkinen
|
r2854 | ** and conditions see https://www.qt.io/terms-conditions. For further | ||
** information use the contact form at https://www.qt.io/contact-us. | ||||
** | ||||
** GNU General Public License Usage | ||||
** Alternatively, this file may be used under the terms of the GNU | ||||
** General Public License version 3 or (at your option) any later version | ||||
** approved by the KDE Free Qt Foundation. The licenses are as published by | ||||
** the Free Software Foundation and appearing in the file LICENSE.GPL3 | ||||
** included in the packaging of this file. Please review the following | ||||
** information to ensure the GNU General Public License requirements will | ||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html. | ||||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
Miikka Heikkinen
|
r2854 | ****************************************************************************/ | ||
Jani Honkonen
|
r794 | |||
Titta Heikkala
|
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> | ||||
Marek Rosa
|
r295 | |||
Marek Rosa
|
r433 | /*! | ||
\class QSplineSeries | ||||
Titta Heikkala
|
r2639 | \inmodule Qt Charts | ||
Marek Rosa
|
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. | ||||
Tero Ahola
|
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
|
r433 | */ | ||
Titta Heikkala
|
r2639 | /*! | ||
\qmltype SplineSeries | ||||
\instantiates QSplineSeries | ||||
Titta Heikkala
|
r2712 | \inqmlmodule QtCharts | ||
Marek Rosa
|
r433 | |||
Titta Heikkala
|
r2712 | \inherits XYSeries | ||
\brief The SplineSeries type is used for making spline charts. | ||||
Tero Ahola
|
r1491 | |||
Titta Heikkala
|
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 | ||||
Tero Ahola
|
r1491 | */ | ||
/*! | ||||
\fn QSeriesType QSplineSeries::type() const | ||||
Returns the type of the series | ||||
*/ | ||||
Marek Rosa
|
r433 | |||
Tero Ahola
|
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. | ||||
*/ | ||||
Titta Heikkala
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
Marek Rosa
|
r401 | |||
Marek Rosa
|
r433 | /*! | ||
Constructs empty series object which is a child of \a parent. | ||||
Miikka Heikkinen
|
r2494 | When series object is added to a QChart instance then the ownerships is transferred. | ||
Marek Rosa
|
r433 | */ | ||
Jani Honkonen
|
r2097 | QSplineSeries::QSplineSeries(QObject *parent) | ||
: QLineSeries(*new QSplineSeriesPrivate(this), parent) | ||||
Marek Rosa
|
r295 | { | ||
} | ||||
Marek Rosa
|
r305 | |||
Jani Honkonen
|
r1351 | /*! | ||
Destroys the object. | ||||
*/ | ||||
Michal Klocek
|
r1082 | QSplineSeries::~QSplineSeries() | ||
{ | ||||
Q_D(QSplineSeries); | ||||
Michal Klocek
|
r2273 | if (d->m_chart) | ||
d->m_chart->removeSeries(this); | ||||
Michal Klocek
|
r1082 | } | ||
Michal Klocek
|
r1107 | QAbstractSeries::SeriesType QSplineSeries::type() const | ||
Michal Klocek
|
r938 | { | ||
Tero Ahola
|
r988 | return QAbstractSeries::SeriesTypeSpline; | ||
Michal Klocek
|
r938 | } | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
Jani Honkonen
|
r2104 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q) | ||
Jani Honkonen
|
r2097 | : QLineSeriesPrivate(q) | ||
Michal Klocek
|
r938 | { | ||
Marek Rosa
|
r1309 | } | ||
Michal Klocek
|
r938 | |||
Michal Klocek
|
r2273 | void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | ||
Michal Klocek
|
r943 | { | ||
Q_Q(QSplineSeries); | ||||
Michal Klocek
|
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(); | ||||
Miikka Heikkinen
|
r2516 | if (forced || QChartPrivate::defaultPen() == m_pen) { | ||
QPen pen; | ||||
Michal Klocek
|
r2273 | pen.setColor(colors.at(index % colors.size())); | ||
pen.setWidthF(2); | ||||
q->setPen(pen); | ||||
} | ||||
Titta Heikkala
|
r2689 | |||
if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { | ||||
QColor color = theme->labelBrush().color(); | ||||
q->setPointLabelsColor(color); | ||||
} | ||||
Michal Klocek
|
r2273 | } | ||
Titta Heikkala
|
r2804 | void QSplineSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, | ||
int duration, QEasingCurve &curve) | ||||
Michal Klocek
|
r2273 | { | ||
SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); | ||||
Q_ASSERT(item); | ||||
Miikka Heikkinen
|
r2555 | if (item->animation()) | ||
item->animation()->stopAndDestroyLater(); | ||||
if (options.testFlag(QChart::SeriesAnimations)) | ||||
Titta Heikkala
|
r2804 | item->setAnimation(new SplineAnimation(item, duration, curve)); | ||
Miikka Heikkinen
|
r2555 | else | ||
Michal Klocek
|
r2273 | item->setAnimation(0); | ||
Titta Heikkala
|
r2804 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); | ||
Michal Klocek
|
r943 | } | ||
Marek Rosa
|
r401 | #include "moc_qsplineseries.cpp" | ||
Michal Klocek
|
r938 | #include "moc_qsplineseries_p.cpp" | ||
Marek Rosa
|
r401 | |||
Titta Heikkala
|
r2712 | QT_CHARTS_END_NAMESPACE | ||