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