##// END OF EJS Templates
Refactor xychartitem -> xychart
Michal Klocek -
r1218:b8de085c4198
parent child
Show More
@@ -22,7 +22,7
22 22 #include "axisanimation_p.h"
23 23 #include "xyanimation_p.h"
24 24 #include "splineanimation_p.h"
25 #include "xychartitem_p.h"
25 #include "xychart_p.h"
26 26 #include "pieanimation_p.h"
27 27 #include "baranimation_p.h"
28 28 #include "barchartitem_p.h"
@@ -19,14 +19,14
19 19 ****************************************************************************/
20 20
21 21 #include "xyanimation_p.h"
22 #include "xychartitem_p.h"
22 #include "xychart_p.h"
23 23 #include <QDebug>
24 24
25 25 Q_DECLARE_METATYPE(QVector<QPointF>)
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 XYAnimation::XYAnimation(XYChartItem *item):ChartAnimation(item),
29 XYAnimation::XYAnimation(XYChart *item):ChartAnimation(item),
30 30 m_item(item),
31 31 m_dirty(false),
32 32 m_type(MoveDownAnimation)
@@ -26,13 +26,13
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 class XYChartItem;
29 class XYChart;
30 30
31 31 class XYAnimation : public ChartAnimation
32 32 {
33 33 public:
34 34 enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation };
35 XYAnimation(XYChartItem *item);
35 XYAnimation(XYChart *item);
36 36 ~XYAnimation();
37 37 void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index);
38 38 void setAnimationType(Animation type);
@@ -43,7 +43,7 protected:
43 43 void updateCurrentValue (const QVariant &value );
44 44
45 45 private:
46 XYChartItem *m_item;
46 XYChart *m_item;
47 47 QVector<QPointF> m_oldPoints;
48 48 bool m_dirty;
49 49 Animation m_type;
@@ -23,13 +23,15
23 23 #include "qlineseries_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include <QPainter>
26 #include <QGraphicsSceneMouseEvent>
26 27
27 28
28 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 30
30 31 //TODO: optimize : remove points which are not visible
31 32
32 LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChartItem(series,presenter),
33 LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChart(series,presenter),
34 QGraphicsItem(presenter ? presenter->rootItem() : 0),
33 35 m_series(series),
34 36 m_pointsVisible(false)
35 37 {
@@ -67,6 +69,7 void LineChartItem::updateGeometry()
67 69 prepareGeometryChange();
68 70 m_path = linePath;
69 71 m_rect = linePath.boundingRect();
72 setPos(origin());
70 73 }
71 74
72 75 void LineChartItem::handleUpdated()
@@ -96,6 +99,11 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
96 99 painter->restore();
97 100 }
98 101
102 void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
103 {
104 emit XYChart::clicked(calculateDomainPoint(event->pos()));
105 }
106
99 107 #include "moc_linechartitem_p.cpp"
100 108
101 109 QTCOMMERCIALCHART_END_NAMESPACE
@@ -22,7 +22,7
22 22 #define LINECHARTITEM_H
23 23
24 24 #include "qchartglobal.h"
25 #include "xychartitem_p.h"
25 #include "xychart_p.h"
26 26 #include <QPen>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -30,9 +30,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 class QLineSeries;
31 31 class ChartPresenter;
32 32
33 class LineChartItem : public XYChartItem
33 class LineChartItem : public XYChart , public QGraphicsItem
34 34 {
35 35 Q_OBJECT
36 Q_INTERFACES(QGraphicsItem)
36 37 public:
37 38 explicit LineChartItem(QLineSeries *series,ChartPresenter *presenter);
38 39 ~LineChartItem() {};
@@ -46,6 +47,7 public Q_SLOTS:
46 47 void handleUpdated();
47 48 protected:
48 49 void updateGeometry();
50 void mousePressEvent(QGraphicsSceneMouseEvent *event);
49 51
50 52 private:
51 53 QLineSeries* m_series;
@@ -1,22 +1,22
1 1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20 20
21 21 #include "scatterchartitem_p.h"
22 22 #include "qscatterseries.h"
@@ -25,16 +25,17
25 25 #include <QPainter>
26 26 #include <QGraphicsScene>
27 27 #include <QDebug>
28 #include <QGraphicsSceneMouseEvent>
28 29
29 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 31
31 32 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
32 XYChartItem(series,presenter),
33 m_series(series),
34 m_items(this),
35 m_shape(QScatterSeries::MarkerShapeRectangle),
36 m_size(15)
37
33 XYChart(series,presenter),
34 QGraphicsItem(presenter ? presenter->rootItem() : 0),
35 m_series(series),
36 m_items(this),
37 m_shape(QScatterSeries::MarkerShapeRectangle),
38 m_size(15)
38 39 {
39 40 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated()));
40 41
@@ -52,7 +53,6 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *prese
52 53 // setGraphicsEffect(dropShadow);
53 54 }
54 55
55
56 56 QRectF ScatterChartItem::boundingRect() const
57 57 {
58 58 return m_rect;
@@ -65,22 +65,22 void ScatterChartItem::createPoints(int count)
65 65 QGraphicsItem *item = 0;
66 66
67 67 switch (m_shape) {
68 case QScatterSeries::MarkerShapeCircle:{
69 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
70 const QRectF& rect = i->boundingRect();
71 i->setPos(-rect.width()/2,-rect.height()/2);
72 item = new Marker(i,this);
73 break;
74 }
75 case QScatterSeries::MarkerShapeRectangle:{
76 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
77 i->setPos(-m_size/2,-m_size/2);
78 item = new Marker(i,this);
79 break;
80 }
81 default:
82 qWarning()<<"Unsupported marker type";
83 break;
68 case QScatterSeries::MarkerShapeCircle: {
69 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
70 const QRectF& rect = i->boundingRect();
71 i->setPos(-rect.width()/2,-rect.height()/2);
72 item = new Marker(i,this);
73 break;
74 }
75 case QScatterSeries::MarkerShapeRectangle: {
76 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
77 i->setPos(-m_size/2,-m_size/2);
78 item = new Marker(i,this);
79 break;
80 }
81 default:
82 qWarning()<<"Unsupported marker type";
83 break;
84 84
85 85 }
86 86 m_items.addToGroup(item);
@@ -98,7 +98,7 void ScatterChartItem::deletePoints(int count)
98 98
99 99 void ScatterChartItem::markerSelected(Marker *marker)
100 100 {
101 emit XYChartItem::clicked(marker->point());
101 emit XYChart::clicked(marker->point());
102 102 }
103 103
104 104 void ScatterChartItem::updateGeometry()
@@ -141,9 +141,9 void ScatterChartItem::updateGeometry()
141 141
142 142 prepareGeometryChange();
143 143 m_rect = clipRect();
144 setPos(origin());
144 145 }
145 146
146
147 147 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
148 148 {
149 149 Q_UNUSED(painter)
@@ -154,15 +154,15 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
154 154 void ScatterChartItem::setPen(const QPen& pen)
155 155 {
156 156 foreach(QGraphicsItem* item , m_items.childItems()) {
157 static_cast<Marker*>(item)->setPen(pen);
157 static_cast<Marker*>(item)->setPen(pen);
158 158 }
159 159 }
160 160
161 161 void ScatterChartItem::setBrush(const QBrush& brush)
162 162 {
163 163 foreach(QGraphicsItem* item , m_items.childItems()) {
164 static_cast<Marker*>(item)->setBrush(brush);
165 }
164 static_cast<Marker*>(item)->setBrush(brush);
165 }
166 166 }
167 167
168 168 void ScatterChartItem::handleUpdated()
@@ -179,7 +179,7 void ScatterChartItem::handleUpdated()
179 179 m_size = m_series->size();
180 180 m_shape = m_series->shape();
181 181
182 if(recreate){
182 if(recreate) {
183 183 deletePoints(count);
184 184 createPoints(count);
185 185 }
@@ -188,6 +188,11 void ScatterChartItem::handleUpdated()
188 188 setBrush(m_series->brush());
189 189 }
190 190
191 void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
192 {
193 emit XYChart::clicked(calculateDomainPoint(event->pos()));
194 }
195
191 196 #include "moc_scatterchartitem_p.cpp"
192 197
193 198 QTCOMMERCIALCHART_END_NAMESPACE
@@ -22,7 +22,7
22 22 #define SCATTERCHARTITEM_H
23 23
24 24 #include "qchartglobal.h"
25 #include "xychartitem_p.h"
25 #include "xychart_p.h"
26 26 #include <QGraphicsEllipseItem>
27 27 #include <QPen>
28 28
@@ -31,7 +31,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31 class QScatterSeries;
32 32 class Marker;
33 33
34 class ScatterChartItem : public XYChartItem
34 class ScatterChartItem : public XYChart, public QGraphicsItem
35 35 {
36 36 Q_OBJECT
37 37 public:
@@ -56,6 +56,7 private:
56 56
57 57 protected:
58 58 void updateGeometry();
59 void mousePressEvent(QGraphicsSceneMouseEvent *event);
59 60
60 61 private:
61 62 QScatterSeries *m_series;
@@ -1,37 +1,38
1 1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20 20
21 21 #include "splinechartitem_p.h"
22 22 #include "qsplineseries_p.h"
23 23 #include "chartpresenter_p.h"
24 24 #include "chartanimator_p.h"
25 25 #include <QPainter>
26 #include <QDebug>
26 #include <QGraphicsSceneMouseEvent>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) :
31 XYChartItem(series, presenter),
32 m_series(series),
33 m_pointsVisible(false),
34 m_animation(0)
31 XYChart(series, presenter),
32 QGraphicsItem(presenter ? presenter->rootItem() : 0),
33 m_series(series),
34 m_pointsVisible(false),
35 m_animation(0)
35 36 {
36 37 setZValue(ChartPresenter::LineChartZValue);
37 38 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
@@ -51,7 +52,7 QPainterPath SplineChartItem::shape() const
51 52 void SplineChartItem::setAnimation(SplineAnimation* animation)
52 53 {
53 54 m_animation=animation;
54 XYChartItem::setAnimation(animation);
55 XYChart::setAnimation(animation);
55 56 }
56 57
57 58 void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points)
@@ -97,7 +98,7 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF>
97 98
98 99 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
99 100 {
100 return XYChartItem::calculateGeometryPoint(m_series->d_func()->controlPoint(index));
101 return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index));
101 102 }
102 103
103 104 void SplineChartItem::updateGeometry()
@@ -122,6 +123,7 void SplineChartItem::updateGeometry()
122 123 prepareGeometryChange();
123 124 m_path = splinePath;
124 125 m_rect = splinePath.boundingRect();
126 setPos(origin());
125 127 }
126 128
127 129 //handlers
@@ -152,7 +154,10 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
152 154 painter->restore();
153 155 }
154 156
155
157 void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
158 {
159 emit XYChart::clicked(calculateDomainPoint(event->pos()));
160 }
156 161
157 162 #include "moc_splinechartitem_p.cpp"
158 163
@@ -22,14 +22,15
22 22 #define SPLINECHARTITEM_P_H
23 23
24 24 #include "qsplineseries.h"
25 #include "xychartitem_p.h"
25 #include "xychart_p.h"
26 26 #include "splineanimation_p.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 class SplineChartItem : public XYChartItem
30 class SplineChartItem : public XYChart, public QGraphicsItem
31 31 {
32 32 Q_OBJECT
33 Q_INTERFACES(QGraphicsItem)
33 34 public:
34 35 SplineChartItem(QSplineSeries *series, ChartPresenter *presenter);
35 36
@@ -50,6 +51,7 public Q_SLOTS:
50 51 protected:
51 52 void updateGeometry();
52 53 void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index);
54 void mousePressEvent(QGraphicsSceneMouseEvent *event);
53 55
54 56 private:
55 57 QPointF calculateGeometryControlPoint(int index) const;
@@ -78,7 +78,7 private:
78 78 Q_DECLARE_PRIVATE(QXYSeries);
79 79 Q_DISABLE_COPY(QXYSeries);
80 80 friend class XYLegendMarker;
81 friend class XYChartItem;
81 friend class XYChart;
82 82 };
83 83
84 84 QTCOMMERCIALCHART_END_NAMESPACE
@@ -18,22 +18,20
18 18 **
19 19 ****************************************************************************/
20 20
21 #include "xychartitem_p.h"
21 #include "xychart_p.h"
22 22 #include "qxyseries.h"
23 23 #include "qxyseries_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include "chartanimator_p.h"
26 26 #include <QPainter>
27 #include <QGraphicsSceneMouseEvent>
28 27 #include <QAbstractItemModel>
29 28 #include "qxymodelmapper.h"
30 #include <QDebug>
31 29
32 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 31
34 32 //TODO: optimize : remove points which are not visible
35 33
36 XYChartItem::XYChartItem(QXYSeries *series, ChartPresenter *presenter):ChartItem(presenter),
34 XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):Chart(presenter),
37 35 m_minX(0),
38 36 m_maxX(0),
39 37 m_minY(0),
@@ -50,22 +48,22 m_animation(0)
50 48 QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF)));
51 49 }
52 50
53 void XYChartItem::setGeometryPoints(QVector<QPointF>& points)
51 void XYChart::setGeometryPoints(QVector<QPointF>& points)
54 52 {
55 53 m_points = points;
56 54 }
57 55
58 void XYChartItem::setClipRect(const QRectF &rect)
56 void XYChart::setClipRect(const QRectF &rect)
59 57 {
60 58 m_clipRect = rect;
61 59 }
62 60
63 void XYChartItem::setAnimation(XYAnimation* animation)
61 void XYChart::setAnimation(XYAnimation* animation)
64 62 {
65 63 m_animation=animation;
66 64 }
67 65
68 QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const
66 QPointF XYChart::calculateGeometryPoint(const QPointF &point) const
69 67 {
70 68 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
71 69 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
@@ -74,7 +72,7 QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const
74 72 return QPointF(x,y);
75 73 }
76 74
77 QPointF XYChartItem::calculateGeometryPoint(int index) const
75 QPointF XYChart::calculateGeometryPoint(int index) const
78 76 {
79 77 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
80 78 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
@@ -84,7 +82,7 QPointF XYChartItem::calculateGeometryPoint(int index) const
84 82 return QPointF(x,y);
85 83 }
86 84
87 QVector<QPointF> XYChartItem::calculateGeometryPoints() const
85 QVector<QPointF> XYChart::calculateGeometryPoints() const
88 86 {
89 87 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
90 88 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
@@ -101,7 +99,7 QVector<QPointF> XYChartItem::calculateGeometryPoints() const
101 99 return result;
102 100 }
103 101
104 QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const
102 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
105 103 {
106 104 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
107 105 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
@@ -110,7 +108,7 QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const
110 108 return QPointF(x,y);
111 109 }
112 110
113 void XYChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
111 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
114 112 {
115 113 if (m_animation) {
116 114 m_animation->setValues(oldPoints, newPoints, index);
@@ -122,13 +120,9 void XYChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &new
122 120 }
123 121 }
124 122
125 void XYChartItem::updateGeometry()
126 {
127 update();
128 }
129 123 //handlers
130 124
131 void XYChartItem::handlePointAdded(int index)
125 void XYChart::handlePointAdded(int index)
132 126 {
133 127 if (m_series->model() == 0) {
134 128 Q_ASSERT(index<m_series->count());
@@ -147,7 +141,7 void XYChartItem::handlePointAdded(int index)
147 141 updateChart(m_points,points,index);
148 142 }
149 143
150 void XYChartItem::handlePointsAdded(int start, int end)
144 void XYChart::handlePointsAdded(int start, int end)
151 145 {
152 146 if (m_series->model() == 0) {
153 147 for (int i = start; i <= end; i++)
@@ -177,7 +171,7 void XYChartItem::handlePointsAdded(int start, int end)
177 171 }
178 172 }
179 173
180 void XYChartItem::handlePointRemoved(int index)
174 void XYChart::handlePointRemoved(int index)
181 175 {
182 176 if (m_series->model() == 0) {
183 177 Q_ASSERT(index<m_series->count() + 1);
@@ -193,7 +187,7 void XYChartItem::handlePointRemoved(int index)
193 187 updateChart(m_points,points,index);
194 188 }
195 189
196 void XYChartItem::handlePointsRemoved(int start, int end)
190 void XYChart::handlePointsRemoved(int start, int end)
197 191 {
198 192 Q_UNUSED(start)
199 193 Q_UNUSED(end)
@@ -244,7 +238,7 void XYChartItem::handlePointsRemoved(int start, int end)
244 238
245 239 }
246 240
247 void XYChartItem::handlePointReplaced(int index)
241 void XYChart::handlePointReplaced(int index)
248 242 {
249 243 Q_ASSERT(index<m_series->count());
250 244 Q_ASSERT(index>=0);
@@ -259,7 +253,7 void XYChartItem::handlePointReplaced(int index)
259 253 updateChart(m_points,points,index);
260 254 }
261 255
262 void XYChartItem::handleReinitialized()
256 void XYChart::handleReinitialized()
263 257 {
264 258 QVector<QPointF> points = calculateGeometryPoints();
265 259
@@ -270,7 +264,7 void XYChartItem::handleReinitialized()
270 264 updateChart(m_points,points);
271 265 }
272 266
273 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
267 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
274 268 {
275 269 m_minX=minX;
276 270 m_maxX=maxX;
@@ -285,12 +279,12 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal
285 279 updateChart(m_points,points);
286 280 }
287 281
288 void XYChartItem::handleGeometryChanged(const QRectF &rect)
282 void XYChart::handleGeometryChanged(const QRectF &rect)
289 283 {
290 284 Q_ASSERT(rect.isValid());
291 285 m_size=rect.size();
292 286 m_clipRect=rect.translated(-rect.topLeft());
293 setPos(rect.topLeft());
287 m_origin=rect.topLeft();
294 288
295 289 if (isEmpty()) return;
296 290 QVector<QPointF> points = calculateGeometryPoints();
@@ -300,16 +294,11 void XYChartItem::handleGeometryChanged(const QRectF &rect)
300 294 updateChart(m_points,points);
301 295 }
302 296
303 bool XYChartItem::isEmpty()
297 bool XYChart::isEmpty()
304 298 {
305 299 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty();
306 300 }
307 301
308 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
309 {
310 emit clicked(calculateDomainPoint(event->pos()));
311 }
312
313 #include "moc_xychartitem_p.cpp"
302 #include "moc_xychart_p.cpp"
314 303
315 304 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,12 +2,12 INCLUDEPATH += $$PWD
2 2 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 $$PWD/xychartitem.cpp \
5 $$PWD/xychart.cpp \
6 6 $$PWD/qxyseries.cpp \
7 7 $$PWD/qxymodelmapper.cpp
8 8
9 9 PRIVATE_HEADERS += \
10 $$PWD/xychartitem_p.h \
10 $$PWD/xychart_p.h \
11 11 $$PWD/qxyseries_p.h
12 12
13 13
@@ -31,12 +31,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31 class ChartPresenter;
32 32 class QXYSeries;
33 33
34 class XYChartItem : public ChartItem
34 class XYChart : public Chart
35 35 {
36 36 Q_OBJECT
37 37 public:
38 explicit XYChartItem(QXYSeries *series, ChartPresenter *presenter);
39 ~XYChartItem(){};
38 explicit XYChart(QXYSeries *series, ChartPresenter *presenter);
39 ~XYChart(){};
40 40
41 41 void setGeometryPoints(QVector<QPointF>& points);
42 42 QVector<QPointF> geometryPoints() const { return m_points; }
@@ -44,9 +44,12 public:
44 44 void setClipRect(const QRectF &rect);
45 45 QRectF clipRect() const { return m_clipRect; }
46 46
47 QSizeF size() const { return m_size; }
48 QPointF origin() const { return m_origin; }
49
47 50 void setAnimation(XYAnimation* animation);
48 51 ChartAnimation* animation() const { return m_animation; }
49 virtual void updateGeometry();
52 virtual void updateGeometry() = 0;
50 53
51 54 public Q_SLOTS:
52 55 void handlePointAdded(int index);
@@ -67,7 +70,6 protected:
67 70 QPointF calculateGeometryPoint(int index) const;
68 71 QPointF calculateDomainPoint(const QPointF &point) const;
69 72 QVector<QPointF> calculateGeometryPoints() const;
70 void mousePressEvent(QGraphicsSceneMouseEvent *event);
71 73
72 74 private:
73 75 inline bool isEmpty();
@@ -79,6 +81,7 private:
79 81 qreal m_maxY;
80 82 QXYSeries* m_series;
81 83 QSizeF m_size;
84 QPointF m_origin;
82 85 QRectF m_clipRect;
83 86 QVector<QPointF> m_points;
84 87 XYAnimation* m_animation;
General Comments 0
You need to be logged in to leave comments. Login now