@@ -1,168 +1,178 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qscatterseries.h" |
|
21 | #include "qscatterseries.h" | |
22 | #include "qscatterseries_p.h" |
|
22 | #include "qscatterseries_p.h" | |
23 | #include "scatterchartitem_p.h" |
|
23 | #include "scatterchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QScatterSeries |
|
29 | \class QScatterSeries | |
30 | \brief The QScatterSeries class is used for making scatter charts. |
|
30 | \brief The QScatterSeries class is used for making scatter charts. | |
31 |
|
31 | |||
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis |
|
34 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis | |
35 | and the vertical axis. |
|
35 | and the vertical axis. | |
36 |
|
36 | |||
37 | \image examples_scatterchart.png |
|
37 | \image examples_scatterchart.png | |
38 |
|
38 | |||
39 | Creating basic scatter chart is simple: |
|
39 | Creating basic scatter chart is simple: | |
40 | \code |
|
40 | \code | |
41 | QScatterSeries* series = new QScatterSeries(); |
|
41 | QScatterSeries* series = new QScatterSeries(); | |
42 | series->append(0, 6); |
|
42 | series->append(0, 6); | |
43 | series->append(2, 4); |
|
43 | series->append(2, 4); | |
44 | ... |
|
44 | ... | |
45 | chart->addSeries(series); |
|
45 | chart->addSeries(series); | |
46 | \endcode |
|
46 | \endcode | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \enum QScatterSeries::MarkerShape |
|
50 | \enum QScatterSeries::MarkerShape | |
51 |
|
51 | |||
52 | This enum describes the shape used when rendering marker items. |
|
52 | This enum describes the shape used when rendering marker items. | |
53 |
|
53 | |||
54 | \value MarkerShapeCircle |
|
54 | \value MarkerShapeCircle | |
55 | \value MarkerShapeRectangle |
|
55 | \value MarkerShapeRectangle | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QScatterSeries::markerShape |
|
59 | \property QScatterSeries::markerShape | |
60 |
|
60 | |||
61 | Defines the shape of the marker used to draw the points in the series. |
|
61 | Defines the shape of the marker used to draw the points in the series. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
|
65 | \fn void QScatterSeries::markerShapeChanged() | |||
|
66 | Emitted when marker shape is changed | |||
|
67 | */ | |||
|
68 | ||||
|
69 | /*! | |||
|
70 | \fn void QScatterSeries::markerSizeChanged() | |||
|
71 | Emitted when marker size is changed | |||
|
72 | */ | |||
|
73 | ||||
|
74 | /*! | |||
65 | \property QScatterSeries::markerSize |
|
75 | \property QScatterSeries::markerSize | |
66 |
|
76 | |||
67 | Defines the size of the marker used to draw the points in the series. |
|
77 | Defines the size of the marker used to draw the points in the series. | |
68 | */ |
|
78 | */ | |
69 |
|
79 | |||
70 | /*! |
|
80 | /*! | |
71 | \fn QChartSeriesType QScatterSeries::type() const |
|
81 | \fn QChartSeriesType QScatterSeries::type() const | |
72 | \brief Returns QChartSeries::SeriesTypeScatter. |
|
82 | \brief Returns QChartSeries::SeriesTypeScatter. | |
73 | \sa QAbstractSeries, SeriesType |
|
83 | \sa QAbstractSeries, SeriesType | |
74 | */ |
|
84 | */ | |
75 |
|
85 | |||
76 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
86 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
77 |
|
87 | |||
78 | /*! |
|
88 | /*! | |
79 | Constructs a series object which is a child of \a parent. |
|
89 | Constructs a series object which is a child of \a parent. | |
80 | */ |
|
90 | */ | |
81 | QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent) |
|
91 | QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent) | |
82 | { |
|
92 | { | |
83 | } |
|
93 | } | |
84 |
|
94 | |||
85 | /*! |
|
95 | /*! | |
86 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
96 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
87 | */ |
|
97 | */ | |
88 | QScatterSeries::~QScatterSeries() |
|
98 | QScatterSeries::~QScatterSeries() | |
89 | { |
|
99 | { | |
90 | Q_D(QScatterSeries); |
|
100 | Q_D(QScatterSeries); | |
91 | if(d->m_dataset) { |
|
101 | if(d->m_dataset) { | |
92 | d->m_dataset->removeSeries(this); |
|
102 | d->m_dataset->removeSeries(this); | |
93 | } |
|
103 | } | |
94 | } |
|
104 | } | |
95 |
|
105 | |||
96 | QAbstractSeries::SeriesType QScatterSeries::type() const |
|
106 | QAbstractSeries::SeriesType QScatterSeries::type() const | |
97 | { |
|
107 | { | |
98 | return QAbstractSeries::SeriesTypeScatter; |
|
108 | return QAbstractSeries::SeriesTypeScatter; | |
99 | } |
|
109 | } | |
100 |
|
110 | |||
101 | /*! |
|
111 | /*! | |
102 | Returns the shape used for drawing markers. |
|
112 | Returns the shape used for drawing markers. | |
103 | */ |
|
113 | */ | |
104 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const |
|
114 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const | |
105 | { |
|
115 | { | |
106 | Q_D(const QScatterSeries); |
|
116 | Q_D(const QScatterSeries); | |
107 | return d->m_shape; |
|
117 | return d->m_shape; | |
108 | } |
|
118 | } | |
109 |
|
119 | |||
110 | /*! |
|
120 | /*! | |
111 | Overrides the default shape of the marker items with a user defined \a shape. The default shape |
|
121 | Overrides the default shape of the marker items with a user defined \a shape. The default shape | |
112 | is defined by chart theme setting. |
|
122 | is defined by chart theme setting. | |
113 | */ |
|
123 | */ | |
114 | void QScatterSeries::setMarkerShape(MarkerShape shape) |
|
124 | void QScatterSeries::setMarkerShape(MarkerShape shape) | |
115 | { |
|
125 | { | |
116 | Q_D(QScatterSeries); |
|
126 | Q_D(QScatterSeries); | |
117 | if (d->m_shape != shape) { |
|
127 | if (d->m_shape != shape) { | |
118 | d->m_shape = shape; |
|
128 | d->m_shape = shape; | |
119 |
emit |
|
129 | emit markerShapeChanged(); | |
120 | } |
|
130 | } | |
121 | } |
|
131 | } | |
122 |
|
132 | |||
123 | /*! |
|
133 | /*! | |
124 | Returns the size of the marker items. |
|
134 | Returns the size of the marker items. | |
125 | */ |
|
135 | */ | |
126 | qreal QScatterSeries::markerSize() const |
|
136 | qreal QScatterSeries::markerSize() const | |
127 | { |
|
137 | { | |
128 | Q_D(const QScatterSeries); |
|
138 | Q_D(const QScatterSeries); | |
129 | return d->m_size; |
|
139 | return d->m_size; | |
130 | } |
|
140 | } | |
131 |
|
141 | |||
132 | /*! |
|
142 | /*! | |
133 | Set the \a size of the marker items. The default size is 15. |
|
143 | Set the \a size of the marker items. The default size is 15. | |
134 | */ |
|
144 | */ | |
135 | void QScatterSeries::setMarkerSize(qreal size) |
|
145 | void QScatterSeries::setMarkerSize(qreal size) | |
136 | { |
|
146 | { | |
137 | Q_D(QScatterSeries); |
|
147 | Q_D(QScatterSeries); | |
138 |
|
148 | |||
139 | if (!qFuzzyIsNull(d->m_size - size)) { |
|
149 | if (!qFuzzyIsNull(d->m_size - size)) { | |
140 | d->m_size = size; |
|
150 | d->m_size = size; | |
141 |
emit |
|
151 | emit markerSizeChanged(); | |
142 | } |
|
152 | } | |
143 | } |
|
153 | } | |
144 |
|
154 | |||
145 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
146 |
|
156 | |||
147 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q), |
|
157 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q), | |
148 | m_shape(QScatterSeries::MarkerShapeCircle), |
|
158 | m_shape(QScatterSeries::MarkerShapeCircle), | |
149 | m_size(15.0) |
|
159 | m_size(15.0) | |
150 | { |
|
160 | { | |
151 |
|
161 | |||
152 | }; |
|
162 | }; | |
153 |
|
163 | |||
154 | Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
164 | Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
155 | { |
|
165 | { | |
156 | Q_Q(QScatterSeries); |
|
166 | Q_Q(QScatterSeries); | |
157 | ScatterChartItem *scatter = new ScatterChartItem(q,presenter); |
|
167 | ScatterChartItem *scatter = new ScatterChartItem(q,presenter); | |
158 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
168 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
159 | scatter->setAnimator(presenter->animator()); |
|
169 | scatter->setAnimator(presenter->animator()); | |
160 | scatter->setAnimation(new XYAnimation(scatter)); |
|
170 | scatter->setAnimation(new XYAnimation(scatter)); | |
161 | } |
|
171 | } | |
162 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
172 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
163 | return scatter; |
|
173 | return scatter; | |
164 | } |
|
174 | } | |
165 |
|
175 | |||
166 | #include "moc_qscatterseries.cpp" |
|
176 | #include "moc_qscatterseries.cpp" | |
167 |
|
177 | |||
168 | QTCOMMERCIALCHART_END_NAMESPACE |
|
178 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,62 +1,66 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QSCATTERSERIES_H |
|
21 | #ifndef QSCATTERSERIES_H | |
22 | #define QSCATTERSERIES_H |
|
22 | #define QSCATTERSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qxyseries.h> |
|
25 | #include <qxyseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QScatterSeriesPrivate; |
|
29 | class QScatterSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape) |
|
34 | Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape NOTIFY markerShapeChanged) | |
35 | Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize) |
|
35 | Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize NOTIFY markerSizeChanged) | |
36 | Q_ENUMS(MarkerShape) |
|
36 | Q_ENUMS(MarkerShape) | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | enum MarkerShape { |
|
39 | enum MarkerShape { | |
40 | MarkerShapeCircle, |
|
40 | MarkerShapeCircle, | |
41 | MarkerShapeRectangle |
|
41 | MarkerShapeRectangle | |
42 | }; |
|
42 | }; | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | explicit QScatterSeries(QObject *parent = 0); |
|
45 | explicit QScatterSeries(QObject *parent = 0); | |
46 | ~QScatterSeries(); |
|
46 | ~QScatterSeries(); | |
47 | QAbstractSeries::SeriesType type() const; |
|
47 | QAbstractSeries::SeriesType type() const; | |
48 | MarkerShape markerShape() const; |
|
48 | MarkerShape markerShape() const; | |
49 | void setMarkerShape(MarkerShape shape); |
|
49 | void setMarkerShape(MarkerShape shape); | |
50 | qreal markerSize() const; |
|
50 | qreal markerSize() const; | |
51 | void setMarkerSize(qreal size); |
|
51 | void setMarkerSize(qreal size); | |
52 |
|
52 | |||
|
53 | Q_SIGNALS: | |||
|
54 | void markerShapeChanged(); | |||
|
55 | void markerSizeChanged(); | |||
|
56 | ||||
53 | private: |
|
57 | private: | |
54 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
58 | Q_DECLARE_PRIVATE(QScatterSeries) | |
55 | Q_DISABLE_COPY(QScatterSeries) |
|
59 | Q_DISABLE_COPY(QScatterSeries) | |
56 | friend class ScatterChartItem; |
|
60 | friend class ScatterChartItem; | |
57 |
|
61 | |||
58 | }; |
|
62 | }; | |
59 |
|
63 | |||
60 | QTCOMMERCIALCHART_END_NAMESPACE |
|
64 | QTCOMMERCIALCHART_END_NAMESPACE | |
61 |
|
65 | |||
62 | #endif // QSCATTERSERIES_H |
|
66 | #endif // QSCATTERSERIES_H |
@@ -1,205 +1,207 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "scatterchartitem_p.h" |
|
21 | #include "scatterchartitem_p.h" | |
22 | #include "qscatterseries.h" |
|
22 | #include "qscatterseries.h" | |
23 | #include "qscatterseries_p.h" |
|
23 | #include "qscatterseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsScene> |
|
26 | #include <QGraphicsScene> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : |
|
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : | |
33 | XYChart(series,presenter), |
|
33 | XYChart(series,presenter), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_items(this), |
|
36 | m_items(this), | |
37 | m_visible(true), |
|
37 | m_visible(true), | |
38 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
38 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
39 | m_size(15) |
|
39 | m_size(15) | |
40 | { |
|
40 | { | |
41 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
41 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); | |
42 |
QObject::connect(series, SIGNAL( |
|
42 | QObject::connect(m_series, SIGNAL(markerShapeChanged()), this, SLOT(handleUpdated())); | |
|
43 | QObject::connect(m_series, SIGNAL(markerSizeChanged()), this, SLOT(handleUpdated())); | |||
|
44 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |||
43 |
|
45 | |||
44 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
46 | setZValue(ChartPresenter::ScatterSeriesZValue); | |
45 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
47 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
46 |
|
48 | |||
47 | handleUpdated(); |
|
49 | handleUpdated(); | |
48 |
|
50 | |||
49 | m_items.setHandlesChildEvents(false); |
|
51 | m_items.setHandlesChildEvents(false); | |
50 |
|
52 | |||
51 | // TODO: how to draw a drop shadow? |
|
53 | // TODO: how to draw a drop shadow? | |
52 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); |
|
54 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); | |
53 | // dropShadow->setOffset(2.0); |
|
55 | // dropShadow->setOffset(2.0); | |
54 | // dropShadow->setBlurRadius(2.0); |
|
56 | // dropShadow->setBlurRadius(2.0); | |
55 | // setGraphicsEffect(dropShadow); |
|
57 | // setGraphicsEffect(dropShadow); | |
56 | } |
|
58 | } | |
57 |
|
59 | |||
58 | QRectF ScatterChartItem::boundingRect() const |
|
60 | QRectF ScatterChartItem::boundingRect() const | |
59 | { |
|
61 | { | |
60 | return m_rect; |
|
62 | return m_rect; | |
61 | } |
|
63 | } | |
62 |
|
64 | |||
63 | void ScatterChartItem::createPoints(int count) |
|
65 | void ScatterChartItem::createPoints(int count) | |
64 | { |
|
66 | { | |
65 | for (int i = 0; i < count; ++i) { |
|
67 | for (int i = 0; i < count; ++i) { | |
66 |
|
68 | |||
67 | QGraphicsItem *item = 0; |
|
69 | QGraphicsItem *item = 0; | |
68 |
|
70 | |||
69 | switch (m_shape) { |
|
71 | switch (m_shape) { | |
70 | case QScatterSeries::MarkerShapeCircle: { |
|
72 | case QScatterSeries::MarkerShapeCircle: { | |
71 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); |
|
73 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); | |
72 | const QRectF& rect = i->boundingRect(); |
|
74 | const QRectF& rect = i->boundingRect(); | |
73 | i->setPos(-rect.width()/2,-rect.height()/2); |
|
75 | i->setPos(-rect.width()/2,-rect.height()/2); | |
74 | item = new Marker(i,this); |
|
76 | item = new Marker(i,this); | |
75 | break; |
|
77 | break; | |
76 | } |
|
78 | } | |
77 | case QScatterSeries::MarkerShapeRectangle: { |
|
79 | case QScatterSeries::MarkerShapeRectangle: { | |
78 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); |
|
80 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); | |
79 | i->setPos(-m_size/2,-m_size/2); |
|
81 | i->setPos(-m_size/2,-m_size/2); | |
80 | item = new Marker(i,this); |
|
82 | item = new Marker(i,this); | |
81 | break; |
|
83 | break; | |
82 | } |
|
84 | } | |
83 | default: |
|
85 | default: | |
84 | qWarning()<<"Unsupported marker type"; |
|
86 | qWarning()<<"Unsupported marker type"; | |
85 | break; |
|
87 | break; | |
86 |
|
88 | |||
87 | } |
|
89 | } | |
88 | m_items.addToGroup(item); |
|
90 | m_items.addToGroup(item); | |
89 | } |
|
91 | } | |
90 | } |
|
92 | } | |
91 |
|
93 | |||
92 | void ScatterChartItem::deletePoints(int count) |
|
94 | void ScatterChartItem::deletePoints(int count) | |
93 | { |
|
95 | { | |
94 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
96 | QList<QGraphicsItem *> items = m_items.childItems(); | |
95 |
|
97 | |||
96 | for (int i = 0; i < count; ++i) { |
|
98 | for (int i = 0; i < count; ++i) { | |
97 | delete(items.takeLast()); |
|
99 | delete(items.takeLast()); | |
98 | } |
|
100 | } | |
99 | } |
|
101 | } | |
100 |
|
102 | |||
101 | void ScatterChartItem::markerSelected(Marker *marker) |
|
103 | void ScatterChartItem::markerSelected(Marker *marker) | |
102 | { |
|
104 | { | |
103 | emit XYChart::clicked(marker->point()); |
|
105 | emit XYChart::clicked(marker->point()); | |
104 | } |
|
106 | } | |
105 |
|
107 | |||
106 | void ScatterChartItem::updateGeometry() |
|
108 | void ScatterChartItem::updateGeometry() | |
107 | { |
|
109 | { | |
108 |
|
110 | |||
109 | const QVector<QPointF>& points = geometryPoints(); |
|
111 | const QVector<QPointF>& points = geometryPoints(); | |
110 |
|
112 | |||
111 | if(points.size()==0) |
|
113 | if(points.size()==0) | |
112 | { |
|
114 | { | |
113 | deletePoints(m_items.childItems().count()); |
|
115 | deletePoints(m_items.childItems().count()); | |
114 | return; |
|
116 | return; | |
115 | } |
|
117 | } | |
116 |
|
118 | |||
117 | int diff = m_items.childItems().size() - points.size(); |
|
119 | int diff = m_items.childItems().size() - points.size(); | |
118 |
|
120 | |||
119 | if(diff>0) { |
|
121 | if(diff>0) { | |
120 | deletePoints(diff); |
|
122 | deletePoints(diff); | |
121 | } |
|
123 | } | |
122 | else if(diff<0) { |
|
124 | else if(diff<0) { | |
123 | createPoints(-diff); |
|
125 | createPoints(-diff); | |
124 | } |
|
126 | } | |
125 |
|
127 | |||
126 | if(diff!=0) handleUpdated(); |
|
128 | if(diff!=0) handleUpdated(); | |
127 |
|
129 | |||
128 | QList<QGraphicsItem*> items = m_items.childItems(); |
|
130 | QList<QGraphicsItem*> items = m_items.childItems(); | |
129 |
|
131 | |||
130 | for (int i = 0; i < points.size(); i++) { |
|
132 | for (int i = 0; i < points.size(); i++) { | |
131 | Marker* item = static_cast<Marker*>(items.at(i)); |
|
133 | Marker* item = static_cast<Marker*>(items.at(i)); | |
132 | const QPointF& point = points.at(i); |
|
134 | const QPointF& point = points.at(i); | |
133 | const QRectF& rect = item->boundingRect(); |
|
135 | const QRectF& rect = item->boundingRect(); | |
134 | item->setPoint(point); |
|
136 | item->setPoint(point); | |
135 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); |
|
137 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); | |
136 | if(!m_visible || !clipRect().contains(point)) { |
|
138 | if(!m_visible || !clipRect().contains(point)) { | |
137 | item->setVisible(false); |
|
139 | item->setVisible(false); | |
138 | } |
|
140 | } | |
139 | else { |
|
141 | else { | |
140 | item->setVisible(true); |
|
142 | item->setVisible(true); | |
141 | } |
|
143 | } | |
142 | } |
|
144 | } | |
143 |
|
145 | |||
144 | prepareGeometryChange(); |
|
146 | prepareGeometryChange(); | |
145 | m_rect = clipRect(); |
|
147 | m_rect = clipRect(); | |
146 | setPos(origin()); |
|
148 | setPos(origin()); | |
147 | } |
|
149 | } | |
148 |
|
150 | |||
149 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
151 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
150 | { |
|
152 | { | |
151 | Q_UNUSED(painter) |
|
153 | Q_UNUSED(painter) | |
152 | Q_UNUSED(option) |
|
154 | Q_UNUSED(option) | |
153 | Q_UNUSED(widget) |
|
155 | Q_UNUSED(widget) | |
154 | } |
|
156 | } | |
155 |
|
157 | |||
156 | void ScatterChartItem::setPen(const QPen& pen) |
|
158 | void ScatterChartItem::setPen(const QPen& pen) | |
157 | { |
|
159 | { | |
158 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
160 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
159 | static_cast<Marker*>(item)->setPen(pen); |
|
161 | static_cast<Marker*>(item)->setPen(pen); | |
160 | } |
|
162 | } | |
161 | } |
|
163 | } | |
162 |
|
164 | |||
163 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
165 | void ScatterChartItem::setBrush(const QBrush& brush) | |
164 | { |
|
166 | { | |
165 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
167 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
166 | static_cast<Marker*>(item)->setBrush(brush); |
|
168 | static_cast<Marker*>(item)->setBrush(brush); | |
167 | } |
|
169 | } | |
168 | } |
|
170 | } | |
169 |
|
171 | |||
170 | void ScatterChartItem::handleUpdated() |
|
172 | void ScatterChartItem::handleUpdated() | |
171 | { |
|
173 | { | |
172 | int count = m_items.childItems().count(); |
|
174 | int count = m_items.childItems().count(); | |
173 |
|
175 | |||
174 | if(count==0) return; |
|
176 | if(count==0) return; | |
175 |
|
177 | |||
176 | bool recreate = m_visible != m_series->isVisible() |
|
178 | bool recreate = m_visible != m_series->isVisible() | |
177 | || m_size != m_series->markerSize() |
|
179 | || m_size != m_series->markerSize() | |
178 | || m_shape != m_series->markerShape(); |
|
180 | || m_shape != m_series->markerShape(); | |
179 |
|
181 | |||
180 | m_visible = m_series->isVisible(); |
|
182 | m_visible = m_series->isVisible(); | |
181 | m_size = m_series->markerSize(); |
|
183 | m_size = m_series->markerSize(); | |
182 | m_shape = m_series->markerShape(); |
|
184 | m_shape = m_series->markerShape(); | |
183 |
|
185 | |||
184 | if(recreate) { |
|
186 | if(recreate) { | |
185 | // TODO: optimize handleUpdate to recreate points only in case shape changed |
|
187 | // TODO: optimize handleUpdate to recreate points only in case shape changed | |
186 | deletePoints(count); |
|
188 | deletePoints(count); | |
187 | createPoints(count); |
|
189 | createPoints(count); | |
188 |
|
190 | |||
189 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points |
|
191 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points | |
190 | updateGeometry(); |
|
192 | updateGeometry(); | |
191 | } |
|
193 | } | |
192 |
|
194 | |||
193 | setPen(m_series->pen()); |
|
195 | setPen(m_series->pen()); | |
194 | setBrush(m_series->brush()); |
|
196 | setBrush(m_series->brush()); | |
195 | update(); |
|
197 | update(); | |
196 | } |
|
198 | } | |
197 |
|
199 | |||
198 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
200 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
199 | { |
|
201 | { | |
200 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
202 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
201 | } |
|
203 | } | |
202 |
|
204 | |||
203 | #include "moc_scatterchartitem_p.cpp" |
|
205 | #include "moc_scatterchartitem_p.cpp" | |
204 |
|
206 | |||
205 | QTCOMMERCIALCHART_END_NAMESPACE |
|
207 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now