@@ -1,112 +1,111 | |||
|
1 | 1 | #include "scatterpresenter_p.h" |
|
2 | 2 | #include "qscatterseries.h" |
|
3 | 3 | #include <QPen> |
|
4 | 4 | #include <QPainter> |
|
5 | 5 | #include <QGraphicsScene> |
|
6 | 6 | #include <QDebug> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : |
|
11 | 11 | ChartItem(parent), |
|
12 | 12 | m_series(series), |
|
13 | 13 | m_boundingRect(), |
|
14 | 14 | //m_markerColor(QColor()), |
|
15 | 15 | // m_markerColor(QColor(255, 0, 0)), |
|
16 | 16 | m_visibleChartArea() |
|
17 | 17 | { |
|
18 | 18 | if (parent) |
|
19 | 19 | m_boundingRect = parent->boundingRect(); |
|
20 | 20 | |
|
21 | 21 | if (series) { |
|
22 | 22 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); |
|
23 | 23 | } |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | void ScatterPresenter::handleDomainChanged(const Domain& domain) |
|
27 | 27 | { |
|
28 | 28 | m_visibleChartArea = domain; |
|
29 | 29 | changeGeometry(); |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) |
|
33 | 33 | { |
|
34 | 34 | m_boundingRect = rect; |
|
35 | 35 | changeGeometry(); |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | void ScatterPresenter::handleModelChanged() |
|
39 | 39 | { |
|
40 | 40 | // TODO: more fine grained modelChanged signaling |
|
41 | 41 | changeGeometry(); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
45 | 45 | { |
|
46 | 46 | // TODO: Optimization: avoid setting on every paint method call? |
|
47 | 47 | // The custom settings in series override those defined by the theme |
|
48 | 48 | if (m_series->markerPen().color().isValid()) { |
|
49 | 49 | painter->setPen(m_series->markerPen()); |
|
50 | 50 | painter->setBrush(m_series->markerBrush()); |
|
51 | 51 | } else { |
|
52 | 52 | painter->setPen(m_markerPen); |
|
53 | 53 | painter->setBrush(m_markerBrush); |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | int shape = m_series->markerShape(); |
|
57 | 57 | |
|
58 | 58 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
59 | 59 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
60 | 60 | // Paint a shape |
|
61 | 61 | switch (shape) { |
|
62 | 62 | case QScatterSeries::MarkerShapeDefault: |
|
63 | 63 | // Fallthrough, defaults to circle |
|
64 | 64 | case QScatterSeries::MarkerShapeCircle: |
|
65 | 65 | painter->drawChord(m_scenex.at(i), m_sceney.at(i), 9, 9, 0, 5760); |
|
66 | 66 | break; |
|
67 | 67 | case QScatterSeries::MarkerShapePoint: |
|
68 | 68 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
69 | 69 | break; |
|
70 | 70 | case QScatterSeries::MarkerShapeRectangle: |
|
71 | 71 | painter->drawRect(m_scenex.at(i), m_sceney.at(i), 9, 9); |
|
72 | 72 | break; |
|
73 |
case QScatterSeries::MarkerShapeTiltedRectangle: |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 | } | |
|
73 | case QScatterSeries::MarkerShapeTiltedRectangle: | |
|
74 | // TODO: | |
|
75 | static const QPointF points[4] = { | |
|
76 | QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |
|
77 | QPointF(0.0 + m_scenex.at(i), 1.0 + m_sceney.at(i)), | |
|
78 | QPointF(1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |
|
79 | QPointF(0.0 + m_scenex.at(i), -1.0 + m_sceney.at(i)) | |
|
80 | }; | |
|
81 | painter->drawPolygon(points, 4); | |
|
83 | 82 | break; |
|
84 | 83 | default: |
|
85 | 84 | // TODO: implement the rest of the shapes |
|
86 | 85 | Q_ASSERT(false); |
|
87 | 86 | break; |
|
88 | 87 | } |
|
89 | 88 | } |
|
90 | 89 | } |
|
91 | 90 | |
|
92 | 91 | void ScatterPresenter::changeGeometry() |
|
93 | 92 | { |
|
94 | 93 | if (m_boundingRect.isValid()) { |
|
95 | 94 | |
|
96 | 95 | prepareGeometryChange(); |
|
97 | 96 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
98 | 97 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
99 | 98 | m_scenex.clear(); |
|
100 | 99 | m_sceney.clear(); |
|
101 | 100 | |
|
102 | 101 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
103 | 102 | foreach (QPointF point, m_series->data()) { |
|
104 | 103 | m_scenex.append(m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex); |
|
105 | 104 | m_sceney.append(m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley); |
|
106 | 105 | } |
|
107 | 106 | } |
|
108 | 107 | } |
|
109 | 108 | |
|
110 | 109 | #include "moc_scatterpresenter_p.cpp" |
|
111 | 110 | |
|
112 | 111 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now