@@ -1,333 +1,335 | |||||
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 |
|
61 | |||
62 | m_thicksList.clear(); |
|
62 | m_thicksList.clear(); | |
63 |
|
63 | |||
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
66 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
67 | { |
|
67 | { | |
68 | Q_UNUSED(painter); |
|
68 | Q_UNUSED(painter); | |
69 | Q_UNUSED(option); |
|
69 | Q_UNUSED(option); | |
70 | Q_UNUSED(widget); |
|
70 | Q_UNUSED(widget); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void AxisItem::updateItems(QVector<qreal>& vector) |
|
73 | void AxisItem::updateItems(QVector<qreal>& vector) | |
74 | { |
|
74 | { | |
75 | calculateLayout(vector); |
|
75 | calculateLayout(vector); | |
76 | if(vector.count()==0) return; |
|
76 | if(vector.count()==0) return; | |
77 | applyLayout(vector); |
|
77 | applyLayout(vector); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void AxisItem::handleAxisUpdate(QChartAxis* axis) |
|
80 | void AxisItem::handleAxisUpdate(QChartAxis* axis) | |
81 | { |
|
81 | { | |
|
82 | if(m_layoutVector.count()==0) return; | |||
|
83 | ||||
82 | if(axis->isAxisVisible()) { |
|
84 | if(axis->isAxisVisible()) { | |
83 | setAxisOpacity(100); |
|
85 | setAxisOpacity(100); | |
84 | } |
|
86 | } | |
85 | else { |
|
87 | else { | |
86 | setAxisOpacity(0); |
|
88 | setAxisOpacity(0); | |
87 | } |
|
89 | } | |
88 |
|
90 | |||
89 | if(axis->isGridVisible()) { |
|
91 | if(axis->isGridVisible()) { | |
90 | setGridOpacity(100); |
|
92 | setGridOpacity(100); | |
91 | } |
|
93 | } | |
92 | else { |
|
94 | else { | |
93 | setGridOpacity(0); |
|
95 | setGridOpacity(0); | |
94 | } |
|
96 | } | |
95 |
|
97 | |||
96 | if(axis->isLabelsVisible()) |
|
98 | if(axis->isLabelsVisible()) | |
97 | { |
|
99 | { | |
98 | setLabelsOpacity(100); |
|
100 | setLabelsOpacity(100); | |
99 | } |
|
101 | } | |
100 | else { |
|
102 | else { | |
101 | setLabelsOpacity(0); |
|
103 | setLabelsOpacity(0); | |
102 | } |
|
104 | } | |
103 |
|
105 | |||
104 | if(axis->isShadesVisible()) { |
|
106 | if(axis->isShadesVisible()) { | |
105 | setShadesOpacity(axis->shadesOpacity()); |
|
107 | setShadesOpacity(axis->shadesOpacity()); | |
106 | } |
|
108 | } | |
107 | else { |
|
109 | else { | |
108 | setShadesOpacity(0); |
|
110 | setShadesOpacity(0); | |
109 | } |
|
111 | } | |
110 |
|
112 | |||
111 | setLabelsAngle(axis->labelsAngle()); |
|
113 | setLabelsAngle(axis->labelsAngle()); | |
112 | setAxisPen(axis->axisPen()); |
|
114 | setAxisPen(axis->axisPen()); | |
113 | setLabelsPen(axis->labelsPen()); |
|
115 | setLabelsPen(axis->labelsPen()); | |
114 | setLabelsBrush(axis->labelsBrush()); |
|
116 | setLabelsBrush(axis->labelsBrush()); | |
115 | setLabelsFont(axis->labelFont()); |
|
117 | setLabelsFont(axis->labelFont()); | |
116 | setGridPen(axis->gridPen()); |
|
118 | setGridPen(axis->gridPen()); | |
117 | setShadesPen(axis->shadesPen()); |
|
119 | setShadesPen(axis->shadesPen()); | |
118 | setShadesBrush(axis->shadesBrush()); |
|
120 | setShadesBrush(axis->shadesBrush()); | |
119 | } |
|
121 | } | |
120 |
|
122 | |||
121 | void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
123 | void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
122 | { |
|
124 | { | |
123 | int diff = m_thicksList.size() - labels.size(); |
|
125 | int diff = m_thicksList.size() - labels.size(); | |
124 |
|
126 | |||
125 | if(diff>0){ |
|
127 | if(diff>0){ | |
126 | clear(diff); |
|
128 | clear(diff); | |
127 | }else if(diff<0){ |
|
129 | }else if(diff<0){ | |
128 | createItems(-diff); |
|
130 | createItems(-diff); | |
129 | } |
|
131 | } | |
130 | m_thicksList=labels; |
|
132 | m_thicksList=labels; | |
131 | m_layoutVector.resize(m_thicksList.size()); |
|
133 | m_layoutVector.resize(m_thicksList.size()); | |
132 | updateItems(m_layoutVector); |
|
134 | updateItems(m_layoutVector); | |
133 | handleAxisUpdate(axis); |
|
135 | if(diff!=0) handleAxisUpdate(axis); | |
134 | } |
|
136 | } | |
135 |
|
137 | |||
136 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
138 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |
137 | { |
|
139 | { | |
138 | m_rect = rect; |
|
140 | m_rect = rect; | |
139 | updateItems(m_layoutVector); |
|
141 | updateItems(m_layoutVector); | |
140 | } |
|
142 | } | |
141 |
|
143 | |||
142 | void AxisItem::setAxisOpacity(qreal opacity) |
|
144 | void AxisItem::setAxisOpacity(qreal opacity) | |
143 | { |
|
145 | { | |
144 | m_axis.setOpacity(opacity); |
|
146 | m_axis.setOpacity(opacity); | |
145 | } |
|
147 | } | |
146 |
|
148 | |||
147 | qreal AxisItem::axisOpacity() const |
|
149 | qreal AxisItem::axisOpacity() const | |
148 | { |
|
150 | { | |
149 | return m_axis.opacity(); |
|
151 | return m_axis.opacity(); | |
150 | } |
|
152 | } | |
151 |
|
153 | |||
152 | void AxisItem::setGridOpacity(qreal opacity) |
|
154 | void AxisItem::setGridOpacity(qreal opacity) | |
153 | { |
|
155 | { | |
154 | m_grid.setOpacity(opacity); |
|
156 | m_grid.setOpacity(opacity); | |
155 | } |
|
157 | } | |
156 |
|
158 | |||
157 | qreal AxisItem::gridOpacity() const |
|
159 | qreal AxisItem::gridOpacity() const | |
158 | { |
|
160 | { | |
159 | return m_grid.opacity(); |
|
161 | return m_grid.opacity(); | |
160 | } |
|
162 | } | |
161 |
|
163 | |||
162 | void AxisItem::setLabelsOpacity(qreal opacity) |
|
164 | void AxisItem::setLabelsOpacity(qreal opacity) | |
163 | { |
|
165 | { | |
164 | m_labels.setOpacity(opacity); |
|
166 | m_labels.setOpacity(opacity); | |
165 | } |
|
167 | } | |
166 |
|
168 | |||
167 | qreal AxisItem::labelsOpacity() const |
|
169 | qreal AxisItem::labelsOpacity() const | |
168 | { |
|
170 | { | |
169 | return m_labels.opacity(); |
|
171 | return m_labels.opacity(); | |
170 | } |
|
172 | } | |
171 |
|
173 | |||
172 | void AxisItem::setShadesOpacity(qreal opacity) |
|
174 | void AxisItem::setShadesOpacity(qreal opacity) | |
173 | { |
|
175 | { | |
174 | m_shades.setOpacity(opacity); |
|
176 | m_shades.setOpacity(opacity); | |
175 | } |
|
177 | } | |
176 |
|
178 | |||
177 | qreal AxisItem::shadesOpacity() const |
|
179 | qreal AxisItem::shadesOpacity() const | |
178 | { |
|
180 | { | |
179 | return m_shades.opacity(); |
|
181 | return m_shades.opacity(); | |
180 | } |
|
182 | } | |
181 |
|
183 | |||
182 | void AxisItem::setLabelsAngle(int angle) |
|
184 | void AxisItem::setLabelsAngle(int angle) | |
183 | { |
|
185 | { | |
184 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
186 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
185 | QPointF center = item->boundingRect().center(); |
|
187 | QPointF center = item->boundingRect().center(); | |
186 | item->setRotation(angle); |
|
188 | item->setRotation(angle); | |
187 | } |
|
189 | } | |
188 |
|
190 | |||
189 | m_labelsAngle=angle; |
|
191 | m_labelsAngle=angle; | |
190 | } |
|
192 | } | |
191 |
|
193 | |||
192 | void AxisItem::setLabelsPen(const QPen& pen) |
|
194 | void AxisItem::setLabelsPen(const QPen& pen) | |
193 | { |
|
195 | { | |
194 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
196 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
195 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
197 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
196 | } |
|
198 | } | |
197 | } |
|
199 | } | |
198 |
|
200 | |||
199 | void AxisItem::setLabelsBrush(const QBrush& brush) |
|
201 | void AxisItem::setLabelsBrush(const QBrush& brush) | |
200 | { |
|
202 | { | |
201 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
203 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
202 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
204 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
203 | } |
|
205 | } | |
204 | } |
|
206 | } | |
205 |
|
207 | |||
206 | void AxisItem::setLabelsFont(const QFont& font) |
|
208 | void AxisItem::setLabelsFont(const QFont& font) | |
207 | { |
|
209 | { | |
208 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
210 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
209 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
211 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
210 | } |
|
212 | } | |
211 | } |
|
213 | } | |
212 |
|
214 | |||
213 | void AxisItem::setShadesBrush(const QBrush& brush) |
|
215 | void AxisItem::setShadesBrush(const QBrush& brush) | |
214 | { |
|
216 | { | |
215 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
217 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
216 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
218 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
217 | } |
|
219 | } | |
218 | } |
|
220 | } | |
219 |
|
221 | |||
220 | void AxisItem::setShadesPen(const QPen& pen) |
|
222 | void AxisItem::setShadesPen(const QPen& pen) | |
221 | { |
|
223 | { | |
222 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
224 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
223 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
225 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
224 | } |
|
226 | } | |
225 | } |
|
227 | } | |
226 |
|
228 | |||
227 | void AxisItem::setAxisPen(const QPen& pen) |
|
229 | void AxisItem::setAxisPen(const QPen& pen) | |
228 | { |
|
230 | { | |
229 | foreach(QGraphicsItem* item , m_axis.childItems()) { |
|
231 | foreach(QGraphicsItem* item , m_axis.childItems()) { | |
230 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
232 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
231 | } |
|
233 | } | |
232 | } |
|
234 | } | |
233 |
|
235 | |||
234 | void AxisItem::setGridPen(const QPen& pen) |
|
236 | void AxisItem::setGridPen(const QPen& pen) | |
235 | { |
|
237 | { | |
236 | foreach(QGraphicsItem* item , m_grid.childItems()) { |
|
238 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |
237 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
239 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
238 | } |
|
240 | } | |
239 | } |
|
241 | } | |
240 |
|
242 | |||
241 | void AxisItem::calculateLayout(QVector<qreal>& points) |
|
243 | void AxisItem::calculateLayout(QVector<qreal>& points) | |
242 | { |
|
244 | { | |
243 | switch (m_type) |
|
245 | switch (m_type) | |
244 | { |
|
246 | { | |
245 | case X_AXIS: |
|
247 | case X_AXIS: | |
246 | { |
|
248 | { | |
247 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); |
|
249 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); | |
248 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
250 | for (int i = 0; i < m_thicksList.size(); ++i) { | |
249 | int x = i * deltaX + m_rect.left(); |
|
251 | int x = i * deltaX + m_rect.left(); | |
250 | points[i]=x; |
|
252 | points[i]=x; | |
251 | } |
|
253 | } | |
252 | } |
|
254 | } | |
253 | break; |
|
255 | break; | |
254 | case Y_AXIS: |
|
256 | case Y_AXIS: | |
255 | { |
|
257 | { | |
256 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); |
|
258 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); | |
257 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
259 | for (int i = 0; i < m_thicksList.size(); ++i) { | |
258 | int y = i * -deltaY + m_rect.bottom(); |
|
260 | int y = i * -deltaY + m_rect.bottom(); | |
259 | points[i]=y; |
|
261 | points[i]=y; | |
260 | } |
|
262 | } | |
261 | } |
|
263 | } | |
262 | break; |
|
264 | break; | |
263 | } |
|
265 | } | |
264 | } |
|
266 | } | |
265 |
|
267 | |||
266 | void AxisItem::applyLayout(const QVector<qreal>& points) |
|
268 | void AxisItem::applyLayout(const QVector<qreal>& points) | |
267 | { |
|
269 | { | |
268 | Q_ASSERT(points.size() == m_thicksList.size()); |
|
270 | Q_ASSERT(points.size() == m_thicksList.size()); | |
269 |
|
271 | |||
270 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
272 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
271 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
273 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
272 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
274 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
273 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
275 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
274 |
|
276 | |||
275 | Q_ASSERT(labels.size() == m_thicksList.size()); |
|
277 | Q_ASSERT(labels.size() == m_thicksList.size()); | |
276 |
|
278 | |||
277 | switch (m_type) |
|
279 | switch (m_type) | |
278 | { |
|
280 | { | |
279 | case X_AXIS: |
|
281 | case X_AXIS: | |
280 | { |
|
282 | { | |
281 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
283 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
282 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
284 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
283 |
|
285 | |||
284 | for (int i = 0; i < points.size(); ++i) { |
|
286 | for (int i = 0; i < points.size(); ++i) { | |
285 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
287 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
286 | lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom()); |
|
288 | lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom()); | |
287 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
289 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
288 | labelItem->setText(m_thicksList.at(i)); |
|
290 | labelItem->setText(m_thicksList.at(i)); | |
289 | QPointF center = labelItem->boundingRect().center(); |
|
291 | QPointF center = labelItem->boundingRect().center(); | |
290 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
292 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
291 | labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding); |
|
293 | labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding); | |
292 | if(i%2){ |
|
294 | if(i%2){ | |
293 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
295 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |
294 | rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height()); |
|
296 | rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height()); | |
295 | } |
|
297 | } | |
296 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
298 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
297 | lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5); |
|
299 | lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5); | |
298 | } |
|
300 | } | |
299 | } |
|
301 | } | |
300 | break; |
|
302 | break; | |
301 |
|
303 | |||
302 | case Y_AXIS: |
|
304 | case Y_AXIS: | |
303 | { |
|
305 | { | |
304 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
306 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
305 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
307 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
306 |
|
308 | |||
307 | for (int i = 0; i < points.size(); ++i) { |
|
309 | for (int i = 0; i < points.size(); ++i) { | |
308 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
310 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
309 | lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]); |
|
311 | lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]); | |
310 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
312 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
311 | labelItem->setText(m_thicksList.at(i)); |
|
313 | labelItem->setText(m_thicksList.at(i)); | |
312 | QPointF center = labelItem->boundingRect().center(); |
|
314 | QPointF center = labelItem->boundingRect().center(); | |
313 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
315 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
314 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y()); |
|
316 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y()); | |
315 | if(i%2){ |
|
317 | if(i%2){ | |
316 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
318 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |
317 | rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]); |
|
319 | rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]); | |
318 | } |
|
320 | } | |
319 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
321 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
320 | lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]); |
|
322 | lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]); | |
321 | } |
|
323 | } | |
322 | } |
|
324 | } | |
323 | break; |
|
325 | break; | |
324 | default: |
|
326 | default: | |
325 | qDebug()<<"Unknown axis type"; |
|
327 | qDebug()<<"Unknown axis type"; | |
326 | break; |
|
328 | break; | |
327 | } |
|
329 | } | |
328 | } |
|
330 | } | |
329 |
|
331 | |||
330 | //TODO "nice numbers algorithm" |
|
332 | //TODO "nice numbers algorithm" | |
331 | #include "moc_axisitem_p.cpp" |
|
333 | #include "moc_axisitem_p.cpp" | |
332 |
|
334 | |||
333 | QTCOMMERCIALCHART_END_NAMESPACE |
|
335 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,60 | |||||
1 | #ifndef CHARTDATASET_P_H_ |
|
1 | #ifndef CHARTDATASET_P_H_ | |
2 | #define CHARTDATASET_P_H_ |
|
2 | #define CHARTDATASET_P_H_ | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include "domain_p.h" |
|
5 | #include "domain_p.h" | |
6 | #include <QVector> |
|
6 | #include <QVector> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class ChartDataSet : public QObject |
|
12 | class ChartDataSet : public QObject | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | ChartDataSet(QObject* parent=0); |
|
16 | ChartDataSet(QObject* parent=0); | |
17 | virtual ~ChartDataSet(); |
|
17 | virtual ~ChartDataSet(); | |
18 |
|
18 | |||
19 | void addSeries(QChartSeries* series,QChartAxis *axisY = 0); |
|
19 | void addSeries(QChartSeries* series,QChartAxis *axisY = 0); | |
20 | void removeSeries(QChartSeries* series); |
|
20 | void removeSeries(QChartSeries* series); | |
21 | void removeAllSeries(); |
|
21 | void removeAllSeries(); | |
22 | void addDomain(const QRectF& rect, const QRectF& viewport); |
|
22 | void addDomain(const QRectF& rect, const QRectF& viewport); | |
23 | bool nextDomain(); |
|
23 | bool nextDomain(); | |
24 | bool previousDomain(); |
|
24 | bool previousDomain(); | |
25 | void clearDomains(int toIndex =0); |
|
25 | void clearDomains(int toIndex =0); | |
26 | const Domain domain(QChartAxis *axisY) const; |
|
26 | const Domain domain(QChartAxis *axisY) const; | |
27 | int domainIndex() const {return m_domainIndex;} |
|
27 | int domainIndex() const {return m_domainIndex;} | |
|
28 | void setDomain(int index); | |||
28 |
|
29 | |||
29 | QChartAxis* axisX() const { return m_axisX;}; |
|
30 | QChartAxis* axisX() const { return m_axisX;}; | |
30 | QChartAxis* axisY(QChartSeries* series = 0) const; |
|
31 | QChartAxis* axisY(QChartSeries* series = 0) const; | |
31 |
|
32 | |||
32 | signals: |
|
33 | signals: | |
33 | void seriesAdded(QChartSeries* series); |
|
34 | void seriesAdded(QChartSeries* series); | |
34 | void seriesRemoved(QChartSeries* series); |
|
35 | void seriesRemoved(QChartSeries* series); | |
35 | void axisAdded(QChartAxis* axis); |
|
36 | void axisAdded(QChartAxis* axis); | |
36 | void axisRemoved(QChartAxis* axis); |
|
37 | void axisRemoved(QChartAxis* axis); | |
37 | void axisLabelsChanged(QChartAxis* axis, const QStringList& labels); |
|
38 | void axisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
38 | void seriesDomainChanged(QChartSeries* series,const Domain& domain); |
|
39 | void seriesDomainChanged(QChartSeries* series,const Domain& domain); | |
39 |
|
40 | |||
40 | private slots: |
|
41 | private slots: | |
41 | void handleMinChanged(qreal min); |
|
42 | void handleMinChanged(qreal min); | |
42 | void handleMaxChanged(qreal max); |
|
43 | void handleMaxChanged(qreal max); | |
43 | void handleTickChanged(QChartAxis*); |
|
44 | void handleTickChanged(QChartAxis*); | |
44 |
|
45 | |||
45 | private: |
|
46 | private: | |
46 | void setDomain(int index); |
|
|||
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); |
|
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); | |
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 | QMultiMap<QChartAxis*, Domain> m_domainMap; |
|
50 | QMultiMap<QChartAxis*, Domain> m_domainMap; | |
51 | QMultiMap<QChartAxis*, QChartSeries*> m_seriesMap; |
|
51 | QMultiMap<QChartAxis*, QChartSeries*> m_seriesMap; | |
52 | QChartAxis* m_axisX; |
|
52 | QChartAxis* m_axisX; | |
53 | QChartAxis* m_axisY; |
|
53 | QChartAxis* m_axisY; | |
54 | int m_domainIndex; |
|
54 | int m_domainIndex; | |
55 | bool m_axisXInitialized; |
|
55 | bool m_axisXInitialized; | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 |
|
59 | |||
60 | #endif /* CHARTENGINE_P_H_ */ |
|
60 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,241 +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 "qbarchartseries.h" |
|
7 | #include "qbarchartseries.h" | |
8 | #include "qstackedbarchartseries.h" |
|
8 | #include "qstackedbarchartseries.h" | |
9 | #include "qpercentbarchartseries.h" |
|
9 | #include "qpercentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.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 "barpresenter.h" |
|
16 | #include "barpresenter.h" | |
16 | #include "stackedbarpresenter.h" |
|
17 | #include "stackedbarpresenter.h" | |
17 | #include "linechartitem_p.h" |
|
18 | #include "linechartitem_p.h" | |
18 | #include "percentbarpresenter.h" |
|
19 | #include "percentbarpresenter.h" | |
19 | #include "linechartanimationitem_p.h" |
|
20 | #include "linechartanimationitem_p.h" | |
20 | #include "piepresenter.h" |
|
21 | #include "piepresenter.h" | |
21 | #include "scatterpresenter_p.h" |
|
22 | #include "scatterpresenter_p.h" | |
22 |
|
23 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
25 | |||
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
26 | m_chart(chart), |
|
27 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
28 | m_dataset(dataset), | |
28 | m_chartTheme(0), |
|
29 | m_chartTheme(0), | |
29 | m_marginSize(0), |
|
30 | m_marginSize(0), | |
30 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
|
32 | m_options(0) | |||
31 | { |
|
33 | { | |
32 | createConnections(); |
|
34 | createConnections(); | |
33 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
34 |
|
36 | |||
35 | } |
|
37 | } | |
36 |
|
38 | |||
37 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
38 | { |
|
40 | { | |
39 | } |
|
41 | } | |
40 |
|
42 | |||
41 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
42 | { |
|
44 | { | |
43 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
44 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
45 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*))); |
|
47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*))); | |
46 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); | |
47 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
48 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&))); |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&))); | |
49 | 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&))); | |
50 | } |
|
52 | } | |
51 |
|
53 | |||
52 |
|
54 | |||
53 | QRectF ChartPresenter::geometry() const |
|
55 | QRectF ChartPresenter::geometry() const | |
54 | { |
|
56 | { | |
55 | return m_rect; |
|
57 | return m_rect; | |
56 | } |
|
58 | } | |
57 |
|
59 | |||
58 | void ChartPresenter::handleGeometryChanged() |
|
60 | void ChartPresenter::handleGeometryChanged() | |
59 | { |
|
61 | { | |
60 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
61 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
62 | Q_ASSERT(m_rect.isValid()); |
|
64 | Q_ASSERT(m_rect.isValid()); | |
63 | emit geometryChanged(m_rect); |
|
65 | emit geometryChanged(m_rect); | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | int ChartPresenter::margin() const |
|
68 | int ChartPresenter::margin() const | |
67 | { |
|
69 | { | |
68 | return m_marginSize; |
|
70 | return m_marginSize; | |
69 | } |
|
71 | } | |
70 |
|
72 | |||
71 | void ChartPresenter::setMargin(int margin) |
|
73 | void ChartPresenter::setMargin(int margin) | |
72 | { |
|
74 | { | |
73 | m_marginSize = margin; |
|
75 | m_marginSize = margin; | |
74 | } |
|
76 | } | |
75 |
|
77 | |||
76 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) | |
77 | { |
|
79 | { | |
|
80 | ||||
78 | AxisItem* item ; |
|
81 | AxisItem* item ; | |
79 |
|
82 | |||
80 | if(axis==m_dataset->axisX()){ |
|
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
81 | item = new AxisItem(AxisItem::X_AXIS,m_chart); |
|
84 | { | |
|
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |||
|
86 | qDebug()<<"kuku1"; | |||
82 | }else{ |
|
87 | }else{ | |
83 |
item = new AxisItem |
|
88 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
|
89 | qDebug()<<"kuku2"; | |||
84 | } |
|
90 | } | |
|
91 | ||||
85 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
92 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
86 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
93 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); | |
87 |
|
94 | |||
88 | item->handleAxisUpdate(axis); |
|
95 | item->handleAxisUpdate(axis); | |
89 | item->handleGeometryChanged(m_rect); |
|
96 | item->handleGeometryChanged(m_rect); | |
90 | m_chartTheme->decorate(axis,item); |
|
97 | m_chartTheme->decorate(axis,item); | |
91 | m_axisItems.insert(axis,item); |
|
98 | m_axisItems.insert(axis,item); | |
92 | } |
|
99 | } | |
93 |
|
100 | |||
94 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
101 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
95 | { |
|
102 | { | |
96 | AxisItem* item = m_axisItems.take(axis); |
|
103 | AxisItem* item = m_axisItems.take(axis); | |
97 | Q_ASSERT(item); |
|
104 | Q_ASSERT(item); | |
98 | delete item; |
|
105 | delete item; | |
99 | } |
|
106 | } | |
100 |
|
107 | |||
101 |
|
108 | |||
102 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
109 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
103 | { |
|
110 | { | |
104 | switch(series->type()) |
|
111 | switch(series->type()) | |
105 | { |
|
112 | { | |
106 | case QChartSeries::SeriesTypeLine: { |
|
113 | case QChartSeries::SeriesTypeLine: { | |
107 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
114 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
108 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
115 | LineChartItem* item; | |
|
116 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |||
|
117 | item = new LineChartAnimationItem(this,lineSeries,m_chart); | |||
|
118 | }else{ | |||
|
119 | item = new LineChartItem(this,lineSeries,m_chart); | |||
|
120 | } | |||
109 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
121 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
110 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
122 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
111 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
123 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
112 | m_chartItems.insert(series,item); |
|
124 | m_chartItems.insert(series,item); | |
113 | break; |
|
125 | break; | |
114 | } |
|
126 | } | |
115 |
|
127 | |||
116 | case QChartSeries::SeriesTypeBar: { |
|
128 | case QChartSeries::SeriesTypeBar: { | |
117 | QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series); |
|
129 | QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series); | |
118 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
130 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
119 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
131 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
132 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
121 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
133 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
122 | m_chartItems.insert(series,item); |
|
134 | m_chartItems.insert(series,item); | |
123 | // m_axisXItem->setVisible(false); |
|
135 | // m_axisXItem->setVisible(false); | |
124 | break; |
|
136 | break; | |
125 | } |
|
137 | } | |
126 |
|
138 | |||
127 | case QChartSeries::SeriesTypeStackedBar: { |
|
139 | case QChartSeries::SeriesTypeStackedBar: { | |
128 |
|
140 | |||
129 | QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series); |
|
141 | QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series); | |
130 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
142 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
131 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
143 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
132 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
144 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
133 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
145 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
134 | m_chartItems.insert(series,item); |
|
146 | m_chartItems.insert(series,item); | |
135 | break; |
|
147 | break; | |
136 | } |
|
148 | } | |
137 |
|
149 | |||
138 | case QChartSeries::SeriesTypePercentBar: { |
|
150 | case QChartSeries::SeriesTypePercentBar: { | |
139 |
|
151 | |||
140 | QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series); |
|
152 | QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series); | |
141 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
153 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
142 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
154 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
143 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
155 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
144 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
156 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
145 | m_chartItems.insert(series,item); |
|
157 | m_chartItems.insert(series,item); | |
146 | break; |
|
158 | break; | |
147 | } |
|
159 | } | |
148 | case QChartSeries::SeriesTypeScatter: { |
|
160 | case QChartSeries::SeriesTypeScatter: { | |
149 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
161 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
150 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
162 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
151 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
163 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
152 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
164 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
153 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
165 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
154 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
166 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
155 | break; |
|
167 | break; | |
156 | } |
|
168 | } | |
157 | case QChartSeries::SeriesTypePie: { |
|
169 | case QChartSeries::SeriesTypePie: { | |
158 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
170 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
159 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
171 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
160 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
172 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
161 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
162 |
|
174 | |||
163 | // Hide all from background when there is only piechart |
|
175 | // Hide all from background when there is only piechart | |
164 | // TODO: refactor this ugly code... should be one setting for this |
|
176 | // TODO: refactor this ugly code... should be one setting for this | |
165 | if (m_chartItems.count() == 0) { |
|
177 | if (m_chartItems.count() == 0) { | |
166 | m_chart->axisX()->setAxisVisible(false); |
|
178 | m_chart->axisX()->setAxisVisible(false); | |
167 | m_chart->axisY()->setAxisVisible(false); |
|
179 | m_chart->axisY()->setAxisVisible(false); | |
168 | m_chart->axisX()->setGridVisible(false); |
|
180 | m_chart->axisX()->setGridVisible(false); | |
169 | m_chart->axisY()->setGridVisible(false); |
|
181 | m_chart->axisY()->setGridVisible(false); | |
170 | m_chart->axisX()->setLabelsVisible(false); |
|
182 | m_chart->axisX()->setLabelsVisible(false); | |
171 | m_chart->axisY()->setLabelsVisible(false); |
|
183 | m_chart->axisY()->setLabelsVisible(false); | |
172 | m_chart->axisX()->setShadesVisible(false); |
|
184 | m_chart->axisX()->setShadesVisible(false); | |
173 | m_chart->axisY()->setShadesVisible(false); |
|
185 | m_chart->axisY()->setShadesVisible(false); | |
174 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
186 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
175 | } |
|
187 | } | |
176 |
|
188 | |||
177 | m_chartItems.insert(series, pie); |
|
189 | m_chartItems.insert(series, pie); | |
178 | break; |
|
190 | break; | |
179 | } |
|
191 | } | |
180 | default: { |
|
192 | default: { | |
181 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
193 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
182 | break; |
|
194 | break; | |
183 | } |
|
195 | } | |
184 | } |
|
196 | } | |
185 |
|
197 | |||
186 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
198 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
187 | } |
|
199 | } | |
188 |
|
200 | |||
189 | void ChartPresenter::handleSeriesRemoved(QChartSeries* series) |
|
201 | void ChartPresenter::handleSeriesRemoved(QChartSeries* series) | |
190 | { |
|
202 | { | |
191 | ChartItem* item = m_chartItems.take(series); |
|
203 | ChartItem* item = m_chartItems.take(series); | |
192 | delete item; |
|
204 | delete item; | |
193 | } |
|
205 | } | |
194 |
|
206 | |||
195 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
207 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
196 | { |
|
208 | { | |
197 | //TODO: |
|
209 | //TODO: | |
198 | } |
|
210 | } | |
199 |
|
211 | |||
200 | void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain) |
|
212 | void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain) | |
201 | { |
|
213 | { | |
202 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
214 | m_chartItems.value(series)->handleDomainChanged(domain); | |
203 | } |
|
215 | } | |
204 |
|
216 | |||
205 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
217 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
206 | { |
|
218 | { | |
207 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); |
|
219 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); | |
208 | } |
|
220 | } | |
209 |
|
221 | |||
210 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
222 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
211 | { |
|
223 | { | |
212 | delete m_chartTheme; |
|
224 | delete m_chartTheme; | |
213 |
|
225 | |||
214 | m_chartTheme = ChartTheme::createTheme(theme); |
|
226 | m_chartTheme = ChartTheme::createTheme(theme); | |
215 |
|
227 | |||
216 | m_chartTheme->decorate(m_chart); |
|
228 | m_chartTheme->decorate(m_chart); | |
217 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
229 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
218 |
|
230 | |||
219 | int index=0; |
|
231 | int index=0; | |
220 | while (i.hasNext()) { |
|
232 | while (i.hasNext()) { | |
221 | i.next(); |
|
233 | i.next(); | |
222 | index++; |
|
234 | index++; | |
223 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
235 | m_chartTheme->decorate(i.value(),i.key(),index); | |
224 | } |
|
236 | } | |
225 |
|
237 | |||
226 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
238 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
227 | while (j.hasNext()) { |
|
239 | while (j.hasNext()) { | |
228 | j.next(); |
|
240 | j.next(); | |
229 | m_chartTheme->decorate(j.key(),j.value()); |
|
241 | m_chartTheme->decorate(j.key(),j.value()); | |
230 | } |
|
242 | } | |
231 | } |
|
243 | } | |
232 |
|
244 | |||
233 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
245 | QChart::ChartTheme ChartPresenter::chartTheme() | |
234 | { |
|
246 | { | |
235 | return m_chartTheme->id(); |
|
247 | return m_chartTheme->id(); | |
236 | } |
|
248 | } | |
237 |
|
249 | |||
|
250 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |||
|
251 | { | |||
|
252 | if(m_options!=options) { | |||
|
253 | ||||
|
254 | m_options=options; | |||
|
255 | ||||
|
256 | //recreate elements | |||
|
257 | ||||
|
258 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |||
|
259 | QList<QChartSeries*> seriesList = m_chartItems.uniqueKeys(); | |||
|
260 | ||||
|
261 | foreach(QChartAxis* axis, axisList) { | |||
|
262 | handleAxisRemoved(axis); | |||
|
263 | handleAxisAdded(axis); | |||
|
264 | } | |||
|
265 | foreach(QChartSeries* series, seriesList) { | |||
|
266 | handleSeriesRemoved(series); | |||
|
267 | handleSeriesAdded(series); | |||
|
268 | } | |||
|
269 | ||||
|
270 | //now reintialize view data | |||
|
271 | //TODO: make it more nice | |||
|
272 | m_dataset->setDomain(m_dataset->domainIndex()); | |||
|
273 | } | |||
|
274 | } | |||
|
275 | ||||
|
276 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |||
|
277 | { | |||
|
278 | return m_options; | |||
|
279 | } | |||
|
280 | ||||
238 |
|
281 | |||
239 | #include "moc_chartpresenter_p.cpp" |
|
282 | #include "moc_chartpresenter_p.cpp" | |
240 |
|
283 | |||
241 | QTCOMMERCIALCHART_END_NAMESPACE |
|
284 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,63 +1,67 | |||||
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 QChartSeries; |
|
12 | class QChartSeries; | |
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 { BackgroundZValue = -1 , ShadesZValue, GridZValue, AxisZValue , LineChartZValue }; |
|
23 | enum ZValues { BackgroundZValue = -1 , ShadesZValue, GridZValue, AxisZValue , LineChartZValue }; | |
24 |
|
24 | |||
25 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
25 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
26 | virtual ~ChartPresenter(); |
|
26 | virtual ~ChartPresenter(); | |
27 |
|
27 | |||
28 | void setMargin(int margin); |
|
28 | void setMargin(int margin); | |
29 | int margin() const; |
|
29 | int margin() const; | |
30 |
|
30 | |||
31 | QRectF geometry() const; |
|
31 | QRectF geometry() const; | |
32 |
|
32 | |||
33 | void setChartTheme(QChart::ChartTheme theme); |
|
33 | void setChartTheme(QChart::ChartTheme theme); | |
34 | QChart::ChartTheme chartTheme(); |
|
34 | QChart::ChartTheme chartTheme(); | |
35 |
|
35 | |||
|
36 | void setAnimationOptions(QChart::AnimationOptions options); | |||
|
37 | QChart::AnimationOptions animationOptions() const; | |||
|
38 | ||||
36 | private: |
|
39 | private: | |
37 | void createConnections(); |
|
40 | void createConnections(); | |
38 |
|
41 | |||
39 | public slots: |
|
42 | public slots: | |
40 | void handleSeriesAdded(QChartSeries* series); |
|
43 | void handleSeriesAdded(QChartSeries* series); | |
41 | void handleSeriesRemoved(QChartSeries* series); |
|
44 | void handleSeriesRemoved(QChartSeries* series); | |
42 | void handleAxisAdded(QChartAxis* axis); |
|
45 | void handleAxisAdded(QChartAxis* axis); | |
43 | void handleAxisRemoved(QChartAxis* axis); |
|
46 | void handleAxisRemoved(QChartAxis* axis); | |
44 | void handleSeriesDomainChanged(QChartSeries* series, const Domain& domain); |
|
47 | void handleSeriesDomainChanged(QChartSeries* series, const Domain& domain); | |
45 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); |
|
48 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
46 | void handleSeriesChanged(QChartSeries* series); |
|
49 | void handleSeriesChanged(QChartSeries* series); | |
47 | void handleGeometryChanged(); |
|
50 | void handleGeometryChanged(); | |
48 | signals: |
|
51 | signals: | |
49 | void geometryChanged(const QRectF& rect); |
|
52 | void geometryChanged(const QRectF& rect); | |
50 | private: |
|
53 | private: | |
51 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
54 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
52 | QMap<QChartAxis*,AxisItem*> m_axisItems; |
|
55 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |
53 | QChart* m_chart; |
|
56 | QChart* m_chart; | |
54 | ChartDataSet* m_dataset; |
|
57 | ChartDataSet* m_dataset; | |
55 | ChartTheme *m_chartTheme; |
|
58 | ChartTheme *m_chartTheme; | |
56 | int m_marginSize; |
|
59 | int m_marginSize; | |
57 | QRectF m_rect; |
|
60 | QRectF m_rect; | |
|
61 | QChart::AnimationOptions m_options; | |||
58 |
|
62 | |||
59 | }; |
|
63 | }; | |
60 |
|
64 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
66 | |||
63 | #endif /* CHARTPRESENTER_H_ */ |
|
67 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,258 +1,274 | |||||
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 <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QGraphicsSceneResizeEvent> |
|
6 | #include <QGraphicsSceneResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | /*! |
|
11 | /*! | |
12 | \enum QChart::ChartTheme |
|
12 | \enum QChart::ChartTheme | |
13 |
|
13 | |||
14 | This enum describes the theme used by the chart. |
|
14 | This enum describes the theme used by the chart. | |
15 |
|
15 | |||
16 | \value ChartThemeDefault |
|
16 | \value ChartThemeDefault | |
17 | \value ChartThemeVanilla |
|
17 | \value ChartThemeVanilla | |
18 | \value ChartThemeIcy |
|
18 | \value ChartThemeIcy | |
19 | \value ChartThemeGrayscale |
|
19 | \value ChartThemeGrayscale | |
20 | \value ChartThemeScientific |
|
20 | \value ChartThemeScientific | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | \class QChart |
|
24 | \class QChart | |
25 | \brief QtCommercial chart API. |
|
25 | \brief QtCommercial chart API. | |
26 |
|
26 | |||
27 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
27 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
28 | representation of different types of QChartSeries and other chart related objects like |
|
28 | representation of different types of QChartSeries and other chart related objects like | |
29 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
29 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
30 | convenience class QChartView instead of QChart. |
|
30 | convenience class QChartView instead of QChart. | |
31 | \sa QChartView |
|
31 | \sa QChartView | |
32 | */ |
|
32 | */ | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
35 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
36 | */ |
|
36 | */ | |
37 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
37 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
38 | m_backgroundItem(0), |
|
38 | m_backgroundItem(0), | |
39 | m_titleItem(0), |
|
39 | m_titleItem(0), | |
40 | m_dataset(new ChartDataSet(this)), |
|
40 | m_dataset(new ChartDataSet(this)), | |
41 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
41 | m_presenter(new ChartPresenter(this,m_dataset)) | |
42 | { |
|
42 | { | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
46 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
47 | */ |
|
47 | */ | |
48 | QChart::~QChart() |
|
48 | QChart::~QChart() | |
49 | { |
|
49 | { | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
53 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
54 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
54 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
55 | the y axis). |
|
55 | the y axis). | |
56 | */ |
|
56 | */ | |
57 | void QChart::addSeries(QChartSeries* series, QChartAxis* axisY) |
|
57 | void QChart::addSeries(QChartSeries* series, QChartAxis* axisY) | |
58 | { |
|
58 | { | |
59 | m_dataset->addSeries(series, axisY); |
|
59 | m_dataset->addSeries(series, axisY); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | Removes the \a series specified in a perameter from the QChartView. |
|
63 | Removes the \a series specified in a perameter from the QChartView. | |
64 | It releses its ownership of the specified QChartSeries object. |
|
64 | It releses its ownership of the specified QChartSeries object. | |
65 | It does not delete the pointed QChartSeries data object |
|
65 | It does not delete the pointed QChartSeries data object | |
66 | \sa addSeries(), removeAllSeries() |
|
66 | \sa addSeries(), removeAllSeries() | |
67 | */ |
|
67 | */ | |
68 | void QChart::removeSeries(QChartSeries* series) |
|
68 | void QChart::removeSeries(QChartSeries* series) | |
69 | { |
|
69 | { | |
70 | m_dataset->removeSeries(series); |
|
70 | m_dataset->removeSeries(series); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Removes all the QChartSeries that have been added to the QChartView |
|
74 | Removes all the QChartSeries that have been added to the QChartView | |
75 | It also deletes the pointed QChartSeries data objects |
|
75 | It also deletes the pointed QChartSeries data objects | |
76 | \sa addSeries(), removeSeries() |
|
76 | \sa addSeries(), removeSeries() | |
77 | */ |
|
77 | */ | |
78 | void QChart::removeAllSeries() |
|
78 | void QChart::removeAllSeries() | |
79 | { |
|
79 | { | |
80 | m_dataset->removeAllSeries(); |
|
80 | m_dataset->removeAllSeries(); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | Sets the \a brush that is used for painting the background of the chart area. |
|
84 | Sets the \a brush that is used for painting the background of the chart area. | |
85 | */ |
|
85 | */ | |
86 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
86 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
87 | { |
|
87 | { | |
88 | createChartBackgroundItem(); |
|
88 | createChartBackgroundItem(); | |
89 | m_backgroundItem->setBrush(brush); |
|
89 | m_backgroundItem->setBrush(brush); | |
90 | m_backgroundItem->update(); |
|
90 | m_backgroundItem->update(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | Sets the \a pen that is used for painting the background of the chart area. |
|
94 | Sets the \a pen that is used for painting the background of the chart area. | |
95 | */ |
|
95 | */ | |
96 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
96 | void QChart::setChartBackgroundPen(const QPen& pen) | |
97 | { |
|
97 | { | |
98 | createChartBackgroundItem(); |
|
98 | createChartBackgroundItem(); | |
99 | m_backgroundItem->setPen(pen); |
|
99 | m_backgroundItem->setPen(pen); | |
100 | m_backgroundItem->update(); |
|
100 | m_backgroundItem->update(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | Sets the chart \a title. The description text that is rendered above the chart. |
|
104 | Sets the chart \a title. The description text that is rendered above the chart. | |
105 | */ |
|
105 | */ | |
106 | void QChart::setChartTitle(const QString& title) |
|
106 | void QChart::setChartTitle(const QString& title) | |
107 | { |
|
107 | { | |
108 | createChartTitleItem(); |
|
108 | createChartTitleItem(); | |
109 | m_titleItem->setPlainText(title); |
|
109 | m_titleItem->setPlainText(title); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
113 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
114 | */ |
|
114 | */ | |
115 | void QChart::setChartTitleFont(const QFont& font) |
|
115 | void QChart::setChartTitleFont(const QFont& font) | |
116 | { |
|
116 | { | |
117 | createChartTitleItem(); |
|
117 | createChartTitleItem(); | |
118 | m_titleItem->setFont(font); |
|
118 | m_titleItem->setFont(font); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void QChart::createChartBackgroundItem() |
|
121 | void QChart::createChartBackgroundItem() | |
122 | { |
|
122 | { | |
123 | if(!m_backgroundItem) { |
|
123 | if(!m_backgroundItem) { | |
124 | m_backgroundItem = new QGraphicsRectItem(this); |
|
124 | m_backgroundItem = new QGraphicsRectItem(this); | |
125 | m_backgroundItem->setPen(Qt::NoPen); |
|
125 | m_backgroundItem->setPen(Qt::NoPen); | |
126 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
126 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void QChart::createChartTitleItem() |
|
130 | void QChart::createChartTitleItem() | |
131 | { |
|
131 | { | |
132 | if(!m_titleItem) { |
|
132 | if(!m_titleItem) { | |
133 | m_titleItem = new QGraphicsTextItem(this); |
|
133 | m_titleItem = new QGraphicsTextItem(this); | |
134 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
134 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
139 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
140 | \sa setMargin() |
|
140 | \sa setMargin() | |
141 | */ |
|
141 | */ | |
142 | int QChart::margin() const |
|
142 | int QChart::margin() const | |
143 | { |
|
143 | { | |
144 | return m_presenter->margin(); |
|
144 | return m_presenter->margin(); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
148 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
149 | \sa margin() |
|
149 | \sa margin() | |
150 | */ |
|
150 | */ | |
151 | void QChart::setMargin(int margin) |
|
151 | void QChart::setMargin(int margin) | |
152 | { |
|
152 | { | |
153 | m_presenter->setMargin(margin); |
|
153 | m_presenter->setMargin(margin); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
157 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
158 | \sa ChartTheme, chartTheme() |
|
158 | \sa ChartTheme, chartTheme() | |
159 | */ |
|
159 | */ | |
160 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
160 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
161 | { |
|
161 | { | |
162 | m_presenter->setChartTheme(theme); |
|
162 | m_presenter->setChartTheme(theme); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | Returns the theme enum used by the chart. |
|
166 | Returns the theme enum used by the chart. | |
167 | \sa ChartTheme, setChartTheme() |
|
167 | \sa ChartTheme, setChartTheme() | |
168 | */ |
|
168 | */ | |
169 | QChart::ChartTheme QChart::chartTheme() const |
|
169 | QChart::ChartTheme QChart::chartTheme() const | |
170 | { |
|
170 | { | |
171 | return m_presenter->chartTheme(); |
|
171 | return m_presenter->chartTheme(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Zooms in the view by a factor of 2 |
|
175 | Zooms in the view by a factor of 2 | |
176 | */ |
|
176 | */ | |
177 | void QChart::zoomIn() |
|
177 | void QChart::zoomIn() | |
178 | { |
|
178 | { | |
179 | if (!m_dataset->nextDomain()) { |
|
179 | if (!m_dataset->nextDomain()) { | |
180 | QRectF rect = m_presenter->geometry(); |
|
180 | QRectF rect = m_presenter->geometry(); | |
181 | rect.setWidth(rect.width()/2); |
|
181 | rect.setWidth(rect.width()/2); | |
182 | rect.setHeight(rect.height()/2); |
|
182 | rect.setHeight(rect.height()/2); | |
183 | rect.moveCenter(m_presenter->geometry().center()); |
|
183 | rect.moveCenter(m_presenter->geometry().center()); | |
184 | zoomIn(rect); |
|
184 | zoomIn(rect); | |
185 | } |
|
185 | } | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
189 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
190 | */ |
|
190 | */ | |
191 | void QChart::zoomIn(const QRectF& rect) |
|
191 | void QChart::zoomIn(const QRectF& rect) | |
192 | { |
|
192 | { | |
193 | if(!rect.isValid()) return; |
|
193 | if(!rect.isValid()) return; | |
194 | QRectF r = rect.normalized(); |
|
194 | QRectF r = rect.normalized(); | |
195 | int margin = m_presenter->margin(); |
|
195 | int margin = m_presenter->margin(); | |
196 | r.translate(-margin, -margin); |
|
196 | r.translate(-margin, -margin); | |
197 | m_dataset->addDomain(r,m_presenter->geometry()); |
|
197 | m_dataset->addDomain(r,m_presenter->geometry()); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Restores the view zoom level to the previous one. |
|
201 | Restores the view zoom level to the previous one. | |
202 | */ |
|
202 | */ | |
203 | void QChart::zoomOut() |
|
203 | void QChart::zoomOut() | |
204 | { |
|
204 | { | |
205 | m_dataset->previousDomain(); |
|
205 | m_dataset->previousDomain(); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | Resets to the default view. |
|
209 | Resets to the default view. | |
210 | */ |
|
210 | */ | |
211 | void QChart::zoomReset() |
|
211 | void QChart::zoomReset() | |
212 | { |
|
212 | { | |
213 | m_dataset->clearDomains(); |
|
213 | m_dataset->clearDomains(); | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | Returns the pointer to the x axis object of the chart |
|
217 | Returns the pointer to the x axis object of the chart | |
218 | */ |
|
218 | */ | |
219 | QChartAxis* QChart::axisX() const |
|
219 | QChartAxis* QChart::axisX() const | |
220 | { |
|
220 | { | |
221 | return m_dataset->axisX(); |
|
221 | return m_dataset->axisX(); | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | Returns the pointer to the y axis object of the chart |
|
225 | Returns the pointer to the y axis object of the chart | |
226 | */ |
|
226 | */ | |
227 | QChartAxis* QChart::axisY() const |
|
227 | QChartAxis* QChart::axisY() const | |
228 | { |
|
228 | { | |
229 | return m_dataset->axisY(); |
|
229 | return m_dataset->axisY(); | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | Resizes and updates the chart area using the \a event data |
|
233 | Resizes and updates the chart area using the \a event data | |
234 | */ |
|
234 | */ | |
235 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
235 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
236 | { |
|
236 | { | |
237 |
|
237 | |||
238 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
238 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
239 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
239 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
240 |
|
240 | |||
241 | // recalculate title position |
|
241 | // recalculate title position | |
242 | if (m_titleItem) { |
|
242 | if (m_titleItem) { | |
243 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
243 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
244 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
244 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | //recalculate background gradient |
|
247 | //recalculate background gradient | |
248 | if (m_backgroundItem) { |
|
248 | if (m_backgroundItem) { | |
249 | m_backgroundItem->setRect(rect); |
|
249 | m_backgroundItem->setRect(rect); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | QGraphicsWidget::resizeEvent(event); |
|
252 | QGraphicsWidget::resizeEvent(event); | |
253 | update(); |
|
253 | update(); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
|
256 | /*! | |||
|
257 | Sets animation options for the chart | |||
|
258 | */ | |||
|
259 | void QChart::setAnimationOptions(AnimationOptions options) | |||
|
260 | { | |||
|
261 | m_presenter->setAnimationOptions(options); | |||
|
262 | } | |||
|
263 | ||||
|
264 | /*! | |||
|
265 | Returns animation options for the chart | |||
|
266 | */ | |||
|
267 | QChart::AnimationOptions QChart::animationOptions() const | |||
|
268 | { | |||
|
269 | return m_presenter->animationOptions(); | |||
|
270 | } | |||
|
271 | ||||
256 | #include "moc_qchart.cpp" |
|
272 | #include "moc_qchart.cpp" | |
257 |
|
273 | |||
258 | QTCOMMERCIALCHART_END_NAMESPACE |
|
274 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,95 | |||||
1 | #ifndef QCHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define QCHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarPresenter; |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
25 | { |
|
25 | { | |
26 | Q_OBJECT |
|
26 | Q_OBJECT | |
27 | public: |
|
27 | public: | |
28 |
enum ChartTheme { |
|
28 | enum ChartTheme { | |
29 | ChartThemeDefault, |
|
29 | ChartThemeDefault, | |
30 | ChartThemeVanilla, |
|
30 | ChartThemeVanilla, | |
31 | ChartThemeIcy, |
|
31 | ChartThemeIcy, | |
32 | ChartThemeGrayscale, |
|
32 | ChartThemeGrayscale, | |
33 | ChartThemeScientific |
|
33 | ChartThemeScientific | |
34 | //ChartThemeUnnamed1 |
|
34 | //ChartThemeUnnamed1 | |
35 | /*! The default theme follows the GUI style of the Operating System */ |
|
35 | /*! The default theme follows the GUI style of the Operating System */ | |
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
|
38 | enum AnimationOption { | |||
|
39 | NoAnimation = 0x0, | |||
|
40 | GridAxisAnimations = 0x1, | |||
|
41 | SeriesAnimations =0x2, | |||
|
42 | AllAnimations = 0x3 | |||
|
43 | }; | |||
|
44 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |||
|
45 | ||||
38 | public: |
|
46 | public: | |
39 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
40 | ~QChart(); |
|
48 | ~QChart(); | |
41 |
|
49 | |||
42 | void addSeries(QChartSeries* series, QChartAxis* axisY = 0); |
|
50 | void addSeries(QChartSeries* series, QChartAxis* axisY = 0); | |
43 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached |
|
51 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached | |
44 | void removeAllSeries(); // deletes series and axis |
|
52 | void removeAllSeries(); // deletes series and axis | |
45 |
|
53 | |||
46 | void setMargin(int margin); |
|
54 | void setMargin(int margin); | |
47 | int margin() const; |
|
55 | int margin() const; | |
48 | void setChartTheme(QChart::ChartTheme theme); |
|
56 | void setChartTheme(QChart::ChartTheme theme); | |
49 | QChart::ChartTheme chartTheme() const; |
|
57 | QChart::ChartTheme chartTheme() const; | |
50 |
|
58 | |||
51 | void setChartTitle(const QString& title); |
|
59 | void setChartTitle(const QString& title); | |
52 | void setChartTitleFont(const QFont& font); |
|
60 | void setChartTitleFont(const QFont& font); | |
53 | void setChartBackgroundBrush(const QBrush& brush); |
|
61 | void setChartBackgroundBrush(const QBrush& brush); | |
54 | void setChartBackgroundPen(const QPen& pen); |
|
62 | void setChartBackgroundPen(const QPen& pen); | |
55 |
|
63 | |||
|
64 | void setAnimationOptions(AnimationOptions options); | |||
|
65 | AnimationOptions animationOptions() const; | |||
|
66 | ||||
56 | void zoomIn(); |
|
67 | void zoomIn(); | |
57 | void zoomIn(const QRectF& rect); |
|
68 | void zoomIn(const QRectF& rect); | |
58 | void zoomOut(); |
|
69 | void zoomOut(); | |
59 | void zoomReset(); |
|
70 | void zoomReset(); | |
60 |
|
71 | |||
61 | QChartAxis* axisX() const; |
|
72 | QChartAxis* axisX() const; | |
62 | QChartAxis* axisY() const; |
|
73 | QChartAxis* axisY() const; | |
63 |
|
74 | |||
64 | protected: |
|
75 | protected: | |
65 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
66 |
|
77 | |||
67 | private: |
|
78 | private: | |
68 | inline void createChartBackgroundItem(); |
|
79 | inline void createChartBackgroundItem(); | |
69 | inline void createChartTitleItem(); |
|
80 | inline void createChartTitleItem(); | |
70 |
|
81 | |||
71 | private: |
|
82 | private: | |
72 | Q_DISABLE_COPY(QChart) |
|
83 | Q_DISABLE_COPY(QChart) | |
73 | QGraphicsRectItem* m_backgroundItem; |
|
84 | QGraphicsRectItem* m_backgroundItem; | |
74 | QGraphicsTextItem* m_titleItem; |
|
85 | QGraphicsTextItem* m_titleItem; | |
75 | QRectF m_rect; |
|
86 | QRectF m_rect; | |
76 | ChartDataSet *m_dataset; |
|
87 | ChartDataSet *m_dataset; | |
77 | ChartPresenter *m_presenter; |
|
88 | ChartPresenter *m_presenter; | |
78 | }; |
|
89 | }; | |
79 |
|
90 | |||
80 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
81 |
|
92 | |||
|
93 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |||
|
94 | ||||
82 | #endif |
|
95 | #endif |
@@ -1,334 +1,350 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
7 | #include <QResizeEvent> |
|
7 | #include <QResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \enum QChartView::RubberBandPolicy |
|
11 | \enum QChartView::RubberBandPolicy | |
12 |
|
12 | |||
13 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
13 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
14 |
|
14 | |||
15 | \value NoRubberBand |
|
15 | \value NoRubberBand | |
16 | \value VerticalRubberBand |
|
16 | \value VerticalRubberBand | |
17 | \value HorizonalRubberBand |
|
17 | \value HorizonalRubberBand | |
18 | \value RectangleRubberBand |
|
18 | \value RectangleRubberBand | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \class QChartView |
|
22 | \class QChartView | |
23 | \brief Standalone charting widget. |
|
23 | \brief Standalone charting widget. | |
24 |
|
24 | |||
25 | QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. It manages the graphical |
|
25 | QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. It manages the graphical | |
26 | representation of different types of QChartSeries and other chart related objects like |
|
26 | representation of different types of QChartSeries and other chart related objects like | |
27 | QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
27 | QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
28 |
|
28 | |||
29 | \sa QChart |
|
29 | \sa QChart | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | Constructs a chartView object which is a child of a\a parent. |
|
35 | Constructs a chartView object which is a child of a\a parent. | |
36 | */ |
|
36 | */ | |
37 | QChartView::QChartView(QWidget *parent) : |
|
37 | QChartView::QChartView(QWidget *parent) : | |
38 | QGraphicsView(parent), |
|
38 | QGraphicsView(parent), | |
39 | m_scene(new QGraphicsScene(this)), |
|
39 | m_scene(new QGraphicsScene(this)), | |
40 | m_chart(new QChart()), |
|
40 | m_chart(new QChart()), | |
41 | m_rubberBand(0), |
|
41 | m_rubberBand(0), | |
42 | m_verticalRubberBand(false), |
|
42 | m_verticalRubberBand(false), | |
43 | m_horizonalRubberBand(false) |
|
43 | m_horizonalRubberBand(false) | |
44 | { |
|
44 | { | |
45 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
45 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
46 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
46 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
47 | setScene(m_scene); |
|
47 | setScene(m_scene); | |
48 | m_chart->setMargin(50); |
|
48 | m_chart->setMargin(50); | |
49 | m_scene->addItem(m_chart); |
|
49 | m_scene->addItem(m_chart); | |
50 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
50 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
55 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
56 | */ |
|
56 | */ | |
57 | QChartView::~QChartView() |
|
57 | QChartView::~QChartView() | |
58 | { |
|
58 | { | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | Resizes and updates the chart area using the \a event data |
|
62 | Resizes and updates the chart area using the \a event data | |
63 | */ |
|
63 | */ | |
64 | void QChartView::resizeEvent(QResizeEvent *event) |
|
64 | void QChartView::resizeEvent(QResizeEvent *event) | |
65 | { |
|
65 | { | |
66 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
66 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
67 | m_chart->resize(size()); |
|
67 | m_chart->resize(size()); | |
68 | QWidget::resizeEvent(event); |
|
68 | QWidget::resizeEvent(event); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
72 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
73 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
73 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
74 | the y axis). |
|
74 | the y axis). | |
75 | \sa removeSeries(), removeAllSeries() |
|
75 | \sa removeSeries(), removeAllSeries() | |
76 | */ |
|
76 | */ | |
77 | void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) |
|
77 | void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) | |
78 | { |
|
78 | { | |
79 | m_chart->addSeries(series,axisY); |
|
79 | m_chart->addSeries(series,axisY); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | Removes the \a series specified in a perameter from the QChartView. |
|
83 | Removes the \a series specified in a perameter from the QChartView. | |
84 | It releses its ownership of the specified QChartSeries object. |
|
84 | It releses its ownership of the specified QChartSeries object. | |
85 | It does not delete the pointed QChartSeries data object |
|
85 | It does not delete the pointed QChartSeries data object | |
86 | \sa addSeries(), removeAllSeries() |
|
86 | \sa addSeries(), removeAllSeries() | |
87 | */ |
|
87 | */ | |
88 | void QChartView::removeSeries(QChartSeries* series) |
|
88 | void QChartView::removeSeries(QChartSeries* series) | |
89 | { |
|
89 | { | |
90 | m_chart->removeSeries(series); |
|
90 | m_chart->removeSeries(series); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | Removes all the QChartSeries that have been added to the QChartView |
|
94 | Removes all the QChartSeries that have been added to the QChartView | |
95 | It also deletes the pointed QChartSeries data objects |
|
95 | It also deletes the pointed QChartSeries data objects | |
96 | \sa addSeries(), removeSeries() |
|
96 | \sa addSeries(), removeSeries() | |
97 | */ |
|
97 | */ | |
98 | void QChartView::removeAllSeries() |
|
98 | void QChartView::removeAllSeries() | |
99 | { |
|
99 | { | |
100 | m_chart->removeAllSeries(); |
|
100 | m_chart->removeAllSeries(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | Zooms in the view by a factor of 2 |
|
104 | Zooms in the view by a factor of 2 | |
105 | */ |
|
105 | */ | |
106 | void QChartView::zoomIn() |
|
106 | void QChartView::zoomIn() | |
107 | { |
|
107 | { | |
108 | m_chart->zoomIn(); |
|
108 | m_chart->zoomIn(); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
112 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
113 | */ |
|
113 | */ | |
114 | void QChartView::zoomIn(const QRect& rect) |
|
114 | void QChartView::zoomIn(const QRect& rect) | |
115 | { |
|
115 | { | |
116 | m_chart->zoomIn(rect); |
|
116 | m_chart->zoomIn(rect); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | Restores the view zoom level to the previous one. |
|
120 | Restores the view zoom level to the previous one. | |
121 | */ |
|
121 | */ | |
122 | void QChartView::zoomOut() |
|
122 | void QChartView::zoomOut() | |
123 | { |
|
123 | { | |
124 | m_chart->zoomOut(); |
|
124 | m_chart->zoomOut(); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
128 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
129 | */ |
|
129 | */ | |
130 | int QChartView::margin() const |
|
130 | int QChartView::margin() const | |
131 | { |
|
131 | { | |
132 | return m_chart->margin(); |
|
132 | return m_chart->margin(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Sets the chart \a title. A description text that is rendered above the chart. |
|
136 | Sets the chart \a title. A description text that is rendered above the chart. | |
137 | */ |
|
137 | */ | |
138 | void QChartView::setChartTitle(const QString& title) |
|
138 | void QChartView::setChartTitle(const QString& title) | |
139 | { |
|
139 | { | |
140 | m_chart->setChartTitle(title); |
|
140 | m_chart->setChartTitle(title); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
144 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
145 | */ |
|
145 | */ | |
146 | void QChartView::setChartTitleFont(const QFont& font) |
|
146 | void QChartView::setChartTitleFont(const QFont& font) | |
147 | { |
|
147 | { | |
148 | m_chart->setChartTitleFont(font); |
|
148 | m_chart->setChartTitleFont(font); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. |
|
152 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. | |
153 | */ |
|
153 | */ | |
154 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
154 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
155 | { |
|
155 | { | |
156 | m_chart->setChartBackgroundBrush(brush); |
|
156 | m_chart->setChartBackgroundBrush(brush); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. |
|
160 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. | |
161 | */ |
|
161 | */ | |
162 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
162 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
163 | { |
|
163 | { | |
164 | m_chart->setChartBackgroundPen(pen); |
|
164 | m_chart->setChartBackgroundPen(pen); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. |
|
168 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. | |
169 | */ |
|
169 | */ | |
170 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
170 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
171 | { |
|
171 | { | |
172 | switch(policy) { |
|
172 | switch(policy) { | |
173 | case VerticalRubberBand: |
|
173 | case VerticalRubberBand: | |
174 | m_verticalRubberBand = true; |
|
174 | m_verticalRubberBand = true; | |
175 | m_horizonalRubberBand = false; |
|
175 | m_horizonalRubberBand = false; | |
176 | break; |
|
176 | break; | |
177 | case HorizonalRubberBand: |
|
177 | case HorizonalRubberBand: | |
178 | m_verticalRubberBand = false; |
|
178 | m_verticalRubberBand = false; | |
179 | m_horizonalRubberBand = true; |
|
179 | m_horizonalRubberBand = true; | |
180 | break; |
|
180 | break; | |
181 | case RectangleRubberBand: |
|
181 | case RectangleRubberBand: | |
182 | m_verticalRubberBand = true; |
|
182 | m_verticalRubberBand = true; | |
183 | m_horizonalRubberBand = true; |
|
183 | m_horizonalRubberBand = true; | |
184 | break; |
|
184 | break; | |
185 | case NoRubberBand: |
|
185 | case NoRubberBand: | |
186 | default: |
|
186 | default: | |
187 | delete m_rubberBand; |
|
187 | delete m_rubberBand; | |
188 | m_rubberBand=0; |
|
188 | m_rubberBand=0; | |
189 | m_horizonalRubberBand = false; |
|
189 | m_horizonalRubberBand = false; | |
190 | m_verticalRubberBand = false; |
|
190 | m_verticalRubberBand = false; | |
191 | return; |
|
191 | return; | |
192 | } |
|
192 | } | |
193 | if(!m_rubberBand) { |
|
193 | if(!m_rubberBand) { | |
194 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
194 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
195 | m_rubberBand->setEnabled(true); |
|
195 | m_rubberBand->setEnabled(true); | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
200 | Returns the RubberBandPolicy that is currently being used by the widget. | |
201 | */ |
|
201 | */ | |
202 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
202 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
203 | { |
|
203 | { | |
204 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
204 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
205 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
205 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
206 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
206 | if(m_verticalRubberBand) return VerticalRubberBand; | |
207 | return NoRubberBand; |
|
207 | return NoRubberBand; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. |
|
211 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
212 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called. |
|
212 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called. | |
213 | */ |
|
213 | */ | |
214 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
214 | void QChartView::mousePressEvent(QMouseEvent *event) | |
215 | { |
|
215 | { | |
216 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
216 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
217 |
|
217 | |||
218 | int margin = m_chart->margin(); |
|
218 | int margin = m_chart->margin(); | |
219 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
219 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
220 |
|
220 | |||
221 | if (rect.contains(event->pos())) { |
|
221 | if (rect.contains(event->pos())) { | |
222 | m_rubberBandOrigin = event->pos(); |
|
222 | m_rubberBandOrigin = event->pos(); | |
223 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
223 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
224 | m_rubberBand->show(); |
|
224 | m_rubberBand->show(); | |
225 | event->accept(); |
|
225 | event->accept(); | |
226 | } |
|
226 | } | |
227 | } |
|
227 | } | |
228 | else { |
|
228 | else { | |
229 | QGraphicsView::mousePressEvent(event); |
|
229 | QGraphicsView::mousePressEvent(event); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
234 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
235 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
235 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
236 | */ |
|
236 | */ | |
237 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
237 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
238 | { |
|
238 | { | |
239 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
239 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
240 | int margin = m_chart->margin(); |
|
240 | int margin = m_chart->margin(); | |
241 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
241 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
242 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
242 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
243 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
243 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
244 | if(!m_verticalRubberBand) { |
|
244 | if(!m_verticalRubberBand) { | |
245 | m_rubberBandOrigin.setY(rect.top()); |
|
245 | m_rubberBandOrigin.setY(rect.top()); | |
246 | height = rect.height(); |
|
246 | height = rect.height(); | |
247 | } |
|
247 | } | |
248 | if(!m_horizonalRubberBand) { |
|
248 | if(!m_horizonalRubberBand) { | |
249 | m_rubberBandOrigin.setX(rect.left()); |
|
249 | m_rubberBandOrigin.setX(rect.left()); | |
250 | width= rect.width(); |
|
250 | width= rect.width(); | |
251 | } |
|
251 | } | |
252 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
252 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
253 | } |
|
253 | } | |
254 | else { |
|
254 | else { | |
255 | QGraphicsView::mouseMoveEvent(event); |
|
255 | QGraphicsView::mouseMoveEvent(event); | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand |
|
260 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
261 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
261 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
262 | */ |
|
262 | */ | |
263 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
263 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
264 | { |
|
264 | { | |
265 | if(m_rubberBand) { |
|
265 | if(m_rubberBand) { | |
266 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
266 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
267 | m_rubberBand->hide(); |
|
267 | m_rubberBand->hide(); | |
268 | QRect rect = m_rubberBand->geometry(); |
|
268 | QRect rect = m_rubberBand->geometry(); | |
269 | m_chart->zoomIn(rect); |
|
269 | m_chart->zoomIn(rect); | |
270 | event->accept(); |
|
270 | event->accept(); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | if(event->button()==Qt::RightButton) |
|
273 | if(event->button()==Qt::RightButton) | |
274 | m_chart->zoomReset(); |
|
274 | m_chart->zoomReset(); | |
275 | } |
|
275 | } | |
276 | else { |
|
276 | else { | |
277 | QGraphicsView::mouseReleaseEvent(event); |
|
277 | QGraphicsView::mouseReleaseEvent(event); | |
278 | } |
|
278 | } | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | /*! |
|
281 | /*! | |
282 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
282 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
283 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
283 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
284 | */ |
|
284 | */ | |
285 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
285 | void QChartView::keyPressEvent(QKeyEvent *event) | |
286 | { |
|
286 | { | |
287 | switch (event->key()) { |
|
287 | switch (event->key()) { | |
288 | case Qt::Key_Plus: |
|
288 | case Qt::Key_Plus: | |
289 | zoomIn(); |
|
289 | zoomIn(); | |
290 | break; |
|
290 | break; | |
291 | case Qt::Key_Minus: |
|
291 | case Qt::Key_Minus: | |
292 | zoomOut(); |
|
292 | zoomOut(); | |
293 | break; |
|
293 | break; | |
294 | default: |
|
294 | default: | |
295 | QGraphicsView::keyPressEvent(event); |
|
295 | QGraphicsView::keyPressEvent(event); | |
296 | break; |
|
296 | break; | |
297 | } |
|
297 | } | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | /*! |
|
300 | /*! | |
301 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
301 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
302 | \sa QChart::ChartTheme, chartTheme() |
|
302 | \sa QChart::ChartTheme, chartTheme() | |
303 | */ |
|
303 | */ | |
304 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
304 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
305 | { |
|
305 | { | |
306 | m_chart->setChartTheme(theme); |
|
306 | m_chart->setChartTheme(theme); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Returns the theme enum used by the chart. |
|
310 | Returns the theme enum used by the chart. | |
311 | \sa setChartTheme() |
|
311 | \sa setChartTheme() | |
312 | */ |
|
312 | */ | |
313 | QChart::ChartTheme QChartView::chartTheme() const |
|
313 | QChart::ChartTheme QChartView::chartTheme() const | |
314 | { |
|
314 | { | |
315 | return m_chart->chartTheme(); |
|
315 | return m_chart->chartTheme(); | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | /*! |
|
318 | /*! | |
319 | Returns the pointer to the x axis object of the chart |
|
319 | Returns the pointer to the x axis object of the chart | |
320 | */ |
|
320 | */ | |
321 | QChartAxis* QChartView::axisX() const |
|
321 | QChartAxis* QChartView::axisX() const | |
322 | { |
|
322 | { | |
323 | return m_chart->axisX(); |
|
323 | return m_chart->axisX(); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | Returns the pointer to the y axis object of the chart |
|
327 | Returns the pointer to the y axis object of the chart | |
328 | */ |
|
328 | */ | |
329 | QChartAxis* QChartView::axisY() const |
|
329 | QChartAxis* QChartView::axisY() const | |
330 | { |
|
330 | { | |
331 | return m_chart->axisY(); |
|
331 | return m_chart->axisY(); | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
|
334 | /*! | |||
|
335 | Sets animation options for the chart | |||
|
336 | */ | |||
|
337 | void QChartView::setAnimationOptions(QChart::AnimationOptions options) | |||
|
338 | { | |||
|
339 | m_chart->setAnimationOptions(options); | |||
|
340 | } | |||
|
341 | ||||
|
342 | /*! | |||
|
343 | Returns animation options for the chart | |||
|
344 | */ | |||
|
345 | QChart::AnimationOptions QChartView::animationOptions() const | |||
|
346 | { | |||
|
347 | return m_chart->animationOptions(); | |||
|
348 | } | |||
|
349 | ||||
334 | QTCOMMERCIALCHART_END_NAMESPACE |
|
350 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,71 +1,74 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 | class QRubberBand; |
|
10 | class QRubberBand; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class QChart; |
|
14 | class QChart; | |
15 |
|
15 | |||
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
17 | { |
|
17 | { | |
18 | public: |
|
18 | public: | |
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
20 |
|
20 | |||
21 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
22 | ~QChartView(); |
|
22 | ~QChartView(); | |
23 |
|
23 | |||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 | void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership |
|
27 | void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership | |
28 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached |
|
28 | void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached | |
29 | void removeAllSeries(); // deletes series and axis |
|
29 | void removeAllSeries(); // deletes series and axis | |
30 | int margin() const; |
|
30 | int margin() const; | |
31 |
|
31 | |||
32 | void setChartTitle(const QString& title); |
|
32 | void setChartTitle(const QString& title); | |
33 | void setChartTitleFont(const QFont& font); |
|
33 | void setChartTitleFont(const QFont& font); | |
34 | void setChartBackgroundBrush(const QBrush& brush); |
|
34 | void setChartBackgroundBrush(const QBrush& brush); | |
35 | void setChartBackgroundPen(const QPen& pen); |
|
35 | void setChartBackgroundPen(const QPen& pen); | |
36 |
|
36 | |||
37 | void zoomIn(); |
|
37 | void zoomIn(); | |
38 | void zoomIn(const QRect& rect); |
|
38 | void zoomIn(const QRect& rect); | |
39 | void zoomOut(); |
|
39 | void zoomOut(); | |
40 |
|
40 | |||
41 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
41 | void setRubberBandPolicy(const RubberBandPolicy ); | |
42 | RubberBandPolicy rubberBandPolicy() const; |
|
42 | RubberBandPolicy rubberBandPolicy() const; | |
43 |
|
43 | |||
44 | void setChartTheme(QChart::ChartTheme theme); |
|
44 | void setChartTheme(QChart::ChartTheme theme); | |
45 | QChart::ChartTheme chartTheme() const; |
|
45 | QChart::ChartTheme chartTheme() const; | |
46 |
|
46 | |||
|
47 | void setAnimationOptions(QChart::AnimationOptions options); | |||
|
48 | QChart::AnimationOptions animationOptions() const; | |||
|
49 | ||||
47 | QChartAxis* axisX() const; |
|
50 | QChartAxis* axisX() const; | |
48 | QChartAxis* axisY() const; |
|
51 | QChartAxis* axisY() const; | |
49 |
|
52 | |||
50 | protected: |
|
53 | protected: | |
51 | void mousePressEvent(QMouseEvent *event); |
|
54 | void mousePressEvent(QMouseEvent *event); | |
52 | void mouseMoveEvent(QMouseEvent *event); |
|
55 | void mouseMoveEvent(QMouseEvent *event); | |
53 | void mouseReleaseEvent(QMouseEvent *event); |
|
56 | void mouseReleaseEvent(QMouseEvent *event); | |
54 | void keyPressEvent(QKeyEvent *event); |
|
57 | void keyPressEvent(QKeyEvent *event); | |
55 |
|
58 | |||
56 |
|
59 | |||
57 | private: |
|
60 | private: | |
58 | QGraphicsScene *m_scene; |
|
61 | QGraphicsScene *m_scene; | |
59 | QChart* m_chart; |
|
62 | QChart* m_chart; | |
60 | QPoint m_rubberBandOrigin; |
|
63 | QPoint m_rubberBandOrigin; | |
61 | QRubberBand* m_rubberBand; |
|
64 | QRubberBand* m_rubberBand; | |
62 | bool m_verticalRubberBand; |
|
65 | bool m_verticalRubberBand; | |
63 | bool m_horizonalRubberBand; |
|
66 | bool m_horizonalRubberBand; | |
64 | Q_DISABLE_COPY(QChartView) |
|
67 | Q_DISABLE_COPY(QChartView) | |
65 |
|
68 | |||
66 |
|
69 | |||
67 | }; |
|
70 | }; | |
68 |
|
71 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
73 | |||
71 | #endif // QCHARTWIDGET_H |
|
74 | #endif // QCHARTWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now