##// END OF EJS Templates
Fix crash with ScatterChartItem mouse events...
Titta Heikkala -
r2684:0a14af81c23e
parent child
Show More
@@ -1,146 +1,146
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the Qt Enterprise Chart API. It exists purely as an
24 // This file is not part of the Qt Enterprise Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef SCATTERCHARTITEM_H
30 #ifndef SCATTERCHARTITEM_H
31 #define SCATTERCHARTITEM_H
31 #define SCATTERCHARTITEM_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "xychart_p.h"
34 #include "xychart_p.h"
35 #include <QGraphicsEllipseItem>
35 #include <QGraphicsEllipseItem>
36 #include <QPen>
36 #include <QPen>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QScatterSeries;
40 class QScatterSeries;
41
41
42 class ScatterChartItem : public XYChart
42 class ScatterChartItem : public XYChart
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 Q_INTERFACES(QGraphicsItem)
45 Q_INTERFACES(QGraphicsItem)
46 public:
46 public:
47 explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem *item = 0);
47 explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem *item = 0);
48
48
49 public:
49 public:
50 //from QGraphicsItem
50 //from QGraphicsItem
51 QRectF boundingRect() const;
51 QRectF boundingRect() const;
52 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
52 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
53
53
54 void setPen(const QPen &pen);
54 void setPen(const QPen &pen);
55 void setBrush(const QBrush &brush);
55 void setBrush(const QBrush &brush);
56
56
57 void markerSelected(QGraphicsItem *item);
57 void markerSelected(QGraphicsItem *item);
58 void markerHovered(QGraphicsItem *item, bool state);
58 void markerHovered(QGraphicsItem *item, bool state);
59
59
60 public Q_SLOTS:
60 public Q_SLOTS:
61 void handleUpdated();
61 void handleUpdated();
62
62
63 private:
63 private:
64 void createPoints(int count);
64 void createPoints(int count);
65 void deletePoints(int count);
65 void deletePoints(int count);
66
66
67 protected:
67 protected:
68 void updateGeometry();
68 void updateGeometry();
69
69
70 private:
70 private:
71 QScatterSeries *m_series;
71 QScatterSeries *m_series;
72 QGraphicsItemGroup m_items;
72 QGraphicsItemGroup m_items;
73 bool m_visible;
73 bool m_visible;
74 int m_shape;
74 int m_shape;
75 int m_size;
75 int m_size;
76 QRectF m_rect;
76 QRectF m_rect;
77 QMap<QGraphicsItem *, QPointF> m_markerMap;
77 QMap<QGraphicsItem *, QPointF> m_markerMap;
78 };
78 };
79
79
80 class CircleMarker: public QGraphicsEllipseItem
80 class CircleMarker: public QGraphicsEllipseItem
81 {
81 {
82
82
83 public:
83 public:
84 CircleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
84 CircleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
85 : QGraphicsEllipseItem(x, y, w, h, parent),
85 : QGraphicsEllipseItem(x, y, w, h, parent),
86 m_parent(parent)
86 m_parent(parent)
87 {
87 {
88 setAcceptHoverEvents(true);
88 setAcceptHoverEvents(true);
89 }
89 }
90
90
91 protected:
91 protected:
92 void mousePressEvent(QGraphicsSceneMouseEvent *event)
92 void mousePressEvent(QGraphicsSceneMouseEvent *event)
93 {
93 {
94 m_parent->markerSelected(this);
95 QGraphicsEllipseItem::mousePressEvent(event);
94 QGraphicsEllipseItem::mousePressEvent(event);
95 m_parent->markerSelected(this);
96 }
96 }
97 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
97 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
98 {
98 {
99 m_parent->markerHovered(this, true);
100 QGraphicsEllipseItem::hoverEnterEvent(event);
99 QGraphicsEllipseItem::hoverEnterEvent(event);
100 m_parent->markerHovered(this, true);
101 }
101 }
102 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
102 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
103 {
103 {
104 m_parent->markerHovered(this, false);
105 QGraphicsEllipseItem::hoverLeaveEvent(event);
104 QGraphicsEllipseItem::hoverLeaveEvent(event);
105 m_parent->markerHovered(this, false);
106 }
106 }
107
107
108 private:
108 private:
109 ScatterChartItem *m_parent;
109 ScatterChartItem *m_parent;
110 };
110 };
111
111
112 class RectangleMarker: public QGraphicsRectItem
112 class RectangleMarker: public QGraphicsRectItem
113 {
113 {
114
114
115 public:
115 public:
116 RectangleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
116 RectangleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
117 : QGraphicsRectItem(x, y, w, h, parent),
117 : QGraphicsRectItem(x, y, w, h, parent),
118 m_parent(parent)
118 m_parent(parent)
119 {
119 {
120 setAcceptHoverEvents(true);
120 setAcceptHoverEvents(true);
121 }
121 }
122
122
123 protected:
123 protected:
124 void mousePressEvent(QGraphicsSceneMouseEvent *event)
124 void mousePressEvent(QGraphicsSceneMouseEvent *event)
125 {
125 {
126 m_parent->markerSelected(this);
127 QGraphicsRectItem::mousePressEvent(event);
126 QGraphicsRectItem::mousePressEvent(event);
127 m_parent->markerSelected(this);
128 }
128 }
129 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
129 void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
130 {
130 {
131 m_parent->markerHovered(this, true);
132 QGraphicsRectItem::hoverEnterEvent(event);
131 QGraphicsRectItem::hoverEnterEvent(event);
132 m_parent->markerHovered(this, true);
133 }
133 }
134 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
134 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
135 {
135 {
136 m_parent->markerHovered(this, false);
137 QGraphicsRectItem::hoverLeaveEvent(event);
136 QGraphicsRectItem::hoverLeaveEvent(event);
137 m_parent->markerHovered(this, false);
138 }
138 }
139
139
140 private:
140 private:
141 ScatterChartItem *m_parent;
141 ScatterChartItem *m_parent;
142 };
142 };
143
143
144 QTCOMMERCIALCHART_END_NAMESPACE
144 QTCOMMERCIALCHART_END_NAMESPACE
145
145
146 #endif // SCATTERPRESENTER_H
146 #endif // SCATTERPRESENTER_H
General Comments 0
You need to be logged in to leave comments. Login now