##// END OF EJS Templates
Fixed drawing issues in Scatter
Tero Ahola -
r375:cfa1350263ea
parent child
Show More
@@ -20,7 +20,14 class ChartPresenter: public QObject
20 {
20 {
21 Q_OBJECT
21 Q_OBJECT
22 public:
22 public:
23 enum ZValues { BackgroundZValue = -1 , ShadesZValue, GridZValue, AxisZValue , LineChartZValue };
23 enum ZValues {
24 BackgroundZValue = -1,
25 ShadesZValue,
26 GridZValue,
27 AxisZValue,
28 LineChartZValue,
29 ScatterSeriesZValue
30 };
24
31
25 ChartPresenter(QChart* chart,ChartDataSet *dataset);
32 ChartPresenter(QChart* chart,ChartDataSet *dataset);
26 virtual ~ChartPresenter();
33 virtual ~ChartPresenter();
@@ -49,13 +49,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
49
49
50 QScatterSeriesPrivate::QScatterSeriesPrivate() :
50 QScatterSeriesPrivate::QScatterSeriesPrivate() :
51 m_data(QList<QPointF>()),
51 m_data(QList<QPointF>()),
52 m_markerPen(QPen()),
52 m_markerPen(QPen(QColor::Invalid)),
53 m_markerBrush(QBrush()),
53 m_markerBrush(QBrush(QColor::Invalid)),
54 m_markerShape(QScatterSeries::MarkerShapeDefault)
54 m_markerShape(QScatterSeries::MarkerShapeDefault)
55 {
55 {
56 // Initialize pen color to invalid to use a theme color by default
57 m_markerPen.setColor(QColor::Invalid);
58 m_markerBrush.setColor(QColor::Invalid);
59 }
56 }
60
57
61 /*!
58 /*!
@@ -1,5 +1,6
1 #include "scatterpresenter_p.h"
1 #include "scatterpresenter_p.h"
2 #include "qscatterseries.h"
2 #include "qscatterseries.h"
3 #include "chartpresenter_p.h"
3 #include <QPen>
4 #include <QPen>
4 #include <QPainter>
5 #include <QPainter>
5 #include <QGraphicsScene>
6 #include <QGraphicsScene>
@@ -23,10 +24,13 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
23 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
24 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
24 }
25 }
25
26
26 QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
27 setZValue(ChartPresenter::ScatterSeriesZValue);
27 dropShadow->setOffset(2.0);
28
28 dropShadow->setBlurRadius(2.0);
29 // TODO: how to draw a drop shadow?
29 setGraphicsEffect(dropShadow);
30 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
31 // dropShadow->setOffset(2.0);
32 // dropShadow->setBlurRadius(2.0);
33 // setGraphicsEffect(dropShadow);
30 }
34 }
31
35
32 void ScatterPresenter::handleDomainChanged(const Domain& domain)
36 void ScatterPresenter::handleDomainChanged(const Domain& domain)
@@ -52,17 +56,34 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *
52 painter->save();
56 painter->save();
53 painter->setClipRect(m_boundingRect);
57 painter->setClipRect(m_boundingRect);
54
58
59 // TODO: how to draw a drop shadow?
60 // Now using a custom implementation for drop shadow instead of QGraphicsDropShadowEffect.
61 // It seems QGraphicsDropShadowEffect is quite heavy, at least on windows without open gl.
62 QPen dropShadowPen(QColor(0, 0, 0, 70));
63 dropShadowPen.setWidth(3);
64 painter->setPen(dropShadowPen);
65 painter->setBrush(dropShadowPen.color());
66 // painter->setRenderHint(QPainter::Antialiasing);
67 painter->drawPath(m_path.translated(2, 2));
68
55 // Paint the shape
69 // Paint the shape
56 // The custom settings in series override those defined by the theme
70 // The custom settings in series override those defined by the theme
57 QPen pen = m_markerPen;
71 QPen pen = m_markerPen;
58 if (m_series->pen().color().isValid())
72 if (m_series->pen().color().isValid())
59 pen = m_series->pen();
73 pen = m_series->pen();
74 painter->setPen(pen);
60 if (m_series->brush().color().isValid())
75 if (m_series->brush().color().isValid())
61 painter->setBrush(m_series->brush());
76 painter->setBrush(m_series->brush());
62 else
77 else
63 painter->setBrush(m_markerBrush);
78 painter->setBrush(m_markerBrush);
64 painter->setPen(pen);
79
65 painter->drawPath(m_path);
80 // If either pen or brush is opaque, we need to draw the polygons one-by-one
81 if (painter->pen().color().alpha() < 255 || painter->brush().color().alpha() < 255) {
82 foreach (QPolygonF pol, m_path.toSubpathPolygons())
83 painter->drawPolygon(pol);
84 } else {
85 painter->drawPath(m_path);
86 }
66
87
67 painter->restore();
88 painter->restore();
68 }
89 }
@@ -85,6 +106,7 void ScatterPresenter::changeGeometry()
85
106
86 int shape = m_series->shape();
107 int shape = m_series->shape();
87 m_path = QPainterPath();
108 m_path = QPainterPath();
109 m_path.setFillRule(Qt::WindingFill);
88
110
89 foreach (QPointF point, m_series->data()) {
111 foreach (QPointF point, m_series->data()) {
90 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
112 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
General Comments 0
You need to be logged in to leave comments. Login now