##// END OF EJS Templates
Bugfixes for scatter series...
Michal Klocek -
r1763:b2458d94e609
parent child
Show More
@@ -82,7 +82,6 Window::Window(QWidget* parent) :
82 settingsLayout->addStretch();
82 settingsLayout->addStretch();
83 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
83 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
84 //create charts
84 //create charts
85
86 Charts::ChartList list = Charts::chartList();
85 Charts::ChartList list = Charts::chartList();
87
86
88 for(int i = 0 ; i < 9 && i<list.size() ; ++i)
87 for(int i = 0 ; i < 9 && i<list.size() ; ++i)
@@ -145,7 +144,6 void Window::createProxyWidgets()
145
144
146 QComboBox* Window::createThemeBox()
145 QComboBox* Window::createThemeBox()
147 {
146 {
148 // settings layoutQGLWidget’
149 QComboBox* themeComboBox = new ComboBox(this);
147 QComboBox* themeComboBox = new ComboBox(this);
150 themeComboBox->addItem("Light", QChart::ChartThemeLight);
148 themeComboBox->addItem("Light", QChart::ChartThemeLight);
151 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
149 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
@@ -159,7 +157,6 QComboBox* Window::createThemeBox()
159
157
160 QComboBox* Window::createAnimationBox()
158 QComboBox* Window::createAnimationBox()
161 {
159 {
162 // settings layout
163 QComboBox* animationComboBox = new ComboBox(this);
160 QComboBox* animationComboBox = new ComboBox(this);
164 animationComboBox->addItem("No Animations", QChart::NoAnimation);
161 animationComboBox->addItem("No Animations", QChart::NoAnimation);
165 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
162 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
@@ -47,12 +47,6 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *prese
47 handleUpdated();
47 handleUpdated();
48
48
49 m_items.setHandlesChildEvents(false);
49 m_items.setHandlesChildEvents(false);
50
51 // TODO: how to draw a drop shadow?
52 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
53 // dropShadow->setOffset(2.0);
54 // dropShadow->setBlurRadius(2.0);
55 // setGraphicsEffect(dropShadow);
56 }
50 }
57
51
58 QRectF ScatterChartItem::boundingRect() const
52 QRectF ScatterChartItem::boundingRect() const
@@ -68,16 +62,14 void ScatterChartItem::createPoints(int count)
68
62
69 switch (m_shape) {
63 switch (m_shape) {
70 case QScatterSeries::MarkerShapeCircle: {
64 case QScatterSeries::MarkerShapeCircle: {
71 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size,this);
65 item = new CircleMarker(0,0,m_size,m_size,this);
72 const QRectF& rect = i->boundingRect();
66 const QRectF& rect = item->boundingRect();
73 i->setPos(-rect.width()/2,-rect.height()/2);
67 item->setPos(-rect.width()/2,-rect.height()/2);
74 item = new Marker(i,this);
75 break;
68 break;
76 }
69 }
77 case QScatterSeries::MarkerShapeRectangle: {
70 case QScatterSeries::MarkerShapeRectangle: {
78 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size,this);
71 item = new RectangleMarker(0,0,m_size,m_size,this);
79 i->setPos(-m_size/2,-m_size/2);
72 item->setPos(-m_size/2,-m_size/2);
80 item = new Marker(i,this);
81 break;
73 break;
82 }
74 }
83 default:
75 default:
@@ -94,13 +86,15 void ScatterChartItem::deletePoints(int count)
94 QList<QGraphicsItem *> items = m_items.childItems();
86 QList<QGraphicsItem *> items = m_items.childItems();
95
87
96 for (int i = 0; i < count; ++i) {
88 for (int i = 0; i < count; ++i) {
97 delete(items.takeLast());
89 QGraphicsItem * item = items.takeLast();
90 m_markerMap.remove(item);
91 delete(item);
98 }
92 }
99 }
93 }
100
94
101 void ScatterChartItem::markerSelected(Marker *marker)
95 void ScatterChartItem::markerSelected(QGraphicsItem *marker)
102 {
96 {
103 emit XYChart::clicked(calculateDomainPoint(marker->point()));
97 emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker]));
104 }
98 }
105
99
106 void ScatterChartItem::updateGeometry()
100 void ScatterChartItem::updateGeometry()
@@ -128,10 +122,10 void ScatterChartItem::updateGeometry()
128 QList<QGraphicsItem*> items = m_items.childItems();
122 QList<QGraphicsItem*> items = m_items.childItems();
129
123
130 for (int i = 0; i < points.size(); i++) {
124 for (int i = 0; i < points.size(); i++) {
131 Marker* item = static_cast<Marker*>(items.at(i));
125 QGraphicsItem* item = items.at(i);
132 const QPointF& point = points.at(i);
126 const QPointF& point = points.at(i);
133 const QRectF& rect = item->boundingRect();
127 const QRectF& rect = item->boundingRect();
134 item->setPoint(point);
128 m_markerMap[item]=point;
135 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
129 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
136 if(!m_visible || !clipRect().contains(point)) {
130 if(!m_visible || !clipRect().contains(point)) {
137 item->setVisible(false);
131 item->setVisible(false);
@@ -156,14 +150,14 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
156 void ScatterChartItem::setPen(const QPen& pen)
150 void ScatterChartItem::setPen(const QPen& pen)
157 {
151 {
158 foreach(QGraphicsItem* item , m_items.childItems()) {
152 foreach(QGraphicsItem* item , m_items.childItems()) {
159 static_cast<Marker*>(item)->setPen(pen);
153 static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
160 }
154 }
161 }
155 }
162
156
163 void ScatterChartItem::setBrush(const QBrush& brush)
157 void ScatterChartItem::setBrush(const QBrush& brush)
164 {
158 {
165 foreach(QGraphicsItem* item , m_items.childItems()) {
159 foreach(QGraphicsItem* item , m_items.childItems()) {
166 static_cast<Marker*>(item)->setBrush(brush);
160 static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
167 }
161 }
168 }
162 }
169
163
@@ -195,12 +189,6 void ScatterChartItem::handleUpdated()
195 update();
189 update();
196 }
190 }
197
191
198 void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
199 {
200 emit XYChart::clicked(calculateDomainPoint(event->pos()));
201 QGraphicsItem::mousePressEvent(event);
202 }
203
204 #include "moc_scatterchartitem_p.cpp"
192 #include "moc_scatterchartitem_p.cpp"
205
193
206 QTCOMMERCIALCHART_END_NAMESPACE
194 QTCOMMERCIALCHART_END_NAMESPACE
@@ -38,7 +38,6
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QScatterSeries;
40 class QScatterSeries;
41 class Marker;
42
41
43 class ScatterChartItem : public XYChart, public QGraphicsItem
42 class ScatterChartItem : public XYChart, public QGraphicsItem
44 {
43 {
@@ -55,7 +54,7 public:
55 void setPen(const QPen &pen);
54 void setPen(const QPen &pen);
56 void setBrush(const QBrush &brush);
55 void setBrush(const QBrush &brush);
57
56
58 void markerSelected(Marker *item);
57 void markerSelected(QGraphicsItem *item);
59
58
60 public Q_SLOTS:
59 public Q_SLOTS:
61 void handleUpdated();
60 void handleUpdated();
@@ -66,7 +65,6 private:
66
65
67 protected:
66 protected:
68 void updateGeometry();
67 void updateGeometry();
69 void mousePressEvent(QGraphicsSceneMouseEvent *event);
70
68
71 private:
69 private:
72 QScatterSeries *m_series;
70 QScatterSeries *m_series;
@@ -75,76 +73,47 private:
75 int m_shape;
73 int m_shape;
76 int m_size;
74 int m_size;
77 QRectF m_rect;
75 QRectF m_rect;
76 QMap<QGraphicsItem *, QPointF> m_markerMap;
78 };
77 };
79
78
80
79 class CircleMarker: public QGraphicsEllipseItem
81 class Marker: public QAbstractGraphicsShapeItem
82 {
80 {
83
81
84 public:
82 public:
85
83 CircleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent) : QGraphicsEllipseItem(x,y,w,h,parent),
86 Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent)
84 m_parent(parent)
87 {
88 }
89
90 ~Marker()
91 {
92 delete m_item;
93 }
94
95 void setPoint(const QPointF& point)
96 {
97 m_point=point;
98 }
99
100 QPointF point() const
101 {
102 return m_point;
103 }
104
105 QPainterPath shape() const
106 {
107 return m_item->shape();
108 }
109
110 QRectF boundingRect() const
111 {
85 {
112 return m_item->boundingRect();
113 }
86 }
114
87
115 bool contains(const QPointF &point) const
88 protected:
89 void mousePressEvent(QGraphicsSceneMouseEvent *event)
116 {
90 {
117 return m_item->contains(point);
91 m_parent->markerSelected(this);
92 QGraphicsEllipseItem::mousePressEvent(event);
118 }
93 }
119
94
120 void setPen(const QPen &pen)
95 private:
121 {
96 ScatterChartItem* m_parent;
122 m_item->setPen(pen);
97 };
123 }
124
98
125 void setBrush(const QBrush &brush)
99 class RectangleMarker: public QGraphicsRectItem
126 {
100 {
127 m_item->setBrush(brush);
128 }
129
101
130 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
102 public:
103 RectangleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent) : QGraphicsRectItem(x,y,w,h,parent),
104 m_parent(parent)
131 {
105 {
132 m_item->paint(painter,option,widget);
133 }
106 }
134
107
135 protected:
108 protected:
136
137 void mousePressEvent(QGraphicsSceneMouseEvent *event)
109 void mousePressEvent(QGraphicsSceneMouseEvent *event)
138 {
110 {
139 Q_UNUSED(event)
140 m_parent->markerSelected(this);
111 m_parent->markerSelected(this);
141 QAbstractGraphicsShapeItem::mousePressEvent(event);
112 QGraphicsRectItem::mousePressEvent(event);
142 }
113 }
143
114
144 private:
115 private:
145 QAbstractGraphicsShapeItem* m_item;
146 ScatterChartItem* m_parent;
116 ScatterChartItem* m_parent;
147 QPointF m_point;
148 };
117 };
149
118
150 QTCOMMERCIALCHART_END_NAMESPACE
119 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now