@@ -1,210 +1,210 | |||||
1 | #include "linechartitem_p.h" |
|
1 | #include "linechartitem_p.h" | |
2 | #include "qlineseries.h" |
|
2 | #include "qlineseries.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | //TODO: optimazie : remove points which are not visible |
|
9 | //TODO: optimazie : remove points which are not visible | |
10 |
|
10 | |||
11 | LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent), |
|
11 | LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent), | |
12 | m_presenter(presenter), |
|
12 | m_presenter(presenter), | |
13 | m_series(series), |
|
13 | m_series(series), | |
14 | m_dirtyData(false), |
|
14 | m_dirtyData(false), | |
15 | m_dirtyGeometry(false), |
|
15 | m_dirtyGeometry(false), | |
16 | m_dirtyDomain(false) |
|
16 | m_dirtyDomain(false) | |
17 | { |
|
17 | { | |
18 | setZValue(ChartPresenter::LineChartZValue); |
|
18 | setZValue(ChartPresenter::LineChartZValue); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | QRectF LineChartItem::boundingRect() const |
|
21 | QRectF LineChartItem::boundingRect() const | |
22 | { |
|
22 | { | |
23 | return m_rect; |
|
23 | return m_rect; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | QPainterPath LineChartItem::shape() const |
|
26 | QPainterPath LineChartItem::shape() const | |
27 | { |
|
27 | { | |
28 | return m_path; |
|
28 | return m_path; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | void LineChartItem::addPoints(const QVector<QPointF>& points) |
|
32 | void LineChartItem::addPoints(const QVector<QPointF>& points) | |
33 | { |
|
33 | { | |
34 | m_data = points; |
|
34 | m_data = points; | |
35 | for(int i=0; i<m_data.size();i++){ |
|
35 | for(int i=0; i<m_data.size();i++){ | |
36 | const QPointF& point =m_data[i]; |
|
36 | const QPointF& point =m_data[i]; | |
37 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
37 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); | |
38 | item->setPos(point.x()-1,point.y()-1);; |
|
38 | item->setPos(point.x()-1,point.y()-1);; | |
39 |
if(!m_clipRect.contains(point) || !m_series-> |
|
39 | if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false); | |
40 | m_points << item; |
|
40 | m_points << item; | |
41 | } |
|
41 | } | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void LineChartItem::addPoint(const QPointF& point) |
|
44 | void LineChartItem::addPoint(const QPointF& point) | |
45 | { |
|
45 | { | |
46 | m_data << point; |
|
46 | m_data << point; | |
47 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
47 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); | |
48 | m_clipRect.contains(point); |
|
48 | m_clipRect.contains(point); | |
49 | item->setPos(point.x()-1,point.y()-1); |
|
49 | item->setPos(point.x()-1,point.y()-1); | |
50 |
if(!m_clipRect.contains(point) || !m_series-> |
|
50 | if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false); | |
51 | m_points << item; |
|
51 | m_points << item; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void LineChartItem::removePoint(const QPointF& point) |
|
54 | void LineChartItem::removePoint(const QPointF& point) | |
55 | { |
|
55 | { | |
56 | Q_ASSERT(m_data.count() == m_points.count()); |
|
56 | Q_ASSERT(m_data.count() == m_points.count()); | |
57 | int index = m_data.lastIndexOf(point,0); |
|
57 | int index = m_data.lastIndexOf(point,0); | |
58 | m_data.remove(index); |
|
58 | m_data.remove(index); | |
59 | delete(m_points.takeAt(index)); |
|
59 | delete(m_points.takeAt(index)); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint) |
|
62 | void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint) | |
63 | { |
|
63 | { | |
64 | Q_ASSERT(m_data.count() == m_points.count()); |
|
64 | Q_ASSERT(m_data.count() == m_points.count()); | |
65 | int index = m_data.lastIndexOf(oldPoint,0); |
|
65 | int index = m_data.lastIndexOf(oldPoint,0); | |
66 |
|
66 | |||
67 | if(index > -1){ |
|
67 | if(index > -1){ | |
68 | m_data.replace(index,newPoint); |
|
68 | m_data.replace(index,newPoint); | |
69 | QGraphicsItem* item = m_points.at(index); |
|
69 | QGraphicsItem* item = m_points.at(index); | |
70 | item->setPos(newPoint.x()-1,newPoint.y()-1); |
|
70 | item->setPos(newPoint.x()-1,newPoint.y()-1); | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void LineChartItem::setPoint(int index,const QPointF& point) |
|
74 | void LineChartItem::setPoint(int index,const QPointF& point) | |
75 | { |
|
75 | { | |
76 | Q_ASSERT(m_data.count() == m_points.count()); |
|
76 | Q_ASSERT(m_data.count() == m_points.count()); | |
77 | Q_ASSERT(index>=0); |
|
77 | Q_ASSERT(index>=0); | |
78 |
|
78 | |||
79 | m_data.replace(index,point); |
|
79 | m_data.replace(index,point); | |
80 | QGraphicsItem* item = m_points.at(index); |
|
80 | QGraphicsItem* item = m_points.at(index); | |
81 | item->setPos(point.x()-1,point.y()-1); |
|
81 | item->setPos(point.x()-1,point.y()-1); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void LineChartItem::clear() |
|
84 | void LineChartItem::clear() | |
85 | { |
|
85 | { | |
86 | qDeleteAll(m_points); |
|
86 | qDeleteAll(m_points); | |
87 | m_points.clear(); |
|
87 | m_points.clear(); | |
88 | m_hash.clear(); |
|
88 | m_hash.clear(); | |
89 | m_path = QPainterPath(); |
|
89 | m_path = QPainterPath(); | |
90 | m_rect = QRect(); |
|
90 | m_rect = QRect(); | |
91 | m_data.clear(); |
|
91 | m_data.clear(); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void LineChartItem::clearView() |
|
94 | void LineChartItem::clearView() | |
95 | { |
|
95 | { | |
96 | qDeleteAll(m_points); |
|
96 | qDeleteAll(m_points); | |
97 | m_points.clear(); |
|
97 | m_points.clear(); | |
98 | m_path = QPainterPath(); |
|
98 | m_path = QPainterPath(); | |
99 | m_rect = QRect(); |
|
99 | m_rect = QRect(); | |
100 | m_data.clear(); |
|
100 | m_data.clear(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
103 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
104 | { |
|
104 | { | |
105 | Q_UNUSED(widget); |
|
105 | Q_UNUSED(widget); | |
106 | Q_UNUSED(option); |
|
106 | Q_UNUSED(option); | |
107 | painter->save(); |
|
107 | painter->save(); | |
108 | painter->setPen(m_pen); |
|
108 | painter->setPen(m_pen); | |
109 | painter->setClipRect(m_clipRect); |
|
109 | painter->setClipRect(m_clipRect); | |
110 | painter->drawPath(m_path); |
|
110 | painter->drawPath(m_path); | |
111 | painter->restore(); |
|
111 | painter->restore(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void LineChartItem::calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const |
|
114 | void LineChartItem::calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const | |
115 | { |
|
115 | { | |
116 | const qreal deltaX = size.width()/domain.spanX(); |
|
116 | const qreal deltaX = size.width()/domain.spanX(); | |
117 | const qreal deltaY = size.height()/domain.spanY(); |
|
117 | const qreal deltaY = size.height()/domain.spanY(); | |
118 | qreal x = (series->x(index) - domain.m_minX)* deltaX; |
|
118 | qreal x = (series->x(index) - domain.m_minX)* deltaX; | |
119 | qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height(); |
|
119 | qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height(); | |
120 | point.setX(x); |
|
120 | point.setX(x); | |
121 | point.setY(y); |
|
121 | point.setY(y); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineSeries* series,const QSizeF& size, const Domain& domain) const |
|
125 | void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineSeries* series,const QSizeF& size, const Domain& domain) const | |
126 | { |
|
126 | { | |
127 | const qreal deltaX = size.width()/domain.spanX(); |
|
127 | const qreal deltaX = size.width()/domain.spanX(); | |
128 | const qreal deltaY = size.height()/domain.spanY(); |
|
128 | const qreal deltaY = size.height()/domain.spanY(); | |
129 |
|
129 | |||
130 | for (int i = 0; i < series->count(); ++i) { |
|
130 | for (int i = 0; i < series->count(); ++i) { | |
131 | qreal x = (series->x(i) - domain.m_minX)* deltaX; |
|
131 | qreal x = (series->x(i) - domain.m_minX)* deltaX; | |
132 | qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height(); |
|
132 | qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height(); | |
133 | hash[i] = points.size(); |
|
133 | hash[i] = points.size(); | |
134 | points << QPointF(x,y); |
|
134 | points << QPointF(x,y); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void LineChartItem::updateDomain() |
|
138 | void LineChartItem::updateDomain() | |
139 | { |
|
139 | { | |
140 | clear(); |
|
140 | clear(); | |
141 | prepareGeometryChange(); |
|
141 | prepareGeometryChange(); | |
142 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); |
|
142 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); | |
143 | addPoints(m_data); |
|
143 | addPoints(m_data); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void LineChartItem::updateData() |
|
146 | void LineChartItem::updateData() | |
147 | { |
|
147 | { | |
148 | //for now the same |
|
148 | //for now the same | |
149 | updateDomain(); |
|
149 | updateDomain(); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void LineChartItem::updateGeometry() |
|
152 | void LineChartItem::updateGeometry() | |
153 | { |
|
153 | { | |
154 |
|
154 | |||
155 | if(m_data.size()==0) return; |
|
155 | if(m_data.size()==0) return; | |
156 |
|
156 | |||
157 | prepareGeometryChange(); |
|
157 | prepareGeometryChange(); | |
158 | QPainterPath path; |
|
158 | QPainterPath path; | |
159 | const QPointF& point = m_data.at(0); |
|
159 | const QPointF& point = m_data.at(0); | |
160 | path.moveTo(point); |
|
160 | path.moveTo(point); | |
161 |
|
161 | |||
162 | foreach( const QPointF& point , m_data) { |
|
162 | foreach( const QPointF& point , m_data) { | |
163 | path.lineTo(point); |
|
163 | path.lineTo(point); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | m_path = path; |
|
166 | m_path = path; | |
167 | m_rect = path.boundingRect(); |
|
167 | m_rect = path.boundingRect(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void LineChartItem::setPen(const QPen& pen) |
|
170 | void LineChartItem::setPen(const QPen& pen) | |
171 | { |
|
171 | { | |
172 | m_pen = pen; |
|
172 | m_pen = pen; | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | //handlers |
|
175 | //handlers | |
176 |
|
176 | |||
177 | void LineChartItem::handleModelChanged(int index) |
|
177 | void LineChartItem::handleModelChanged(int index) | |
178 | { |
|
178 | { | |
179 | Q_ASSERT(index<m_series->count()); |
|
179 | Q_ASSERT(index<m_series->count()); | |
180 | if(m_hash.contains(index)){ |
|
180 | if(m_hash.contains(index)){ | |
181 | int i = m_hash.value(index); |
|
181 | int i = m_hash.value(index); | |
182 | QPointF point; |
|
182 | QPointF point; | |
183 | calculatePoint(point,index,m_series,m_size,m_domain); |
|
183 | calculatePoint(point,index,m_series,m_size,m_domain); | |
184 | setPoint(i,point); |
|
184 | setPoint(i,point); | |
185 | } |
|
185 | } | |
186 | update(); |
|
186 | update(); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void LineChartItem::handleDomainChanged(const Domain& domain) |
|
189 | void LineChartItem::handleDomainChanged(const Domain& domain) | |
190 | { |
|
190 | { | |
191 | m_domain = domain; |
|
191 | m_domain = domain; | |
192 | updateDomain(); |
|
192 | updateDomain(); | |
193 | update(); |
|
193 | update(); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void LineChartItem::handleGeometryChanged(const QRectF& rect) |
|
196 | void LineChartItem::handleGeometryChanged(const QRectF& rect) | |
197 | { |
|
197 | { | |
198 | Q_ASSERT(rect.isValid()); |
|
198 | Q_ASSERT(rect.isValid()); | |
199 | m_size=rect.size(); |
|
199 | m_size=rect.size(); | |
200 | m_clipRect=rect.translated(-rect.topLeft()); |
|
200 | m_clipRect=rect.translated(-rect.topLeft()); | |
201 | updateDomain(); |
|
201 | updateDomain(); | |
202 | updateGeometry(); |
|
202 | updateGeometry(); | |
203 | setPos(rect.topLeft()); |
|
203 | setPos(rect.topLeft()); | |
204 | update(); |
|
204 | update(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 |
|
207 | |||
208 | #include "moc_linechartitem_p.cpp" |
|
208 | #include "moc_linechartitem_p.cpp" | |
209 |
|
209 | |||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
210 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,195 +1,195 | |||||
1 | #include "qlineseries.h" |
|
1 | #include "qlineseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QLineSeries |
|
6 | \class QLineSeries | |
7 | \brief The QLineSeries class is used for making line charts. |
|
7 | \brief The QLineSeries class is used for making line charts. | |
8 |
|
8 | |||
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | A line chart is used to show information as a series of data points |
|
11 | A line chart is used to show information as a series of data points | |
12 | connected by straight lines. |
|
12 | connected by straight lines. | |
13 |
|
13 | |||
14 | \image linechart.png |
|
14 | \image linechart.png | |
15 |
|
15 | |||
16 | To create line charts, users need to first QLineSeries object. |
|
16 | To create line charts, users need to first QLineSeries object. | |
17 |
|
17 | |||
18 | \snippet ../example/linechart/main.cpp 1 |
|
18 | \snippet ../example/linechart/main.cpp 1 | |
19 |
|
19 | |||
20 | Populate with the data |
|
20 | Populate with the data | |
21 |
|
21 | |||
22 | \snippet ../example/linechart/main.cpp 2 |
|
22 | \snippet ../example/linechart/main.cpp 2 | |
23 |
|
23 | |||
24 | Add created series objects to QChartView or QChart instance. |
|
24 | Add created series objects to QChartView or QChart instance. | |
25 |
|
25 | |||
26 | \snippet ../example/linechart/main.cpp 3 |
|
26 | \snippet ../example/linechart/main.cpp 3 | |
27 |
|
27 | |||
28 | */ |
|
28 | */ | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \fn virtual QSeriesType QLineSeries::type() const |
|
31 | \fn virtual QSeriesType QLineSeries::type() const | |
32 | \brief Returns type of series. |
|
32 | \brief Returns type of series. | |
33 | \sa QSeries, QSeriesType |
|
33 | \sa QSeries, QSeriesType | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \fn QPen QLineSeries::pen() const |
|
37 | \fn QPen QLineSeries::pen() const | |
38 | \brief Returns the pen used to draw line for this series. |
|
38 | \brief Returns the pen used to draw line for this series. | |
39 | \sa setPen() |
|
39 | \sa setPen() | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 |
\fn bool QLineSeries:: |
|
43 | \fn bool QLineSeries::pointsVisible() const | |
44 | \brief Returns if the points are drawn for this series. |
|
44 | \brief Returns if the points are drawn for this series. | |
45 | \sa setPointsVisible() |
|
45 | \sa setPointsVisible() | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn void QLineSeries::changed(int index) |
|
50 | \fn void QLineSeries::changed(int index) | |
51 | \brief \internal \a index |
|
51 | \brief \internal \a index | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs empty series object which is a child of \a parent. |
|
55 | Constructs empty series object which is a child of \a parent. | |
56 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
56 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
57 | */ |
|
57 | */ | |
58 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), |
|
58 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), | |
59 | m_pointsVisible(false) |
|
59 | m_pointsVisible(false) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 | /*! |
|
62 | /*! | |
63 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
63 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
64 | and are deleted when mentioned object are destroyed. |
|
64 | and are deleted when mentioned object are destroyed. | |
65 | */ |
|
65 | */ | |
66 | QLineSeries::~QLineSeries() |
|
66 | QLineSeries::~QLineSeries() | |
67 | { |
|
67 | { | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
71 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
72 | */ |
|
72 | */ | |
73 | void QLineSeries::add(qreal x,qreal y) |
|
73 | void QLineSeries::add(qreal x,qreal y) | |
74 | { |
|
74 | { | |
75 | m_x<<x; |
|
75 | m_x<<x; | |
76 | m_y<<y; |
|
76 | m_y<<y; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | This is an overloaded function. |
|
80 | This is an overloaded function. | |
81 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
81 | Adds data \a point to the series. Points are connected with lines on the chart. | |
82 | */ |
|
82 | */ | |
83 | void QLineSeries::add(const QPointF& point) |
|
83 | void QLineSeries::add(const QPointF& point) | |
84 | { |
|
84 | { | |
85 | m_x<<point.x(); |
|
85 | m_x<<point.x(); | |
86 | m_y<<point.y(); |
|
86 | m_y<<point.y(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | Modifies \a y value for given \a x a value. |
|
90 | Modifies \a y value for given \a x a value. | |
91 | */ |
|
91 | */ | |
92 | void QLineSeries::replace(qreal x,qreal y) |
|
92 | void QLineSeries::replace(qreal x,qreal y) | |
93 | { |
|
93 | { | |
94 | int index = m_x.indexOf(x); |
|
94 | int index = m_x.indexOf(x); | |
95 | m_x[index]=x; |
|
95 | m_x[index]=x; | |
96 | m_y[index]=y; |
|
96 | m_y[index]=y; | |
97 | emit changed(index); |
|
97 | emit changed(index); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | This is an overloaded function. |
|
101 | This is an overloaded function. | |
102 | Replaces current y value of for given \a point x value with \a point y value. |
|
102 | Replaces current y value of for given \a point x value with \a point y value. | |
103 | */ |
|
103 | */ | |
104 | void QLineSeries::replace(const QPointF& point) |
|
104 | void QLineSeries::replace(const QPointF& point) | |
105 | { |
|
105 | { | |
106 | int index = m_x.indexOf(point.x()); |
|
106 | int index = m_x.indexOf(point.x()); | |
107 | m_x[index]=point.x(); |
|
107 | m_x[index]=point.x(); | |
108 | m_y[index]=point.y(); |
|
108 | m_y[index]=point.y(); | |
109 | emit changed(index); |
|
109 | emit changed(index); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Removes current \a x and y value. |
|
113 | Removes current \a x and y value. | |
114 | */ |
|
114 | */ | |
115 | void QLineSeries::remove(qreal x) |
|
115 | void QLineSeries::remove(qreal x) | |
116 | { |
|
116 | { | |
117 |
|
117 | |||
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Removes current \a point x value. Note \a point y value is ignored. |
|
121 | Removes current \a point x value. Note \a point y value is ignored. | |
122 | */ |
|
122 | */ | |
123 | void QLineSeries::remove(const QPointF& point) |
|
123 | void QLineSeries::remove(const QPointF& point) | |
124 | { |
|
124 | { | |
125 |
|
125 | |||
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Clears all the data. |
|
129 | Clears all the data. | |
130 | */ |
|
130 | */ | |
131 | void QLineSeries::clear() |
|
131 | void QLineSeries::clear() | |
132 | { |
|
132 | { | |
133 | m_x.clear(); |
|
133 | m_x.clear(); | |
134 | m_y.clear(); |
|
134 | m_y.clear(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \internal \a pos |
|
138 | \internal \a pos | |
139 | */ |
|
139 | */ | |
140 | qreal QLineSeries::x(int pos) const |
|
140 | qreal QLineSeries::x(int pos) const | |
141 | { |
|
141 | { | |
142 | return m_x.at(pos); |
|
142 | return m_x.at(pos); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \internal \a pos |
|
146 | \internal \a pos | |
147 | */ |
|
147 | */ | |
148 | qreal QLineSeries::y(int pos) const |
|
148 | qreal QLineSeries::y(int pos) const | |
149 | { |
|
149 | { | |
150 | return m_y.at(pos); |
|
150 | return m_y.at(pos); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Returns number of data points within series. |
|
154 | Returns number of data points within series. | |
155 | */ |
|
155 | */ | |
156 | int QLineSeries::count() const |
|
156 | int QLineSeries::count() const | |
157 | { |
|
157 | { | |
158 | Q_ASSERT(m_x.size() == m_y.size()); |
|
158 | Q_ASSERT(m_x.size() == m_y.size()); | |
159 |
|
159 | |||
160 | return m_x.size(); |
|
160 | return m_x.size(); | |
161 |
|
161 | |||
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Sets \a pen used for drawing given series.. |
|
165 | Sets \a pen used for drawing given series.. | |
166 | */ |
|
166 | */ | |
167 | void QLineSeries::setPen(const QPen& pen) |
|
167 | void QLineSeries::setPen(const QPen& pen) | |
168 | { |
|
168 | { | |
169 | m_pen=pen; |
|
169 | m_pen=pen; | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Sets if data points are \a visible and should be drawn on line. |
|
173 | Sets if data points are \a visible and should be drawn on line. | |
174 | */ |
|
174 | */ | |
175 | void QLineSeries::setPointsVisible(bool visible) |
|
175 | void QLineSeries::setPointsVisible(bool visible) | |
176 | { |
|
176 | { | |
177 | m_pointsVisible=visible; |
|
177 | m_pointsVisible=visible; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
180 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
181 | { |
|
181 | { | |
182 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
182 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
183 |
|
183 | |||
184 | int size = series.m_x.size(); |
|
184 | int size = series.m_x.size(); | |
185 |
|
185 | |||
186 | for (int i=0;i<size;i++) { |
|
186 | for (int i=0;i<size;i++) { | |
187 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
187 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
188 | } |
|
188 | } | |
189 | return debug.space(); |
|
189 | return debug.space(); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 |
|
192 | |||
193 | #include "moc_qlineseries.cpp" |
|
193 | #include "moc_qlineseries.cpp" | |
194 |
|
194 | |||
195 | QTCOMMERCIALCHART_END_NAMESPACE |
|
195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||||
1 | #ifndef QLINESERIES_H_ |
|
1 | #ifndef QLINESERIES_H_ | |
2 | #define QLINESERIES_H_ |
|
2 | #define QLINESERIES_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qseries.h" |
|
5 | #include "qseries.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 | #include <QBrush> |
|
8 | #include <QBrush> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries |
|
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | QLineSeries(QObject* parent=0); |
|
16 | QLineSeries(QObject* parent=0); | |
17 | virtual ~QLineSeries(); |
|
17 | virtual ~QLineSeries(); | |
18 |
|
18 | |||
19 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} |
|
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} | |
21 | void add(qreal x, qreal y); |
|
21 | void add(qreal x, qreal y); | |
22 | void add(const QPointF& point); |
|
22 | void add(const QPointF& point); | |
23 | void replace(qreal x,qreal y); |
|
23 | void replace(qreal x,qreal y); | |
24 | void replace(const QPointF& point); |
|
24 | void replace(const QPointF& point); | |
25 | void remove(qreal x); |
|
25 | void remove(qreal x); | |
26 | void remove(const QPointF& point); |
|
26 | void remove(const QPointF& point); | |
27 | void clear(); |
|
27 | void clear(); | |
28 |
|
28 | |||
29 | void setPen(const QPen& pen); |
|
29 | void setPen(const QPen& pen); | |
30 | QPen pen() const { return m_pen;} |
|
30 | QPen pen() const { return m_pen;} | |
31 |
|
31 | |||
32 | void setPointsVisible(bool visible); |
|
32 | void setPointsVisible(bool visible); | |
33 |
bool |
|
33 | bool pointsVisible() const {return m_pointsVisible;} | |
34 |
|
34 | |||
35 | int count() const; |
|
35 | int count() const; | |
36 | qreal x(int pos) const; |
|
36 | qreal x(int pos) const; | |
37 | qreal y(int pos) const; |
|
37 | qreal y(int pos) const; | |
38 | friend QDebug operator<< (QDebug d, const QLineSeries series); |
|
38 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
39 |
|
39 | |||
40 | signals: |
|
40 | signals: | |
41 | void changed(int index); |
|
41 | void changed(int index); | |
42 |
|
42 | |||
43 | private: |
|
43 | private: | |
44 | QVector<qreal> m_x; |
|
44 | QVector<qreal> m_x; | |
45 | QVector<qreal> m_y; |
|
45 | QVector<qreal> m_y; | |
46 | QPen m_pen; |
|
46 | QPen m_pen; | |
47 | bool m_pointsVisible; |
|
47 | bool m_pointsVisible; | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif |
|
52 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now