##// END OF EJS Templates
Correct graphics flags for items
Michal Klocek -
r856:cabe72fb9d4b
parent child
Show More
@@ -1,211 +1,212
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 "piechartitem_p.h"
21 #include "piechartitem_p.h"
22 #include "piesliceitem_p.h"
22 #include "piesliceitem_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "chartpresenter_p.h"
25 #include "chartpresenter_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "chartanimator_p.h"
27 #include "chartanimator_p.h"
28 #include <QDebug>
28 #include <QDebug>
29 #include <QPainter>
29 #include <QPainter>
30 #include <QTimer>
30 #include <QTimer>
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
34 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
35 :ChartItem(presenter),
35 :ChartItem(presenter),
36 m_series(series)
36 m_series(series)
37 {
37 {
38 Q_ASSERT(series);
38 Q_ASSERT(series);
39 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
39 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
40 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
40 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
41 connect(series, SIGNAL(piePositionChanged()), this, SLOT(handlePieLayoutChanged()));
41 connect(series, SIGNAL(piePositionChanged()), this, SLOT(handlePieLayoutChanged()));
42 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(handlePieLayoutChanged()));
42 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(handlePieLayoutChanged()));
43
43
44 QTimer::singleShot(0, this, SLOT(initialize()));
44 QTimer::singleShot(0, this, SLOT(initialize()));
45
45
46 // Note: the following does not affect as long as the item does not have anything to paint
46 // Note: the following does not affect as long as the item does not have anything to paint
47 setZValue(ChartPresenter::PieSeriesZValue);
47 setZValue(ChartPresenter::PieSeriesZValue);
48 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
48 }
49 }
49
50
50 PieChartItem::~PieChartItem()
51 PieChartItem::~PieChartItem()
51 {
52 {
52 // slices deleted automatically through QGraphicsItem
53 // slices deleted automatically through QGraphicsItem
53 }
54 }
54
55
55 void PieChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
56 void PieChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
56 {
57 {
57 Q_UNUSED(painter)
58 Q_UNUSED(painter)
58 // TODO: paint shadows for all components
59 // TODO: paint shadows for all components
59 // - get paths from items & merge & offset and draw with shadow color?
60 // - get paths from items & merge & offset and draw with shadow color?
60 //painter->setBrush(QBrush(Qt::red));
61 //painter->setBrush(QBrush(Qt::red));
61 //painter->drawRect(m_debugRect);
62 //painter->drawRect(m_debugRect);
62 }
63 }
63
64
64 void PieChartItem::initialize()
65 void PieChartItem::initialize()
65 {
66 {
66 handleSlicesAdded(m_series->slices());
67 handleSlicesAdded(m_series->slices());
67 }
68 }
68
69
69 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
70 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
70 {
71 {
71 bool isEmpty = m_slices.isEmpty();
72 bool isEmpty = m_slices.isEmpty();
72
73
73 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
74 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
74
75
75 foreach (QPieSlice *s, slices) {
76 foreach (QPieSlice *s, slices) {
76 PieSliceItem* item = new PieSliceItem(this);
77 PieSliceItem* item = new PieSliceItem(this);
77 m_slices.insert(s, item);
78 m_slices.insert(s, item);
78 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
79 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
79 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked(Qt::MouseButtons)));
80 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked(Qt::MouseButtons)));
80 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
81 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
81 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
82 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
82
83
83 PieSliceData data = sliceData(s);
84 PieSliceData data = sliceData(s);
84
85
85 if (animator())
86 if (animator())
86 animator()->addAnimation(this, s, data, isEmpty);
87 animator()->addAnimation(this, s, data, isEmpty);
87 else
88 else
88 setLayout(s, data);
89 setLayout(s, data);
89 }
90 }
90 }
91 }
91
92
92 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
93 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
93 {
94 {
94 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
95 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
95
96
96 foreach (QPieSlice *s, slices) {
97 foreach (QPieSlice *s, slices) {
97 if (animator())
98 if (animator())
98 animator()->removeAnimation(this, s);
99 animator()->removeAnimation(this, s);
99 else
100 else
100 destroySlice(s);
101 destroySlice(s);
101 }
102 }
102 }
103 }
103
104
104 void PieChartItem::handlePieLayoutChanged()
105 void PieChartItem::handlePieLayoutChanged()
105 {
106 {
106 PieLayout layout = calculateLayout();
107 PieLayout layout = calculateLayout();
107 applyLayout(layout);
108 applyLayout(layout);
108 update();
109 update();
109 }
110 }
110
111
111 void PieChartItem::handleSliceChanged()
112 void PieChartItem::handleSliceChanged()
112 {
113 {
113 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
114 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
114 Q_ASSERT(m_slices.contains(slice));
115 Q_ASSERT(m_slices.contains(slice));
115 PieSliceData data = sliceData(slice);
116 PieSliceData data = sliceData(slice);
116 updateLayout(slice, data);
117 updateLayout(slice, data);
117 update();
118 update();
118 }
119 }
119
120
120 void PieChartItem::handleDomainChanged(qreal, qreal, qreal, qreal)
121 void PieChartItem::handleDomainChanged(qreal, qreal, qreal, qreal)
121 {
122 {
122 // TODO
123 // TODO
123 }
124 }
124
125
125 void PieChartItem::handleGeometryChanged(const QRectF& rect)
126 void PieChartItem::handleGeometryChanged(const QRectF& rect)
126 {
127 {
127 prepareGeometryChange();
128 prepareGeometryChange();
128 m_rect = rect;
129 m_rect = rect;
129 handlePieLayoutChanged();
130 handlePieLayoutChanged();
130 }
131 }
131
132
132 void PieChartItem::calculatePieLayout()
133 void PieChartItem::calculatePieLayout()
133 {
134 {
134 // find pie center coordinates
135 // find pie center coordinates
135 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition()));
136 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition()));
136 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition()));
137 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition()));
137
138
138 // find maximum radius for pie
139 // find maximum radius for pie
139 m_pieRadius = m_rect.height() / 2;
140 m_pieRadius = m_rect.height() / 2;
140 if (m_rect.width() < m_rect.height())
141 if (m_rect.width() < m_rect.height())
141 m_pieRadius = m_rect.width() / 2;
142 m_pieRadius = m_rect.width() / 2;
142
143
143 // apply size factor
144 // apply size factor
144 m_pieRadius *= m_series->pieSize();
145 m_pieRadius *= m_series->pieSize();
145 }
146 }
146
147
147 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
148 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
148 {
149 {
149 // TODO: This function is kid of useless now. Refactor.
150 // TODO: This function is kid of useless now. Refactor.
150 PieSliceData sliceData = PieSliceData::data(slice);
151 PieSliceData sliceData = PieSliceData::data(slice);
151 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
152 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
152 sliceData.m_radius = m_pieRadius;
153 sliceData.m_radius = m_pieRadius;
153 return sliceData;
154 return sliceData;
154 }
155 }
155
156
156 PieLayout PieChartItem::calculateLayout()
157 PieLayout PieChartItem::calculateLayout()
157 {
158 {
158 calculatePieLayout();
159 calculatePieLayout();
159 PieLayout layout;
160 PieLayout layout;
160 foreach (QPieSlice* s, m_series->slices()) {
161 foreach (QPieSlice* s, m_series->slices()) {
161 if (m_slices.contains(s)) // calculate layout only for those slices that are already visible
162 if (m_slices.contains(s)) // calculate layout only for those slices that are already visible
162 layout.insert(s, sliceData(s));
163 layout.insert(s, sliceData(s));
163 }
164 }
164 return layout;
165 return layout;
165 }
166 }
166
167
167 void PieChartItem::applyLayout(const PieLayout &layout)
168 void PieChartItem::applyLayout(const PieLayout &layout)
168 {
169 {
169 if (animator())
170 if (animator())
170 animator()->updateLayout(this, layout);
171 animator()->updateLayout(this, layout);
171 else
172 else
172 setLayout(layout);
173 setLayout(layout);
173 }
174 }
174
175
175 void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData)
176 void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData)
176 {
177 {
177 if (animator())
178 if (animator())
178 animator()->updateLayout(this, slice, sliceData);
179 animator()->updateLayout(this, slice, sliceData);
179 else
180 else
180 setLayout(slice, sliceData);
181 setLayout(slice, sliceData);
181 }
182 }
182
183
183 void PieChartItem::setLayout(const PieLayout &layout)
184 void PieChartItem::setLayout(const PieLayout &layout)
184 {
185 {
185 foreach (QPieSlice *slice, layout.keys()) {
186 foreach (QPieSlice *slice, layout.keys()) {
186 PieSliceItem *item = m_slices.value(slice);
187 PieSliceItem *item = m_slices.value(slice);
187 Q_ASSERT(item);
188 Q_ASSERT(item);
188 item->setSliceData(layout.value(slice));
189 item->setSliceData(layout.value(slice));
189 item->updateGeometry();
190 item->updateGeometry();
190 item->update();
191 item->update();
191 }
192 }
192 }
193 }
193
194
194 void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData)
195 void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData)
195 {
196 {
196 // find slice
197 // find slice
197 PieSliceItem *item = m_slices.value(slice);
198 PieSliceItem *item = m_slices.value(slice);
198 Q_ASSERT(item);
199 Q_ASSERT(item);
199 item->setSliceData(sliceData);
200 item->setSliceData(sliceData);
200 item->updateGeometry();
201 item->updateGeometry();
201 item->update();
202 item->update();
202 }
203 }
203
204
204 void PieChartItem::destroySlice(QPieSlice *slice)
205 void PieChartItem::destroySlice(QPieSlice *slice)
205 {
206 {
206 delete m_slices.take(slice);
207 delete m_slices.take(slice);
207 }
208 }
208
209
209 #include "moc_piechartitem_p.cpp"
210 #include "moc_piechartitem_p.cpp"
210
211
211 QTCOMMERCIALCHART_END_NAMESPACE
212 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,190 +1,189
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 "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include <QPainter>
24 #include <QPainter>
25 #include <QGraphicsScene>
25 #include <QGraphicsScene>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
29 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
30 XYChartItem(series,presenter),
30 XYChartItem(series,presenter),
31 m_series(series),
31 m_series(series),
32 m_items(this),
32 m_items(this),
33 m_shape(QScatterSeries::MarkerShapeRectangle),
33 m_shape(QScatterSeries::MarkerShapeRectangle),
34 m_size(15)
34 m_size(15)
35
35
36 {
36 {
37 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
37 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
38
38
39 setZValue(ChartPresenter::ScatterSeriesZValue);
39 setZValue(ChartPresenter::ScatterSeriesZValue);
40 setFlags(QGraphicsItem::ItemHasNoContents);
41 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
40 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
42
41
43 handleUpdated();
42 handleUpdated();
44
43
45 m_items.setHandlesChildEvents(false);
44 m_items.setHandlesChildEvents(false);
46
45
47 // TODO: how to draw a drop shadow?
46 // TODO: how to draw a drop shadow?
48 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
47 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
49 // dropShadow->setOffset(2.0);
48 // dropShadow->setOffset(2.0);
50 // dropShadow->setBlurRadius(2.0);
49 // dropShadow->setBlurRadius(2.0);
51 // setGraphicsEffect(dropShadow);
50 // setGraphicsEffect(dropShadow);
52 }
51 }
53
52
54
53
55 QRectF ScatterChartItem::boundingRect() const
54 QRectF ScatterChartItem::boundingRect() const
56 {
55 {
57 return m_rect;
56 return m_rect;
58 }
57 }
59
58
60 void ScatterChartItem::createPoints(int count)
59 void ScatterChartItem::createPoints(int count)
61 {
60 {
62 for (int i = 0; i < count; ++i) {
61 for (int i = 0; i < count; ++i) {
63
62
64 QGraphicsItem *item = 0;
63 QGraphicsItem *item = 0;
65
64
66 switch (m_shape) {
65 switch (m_shape) {
67 case QScatterSeries::MarkerShapeCircle:{
66 case QScatterSeries::MarkerShapeCircle:{
68 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
67 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
69 const QRectF& rect = i->boundingRect();
68 const QRectF& rect = i->boundingRect();
70 i->setPos(-rect.width()/2,-rect.height()/2);
69 i->setPos(-rect.width()/2,-rect.height()/2);
71 item = new Marker(i,this);
70 item = new Marker(i,this);
72 break;
71 break;
73 }
72 }
74 case QScatterSeries::MarkerShapeRectangle:{
73 case QScatterSeries::MarkerShapeRectangle:{
75 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
74 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
76 i->setPos(-m_size/2,-m_size/2);
75 i->setPos(-m_size/2,-m_size/2);
77 item = new Marker(i,this);
76 item = new Marker(i,this);
78 break;
77 break;
79 }
78 }
80 default:
79 default:
81 qWarning()<<"Unsupported marker type";
80 qWarning()<<"Unsupported marker type";
82 break;
81 break;
83
82
84 }
83 }
85 m_items.addToGroup(item);
84 m_items.addToGroup(item);
86 }
85 }
87 }
86 }
88
87
89 void ScatterChartItem::deletePoints(int count)
88 void ScatterChartItem::deletePoints(int count)
90 {
89 {
91 QList<QGraphicsItem *> items = m_items.childItems();
90 QList<QGraphicsItem *> items = m_items.childItems();
92
91
93 for (int i = 0; i < count; ++i) {
92 for (int i = 0; i < count; ++i) {
94 delete(items.takeLast());
93 delete(items.takeLast());
95 }
94 }
96 }
95 }
97
96
98 void ScatterChartItem::markerSelected(Marker *marker)
97 void ScatterChartItem::markerSelected(Marker *marker)
99 {
98 {
100 emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index())));
99 emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index())));
101 }
100 }
102
101
103 void ScatterChartItem::setLayout(QVector<QPointF>& points)
102 void ScatterChartItem::setLayout(QVector<QPointF>& points)
104 {
103 {
105 if(points.size()==0)
104 if(points.size()==0)
106 {
105 {
107 XYChartItem::setLayout(points);
106 XYChartItem::setLayout(points);
108 return;
107 return;
109 }
108 }
110
109
111 int diff = XYChartItem::points().size() - points.size();
110 int diff = XYChartItem::points().size() - points.size();
112
111
113 if(diff>0) {
112 if(diff>0) {
114 deletePoints(diff);
113 deletePoints(diff);
115 }
114 }
116 else if(diff<0) {
115 else if(diff<0) {
117 createPoints(-diff);
116 createPoints(-diff);
118 }
117 }
119
118
120 if(diff!=0) handleUpdated();
119 if(diff!=0) handleUpdated();
121
120
122 QList<QGraphicsItem*> items = m_items.childItems();
121 QList<QGraphicsItem*> items = m_items.childItems();
123
122
124 for (int i = 0; i < points.size(); i++) {
123 for (int i = 0; i < points.size(); i++) {
125 Marker* item = static_cast<Marker*>(items.at(i));
124 Marker* item = static_cast<Marker*>(items.at(i));
126 const QPointF& point = points.at(i);
125 const QPointF& point = points.at(i);
127 const QRectF& rect = item->boundingRect();
126 const QRectF& rect = item->boundingRect();
128 item->setIndex(i);
127 item->setIndex(i);
129 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
128 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
130 if(!clipRect().contains(point)) {
129 if(!clipRect().contains(point)) {
131 item->setVisible(false);
130 item->setVisible(false);
132 }
131 }
133 else {
132 else {
134 item->setVisible(true);
133 item->setVisible(true);
135 }
134 }
136 }
135 }
137
136
138 prepareGeometryChange();
137 prepareGeometryChange();
139 m_rect = clipRect();
138 m_rect = clipRect();
140 XYChartItem::setLayout(points);
139 XYChartItem::setLayout(points);
141 }
140 }
142
141
143
142
144 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
143 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
145 {
144 {
146 Q_UNUSED(painter)
145 Q_UNUSED(painter)
147 Q_UNUSED(option)
146 Q_UNUSED(option)
148 Q_UNUSED(widget)
147 Q_UNUSED(widget)
149 }
148 }
150
149
151 void ScatterChartItem::setPen(const QPen& pen)
150 void ScatterChartItem::setPen(const QPen& pen)
152 {
151 {
153 foreach(QGraphicsItem* item , m_items.childItems()) {
152 foreach(QGraphicsItem* item , m_items.childItems()) {
154 static_cast<Marker*>(item)->setPen(pen);
153 static_cast<Marker*>(item)->setPen(pen);
155 }
154 }
156 }
155 }
157
156
158 void ScatterChartItem::setBrush(const QBrush& brush)
157 void ScatterChartItem::setBrush(const QBrush& brush)
159 {
158 {
160 foreach(QGraphicsItem* item , m_items.childItems()) {
159 foreach(QGraphicsItem* item , m_items.childItems()) {
161 static_cast<Marker*>(item)->setBrush(brush);
160 static_cast<Marker*>(item)->setBrush(brush);
162 }
161 }
163 }
162 }
164
163
165 void ScatterChartItem::handleUpdated()
164 void ScatterChartItem::handleUpdated()
166 {
165 {
167
166
168 int count = m_items.childItems().count();
167 int count = m_items.childItems().count();
169
168
170 if(count==0) return;
169 if(count==0) return;
171
170
172 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
171 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
173
172
174 //TODO: only rewrite on size change
173 //TODO: only rewrite on size change
175
174
176 m_size = m_series->size();
175 m_size = m_series->size();
177 m_shape = m_series->shape();
176 m_shape = m_series->shape();
178
177
179 if(recreate){
178 if(recreate){
180 deletePoints(count);
179 deletePoints(count);
181 createPoints(count);
180 createPoints(count);
182 }
181 }
183
182
184 setPen(m_series->pen());
183 setPen(m_series->pen());
185 setBrush(m_series->brush());
184 setBrush(m_series->brush());
186 }
185 }
187
186
188 #include "moc_scatterchartitem_p.cpp"
187 #include "moc_scatterchartitem_p.cpp"
189
188
190 QTCOMMERCIALCHART_END_NAMESPACE
189 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now