qlineseries.cpp
162 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r349 | #include "qlineseries.h" | ||
|
r938 | #include "qlineseries_p.h" | ||
|
r943 | #include "linechartitem_p.h" | ||
#include "chartdataset_p.h" | ||||
#include "charttheme_p.h" | ||||
|
r2516 | #include "qchart_p.h" | ||
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
r21 | |||
|
r331 | /*! | ||
|
r350 | \class QLineSeries | ||
\brief The QLineSeries class is used for making line charts. | ||||
|
r331 | |||
\mainclass | ||||
|
r2097 | A line chart is used to show information as a series of data points | ||
connected by straight lines. | ||||
|
r331 | |||
|
r995 | \image examples_linechart.png | ||
|
r331 | |||
|
r2097 | Creating basic line chart is simple: | ||
\code | ||||
|
r995 | QLineSeries* series = new QLineSeries(); | ||
|
r796 | series->append(0, 6); | ||
series->append(2, 4); | ||||
|
r995 | ... | ||
chart->addSeries(series); | ||||
|
r369 | \endcode | ||
|
r331 | */ | ||
|
r1491 | /*! | ||
\qmlclass LineSeries QLineSeries | ||||
\inherits XYSeries | ||||
The following QML shows how to create a simple line chart: | ||||
\snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1 | ||||
\beginfloatleft | ||||
\image demos_qmlchart2.png | ||||
\endfloat | ||||
\clearfloat | ||||
*/ | ||||
|
r331 | |||
/*! | ||||
|
r1107 | \fn virtual SeriesType QLineSeries::type() const | ||
|
r331 | \brief Returns type of series. | ||
|
r1107 | \sa QAbstractSeries, SeriesType | ||
|
r331 | */ | ||
|
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. | ||||
*/ | ||||
|
r374 | /*! | ||
|
r470 | Constructs empty series object which is a child of \a parent. | ||
|
r974 | When series object is added to QChartView or QChart instance ownerships is transferred. | ||
|
r331 | */ | ||
|
r2097 | QLineSeries::QLineSeries(QObject *parent) | ||
: QXYSeries(*new QLineSeriesPrivate(this), parent) | ||||
|
r938 | { | ||
} | ||||
|
r973 | /*! | ||
\internal | ||||
*/ | ||||
|
r2097 | QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent) | ||
: QXYSeries(d, parent) | ||||
|
r470 | { | ||
|
r331 | |||
|
r470 | } | ||
|
r392 | /*! | ||
|
r470 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | ||
and are deleted when mentioned object are destroyed. | ||||
|
r392 | */ | ||
|
r470 | QLineSeries::~QLineSeries() | ||
{ | ||||
|
r1069 | Q_D(QLineSeries); | ||
|
r2273 | if (d->m_chart) | ||
d->m_chart->removeSeries(this); | ||||
|
r470 | } | ||
|
r392 | |||
|
r1107 | QAbstractSeries::SeriesType QLineSeries::type() const | ||
|
r21 | { | ||
|
r988 | return QAbstractSeries::SeriesTypeLine; | ||
|
r21 | } | ||
|
r938 | /* | ||
|
r349 | QDebug operator<< (QDebug debug, const QLineSeries series) | ||
|
r21 | { | ||
|
r938 | Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size()); | ||
int size = series.d_func()->m_x.size(); | ||||
|
r743 | for (int i=0; i<size; i++) { | ||
|
r938 | debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") "; | ||
|
r21 | } | ||
return debug.space(); | ||||
} | ||||
|
r938 | */ | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
|
r2104 | QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q) | ||
: QXYSeriesPrivate(q) | ||||
|
r938 | { | ||
}; | ||||
|
r21 | |||
|
r2273 | void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | ||
|
r943 | { | ||
Q_Q(QLineSeries); | ||||
|
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(); | ||||
|
r2516 | if (forced || QChartPrivate::defaultPen() == m_pen) { | ||
QPen pen; | ||||
|
r2273 | pen.setColor(colors.at(index % colors.size())); | ||
pen.setWidthF(2); | ||||
q->setPen(pen); | ||||
} | ||||
|
r943 | } | ||
|
r1276 | #include "moc_qlineseries.cpp" | ||
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||