@@ -1,44 +1,44 | |||||
1 | #ifndef AXISANIMATIONITEM_H_ |
|
1 | #ifndef AXISANIMATIONITEM_H_ | |
2 | #define AXISANIMATIONITEM_H_ |
|
2 | #define AXISANIMATIONITEM_H_ | |
3 |
|
3 | |||
4 | #include "domain_p.h" |
|
4 | #include "domain_p.h" | |
5 | #include "axisitem_p.h" |
|
5 | #include "axisitem_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 | #include <QVariantAnimation> |
|
7 | #include <QVariantAnimation> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QChartAxis; |
|
11 | class QChartAxis; | |
12 |
|
12 | |||
13 | class AxisAnimationItem : public AxisItem |
|
13 | class AxisAnimationItem : public AxisItem | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 | AxisAnimationItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); |
|
18 | AxisAnimationItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisAnimationItem(); |
|
19 | ~AxisAnimationItem(); | |
20 |
|
20 | |||
21 | void setLabelsAngle(int angle); |
|
21 | void setLabelsAngle(int angle); | |
22 |
|
22 | |||
23 | protected: |
|
23 | protected: | |
24 | void updateItems(QVector<qreal>& vector); |
|
24 | void updateItems(QVector<qreal>& vector); | |
25 |
|
25 | |||
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
28 | class AxisAnimator: public QVariantAnimation |
|
28 | class AxisAnimator: public QVariantAnimation | |
29 | { |
|
29 | { | |
30 | public: |
|
30 | public: | |
31 | AxisAnimator(AxisItem *axis,QObject *parent = 0); |
|
31 | AxisAnimator(AxisItem *axis,QObject *parent = 0); | |
32 |
|
|
32 | ~AxisAnimator(); | |
33 | protected: |
|
33 | protected: | |
34 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; |
|
34 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; | |
35 | virtual void updateCurrentValue (const QVariant & value ); |
|
35 | virtual void updateCurrentValue (const QVariant & value ); | |
36 | private: |
|
36 | private: | |
37 | AxisItem* m_axis; |
|
37 | AxisItem* m_axis; | |
38 | }; |
|
38 | }; | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |
41 |
|
41 | |||
42 |
|
42 | |||
43 |
|
43 | |||
44 | #endif /* AXISITEM_H_ */ |
|
44 | #endif /* AXISITEM_H_ */ |
@@ -1,335 +1,332 | |||||
1 | #include "axisitem_p.h" |
|
1 | #include "axisitem_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | static int label_padding = 5; |
|
7 | static int label_padding = 5; | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : |
|
11 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : | |
12 | ChartItem(parent), |
|
12 | ChartItem(parent), | |
13 | m_type(type), |
|
13 | m_type(type), | |
14 | m_labelsAngle(0), |
|
14 | m_labelsAngle(0), | |
15 | m_grid(parent), |
|
15 | m_grid(parent), | |
16 | m_shades(parent), |
|
16 | m_shades(parent), | |
17 | m_labels(parent), |
|
17 | m_labels(parent), | |
18 | m_axis(parent) |
|
18 | m_axis(parent) | |
19 | { |
|
19 | { | |
20 | //initial initialization |
|
20 | //initial initialization | |
21 | m_axis.setZValue(ChartPresenter::AxisZValue); |
|
21 | m_axis.setZValue(ChartPresenter::AxisZValue); | |
22 | m_shades.setZValue(ChartPresenter::ShadesZValue); |
|
22 | m_shades.setZValue(ChartPresenter::ShadesZValue); | |
23 | m_grid.setZValue(ChartPresenter::GridZValue); |
|
23 | m_grid.setZValue(ChartPresenter::GridZValue); | |
24 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
24 | setFlags(QGraphicsItem::ItemHasNoContents); | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | AxisItem::~AxisItem() |
|
27 | AxisItem::~AxisItem() | |
28 | { |
|
28 | { | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QRectF AxisItem::boundingRect() const |
|
31 | QRectF AxisItem::boundingRect() const | |
32 | { |
|
32 | { | |
33 | return QRectF(); |
|
33 | return QRectF(); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void AxisItem::createItems(int count) |
|
36 | void AxisItem::createItems(int count) | |
37 | { |
|
37 | { | |
38 | if(m_axis.children().size()==0) |
|
38 | if(m_axis.children().size()==0) | |
39 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
39 | m_axis.addToGroup(new QGraphicsLineItem()); | |
40 | for (int i = 0; i < count; ++i) { |
|
40 | for (int i = 0; i < count; ++i) { | |
41 | m_grid.addToGroup(new QGraphicsLineItem()); |
|
41 | m_grid.addToGroup(new QGraphicsLineItem()); | |
42 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); |
|
42 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); | |
43 | if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem()); |
|
43 | if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem()); | |
44 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
44 | m_axis.addToGroup(new QGraphicsLineItem()); | |
45 | } |
|
45 | } | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void AxisItem::clear(int count) |
|
48 | void AxisItem::clear(int count) | |
49 | { |
|
49 | { | |
50 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
50 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
51 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
51 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
52 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
52 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
53 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
53 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
54 |
|
54 | |||
55 | for (int i = 0; i < count; ++i) { |
|
55 | for (int i = 0; i < count; ++i) { | |
56 | delete(lines.takeLast()); |
|
56 | delete(lines.takeLast()); | |
57 | delete(labels.takeLast()); |
|
57 | delete(labels.takeLast()); | |
58 | if(lines.size()%2) delete(shades.takeLast()); |
|
58 | if(lines.size()%2) delete(shades.takeLast()); | |
59 | delete(axis.takeLast()); |
|
59 | delete(axis.takeLast()); | |
60 | } |
|
60 | } | |
61 |
|
||||
62 | m_thicksList.clear(); |
|
|||
63 |
|
||||
64 | } |
|
61 | } | |
65 |
|
62 | |||
66 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
63 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
67 | { |
|
64 | { | |
68 | Q_UNUSED(painter); |
|
65 | Q_UNUSED(painter); | |
69 | Q_UNUSED(option); |
|
66 | Q_UNUSED(option); | |
70 | Q_UNUSED(widget); |
|
67 | Q_UNUSED(widget); | |
71 | } |
|
68 | } | |
72 |
|
69 | |||
73 | void AxisItem::updateItems(QVector<qreal>& vector) |
|
70 | void AxisItem::updateItems(QVector<qreal>& vector) | |
74 | { |
|
71 | { | |
75 | calculateLayout(vector); |
|
72 | calculateLayout(vector); | |
76 | if(vector.count()==0) return; |
|
73 | if(vector.count()==0) return; | |
77 | applyLayout(vector); |
|
74 | applyLayout(vector); | |
78 | } |
|
75 | } | |
79 |
|
76 | |||
80 | void AxisItem::handleAxisUpdate(QChartAxis* axis) |
|
77 | void AxisItem::handleAxisUpdate(QChartAxis* axis) | |
81 | { |
|
78 | { | |
82 | if(m_layoutVector.count()==0) return; |
|
79 | if(m_layoutVector.count()==0) return; | |
83 |
|
80 | |||
84 | if(axis->isAxisVisible()) { |
|
81 | if(axis->isAxisVisible()) { | |
85 | setAxisOpacity(100); |
|
82 | setAxisOpacity(100); | |
86 | } |
|
83 | } | |
87 | else { |
|
84 | else { | |
88 | setAxisOpacity(0); |
|
85 | setAxisOpacity(0); | |
89 | } |
|
86 | } | |
90 |
|
87 | |||
91 | if(axis->isGridVisible()) { |
|
88 | if(axis->isGridVisible()) { | |
92 | setGridOpacity(100); |
|
89 | setGridOpacity(100); | |
93 | } |
|
90 | } | |
94 | else { |
|
91 | else { | |
95 | setGridOpacity(0); |
|
92 | setGridOpacity(0); | |
96 | } |
|
93 | } | |
97 |
|
94 | |||
98 | if(axis->labelsVisible()) |
|
95 | if(axis->labelsVisible()) | |
99 | { |
|
96 | { | |
100 | setLabelsOpacity(100); |
|
97 | setLabelsOpacity(100); | |
101 | } |
|
98 | } | |
102 | else { |
|
99 | else { | |
103 | setLabelsOpacity(0); |
|
100 | setLabelsOpacity(0); | |
104 | } |
|
101 | } | |
105 |
|
102 | |||
106 | if(axis->shadesVisible()) { |
|
103 | if(axis->shadesVisible()) { | |
107 | setShadesOpacity(axis->shadesOpacity()); |
|
104 | setShadesOpacity(axis->shadesOpacity()); | |
108 | } |
|
105 | } | |
109 | else { |
|
106 | else { | |
110 | setShadesOpacity(0); |
|
107 | setShadesOpacity(0); | |
111 | } |
|
108 | } | |
112 |
|
109 | |||
113 | setLabelsAngle(axis->labelsAngle()); |
|
110 | setLabelsAngle(axis->labelsAngle()); | |
114 | setAxisPen(axis->axisPen()); |
|
111 | setAxisPen(axis->axisPen()); | |
115 | setLabelsPen(axis->labelsPen()); |
|
112 | setLabelsPen(axis->labelsPen()); | |
116 | setLabelsBrush(axis->labelsBrush()); |
|
113 | setLabelsBrush(axis->labelsBrush()); | |
117 | setLabelsFont(axis->labelsFont()); |
|
114 | setLabelsFont(axis->labelsFont()); | |
118 | setGridPen(axis->gridPen()); |
|
115 | setGridPen(axis->gridPen()); | |
119 | setShadesPen(axis->shadesPen()); |
|
116 | setShadesPen(axis->shadesPen()); | |
120 | setShadesBrush(axis->shadesBrush()); |
|
117 | setShadesBrush(axis->shadesBrush()); | |
121 | } |
|
118 | } | |
122 |
|
119 | |||
123 | void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
120 | void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
124 | { |
|
121 | { | |
125 | int diff = m_thicksList.size() - labels.size(); |
|
122 | int diff = m_thicksList.size() - labels.size(); | |
126 |
|
123 | |||
127 | if(diff>0){ |
|
124 | if(diff>0){ | |
128 | clear(diff); |
|
125 | clear(diff); | |
129 | }else if(diff<0){ |
|
126 | }else if(diff<0){ | |
130 | createItems(-diff); |
|
127 | createItems(-diff); | |
131 | } |
|
128 | } | |
132 | m_thicksList=labels; |
|
129 | m_thicksList=labels; | |
133 | m_layoutVector.resize(m_thicksList.size()); |
|
130 | m_layoutVector.resize(m_thicksList.size()); | |
134 | updateItems(m_layoutVector); |
|
131 | updateItems(m_layoutVector); | |
135 | if(diff!=0) handleAxisUpdate(axis); |
|
132 | if(diff!=0) handleAxisUpdate(axis); | |
136 | } |
|
133 | } | |
137 |
|
134 | |||
138 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
135 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |
139 | { |
|
136 | { | |
140 | m_rect = rect; |
|
137 | m_rect = rect; | |
141 | updateItems(m_layoutVector); |
|
138 | updateItems(m_layoutVector); | |
142 | } |
|
139 | } | |
143 |
|
140 | |||
144 | void AxisItem::setAxisOpacity(qreal opacity) |
|
141 | void AxisItem::setAxisOpacity(qreal opacity) | |
145 | { |
|
142 | { | |
146 | m_axis.setOpacity(opacity); |
|
143 | m_axis.setOpacity(opacity); | |
147 | } |
|
144 | } | |
148 |
|
145 | |||
149 | qreal AxisItem::axisOpacity() const |
|
146 | qreal AxisItem::axisOpacity() const | |
150 | { |
|
147 | { | |
151 | return m_axis.opacity(); |
|
148 | return m_axis.opacity(); | |
152 | } |
|
149 | } | |
153 |
|
150 | |||
154 | void AxisItem::setGridOpacity(qreal opacity) |
|
151 | void AxisItem::setGridOpacity(qreal opacity) | |
155 | { |
|
152 | { | |
156 | m_grid.setOpacity(opacity); |
|
153 | m_grid.setOpacity(opacity); | |
157 | } |
|
154 | } | |
158 |
|
155 | |||
159 | qreal AxisItem::gridOpacity() const |
|
156 | qreal AxisItem::gridOpacity() const | |
160 | { |
|
157 | { | |
161 | return m_grid.opacity(); |
|
158 | return m_grid.opacity(); | |
162 | } |
|
159 | } | |
163 |
|
160 | |||
164 | void AxisItem::setLabelsOpacity(qreal opacity) |
|
161 | void AxisItem::setLabelsOpacity(qreal opacity) | |
165 | { |
|
162 | { | |
166 | m_labels.setOpacity(opacity); |
|
163 | m_labels.setOpacity(opacity); | |
167 | } |
|
164 | } | |
168 |
|
165 | |||
169 | qreal AxisItem::labelsOpacity() const |
|
166 | qreal AxisItem::labelsOpacity() const | |
170 | { |
|
167 | { | |
171 | return m_labels.opacity(); |
|
168 | return m_labels.opacity(); | |
172 | } |
|
169 | } | |
173 |
|
170 | |||
174 | void AxisItem::setShadesOpacity(qreal opacity) |
|
171 | void AxisItem::setShadesOpacity(qreal opacity) | |
175 | { |
|
172 | { | |
176 | m_shades.setOpacity(opacity); |
|
173 | m_shades.setOpacity(opacity); | |
177 | } |
|
174 | } | |
178 |
|
175 | |||
179 | qreal AxisItem::shadesOpacity() const |
|
176 | qreal AxisItem::shadesOpacity() const | |
180 | { |
|
177 | { | |
181 | return m_shades.opacity(); |
|
178 | return m_shades.opacity(); | |
182 | } |
|
179 | } | |
183 |
|
180 | |||
184 | void AxisItem::setLabelsAngle(int angle) |
|
181 | void AxisItem::setLabelsAngle(int angle) | |
185 | { |
|
182 | { | |
186 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
183 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
187 | QPointF center = item->boundingRect().center(); |
|
184 | QPointF center = item->boundingRect().center(); | |
188 | item->setRotation(angle); |
|
185 | item->setRotation(angle); | |
189 | } |
|
186 | } | |
190 |
|
187 | |||
191 | m_labelsAngle=angle; |
|
188 | m_labelsAngle=angle; | |
192 | } |
|
189 | } | |
193 |
|
190 | |||
194 | void AxisItem::setLabelsPen(const QPen& pen) |
|
191 | void AxisItem::setLabelsPen(const QPen& pen) | |
195 | { |
|
192 | { | |
196 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
193 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
197 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
194 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
198 | } |
|
195 | } | |
199 | } |
|
196 | } | |
200 |
|
197 | |||
201 | void AxisItem::setLabelsBrush(const QBrush& brush) |
|
198 | void AxisItem::setLabelsBrush(const QBrush& brush) | |
202 | { |
|
199 | { | |
203 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
200 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
204 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
201 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
205 | } |
|
202 | } | |
206 | } |
|
203 | } | |
207 |
|
204 | |||
208 | void AxisItem::setLabelsFont(const QFont& font) |
|
205 | void AxisItem::setLabelsFont(const QFont& font) | |
209 | { |
|
206 | { | |
210 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
207 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
211 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
208 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
212 | } |
|
209 | } | |
213 | } |
|
210 | } | |
214 |
|
211 | |||
215 | void AxisItem::setShadesBrush(const QBrush& brush) |
|
212 | void AxisItem::setShadesBrush(const QBrush& brush) | |
216 | { |
|
213 | { | |
217 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
214 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
218 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
215 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
219 | } |
|
216 | } | |
220 | } |
|
217 | } | |
221 |
|
218 | |||
222 | void AxisItem::setShadesPen(const QPen& pen) |
|
219 | void AxisItem::setShadesPen(const QPen& pen) | |
223 | { |
|
220 | { | |
224 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
221 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
225 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
222 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
226 | } |
|
223 | } | |
227 | } |
|
224 | } | |
228 |
|
225 | |||
229 | void AxisItem::setAxisPen(const QPen& pen) |
|
226 | void AxisItem::setAxisPen(const QPen& pen) | |
230 | { |
|
227 | { | |
231 | foreach(QGraphicsItem* item , m_axis.childItems()) { |
|
228 | foreach(QGraphicsItem* item , m_axis.childItems()) { | |
232 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
229 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
233 | } |
|
230 | } | |
234 | } |
|
231 | } | |
235 |
|
232 | |||
236 | void AxisItem::setGridPen(const QPen& pen) |
|
233 | void AxisItem::setGridPen(const QPen& pen) | |
237 | { |
|
234 | { | |
238 | foreach(QGraphicsItem* item , m_grid.childItems()) { |
|
235 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |
239 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
236 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
240 | } |
|
237 | } | |
241 | } |
|
238 | } | |
242 |
|
239 | |||
243 | void AxisItem::calculateLayout(QVector<qreal>& points) |
|
240 | void AxisItem::calculateLayout(QVector<qreal>& points) | |
244 | { |
|
241 | { | |
245 | switch (m_type) |
|
242 | switch (m_type) | |
246 | { |
|
243 | { | |
247 | case X_AXIS: |
|
244 | case X_AXIS: | |
248 | { |
|
245 | { | |
249 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); |
|
246 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); | |
250 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
247 | for (int i = 0; i < m_thicksList.size(); ++i) { | |
251 | int x = i * deltaX + m_rect.left(); |
|
248 | int x = i * deltaX + m_rect.left(); | |
252 | points[i]=x; |
|
249 | points[i]=x; | |
253 | } |
|
250 | } | |
254 | } |
|
251 | } | |
255 | break; |
|
252 | break; | |
256 | case Y_AXIS: |
|
253 | case Y_AXIS: | |
257 | { |
|
254 | { | |
258 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); |
|
255 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); | |
259 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
256 | for (int i = 0; i < m_thicksList.size(); ++i) { | |
260 | int y = i * -deltaY + m_rect.bottom(); |
|
257 | int y = i * -deltaY + m_rect.bottom(); | |
261 | points[i]=y; |
|
258 | points[i]=y; | |
262 | } |
|
259 | } | |
263 | } |
|
260 | } | |
264 | break; |
|
261 | break; | |
265 | } |
|
262 | } | |
266 | } |
|
263 | } | |
267 |
|
264 | |||
268 | void AxisItem::applyLayout(const QVector<qreal>& points) |
|
265 | void AxisItem::applyLayout(const QVector<qreal>& points) | |
269 | { |
|
266 | { | |
270 | Q_ASSERT(points.size() == m_thicksList.size()); |
|
267 | Q_ASSERT(points.size() == m_thicksList.size()); | |
271 |
|
268 | |||
272 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
269 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
273 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
270 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
274 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
271 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
275 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
272 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
276 |
|
273 | |||
277 | Q_ASSERT(labels.size() == m_thicksList.size()); |
|
274 | Q_ASSERT(labels.size() == m_thicksList.size()); | |
278 |
|
275 | |||
279 | switch (m_type) |
|
276 | switch (m_type) | |
280 | { |
|
277 | { | |
281 | case X_AXIS: |
|
278 | case X_AXIS: | |
282 | { |
|
279 | { | |
283 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
280 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
284 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
281 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
285 |
|
282 | |||
286 | for (int i = 0; i < points.size(); ++i) { |
|
283 | for (int i = 0; i < points.size(); ++i) { | |
287 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
284 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
288 | lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom()); |
|
285 | lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom()); | |
289 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
286 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
290 | labelItem->setText(m_thicksList.at(i)); |
|
287 | labelItem->setText(m_thicksList.at(i)); | |
291 | QPointF center = labelItem->boundingRect().center(); |
|
288 | QPointF center = labelItem->boundingRect().center(); | |
292 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
289 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
293 | labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding); |
|
290 | labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding); | |
294 | if(i%2){ |
|
291 | if(i%2){ | |
295 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
292 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |
296 | rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height()); |
|
293 | rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height()); | |
297 | } |
|
294 | } | |
298 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
295 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
299 | lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5); |
|
296 | lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5); | |
300 | } |
|
297 | } | |
301 | } |
|
298 | } | |
302 | break; |
|
299 | break; | |
303 |
|
300 | |||
304 | case Y_AXIS: |
|
301 | case Y_AXIS: | |
305 | { |
|
302 | { | |
306 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
303 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
307 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
304 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
308 |
|
305 | |||
309 | for (int i = 0; i < points.size(); ++i) { |
|
306 | for (int i = 0; i < points.size(); ++i) { | |
310 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
307 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
311 | lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]); |
|
308 | lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]); | |
312 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
309 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
313 | labelItem->setText(m_thicksList.at(i)); |
|
310 | labelItem->setText(m_thicksList.at(i)); | |
314 | QPointF center = labelItem->boundingRect().center(); |
|
311 | QPointF center = labelItem->boundingRect().center(); | |
315 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
312 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
316 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y()); |
|
313 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y()); | |
317 | if(i%2){ |
|
314 | if(i%2){ | |
318 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
315 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |
319 | rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]); |
|
316 | rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]); | |
320 | } |
|
317 | } | |
321 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
318 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
322 | lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]); |
|
319 | lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]); | |
323 | } |
|
320 | } | |
324 | } |
|
321 | } | |
325 | break; |
|
322 | break; | |
326 | default: |
|
323 | default: | |
327 | qDebug()<<"Unknown axis type"; |
|
324 | qDebug()<<"Unknown axis type"; | |
328 | break; |
|
325 | break; | |
329 | } |
|
326 | } | |
330 | } |
|
327 | } | |
331 |
|
328 | |||
332 | //TODO "nice numbers algorithm" |
|
329 | //TODO "nice numbers algorithm" | |
333 | #include "moc_axisitem_p.cpp" |
|
330 | #include "moc_axisitem_p.cpp" | |
334 |
|
331 | |||
335 | QTCOMMERCIALCHART_END_NAMESPACE |
|
332 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,72 | |||||
1 | #ifndef BARPRESENTERBASE_H |
|
1 | #ifndef BARPRESENTERBASE_H | |
2 | #define BARPRESENTERBASE_H |
|
2 | #define BARPRESENTERBASE_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 | #include <QBrush> |
|
7 | #include <QBrush> | |
8 | #include <QGraphicsItem> |
|
8 | #include <QGraphicsItem> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class Bar; |
|
12 | class Bar; | |
13 | class BarLabel; |
|
13 | class BarLabel; | |
14 | class Separator; |
|
14 | class Separator; | |
15 | class BarValue; |
|
15 | class BarValue; | |
16 |
|
16 | |||
17 | // Common implemantation of different presenters. Not to be instantiated. |
|
17 | // Common implemantation of different presenters. Not to be instantiated. | |
18 | // TODO: combine this with BarPresenter and derive other presenters from it? |
|
18 | // TODO: combine this with BarPresenter and derive other presenters from it? | |
19 | class BarPresenterBase : public QObject, public ChartItem |
|
19 | class BarPresenterBase : public QObject, public ChartItem | |
20 | { |
|
20 | { | |
21 | Q_OBJECT |
|
21 | Q_OBJECT | |
22 | public: |
|
22 | public: | |
23 | BarPresenterBase(QBarSeries *series, QGraphicsItem *parent = 0); |
|
23 | BarPresenterBase(QBarSeries *series, QGraphicsItem *parent = 0); | |
24 | ~BarPresenterBase(); |
|
24 | ~BarPresenterBase(); | |
25 |
|
25 | |||
26 | public: |
|
26 | public: | |
27 | // From QGraphicsItem |
|
27 | // From QGraphicsItem | |
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
29 | QRectF boundingRect() const; |
|
29 | QRectF boundingRect() const; | |
30 |
|
30 | |||
31 | // TODO: these may change with layout awarness. |
|
31 | // TODO: these may change with layout awarness. | |
32 | void setBarWidth( int w ); |
|
32 | void setBarWidth( int w ); | |
33 |
|
33 | |||
34 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
34 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it | |
35 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
35 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
36 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes |
|
36 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes | |
37 |
|
37 | |||
38 |
p |
|
38 | public slots: | |
39 | void handleModelChanged(int index); |
|
39 | void handleModelChanged(int index); | |
40 | void handleDomainChanged(const Domain& domain); |
|
40 | void handleDomainChanged(const Domain& domain); | |
41 | void handleGeometryChanged(const QRectF& size); |
|
41 | void handleGeometryChanged(const QRectF& size); | |
42 |
|
42 | |||
43 | // Internal slots |
|
43 | // Internal slots | |
44 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
|
44 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) | |
45 | void enableSeparators(bool enabled); |
|
45 | void enableSeparators(bool enabled); | |
46 |
|
46 | |||
47 | protected: |
|
47 | protected: | |
48 |
|
48 | |||
49 | // TODO: consider these. |
|
49 | // TODO: consider these. | |
50 | int mHeight; // Layout spesific |
|
50 | int mHeight; // Layout spesific | |
51 | int mWidth; |
|
51 | int mWidth; | |
52 | int mBarDefaultWidth; |
|
52 | int mBarDefaultWidth; | |
53 |
|
53 | |||
54 | bool mLayoutSet; // True, if component has been laid out. |
|
54 | bool mLayoutSet; // True, if component has been laid out. | |
55 | bool mLayoutDirty; |
|
55 | bool mLayoutDirty; | |
56 |
|
56 | |||
57 | bool mSeparatorsEnabled; |
|
57 | bool mSeparatorsEnabled; | |
58 |
|
58 | |||
59 | // Owned |
|
59 | // Owned | |
60 | QBarSeries* mSeries; |
|
60 | QBarSeries* mSeries; | |
61 |
|
61 | |||
62 | // Not owned. |
|
62 | // Not owned. | |
63 | QList<Bar*> mBars; |
|
63 | QList<Bar*> mBars; | |
64 | QList<BarLabel*> mLabels; |
|
64 | QList<BarLabel*> mLabels; | |
65 | QList<Separator*> mSeparators; |
|
65 | QList<Separator*> mSeparators; | |
66 | QList<BarValue*> mFloatingValues; |
|
66 | QList<BarValue*> mFloatingValues; | |
67 |
|
67 | |||
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
71 | |||
72 | #endif // BARPRESENTERBASE_H |
|
72 | #endif // BARPRESENTERBASE_H |
@@ -1,359 +1,358 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlineseries.h" |
|
4 | #include "qlineseries.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qstackedbarseries.h" |
|
6 | #include "qstackedbarseries.h" | |
7 | #include "qpercentbarseries.h" |
|
7 | #include "qpercentbarseries.h" | |
8 | #include "qpieseries.h" |
|
8 | #include "qpieseries.h" | |
9 | #include "qscatterseries.h" |
|
9 | #include "qscatterseries.h" | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
14 | m_axisX(new QChartAxis(this)), |
|
14 | m_axisX(new QChartAxis(this)), | |
15 | m_axisY(new QChartAxis(this)), |
|
15 | m_axisY(new QChartAxis(this)), | |
16 | m_domainIndex(0), |
|
16 | m_domainIndex(0), | |
17 | m_axisXInitialized(false) |
|
17 | m_axisXInitialized(false) | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | ChartDataSet::~ChartDataSet() |
|
21 | ChartDataSet::~ChartDataSet() | |
22 | { |
|
22 | { | |
23 | // TODO Auto-generated destructor stub |
|
23 | // TODO Auto-generated destructor stub | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const |
|
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const | |
27 | { |
|
27 | { | |
28 | int i = m_domainMap.count(axisY); |
|
28 | int i = m_domainMap.count(axisY); | |
29 | if(i == 0){ |
|
29 | if(i == 0){ | |
30 | return Domain(); |
|
30 | return Domain(); | |
31 | } |
|
31 | } | |
32 | i = i - m_domainIndex -1; |
|
32 | i = i - m_domainIndex -1; | |
33 | return m_domainMap.values(axisY).at(i); |
|
33 | return m_domainMap.values(axisY).at(i); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
37 | { |
|
37 | { | |
38 | // TODO: we should check the series not already added |
|
38 | // TODO: we should check the series not already added | |
39 |
|
39 | |||
40 | series->setParent(this); // take ownership |
|
40 | series->setParent(this); // take ownership | |
41 | clearDomains(); |
|
41 | clearDomains(); | |
42 |
|
42 | |||
43 | if(axisY==0) axisY = m_axisY; |
|
43 | if(axisY==0) axisY = m_axisY; | |
44 | axisY->setParent(this); // take ownership |
|
44 | axisY->setParent(this); // take ownership | |
45 |
|
45 | |||
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); |
|
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); | |
47 |
|
47 | |||
48 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
48 | QList<Domain> domainList = m_domainMap.values(axisY); | |
49 |
|
49 | |||
50 | Q_ASSERT(domainList.size()<=1); |
|
50 | Q_ASSERT(domainList.size()<=1); | |
51 |
|
51 | |||
52 | Domain domain; |
|
52 | Domain domain; | |
53 |
|
53 | |||
54 | if(domainList.size()>0) domain = domainList.at(0); |
|
54 | if(domainList.size()>0) domain = domainList.at(0); | |
55 |
|
55 | |||
56 | switch(series->type()) |
|
56 | switch(series->type()) | |
57 | { |
|
57 | { | |
58 | case QSeries::SeriesTypeLine: { |
|
58 | case QSeries::SeriesTypeLine: { | |
59 |
|
59 | |||
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); |
|
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); | |
61 |
|
61 | |||
62 | for (int i = 0; i < xyseries->count(); i++) |
|
62 | for (int i = 0; i < xyseries->count(); i++) | |
63 | { |
|
63 | { | |
64 | qreal x = xyseries->x(i); |
|
64 | qreal x = xyseries->x(i); | |
65 | qreal y = xyseries->y(i); |
|
65 | qreal y = xyseries->y(i); | |
66 | domain.m_minX = qMin(domain.m_minX,x); |
|
66 | domain.m_minX = qMin(domain.m_minX,x); | |
67 | domain.m_minY = qMin(domain.m_minY,y); |
|
67 | domain.m_minY = qMin(domain.m_minY,y); | |
68 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
68 | domain.m_maxX = qMax(domain.m_maxX,x); | |
69 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
69 | domain.m_maxY = qMax(domain.m_maxY,y); | |
70 | } |
|
70 | } | |
71 | break; |
|
71 | break; | |
72 | } |
|
72 | } | |
73 | case QSeries::SeriesTypeBar: { |
|
73 | case QSeries::SeriesTypeBar: { | |
74 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
74 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
76 | qreal x = barSeries->categoryCount(); |
|
76 | qreal x = barSeries->categoryCount(); | |
77 | qreal y = barSeries->max(); |
|
77 | qreal y = barSeries->max(); | |
78 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
79 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
80 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |
81 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
81 | domain.m_maxY = qMax(domain.m_maxY,y); | |
82 | break; |
|
82 | break; | |
83 | } |
|
83 | } | |
84 | case QSeries::SeriesTypeStackedBar: { |
|
84 | case QSeries::SeriesTypeStackedBar: { | |
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
86 |
|
86 | |||
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
88 | qreal x = stackedBarSeries->categoryCount(); |
|
88 | qreal x = stackedBarSeries->categoryCount(); | |
89 | qreal y = stackedBarSeries->maxCategorySum(); |
|
89 | qreal y = stackedBarSeries->maxCategorySum(); | |
90 | domain.m_minX = qMin(domain.m_minX,x); |
|
90 | domain.m_minX = qMin(domain.m_minX,x); | |
91 | domain.m_minY = qMin(domain.m_minY,y); |
|
91 | domain.m_minY = qMin(domain.m_minY,y); | |
92 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
92 | domain.m_maxX = qMax(domain.m_maxX,x); | |
93 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
93 | domain.m_maxY = qMax(domain.m_maxY,y); | |
94 | break; |
|
94 | break; | |
95 | } |
|
95 | } | |
96 | case QSeries::SeriesTypePercentBar: { |
|
96 | case QSeries::SeriesTypePercentBar: { | |
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
98 |
|
98 | |||
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
100 | qreal x = percentBarSeries->categoryCount(); |
|
100 | qreal x = percentBarSeries->categoryCount(); | |
101 | domain.m_minX = qMin(domain.m_minX,x); |
|
101 | domain.m_minX = qMin(domain.m_minX,x); | |
102 | domain.m_minY = 0; |
|
102 | domain.m_minY = 0; | |
103 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
103 | domain.m_maxX = qMax(domain.m_maxX,x); | |
104 | domain.m_maxY = 100; |
|
104 | domain.m_maxY = 100; | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | case QSeries::SeriesTypePie: { |
|
108 | case QSeries::SeriesTypePie: { | |
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
110 | // TODO: domain stuff |
|
110 | // TODO: domain stuff | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | case QSeries::SeriesTypeScatter: { |
|
114 | case QSeries::SeriesTypeScatter: { | |
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
116 | Q_ASSERT(scatterSeries); |
|
116 | Q_ASSERT(scatterSeries); | |
117 | foreach (QPointF point, scatterSeries->data()) { |
|
117 | foreach (QPointF point, scatterSeries->data()) { | |
118 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
118 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
120 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
120 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
122 | } |
|
122 | } | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | default: { |
|
126 | default: { | |
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
128 | return; |
|
128 | return; | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | if(!m_domainMap.contains(axisY)) |
|
134 | if(!m_domainMap.contains(axisY)) | |
135 | { |
|
135 | { | |
136 | emit axisAdded(axisY); |
|
136 | emit axisAdded(axisY); | |
137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
140 | } |
|
140 | } | |
141 | m_domainMap.replace(axisY,domain); |
|
141 | m_domainMap.replace(axisY,domain); | |
142 | m_seriesMap.insert(axisY,series); |
|
142 | m_seriesMap.insert(axisY,series); | |
143 |
|
143 | |||
144 | if(!m_axisXInitialized) |
|
144 | if(!m_axisXInitialized) | |
145 | { |
|
145 | { | |
146 | emit axisAdded(axisX()); |
|
146 | emit axisAdded(axisX()); | |
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
150 | m_axisXInitialized=true; |
|
150 | m_axisXInitialized=true; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 |
|
||||
154 | emit seriesAdded(series); |
|
|||
155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
153 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); | |
156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
154 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
157 | emit axisLabelsChanged(axisY,ylabels); |
|
155 | emit axisLabelsChanged(axisY,ylabels); | |
158 | emit axisLabelsChanged(axisX(),xlabels); |
|
156 | emit axisLabelsChanged(axisX(),xlabels); | |
|
157 | emit seriesAdded(series); | |||
159 | emit seriesDomainChanged(series,domain); |
|
158 | emit seriesDomainChanged(series,domain); | |
160 |
|
159 | |||
161 | } |
|
160 | } | |
162 |
|
161 | |||
163 | void ChartDataSet::removeSeries(QSeries* series) |
|
162 | void ChartDataSet::removeSeries(QSeries* series) | |
164 | { |
|
163 | { | |
165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
164 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
166 | foreach(QChartAxis* axis , keys) { |
|
165 | foreach(QChartAxis* axis , keys) { | |
167 | if(m_seriesMap.contains(axis,series)){ |
|
166 | if(m_seriesMap.contains(axis,series)){ | |
168 | emit seriesRemoved(series); |
|
167 | emit seriesRemoved(series); | |
169 | m_seriesMap.remove(axis,series); |
|
168 | m_seriesMap.remove(axis,series); | |
170 | //remove axis if no longer there |
|
169 | //remove axis if no longer there | |
171 | if(!m_seriesMap.contains(axis)){ |
|
170 | if(!m_seriesMap.contains(axis)){ | |
172 | emit axisRemoved(axis); |
|
171 | emit axisRemoved(axis); | |
173 | m_domainMap.remove(axis); |
|
172 | m_domainMap.remove(axis); | |
174 | if(axis != m_axisY) |
|
173 | if(axis != m_axisY) | |
175 | delete axis; |
|
174 | delete axis; | |
176 | } |
|
175 | } | |
177 | series->setParent(0); |
|
176 | series->setParent(0); | |
178 | break; |
|
177 | break; | |
179 | } |
|
178 | } | |
180 | } |
|
179 | } | |
181 | } |
|
180 | } | |
182 |
|
181 | |||
183 | void ChartDataSet::removeAllSeries() |
|
182 | void ChartDataSet::removeAllSeries() | |
184 | { |
|
183 | { | |
185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
184 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
186 | foreach(QChartAxis* axis , keys) { |
|
185 | foreach(QChartAxis* axis , keys) { | |
187 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
186 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
188 | for(int i =0 ; i < seriesList.size();i++ ) |
|
187 | for(int i =0 ; i < seriesList.size();i++ ) | |
189 | { |
|
188 | { | |
190 | emit seriesRemoved(seriesList.at(i)); |
|
189 | emit seriesRemoved(seriesList.at(i)); | |
191 | delete(seriesList.at(i)); |
|
190 | delete(seriesList.at(i)); | |
192 | } |
|
191 | } | |
193 | m_seriesMap.remove(axis); |
|
192 | m_seriesMap.remove(axis); | |
194 | m_domainMap.remove(axis); |
|
193 | m_domainMap.remove(axis); | |
195 | emit axisRemoved(axis); |
|
194 | emit axisRemoved(axis); | |
196 | if(axis != m_axisY) delete axis; |
|
195 | if(axis != m_axisY) delete axis; | |
197 | } |
|
196 | } | |
198 | m_domainIndex=0; |
|
197 | m_domainIndex=0; | |
199 | } |
|
198 | } | |
200 |
|
199 | |||
201 | bool ChartDataSet::nextDomain() |
|
200 | bool ChartDataSet::nextDomain() | |
202 | { |
|
201 | { | |
203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
202 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
204 |
|
203 | |||
205 | if (m_domainIndex < limit) { |
|
204 | if (m_domainIndex < limit) { | |
206 | m_domainIndex++; |
|
205 | m_domainIndex++; | |
207 | setDomain(m_domainIndex); |
|
206 | setDomain(m_domainIndex); | |
208 | return true; |
|
207 | return true; | |
209 | } |
|
208 | } | |
210 | else { |
|
209 | else { | |
211 | return false; |
|
210 | return false; | |
212 | } |
|
211 | } | |
213 | } |
|
212 | } | |
214 |
|
213 | |||
215 | bool ChartDataSet::previousDomain() |
|
214 | bool ChartDataSet::previousDomain() | |
216 | { |
|
215 | { | |
217 | if (m_domainIndex > 0) { |
|
216 | if (m_domainIndex > 0) { | |
218 | m_domainIndex--; |
|
217 | m_domainIndex--; | |
219 | setDomain(m_domainIndex); |
|
218 | setDomain(m_domainIndex); | |
220 | return true; |
|
219 | return true; | |
221 | } |
|
220 | } | |
222 | else { |
|
221 | else { | |
223 | return false; |
|
222 | return false; | |
224 | } |
|
223 | } | |
225 | } |
|
224 | } | |
226 |
|
225 | |||
227 | void ChartDataSet::setDomain(int index) |
|
226 | void ChartDataSet::setDomain(int index) | |
228 | { |
|
227 | { | |
229 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
228 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
230 |
|
229 | |||
231 | if(domainList.count()==0) return; |
|
230 | if(domainList.count()==0) return; | |
232 |
|
231 | |||
233 | Domain domain; |
|
232 | Domain domain; | |
234 |
|
233 | |||
235 | foreach (QChartAxis* axis , domainList) { |
|
234 | foreach (QChartAxis* axis , domainList) { | |
236 | int i = m_domainMap.count(axis) - index -1; |
|
235 | int i = m_domainMap.count(axis) - index -1; | |
237 | Q_ASSERT(i>=0); |
|
236 | Q_ASSERT(i>=0); | |
238 | domain = m_domainMap.values(axis).at(i); |
|
237 | domain = m_domainMap.values(axis).at(i); | |
239 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
238 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
240 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
239 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
241 | foreach(QSeries* series, seriesList) { |
|
240 | foreach(QSeries* series, seriesList) { | |
242 | emit seriesDomainChanged(series,domain); |
|
241 | emit seriesDomainChanged(series,domain); | |
243 | } |
|
242 | } | |
244 | emit axisLabelsChanged(axis,labels); |
|
243 | emit axisLabelsChanged(axis,labels); | |
245 | } |
|
244 | } | |
246 |
|
245 | |||
247 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
246 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
248 | emit axisLabelsChanged(axisX(),labels); |
|
247 | emit axisLabelsChanged(axisX(),labels); | |
249 | } |
|
248 | } | |
250 |
|
249 | |||
251 | void ChartDataSet::clearDomains(int toIndex) |
|
250 | void ChartDataSet::clearDomains(int toIndex) | |
252 | { |
|
251 | { | |
253 | Q_ASSERT(toIndex>=0); |
|
252 | Q_ASSERT(toIndex>=0); | |
254 |
|
253 | |||
255 | m_domainIndex = toIndex; |
|
254 | m_domainIndex = toIndex; | |
256 |
|
255 | |||
257 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
256 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
258 |
|
257 | |||
259 | foreach (QChartAxis* key , keys) |
|
258 | foreach (QChartAxis* key , keys) | |
260 | { |
|
259 | { | |
261 | QList<Domain> domains = m_domainMap.values(key); |
|
260 | QList<Domain> domains = m_domainMap.values(key); | |
262 | m_domainMap.remove(key); |
|
261 | m_domainMap.remove(key); | |
263 | int i = domains.size() - toIndex - 1; |
|
262 | int i = domains.size() - toIndex - 1; | |
264 | while(i--){ |
|
263 | while(i--){ | |
265 | domains.removeFirst(); |
|
264 | domains.removeFirst(); | |
266 | } |
|
265 | } | |
267 | for(int j=domains.size()-1; j>=0 ;j--) |
|
266 | for(int j=domains.size()-1; j>=0 ;j--) | |
268 | m_domainMap.insert(key,domains.at(j)); |
|
267 | m_domainMap.insert(key,domains.at(j)); | |
269 | } |
|
268 | } | |
270 | } |
|
269 | } | |
271 |
|
270 | |||
272 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
271 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
273 | { |
|
272 | { | |
274 | Q_ASSERT(rect.isValid()); |
|
273 | Q_ASSERT(rect.isValid()); | |
275 | Q_ASSERT(viewport.isValid()); |
|
274 | Q_ASSERT(viewport.isValid()); | |
276 |
|
275 | |||
277 | clearDomains(m_domainIndex); |
|
276 | clearDomains(m_domainIndex); | |
278 |
|
277 | |||
279 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
278 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
280 |
|
279 | |||
281 | Domain domain; |
|
280 | Domain domain; | |
282 |
|
281 | |||
283 | foreach (QChartAxis* axis , domainList){ |
|
282 | foreach (QChartAxis* axis , domainList){ | |
284 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
283 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
285 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
284 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
286 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
285 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
287 | foreach(QSeries* series, seriesList){ |
|
286 | foreach(QSeries* series, seriesList){ | |
288 | emit seriesDomainChanged(series,domain); |
|
287 | emit seriesDomainChanged(series,domain); | |
289 | } |
|
288 | } | |
290 | emit axisLabelsChanged(axis,labels); |
|
289 | emit axisLabelsChanged(axis,labels); | |
291 | m_domainMap.insert(axis,domain); |
|
290 | m_domainMap.insert(axis,domain); | |
292 | } |
|
291 | } | |
293 |
|
292 | |||
294 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
293 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
295 | emit axisLabelsChanged(axisX(),labels); |
|
294 | emit axisLabelsChanged(axisX(),labels); | |
296 |
|
295 | |||
297 | m_domainIndex++; |
|
296 | m_domainIndex++; | |
298 | } |
|
297 | } | |
299 |
|
298 | |||
300 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
299 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
301 | { |
|
300 | { | |
302 | if(series == 0) return m_axisY; |
|
301 | if(series == 0) return m_axisY; | |
303 |
|
302 | |||
304 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
303 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
305 |
|
304 | |||
306 | foreach(QChartAxis* axis , keys) { |
|
305 | foreach(QChartAxis* axis , keys) { | |
307 | if(m_seriesMap.contains(axis,series)){ |
|
306 | if(m_seriesMap.contains(axis,series)){ | |
308 | return axis; |
|
307 | return axis; | |
309 | } |
|
308 | } | |
310 | } |
|
309 | } | |
311 | return 0; |
|
310 | return 0; | |
312 | } |
|
311 | } | |
313 |
|
312 | |||
314 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
313 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
315 | { |
|
314 | { | |
316 | Q_ASSERT(max>=min); |
|
315 | Q_ASSERT(max>=min); | |
317 |
|
316 | |||
318 | QStringList labels; |
|
317 | QStringList labels; | |
319 |
|
318 | |||
320 | int ticks = axis->ticksCount()-1; |
|
319 | int ticks = axis->ticksCount()-1; | |
321 |
|
320 | |||
322 | for(int i=0; i<= ticks; i++){ |
|
321 | for(int i=0; i<= ticks; i++){ | |
323 | qreal value = min + (i * (max - min)/ ticks); |
|
322 | qreal value = min + (i * (max - min)/ ticks); | |
324 | QString label = axis->axisTickLabel(value); |
|
323 | QString label = axis->axisTickLabel(value); | |
325 | if(label.isEmpty()){ |
|
324 | if(label.isEmpty()){ | |
326 | labels << QString::number(value); |
|
325 | labels << QString::number(value); | |
327 | }else{ |
|
326 | }else{ | |
328 | labels << label; |
|
327 | labels << label; | |
329 | } |
|
328 | } | |
330 | } |
|
329 | } | |
331 | return labels; |
|
330 | return labels; | |
332 | } |
|
331 | } | |
333 |
|
332 | |||
334 |
|
333 | |||
335 | void ChartDataSet::handleMinChanged(qreal min) |
|
334 | void ChartDataSet::handleMinChanged(qreal min) | |
336 | { |
|
335 | { | |
337 |
|
336 | |||
338 | } |
|
337 | } | |
339 |
|
338 | |||
340 | void ChartDataSet::handleMaxChanged(qreal max) |
|
339 | void ChartDataSet::handleMaxChanged(qreal max) | |
341 | { |
|
340 | { | |
342 |
|
341 | |||
343 | } |
|
342 | } | |
344 |
|
343 | |||
345 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
344 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
346 | { |
|
345 | { | |
347 | Domain domain = m_domainMap.value(axisY()); |
|
346 | Domain domain = m_domainMap.value(axisY()); | |
348 | if(axis==axisX()){ |
|
347 | if(axis==axisX()){ | |
349 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
348 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
350 | emit axisLabelsChanged(axis,labels); |
|
349 | emit axisLabelsChanged(axis,labels); | |
351 | }else{ |
|
350 | }else{ | |
352 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
351 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
353 | emit axisLabelsChanged(axis,labels); |
|
352 | emit axisLabelsChanged(axis,labels); | |
354 | } |
|
353 | } | |
355 | } |
|
354 | } | |
356 |
|
355 | |||
357 | #include "moc_chartdataset_p.cpp" |
|
356 | #include "moc_chartdataset_p.cpp" | |
358 |
|
357 | |||
359 | QTCOMMERCIALCHART_END_NAMESPACE |
|
358 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,283 +1,284 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "qbarseries.h" |
|
7 | #include "qbarseries.h" | |
8 | #include "qstackedbarseries.h" |
|
8 | #include "qstackedbarseries.h" | |
9 | #include "qpercentbarseries.h" |
|
9 | #include "qpercentbarseries.h" | |
10 | #include "qlineseries.h" |
|
10 | #include "qlineseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 | #include "axisanimationitem_p.h" |
|
15 | #include "axisanimationitem_p.h" | |
16 | #include "barpresenter_p.h" |
|
16 | #include "barpresenter_p.h" | |
17 | #include "stackedbarpresenter_p.h" |
|
17 | #include "stackedbarpresenter_p.h" | |
18 | #include "percentbarpresenter_p.h" |
|
18 | #include "percentbarpresenter_p.h" | |
19 | #include "linechartitem_p.h" |
|
19 | #include "linechartitem_p.h" | |
20 | #include "linechartanimationitem_p.h" |
|
20 | #include "linechartanimationitem_p.h" | |
21 | #include "piepresenter_p.h" |
|
21 | #include "piepresenter_p.h" | |
22 | #include "scatterpresenter_p.h" |
|
22 | #include "scatterpresenter_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
27 | m_chart(chart), |
|
27 | m_chart(chart), | |
28 | m_dataset(dataset), |
|
28 | m_dataset(dataset), | |
29 | m_chartTheme(0), |
|
29 | m_chartTheme(0), | |
30 | m_marginSize(0), |
|
30 | m_marginSize(0), | |
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
32 | m_options(0) |
|
32 | m_options(0) | |
33 | { |
|
33 | { | |
34 | createConnections(); |
|
34 | createConnections(); | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); | |
47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); | |
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); | |
51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); |
|
51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | QRectF ChartPresenter::geometry() const |
|
55 | QRectF ChartPresenter::geometry() const | |
56 | { |
|
56 | { | |
57 | return m_rect; |
|
57 | return m_rect; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void ChartPresenter::handleGeometryChanged() |
|
60 | void ChartPresenter::handleGeometryChanged() | |
61 | { |
|
61 | { | |
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
64 | Q_ASSERT(m_rect.isValid()); |
|
64 | Q_ASSERT(m_rect.isValid()); | |
65 | emit geometryChanged(m_rect); |
|
65 | emit geometryChanged(m_rect); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | int ChartPresenter::margin() const |
|
68 | int ChartPresenter::margin() const | |
69 | { |
|
69 | { | |
70 | return m_marginSize; |
|
70 | return m_marginSize; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartPresenter::setMargin(int margin) |
|
73 | void ChartPresenter::setMargin(int margin) | |
74 | { |
|
74 | { | |
75 | m_marginSize = margin; |
|
75 | m_marginSize = margin; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | AxisItem* item ; |
|
81 | AxisItem* item ; | |
82 |
|
82 | |||
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
84 | { |
|
84 | { | |
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
86 | }else{ |
|
86 | }else{ | |
87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); | |
92 |
|
92 | |||
93 | item->handleAxisUpdate(axis); |
|
93 | item->handleAxisUpdate(axis); | |
94 | item->handleGeometryChanged(m_rect); |
|
94 | item->handleGeometryChanged(m_rect); | |
95 | m_chartTheme->decorate(axis,item); |
|
95 | m_chartTheme->decorate(axis,item); | |
96 | m_axisItems.insert(axis,item); |
|
96 | m_axisItems.insert(axis,item); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
100 | { |
|
100 | { | |
101 | AxisItem* item = m_axisItems.take(axis); |
|
101 | AxisItem* item = m_axisItems.take(axis); | |
102 | Q_ASSERT(item); |
|
102 | Q_ASSERT(item); | |
103 | delete item; |
|
103 | delete item; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | void ChartPresenter::handleSeriesAdded(QSeries* series) |
|
107 | void ChartPresenter::handleSeriesAdded(QSeries* series) | |
108 | { |
|
108 | { | |
109 | switch(series->type()) |
|
109 | switch(series->type()) | |
110 | { |
|
110 | { | |
111 | case QSeries::SeriesTypeLine: { |
|
111 | case QSeries::SeriesTypeLine: { | |
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
113 | LineChartItem* item; |
|
113 | LineChartItem* item; | |
114 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
114 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
116 | }else{ |
|
116 | }else{ | |
117 | item = new LineChartItem(this,lineSeries,m_chart); |
|
117 | item = new LineChartItem(this,lineSeries,m_chart); | |
118 | } |
|
118 | } | |
119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
121 |
QObject::connect(lineSeries,SIGNAL(point |
|
121 | QObject::connect(lineSeries,SIGNAL(pointReplaced(int)),item,SLOT(handlePointReplaced(int))); | |
|
122 | QObject::connect(lineSeries,SIGNAL(pointAdded(int)),item,SLOT(handlePointAdded(int))); | |||
|
123 | QObject::connect(lineSeries,SIGNAL(pointRemoved(int)),item,SLOT(handlePointRemoved(int))); | |||
122 | m_chartItems.insert(series,item); |
|
124 | m_chartItems.insert(series,item); | |
|
125 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |||
123 | break; |
|
126 | break; | |
124 | } |
|
127 | } | |
125 |
|
128 | |||
126 | case QSeries::SeriesTypeBar: { |
|
129 | case QSeries::SeriesTypeBar: { | |
127 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
130 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
128 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
131 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
129 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
132 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
130 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
133 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
131 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
134 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
132 | m_chartItems.insert(series,item); |
|
135 | m_chartItems.insert(series,item); | |
133 | // m_axisXItem->setVisible(false); |
|
136 | // m_axisXItem->setVisible(false); | |
|
137 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |||
134 | break; |
|
138 | break; | |
135 | } |
|
139 | } | |
136 |
|
140 | |||
137 | case QSeries::SeriesTypeStackedBar: { |
|
141 | case QSeries::SeriesTypeStackedBar: { | |
138 |
|
142 | |||
139 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
143 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
140 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
144 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
141 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
145 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
142 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
146 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
143 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
147 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
144 | m_chartItems.insert(series,item); |
|
148 | m_chartItems.insert(series,item); | |
|
149 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |||
145 | break; |
|
150 | break; | |
146 | } |
|
151 | } | |
147 |
|
152 | |||
148 | case QSeries::SeriesTypePercentBar: { |
|
153 | case QSeries::SeriesTypePercentBar: { | |
149 |
|
154 | |||
150 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
155 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
151 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
156 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
152 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
157 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
153 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
158 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
154 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
159 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
155 | m_chartItems.insert(series,item); |
|
160 | m_chartItems.insert(series,item); | |
|
161 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |||
156 | break; |
|
162 | break; | |
157 | } |
|
163 | } | |
158 | case QSeries::SeriesTypeScatter: { |
|
164 | case QSeries::SeriesTypeScatter: { | |
159 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
165 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
160 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
166 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
161 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); |
|
167 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); | |
162 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
168 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
163 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
169 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
164 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
170 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
165 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
171 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
|
172 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); | |||
166 | break; |
|
173 | break; | |
167 | } |
|
174 | } | |
168 | case QSeries::SeriesTypePie: { |
|
175 | case QSeries::SeriesTypePie: { | |
169 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
176 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
170 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
177 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
171 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
178 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
172 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
179 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
173 |
|
180 | |||
174 | // Hide all from background when there is only piechart |
|
181 | // Hide all from background when there is only piechart | |
175 | // TODO: refactor this ugly code... should be one setting for this |
|
182 | // TODO: refactor this ugly code... should be one setting for this | |
176 | if (m_chartItems.count() == 0) { |
|
183 | if (m_chartItems.count() == 0) { | |
177 | m_chart->axisX()->setAxisVisible(false); |
|
184 | m_chart->axisX()->setAxisVisible(false); | |
178 | m_chart->axisY()->setAxisVisible(false); |
|
185 | m_chart->axisY()->setAxisVisible(false); | |
179 | m_chart->axisX()->setGridVisible(false); |
|
186 | m_chart->axisX()->setGridVisible(false); | |
180 | m_chart->axisY()->setGridVisible(false); |
|
187 | m_chart->axisY()->setGridVisible(false); | |
181 | m_chart->axisX()->setLabelsVisible(false); |
|
188 | m_chart->axisX()->setLabelsVisible(false); | |
182 | m_chart->axisY()->setLabelsVisible(false); |
|
189 | m_chart->axisY()->setLabelsVisible(false); | |
183 | m_chart->axisX()->setShadesVisible(false); |
|
190 | m_chart->axisX()->setShadesVisible(false); | |
184 | m_chart->axisY()->setShadesVisible(false); |
|
191 | m_chart->axisY()->setShadesVisible(false); | |
185 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
192 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
186 | } |
|
193 | } | |
187 |
|
194 | |||
188 | m_chartItems.insert(series, pie); |
|
195 | m_chartItems.insert(series, pie); | |
|
196 | pie->handleGeometryChanged(m_rect); | |||
189 | break; |
|
197 | break; | |
190 | } |
|
198 | } | |
191 | default: { |
|
199 | default: { | |
192 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
200 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
193 | break; |
|
201 | break; | |
194 | } |
|
202 | } | |
195 | } |
|
203 | } | |
196 |
|
||||
197 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
|||
198 | } |
|
204 | } | |
199 |
|
205 | |||
200 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
206 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
201 | { |
|
207 | { | |
202 | ChartItem* item = m_chartItems.take(series); |
|
208 | ChartItem* item = m_chartItems.take(series); | |
203 | delete item; |
|
209 | delete item; | |
204 | } |
|
210 | } | |
205 |
|
211 | |||
206 | void ChartPresenter::handleSeriesChanged(QSeries* series) |
|
|||
207 | { |
|
|||
208 | //TODO: |
|
|||
209 | } |
|
|||
210 |
|
||||
211 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) |
|
212 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) | |
212 | { |
|
213 | { | |
213 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
214 | m_chartItems.value(series)->handleDomainChanged(domain); | |
214 | } |
|
215 | } | |
215 |
|
216 | |||
216 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
217 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
217 | { |
|
218 | { | |
218 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); |
|
219 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); | |
219 | } |
|
220 | } | |
220 |
|
221 | |||
221 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
222 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
222 | { |
|
223 | { | |
223 | delete m_chartTheme; |
|
224 | delete m_chartTheme; | |
224 |
|
225 | |||
225 | m_chartTheme = ChartTheme::createTheme(theme); |
|
226 | m_chartTheme = ChartTheme::createTheme(theme); | |
226 |
|
227 | |||
227 | m_chartTheme->decorate(m_chart); |
|
228 | m_chartTheme->decorate(m_chart); | |
228 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); |
|
229 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); | |
229 |
|
230 | |||
230 | int index=0; |
|
231 | int index=0; | |
231 | while (i.hasNext()) { |
|
232 | while (i.hasNext()) { | |
232 | i.next(); |
|
233 | i.next(); | |
233 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
234 | m_chartTheme->decorate(i.value(),i.key(),index); | |
234 | index++; |
|
235 | index++; | |
235 | } |
|
236 | } | |
236 |
|
237 | |||
237 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
238 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
238 | while (j.hasNext()) { |
|
239 | while (j.hasNext()) { | |
239 | j.next(); |
|
240 | j.next(); | |
240 | m_chartTheme->decorate(j.key(),j.value()); |
|
241 | m_chartTheme->decorate(j.key(),j.value()); | |
241 | } |
|
242 | } | |
242 | } |
|
243 | } | |
243 |
|
244 | |||
244 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
245 | QChart::ChartTheme ChartPresenter::chartTheme() | |
245 | { |
|
246 | { | |
246 | return m_chartTheme->id(); |
|
247 | return m_chartTheme->id(); | |
247 | } |
|
248 | } | |
248 |
|
249 | |||
249 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
250 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
250 | { |
|
251 | { | |
251 | if(m_options!=options) { |
|
252 | if(m_options!=options) { | |
252 |
|
253 | |||
253 | m_options=options; |
|
254 | m_options=options; | |
254 |
|
255 | |||
255 | //recreate elements |
|
256 | //recreate elements | |
256 |
|
257 | |||
257 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
258 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
258 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
259 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
259 |
|
260 | |||
260 | foreach(QChartAxis* axis, axisList) { |
|
261 | foreach(QChartAxis* axis, axisList) { | |
261 | handleAxisRemoved(axis); |
|
262 | handleAxisRemoved(axis); | |
262 | handleAxisAdded(axis); |
|
263 | handleAxisAdded(axis); | |
263 | } |
|
264 | } | |
264 | foreach(QSeries* series, seriesList) { |
|
265 | foreach(QSeries* series, seriesList) { | |
265 | handleSeriesRemoved(series); |
|
266 | handleSeriesRemoved(series); | |
266 | handleSeriesAdded(series); |
|
267 | handleSeriesAdded(series); | |
267 | } |
|
268 | } | |
268 |
|
269 | |||
269 | //now reintialize view data |
|
270 | //now reintialize view data | |
270 | //TODO: make it more nice |
|
271 | //TODO: make it more nice | |
271 | m_dataset->setDomain(m_dataset->domainIndex()); |
|
272 | m_dataset->setDomain(m_dataset->domainIndex()); | |
272 | } |
|
273 | } | |
273 | } |
|
274 | } | |
274 |
|
275 | |||
275 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
276 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
276 | { |
|
277 | { | |
277 | return m_options; |
|
278 | return m_options; | |
278 | } |
|
279 | } | |
279 |
|
280 | |||
280 |
|
281 | |||
281 | #include "moc_chartpresenter_p.cpp" |
|
282 | #include "moc_chartpresenter_p.cpp" | |
282 |
|
283 | |||
283 | QTCOMMERCIALCHART_END_NAMESPACE |
|
284 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,73 | |||||
1 | #ifndef CHARTPRESENTER_H_ |
|
1 | #ifndef CHARTPRESENTER_H_ | |
2 | #define CHARTPRESENTER_H_ |
|
2 | #define CHARTPRESENTER_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
6 | #include "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
7 | #include <QRectF> |
|
7 | #include <QRectF> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class ChartItem; |
|
11 | class ChartItem; | |
12 | class QSeries; |
|
12 | class QSeries; | |
13 | class ChartDataSet; |
|
13 | class ChartDataSet; | |
14 | //class QChart; |
|
14 | //class QChart; | |
15 | class Domain; |
|
15 | class Domain; | |
16 | class AxisItem; |
|
16 | class AxisItem; | |
17 | class ChartTheme; |
|
17 | class ChartTheme; | |
18 |
|
18 | |||
19 | class ChartPresenter: public QObject |
|
19 | class ChartPresenter: public QObject | |
20 | { |
|
20 | { | |
21 | Q_OBJECT |
|
21 | Q_OBJECT | |
22 | public: |
|
22 | public: | |
23 | enum ZValues { |
|
23 | enum ZValues { | |
24 | BackgroundZValue = -1, |
|
24 | BackgroundZValue = -1, | |
25 | ShadesZValue, |
|
25 | ShadesZValue, | |
26 | GridZValue, |
|
26 | GridZValue, | |
27 | AxisZValue, |
|
27 | AxisZValue, | |
28 | LineChartZValue, |
|
28 | LineChartZValue, | |
29 | ScatterSeriesZValue |
|
29 | ScatterSeriesZValue | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
32 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
33 | virtual ~ChartPresenter(); |
|
33 | virtual ~ChartPresenter(); | |
34 |
|
34 | |||
35 | void setMargin(int margin); |
|
35 | void setMargin(int margin); | |
36 | int margin() const; |
|
36 | int margin() const; | |
37 |
|
37 | |||
38 | QRectF geometry() const; |
|
38 | QRectF geometry() const; | |
39 |
|
39 | |||
40 | void setChartTheme(QChart::ChartTheme theme); |
|
40 | void setChartTheme(QChart::ChartTheme theme); | |
41 | QChart::ChartTheme chartTheme(); |
|
41 | QChart::ChartTheme chartTheme(); | |
42 |
|
42 | |||
43 | void setAnimationOptions(QChart::AnimationOptions options); |
|
43 | void setAnimationOptions(QChart::AnimationOptions options); | |
44 | QChart::AnimationOptions animationOptions() const; |
|
44 | QChart::AnimationOptions animationOptions() const; | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | void createConnections(); |
|
47 | void createConnections(); | |
48 |
|
48 | |||
49 | public slots: |
|
49 | public slots: | |
50 | void handleSeriesAdded(QSeries* series); |
|
50 | void handleSeriesAdded(QSeries* series); | |
51 | void handleSeriesRemoved(QSeries* series); |
|
51 | void handleSeriesRemoved(QSeries* series); | |
52 | void handleAxisAdded(QChartAxis* axis); |
|
52 | void handleAxisAdded(QChartAxis* axis); | |
53 | void handleAxisRemoved(QChartAxis* axis); |
|
53 | void handleAxisRemoved(QChartAxis* axis); | |
54 | void handleSeriesDomainChanged(QSeries* series, const Domain& domain); |
|
54 | void handleSeriesDomainChanged(QSeries* series, const Domain& domain); | |
55 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); |
|
55 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
56 | void handleSeriesChanged(QSeries* series); |
|
|||
57 | void handleGeometryChanged(); |
|
56 | void handleGeometryChanged(); | |
58 | signals: |
|
57 | signals: | |
59 | void geometryChanged(const QRectF& rect); |
|
58 | void geometryChanged(const QRectF& rect); | |
60 | private: |
|
59 | private: | |
61 | QMap<QSeries*,ChartItem*> m_chartItems; |
|
60 | QMap<QSeries*,ChartItem*> m_chartItems; | |
62 | QMap<QChartAxis*,AxisItem*> m_axisItems; |
|
61 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |
63 | QChart* m_chart; |
|
62 | QChart* m_chart; | |
64 | ChartDataSet* m_dataset; |
|
63 | ChartDataSet* m_dataset; | |
65 | ChartTheme *m_chartTheme; |
|
64 | ChartTheme *m_chartTheme; | |
66 | int m_marginSize; |
|
65 | int m_marginSize; | |
67 | QRectF m_rect; |
|
66 | QRectF m_rect; | |
68 | QChart::AnimationOptions m_options; |
|
67 | QChart::AnimationOptions m_options; | |
69 |
|
68 | |||
70 | }; |
|
69 | }; | |
71 |
|
70 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
73 |
|
72 | |||
74 | #endif /* CHARTPRESENTER_H_ */ |
|
73 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,63 +1,105 | |||||
1 | #include "linechartanimationitem_p.h" |
|
1 | #include "linechartanimationitem_p.h" | |
2 | #include "linechartitem_p.h" |
|
2 | #include "linechartitem_p.h" | |
3 | #include <QPropertyAnimation> |
|
3 | #include <QPropertyAnimation> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | const static int duration = 500; |
|
7 | const static int duration = 500; | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent): |
|
10 | LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent): | |
11 | LineChartItem(presenter,series,parent) |
|
11 | LineChartItem(presenter,series,parent) | |
12 | { |
|
12 | { | |
13 |
|
13 | |||
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | LineChartAnimationItem::~LineChartAnimationItem() |
|
16 | LineChartAnimationItem::~LineChartAnimationItem() | |
17 | { |
|
17 | { | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void LineChartAnimationItem::addPoints(const QVector<QPointF>& points) |
|
20 | void LineChartAnimationItem::addPoints(const QVector<QPointF>& points) | |
21 | { |
|
21 | { | |
22 | m_data=points; |
|
22 | QVector<qreal> vector0 = vector1; | |
23 | clearView(); |
|
23 | calculateLayout(vector1); | |
|
24 | if(vector1.count()==0) return; | |||
|
25 | vector0.resize(vector1.size()); | |||
|
26 | ||||
|
27 | ||||
|
28 | LineChartAnimatator *animation = new LineChartAnimatator(this,this); | |||
|
29 | animation->setDuration(duration); | |||
|
30 | animation->setEasingCurve(QEasingCurve::InOutBack); | |||
|
31 | animation->setKeyValueAt(0.0, qVariantFromValue(vector0)); | |||
|
32 | animation->setKeyValueAt(1.0, qVariantFromValue(vector1)); | |||
|
33 | animation->start(QAbstractAnimation::DeleteWhenStopped); | |||
|
34 | ||||
24 | QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent()); |
|
35 | QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent()); | |
25 | animation->setDuration(duration); |
|
36 | animation->setDuration(duration); | |
26 | //animation->setEasingCurve(QEasingCurve::InOutBack); |
|
37 | //animation->setEasingCurve(QEasingCurve::InOutBack); | |
27 | animation->setKeyValueAt(0.0, 0); |
|
38 | animation->setKeyValueAt(0.0, 0); | |
28 | animation->setKeyValueAt(1.0, m_data.size()); |
|
39 | animation->setKeyValueAt(1.0, m_data.size()); | |
29 | animation->start(QAbstractAnimation::DeleteWhenStopped); |
|
40 | animation->start(QAbstractAnimation::DeleteWhenStopped); | |
30 | } |
|
41 | } | |
31 |
|
42 | |||
32 |
void LineChartAnimationItem:: |
|
43 | void LineChartAnimationItem::replacePoint(int index,const QPointF& point) | |
33 | { |
|
44 | { | |
34 | AnimationHelper* helper = new AnimationHelper(this,index); |
|
45 | AnimationHelper* helper = new AnimationHelper(this,index); | |
35 | QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent()); |
|
46 | QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent()); | |
36 | animation->setDuration(duration); |
|
47 | animation->setDuration(duration); | |
37 | //animation->setEasingCurve(QEasingCurve::InOutBack); |
|
48 | //animation->setEasingCurve(QEasingCurve::InOutBack); | |
38 | animation->setKeyValueAt(0.0, points().value(index)); |
|
49 | animation->setKeyValueAt(0.0, points().value(index)); | |
39 | animation->setKeyValueAt(1.0, point); |
|
50 | animation->setKeyValueAt(1.0, point); | |
40 | animation->start(QAbstractAnimation::DeleteWhenStopped); |
|
51 | animation->start(QAbstractAnimation::DeleteWhenStopped); | |
41 | } |
|
52 | } | |
42 |
|
53 | |||
43 | void LineChartAnimationItem::aw_addPoints(int points) |
|
54 | void LineChartAnimationItem::aw_addPoints(int points) | |
44 | { |
|
55 | { | |
45 | int index = count(); |
|
56 | int index = count(); | |
46 | for(int i = index;i< points ;i++){ |
|
57 | for(int i = index;i< points ;i++){ | |
47 | LineChartItem::addPoint(m_data.at(i)); |
|
58 | LineChartItem::addPoint(m_data.at(i)); | |
48 | } |
|
59 | } | |
49 | updateGeometry(); |
|
60 | updateGeometry(); | |
50 | update(); |
|
61 | update(); | |
51 | } |
|
62 | } | |
52 |
|
63 | |||
53 | void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point) |
|
64 | void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point) | |
54 | { |
|
65 | { | |
55 |
LineChartItem:: |
|
66 | LineChartItem::replacePoint(index,point); | |
56 | updateGeometry(); |
|
67 | updateGeometry(); | |
57 | update(); |
|
68 | update(); | |
58 | } |
|
69 | } | |
59 |
|
70 | |||
|
71 | LineChartAnimatator::LineChartAnimatator(LineChartItem *item, int index , QObject *parent = 0 ):QVariantAnimation(parent), | |||
|
72 | m_item(item), | |||
|
73 | m_index(index) | |||
|
74 | { | |||
|
75 | }; | |||
|
76 | ||||
|
77 | LineChartAnimatator::~LineChartAnimatator() | |||
|
78 | { | |||
|
79 | } | |||
|
80 | ||||
|
81 | QVariant LineChartAnimatator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const | |||
|
82 | { | |||
|
83 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); | |||
|
84 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); | |||
|
85 | QVector<qreal> result; | |||
|
86 | Q_ASSERT(startVector.count() == endVecotr.count()); | |||
|
87 | ||||
|
88 | for(int i =0 ;i< startVector.count();i++){ | |||
|
89 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); | |||
|
90 | result << value; | |||
|
91 | } | |||
|
92 | return qVariantFromValue(result); | |||
|
93 | } | |||
|
94 | ||||
|
95 | ||||
|
96 | void LineChartAnimatator::updateCurrentValue (const QVariant & value ) | |||
|
97 | { | |||
|
98 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); | |||
|
99 | m_axis->applyLayout(vector); | |||
|
100 | } | |||
|
101 | ||||
60 |
|
102 | |||
61 | #include "moc_linechartanimationitem_p.cpp" |
|
103 | #include "moc_linechartanimationitem_p.cpp" | |
62 |
|
104 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
105 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,55 +1,42 | |||||
1 | #ifndef LINECHARTANIMATIONITEM_P_H_ |
|
1 | #ifndef LINECHARTANIMATIONITEM_P_H_ | |
2 | #define LINECHARTANIMATIONITEM_P_H_ |
|
2 | #define LINECHARTANIMATIONITEM_P_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "linechartitem_p.h" |
|
5 | #include "linechartitem_p.h" | |
6 | #include "domain_p.h" |
|
6 | #include "domain_p.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class LineChartItem; |
|
10 | class LineChartItem; | |
11 |
|
11 | |||
12 | class LineChartAnimationItem : public LineChartItem { |
|
12 | class LineChartAnimationItem : public LineChartItem { | |
13 | Q_OBJECT |
|
13 | ||
14 | Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints); |
|
|||
15 | // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint); |
|
|||
16 | public: |
|
14 | public: | |
17 | LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0); |
|
15 | LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0); | |
18 | virtual ~LineChartAnimationItem(); |
|
16 | virtual ~LineChartAnimationItem(); | |
19 |
|
17 | |||
20 | void addPoints(const QVector<QPointF>& points); |
|
18 | void addPoints(const QVector<QPointF>& points); | |
21 |
void |
|
19 | void replacePoint(int index,const QPointF& point); | |
22 | //void removePoint(const QPointF& point){}; |
|
|||
23 | //void setPoint(const QPointF& oldPoint, const QPointF& newPoint){}; |
|
|||
24 |
|
||||
25 | int ar_addPoints() const { return m_addPoints;} |
|
|||
26 | void aw_addPoints(int points); |
|
|||
27 | const QPointF& ar_setPoint() const { return m_setPoint;} |
|
|||
28 | void aw_setPoint(int index,const QPointF& point); |
|
|||
29 |
|
20 | |||
30 | private: |
|
21 | private: | |
31 | QVector<QPointF> m_data; |
|
22 | QVector<QPointF> m_data; | |
32 | Domain m_domain; |
|
23 | Domain m_domain; | |
33 | int m_addPoints; |
|
24 | int m_addPoints; | |
34 | QPointF m_setPoint; |
|
25 | QPointF m_setPoint; | |
35 | int m_setPoint_index; |
|
26 | int m_setPoint_index; | |
36 | }; |
|
27 | }; | |
37 |
|
28 | |||
38 | class AnimationHelper: public QObject |
|
29 | class LineChartAnimatator: public QVariantAnimation | |
39 | { |
|
30 | { | |
40 | Q_OBJECT |
|
31 | ||
41 | Q_PROPERTY(QPointF point READ point WRITE setPoint); |
|
|||
42 | public: |
|
32 | public: | |
43 |
Animat |
|
33 | LineChartAnimatator(LineChartItem *item, int index , QObject *parent = 0 ):m_item(item),m_index(index){}; | |
44 | void setPoint(const QPointF& point){ |
|
34 | ||
45 | m_item->aw_setPoint(m_index,point); |
|
|||
46 | } |
|
|||
47 | QPointF point(){return m_point;} |
|
|||
48 | QPointF m_point; |
|
35 | QPointF m_point; | |
49 | LineChartAnimationItem* m_item; |
|
36 | LineChartAnimationItem* m_item; | |
50 | int m_index; |
|
37 | int m_index; | |
51 | }; |
|
38 | }; | |
52 |
|
39 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
41 | |||
55 | #endif |
|
42 | #endif |
@@ -1,210 +1,244 | |||||
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), |
|
|||
15 | m_dirtyGeometry(false), |
|
|||
16 | m_dirtyDomain(false) |
|
|||
17 | { |
|
14 | { | |
18 | setZValue(ChartPresenter::LineChartZValue); |
|
15 | setZValue(ChartPresenter::LineChartZValue); | |
19 | } |
|
16 | } | |
20 |
|
17 | |||
21 | QRectF LineChartItem::boundingRect() const |
|
18 | QRectF LineChartItem::boundingRect() const | |
22 | { |
|
19 | { | |
23 | return m_rect; |
|
20 | return m_rect; | |
24 | } |
|
21 | } | |
25 |
|
22 | |||
26 | QPainterPath LineChartItem::shape() const |
|
23 | QPainterPath LineChartItem::shape() const | |
27 | { |
|
24 | { | |
28 | return m_path; |
|
25 | return m_path; | |
29 | } |
|
26 | } | |
30 |
|
27 | |||
31 |
|
28 | void LineChartItem::createPoints(int count) | ||
32 | void LineChartItem::addPoints(const QVector<QPointF>& points) |
|
|||
33 | { |
|
29 | { | |
34 | m_data = points; |
|
30 | for (int i = 0; i < count; ++i) { | |
35 | for(int i=0; i<m_data.size();i++){ |
|
31 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); | |
36 | const QPointF& point =m_data[i]; |
|
32 | m_items.addToGroup(item); | |
37 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
|||
38 | item->setPos(point.x()-1,point.y()-1);; |
|
|||
39 | if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false); |
|
|||
40 | m_points << item; |
|
|||
41 | } |
|
33 | } | |
42 | } |
|
34 | } | |
43 |
|
35 | |||
44 |
void LineChartItem:: |
|
36 | void LineChartItem::clearPoints(int count) | |
45 | { |
|
37 | { | |
46 | m_data << point; |
|
38 | QList<QGraphicsItem *> items = m_items.childItems(); | |
47 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
|||
48 | m_clipRect.contains(point); |
|
|||
49 | item->setPos(point.x()-1,point.y()-1); |
|
|||
50 | if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false); |
|
|||
51 | m_points << item; |
|
|||
52 | } |
|
|||
53 |
|
||||
54 | void LineChartItem::removePoint(const QPointF& point) |
|
|||
55 | { |
|
|||
56 | Q_ASSERT(m_data.count() == m_points.count()); |
|
|||
57 | int index = m_data.lastIndexOf(point,0); |
|
|||
58 | m_data.remove(index); |
|
|||
59 | delete(m_points.takeAt(index)); |
|
|||
60 | } |
|
|||
61 |
|
39 | |||
62 | void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint) |
|
40 | for (int i = 0; i < count; ++i) { | |
63 | { |
|
41 | delete(items.takeLast()); | |
64 | Q_ASSERT(m_data.count() == m_points.count()); |
|
|||
65 | int index = m_data.lastIndexOf(oldPoint,0); |
|
|||
66 |
|
||||
67 | if(index > -1){ |
|
|||
68 | m_data.replace(index,newPoint); |
|
|||
69 | QGraphicsItem* item = m_points.at(index); |
|
|||
70 | item->setPos(newPoint.x()-1,newPoint.y()-1); |
|
|||
71 | } |
|
42 | } | |
72 | } |
|
43 | } | |
73 |
|
44 | |||
74 | void LineChartItem::setPoint(int index,const QPointF& point) |
|
|||
75 | { |
|
|||
76 | Q_ASSERT(m_data.count() == m_points.count()); |
|
|||
77 | Q_ASSERT(index>=0); |
|
|||
78 |
|
||||
79 | m_data.replace(index,point); |
|
|||
80 | QGraphicsItem* item = m_points.at(index); |
|
|||
81 | item->setPos(point.x()-1,point.y()-1); |
|
|||
82 | } |
|
|||
83 |
|
||||
84 | void LineChartItem::clear() |
|
|||
85 | { |
|
|||
86 | qDeleteAll(m_points); |
|
|||
87 | m_points.clear(); |
|
|||
88 | m_hash.clear(); |
|
|||
89 | m_path = QPainterPath(); |
|
|||
90 | m_rect = QRect(); |
|
|||
91 | m_data.clear(); |
|
|||
92 | } |
|
|||
93 |
|
||||
94 | void LineChartItem::clearView() |
|
|||
95 | { |
|
|||
96 | qDeleteAll(m_points); |
|
|||
97 | m_points.clear(); |
|
|||
98 | m_path = QPainterPath(); |
|
|||
99 | m_rect = QRect(); |
|
|||
100 | m_data.clear(); |
|
|||
101 | } |
|
|||
102 |
|
||||
103 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
45 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
104 | { |
|
46 | { | |
105 | Q_UNUSED(widget); |
|
47 | Q_UNUSED(widget); | |
106 | Q_UNUSED(option); |
|
48 | Q_UNUSED(option); | |
107 | painter->save(); |
|
49 | painter->save(); | |
108 | painter->setPen(m_pen); |
|
50 | painter->setPen(m_pen); | |
109 | painter->setClipRect(m_clipRect); |
|
51 | painter->setClipRect(m_clipRect); | |
110 | painter->drawPath(m_path); |
|
52 | painter->drawPath(m_path); | |
111 | painter->restore(); |
|
53 | painter->restore(); | |
112 | } |
|
54 | } | |
113 |
|
55 | |||
114 | void LineChartItem::calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const |
|
56 | QPointF LineChartItem::calculatePoint(int index) const | |
115 | { |
|
57 | { | |
116 | const qreal deltaX = size.width()/domain.spanX(); |
|
58 | const qreal deltaX = m_size.width()/m_domain.spanX(); | |
117 | const qreal deltaY = size.height()/domain.spanY(); |
|
59 | const qreal deltaY = m_size.height()/m_domain.spanY(); | |
118 | qreal x = (series->x(index) - domain.m_minX)* deltaX; |
|
60 | qreal x = (m_series->x(index) - m_domain.m_minX)* deltaX; | |
119 | qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height(); |
|
61 | qreal y = (m_series->y(index) - m_domain.m_minY)*-deltaY + m_size.height(); | |
120 | point.setX(x); |
|
62 | return QPointF(x,y); | |
121 | point.setY(y); |
|
|||
122 | } |
|
63 | } | |
123 |
|
64 | |||
124 |
|
65 | |||
125 |
void LineChartItem::calculatePoints(QVector<QPointF>& points, Q |
|
66 | void LineChartItem::calculatePoints(QVector<QPointF>& points, QVector<int>& map) const | |
126 | { |
|
67 | { | |
127 | const qreal deltaX = size.width()/domain.spanX(); |
|
68 | const qreal deltaX = m_size.width()/m_domain.spanX(); | |
128 | const qreal deltaY = size.height()/domain.spanY(); |
|
69 | const qreal deltaY = m_size.height()/m_domain.spanY(); | |
129 |
|
70 | |||
130 | for (int i = 0; i < series->count(); ++i) { |
|
71 | for (int i = 0; i < m_series->count(); ++i) { | |
131 | qreal x = (series->x(i) - domain.m_minX)* deltaX; |
|
72 | qreal x = (m_series->x(i) - m_domain.m_minX)* deltaX; | |
132 | qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height(); |
|
73 | qreal y = (m_series->y(i) - m_domain.m_minY)*-deltaY + m_size.height(); | |
133 | hash[i] = points.size(); |
|
74 | map << i; | |
134 | points << QPointF(x,y); |
|
75 | points << QPointF(x,y); | |
135 | } |
|
76 | } | |
136 | } |
|
77 | } | |
137 |
|
78 | |||
138 | void LineChartItem::updateDomain() |
|
79 | void LineChartItem::updateItem(QVector<QPointF>& points,QVector<int>& map) | |
139 | { |
|
80 | { | |
140 | clear(); |
|
81 | int diff = m_points.size() - points.size(); | |
141 | prepareGeometryChange(); |
|
|||
142 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); |
|
|||
143 | addPoints(m_data); |
|
|||
144 | } |
|
|||
145 |
|
82 | |||
146 | void LineChartItem::updateData() |
|
83 | if(diff>0) { | |
147 | { |
|
84 | clearPoints(diff); | |
148 | //for now the same |
|
85 | } | |
149 | updateDomain(); |
|
86 | else if(diff<0) { | |
|
87 | createPoints(-diff); | |||
|
88 | } | |||
|
89 | ||||
|
90 | applyGeometry(points); | |||
|
91 | m_points=points; | |||
|
92 | m_map=map; | |||
150 | } |
|
93 | } | |
151 |
|
94 | |||
152 |
void LineChartItem:: |
|
95 | void LineChartItem::applyGeometry(QVector<QPointF>& points) | |
153 | { |
|
96 | { | |
|
97 | if(points.size()==0) return; | |||
154 |
|
98 | |||
155 | if(m_data.size()==0) return; |
|
99 | QList<QGraphicsItem*> items = m_items.childItems(); | |
156 |
|
100 | |||
157 | prepareGeometryChange(); |
|
|||
158 | QPainterPath path; |
|
101 | QPainterPath path; | |
159 |
const QPointF& point = |
|
102 | const QPointF& point = points.at(0); | |
160 | path.moveTo(point); |
|
103 | path.moveTo(point); | |
161 |
|
104 | QGraphicsItem* item = items.at(0); | ||
162 | foreach( const QPointF& point , m_data) { |
|
105 | item->setPos(point.x()-1,point.y()-1); | |
|
106 | ||||
|
107 | for(int i=1 ; i< points.size();i++) { | |||
|
108 | QGraphicsItem* item = items.at(i); | |||
|
109 | const QPointF& point = points.at(i); | |||
|
110 | item->setPos(point.x()-1,point.y()-1); | |||
|
111 | if(!m_clipRect.contains(point)) item->setVisible(false); | |||
163 | path.lineTo(point); |
|
112 | path.lineTo(point); | |
164 | } |
|
113 | } | |
165 |
|
114 | |||
|
115 | prepareGeometryChange(); | |||
166 | m_path = path; |
|
116 | m_path = path; | |
167 | m_rect = path.boundingRect(); |
|
117 | m_rect = path.boundingRect(); | |
168 | } |
|
118 | } | |
169 |
|
119 | |||
170 | void LineChartItem::setPen(const QPen& pen) |
|
120 | void LineChartItem::setPen(const QPen& pen) | |
171 | { |
|
121 | { | |
172 | m_pen = pen; |
|
122 | m_pen = pen; | |
173 | } |
|
123 | } | |
174 |
|
124 | |||
175 | //handlers |
|
125 | //handlers | |
176 |
|
126 | |||
177 |
void LineChartItem::handle |
|
127 | void LineChartItem::handlePointAdded(int index) | |
178 | { |
|
128 | { | |
179 | Q_ASSERT(index<m_series->count()); |
|
129 | Q_ASSERT(index<m_series->count()); | |
180 | if(m_hash.contains(index)){ |
|
130 | Q_ASSERT(index>=0); | |
181 | int i = m_hash.value(index); |
|
131 | ||
182 | QPointF point; |
|
132 | if(m_map.contains(index)){ | |
183 | calculatePoint(point,index,m_series,m_size,m_domain); |
|
133 | ||
184 | setPoint(i,point); |
|
134 | int i = m_map.indexOf(index); | |
|
135 | ||||
|
136 | QPointF point = calculatePoint(index); | |||
|
137 | ||||
|
138 | if(point.isNull()) return; | |||
|
139 | ||||
|
140 | QVector<QPointF> points = m_points; | |||
|
141 | points.insert(i,point); | |||
|
142 | ||||
|
143 | for(int j=i;j<m_map.count();j++) | |||
|
144 | m_map[j]-=1; | |||
|
145 | ||||
|
146 | updateItem(points,m_map); | |||
|
147 | ||||
|
148 | }else{ | |||
|
149 | //ignore | |||
|
150 | return; | |||
|
151 | } | |||
|
152 | update(); | |||
|
153 | } | |||
|
154 | void LineChartItem::handlePointRemoved(int index) | |||
|
155 | { | |||
|
156 | Q_ASSERT(index<m_series->count()); | |||
|
157 | Q_ASSERT(index>=0); | |||
|
158 | ||||
|
159 | if(m_map.contains(index)){ | |||
|
160 | ||||
|
161 | int i = m_map.value(index); | |||
|
162 | ||||
|
163 | QVector<QPointF> points = m_points; | |||
|
164 | points.remove(i); | |||
|
165 | ||||
|
166 | for(int j=i;j<m_map.count();j++) | |||
|
167 | m_map[j]+=1; | |||
|
168 | ||||
|
169 | m_map<< | |||
|
170 | ||||
|
171 | updateItem(points,m_map); | |||
|
172 | ||||
|
173 | }else{ | |||
|
174 | //ignore | |||
|
175 | return; | |||
|
176 | } | |||
|
177 | update(); | |||
|
178 | } | |||
|
179 | ||||
|
180 | void LineChartItem::handlePointReplaced(int index) | |||
|
181 | { | |||
|
182 | Q_ASSERT(index<m_series->count()); | |||
|
183 | Q_ASSERT(index>=0); | |||
|
184 | ||||
|
185 | if(m_map.contains(index)){ | |||
|
186 | ||||
|
187 | int i = m_map.indexOf(index); | |||
|
188 | ||||
|
189 | QPointF point = calculatePoint(index); | |||
|
190 | ||||
|
191 | QVector<QPointF> points = m_points; | |||
|
192 | points.replace(i,point); | |||
|
193 | ||||
|
194 | updateItem(points,m_map); | |||
|
195 | ||||
|
196 | }else{ | |||
|
197 | //ignore | |||
|
198 | return; | |||
185 | } |
|
199 | } | |
186 | update(); |
|
200 | update(); | |
187 | } |
|
201 | } | |
188 |
|
202 | |||
189 | void LineChartItem::handleDomainChanged(const Domain& domain) |
|
203 | void LineChartItem::handleDomainChanged(const Domain& domain) | |
190 | { |
|
204 | { | |
191 | m_domain = domain; |
|
205 | m_domain = domain; | |
192 | updateDomain(); |
|
206 | if(m_domain.isEmpty()) return; | |
|
207 | ||||
|
208 | QVector<QPointF> points; | |||
|
209 | QVector<int> map; | |||
|
210 | calculatePoints(points,map); | |||
|
211 | updateItem(points,map); | |||
193 | update(); |
|
212 | update(); | |
194 | } |
|
213 | } | |
195 |
|
214 | |||
196 | void LineChartItem::handleGeometryChanged(const QRectF& rect) |
|
215 | void LineChartItem::handleGeometryChanged(const QRectF& rect) | |
197 | { |
|
216 | { | |
198 | Q_ASSERT(rect.isValid()); |
|
217 | Q_ASSERT(rect.isValid()); | |
199 | m_size=rect.size(); |
|
218 | m_size=rect.size(); | |
200 | m_clipRect=rect.translated(-rect.topLeft()); |
|
219 | m_clipRect=rect.translated(-rect.topLeft()); | |
201 | updateDomain(); |
|
|||
202 | updateGeometry(); |
|
|||
203 | setPos(rect.topLeft()); |
|
220 | setPos(rect.topLeft()); | |
|
221 | ||||
|
222 | if(m_domain.isEmpty()) return; | |||
|
223 | if(m_points.isEmpty()) return; | |||
|
224 | ||||
|
225 | QVector<QPointF> points; | |||
|
226 | QVector<int> map; | |||
|
227 | calculatePoints(points,map); | |||
|
228 | updateItem(points,map); | |||
|
229 | update(); | |||
|
230 | } | |||
|
231 | ||||
|
232 | void LineChartItem::handleSeriesUpdated() | |||
|
233 | { | |||
|
234 | if(m_points.count()==0) return; | |||
|
235 | ||||
|
236 | m_items.setVisible(m_series->pointsVisible()); | |||
|
237 | setPen(m_series->pen()); | |||
204 | update(); |
|
238 | update(); | |
205 | } |
|
239 | } | |
206 |
|
240 | |||
207 |
|
241 | |||
208 | #include "moc_linechartitem_p.cpp" |
|
242 | #include "moc_linechartitem_p.cpp" | |
209 |
|
243 | |||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
244 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,66 | |||||
1 | #ifndef LINECHARTITEM_H |
|
1 | #ifndef LINECHARTITEM_H | |
2 | #define LINECHARTITEM_H |
|
2 | #define LINECHARTITEM_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartPresenter; |
|
10 | class ChartPresenter; | |
11 | class QLineSeries; |
|
11 | class QLineSeries; | |
12 | class LineChartAnimationItem; |
|
|||
13 |
|
12 | |||
14 | class LineChartItem : public QObject , public ChartItem |
|
13 | class LineChartItem : public QObject , public ChartItem | |
15 | { |
|
14 | { | |
16 | Q_OBJECT |
|
15 | Q_OBJECT | |
17 | public: |
|
16 | public: | |
18 | LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0); |
|
17 | LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0); | |
19 | ~ LineChartItem(){}; |
|
18 | ~ LineChartItem(){}; | |
20 |
|
19 | |||
21 | //from QGraphicsItem |
|
20 | //from QGraphicsItem | |
22 | QRectF boundingRect() const; |
|
21 | QRectF boundingRect() const; | |
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
24 | QPainterPath shape() const; |
|
23 | QPainterPath shape() const; | |
25 |
|
24 | |||
26 | void setPen(const QPen& pen); |
|
25 | void setPen(const QPen& pen); | |
27 | const Domain& domain() const { return m_domain;} |
|
26 | void setPointsVisible(bool visible); | |
|
27 | ||||
|
28 | public slots: | |||
|
29 | void handlePointAdded(int index); | |||
|
30 | void handlePointRemoved(int index); | |||
|
31 | void handlePointReplaced(int index); | |||
|
32 | void handleDomainChanged(const Domain& domain); | |||
|
33 | void handleGeometryChanged(const QRectF& size); | |||
28 |
|
34 | |||
|
35 | protected: | |||
29 | virtual void addPoint(const QPointF& ); |
|
36 | virtual void addPoint(const QPointF& ); | |
30 | virtual void addPoints(const QVector<QPointF>& points); |
|
37 | virtual void addPoints(const QVector<QPointF>& points); | |
31 | virtual void removePoint(const QPointF& point); |
|
38 | virtual void removePoint(const QPointF& point); | |
32 |
virtual void |
|
39 | virtual void replacePoint(const QPointF& oldPoint, const QPointF& newPoint); | |
33 |
virtual void |
|
40 | virtual void replacePoint(int index,const QPointF& point); | |
34 | void setPointsVisible(bool visible); |
|
41 | virtual void updateItem(QVector<QPointF>& points,QVector<int>& map); | |
35 | void clear(); |
|
42 | virtual void applyGeometry(QVector<QPointF>& points); | |
36 | void clearView(); |
|
|||
37 | int count() const { return m_data.size();} |
|
|||
38 |
|
||||
39 | const QVector<QPointF>& points(){ return m_data;} |
|
|||
40 |
|
43 | |||
41 | protected: |
|
44 | void clear(); | |
42 | virtual void updateGeometry(); |
|
|||
43 | virtual void updateData(); |
|
|||
44 | virtual void updateDomain(); |
|
|||
45 | //refactor |
|
|||
46 | void calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const; |
|
|||
47 | void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineSeries* series, const QSizeF& size, const Domain& domain) const; |
|
|||
48 |
|
45 | |||
49 | protected slots: |
|
46 | QPointF calculatePoint(int index) const; | |
50 | void handleModelChanged(int index); |
|
47 | void calculatePoints(QVector<QPointF>& points,QVector<int>& map) const; | |
51 | void handleDomainChanged(const Domain& domain); |
|
|||
52 | void handleGeometryChanged(const QRectF& size); |
|
|||
53 |
|
48 | |||
54 | private: |
|
49 | private: | |
55 | ChartPresenter* m_presenter; |
|
50 | ChartPresenter* m_presenter; | |
56 | QPainterPath m_path; |
|
51 | QPainterPath m_path; | |
57 | QSizeF m_size; |
|
52 | QSizeF m_size; | |
58 | QRectF m_rect; |
|
53 | QRectF m_rect; | |
59 | QRectF m_clipRect; |
|
54 | QRectF m_clipRect; | |
60 | Domain m_domain; |
|
55 | Domain m_domain; | |
61 |
QList<QGraphicsItem*> m_ |
|
56 | QList<QGraphicsItem*> m_items; | |
62 |
QVector<QPointF> m_ |
|
57 | QVector<QPointF> m_points; | |
63 |
Q |
|
58 | QVector<int> m_map; | |
64 | QLineSeries* m_series; |
|
59 | QLineSeries* m_series; | |
65 | QPen m_pen; |
|
60 | QPen m_pen; | |
66 | bool m_dirtyData; |
|
|||
67 | bool m_dirtyGeometry; |
|
|||
68 | bool m_dirtyDomain; |
|
|||
69 |
|
61 | |||
70 | }; |
|
62 | }; | |
71 |
|
63 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
64 | QTCOMMERCIALCHART_END_NAMESPACE | |
73 |
|
65 | |||
74 | #endif |
|
66 | #endif |
@@ -1,213 +1,213 | |||||
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 | Creating basic line chart is simple: |
|
16 | Creating basic line chart is simple: | |
17 | \code |
|
17 | \code | |
18 | QLineSeries* series = new QLineSeries(); |
|
18 | QLineSeries* series = new QLineSeries(); | |
19 | series->add(0, 6); |
|
19 | series->add(0, 6); | |
20 | series->add(2, 4); |
|
20 | series->add(2, 4); | |
21 | ... |
|
21 | ... | |
22 | chartView->addSeries(series); |
|
22 | chartView->addSeries(series); | |
23 | \endcode |
|
23 | \endcode | |
24 | */ |
|
24 | */ | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \fn virtual QSeriesType QLineSeries::type() const |
|
27 | \fn virtual QSeriesType QLineSeries::type() const | |
28 | \brief Returns type of series. |
|
28 | \brief Returns type of series. | |
29 | \sa QSeries, QSeriesType |
|
29 | \sa QSeries, QSeriesType | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \fn QPen QLineSeries::pen() const |
|
33 | \fn QPen QLineSeries::pen() const | |
34 | \brief Returns the pen used to draw line for this series. |
|
34 | \brief Returns the pen used to draw line for this series. | |
35 | \sa setPen() |
|
35 | \sa setPen() | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn bool QLineSeries::pointsVisible() const |
|
39 | \fn bool QLineSeries::pointsVisible() const | |
40 | \brief Returns if the points are drawn for this series. |
|
40 | \brief Returns if the points are drawn for this series. | |
41 | \sa setPointsVisible() |
|
41 | \sa setPointsVisible() | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 |
\fn void QLineSeries::point |
|
46 | \fn void QLineSeries::pointReplaced(int index) | |
47 | \brief \internal \a index |
|
47 | \brief \internal \a index | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \fn void QLineSeries::pointAdded(int index) |
|
51 | \fn void QLineSeries::pointAdded(int index) | |
52 | \brief \internal \a index |
|
52 | \brief \internal \a index | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \fn void QLineSeries::pointRemoved(int index) |
|
56 | \fn void QLineSeries::pointRemoved(int index) | |
57 | \brief \internal \a index |
|
57 | \brief \internal \a index | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | Constructs empty series object which is a child of \a parent. |
|
61 | Constructs empty series object which is a child of \a parent. | |
62 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
62 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
63 | */ |
|
63 | */ | |
64 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), |
|
64 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), | |
65 | m_pointsVisible(false) |
|
65 | m_pointsVisible(false) | |
66 | { |
|
66 | { | |
67 | } |
|
67 | } | |
68 | /*! |
|
68 | /*! | |
69 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
69 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
70 | and are deleted when mentioned object are destroyed. |
|
70 | and are deleted when mentioned object are destroyed. | |
71 | */ |
|
71 | */ | |
72 | QLineSeries::~QLineSeries() |
|
72 | QLineSeries::~QLineSeries() | |
73 | { |
|
73 | { | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
77 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
78 | */ |
|
78 | */ | |
79 | void QLineSeries::add(qreal x,qreal y) |
|
79 | void QLineSeries::add(qreal x,qreal y) | |
80 | { |
|
80 | { | |
81 | Q_ASSERT(m_x.size() == m_y.size()); |
|
81 | Q_ASSERT(m_x.size() == m_y.size()); | |
82 | m_x<<x; |
|
82 | m_x<<x; | |
83 | m_y<<y; |
|
83 | m_y<<y; | |
84 | emit pointAdded(m_x.size()-1); |
|
84 | emit pointAdded(m_x.size()-1); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | This is an overloaded function. |
|
88 | This is an overloaded function. | |
89 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
89 | Adds data \a point to the series. Points are connected with lines on the chart. | |
90 | */ |
|
90 | */ | |
91 | void QLineSeries::add(const QPointF& point) |
|
91 | void QLineSeries::add(const QPointF& point) | |
92 | { |
|
92 | { | |
93 | add(point.x(),point.y()); |
|
93 | add(point.x(),point.y()); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | Modifies \a y value for given \a x a value. |
|
97 | Modifies \a y value for given \a x a value. | |
98 | */ |
|
98 | */ | |
99 | void QLineSeries::replace(qreal x,qreal y) |
|
99 | void QLineSeries::replace(qreal x,qreal y) | |
100 | { |
|
100 | { | |
101 | int index = m_x.indexOf(x); |
|
101 | int index = m_x.indexOf(x); | |
102 | m_x[index]=x; |
|
102 | m_x[index]=x; | |
103 | m_y[index]=y; |
|
103 | m_y[index]=y; | |
104 |
emit point |
|
104 | emit pointReplaced(index); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | This is an overloaded function. |
|
108 | This is an overloaded function. | |
109 | Replaces current y value of for given \a point x value with \a point y value. |
|
109 | Replaces current y value of for given \a point x value with \a point y value. | |
110 | */ |
|
110 | */ | |
111 | void QLineSeries::replace(const QPointF& point) |
|
111 | void QLineSeries::replace(const QPointF& point) | |
112 | { |
|
112 | { | |
113 | replace(point.x(),point.y()); |
|
113 | replace(point.x(),point.y()); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | Removes current \a x and y value. |
|
117 | Removes current \a x and y value. | |
118 | */ |
|
118 | */ | |
119 | void QLineSeries::remove(qreal x) |
|
119 | void QLineSeries::remove(qreal x) | |
120 | { |
|
120 | { | |
121 | int index = m_x.indexOf(x); |
|
121 | int index = m_x.indexOf(x); | |
122 | m_x.remove(index); |
|
122 | m_x.remove(index); | |
123 | m_y.remove(index); |
|
123 | m_y.remove(index); | |
124 | emit pointRemoved(index); |
|
124 | emit pointRemoved(index); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | Removes current \a point x value. Note \a point y value is ignored. |
|
128 | Removes current \a point x value. Note \a point y value is ignored. | |
129 | */ |
|
129 | */ | |
130 | void QLineSeries::remove(const QPointF& point) |
|
130 | void QLineSeries::remove(const QPointF& point) | |
131 | { |
|
131 | { | |
132 | remove(point.x()); |
|
132 | remove(point.x()); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Clears all the data. |
|
136 | Clears all the data. | |
137 | */ |
|
137 | */ | |
138 | void QLineSeries::clear() |
|
138 | void QLineSeries::clear() | |
139 | { |
|
139 | { | |
140 | m_x.clear(); |
|
140 | m_x.clear(); | |
141 | m_y.clear(); |
|
141 | m_y.clear(); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \internal \a pos |
|
145 | \internal \a pos | |
146 | */ |
|
146 | */ | |
147 | qreal QLineSeries::x(int pos) const |
|
147 | qreal QLineSeries::x(int pos) const | |
148 | { |
|
148 | { | |
149 | return m_x.at(pos); |
|
149 | return m_x.at(pos); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \internal \a pos |
|
153 | \internal \a pos | |
154 | */ |
|
154 | */ | |
155 | qreal QLineSeries::y(int pos) const |
|
155 | qreal QLineSeries::y(int pos) const | |
156 | { |
|
156 | { | |
157 | return m_y.at(pos); |
|
157 | return m_y.at(pos); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Returns number of data points within series. |
|
161 | Returns number of data points within series. | |
162 | */ |
|
162 | */ | |
163 | int QLineSeries::count() const |
|
163 | int QLineSeries::count() const | |
164 | { |
|
164 | { | |
165 | Q_ASSERT(m_x.size() == m_y.size()); |
|
165 | Q_ASSERT(m_x.size() == m_y.size()); | |
166 |
|
166 | |||
167 | return m_x.size(); |
|
167 | return m_x.size(); | |
168 |
|
168 | |||
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Sets \a pen used for drawing given series.. |
|
172 | Sets \a pen used for drawing given series.. | |
173 | */ |
|
173 | */ | |
174 | void QLineSeries::setPen(const QPen& pen) |
|
174 | void QLineSeries::setPen(const QPen& pen) | |
175 | { |
|
175 | { | |
176 | m_pen=pen; |
|
176 | m_pen=pen; | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Sets if data points are \a visible and should be drawn on line. |
|
180 | Sets if data points are \a visible and should be drawn on line. | |
181 | */ |
|
181 | */ | |
182 | void QLineSeries::setPointsVisible(bool visible) |
|
182 | void QLineSeries::setPointsVisible(bool visible) | |
183 | { |
|
183 | { | |
184 | m_pointsVisible=visible; |
|
184 | m_pointsVisible=visible; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
187 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
188 | { |
|
188 | { | |
189 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
189 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
190 |
|
190 | |||
191 | int size = series.m_x.size(); |
|
191 | int size = series.m_x.size(); | |
192 |
|
192 | |||
193 | for (int i=0;i<size;i++) { |
|
193 | for (int i=0;i<size;i++) { | |
194 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
194 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
195 | } |
|
195 | } | |
196 | return debug.space(); |
|
196 | return debug.space(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | Stream operator for adding a data \a point to the series. |
|
200 | Stream operator for adding a data \a point to the series. | |
201 | \sa add() |
|
201 | \sa add() | |
202 | */ |
|
202 | */ | |
203 |
|
203 | |||
204 | QLineSeries& QLineSeries::operator<< (const QPointF &point) |
|
204 | QLineSeries& QLineSeries::operator<< (const QPointF &point) | |
205 | { |
|
205 | { | |
206 | add(point); |
|
206 | add(point); | |
207 | return *this; |
|
207 | return *this; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | #include "moc_qlineseries.cpp" |
|
211 | #include "moc_qlineseries.cpp" | |
212 |
|
212 | |||
213 | QTCOMMERCIALCHART_END_NAMESPACE |
|
213 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,56 +1,56 | |||||
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 pointsVisible() const {return m_pointsVisible;} |
|
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 |
|
38 | |||
39 | QLineSeries& operator << (const QPointF &point); |
|
39 | QLineSeries& operator << (const QPointF &point); | |
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); |
|
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
41 |
|
41 | |||
42 | signals: |
|
42 | signals: | |
43 |
void point |
|
43 | void pointReplaced(int index); | |
44 | void pointRemoved(int index); |
|
44 | void pointRemoved(int index); | |
45 | void pointAdded(int index); |
|
45 | void pointAdded(int index); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | QVector<qreal> m_x; |
|
48 | QVector<qreal> m_x; | |
49 | QVector<qreal> m_y; |
|
49 | QVector<qreal> m_y; | |
50 | QPen m_pen; |
|
50 | QPen m_pen; | |
51 | bool m_pointsVisible; |
|
51 | bool m_pointsVisible; | |
52 | }; |
|
52 | }; | |
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
55 |
|
55 | |||
56 | #endif |
|
56 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now