##// END OF EJS Templates
Fixed scatter after the latest refactorings
Tero Ahola -
r447:44996c7702b8
parent child
Show More
@@ -213,12 +213,20 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const
213 case QSeries::SeriesTypeScatter: {
213 case QSeries::SeriesTypeScatter: {
214 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
214 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
215 Q_ASSERT(scatterSeries);
215 Q_ASSERT(scatterSeries);
216 qreal minX(domain->minX());
217 qreal minY(domain->minY());
218 qreal maxX(domain->maxX());
219 qreal maxY(domain->maxY());
216 foreach (QPointF point, scatterSeries->data()) {
220 foreach (QPointF point, scatterSeries->data()) {
217 domain->setMinX(qMin(domain->minX(), point.x()));
221 minX = qMin(minX, point.x());
218 domain->setMinY(qMax(domain->maxX(), point.x()));
222 minY = qMin(minY, point.y());
219 domain->setMaxX(qMin(domain->minY(), point.y()));
223 maxX = qMax(maxX, point.x());
220 domain->setMaxY(qMax(domain->maxY(), point.y()));
224 maxY = qMax(maxY, point.y());
221 }
225 }
226 domain->setMinX(minX);
227 domain->setMinY(minY);
228 domain->setMaxX(maxX);
229 domain->setMaxY(maxY);
222 break;
230 break;
223 }
231 }
224
232
@@ -219,9 +219,13 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
219 scatterSeries, SIGNAL(clicked(QPointF)));
219 scatterSeries, SIGNAL(clicked(QPointF)));
220 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
220 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
221 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
221 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
222 QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),
223 scatterPresenter, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
222 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
224 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
223 m_chartItems.insert(scatterSeries, scatterPresenter);
225 m_chartItems.insert(scatterSeries, scatterPresenter);
224 if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect);
226 if (m_rect.isValid())
227 scatterPresenter->handleGeometryChanged(m_rect);
228 scatterPresenter->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY());
225 break;
229 break;
226 }
230 }
227 case QSeries::SeriesTypePie: {
231 case QSeries::SeriesTypePie: {
@@ -18,10 +18,10 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
18 m_minY(0),
18 m_minY(0),
19 m_maxY(0),
19 m_maxY(0),
20 m_series(series),
20 m_series(series),
21 m_boundingRect()
21 m_clippingRect()
22 {
22 {
23 if (parent)
23 if (parent)
24 m_boundingRect = parent->boundingRect();
24 m_clippingRect = parent->boundingRect();
25
25
26 if (series) {
26 if (series) {
27 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
27 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
@@ -38,16 +38,16 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
38
38
39 void ScatterPresenter::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
39 void ScatterPresenter::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
40 {
40 {
41 m_minX=minX;
41 m_minX = minX;
42 m_maxX=maxX;
42 m_maxX = maxX;
43 m_minY=minY;
43 m_minY = minY;
44 m_maxY=maxY;
44 m_maxY = maxY;
45 changeGeometry();
45 changeGeometry();
46 }
46 }
47
47
48 void ScatterPresenter::handleGeometryChanged(const QRectF& rect)
48 void ScatterPresenter::handleGeometryChanged(const QRectF& rect)
49 {
49 {
50 m_boundingRect = rect.translated(-rect.topLeft());
50 m_clippingRect = rect.translated(-rect.topLeft());
51 changeGeometry();
51 changeGeometry();
52 setPos(rect.topLeft());
52 setPos(rect.topLeft());
53 }
53 }
@@ -61,7 +61,7 void ScatterPresenter::handleModelChanged()
61 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
61 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
62 {
62 {
63 painter->save();
63 painter->save();
64 painter->setClipRect(m_boundingRect);
64 painter->setClipRect(m_clippingRect);
65
65
66 // TODO: how to draw a drop shadow?
66 // TODO: how to draw a drop shadow?
67 // Now using a custom implementation for drop shadow instead of QGraphicsDropShadowEffect.
67 // Now using a custom implementation for drop shadow instead of QGraphicsDropShadowEffect.
@@ -104,17 +104,17 void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event)
104 void ScatterPresenter::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
104 void ScatterPresenter::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
105 {
105 {
106 QPointF clickedPoint(
106 QPointF clickedPoint(
107 m_minX + (event->lastPos().x() / m_boundingRect.width()) * (m_maxX-m_minX),
107 m_minX + (event->lastPos().x() / m_clippingRect.width()) * (m_maxX-m_minX),
108 m_maxY - (event->lastPos().y() / m_boundingRect.height()) * (m_maxY-m_minY));
108 m_maxY - (event->lastPos().y() / m_clippingRect.height()) * (m_maxY-m_minY));
109 emit clicked(clickedPoint);
109 emit clicked(clickedPoint);
110 }
110 }
111
111
112 void ScatterPresenter::changeGeometry()
112 void ScatterPresenter::changeGeometry()
113 {
113 {
114 if (m_boundingRect.isValid()) {
114 if (m_clippingRect.isValid()) {
115 prepareGeometryChange();
115 prepareGeometryChange();
116 qreal scalex = m_boundingRect.width() / (m_maxX-m_minX);
116 qreal scalex = m_clippingRect.width() / (m_maxX - m_minX);
117 qreal scaley = m_boundingRect.height() / (m_maxY-m_minY);
117 qreal scaley = m_clippingRect.height() / (m_maxY - m_minY);
118
118
119 int shape = m_series->shape();
119 int shape = m_series->shape();
120 m_path = QPainterPath();
120 m_path = QPainterPath();
@@ -124,7 +124,7 void ScatterPresenter::changeGeometry()
124 foreach (QPointF point, m_series->data()) {
124 foreach (QPointF point, m_series->data()) {
125 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
125 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
126 qreal x = point.x() * scalex - m_minX * scalex - size / 2;
126 qreal x = point.x() * scalex - m_minX * scalex - size / 2;
127 qreal y = m_boundingRect.height() - point.y() * scaley + m_minY * scaley - size / 2;
127 qreal y = m_clippingRect.height() - point.y() * scaley + m_minY * scaley - size / 2;
128
128
129 if (x < scene()->width() && y < scene()->height()) {
129 if (x < scene()->width() && y < scene()->height()) {
130 switch (shape) {
130 switch (shape) {
@@ -39,7 +39,7 public:
39 qreal m_minY;
39 qreal m_minY;
40 qreal m_maxY;
40 qreal m_maxY;
41 QScatterSeries *m_series;
41 QScatterSeries *m_series;
42 QRectF m_boundingRect;
42 QRectF m_clippingRect;
43 QPen m_markerPen;
43 QPen m_markerPen;
44 QBrush m_markerBrush;
44 QBrush m_markerBrush;
45 QPainterPath m_path;
45 QPainterPath m_path;
General Comments 0
You need to be logged in to leave comments. Login now