summaryrefslogtreecommitdiffstats
path: root/src/charts/scatterchart
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@digia.com>2014-07-01 07:10:00 +0300
committerTitta Heikkala <titta.heikkala@theqtcompany.com>2014-10-14 13:04:52 +0300
commitc544258484ff4fd5d2b88402fbaa5d154b89a3a2 (patch)
tree7659625abb566dec55d3783ed820b928542d9b2b /src/charts/scatterchart
parent76339f714f088645e911cee65bdb66055fe029aa (diff)
Qt Charts project file structure change
Charts repository structure is changed to follow the structure of a Qt Add-On module. The task includes following changes: - All macros and definitions named 'commercial' have been renamed. - Compile errors related to QString and qSort usage have been fixed. - Old demos are moved under examples. The QML examples now support only Qt Quick 2.0, the support for Qt Quick 1 is removed. - The QML examples with multiple views are updated so that they are usable also with touch devices. - Unnecessary version checks are removed from examples. - The build stamp has been removed as it was only meant for Charts development purposes and it's no longer needed. Also development build related debug prints are removed as __DATE__ can't be used for all OS thus it doesn't make much sense. - Documentation structure has been updated based on the new module structure. The raw HTML files have been removed. Demos are combined to examples. - Unnecessary .qdocinc files are no longer needed. The content is moved to the corresponding .cpp files. - The Charts widget designer plugin is updated according to the module change. - The test cases updated according to the project structure change. Tests are added also for version 2.0. - cmake modules generation is not needed with Qt 5.4 and Qt Charts so it's disabled. - The new module name and version are updated to the plugin.qmltypes file. Task-number: QTRD-2844, QTRD-3217, QTRD-3218, QTRD-3277, QTRD-3228, QTRD-2526, QTRD-3233, QTRD-3222 Change-Id: Ib7fb26057cde710ffaf6bc780c8bf52a16f45160 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>
Diffstat (limited to 'src/charts/scatterchart')
-rw-r--r--src/charts/scatterchart/qscatterseries.cpp336
-rw-r--r--src/charts/scatterchart/qscatterseries.h75
-rw-r--r--src/charts/scatterchart/qscatterseries_p.h53
-rw-r--r--src/charts/scatterchart/scatter.pri13
-rw-r--r--src/charts/scatterchart/scatterchartitem.cpp237
-rw-r--r--src/charts/scatterchart/scatterchartitem_p.h151
6 files changed, 865 insertions, 0 deletions
diff --git a/src/charts/scatterchart/qscatterseries.cpp b/src/charts/scatterchart/qscatterseries.cpp
new file mode 100644
index 00000000..346ca83b
--- /dev/null
+++ b/src/charts/scatterchart/qscatterseries.cpp
@@ -0,0 +1,336 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 Enterprise Charts Add-on.
+**
+** $QT_BEGIN_LICENSE$
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise 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$
+**
+****************************************************************************/
+
+#include "qscatterseries.h"
+#include "qscatterseries_p.h"
+#include "scatterchartitem_p.h"
+#include "chartdataset_p.h"
+#include "charttheme_p.h"
+#include "scatteranimation_p.h"
+#include "qchart_p.h"
+
+/*!
+ \class QScatterSeries
+ \inmodule Qt Charts
+ \brief The QScatterSeries class is used for making scatter charts.
+
+ \mainclass
+
+ 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.
+
+ \image examples_scatterchart.png
+
+ Creating basic scatter chart is simple:
+ \code
+ QScatterSeries* series = new QScatterSeries();
+ series->append(0, 6);
+ series->append(2, 4);
+ ...
+ chart->addSeries(series);
+ \endcode
+*/
+/*!
+ \qmltype ScatterSeries
+ \instantiates QScatterSeries
+ \inqmlmodule QtCharts
+
+ \inherits XYSeries
+
+ \brief The ScatterSeries type is used for making scatter charts.
+
+ The following QML shows how to create a chart with two simple scatter series:
+ \snippet qmlchart/qml/qmlchart/View5.qml 1
+
+ \beginfloatleft
+ \image examples_qmlchart5.png
+ \endfloat
+ \clearfloat
+*/
+
+/*!
+ \enum QScatterSeries::MarkerShape
+
+ This enum describes the shape used when rendering marker items.
+
+ \value MarkerShapeCircle
+ \value MarkerShapeRectangle
+*/
+
+/*!
+ \property QScatterSeries::brush
+ Brush used to draw the series.
+*/
+
+/*!
+ \property QScatterSeries::color
+ Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
+ \sa QScatterSeries::brush()
+*/
+
+/*!
+ \property QScatterSeries::borderColor
+ Line (pen) color of the series. This is a convenience property for modifying the color of pen.
+ \sa QScatterSeries::pen()
+*/
+/*!
+ \qmlproperty color ScatterSeries::borderColor
+ Border (pen) color of the series.
+*/
+
+/*!
+ \qmlproperty real ScatterSeries::borderWidth
+ The width of the border line. By default the width is 2.0.
+*/
+
+/*!
+ \property QScatterSeries::markerShape
+ Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
+*/
+/*!
+ \qmlproperty MarkerShape ScatterSeries::markerShape
+ Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
+ ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
+ The default shape is ScatterSeries.MarkerShapeCircle.
+*/
+
+/*!
+ \property QScatterSeries::markerSize
+ Defines the size of the marker used to draw the points in the series. The default size is 15.0.
+*/
+/*!
+ \qmlproperty real ScatterSeries::markerSize
+ Defines the size of the marker used to draw the points in the series. The default size is 15.0.
+*/
+
+/*!
+ \qmlproperty QString ScatterSeries::brushFilename
+ The name of the file used as a brush for the series.
+*/
+
+/*!
+ \fn void QScatterSeries::colorChanged(QColor color)
+ Signal is emitted when the fill (brush) color has changed to \a color.
+*/
+
+/*!
+ \fn void QScatterSeries::borderColorChanged(QColor color)
+ Signal is emitted when the line (pen) color has changed to \a color.
+*/
+/*!
+ \qmlsignal ScatterSeries::borderColorChanged(color color)
+ Signal is emitted when the line (pen) color has changed to \a color.
+*/
+
+/*!
+ \fn QAbstractSeries::SeriesType QScatterSeries::type() const
+ Returns QAbstractSeries::SeriesTypeScatter.
+ \sa QAbstractSeries, SeriesType
+*/
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+/*!
+ Constructs a series object which is a child of \a parent.
+*/
+QScatterSeries::QScatterSeries(QObject *parent)
+ : QXYSeries(*new QScatterSeriesPrivate(this), parent)
+{
+}
+
+/*!
+ Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
+*/
+QScatterSeries::~QScatterSeries()
+{
+ Q_D(QScatterSeries);
+ if (d->m_chart)
+ d->m_chart->removeSeries(this);
+}
+
+QAbstractSeries::SeriesType QScatterSeries::type() const
+{
+ return QAbstractSeries::SeriesTypeScatter;
+}
+
+/*!
+ Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
+ pen from chart theme is used.
+ \sa QChart::setTheme()
+*/
+void QScatterSeries::setPen(const QPen &pen)
+{
+ Q_D(QXYSeries);
+ if (d->m_pen != pen) {
+ bool emitColorChanged = d->m_pen.color() != pen.color();
+ d->m_pen = pen;
+ emit d->updated();
+ if (emitColorChanged)
+ emit borderColorChanged(pen.color());
+ }
+}
+
+/*!
+ Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
+ from chart theme setting is used.
+ \sa QChart::setTheme()
+*/
+void QScatterSeries::setBrush(const QBrush &brush)
+{
+ Q_D(QScatterSeries);
+ if (d->m_brush != brush) {
+ bool emitColorChanged = d->m_brush.color() != brush.color();
+ d->m_brush = brush;
+ emit d->updated();
+ if (emitColorChanged)
+ emit colorChanged(brush.color());
+ }
+}
+
+QBrush QScatterSeries::brush() const
+{
+ Q_D(const QScatterSeries);
+ if (d->m_brush == QChartPrivate::defaultBrush())
+ return QBrush();
+ else
+ return d->m_brush;
+}
+
+void QScatterSeries::setColor(const QColor &color)
+{
+ QBrush b = brush();
+ if (b == QChartPrivate::defaultBrush())
+ b = QBrush();
+ if (b == QBrush())
+ b.setStyle(Qt::SolidPattern);
+ b.setColor(color);
+ setBrush(b);
+}
+
+QColor QScatterSeries::color() const
+{
+ return brush().color();
+}
+
+void QScatterSeries::setBorderColor(const QColor &color)
+{
+ QPen p = pen();
+ if (p == QChartPrivate::defaultPen())
+ p = QPen();
+ p.setColor(color);
+ setPen(p);
+}
+
+QColor QScatterSeries::borderColor() const
+{
+ return pen().color();
+}
+
+QScatterSeries::MarkerShape QScatterSeries::markerShape() const
+{
+ Q_D(const QScatterSeries);
+ return d->m_shape;
+}
+
+void QScatterSeries::setMarkerShape(MarkerShape shape)
+{
+ Q_D(QScatterSeries);
+ if (d->m_shape != shape) {
+ d->m_shape = shape;
+ emit d->updated();
+ }
+}
+
+qreal QScatterSeries::markerSize() const
+{
+ Q_D(const QScatterSeries);
+ return d->m_size;
+}
+
+void QScatterSeries::setMarkerSize(qreal size)
+{
+ Q_D(QScatterSeries);
+
+ if (!qFuzzyCompare(d->m_size, size)) {
+ d->m_size = size;
+ emit d->updated();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
+ : QXYSeriesPrivate(q),
+ m_shape(QScatterSeries::MarkerShapeCircle),
+ m_size(15.0)
+{
+}
+
+void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
+{
+ Q_Q(QScatterSeries);
+ ScatterChartItem *scatter = new ScatterChartItem(q,parent);
+ m_item.reset(scatter);
+ QAbstractSeriesPrivate::initializeGraphics(parent);
+}
+
+void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
+{
+ Q_Q(QScatterSeries);
+ const QList<QColor> colors = theme->seriesColors();
+ const QList<QGradient> gradients = theme->seriesGradients();
+
+ if (forced || QChartPrivate::defaultPen() == m_pen) {
+ QPen pen;
+ pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
+ pen.setWidthF(2);
+ q->setPen(pen);
+ }
+
+ if (forced || QChartPrivate::defaultBrush() == m_brush) {
+ QBrush brush(colors.at(index % colors.size()));
+ q->setBrush(brush);
+ }
+
+ if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
+ QColor color = theme->labelBrush().color();
+ q->setPointLabelsColor(color);
+ }
+}
+
+void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
+{
+ ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
+ Q_ASSERT(item);
+
+ if (item->animation())
+ item->animation()->stopAndDestroyLater();
+
+ if (options.testFlag(QChart::SeriesAnimations))
+ item->setAnimation(new ScatterAnimation(item));
+ else
+ item->setAnimation(0);
+
+ QAbstractSeriesPrivate::initializeAnimations(options);
+}
+
+#include "moc_qscatterseries.cpp"
+
+QT_CHARTS_END_NAMESPACE
diff --git a/src/charts/scatterchart/qscatterseries.h b/src/charts/scatterchart/qscatterseries.h
new file mode 100644
index 00000000..d7f9504a
--- /dev/null
+++ b/src/charts/scatterchart/qscatterseries.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 Enterprise Charts Add-on.
+**
+** $QT_BEGIN_LICENSE$
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise 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$
+**
+****************************************************************************/
+
+#ifndef QSCATTERSERIES_H
+#define QSCATTERSERIES_H
+
+#include <QtCharts/qchartglobal.h>
+#include <QtCharts/qxyseries.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QScatterSeriesPrivate;
+
+class QT_CHARTS_EXPORT QScatterSeries : public QXYSeries
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
+ Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape)
+ Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize)
+ Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
+ Q_ENUMS(MarkerShape)
+
+public:
+ enum MarkerShape {
+ MarkerShapeCircle,
+ MarkerShapeRectangle
+ };
+
+public:
+ explicit QScatterSeries(QObject *parent = 0);
+ ~QScatterSeries();
+ QAbstractSeries::SeriesType type() const;
+ void setPen(const QPen &pen);
+ void setBrush(const QBrush &brush);
+ QBrush brush() const;
+ void setColor(const QColor &color);
+ QColor color() const;
+ void setBorderColor(const QColor &color);
+ QColor borderColor() const;
+ MarkerShape markerShape() const;
+ void setMarkerShape(MarkerShape shape);
+ qreal markerSize() const;
+ void setMarkerSize(qreal size);
+
+Q_SIGNALS:
+ void colorChanged(QColor color);
+ void borderColorChanged(QColor color);
+
+private:
+ Q_DECLARE_PRIVATE(QScatterSeries)
+ Q_DISABLE_COPY(QScatterSeries)
+ friend class ScatterChartItem;
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // QSCATTERSERIES_H
diff --git a/src/charts/scatterchart/qscatterseries_p.h b/src/charts/scatterchart/qscatterseries_p.h
new file mode 100644
index 00000000..69e91655
--- /dev/null
+++ b/src/charts/scatterchart/qscatterseries_p.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 Enterprise Charts Add-on.
+**
+** $QT_BEGIN_LICENSE$
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise 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$
+**
+****************************************************************************/
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt Enterprise Chart API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QSCATTERSERIES_P_H
+#define QSCATTERSERIES_P_H
+
+#include "qxyseries_p.h"
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QScatterSeriesPrivate: public QXYSeriesPrivate
+{
+public:
+ QScatterSeriesPrivate(QScatterSeries *q);
+ void initializeGraphics(QGraphicsItem* parent);
+ void initializeTheme(int index, ChartTheme* theme, bool forced = false);
+ void initializeAnimations(QtCharts::QChart::AnimationOptions options);
+
+private:
+ QScatterSeries::MarkerShape m_shape;
+ qreal m_size;
+ Q_DECLARE_PUBLIC(QScatterSeries)
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif
diff --git a/src/charts/scatterchart/scatter.pri b/src/charts/scatterchart/scatter.pri
new file mode 100644
index 00000000..fcbd119d
--- /dev/null
+++ b/src/charts/scatterchart/scatter.pri
@@ -0,0 +1,13 @@
+INCLUDEPATH += $$PWD
+DEPENDPATH += $$PWD
+
+SOURCES += \
+ $$PWD/qscatterseries.cpp \
+ $$PWD/scatterchartitem.cpp
+
+PRIVATE_HEADERS += \
+ $$PWD/scatterchartitem_p.h \
+ $$PWD/qscatterseries_p.h
+
+PUBLIC_HEADERS += \
+ $$PWD/qscatterseries.h
diff --git a/src/charts/scatterchart/scatterchartitem.cpp b/src/charts/scatterchart/scatterchartitem.cpp
new file mode 100644
index 00000000..597d5d52
--- /dev/null
+++ b/src/charts/scatterchart/scatterchartitem.cpp
@@ -0,0 +1,237 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2014 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 Enterprise Charts Add-on.
+ **
+ ** $QT_BEGIN_LICENSE$
+ ** Licensees holding valid Qt Enterprise licenses may use this file in
+ ** accordance with the Qt Enterprise 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$
+ **
+ ****************************************************************************/
+
+#include "scatterchartitem_p.h"
+#include "qscatterseries.h"
+#include "qscatterseries_p.h"
+#include "chartpresenter_p.h"
+#include "abstractdomain_p.h"
+#include "qchart.h"
+#include <QPainter>
+#include <QGraphicsScene>
+#include <QDebug>
+#include <QGraphicsSceneMouseEvent>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
+ : XYChart(series,item),
+ m_series(series),
+ m_items(this),
+ m_visible(true),
+ m_shape(QScatterSeries::MarkerShapeRectangle),
+ m_size(15),
+ m_pointLabelsVisible(false),
+ m_pointLabelsFormat(series->pointLabelsFormat()),
+ m_pointLabelsFont(series->pointLabelsFont()),
+ m_pointLabelsColor(series->pointLabelsColor())
+{
+ QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
+ QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
+ QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
+ QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)),
+ this, SLOT(handleUpdated()));
+ QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)),
+ this, SLOT(handleUpdated()));
+ QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
+ QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
+
+ setZValue(ChartPresenter::ScatterSeriesZValue);
+ setFlags(QGraphicsItem::ItemClipsChildrenToShape);
+
+ handleUpdated();
+
+ m_items.setHandlesChildEvents(false);
+}
+
+QRectF ScatterChartItem::boundingRect() const
+{
+ return m_rect;
+}
+
+void ScatterChartItem::createPoints(int count)
+{
+ for (int i = 0; i < count; ++i) {
+
+ QGraphicsItem *item = 0;
+
+ switch (m_shape) {
+ case QScatterSeries::MarkerShapeCircle: {
+ item = new CircleMarker(0, 0, m_size, m_size, this);
+ const QRectF &rect = item->boundingRect();
+ item->setPos(-rect.width() / 2, -rect.height() / 2);
+ break;
+ }
+ case QScatterSeries::MarkerShapeRectangle:
+ item = new RectangleMarker(0, 0, m_size, m_size, this);
+ item->setPos(-m_size / 2, -m_size / 2);
+ break;
+ default:
+ qWarning() << "Unsupported marker type";
+ break;
+ }
+ m_items.addToGroup(item);
+ }
+}
+
+void ScatterChartItem::deletePoints(int count)
+{
+ QList<QGraphicsItem *> items = m_items.childItems();
+
+ for (int i = 0; i < count; ++i) {
+ QGraphicsItem *item = items.takeLast();
+ m_markerMap.remove(item);
+ delete(item);
+ }
+}
+
+void ScatterChartItem::markerSelected(QGraphicsItem *marker)
+{
+ emit XYChart::clicked(m_markerMap[marker]);
+}
+
+void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
+{
+ emit XYChart::hovered(m_markerMap[marker], state);
+}
+
+void ScatterChartItem::updateGeometry()
+{
+
+ const QVector<QPointF>& points = geometryPoints();
+
+ if (points.size() == 0) {
+ deletePoints(m_items.childItems().count());
+ return;
+ }
+
+ int diff = m_items.childItems().size() - points.size();
+
+ if (diff > 0)
+ deletePoints(diff);
+ else if (diff < 0)
+ createPoints(-diff);
+
+ if (diff != 0)
+ handleUpdated();
+
+ QList<QGraphicsItem *> items = m_items.childItems();
+
+ QRectF clipRect(QPointF(0,0),domain()->size());
+
+ // Only zoom in if the clipRect fits inside int limits. QWidget::update() uses
+ // a region that has to be compatible with QRect.
+ if (clipRect.height() <= INT_MAX
+ && clipRect.width() <= INT_MAX) {
+ QVector<bool> offGridStatus = offGridStatusVector();
+ const int seriesLastIndex = m_series->count() - 1;
+
+ for (int i = 0; i < points.size(); i++) {
+ QGraphicsItem *item = items.at(i);
+ const QPointF &point = points.at(i);
+ const QRectF &rect = item->boundingRect();
+ // During remove animation series may have different number of points,
+ // so ensure we don't go over the index. Animation handling itself ensures that
+ // if there is actually no points in the series, then it won't generate a fake point,
+ // so we can be assured there is always at least one point in m_series here.
+ // Note that marker map values can be technically incorrect during the animation,
+ // if it was caused by an insert, but this shouldn't be a problem as the points are
+ // fake anyway. After remove animation stops, geometry is updated to correct one.
+ m_markerMap[item] = m_series->at(qMin(seriesLastIndex, i));
+ item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
+
+ if (!m_visible || offGridStatus.at(i))
+ item->setVisible(false);
+ else
+ item->setVisible(true);
+ }
+
+ prepareGeometryChange();
+ m_rect = clipRect;
+ }
+}
+
+void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option)
+ Q_UNUSED(widget)
+
+ QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
+
+ painter->save();
+ painter->setClipRect(clipRect);
+
+ if (m_pointLabelsVisible) {
+ m_series->d_func()->drawSeriesPointLabels(painter, m_points,
+ m_series->markerSize() / 2
+ + m_series->pen().width());
+ }
+
+ painter->restore();
+}
+
+void ScatterChartItem::setPen(const QPen &pen)
+{
+ foreach (QGraphicsItem *item , m_items.childItems())
+ static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
+}
+
+void ScatterChartItem::setBrush(const QBrush &brush)
+{
+ foreach (QGraphicsItem *item , m_items.childItems())
+ static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
+}
+
+void ScatterChartItem::handleUpdated()
+{
+ int count = m_items.childItems().count();
+
+ if (count == 0)
+ return;
+
+ bool recreate = m_visible != m_series->isVisible()
+ || m_size != m_series->markerSize()
+ || m_shape != m_series->markerShape();
+
+ m_visible = m_series->isVisible();
+ m_size = m_series->markerSize();
+ m_shape = m_series->markerShape();
+ setOpacity(m_series->opacity());
+ m_pointLabelsFormat = m_series->pointLabelsFormat();
+ m_pointLabelsVisible = m_series->pointLabelsVisible();
+ m_pointLabelsFont = m_series->pointLabelsFont();
+ m_pointLabelsColor = m_series->pointLabelsColor();
+
+ if (recreate) {
+ deletePoints(count);
+ createPoints(count);
+
+ // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points
+ updateGeometry();
+ }
+
+ setPen(m_series->pen());
+ setBrush(m_series->brush());
+ update();
+}
+
+#include "moc_scatterchartitem_p.cpp"
+
+QT_CHARTS_END_NAMESPACE
diff --git a/src/charts/scatterchart/scatterchartitem_p.h b/src/charts/scatterchart/scatterchartitem_p.h
new file mode 100644
index 00000000..3c18546e
--- /dev/null
+++ b/src/charts/scatterchart/scatterchartitem_p.h
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 Enterprise Charts Add-on.
+**
+** $QT_BEGIN_LICENSE$
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise 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$
+**
+****************************************************************************/
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt Enterprise Chart API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef SCATTERCHARTITEM_H
+#define SCATTERCHARTITEM_H
+
+#include "qchartglobal.h"
+#include "xychart_p.h"
+#include <QGraphicsEllipseItem>
+#include <QPen>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QScatterSeries;
+
+class ScatterChartItem : public XYChart
+{
+ Q_OBJECT
+ Q_INTERFACES(QGraphicsItem)
+public:
+ explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem *item = 0);
+
+public:
+ //from QGraphicsItem
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+ void setPen(const QPen &pen);
+ void setBrush(const QBrush &brush);
+
+ void markerSelected(QGraphicsItem *item);
+ void markerHovered(QGraphicsItem *item, bool state);
+
+public Q_SLOTS:
+ void handleUpdated();
+
+private:
+ void createPoints(int count);
+ void deletePoints(int count);
+
+protected:
+ void updateGeometry();
+
+private:
+ QScatterSeries *m_series;
+ QGraphicsItemGroup m_items;
+ bool m_visible;
+ int m_shape;
+ int m_size;
+ QRectF m_rect;
+ QMap<QGraphicsItem *, QPointF> m_markerMap;
+
+ bool m_pointLabelsVisible;
+ QString m_pointLabelsFormat;
+ QFont m_pointLabelsFont;
+ QColor m_pointLabelsColor;
+};
+
+class CircleMarker: public QGraphicsEllipseItem
+{
+
+public:
+ CircleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
+ : QGraphicsEllipseItem(x, y, w, h, parent),
+ m_parent(parent)
+ {
+ setAcceptHoverEvents(true);
+ }
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event)
+ {
+ QGraphicsEllipseItem::mousePressEvent(event);
+ m_parent->markerSelected(this);
+ }
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+ {
+ QGraphicsEllipseItem::hoverEnterEvent(event);
+ m_parent->markerHovered(this, true);
+ }
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+ {
+ QGraphicsEllipseItem::hoverLeaveEvent(event);
+ m_parent->markerHovered(this, false);
+ }
+
+private:
+ ScatterChartItem *m_parent;
+};
+
+class RectangleMarker: public QGraphicsRectItem
+{
+
+public:
+ RectangleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
+ : QGraphicsRectItem(x, y, w, h, parent),
+ m_parent(parent)
+ {
+ setAcceptHoverEvents(true);
+ }
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event)
+ {
+ QGraphicsRectItem::mousePressEvent(event);
+ m_parent->markerSelected(this);
+ }
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+ {
+ QGraphicsRectItem::hoverEnterEvent(event);
+ m_parent->markerHovered(this, true);
+ }
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+ {
+ QGraphicsRectItem::hoverLeaveEvent(event);
+ m_parent->markerHovered(this, false);
+ }
+
+private:
+ ScatterChartItem *m_parent;
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // SCATTERPRESENTER_H