##// 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 21 Q_OBJECT
22 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 32 ChartPresenter(QChart* chart,ChartDataSet *dataset);
26 33 virtual ~ChartPresenter();
@@ -49,13 +49,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
49 49
50 50 QScatterSeriesPrivate::QScatterSeriesPrivate() :
51 51 m_data(QList<QPointF>()),
52 m_markerPen(QPen()),
53 m_markerBrush(QBrush()),
52 m_markerPen(QPen(QColor::Invalid)),
53 m_markerBrush(QBrush(QColor::Invalid)),
54 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 1 #include "scatterpresenter_p.h"
2 2 #include "qscatterseries.h"
3 #include "chartpresenter_p.h"
3 4 #include <QPen>
4 5 #include <QPainter>
5 6 #include <QGraphicsScene>
@@ -23,10 +24,13 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
23 24 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
24 25 }
25 26
26 QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
27 dropShadow->setOffset(2.0);
28 dropShadow->setBlurRadius(2.0);
29 setGraphicsEffect(dropShadow);
27 setZValue(ChartPresenter::ScatterSeriesZValue);
28
29 // TODO: how to draw a drop shadow?
30 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
31 // dropShadow->setOffset(2.0);
32 // dropShadow->setBlurRadius(2.0);
33 // setGraphicsEffect(dropShadow);
30 34 }
31 35
32 36 void ScatterPresenter::handleDomainChanged(const Domain& domain)
@@ -52,17 +56,34 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *
52 56 painter->save();
53 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 69 // Paint the shape
56 70 // The custom settings in series override those defined by the theme
57 71 QPen pen = m_markerPen;
58 72 if (m_series->pen().color().isValid())
59 73 pen = m_series->pen();
74 painter->setPen(pen);
60 75 if (m_series->brush().color().isValid())
61 76 painter->setBrush(m_series->brush());
62 77 else
63 78 painter->setBrush(m_markerBrush);
64 painter->setPen(pen);
65 painter->drawPath(m_path);
79
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 88 painter->restore();
68 89 }
@@ -85,6 +106,7 void ScatterPresenter::changeGeometry()
85 106
86 107 int shape = m_series->shape();
87 108 m_path = QPainterPath();
109 m_path.setFillRule(Qt::WindingFill);
88 110
89 111 foreach (QPointF point, m_series->data()) {
90 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