qscatterseries.cpp
178 lines
| 4.4 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r794 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
Tero Ahola
|
r42 | #include "qscatterseries.h" | ||
Michal Klocek
|
r938 | #include "qscatterseries_p.h" | ||
Michal Klocek
|
r943 | #include "scatterchartitem_p.h" | ||
#include "chartdataset_p.h" | ||||
#include "charttheme_p.h" | ||||
#include "chartanimator_p.h" | ||||
Tero Ahola
|
r42 | |||
Tero Ahola
|
r300 | /*! | ||
\class QScatterSeries | ||||
Michal Klocek
|
r481 | \brief The QScatterSeries class is used for making scatter charts. | ||
Tero Ahola
|
r42 | |||
Tero Ahola
|
r300 | \mainclass | ||
Michal Klocek
|
r481 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis | ||
and the vertical axis. | ||||
Tero Ahola
|
r300 | |||
Tero Ahola
|
r995 | \image examples_scatterchart.png | ||
Tero Ahola
|
r300 | |||
Michal Klocek
|
r481 | Creating basic scatter chart is simple: | ||
\code | ||||
QScatterSeries* series = new QScatterSeries(); | ||||
Jani Honkonen
|
r796 | series->append(0, 6); | ||
series->append(2, 4); | ||||
Michal Klocek
|
r481 | ... | ||
Tero Ahola
|
r995 | chart->addSeries(series); | ||
Michal Klocek
|
r481 | \endcode | ||
Tero Ahola
|
r300 | */ | ||
Tero Ahola
|
r42 | |||
Tero Ahola
|
r261 | /*! | ||
\enum QScatterSeries::MarkerShape | ||||
This enum describes the shape used when rendering marker items. | ||||
\value MarkerShapeCircle | ||||
Michal Klocek
|
r541 | \value MarkerShapeRectangle | ||
Tero Ahola
|
r261 | */ | ||
Jani Honkonen
|
r1341 | /*! | ||
\property QScatterSeries::markerShape | ||||
Defines the shape of the marker used to draw the points in the series. | ||||
*/ | ||||
Tero Ahola
|
r1349 | /*! | ||
\fn void QScatterSeries::markerShapeChanged() | ||||
Emitted when marker shape is changed | ||||
*/ | ||||
/*! | ||||
\fn void QScatterSeries::markerSizeChanged() | ||||
Emitted when marker size is changed | ||||
*/ | ||||
Jani Honkonen
|
r1341 | /*! | ||
\property QScatterSeries::markerSize | ||||
Defines the size of the marker used to draw the points in the series. | ||||
*/ | ||||
Tero Ahola
|
r260 | /*! | ||
Tero Ahola
|
r300 | \fn QChartSeriesType QScatterSeries::type() const | ||
\brief Returns QChartSeries::SeriesTypeScatter. | ||||
Michal Klocek
|
r1107 | \sa QAbstractSeries, SeriesType | ||
Tero Ahola
|
r300 | */ | ||
Tero Ahola
|
r260 | |||
Tero Ahola
|
r300 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Tero Ahola
|
r261 | /*! | ||
Constructs a series object which is a child of \a parent. | ||||
*/ | ||||
Michal Klocek
|
r938 | QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent) | ||
Tero Ahola
|
r42 | { | ||
} | ||||
Tero Ahola
|
r260 | /*! | ||
Tero Ahola
|
r261 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | ||
Tero Ahola
|
r260 | */ | ||
Tero Ahola
|
r158 | QScatterSeries::~QScatterSeries() | ||
Tero Ahola
|
r42 | { | ||
Michal Klocek
|
r1270 | Q_D(QScatterSeries); | ||
if(d->m_dataset) { | ||||
d->m_dataset->removeSeries(this); | ||||
} | ||||
Tero Ahola
|
r48 | } | ||
Michal Klocek
|
r1107 | QAbstractSeries::SeriesType QScatterSeries::type() const | ||
Michal Klocek
|
r938 | { | ||
Tero Ahola
|
r988 | return QAbstractSeries::SeriesTypeScatter; | ||
Michal Klocek
|
r938 | } | ||
Tero Ahola
|
r261 | /*! | ||
Tero Ahola
|
r459 | Returns the shape used for drawing markers. | ||
Tero Ahola
|
r261 | */ | ||
Tero Ahola
|
r1276 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const | ||
Tero Ahola
|
r195 | { | ||
Michal Klocek
|
r938 | Q_D(const QScatterSeries); | ||
return d->m_shape; | ||||
Tero Ahola
|
r195 | } | ||
Tero Ahola
|
r261 | /*! | ||
Tero Ahola
|
r300 | Overrides the default shape of the marker items with a user defined \a shape. The default shape | ||
is defined by chart theme setting. | ||||
Tero Ahola
|
r261 | */ | ||
Tero Ahola
|
r1276 | void QScatterSeries::setMarkerShape(MarkerShape shape) | ||
Tero Ahola
|
r195 | { | ||
Michal Klocek
|
r938 | Q_D(QScatterSeries); | ||
if (d->m_shape != shape) { | ||||
d->m_shape = shape; | ||||
Tero Ahola
|
r1349 | emit markerShapeChanged(); | ||
Michal Klocek
|
r573 | } | ||
Tero Ahola
|
r195 | } | ||
Tero Ahola
|
r397 | /*! | ||
Returns the size of the marker items. | ||||
*/ | ||||
Tero Ahola
|
r1276 | qreal QScatterSeries::markerSize() const | ||
Tero Ahola
|
r397 | { | ||
Michal Klocek
|
r938 | Q_D(const QScatterSeries); | ||
return d->m_size; | ||||
Tero Ahola
|
r397 | } | ||
/*! | ||||
Tero Ahola
|
r814 | Set the \a size of the marker items. The default size is 15. | ||
Tero Ahola
|
r397 | */ | ||
Tero Ahola
|
r1276 | void QScatterSeries::setMarkerSize(qreal size) | ||
Tero Ahola
|
r397 | { | ||
Michal Klocek
|
r938 | Q_D(QScatterSeries); | ||
if (!qFuzzyIsNull(d->m_size - size)) { | ||||
d->m_size = size; | ||||
Tero Ahola
|
r1349 | emit markerSizeChanged(); | ||
Michal Klocek
|
r573 | } | ||
Tero Ahola
|
r397 | } | ||
Michal Klocek
|
r938 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q), | ||||
m_shape(QScatterSeries::MarkerShapeCircle), | ||||
m_size(15.0) | ||||
{ | ||||
}; | ||||
Michal Klocek
|
r943 | Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) | ||
{ | ||||
Q_Q(QScatterSeries); | ||||
ScatterChartItem *scatter = new ScatterChartItem(q,presenter); | ||||
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | ||||
Michal Klocek
|
r1217 | scatter->setAnimator(presenter->animator()); | ||
scatter->setAnimation(new XYAnimation(scatter)); | ||||
Michal Klocek
|
r943 | } | ||
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | ||||
return scatter; | ||||
} | ||||
Tero Ahola
|
r1276 | #include "moc_qscatterseries.cpp" | ||
Michal Klocek
|
r938 | |||
Tero Ahola
|
r42 | QTCOMMERCIALCHART_END_NAMESPACE | ||