qlineseries.cpp
180 lines
| 5.2 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/QLineSeries> | ||
#include <private/qlineseries_p.h> | ||||
#include <private/linechartitem_p.h> | ||||
#include <private/chartdataset_p.h> | ||||
#include <private/charttheme_p.h> | ||||
#include <private/qchart_p.h> | ||||
Titta Heikkala
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
Michal Klocek
|
r21 | |||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r350 | \class QLineSeries | ||
Titta Heikkala
|
r2639 | \inmodule Qt Charts | ||
Michal Klocek
|
r350 | \brief The QLineSeries class is used for making line charts. | ||
Michal Klocek
|
r331 | |||
Jani Honkonen
|
r2097 | A line chart is used to show information as a series of data points | ||
connected by straight lines. | ||||
Michal Klocek
|
r331 | |||
Tero Ahola
|
r995 | \image examples_linechart.png | ||
Michal Klocek
|
r331 | |||
Jani Honkonen
|
r2097 | Creating basic line chart is simple: | ||
\code | ||||
Tero Ahola
|
r995 | QLineSeries* series = new QLineSeries(); | ||
Jani Honkonen
|
r796 | series->append(0, 6); | ||
series->append(2, 4); | ||||
Tero Ahola
|
r995 | ... | ||
chart->addSeries(series); | ||||
Michal Klocek
|
r369 | \endcode | ||
Michal Klocek
|
r331 | */ | ||
Titta Heikkala
|
r2639 | /*! | ||
\qmltype LineSeries | ||||
\instantiates QLineSeries | ||||
Titta Heikkala
|
r2712 | \inqmlmodule QtCharts | ||
Titta Heikkala
|
r2639 | |||
Titta Heikkala
|
r2712 | \inherits XYSeries | ||
\brief The LineSeries type is used for making line charts. | ||||
Tero Ahola
|
r1491 | |||
Titta Heikkala
|
r2712 | The following QML shows how to create a simple line chart: | ||
\snippet qmlchart/qml/qmlchart/View2.qml 1 | ||||
\beginfloatleft | ||||
\image examples_qmlchart2.png | ||||
\endfloat | ||||
\clearfloat | ||||
Tero Ahola
|
r1491 | */ | ||
Michal Klocek
|
r331 | |||
/*! | ||||
Michal Klocek
|
r1107 | \fn virtual SeriesType QLineSeries::type() const | ||
Michal Klocek
|
r331 | \brief Returns type of series. | ||
Michal Klocek
|
r1107 | \sa QAbstractSeries, SeriesType | ||
Michal Klocek
|
r331 | */ | ||
Tero Ahola
|
r1904 | /*! | ||
\qmlproperty real LineSeries::width | ||||
The width of the line. By default the width is 2.0. | ||||
*/ | ||||
/*! | ||||
\qmlproperty Qt::PenStyle LineSeries::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 LineSeries::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. | ||||
*/ | ||||
Michal Klocek
|
r374 | /*! | ||
Michal Klocek
|
r470 | Constructs empty series object which is a child of \a parent. | ||
Michal Klocek
|
r974 | When series object is added to QChartView or QChart instance ownerships is transferred. | ||
Michal Klocek
|
r331 | */ | ||
Jani Honkonen
|
r2097 | QLineSeries::QLineSeries(QObject *parent) | ||
: QXYSeries(*new QLineSeriesPrivate(this), parent) | ||||
Michal Klocek
|
r938 | { | ||
} | ||||
Tero Ahola
|
r973 | /*! | ||
\internal | ||||
*/ | ||||
Jani Honkonen
|
r2097 | QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent) | ||
: QXYSeries(d, parent) | ||||
Michal Klocek
|
r470 | { | ||
Michal Klocek
|
r331 | |||
Michal Klocek
|
r470 | } | ||
Michal Klocek
|
r392 | /*! | ||
Michal Klocek
|
r470 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | ||
and are deleted when mentioned object are destroyed. | ||||
Michal Klocek
|
r392 | */ | ||
Michal Klocek
|
r470 | QLineSeries::~QLineSeries() | ||
{ | ||||
Michal Klocek
|
r1069 | Q_D(QLineSeries); | ||
Michal Klocek
|
r2273 | if (d->m_chart) | ||
d->m_chart->removeSeries(this); | ||||
Michal Klocek
|
r470 | } | ||
Michal Klocek
|
r392 | |||
Michal Klocek
|
r1107 | QAbstractSeries::SeriesType QLineSeries::type() const | ||
Michal Klocek
|
r21 | { | ||
Tero Ahola
|
r988 | return QAbstractSeries::SeriesTypeLine; | ||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r938 | /* | ||
Michal Klocek
|
r349 | QDebug operator<< (QDebug debug, const QLineSeries series) | ||
Michal Klocek
|
r21 | { | ||
Michal Klocek
|
r938 | Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size()); | ||
int size = series.d_func()->m_x.size(); | ||||
sauimone
|
r743 | for (int i=0; i<size; i++) { | ||
Michal Klocek
|
r938 | debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") "; | ||
Michal Klocek
|
r21 | } | ||
return debug.space(); | ||||
} | ||||
Michal Klocek
|
r938 | */ | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
Jani Honkonen
|
r2104 | QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q) | ||
: QXYSeriesPrivate(q) | ||||
Michal Klocek
|
r938 | { | ||
Miikka Heikkinen
|
r2733 | } | ||
Michal Klocek
|
r21 | |||
Michal Klocek
|
r2273 | void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | ||
Michal Klocek
|
r943 | { | ||
Q_Q(QLineSeries); | ||||
Michal Klocek
|
r2273 | LineChartItem *line = new LineChartItem(q,parent); | ||
m_item.reset(line); | ||||
QAbstractSeriesPrivate::initializeGraphics(parent); | ||||
} | ||||
void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | ||||
{ | ||||
Q_Q(QLineSeries); | ||||
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
|
r943 | } | ||
Tero Ahola
|
r1276 | #include "moc_qlineseries.cpp" | ||
Titta Heikkala
|
r2712 | QT_CHARTS_END_NAMESPACE | ||