@@ -1,393 +1,397 | |||||
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(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : |
|
11 | AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : | |
12 | ChartItem(parent), |
|
12 | ChartItem(parent), | |
13 | m_chartAxis(axis), |
|
13 | m_chartAxis(axis), | |
14 | m_type(type), |
|
14 | m_type(type), | |
15 | m_labelsAngle(0), |
|
15 | m_labelsAngle(0), | |
16 | m_grid(parent), |
|
16 | m_grid(parent), | |
17 | m_shades(parent), |
|
17 | m_shades(parent), | |
18 | m_labels(parent), |
|
18 | m_labels(parent), | |
19 | m_axis(parent) |
|
19 | m_axis(parent) | |
20 | { |
|
20 | { | |
21 | //initial initialization |
|
21 | //initial initialization | |
22 | m_axis.setZValue(ChartPresenter::AxisZValue); |
|
22 | m_axis.setZValue(ChartPresenter::AxisZValue); | |
23 | m_shades.setZValue(ChartPresenter::ShadesZValue); |
|
23 | m_shades.setZValue(ChartPresenter::ShadesZValue); | |
24 | m_grid.setZValue(ChartPresenter::GridZValue); |
|
24 | m_grid.setZValue(ChartPresenter::GridZValue); | |
25 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
25 | setFlags(QGraphicsItem::ItemHasNoContents); | |
26 |
|
26 | |||
27 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
27 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
|
28 | QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |||
28 | } |
|
29 | } | |
29 |
|
30 | |||
30 | AxisItem::~AxisItem() |
|
31 | AxisItem::~AxisItem() | |
31 | { |
|
32 | { | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | QRectF AxisItem::boundingRect() const |
|
35 | QRectF AxisItem::boundingRect() const | |
35 | { |
|
36 | { | |
36 | return QRectF(); |
|
37 | return QRectF(); | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | void AxisItem::createItems(int count) |
|
40 | void AxisItem::createItems(int count) | |
40 | { |
|
41 | { | |
41 | if(m_axis.children().size()==0) |
|
42 | if(m_axis.children().size()==0) | |
42 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
43 | m_axis.addToGroup(new QGraphicsLineItem()); | |
43 | for (int i = 0; i < count; ++i) { |
|
44 | for (int i = 0; i < count; ++i) { | |
44 | m_grid.addToGroup(new QGraphicsLineItem()); |
|
45 | m_grid.addToGroup(new QGraphicsLineItem()); | |
45 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); |
|
46 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); | |
46 | if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem()); |
|
47 | if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem()); | |
47 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
48 | m_axis.addToGroup(new QGraphicsLineItem()); | |
48 | } |
|
49 | } | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | void AxisItem::clear(int count) |
|
52 | void AxisItem::clear(int count) | |
52 | { |
|
53 | { | |
53 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
54 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
54 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
55 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
55 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
56 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
56 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
57 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
57 |
|
58 | |||
58 | for (int i = 0; i < count; ++i) { |
|
59 | for (int i = 0; i < count; ++i) { | |
59 | delete(lines.takeLast()); |
|
60 | delete(lines.takeLast()); | |
60 | delete(labels.takeLast()); |
|
61 | delete(labels.takeLast()); | |
61 | if(lines.size()%2) delete(shades.takeLast()); |
|
62 | if(lines.size()%2) delete(shades.takeLast()); | |
62 | delete(axis.takeLast()); |
|
63 | delete(axis.takeLast()); | |
63 | } |
|
64 | } | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
67 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
67 | { |
|
68 | { | |
68 | Q_UNUSED(painter); |
|
69 | Q_UNUSED(painter); | |
69 | Q_UNUSED(option); |
|
70 | Q_UNUSED(option); | |
70 | Q_UNUSED(widget); |
|
71 | Q_UNUSED(widget); | |
71 | } |
|
72 | } | |
72 |
|
73 | |||
73 | void AxisItem::updateItem() |
|
74 | void AxisItem::updateItem() | |
74 | { |
|
75 | { | |
75 | QStringList labels = createLabels(m_ticks,m_min,m_max); |
|
76 | QStringList labels = createLabels(m_ticks,m_min,m_max); | |
76 |
|
77 | |||
77 | int diff = m_thicksList.size() - labels.size(); |
|
78 | int diff = m_thicksList.size() - labels.size(); | |
78 |
|
79 | |||
79 | if(diff>0) { |
|
80 | if(diff>0) { | |
80 | clear(diff); |
|
81 | clear(diff); | |
81 | } |
|
82 | } | |
82 | else if(diff<0) { |
|
83 | else if(diff<0) { | |
83 | createItems(-diff); |
|
84 | createItems(-diff); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | if(diff!=0) handleAxisUpdated(); |
|
87 | if(diff!=0) handleAxisUpdated(); | |
87 |
|
88 | |||
88 | m_thicksList=labels; |
|
89 | m_thicksList=labels; | |
89 |
|
90 | |||
90 | QVector<qreal> layout = calculateLayout(); |
|
91 | QVector<qreal> layout = calculateLayout(); | |
91 | if(layout.count()==0) return; |
|
92 | if(layout.count()==0) return; | |
92 | setLayout(layout); |
|
93 | setLayout(layout); | |
93 |
|
94 | |||
94 | } |
|
95 | } | |
95 |
|
96 | |||
96 | QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) |
|
97 | QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) | |
97 | { |
|
98 | { | |
98 |
|
||||
99 |
|
||||
100 | Q_ASSERT(max>=min); |
|
99 | Q_ASSERT(max>=min); | |
101 |
|
100 | |||
102 | QStringList labels; |
|
101 | QStringList labels; | |
103 |
|
102 | |||
104 | //int ticks = axis->ticksCount()-1; |
|
103 | QChartAxisCategories* categories = m_chartAxis->categories(); | |
105 |
|
104 | |||
106 | for(int i=0; i<= ticks; i++) { |
|
105 | for(int i=0; i<= ticks; i++) { | |
107 | qreal value = min + (i * (max - min)/ ticks); |
|
106 | qreal value = min + (i * (max - min)/ ticks); | |
108 | QString label ;//= axis->axisTickLabel(value); |
|
107 | if(categories->count()==0) { | |
109 | if(label.isEmpty()) { |
|
|||
110 | labels << QString::number(value); |
|
108 | labels << QString::number(value); | |
111 | } |
|
109 | } | |
112 | else { |
|
110 | else { | |
|
111 | QString label = categories->label(value); | |||
113 | labels << label; |
|
112 | labels << label; | |
114 | } |
|
113 | } | |
115 | } |
|
114 | } | |
116 | return labels; |
|
115 | return labels; | |
117 | } |
|
116 | } | |
118 |
|
117 | |||
119 | void AxisItem::setAxisOpacity(qreal opacity) |
|
118 | void AxisItem::setAxisOpacity(qreal opacity) | |
120 | { |
|
119 | { | |
121 | m_axis.setOpacity(opacity); |
|
120 | m_axis.setOpacity(opacity); | |
122 | } |
|
121 | } | |
123 |
|
122 | |||
124 | qreal AxisItem::axisOpacity() const |
|
123 | qreal AxisItem::axisOpacity() const | |
125 | { |
|
124 | { | |
126 | return m_axis.opacity(); |
|
125 | return m_axis.opacity(); | |
127 | } |
|
126 | } | |
128 |
|
127 | |||
129 | void AxisItem::setGridOpacity(qreal opacity) |
|
128 | void AxisItem::setGridOpacity(qreal opacity) | |
130 | { |
|
129 | { | |
131 | m_grid.setOpacity(opacity); |
|
130 | m_grid.setOpacity(opacity); | |
132 | } |
|
131 | } | |
133 |
|
132 | |||
134 | qreal AxisItem::gridOpacity() const |
|
133 | qreal AxisItem::gridOpacity() const | |
135 | { |
|
134 | { | |
136 | return m_grid.opacity(); |
|
135 | return m_grid.opacity(); | |
137 | } |
|
136 | } | |
138 |
|
137 | |||
139 | void AxisItem::setLabelsOpacity(qreal opacity) |
|
138 | void AxisItem::setLabelsOpacity(qreal opacity) | |
140 | { |
|
139 | { | |
141 | m_labels.setOpacity(opacity); |
|
140 | m_labels.setOpacity(opacity); | |
142 | } |
|
141 | } | |
143 |
|
142 | |||
144 | qreal AxisItem::labelsOpacity() const |
|
143 | qreal AxisItem::labelsOpacity() const | |
145 | { |
|
144 | { | |
146 | return m_labels.opacity(); |
|
145 | return m_labels.opacity(); | |
147 | } |
|
146 | } | |
148 |
|
147 | |||
149 | void AxisItem::setShadesOpacity(qreal opacity) |
|
148 | void AxisItem::setShadesOpacity(qreal opacity) | |
150 | { |
|
149 | { | |
151 | m_shades.setOpacity(opacity); |
|
150 | m_shades.setOpacity(opacity); | |
152 | } |
|
151 | } | |
153 |
|
152 | |||
154 | qreal AxisItem::shadesOpacity() const |
|
153 | qreal AxisItem::shadesOpacity() const | |
155 | { |
|
154 | { | |
156 | return m_shades.opacity(); |
|
155 | return m_shades.opacity(); | |
157 | } |
|
156 | } | |
158 |
|
157 | |||
159 | void AxisItem::setLabelsAngle(int angle) |
|
158 | void AxisItem::setLabelsAngle(int angle) | |
160 | { |
|
159 | { | |
161 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
160 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
162 | QPointF center = item->boundingRect().center(); |
|
161 | QPointF center = item->boundingRect().center(); | |
163 | item->setRotation(angle); |
|
162 | item->setRotation(angle); | |
164 | } |
|
163 | } | |
165 |
|
164 | |||
166 | m_labelsAngle=angle; |
|
165 | m_labelsAngle=angle; | |
167 | } |
|
166 | } | |
168 |
|
167 | |||
169 | void AxisItem::setLabelsPen(const QPen& pen) |
|
168 | void AxisItem::setLabelsPen(const QPen& pen) | |
170 | { |
|
169 | { | |
171 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
170 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
172 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
171 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
173 | } |
|
172 | } | |
174 | } |
|
173 | } | |
175 |
|
174 | |||
176 | void AxisItem::setLabelsBrush(const QBrush& brush) |
|
175 | void AxisItem::setLabelsBrush(const QBrush& brush) | |
177 | { |
|
176 | { | |
178 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
177 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
179 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
178 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
180 | } |
|
179 | } | |
181 | } |
|
180 | } | |
182 |
|
181 | |||
183 | void AxisItem::setLabelsFont(const QFont& font) |
|
182 | void AxisItem::setLabelsFont(const QFont& font) | |
184 | { |
|
183 | { | |
185 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
184 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
186 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
185 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
187 | } |
|
186 | } | |
188 | } |
|
187 | } | |
189 |
|
188 | |||
190 | void AxisItem::setShadesBrush(const QBrush& brush) |
|
189 | void AxisItem::setShadesBrush(const QBrush& brush) | |
191 | { |
|
190 | { | |
192 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
191 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
193 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
192 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
194 | } |
|
193 | } | |
195 | } |
|
194 | } | |
196 |
|
195 | |||
197 | void AxisItem::setShadesPen(const QPen& pen) |
|
196 | void AxisItem::setShadesPen(const QPen& pen) | |
198 | { |
|
197 | { | |
199 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
198 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
200 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
199 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
201 | } |
|
200 | } | |
202 | } |
|
201 | } | |
203 |
|
202 | |||
204 | void AxisItem::setAxisPen(const QPen& pen) |
|
203 | void AxisItem::setAxisPen(const QPen& pen) | |
205 | { |
|
204 | { | |
206 | foreach(QGraphicsItem* item , m_axis.childItems()) { |
|
205 | foreach(QGraphicsItem* item , m_axis.childItems()) { | |
207 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
206 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
208 | } |
|
207 | } | |
209 | } |
|
208 | } | |
210 |
|
209 | |||
211 | void AxisItem::setGridPen(const QPen& pen) |
|
210 | void AxisItem::setGridPen(const QPen& pen) | |
212 | { |
|
211 | { | |
213 | foreach(QGraphicsItem* item , m_grid.childItems()) { |
|
212 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |
214 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
213 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
215 | } |
|
214 | } | |
216 | } |
|
215 | } | |
217 |
|
216 | |||
218 | QVector<qreal> AxisItem::calculateLayout() const |
|
217 | QVector<qreal> AxisItem::calculateLayout() const | |
219 | { |
|
218 | { | |
220 | QVector<qreal> points; |
|
219 | QVector<qreal> points; | |
221 | points.resize(m_thicksList.size()); |
|
220 | points.resize(m_thicksList.size()); | |
222 |
|
221 | |||
223 | switch (m_type) |
|
222 | switch (m_type) | |
224 | { |
|
223 | { | |
225 | case X_AXIS: |
|
224 | case X_AXIS: | |
226 | { |
|
225 | { | |
227 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); |
|
226 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); | |
228 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
227 | for (int i = 0; i < m_thicksList.size(); ++i) { | |
229 | int x = i * deltaX + m_rect.left(); |
|
228 | int x = i * deltaX + m_rect.left(); | |
230 | points[i] = x; |
|
229 | points[i] = x; | |
231 | } |
|
230 | } | |
232 | } |
|
231 | } | |
233 | break; |
|
232 | break; | |
234 | case Y_AXIS: |
|
233 | case Y_AXIS: | |
235 | { |
|
234 | { | |
236 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); |
|
235 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); | |
237 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
236 | for (int i = 0; i < m_thicksList.size(); ++i) { | |
238 | int y = i * -deltaY + m_rect.bottom(); |
|
237 | int y = i * -deltaY + m_rect.bottom(); | |
239 | points[i] = y; |
|
238 | points[i] = y; | |
240 | } |
|
239 | } | |
241 | } |
|
240 | } | |
242 | break; |
|
241 | break; | |
243 | } |
|
242 | } | |
244 | return points; |
|
243 | return points; | |
245 | } |
|
244 | } | |
246 |
|
245 | |||
247 | void AxisItem::setLayout(const QVector<qreal>& layout) |
|
246 | void AxisItem::setLayout(const QVector<qreal>& layout) | |
248 | { |
|
247 | { | |
249 |
|
248 | |||
250 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
249 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
251 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
250 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
252 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
251 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
253 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
252 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
254 |
|
253 | |||
255 | Q_ASSERT(labels.size() == m_thicksList.size()); |
|
254 | Q_ASSERT(labels.size() == m_thicksList.size()); | |
256 | Q_ASSERT(layout.size() == m_thicksList.size()); |
|
255 | Q_ASSERT(layout.size() == m_thicksList.size()); | |
257 |
|
256 | |||
258 | switch (m_type) |
|
257 | switch (m_type) | |
259 | { |
|
258 | { | |
260 | case X_AXIS: |
|
259 | case X_AXIS: | |
261 | { |
|
260 | { | |
262 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
261 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
263 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
262 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
264 |
|
263 | |||
265 | for (int i = 0; i < layout.size(); ++i) { |
|
264 | for (int i = 0; i < layout.size(); ++i) { | |
266 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
265 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
267 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
266 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
268 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
267 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
269 | labelItem->setText(m_thicksList.at(i)); |
|
268 | labelItem->setText(m_thicksList.at(i)); | |
270 | QPointF center = labelItem->boundingRect().center(); |
|
269 | QPointF center = labelItem->boundingRect().center(); | |
271 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
270 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
272 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
271 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
273 | if(i%2){ |
|
272 | if(i%2 && i+1 < layout.size()){ | |
274 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
273 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |
275 | rectItem->setRect(layout[i],m_rect.top(),layout[i+1]-layout[i],m_rect.height()); |
|
274 | rectItem->setRect(layout[i],m_rect.top(),layout[i+1]-layout[i],m_rect.height()); | |
276 | } |
|
275 | } | |
277 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
276 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
278 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
277 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
279 | } |
|
278 | } | |
280 | } |
|
279 | } | |
281 | break; |
|
280 | break; | |
282 |
|
281 | |||
283 | case Y_AXIS: |
|
282 | case Y_AXIS: | |
284 | { |
|
283 | { | |
285 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
284 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
286 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
285 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
287 |
|
286 | |||
288 | for (int i = 0; i < layout.size(); ++i) { |
|
287 | for (int i = 0; i < layout.size(); ++i) { | |
289 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
288 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
290 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
289 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
291 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
290 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
292 | labelItem->setText(m_thicksList.at(i)); |
|
291 | labelItem->setText(m_thicksList.at(i)); | |
293 | QPointF center = labelItem->boundingRect().center(); |
|
292 | QPointF center = labelItem->boundingRect().center(); | |
294 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
293 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
295 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y()); |
|
294 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y()); | |
296 | if(i%2){ |
|
295 | if(i%2 && i+1 < layout.size()){ | |
297 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
296 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |
298 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i]-layout[i+1]); |
|
297 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i]-layout[i+1]); | |
299 | } |
|
298 | } | |
300 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
299 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
301 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
300 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
302 | } |
|
301 | } | |
303 | } |
|
302 | } | |
304 | break; |
|
303 | break; | |
305 | default: |
|
304 | default: | |
306 | qDebug()<<"Unknown axis type"; |
|
305 | qDebug()<<"Unknown axis type"; | |
307 | break; |
|
306 | break; | |
308 | } |
|
307 | } | |
309 |
|
308 | |||
310 | m_layoutVector=layout; |
|
309 | m_layoutVector=layout; | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | //handlers |
|
312 | //handlers | |
314 |
|
313 | |||
|
314 | void AxisItem::handleAxisCategoriesUpdated() | |||
|
315 | { | |||
|
316 | updateItem(); | |||
|
317 | } | |||
|
318 | ||||
315 | void AxisItem::handleAxisUpdated() |
|
319 | void AxisItem::handleAxisUpdated() | |
316 | { |
|
320 | { | |
|
321 | ||||
|
322 | int count = m_chartAxis->ticksCount(); | |||
|
323 | ||||
|
324 | if(m_ticks!=count){ | |||
|
325 | m_ticks=count; | |||
|
326 | updateItem(); | |||
|
327 | } | |||
|
328 | ||||
317 | if(isEmpty()) return; |
|
329 | if(isEmpty()) return; | |
318 |
|
330 | |||
319 | if(m_chartAxis->isAxisVisible()) { |
|
331 | if(m_chartAxis->isAxisVisible()) { | |
320 | setAxisOpacity(100); |
|
332 | setAxisOpacity(100); | |
321 | } |
|
333 | } | |
322 | else { |
|
334 | else { | |
323 | setAxisOpacity(0); |
|
335 | setAxisOpacity(0); | |
324 | } |
|
336 | } | |
325 |
|
337 | |||
326 | if(m_chartAxis->isGridVisible()) { |
|
338 | if(m_chartAxis->isGridVisible()) { | |
327 | setGridOpacity(100); |
|
339 | setGridOpacity(100); | |
328 | } |
|
340 | } | |
329 | else { |
|
341 | else { | |
330 | setGridOpacity(0); |
|
342 | setGridOpacity(0); | |
331 | } |
|
343 | } | |
332 |
|
344 | |||
333 | if(m_chartAxis->labelsVisible()) |
|
345 | if(m_chartAxis->labelsVisible()) | |
334 | { |
|
346 | { | |
335 | setLabelsOpacity(100); |
|
347 | setLabelsOpacity(100); | |
336 | } |
|
348 | } | |
337 | else { |
|
349 | else { | |
338 | setLabelsOpacity(0); |
|
350 | setLabelsOpacity(0); | |
339 | } |
|
351 | } | |
340 |
|
352 | |||
341 | if(m_chartAxis->shadesVisible()) { |
|
353 | if(m_chartAxis->shadesVisible()) { | |
342 | setShadesOpacity(m_chartAxis->shadesOpacity()); |
|
354 | setShadesOpacity(m_chartAxis->shadesOpacity()); | |
343 | } |
|
355 | } | |
344 | else { |
|
356 | else { | |
345 | setShadesOpacity(0); |
|
357 | setShadesOpacity(0); | |
346 | } |
|
358 | } | |
347 |
|
359 | |||
348 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
360 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
349 | setAxisPen(m_chartAxis->axisPen()); |
|
361 | setAxisPen(m_chartAxis->axisPen()); | |
350 | setLabelsPen(m_chartAxis->labelsPen()); |
|
362 | setLabelsPen(m_chartAxis->labelsPen()); | |
351 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
363 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
352 | setLabelsFont(m_chartAxis->labelsFont()); |
|
364 | setLabelsFont(m_chartAxis->labelsFont()); | |
353 | setGridPen(m_chartAxis->gridPen()); |
|
365 | setGridPen(m_chartAxis->gridPen()); | |
354 | setShadesPen(m_chartAxis->shadesPen()); |
|
366 | setShadesPen(m_chartAxis->shadesPen()); | |
355 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
367 | setShadesBrush(m_chartAxis->shadesBrush()); | |
356 |
|
368 | |||
357 | } |
|
369 | } | |
358 |
|
370 | |||
359 | void AxisItem::handleRangeChanged(qreal min, qreal max) |
|
371 | void AxisItem::handleRangeChanged(qreal min, qreal max) | |
360 | { |
|
372 | { | |
361 |
|
373 | |||
362 | m_min = min; |
|
374 | m_min = min; | |
363 | m_max = max; |
|
375 | m_max = max; | |
364 |
|
376 | |||
365 | if(isEmpty()) return; |
|
377 | if(isEmpty()) return; | |
366 | updateItem(); |
|
378 | updateItem(); | |
367 |
|
379 | |||
368 | } |
|
380 | } | |
369 |
|
381 | |||
370 | void AxisItem::handleTicksCountChanged(int ticks) |
|
|||
371 | { |
|
|||
372 | m_ticks=ticks; |
|
|||
373 |
|
||||
374 | if(isEmpty()) return; |
|
|||
375 | updateItem(); |
|
|||
376 | } |
|
|||
377 |
|
||||
378 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
382 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |
379 | { |
|
383 | { | |
380 | m_rect = rect; |
|
384 | m_rect = rect; | |
381 | if(isEmpty()) return; |
|
385 | if(isEmpty()) return; | |
382 | updateItem(); |
|
386 | updateItem(); | |
383 | } |
|
387 | } | |
384 |
|
388 | |||
385 | bool AxisItem::isEmpty() |
|
389 | bool AxisItem::isEmpty() | |
386 | { |
|
390 | { | |
387 | return m_rect.isEmpty() || m_min==m_max || m_ticks==0; |
|
391 | return m_rect.isEmpty() || m_min==m_max || m_ticks==0; | |
388 | } |
|
392 | } | |
389 |
|
393 | |||
390 | //TODO "nice numbers algorithm" |
|
394 | //TODO "nice numbers algorithm" | |
391 | #include "moc_axisitem_p.cpp" |
|
395 | #include "moc_axisitem_p.cpp" | |
392 |
|
396 | |||
393 | QTCOMMERCIALCHART_END_NAMESPACE |
|
397 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,88 +1,89 | |||||
1 | #ifndef AXISITEM_H_ |
|
1 | #ifndef AXISITEM_H_ | |
2 | #define AXISITEM_H_ |
|
2 | #define AXISITEM_H_ | |
3 |
|
3 | |||
4 | #include "domain_p.h" |
|
4 | #include "domain_p.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class AxisItem : public QObject, public ChartItem |
|
12 | class AxisItem : public QObject, public ChartItem | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | enum AxisType{X_AXIS,Y_AXIS}; |
|
16 | enum AxisType{X_AXIS,Y_AXIS}; | |
17 |
|
17 | |||
18 | AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); |
|
18 | AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisItem(); |
|
19 | ~AxisItem(); | |
20 |
|
20 | |||
21 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
22 | QRectF boundingRect() const; |
|
22 | QRectF boundingRect() const; | |
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
24 |
|
24 | |||
25 | AxisType axisType() const {return m_type;}; |
|
25 | AxisType axisType() const {return m_type;}; | |
26 |
|
26 | |||
27 | void setAxisOpacity(qreal opacity); |
|
27 | void setAxisOpacity(qreal opacity); | |
28 | qreal axisOpacity() const; |
|
28 | qreal axisOpacity() const; | |
29 |
|
29 | |||
30 | void setGridOpacity(qreal opacity); |
|
30 | void setGridOpacity(qreal opacity); | |
31 | qreal gridOpacity() const; |
|
31 | qreal gridOpacity() const; | |
32 |
|
32 | |||
33 | void setLabelsOpacity(qreal opacity); |
|
33 | void setLabelsOpacity(qreal opacity); | |
34 | qreal labelsOpacity() const; |
|
34 | qreal labelsOpacity() const; | |
35 |
|
35 | |||
36 | void setShadesOpacity(qreal opacity); |
|
36 | void setShadesOpacity(qreal opacity); | |
37 | qreal shadesOpacity() const; |
|
37 | qreal shadesOpacity() const; | |
38 |
|
38 | |||
39 | void setLabelsAngle(int angle); |
|
39 | void setLabelsAngle(int angle); | |
40 | int labelsAngle()const { return m_labelsAngle; } |
|
40 | int labelsAngle()const { return m_labelsAngle; } | |
41 |
|
41 | |||
42 | void setShadesBrush(const QBrush& brush); |
|
42 | void setShadesBrush(const QBrush& brush); | |
43 | void setShadesPen(const QPen& pen); |
|
43 | void setShadesPen(const QPen& pen); | |
44 |
|
44 | |||
45 | void setAxisPen(const QPen& pen); |
|
45 | void setAxisPen(const QPen& pen); | |
46 | void setGridPen(const QPen& pen); |
|
46 | void setGridPen(const QPen& pen); | |
47 |
|
47 | |||
48 | void setLabelsPen(const QPen& pen); |
|
48 | void setLabelsPen(const QPen& pen); | |
49 | void setLabelsBrush(const QBrush& brush); |
|
49 | void setLabelsBrush(const QBrush& brush); | |
50 | void setLabelsFont(const QFont& font); |
|
50 | void setLabelsFont(const QFont& font); | |
51 |
|
51 | |||
52 | public slots: |
|
52 | public slots: | |
53 | void handleAxisUpdated();//qchartaxis update calls |
|
53 | void handleAxisUpdated();//qchartaxis update calls | |
|
54 | void handleAxisCategoriesUpdated();//qchartaxis update calls | |||
54 | void handleRangeChanged(qreal min , qreal max); //domain update calls |
|
55 | void handleRangeChanged(qreal min , qreal max); //domain update calls | |
55 | void handleTicksCountChanged(int ticks); //ticks changed |
|
|||
56 | void handleGeometryChanged(const QRectF& size); //geometry update calls |
|
56 | void handleGeometryChanged(const QRectF& size); //geometry update calls | |
57 |
|
57 | |||
58 | public: |
|
58 | public: | |
59 | virtual void updateItem(); |
|
59 | virtual void updateItem(); | |
60 | QVector<qreal> calculateLayout() const; |
|
60 | QVector<qreal> calculateLayout() const; | |
61 | void setLayout(const QVector<qreal>& points); |
|
61 | void setLayout(const QVector<qreal>& points); | |
62 | QVector<qreal> layout() { return m_layoutVector;}; |
|
62 | QVector<qreal> layout() { return m_layoutVector;}; | |
63 |
|
63 | |||
64 | private: |
|
64 | private: | |
65 | inline bool isEmpty(); |
|
65 | inline bool isEmpty(); | |
66 | void clear(int count); |
|
66 | void clear(int count); | |
67 | void createItems(int count); |
|
67 | void createItems(int count); | |
68 | QStringList createLabels(int ticks, qreal min, qreal max); |
|
68 | QStringList createLabels(int ticks, qreal min, qreal max); | |
|
69 | ||||
69 | private: |
|
70 | private: | |
70 | QChartAxis* m_chartAxis; |
|
71 | QChartAxis* m_chartAxis; | |
71 | AxisType m_type; |
|
72 | AxisType m_type; | |
72 | QRectF m_rect; |
|
73 | QRectF m_rect; | |
73 | int m_labelsAngle; |
|
74 | int m_labelsAngle; | |
74 | QGraphicsItemGroup m_grid; |
|
75 | QGraphicsItemGroup m_grid; | |
75 | QGraphicsItemGroup m_shades; |
|
76 | QGraphicsItemGroup m_shades; | |
76 | QGraphicsItemGroup m_labels; |
|
77 | QGraphicsItemGroup m_labels; | |
77 | QGraphicsItemGroup m_axis; |
|
78 | QGraphicsItemGroup m_axis; | |
78 | QStringList m_thicksList; |
|
79 | QStringList m_thicksList; | |
79 | QVector<qreal> m_layoutVector; |
|
80 | QVector<qreal> m_layoutVector; | |
80 | qreal m_min; |
|
81 | qreal m_min; | |
81 | qreal m_max; |
|
82 | qreal m_max; | |
82 | int m_ticks; |
|
83 | int m_ticks; | |
83 |
|
84 | |||
84 | }; |
|
85 | }; | |
85 |
|
86 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
87 |
|
88 | |||
88 | #endif /* AXISITEM_H_ */ |
|
89 | #endif /* AXISITEM_H_ */ |
@@ -1,103 +1,103 | |||||
1 | #ifndef QCHARTAXIS_H_ |
|
1 | #ifndef QCHARTAXIS_H_ | |
2 | #define QCHARTAXIS_H_ |
|
2 | #define QCHARTAXIS_H_ | |
3 |
|
3 | |||
4 | #include <qchartaxiscategories.h> |
|
4 | #include <qchartaxiscategories.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 | #include <QFont> |
|
6 | #include <QFont> | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject |
|
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | QChartAxis(QObject* parent =0); |
|
15 | QChartAxis(QObject* parent =0); | |
16 | ~QChartAxis(); |
|
16 | ~QChartAxis(); | |
17 |
|
17 | |||
18 | //axis handling |
|
18 | //axis handling | |
19 | bool isAxisVisible() const { return m_axisVisible;}; |
|
19 | bool isAxisVisible() const { return m_axisVisible;}; | |
20 | void setAxisVisible(bool visible); |
|
20 | void setAxisVisible(bool visible); | |
21 | void setAxisPen(const QPen& pen); |
|
21 | void setAxisPen(const QPen& pen); | |
22 | QPen axisPen() const { return m_axisPen;}; |
|
22 | QPen axisPen() const { return m_axisPen;}; | |
23 |
|
23 | |||
24 | //grid handling |
|
24 | //grid handling | |
25 | bool isGridVisible() const { return m_gridVisible;}; |
|
25 | bool isGridVisible() const { return m_gridVisible;}; | |
26 | void setGridVisible(bool visible); |
|
26 | void setGridVisible(bool visible); | |
27 | void setGridPen(const QPen& pen); |
|
27 | void setGridPen(const QPen& pen); | |
28 | QPen gridPen() const {return m_gridPen;} |
|
28 | QPen gridPen() const {return m_gridPen;} | |
29 |
|
29 | |||
30 | //labels handling |
|
30 | //labels handling | |
31 | bool labelsVisible() const { return m_labelsVisible;}; |
|
31 | bool labelsVisible() const { return m_labelsVisible;}; | |
32 | void setLabelsVisible(bool visible); |
|
32 | void setLabelsVisible(bool visible); | |
33 | void setLabelsPen(const QPen& pen); |
|
33 | void setLabelsPen(const QPen& pen); | |
34 | QPen labelsPen() const { return m_labelsPen;} |
|
34 | QPen labelsPen() const { return m_labelsPen;} | |
35 | void setLabelsBrush(const QBrush& brush); |
|
35 | void setLabelsBrush(const QBrush& brush); | |
36 | QBrush labelsBrush() const { return m_labelsBrush;} |
|
36 | QBrush labelsBrush() const { return m_labelsBrush;} | |
37 | void setLabelsFont(const QFont& font); |
|
37 | void setLabelsFont(const QFont& font); | |
38 | QFont labelsFont() const { return m_labelsFont;} |
|
38 | QFont labelsFont() const { return m_labelsFont;} | |
39 | void setLabelsAngle(int angle); |
|
39 | void setLabelsAngle(int angle); | |
40 | int labelsAngle() const { return m_labelsAngle;}; |
|
40 | int labelsAngle() const { return m_labelsAngle;}; | |
41 |
|
41 | |||
42 | //shades handling |
|
42 | //shades handling | |
43 | bool shadesVisible() const { return m_shadesVisible;}; |
|
43 | bool shadesVisible() const { return m_shadesVisible;}; | |
44 | void setShadesVisible(bool visible); |
|
44 | void setShadesVisible(bool visible); | |
45 | void setShadesPen(const QPen& pen); |
|
45 | void setShadesPen(const QPen& pen); | |
46 | QPen shadesPen() const { return m_shadesPen;} |
|
46 | QPen shadesPen() const { return m_shadesPen;} | |
47 | void setShadesBrush(const QBrush& brush); |
|
47 | void setShadesBrush(const QBrush& brush); | |
48 | QBrush shadesBrush() const { return m_shadesBrush;} |
|
48 | QBrush shadesBrush() const { return m_shadesBrush;} | |
49 | void setShadesOpacity(qreal opacity); |
|
49 | void setShadesOpacity(qreal opacity); | |
50 | qreal shadesOpacity() const { return m_shadesOpacity;} |
|
50 | qreal shadesOpacity() const { return m_shadesOpacity;} | |
51 |
|
51 | |||
52 | //range handling |
|
52 | //range handling | |
53 | void setMin(qreal min); |
|
53 | void setMin(qreal min); | |
54 | qreal min() const { return m_min;}; |
|
54 | qreal min() const { return m_min;}; | |
55 | void setMax(qreal max); |
|
55 | void setMax(qreal max); | |
56 | qreal max() const { return m_max;}; |
|
56 | qreal max() const { return m_max;}; | |
57 | void setRange(qreal min, qreal max); |
|
57 | void setRange(qreal min, qreal max); | |
58 |
|
58 | |||
59 | //ticks handling |
|
59 | //ticks handling | |
60 | void setTicksCount(int count); |
|
60 | void setTicksCount(int count); | |
61 | int ticksCount() const { return m_ticksCount;} |
|
61 | int ticksCount() const { return m_ticksCount;} | |
62 |
|
62 | |||
63 |
QChartAxisCategories |
|
63 | QChartAxisCategories* categories() { return &m_category; } | |
64 |
|
64 | |||
65 | signals: |
|
65 | signals: | |
66 | void minChanged(qreal min); |
|
66 | void minChanged(qreal min); | |
67 | void maxChanged(qreal max); |
|
67 | void maxChanged(qreal max); | |
68 | void rangeChanged(qreal min, qreal max); |
|
68 | void rangeChanged(qreal min, qreal max); | |
69 |
|
69 | |||
70 | //interal signal |
|
70 | //interal signal | |
71 | void updated(); |
|
71 | void updated(); | |
72 | //internal slot |
|
72 | //internal slot | |
73 | public slots: |
|
73 | public slots: | |
74 | void handleAxisRangeChanged(qreal min, qreal max); |
|
74 | void handleAxisRangeChanged(qreal min, qreal max); | |
75 |
|
75 | |||
76 | private: |
|
76 | private: | |
77 | bool m_axisVisible; |
|
77 | bool m_axisVisible; | |
78 | QPen m_axisPen; |
|
78 | QPen m_axisPen; | |
79 | QBrush m_axisBrush; |
|
79 | QBrush m_axisBrush; | |
80 |
|
80 | |||
81 | bool m_gridVisible; |
|
81 | bool m_gridVisible; | |
82 | QPen m_gridPen; |
|
82 | QPen m_gridPen; | |
83 |
|
83 | |||
84 | bool m_labelsVisible; |
|
84 | bool m_labelsVisible; | |
85 | QPen m_labelsPen; |
|
85 | QPen m_labelsPen; | |
86 | QBrush m_labelsBrush; |
|
86 | QBrush m_labelsBrush; | |
87 | QFont m_labelsFont; |
|
87 | QFont m_labelsFont; | |
88 | int m_labelsAngle; |
|
88 | int m_labelsAngle; | |
89 |
|
89 | |||
90 | bool m_shadesVisible; |
|
90 | bool m_shadesVisible; | |
91 | QPen m_shadesPen; |
|
91 | QPen m_shadesPen; | |
92 | QBrush m_shadesBrush; |
|
92 | QBrush m_shadesBrush; | |
93 | qreal m_shadesOpacity; |
|
93 | qreal m_shadesOpacity; | |
94 |
|
94 | |||
95 | qreal m_min; |
|
95 | qreal m_min; | |
96 | qreal m_max; |
|
96 | qreal m_max; | |
97 |
|
97 | |||
98 | int m_ticksCount; |
|
98 | int m_ticksCount; | |
99 | QChartAxisCategories m_category; |
|
99 | QChartAxisCategories m_category; | |
100 | }; |
|
100 | }; | |
101 |
|
101 | |||
102 | QTCOMMERCIALCHART_END_NAMESPACE |
|
102 | QTCOMMERCIALCHART_END_NAMESPACE | |
103 | #endif /* QCHARTAXIS_H_ */ |
|
103 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,39 +1,44 | |||||
1 | #include "qchartaxiscategories.h" |
|
1 | #include "qchartaxiscategories.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QChartAxisCategories::QChartAxisCategories() |
|
5 | QChartAxisCategories::QChartAxisCategories() | |
6 | { |
|
6 | { | |
7 | // TODO Auto-generated constructor stub |
|
7 | // TODO Auto-generated constructor stub | |
8 |
|
8 | |||
9 | } |
|
9 | } | |
10 |
|
10 | |||
11 | QChartAxisCategories::~QChartAxisCategories() |
|
11 | QChartAxisCategories::~QChartAxisCategories() | |
12 | { |
|
12 | { | |
13 | // TODO Auto-generated destructor stub |
|
13 | // TODO Auto-generated destructor stub | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | void QChartAxisCategories::insert(qreal value,QString label) |
|
16 | void QChartAxisCategories::insert(qreal value,QString label) | |
17 | { |
|
17 | { | |
18 | m_map.insert(value,label); |
|
18 | m_map.insert(value,label); | |
19 | emit updated(); |
|
19 | emit updated(); | |
20 | } |
|
20 | } | |
21 | void QChartAxisCategories::remove(qreal value) |
|
21 | void QChartAxisCategories::remove(qreal value) | |
22 | { |
|
22 | { | |
23 | m_map.remove(value); |
|
23 | m_map.remove(value); | |
24 | emit updated(); |
|
24 | emit updated(); | |
25 | } |
|
25 | } | |
26 | void QChartAxisCategories::clear() |
|
26 | void QChartAxisCategories::clear() | |
27 | { |
|
27 | { | |
28 | m_map.clear(); |
|
28 | m_map.clear(); | |
29 | emit updated(); |
|
29 | emit updated(); | |
30 | } |
|
30 | } | |
31 | int QChartAxisCategories::count() |
|
31 | int QChartAxisCategories::count() | |
32 | { |
|
32 | { | |
33 | return m_map.count(); |
|
33 | return m_map.count(); | |
34 | emit updated(); |
|
34 | emit updated(); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
|
37 | QString QChartAxisCategories::label(qreal value) const | |||
|
38 | { | |||
|
39 | return m_map.value(value); | |||
|
40 | } | |||
|
41 | ||||
37 | #include "moc_qchartaxiscategories.cpp" |
|
42 | #include "moc_qchartaxiscategories.cpp" | |
38 |
|
43 | |||
39 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,33 +1,34 | |||||
1 | #ifndef QCHARTAXISCATEGORIES_H_ |
|
1 | #ifndef QCHARTAXISCATEGORIES_H_ | |
2 | #define QCHARTAXISCATEGORIES_H_ |
|
2 | #define QCHARTAXISCATEGORIES_H_ | |
3 | #include "qchartglobal.h" |
|
3 | #include "qchartglobal.h" | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject |
|
7 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject | |
8 | { |
|
8 | { | |
9 | Q_OBJECT |
|
9 | Q_OBJECT | |
10 | private: |
|
10 | private: | |
11 | QChartAxisCategories(); |
|
11 | QChartAxisCategories(); | |
12 | public: |
|
12 | public: | |
13 | ~QChartAxisCategories(); |
|
13 | ~QChartAxisCategories(); | |
14 |
|
14 | |||
15 | void insert(qreal value,QString label); |
|
15 | void insert(qreal value,QString label); | |
16 | void remove(qreal value); |
|
16 | void remove(qreal value); | |
|
17 | QString label(qreal value) const; | |||
17 | void clear(); |
|
18 | void clear(); | |
18 | int count(); |
|
19 | int count(); | |
19 |
|
20 | |||
20 | //internal signal |
|
21 | //internal signal | |
21 | signals: |
|
22 | signals: | |
22 | void updated(); |
|
23 | void updated(); | |
23 |
|
24 | |||
24 | private: |
|
25 | private: | |
25 | QMap<qreal,QString> m_map; |
|
26 | QMap<qreal,QString> m_map; | |
26 |
|
27 | |||
27 | friend class QChartAxis; |
|
28 | friend class QChartAxis; | |
28 | }; |
|
29 | }; | |
29 |
|
30 | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
32 | QTCOMMERCIALCHART_END_NAMESPACE | |
32 |
|
33 | |||
33 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
|
34 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
@@ -1,177 +1,177 | |||||
1 | #include "barpresenterbase_p.h" |
|
1 | #include "barpresenterbase_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "separator_p.h" |
|
4 | #include "separator_p.h" | |
5 | #include "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 | #include "qbarseries.h" |
|
6 | #include "qbarseries.h" | |
7 | #include "qchart.h" |
|
7 | #include "qchart.h" | |
8 | #include "qchartaxis.h" |
|
8 | #include "qchartaxis.h" | |
9 | #include "qchartaxiscategories.h" |
|
9 | #include "qchartaxiscategories.h" | |
10 | #include <QDebug> |
|
10 | #include <QDebug> | |
11 | #include <QToolTip> |
|
11 | #include <QToolTip> | |
12 |
|
12 | |||
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 |
|
14 | |||
15 | BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) |
|
15 | BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) | |
16 | : ChartItem(parent) |
|
16 | : ChartItem(parent) | |
17 | ,mLayoutSet(false) |
|
17 | ,mLayoutSet(false) | |
18 | ,mSeparatorsEnabled(false) |
|
18 | ,mSeparatorsEnabled(false) | |
19 | ,mSeries(series) |
|
19 | ,mSeries(series) | |
20 | ,mChart(parent) |
|
20 | ,mChart(parent) | |
21 | { |
|
21 | { | |
22 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
22 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); | |
23 | initAxisLabels(); |
|
23 | initAxisLabels(); | |
24 | dataChanged(); |
|
24 | dataChanged(); | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | BarPresenterBase::~BarPresenterBase() |
|
27 | BarPresenterBase::~BarPresenterBase() | |
28 | { |
|
28 | { | |
29 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
29 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
32 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
33 | { |
|
33 | { | |
34 | if (!mLayoutSet) { |
|
34 | if (!mLayoutSet) { | |
35 | qDebug() << "BarPresenterBase::paint called without layout set. Aborting."; |
|
35 | qDebug() << "BarPresenterBase::paint called without layout set. Aborting."; | |
36 | return; |
|
36 | return; | |
37 | } |
|
37 | } | |
38 | foreach(QGraphicsItem* i, childItems()) { |
|
38 | foreach(QGraphicsItem* i, childItems()) { | |
39 | i->paint(painter,option,widget); |
|
39 | i->paint(painter,option,widget); | |
40 | } |
|
40 | } | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QRectF BarPresenterBase::boundingRect() const |
|
43 | QRectF BarPresenterBase::boundingRect() const | |
44 | { |
|
44 | { | |
45 | return QRectF(0,0,mWidth,mHeight); |
|
45 | return QRectF(0,0,mWidth,mHeight); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void BarPresenterBase::dataChanged() |
|
48 | void BarPresenterBase::dataChanged() | |
49 | { |
|
49 | { | |
50 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
50 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
51 | // Delete old bars |
|
51 | // Delete old bars | |
52 | foreach (QGraphicsItem* item, childItems()) { |
|
52 | foreach (QGraphicsItem* item, childItems()) { | |
53 | delete item; |
|
53 | delete item; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | mBars.clear(); |
|
56 | mBars.clear(); | |
57 | mSeparators.clear(); |
|
57 | mSeparators.clear(); | |
58 | mFloatingValues.clear(); |
|
58 | mFloatingValues.clear(); | |
59 |
|
59 | |||
60 | // Create new graphic items for bars |
|
60 | // Create new graphic items for bars | |
61 | for (int c=0; c<mSeries->categoryCount(); c++) { |
|
61 | for (int c=0; c<mSeries->categoryCount(); c++) { | |
62 | QString category = mSeries->categoryName(c); |
|
62 | QString category = mSeries->categoryName(c); | |
63 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
63 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
64 | QBarSet *set = mSeries->barsetAt(s); |
|
64 | QBarSet *set = mSeries->barsetAt(s); | |
65 | Bar *bar = new Bar(category,this); |
|
65 | Bar *bar = new Bar(category,this); | |
66 | childItems().append(bar); |
|
66 | childItems().append(bar); | |
67 | mBars.append(bar); |
|
67 | mBars.append(bar); | |
68 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); |
|
68 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); | |
69 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); |
|
69 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); | |
70 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); |
|
70 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); | |
71 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); |
|
71 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | // Create separators |
|
75 | // Create separators | |
76 | int count = mSeries->categoryCount() - 1; // There is one less separator than columns |
|
76 | int count = mSeries->categoryCount() - 1; // There is one less separator than columns | |
77 | for (int i=0; i<count; i++) { |
|
77 | for (int i=0; i<count; i++) { | |
78 | Separator* sep = new Separator(this); |
|
78 | Separator* sep = new Separator(this); | |
79 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
79 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | |
80 | sep->setVisible(mSeparatorsEnabled); |
|
80 | sep->setVisible(mSeparatorsEnabled); | |
81 | childItems().append(sep); |
|
81 | childItems().append(sep); | |
82 | mSeparators.append(sep); |
|
82 | mSeparators.append(sep); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // Create floating values |
|
85 | // Create floating values | |
86 | for (int category=0; category<mSeries->categoryCount(); category++) { |
|
86 | for (int category=0; category<mSeries->categoryCount(); category++) { | |
87 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
87 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
88 | QBarSet *set = mSeries->barsetAt(s); |
|
88 | QBarSet *set = mSeries->barsetAt(s); | |
89 | BarValue *value = new BarValue(*set, this); |
|
89 | BarValue *value = new BarValue(*set, this); | |
90 | childItems().append(value); |
|
90 | childItems().append(value); | |
91 | mFloatingValues.append(value); |
|
91 | mFloatingValues.append(value); | |
92 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); |
|
92 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); | |
93 | } |
|
93 | } | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void BarPresenterBase::initAxisLabels() |
|
97 | void BarPresenterBase::initAxisLabels() | |
98 | { |
|
98 | { | |
99 | int count = mSeries->categoryCount(); |
|
99 | int count = mSeries->categoryCount(); | |
100 | if (0 == count) { |
|
100 | if (0 == count) { | |
101 | return; |
|
101 | return; | |
102 | } |
|
102 | } | |
|
103 | count++; | |||
103 |
|
104 | |||
104 | mChart->axisX()->setTicksCount(count); |
|
105 | mChart->axisX()->setTicksCount(count); | |
105 |
|
106 | |||
106 | qreal min = 0; |
|
107 | qreal min = 0; | |
107 |
qreal max = |
|
108 | qreal max = count; | |
108 |
|
109 | |||
109 | mChart->axisX()->setMin(min); |
|
110 | mChart->axisX()->setMin(min); | |
110 | mChart->axisX()->setMax(max); |
|
111 | mChart->axisX()->setMax(max); | |
111 | qreal step = (max-min)/count; |
|
112 | min++; | |
112 |
QChartAxisCategories |
|
113 | QChartAxisCategories* categories = mChart->axisX()->categories(); | |
113 |
categories |
|
114 | categories->clear(); | |
114 | for (int i=0; i<count; i++) { |
|
115 | for (int i=0; i<count-1; i++) { | |
115 |
|
|
116 | categories->insert(min,mSeries->categoryName(i)); | |
116 | categories.insert(min,mSeries->categoryName(i)); |
|
117 | min++; | |
117 | min += step; |
|
|||
118 | } |
|
118 | } | |
119 | mChart->axisX()->setLabelsVisible(true); |
|
119 | mChart->axisX()->setLabelsVisible(true); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | //handlers |
|
122 | //handlers | |
123 |
|
123 | |||
124 | void BarPresenterBase::handleModelChanged(int index) |
|
124 | void BarPresenterBase::handleModelChanged(int index) | |
125 | { |
|
125 | { | |
126 | // qDebug() << "BarPresenterBase::handleModelChanged" << index; |
|
126 | // qDebug() << "BarPresenterBase::handleModelChanged" << index; | |
127 | dataChanged(); |
|
127 | dataChanged(); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void BarPresenterBase::handleDomainChanged(const Domain& domain) |
|
130 | void BarPresenterBase::handleDomainChanged(const Domain& domain) | |
131 | { |
|
131 | { | |
132 | qDebug() << "BarPresenterBase::handleDomainChanged"; |
|
132 | qDebug() << "BarPresenterBase::handleDomainChanged"; | |
133 | /* |
|
133 | /* | |
134 | int count = mSeries->categoryCount(); |
|
134 | int count = mSeries->categoryCount(); | |
135 | if (0 == count) { |
|
135 | if (0 == count) { | |
136 | return; |
|
136 | return; | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | // Position labels to domain |
|
139 | // Position labels to domain | |
140 | qreal min = domain.minX(); |
|
140 | qreal min = domain.minX(); | |
141 | qreal max = domain.maxX(); |
|
141 | qreal max = domain.maxX(); | |
142 | qreal step = (max-min)/count; |
|
142 | qreal step = (max-min)/count; | |
143 | QChartAxisCategories& categories = mChart->axisX()->categories(); |
|
143 | QChartAxisCategories& categories = mChart->axisX()->categories(); | |
144 | categories.clear(); |
|
144 | categories.clear(); | |
145 | for (int i=0; i<count; i++) { |
|
145 | for (int i=0; i<count; i++) { | |
146 | categories.insert(min,mSeries->categoryName(i)); |
|
146 | categories.insert(min,mSeries->categoryName(i)); | |
147 | min += step; |
|
147 | min += step; | |
148 | } |
|
148 | } | |
149 | */ |
|
149 | */ | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) |
|
152 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) | |
153 | { |
|
153 | { | |
154 | mWidth = rect.width(); |
|
154 | mWidth = rect.width(); | |
155 | mHeight = rect.height(); |
|
155 | mHeight = rect.height(); | |
156 | layoutChanged(); |
|
156 | layoutChanged(); | |
157 | mLayoutSet = true; |
|
157 | mLayoutSet = true; | |
158 | setPos(rect.topLeft()); |
|
158 | setPos(rect.topLeft()); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void BarPresenterBase::showToolTip(QPoint pos, QString tip) |
|
161 | void BarPresenterBase::showToolTip(QPoint pos, QString tip) | |
162 | { |
|
162 | { | |
163 | // TODO: cool tooltip instead of default |
|
163 | // TODO: cool tooltip instead of default | |
164 | QToolTip::showText(pos,tip); |
|
164 | QToolTip::showText(pos,tip); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void BarPresenterBase::enableSeparators(bool enabled) |
|
167 | void BarPresenterBase::enableSeparators(bool enabled) | |
168 | { |
|
168 | { | |
169 | for (int i=0; i<mSeparators.count(); i++) { |
|
169 | for (int i=0; i<mSeparators.count(); i++) { | |
170 | mSeparators.at(i)->setVisible(enabled); |
|
170 | mSeparators.at(i)->setVisible(enabled); | |
171 | } |
|
171 | } | |
172 | mSeparatorsEnabled = enabled; |
|
172 | mSeparatorsEnabled = enabled; | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | #include "moc_barpresenterbase_p.cpp" |
|
175 | #include "moc_barpresenterbase_p.cpp" | |
176 |
|
176 | |||
177 | QTCOMMERCIALCHART_END_NAMESPACE |
|
177 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,386 +1,385 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "qbarseries.h" |
|
7 | #include "qbarseries.h" | |
8 | #include "qstackedbarseries.h" |
|
8 | #include "qstackedbarseries.h" | |
9 | #include "qpercentbarseries.h" |
|
9 | #include "qpercentbarseries.h" | |
10 | #include "qlineseries.h" |
|
10 | #include "qlineseries.h" | |
11 | #include "qareaseries.h" |
|
11 | #include "qareaseries.h" | |
12 | #include "qpieseries.h" |
|
12 | #include "qpieseries.h" | |
13 | #include "qscatterseries.h" |
|
13 | #include "qscatterseries.h" | |
14 | #include "qsplineseries.h" |
|
14 | #include "qsplineseries.h" | |
15 | //items |
|
15 | //items | |
16 | #include "axisitem_p.h" |
|
16 | #include "axisitem_p.h" | |
17 | #include "axisanimationitem_p.h" |
|
17 | #include "axisanimationitem_p.h" | |
18 | #include "areachartitem_p.h" |
|
18 | #include "areachartitem_p.h" | |
19 | #include "barpresenter_p.h" |
|
19 | #include "barpresenter_p.h" | |
20 | #include "stackedbarpresenter_p.h" |
|
20 | #include "stackedbarpresenter_p.h" | |
21 | #include "percentbarpresenter_p.h" |
|
21 | #include "percentbarpresenter_p.h" | |
22 | #include "linechartitem_p.h" |
|
22 | #include "linechartitem_p.h" | |
23 | #include "piepresenter_p.h" |
|
23 | #include "piepresenter_p.h" | |
24 | #include "scatterchartitem_p.h" |
|
24 | #include "scatterchartitem_p.h" | |
25 | #include "splinechartitem_p.h" |
|
25 | #include "splinechartitem_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
29 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
30 | m_chart(chart), |
|
30 | m_chart(chart), | |
31 | m_dataset(dataset), |
|
31 | m_dataset(dataset), | |
32 | m_chartTheme(0), |
|
32 | m_chartTheme(0), | |
33 | m_zoomIndex(0), |
|
33 | m_zoomIndex(0), | |
34 | m_marginSize(0), |
|
34 | m_marginSize(0), | |
35 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
35 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
36 | m_options(QChart::NoAnimation) |
|
36 | m_options(QChart::NoAnimation) | |
37 | { |
|
37 | { | |
38 | createConnections(); |
|
38 | createConnections(); | |
39 | setChartTheme(QChart::ChartThemeDefault); |
|
39 | setChartTheme(QChart::ChartThemeDefault); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | ChartPresenter::~ChartPresenter() |
|
42 | ChartPresenter::~ChartPresenter() | |
43 | { |
|
43 | { | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void ChartPresenter::createConnections() |
|
46 | void ChartPresenter::createConnections() | |
47 | { |
|
47 | { | |
48 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
48 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
49 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
49 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
50 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
51 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
51 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
52 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
52 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | QRectF ChartPresenter::geometry() const |
|
56 | QRectF ChartPresenter::geometry() const | |
57 | { |
|
57 | { | |
58 | return m_rect; |
|
58 | return m_rect; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void ChartPresenter::handleGeometryChanged() |
|
61 | void ChartPresenter::handleGeometryChanged() | |
62 | { |
|
62 | { | |
63 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
63 | QRectF rect(QPoint(0,0),m_chart->size()); | |
64 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
64 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
65 |
|
65 | |||
66 | //rewrite zoom stack |
|
66 | //rewrite zoom stack | |
67 | for(int i=0;i<m_zoomStack.count();i++){ |
|
67 | for(int i=0;i<m_zoomStack.count();i++){ | |
68 | QRectF r = m_zoomStack[i]; |
|
68 | QRectF r = m_zoomStack[i]; | |
69 | qreal w = rect.width()/m_rect.width(); |
|
69 | qreal w = rect.width()/m_rect.width(); | |
70 | qreal h = rect.height()/m_rect.height(); |
|
70 | qreal h = rect.height()/m_rect.height(); | |
71 | QPointF tl = r.topLeft(); |
|
71 | QPointF tl = r.topLeft(); | |
72 | tl.setX(tl.x()*w); |
|
72 | tl.setX(tl.x()*w); | |
73 | tl.setY(tl.y()*h); |
|
73 | tl.setY(tl.y()*h); | |
74 | QPointF br = r.bottomRight(); |
|
74 | QPointF br = r.bottomRight(); | |
75 | br.setX(br.x()*w); |
|
75 | br.setX(br.x()*w); | |
76 | br.setY(br.y()*h); |
|
76 | br.setY(br.y()*h); | |
77 | r.setTopLeft(tl); |
|
77 | r.setTopLeft(tl); | |
78 | r.setBottomRight(br); |
|
78 | r.setBottomRight(br); | |
79 | m_zoomStack[i]=r; |
|
79 | m_zoomStack[i]=r; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | m_rect = rect; |
|
82 | m_rect = rect; | |
83 | Q_ASSERT(m_rect.isValid()); |
|
83 | Q_ASSERT(m_rect.isValid()); | |
84 | emit geometryChanged(m_rect); |
|
84 | emit geometryChanged(m_rect); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | int ChartPresenter::margin() const |
|
87 | int ChartPresenter::margin() const | |
88 | { |
|
88 | { | |
89 | return m_marginSize; |
|
89 | return m_marginSize; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void ChartPresenter::setMargin(int margin) |
|
92 | void ChartPresenter::setMargin(int margin) | |
93 | { |
|
93 | { | |
94 | m_marginSize = margin; |
|
94 | m_marginSize = margin; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
97 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
98 | { |
|
98 | { | |
99 |
|
99 | |||
100 | AxisItem* item ; |
|
100 | AxisItem* item ; | |
101 |
|
101 | |||
102 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
102 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
103 | { |
|
103 | { | |
104 | item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
104 | item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
105 | }else{ |
|
105 | }else{ | |
106 | item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
106 | item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
107 | } |
|
107 | } | |
108 | if(axis==m_dataset->axisX()){ |
|
108 | if(axis==m_dataset->axisX()){ | |
109 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); |
|
109 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); | |
110 | //initialize |
|
110 | //initialize | |
111 | item->handleRangeChanged(domain->minX(),domain->maxX()); |
|
111 | item->handleRangeChanged(domain->minX(),domain->maxX()); | |
112 | item->handleTicksCountChanged(4); |
|
|||
113 | } |
|
112 | } | |
114 | else{ |
|
113 | else{ | |
115 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); |
|
114 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); | |
116 | //initialize |
|
115 | //initialize | |
117 | item->handleRangeChanged(domain->minY(),domain->maxY()); |
|
116 | item->handleRangeChanged(domain->minY(),domain->maxY()); | |
118 | item->handleTicksCountChanged(4); |
|
117 | ||
119 | } |
|
118 | } | |
120 |
|
119 | |||
121 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
122 | //initialize |
|
121 | //initialize | |
123 | item->handleGeometryChanged(m_rect); |
|
122 | item->handleGeometryChanged(m_rect); | |
124 | m_chartTheme->decorate(axis,item); |
|
123 | m_chartTheme->decorate(axis,item); | |
125 | m_axisItems.insert(axis,item); |
|
124 | m_axisItems.insert(axis,item); | |
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
127 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
129 | { |
|
128 | { | |
130 | AxisItem* item = m_axisItems.take(axis); |
|
129 | AxisItem* item = m_axisItems.take(axis); | |
131 | Q_ASSERT(item); |
|
130 | Q_ASSERT(item); | |
132 | delete item; |
|
131 | delete item; | |
133 | } |
|
132 | } | |
134 |
|
133 | |||
135 |
|
134 | |||
136 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
137 | { |
|
136 | { | |
138 | switch(series->type()) |
|
137 | switch(series->type()) | |
139 | { |
|
138 | { | |
140 | case QSeries::SeriesTypeLine: { |
|
139 | case QSeries::SeriesTypeLine: { | |
141 |
|
140 | |||
142 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
141 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
143 | LineChartItem* item; |
|
142 | LineChartItem* item; | |
144 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
143 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
145 | item = new LineChartAnimationItem(lineSeries,m_chart); |
|
144 | item = new LineChartAnimationItem(lineSeries,m_chart); | |
146 | }else{ |
|
145 | }else{ | |
147 | item = new LineChartItem(lineSeries,m_chart); |
|
146 | item = new LineChartItem(lineSeries,m_chart); | |
148 | } |
|
147 | } | |
149 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
148 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
150 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
149 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
151 | //initialize |
|
150 | //initialize | |
152 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
151 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
153 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
152 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
154 | //decorate |
|
153 | //decorate | |
155 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
154 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
156 | m_chartItems.insert(series,item); |
|
155 | m_chartItems.insert(series,item); | |
157 | break; |
|
156 | break; | |
158 | } |
|
157 | } | |
159 |
|
158 | |||
160 | case QSeries::SeriesTypeArea: { |
|
159 | case QSeries::SeriesTypeArea: { | |
161 |
|
160 | |||
162 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
161 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
163 | AreaChartItem* item; |
|
162 | AreaChartItem* item; | |
164 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
163 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
165 | item = new AreaChartItem(areaSeries,m_chart); |
|
164 | item = new AreaChartItem(areaSeries,m_chart); | |
166 | } |
|
165 | } | |
167 | else { |
|
166 | else { | |
168 | item = new AreaChartItem(areaSeries,m_chart); |
|
167 | item = new AreaChartItem(areaSeries,m_chart); | |
169 | } |
|
168 | } | |
170 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
169 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
171 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
170 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
172 | //initialize |
|
171 | //initialize | |
173 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
172 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
174 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
173 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
175 | //decorate |
|
174 | //decorate | |
176 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); |
|
175 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); | |
177 | m_chartItems.insert(series,item); |
|
176 | m_chartItems.insert(series,item); | |
178 | break; |
|
177 | break; | |
179 | } |
|
178 | } | |
180 |
|
179 | |||
181 | case QSeries::SeriesTypeBar: { |
|
180 | case QSeries::SeriesTypeBar: { | |
182 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
181 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
183 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
182 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
184 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
183 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
185 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
184 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
186 | // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
185 | // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
187 | m_chartItems.insert(series,item); |
|
186 | m_chartItems.insert(series,item); | |
188 | // m_axisXItem->setVisible(false); |
|
187 | // m_axisXItem->setVisible(false); | |
189 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
188 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
190 | break; |
|
189 | break; | |
191 | } |
|
190 | } | |
192 |
|
191 | |||
193 | case QSeries::SeriesTypeStackedBar: { |
|
192 | case QSeries::SeriesTypeStackedBar: { | |
194 |
|
193 | |||
195 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
194 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
196 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
195 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
197 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
196 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
198 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
197 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
199 | // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
198 | // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
200 | m_chartItems.insert(series,item); |
|
199 | m_chartItems.insert(series,item); | |
201 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
200 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
202 | break; |
|
201 | break; | |
203 | } |
|
202 | } | |
204 |
|
203 | |||
205 | case QSeries::SeriesTypePercentBar: { |
|
204 | case QSeries::SeriesTypePercentBar: { | |
206 |
|
205 | |||
207 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
206 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
208 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
207 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
209 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
208 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
210 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
209 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
211 | // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
210 | // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
212 | m_chartItems.insert(series,item); |
|
211 | m_chartItems.insert(series,item); | |
213 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
212 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
214 | break; |
|
213 | break; | |
215 | } |
|
214 | } | |
216 | case QSeries::SeriesTypeScatter: { |
|
215 | case QSeries::SeriesTypeScatter: { | |
217 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
216 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
218 | ScatterChartItem *item; |
|
217 | ScatterChartItem *item; | |
219 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
218 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
220 | item = new ScatterChartAnimationItem(scatterSeries,m_chart); |
|
219 | item = new ScatterChartAnimationItem(scatterSeries,m_chart); | |
221 | } else { |
|
220 | } else { | |
222 | item = new ScatterChartItem(scatterSeries, m_chart); |
|
221 | item = new ScatterChartItem(scatterSeries, m_chart); | |
223 | } |
|
222 | } | |
224 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
223 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
225 | item, SLOT(handleGeometryChanged(const QRectF&))); |
|
224 | item, SLOT(handleGeometryChanged(const QRectF&))); | |
226 | QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)), |
|
225 | QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)), | |
227 | item, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
226 | item, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
228 | //initialize |
|
227 | //initialize | |
229 | if (m_rect.isValid()) |
|
228 | if (m_rect.isValid()) | |
230 | item->handleGeometryChanged(m_rect); |
|
229 | item->handleGeometryChanged(m_rect); | |
231 | item->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY()); |
|
230 | item->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY()); | |
232 | //decorate |
|
231 | //decorate | |
233 | m_chartTheme->decorate(item, scatterSeries, m_chartItems.count()); |
|
232 | m_chartTheme->decorate(item, scatterSeries, m_chartItems.count()); | |
234 | m_chartItems.insert(scatterSeries, item); |
|
233 | m_chartItems.insert(scatterSeries, item); | |
235 |
|
234 | |||
236 | break; |
|
235 | break; | |
237 | } |
|
236 | } | |
238 | case QSeries::SeriesTypePie: { |
|
237 | case QSeries::SeriesTypePie: { | |
239 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
238 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
240 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
239 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
241 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
240 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
242 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
241 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
243 |
|
242 | |||
244 | // Hide all from background when there is only piechart |
|
243 | // Hide all from background when there is only piechart | |
245 | // TODO: refactor this ugly code... should be one setting for this |
|
244 | // TODO: refactor this ugly code... should be one setting for this | |
246 | if (m_chartItems.count() == 0) { |
|
245 | if (m_chartItems.count() == 0) { | |
247 | m_chart->axisX()->setAxisVisible(false); |
|
246 | m_chart->axisX()->setAxisVisible(false); | |
248 | m_chart->axisY()->setAxisVisible(false); |
|
247 | m_chart->axisY()->setAxisVisible(false); | |
249 | m_chart->axisX()->setGridVisible(false); |
|
248 | m_chart->axisX()->setGridVisible(false); | |
250 | m_chart->axisY()->setGridVisible(false); |
|
249 | m_chart->axisY()->setGridVisible(false); | |
251 | m_chart->axisX()->setLabelsVisible(false); |
|
250 | m_chart->axisX()->setLabelsVisible(false); | |
252 | m_chart->axisY()->setLabelsVisible(false); |
|
251 | m_chart->axisY()->setLabelsVisible(false); | |
253 | m_chart->axisX()->setShadesVisible(false); |
|
252 | m_chart->axisX()->setShadesVisible(false); | |
254 | m_chart->axisY()->setShadesVisible(false); |
|
253 | m_chart->axisY()->setShadesVisible(false); | |
255 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
254 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
256 | } |
|
255 | } | |
257 |
|
256 | |||
258 | m_chartItems.insert(series, pie); |
|
257 | m_chartItems.insert(series, pie); | |
259 | pie->handleGeometryChanged(m_rect); |
|
258 | pie->handleGeometryChanged(m_rect); | |
260 | break; |
|
259 | break; | |
261 | } |
|
260 | } | |
262 |
|
261 | |||
263 | case QSeries::SeriesTypeSpline: { |
|
262 | case QSeries::SeriesTypeSpline: { | |
264 |
|
263 | |||
265 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); |
|
264 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); | |
266 | SplineChartItem* item; |
|
265 | SplineChartItem* item; | |
267 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
266 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
268 | item = new SplineChartAnimationItem(splineSeries, m_chart); |
|
267 | item = new SplineChartAnimationItem(splineSeries, m_chart); | |
269 | } else { |
|
268 | } else { | |
270 | item = new SplineChartItem(splineSeries, m_chart); |
|
269 | item = new SplineChartItem(splineSeries, m_chart); | |
271 | } |
|
270 | } | |
272 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), item, SLOT(handleGeometryChanged(const QRectF&))); |
|
271 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), item, SLOT(handleGeometryChanged(const QRectF&))); | |
273 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
272 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
274 | //initialize |
|
273 | //initialize | |
275 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
274 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
276 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
275 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
277 | //decorate |
|
276 | //decorate | |
278 | m_chartTheme->decorate(item, splineSeries, m_chartItems.count()); |
|
277 | m_chartTheme->decorate(item, splineSeries, m_chartItems.count()); | |
279 | m_chartItems.insert(splineSeries, item); |
|
278 | m_chartItems.insert(splineSeries, item); | |
280 | break; |
|
279 | break; | |
281 | } |
|
280 | } | |
282 | default: { |
|
281 | default: { | |
283 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
282 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
284 | break; |
|
283 | break; | |
285 | } |
|
284 | } | |
286 | } |
|
285 | } | |
287 |
|
286 | |||
288 | zoomReset(); |
|
287 | zoomReset(); | |
289 | } |
|
288 | } | |
290 |
|
289 | |||
291 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
290 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
292 | { |
|
291 | { | |
293 | ChartItem* item = m_chartItems.take(series); |
|
292 | ChartItem* item = m_chartItems.take(series); | |
294 | delete item; |
|
293 | delete item; | |
295 | } |
|
294 | } | |
296 |
|
295 | |||
297 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
296 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
298 | { |
|
297 | { | |
299 | delete m_chartTheme; |
|
298 | delete m_chartTheme; | |
300 |
|
299 | |||
301 | m_chartTheme = ChartTheme::createTheme(theme); |
|
300 | m_chartTheme = ChartTheme::createTheme(theme); | |
302 |
|
301 | |||
303 | m_chartTheme->decorate(m_chart); |
|
302 | m_chartTheme->decorate(m_chart); | |
304 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); |
|
303 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); | |
305 |
|
304 | |||
306 | int index=0; |
|
305 | int index=0; | |
307 | while (i.hasNext()) { |
|
306 | while (i.hasNext()) { | |
308 | i.next(); |
|
307 | i.next(); | |
309 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
308 | m_chartTheme->decorate(i.value(),i.key(),index); | |
310 | index++; |
|
309 | index++; | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
312 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
314 | while (j.hasNext()) { |
|
313 | while (j.hasNext()) { | |
315 | j.next(); |
|
314 | j.next(); | |
316 | m_chartTheme->decorate(j.key(),j.value()); |
|
315 | m_chartTheme->decorate(j.key(),j.value()); | |
317 | } |
|
316 | } | |
318 | } |
|
317 | } | |
319 |
|
318 | |||
320 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
319 | QChart::ChartTheme ChartPresenter::chartTheme() | |
321 | { |
|
320 | { | |
322 | return m_chartTheme->id(); |
|
321 | return m_chartTheme->id(); | |
323 | } |
|
322 | } | |
324 |
|
323 | |||
325 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
324 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
326 | { |
|
325 | { | |
327 | if(m_options!=options) { |
|
326 | if(m_options!=options) { | |
328 |
|
327 | |||
329 | m_options=options; |
|
328 | m_options=options; | |
330 |
|
329 | |||
331 | //recreate elements |
|
330 | //recreate elements | |
332 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
331 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
333 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
332 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
334 |
|
333 | |||
335 | foreach(QChartAxis* axis, axisList) { |
|
334 | foreach(QChartAxis* axis, axisList) { | |
336 | handleAxisRemoved(axis); |
|
335 | handleAxisRemoved(axis); | |
337 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
336 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
338 | } |
|
337 | } | |
339 | foreach(QSeries* series, seriesList) { |
|
338 | foreach(QSeries* series, seriesList) { | |
340 | handleSeriesRemoved(series); |
|
339 | handleSeriesRemoved(series); | |
341 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
340 | handleSeriesAdded(series,m_dataset->domain(series)); | |
342 | } |
|
341 | } | |
343 | } |
|
342 | } | |
344 | } |
|
343 | } | |
345 |
|
344 | |||
346 | void ChartPresenter::zoomIn() |
|
345 | void ChartPresenter::zoomIn() | |
347 | { |
|
346 | { | |
348 | QRectF rect = geometry(); |
|
347 | QRectF rect = geometry(); | |
349 | rect.setWidth(rect.width()/2); |
|
348 | rect.setWidth(rect.width()/2); | |
350 | rect.setHeight(rect.height()/2); |
|
349 | rect.setHeight(rect.height()/2); | |
351 | rect.moveCenter(geometry().center()); |
|
350 | rect.moveCenter(geometry().center()); | |
352 | zoomIn(rect); |
|
351 | zoomIn(rect); | |
353 | } |
|
352 | } | |
354 |
|
353 | |||
355 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
354 | void ChartPresenter::zoomIn(const QRectF& rect) | |
356 | { |
|
355 | { | |
357 | QRectF r = rect.normalized(); |
|
356 | QRectF r = rect.normalized(); | |
358 | r.translate(-m_marginSize, -m_marginSize); |
|
357 | r.translate(-m_marginSize, -m_marginSize); | |
359 | m_dataset->zoomInDomain(r,geometry().size()); |
|
358 | m_dataset->zoomInDomain(r,geometry().size()); | |
360 | m_zoomStack<<r; |
|
359 | m_zoomStack<<r; | |
361 | m_zoomIndex++; |
|
360 | m_zoomIndex++; | |
362 | } |
|
361 | } | |
363 |
|
362 | |||
364 | void ChartPresenter::zoomOut() |
|
363 | void ChartPresenter::zoomOut() | |
365 | { |
|
364 | { | |
366 | if(m_zoomIndex==0) return; |
|
365 | if(m_zoomIndex==0) return; | |
367 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
366 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
368 | m_zoomIndex--; |
|
367 | m_zoomIndex--; | |
369 | m_zoomStack.resize(m_zoomIndex); |
|
368 | m_zoomStack.resize(m_zoomIndex); | |
370 | } |
|
369 | } | |
371 |
|
370 | |||
372 | void ChartPresenter::zoomReset() |
|
371 | void ChartPresenter::zoomReset() | |
373 | { |
|
372 | { | |
374 | m_zoomIndex=0; |
|
373 | m_zoomIndex=0; | |
375 | m_zoomStack.resize(m_zoomIndex); |
|
374 | m_zoomStack.resize(m_zoomIndex); | |
376 | } |
|
375 | } | |
377 |
|
376 | |||
378 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
377 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
379 | { |
|
378 | { | |
380 | return m_options; |
|
379 | return m_options; | |
381 | } |
|
380 | } | |
382 |
|
381 | |||
383 |
|
382 | |||
384 | #include "moc_chartpresenter_p.cpp" |
|
383 | #include "moc_chartpresenter_p.cpp" | |
385 |
|
384 | |||
386 | QTCOMMERCIALCHART_END_NAMESPACE |
|
385 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now