##// END OF EJS Templates
minor code review fixes
sauimone -
r759:ea8e9f62638e
parent child
Show More
@@ -1,422 +1,421
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 "chartanimator_p.h"
4 #include "chartanimator_p.h"
5 #include <QPainter>
5 #include <QPainter>
6 #include <QDebug>
6 #include <QDebug>
7 #include <cmath>
7 #include <cmath>
8
8
9 static int label_padding = 5;
9 static int label_padding = 5;
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) : Chart(presenter),
13 Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter),
14 m_chartAxis(axis),
14 m_chartAxis(axis),
15 m_type(type),
15 m_type(type),
16 m_labelsAngle(0),
16 m_labelsAngle(0),
17 m_grid(presenter->rootItem()),
17 m_grid(presenter->rootItem()),
18 m_shades(presenter->rootItem()),
18 m_shades(presenter->rootItem()),
19 m_labels(presenter->rootItem()),
19 m_labels(presenter->rootItem()),
20 m_axis(presenter->rootItem()),
20 m_axis(presenter->rootItem()),
21 m_min(0),
21 m_min(0),
22 m_max(0),
22 m_max(0),
23 m_ticksCount(0)
23 m_ticksCount(0)
24 {
24 {
25 //initial initialization
25 //initial initialization
26 m_axis.setZValue(ChartPresenter::AxisZValue);
26 m_axis.setZValue(ChartPresenter::AxisZValue);
27 m_axis.setHandlesChildEvents(false);
27 m_axis.setHandlesChildEvents(false);
28
28
29 m_shades.setZValue(ChartPresenter::ShadesZValue);
29 m_shades.setZValue(ChartPresenter::ShadesZValue);
30 m_grid.setZValue(ChartPresenter::GridZValue);
30 m_grid.setZValue(ChartPresenter::GridZValue);
31
31
32 connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
32 connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
33 connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
33 connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
34
34
35 handleAxisUpdated();
35 handleAxisUpdated();
36 }
36 }
37
37
38 Axis::~Axis()
38 Axis::~Axis()
39 {
39 {
40 }
40 }
41
41
42 void Axis::createItems(int count)
42 void Axis::createItems(int count)
43 {
43 {
44
44
45 if (m_axis.children().size()==0)
45 if (m_axis.children().size() == 0)
46 m_axis.addToGroup(new AxisItem(this));
46 m_axis.addToGroup(new AxisItem(this));
47 for (int i = 0; i < count; ++i) {
47 for (int i = 0; i < count; ++i) {
48 m_grid.addToGroup(new QGraphicsLineItem());
48 m_grid.addToGroup(new QGraphicsLineItem());
49 m_labels.addToGroup(new QGraphicsSimpleTextItem());
49 m_labels.addToGroup(new QGraphicsSimpleTextItem());
50 m_axis.addToGroup(new QGraphicsLineItem());
50 m_axis.addToGroup(new QGraphicsLineItem());
51 if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem());
51 if ((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem());
52 }
52 }
53 }
53 }
54
54
55 void Axis::deleteItems(int count)
55 void Axis::deleteItems(int count)
56 {
56 {
57 QList<QGraphicsItem *> lines = m_grid.childItems();
57 QList<QGraphicsItem *> lines = m_grid.childItems();
58 QList<QGraphicsItem *> labels = m_labels.childItems();
58 QList<QGraphicsItem *> labels = m_labels.childItems();
59 QList<QGraphicsItem *> shades = m_shades.childItems();
59 QList<QGraphicsItem *> shades = m_shades.childItems();
60 QList<QGraphicsItem *> axis = m_axis.childItems();
60 QList<QGraphicsItem *> axis = m_axis.childItems();
61
61
62 for (int i = 0; i < count; ++i) {
62 for (int i = 0; i < count; ++i) {
63 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
63 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
64 delete(lines.takeLast());
64 delete(lines.takeLast());
65 delete(labels.takeLast());
65 delete(labels.takeLast());
66 delete(axis.takeLast());
66 delete(axis.takeLast());
67 }
67 }
68 }
68 }
69
69
70 void Axis::updateLayout(QVector<qreal>& layout)
70 void Axis::updateLayout(QVector<qreal> &layout)
71 {
71 {
72 if (animator()) {
72 if (animator()) {
73 animator()->updateLayout(this,layout);
73 animator()->updateLayout(this,layout);
74 } else {
74 } else {
75 setLayout(layout);
75 setLayout(layout);
76 }
76 }
77 }
77 }
78
78
79 bool Axis::createLabels(QStringList& labels,qreal min, qreal max,int ticks) const
79 bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
80 {
80 {
81 Q_ASSERT(max>=min);
81 Q_ASSERT(max>=min);
82 Q_ASSERT(ticks>1);
82 Q_ASSERT(ticks>1);
83
83
84 QChartAxisCategories* categories = m_chartAxis->categories();
84 QChartAxisCategories* categories = m_chartAxis->categories();
85
85
86 bool category = categories->count()>0;
86 bool category = categories->count()>0;
87
87
88 if (!category) {
88 if (!category) {
89 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
89 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
90 for(int i=0; i< ticks; i++) {
90 for (int i=0; i< ticks; i++) {
91 qreal value = min + (i * (max - min)/ (ticks-1));
91 qreal value = min + (i * (max - min)/ (ticks-1));
92 labels << QString::number(value,'f',n);
92 labels << QString::number(value,'f',n);
93 }
93 }
94 } else {
94 } else {
95 QList<qreal> values = categories->values();
95 QList<qreal> values = categories->values();
96 for (int i=0; i< ticks; i++) {
96 for (int i=0; i< ticks; i++) {
97 qreal value = (min + (i * (max - min)/ (ticks-1)));
97 qreal value = (min + (i * (max - min)/ (ticks-1)));
98 int j=0;
98 int j=0;
99 for (; j<values.count(); j++) {
99 for (; j<values.count(); j++) {
100 if (values.at(j) > value) break;
100 if (values.at(j) > value) break;
101 }
101 }
102 if (j!=0) value=values.at(j-1);
102 if (j!=0) value=values.at(j-1);
103
103
104 QString label = categories->label(value);
104 QString label = categories->label(value);
105 labels << label;
105 labels << label;
106 }
106 }
107 }
107 }
108
108
109 return category;
109 return category;
110 }
110 }
111
111
112 void Axis::setAxisOpacity(qreal opacity)
112 void Axis::setAxisOpacity(qreal opacity)
113 {
113 {
114 m_axis.setOpacity(opacity);
114 m_axis.setOpacity(opacity);
115 }
115 }
116
116
117 qreal Axis::axisOpacity() const
117 qreal Axis::axisOpacity() const
118 {
118 {
119 return m_axis.opacity();
119 return m_axis.opacity();
120 }
120 }
121
121
122 void Axis::setGridOpacity(qreal opacity)
122 void Axis::setGridOpacity(qreal opacity)
123 {
123 {
124 m_grid.setOpacity(opacity);
124 m_grid.setOpacity(opacity);
125 }
125 }
126
126
127 qreal Axis::gridOpacity() const
127 qreal Axis::gridOpacity() const
128 {
128 {
129 return m_grid.opacity();
129 return m_grid.opacity();
130 }
130 }
131
131
132 void Axis::setLabelsOpacity(qreal opacity)
132 void Axis::setLabelsOpacity(qreal opacity)
133 {
133 {
134 m_labels.setOpacity(opacity);
134 m_labels.setOpacity(opacity);
135 }
135 }
136
136
137 qreal Axis::labelsOpacity() const
137 qreal Axis::labelsOpacity() const
138 {
138 {
139 return m_labels.opacity();
139 return m_labels.opacity();
140 }
140 }
141
141
142 void Axis::setShadesOpacity(qreal opacity)
142 void Axis::setShadesOpacity(qreal opacity)
143 {
143 {
144 m_shades.setOpacity(opacity);
144 m_shades.setOpacity(opacity);
145 }
145 }
146
146
147 qreal Axis::shadesOpacity() const
147 qreal Axis::shadesOpacity() const
148 {
148 {
149 return m_shades.opacity();
149 return m_shades.opacity();
150 }
150 }
151
151
152 void Axis::setLabelsAngle(int angle)
152 void Axis::setLabelsAngle(int angle)
153 {
153 {
154 foreach(QGraphicsItem* item , m_labels.childItems()) {
154 foreach(QGraphicsItem* item , m_labels.childItems()) {
155 QPointF center = item->boundingRect().center();
155 QPointF center = item->boundingRect().center();
156 item->setRotation(angle);
156 item->setRotation(angle);
157 }
157 }
158
158
159 m_labelsAngle=angle;
159 m_labelsAngle=angle;
160 }
160 }
161
161
162 void Axis::setLabelsPen(const QPen &pen)
162 void Axis::setLabelsPen(const QPen &pen)
163 {
163 {
164 foreach(QGraphicsItem* item , m_labels.childItems()) {
164 foreach(QGraphicsItem* item , m_labels.childItems()) {
165 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
165 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
166 }
166 }
167 }
167 }
168
168
169 void Axis::setLabelsBrush(const QBrush &brush)
169 void Axis::setLabelsBrush(const QBrush &brush)
170 {
170 {
171 foreach(QGraphicsItem* item , m_labels.childItems()) {
171 foreach(QGraphicsItem* item , m_labels.childItems()) {
172 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
172 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
173 }
173 }
174 }
174 }
175
175
176 void Axis::setLabelsFont(const QFont &font)
176 void Axis::setLabelsFont(const QFont &font)
177 {
177 {
178 foreach(QGraphicsItem* item , m_labels.childItems()) {
178 foreach(QGraphicsItem* item , m_labels.childItems()) {
179 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
179 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
180 }
180 }
181 }
181 }
182
182
183 void Axis::setShadesBrush(const QBrush &brush)
183 void Axis::setShadesBrush(const QBrush &brush)
184 {
184 {
185 foreach(QGraphicsItem* item , m_shades.childItems()) {
185 foreach(QGraphicsItem* item , m_shades.childItems()) {
186 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
186 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
187 }
187 }
188 }
188 }
189
189
190 void Axis::setShadesPen(const QPen &pen)
190 void Axis::setShadesPen(const QPen &pen)
191 {
191 {
192 foreach(QGraphicsItem* item , m_shades.childItems()) {
192 foreach(QGraphicsItem* item , m_shades.childItems()) {
193 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
193 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
194 }
194 }
195 }
195 }
196
196
197 void Axis::setAxisPen(const QPen &pen)
197 void Axis::setAxisPen(const QPen &pen)
198 {
198 {
199 foreach(QGraphicsItem* item , m_axis.childItems()) {
199 foreach(QGraphicsItem* item , m_axis.childItems()) {
200 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
200 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
201 }
201 }
202 }
202 }
203
203
204 void Axis::setGridPen(const QPen &pen)
204 void Axis::setGridPen(const QPen &pen)
205 {
205 {
206 foreach(QGraphicsItem* item , m_grid.childItems()) {
206 foreach(QGraphicsItem* item , m_grid.childItems()) {
207 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
207 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
208 }
208 }
209 }
209 }
210
210
211 QVector<qreal> Axis::calculateLayout() const
211 QVector<qreal> Axis::calculateLayout() const
212 {
212 {
213 Q_ASSERT(m_ticksCount>=2);
213 Q_ASSERT(m_ticksCount>=2);
214
214
215 QVector<qreal> points;
215 QVector<qreal> points;
216 points.resize(m_ticksCount);
216 points.resize(m_ticksCount);
217
217
218 switch (m_type)
218 switch (m_type)
219 {
219 {
220 case X_AXIS:
220 case X_AXIS:
221 {
221 {
222 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
222 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
223 for (int i = 0; i < m_ticksCount; ++i) {
223 for (int i = 0; i < m_ticksCount; ++i) {
224 int x = i * deltaX + m_rect.left();
224 int x = i * deltaX + m_rect.left();
225 points[i] = x;
225 points[i] = x;
226 }
226 }
227 }
227 }
228 break;
228 break;
229 case Y_AXIS:
229 case Y_AXIS:
230 {
230 {
231 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
231 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
232 for (int i = 0; i < m_ticksCount; ++i) {
232 for (int i = 0; i < m_ticksCount; ++i) {
233 int y = i * -deltaY + m_rect.bottom();
233 int y = i * -deltaY + m_rect.bottom();
234 points[i] = y;
234 points[i] = y;
235 }
235 }
236 }
236 }
237 break;
237 break;
238 }
238 }
239 return points;
239 return points;
240 }
240 }
241
241
242 void Axis::setLayout(QVector<qreal>& layout)
242 void Axis::setLayout(QVector<qreal> &layout)
243 {
243 {
244 int diff = m_layoutVector.size() - layout.size();
244 int diff = m_layoutVector.size() - layout.size();
245
245
246 if (diff>0) {
246 if (diff>0) {
247 deleteItems(diff);
247 deleteItems(diff);
248 }
248 } else if (diff<0) {
249 else if(diff<0) {
250 createItems(-diff);
249 createItems(-diff);
251 }
250 }
252
251
253 if(diff!=0) handleAxisUpdated();
252 if( diff!=0) handleAxisUpdated();
254
253
255 QStringList ticksList;
254 QStringList ticksList;
256
255
257 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
256 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
258
257
259 QList<QGraphicsItem *> lines = m_grid.childItems();
258 QList<QGraphicsItem *> lines = m_grid.childItems();
260 QList<QGraphicsItem *> labels = m_labels.childItems();
259 QList<QGraphicsItem *> labels = m_labels.childItems();
261 QList<QGraphicsItem *> shades = m_shades.childItems();
260 QList<QGraphicsItem *> shades = m_shades.childItems();
262 QList<QGraphicsItem *> axis = m_axis.childItems();
261 QList<QGraphicsItem *> axis = m_axis.childItems();
263
262
264 Q_ASSERT(labels.size() == ticksList.size());
263 Q_ASSERT(labels.size() == ticksList.size());
265 Q_ASSERT(layout.size() == ticksList.size());
264 Q_ASSERT(layout.size() == ticksList.size());
266
265
267 switch (m_type)
266 switch (m_type)
268 {
267 {
269 case X_AXIS:
268 case X_AXIS:
270 {
269 {
271 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
270 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
272 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
271 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
273
272
274 for (int i = 0; i < layout.size(); ++i) {
273 for (int i = 0; i < layout.size(); ++i) {
275 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
274 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
276 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
275 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
277 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
276 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
278 if(!categories){
277 if (!categories) {
279 labelItem->setText(ticksList.at(i));
278 labelItem->setText(ticksList.at(i));
280 QPointF center = labelItem->boundingRect().center();
279 QPointF center = labelItem->boundingRect().center();
281 labelItem->setTransformOriginPoint(center.x(), center.y());
280 labelItem->setTransformOriginPoint(center.x(), center.y());
282 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
281 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
283 }else if(i>0){
282 } else if(i>0) {
284 labelItem->setText(ticksList.at(i));
283 labelItem->setText(ticksList.at(i));
285 QPointF center = labelItem->boundingRect().center();
284 QPointF center = labelItem->boundingRect().center();
286 labelItem->setTransformOriginPoint(center.x(), center.y());
285 labelItem->setTransformOriginPoint(center.x(), center.y());
287 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
286 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
288 }
287 }
289
288
290 if((i+1)%2 && i>1) {
289 if ((i+1)%2 && i>1) {
291 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
290 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
292 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
291 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
293 }
292 }
294 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
293 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
295 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
294 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
296 }
295 }
297 }
296 }
298 break;
297 break;
299
298
300 case Y_AXIS:
299 case Y_AXIS:
301 {
300 {
302 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
301 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
303 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
302 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
304
303
305 for (int i = 0; i < layout.size(); ++i) {
304 for (int i = 0; i < layout.size(); ++i) {
306 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
305 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
307 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
306 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
308 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
307 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
309
308
310 if(!categories){
309 if (!categories) {
311 labelItem->setText(ticksList.at(i));
310 labelItem->setText(ticksList.at(i));
312 QPointF center = labelItem->boundingRect().center();
311 QPointF center = labelItem->boundingRect().center();
313 labelItem->setTransformOriginPoint(center.x(), center.y());
312 labelItem->setTransformOriginPoint(center.x(), center.y());
314 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y());
313 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y());
315 } else if(i>0){
314 } else if (i>0) {
316 labelItem->setText(ticksList.at(i));
315 labelItem->setText(ticksList.at(i));
317 QPointF center = labelItem->boundingRect().center();
316 QPointF center = labelItem->boundingRect().center();
318 labelItem->setTransformOriginPoint(center.x(), center.y());
317 labelItem->setTransformOriginPoint(center.x(), center.y());
319 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
318 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
320 }
319 }
321
320
322 if((i+1)%2 && i>1) {
321 if ((i+1)%2 && i>1) {
323 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
322 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
324 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
323 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
325 }
324 }
326 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
325 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
327 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
326 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
328 }
327 }
329 }
328 }
330 break;
329 break;
331 default:
330 default:
332 qDebug()<<"Unknown axis type";
331 qDebug()<<"Unknown axis type";
333 break;
332 break;
334 }
333 }
335
334
336 m_layoutVector=layout;
335 m_layoutVector=layout;
337 }
336 }
338
337
339 bool Axis::isEmpty()
338 bool Axis::isEmpty()
340 {
339 {
341 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
340 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
342 }
341 }
343
342
344 //handlers
343 //handlers
345
344
346 void Axis::handleAxisCategoriesUpdated()
345 void Axis::handleAxisCategoriesUpdated()
347 {
346 {
348 if(isEmpty()) return;
347 if (isEmpty()) return;
349 updateLayout(m_layoutVector);
348 updateLayout(m_layoutVector);
350 }
349 }
351
350
352 void Axis::handleAxisUpdated()
351 void Axis::handleAxisUpdated()
353 {
352 {
354
353
355 if (isEmpty()) return;
354 if (isEmpty()) return;
356
355
357 if (m_chartAxis->isAxisVisible()) {
356 if (m_chartAxis->isAxisVisible()) {
358 setAxisOpacity(100);
357 setAxisOpacity(100);
359 } else {
358 } else {
360 setAxisOpacity(0);
359 setAxisOpacity(0);
361 }
360 }
362
361
363 if(m_chartAxis->isGridLineVisible()) {
362 if (m_chartAxis->isGridLineVisible()) {
364 setGridOpacity(100);
363 setGridOpacity(100);
365 } else {
364 } else {
366 setGridOpacity(0);
365 setGridOpacity(0);
367 }
366 }
368
367
369 if(m_chartAxis->labelsVisible()) {
368 if (m_chartAxis->labelsVisible()) {
370 setLabelsOpacity(100);
369 setLabelsOpacity(100);
371 } else {
370 } else {
372 setLabelsOpacity(0);
371 setLabelsOpacity(0);
373 }
372 }
374
373
375 if (m_chartAxis->shadesVisible()) {
374 if (m_chartAxis->shadesVisible()) {
376 setShadesOpacity(m_chartAxis->shadesOpacity());
375 setShadesOpacity(m_chartAxis->shadesOpacity());
377 } else {
376 } else {
378 setShadesOpacity(0);
377 setShadesOpacity(0);
379 }
378 }
380
379
381 setLabelsAngle(m_chartAxis->labelsAngle());
380 setLabelsAngle(m_chartAxis->labelsAngle());
382 setAxisPen(m_chartAxis->axisPen());
381 setAxisPen(m_chartAxis->axisPen());
383 setLabelsPen(m_chartAxis->labelsPen());
382 setLabelsPen(m_chartAxis->labelsPen());
384 setLabelsBrush(m_chartAxis->labelsBrush());
383 setLabelsBrush(m_chartAxis->labelsBrush());
385 setLabelsFont(m_chartAxis->labelsFont());
384 setLabelsFont(m_chartAxis->labelsFont());
386 setGridPen(m_chartAxis->gridLinePen());
385 setGridPen(m_chartAxis->gridLinePen());
387 setShadesPen(m_chartAxis->shadesPen());
386 setShadesPen(m_chartAxis->shadesPen());
388 setShadesBrush(m_chartAxis->shadesBrush());
387 setShadesBrush(m_chartAxis->shadesBrush());
389
388
390 }
389 }
391
390
392 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
391 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
393 {
392 {
394 if(min==max || tickCount<2) return;
393 if (min==max || tickCount<2) return;
395
394
396 m_min = min;
395 m_min = min;
397 m_max = max;
396 m_max = max;
398 m_ticksCount= tickCount;
397 m_ticksCount= tickCount;
399
398
400 if (isEmpty()) return;
399 if (isEmpty()) return;
401 QVector<qreal> layout = calculateLayout();
400 QVector<qreal> layout = calculateLayout();
402 updateLayout(layout);
401 updateLayout(layout);
403
402
404 }
403 }
405
404
406 void Axis::handleGeometryChanged(const QRectF& rect)
405 void Axis::handleGeometryChanged(const QRectF &rect)
407 {
406 {
408 m_rect = rect;
407 m_rect = rect;
409 if (isEmpty()) return;
408 if (isEmpty()) return;
410 QVector<qreal> layout = calculateLayout();
409 QVector<qreal> layout = calculateLayout();
411 updateLayout(layout);
410 updateLayout(layout);
412 }
411 }
413
412
414 void Axis::axisSelected()
413 void Axis::axisSelected()
415 {
414 {
416 qDebug()<<"TODO axis clicked";
415 qDebug()<<"TODO axis clicked";
417 }
416 }
418
417
419 //TODO "nice numbers algorithm"
418 //TODO "nice numbers algorithm"
420 #include "moc_axisitem_p.cpp"
419 #include "moc_axisitem_p.cpp"
421
420
422 QTCOMMERCIALCHART_END_NAMESPACE
421 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,403 +1,401
1 #include "qchartaxis.h"
1 #include "qchartaxis.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QChartAxis
6 \class QChartAxis
7 \brief The QChartAxis class is used for manipulating chart's axis
7 \brief The QChartAxis class is used for manipulating chart's axis
8 and for adding optional axes to the chart.
8 and for adding optional axes to the chart.
9 \mainclass
9 \mainclass
10
10
11 There is only one x Axis, however there can be multiple y axes.
11 There is only one x Axis, however there can be multiple y axes.
12 Each chart series can be bound to exactly one Y axis and the share common X axis.
12 Each chart series can be bound to exactly one Y axis and the share common X axis.
13 Axis can be setup to show axis line with ticks, gird lines and shades.
13 Axis can be setup to show axis line with ticks, gird lines and shades.
14
14
15 */
15 */
16
16
17 /*!
17 /*!
18 \fn bool QChartAxis::isAxisVisible() const
18 \fn bool QChartAxis::isAxisVisible() const
19 \brief Returns if axis is visible
19 \brief Returns if axis is visible
20 \sa setAxisVisible()
20 \sa setAxisVisible()
21 */
21 */
22
22
23 /*!
23 /*!
24 \fn QPen QChartAxis::axisPen() const
24 \fn QPen QChartAxis::axisPen() const
25 \brief Returns pen used to draw axis and ticks.
25 \brief Returns pen used to draw axis and ticks.
26 \sa setAxisPen()
26 \sa setAxisPen()
27 */
27 */
28
28
29
29
30 /*!
30 /*!
31 \fn bool QChartAxis::isGridLineVisible() const
31 \fn bool QChartAxis::isGridLineVisible() const
32 \brief Returns if grid is visible
32 \brief Returns if grid is visible
33 \sa setGridLineVisible()
33 \sa setGridLineVisible()
34 */
34 */
35
35
36 /*!
36 /*!
37 \fn QPen QChartAxis::gridLinePen() const
37 \fn QPen QChartAxis::gridLinePen() const
38 \brief Returns pen used to draw grid.
38 \brief Returns pen used to draw grid.
39 \sa setGridLinePen()
39 \sa setGridLinePen()
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn bool QChartAxis::labelsVisible() const
43 \fn bool QChartAxis::labelsVisible() const
44 \brief Returns if grid is visible
44 \brief Returns if grid is visible
45 \sa setLabelsVisible()
45 \sa setLabelsVisible()
46 */
46 */
47
47
48 /*!
48 /*!
49 \fn QPen QChartAxis::labelsPen() const
49 \fn QPen QChartAxis::labelsPen() const
50 \brief Returns the pen used to labels.
50 \brief Returns the pen used to labels.
51 \sa setLabelsPen()
51 \sa setLabelsPen()
52 */
52 */
53
53
54 /*!
54 /*!
55 \fn QBrush QChartAxis::labelsBrush() const
55 \fn QBrush QChartAxis::labelsBrush() const
56 \brief Returns brush used to draw labels.
56 \brief Returns brush used to draw labels.
57 \sa setLabelsBrush()
57 \sa setLabelsBrush()
58 */
58 */
59
59
60 /*!
60 /*!
61 \fn QFont QChartAxis::labelsFont() const
61 \fn QFont QChartAxis::labelsFont() const
62 \brief Returns font used to draw labels.
62 \brief Returns font used to draw labels.
63 \sa setLabelsFont()
63 \sa setLabelsFont()
64 */
64 */
65
65
66 /*!
66 /*!
67 \fn QFont QChartAxis::labelsAngle() const
67 \fn QFont QChartAxis::labelsAngle() const
68 \brief Returns angle used to draw labels.
68 \brief Returns angle used to draw labels.
69 \sa setLabelsAngle()
69 \sa setLabelsAngle()
70 */
70 */
71
71
72 /*!
72 /*!
73 \fn bool QChartAxis::shadesVisible() const
73 \fn bool QChartAxis::shadesVisible() const
74 \brief Returns if shades are visible.
74 \brief Returns if shades are visible.
75 \sa setShadesVisible()
75 \sa setShadesVisible()
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn qreal QChartAxis::shadesOpacity() const
79 \fn qreal QChartAxis::shadesOpacity() const
80 \brief Returns opacity of shades.
80 \brief Returns opacity of shades.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn QPen QChartAxis::shadesPen() const
84 \fn QPen QChartAxis::shadesPen() const
85 \brief Returns pen used to draw shades.
85 \brief Returns pen used to draw shades.
86 \sa setShadesPen()
86 \sa setShadesPen()
87 */
87 */
88
88
89 /*!
89 /*!
90 \fn QBrush QChartAxis::shadesBrush() const
90 \fn QBrush QChartAxis::shadesBrush() const
91 \brief Returns brush used to draw shades.
91 \brief Returns brush used to draw shades.
92 \sa setShadesBrush()
92 \sa setShadesBrush()
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn qreal QChartAxis::min() const
96 \fn qreal QChartAxis::min() const
97 \brief Returns minimum value on the axis.
97 \brief Returns minimum value on the axis.
98 \sa setMin()
98 \sa setMin()
99 */
99 */
100
100
101 /*!
101 /*!
102 \fn qreal QChartAxis::max() const
102 \fn qreal QChartAxis::max() const
103 \brief Returns maximim value on the axis.
103 \brief Returns maximim value on the axis.
104 \sa setMax()
104 \sa setMax()
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QChartAxis::minChanged(qreal min)
108 \fn void QChartAxis::minChanged(qreal min)
109 \brief Axis emits signal when \a min of axis has changed.
109 \brief Axis emits signal when \a min of axis has changed.
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QChartAxis::maxChanged(qreal max)
113 \fn void QChartAxis::maxChanged(qreal max)
114 \brief Axis emits signal when \a max of axis has changed.
114 \brief Axis emits signal when \a max of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
118 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
119 \brief Axis emits signal when \a min or \a max of axis has changed.
119 \brief Axis emits signal when \a min or \a max of axis has changed.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn int QChartAxis::ticksCount() const
123 \fn int QChartAxis::ticksCount() const
124 \brief Return number of ticks on the axis
124 \brief Return number of ticks on the axis
125 \sa setTicksCount()
125 \sa setTicksCount()
126 */
126 */
127
127
128 /*!
128 /*!
129 \fn void QChartAxis::updated()
129 \fn void QChartAxis::updated()
130 \brief \internal
130 \brief \internal
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
134 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
135 \brief \internal \a min \a max
135 \brief \internal \a min \a max
136 */
136 */
137
137
138 /*!
138 /*!
139 Constructs new axis object which is a child of \a parent. Ownership is taken by
139 Constructs new axis object which is a child of \a parent. Ownership is taken by
140 QChatView or QChart when axis added.
140 QChatView or QChart when axis added.
141 */
141 */
142
142
143 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
143 QChartAxis::QChartAxis(QObject *parent) : QObject(parent),
144 m_axisVisible(true),
144 m_axisVisible(true),
145 m_gridLineVisible(true),
145 m_gridLineVisible(true),
146 m_labelsVisible(true),
146 m_labelsVisible(true),
147 m_labelsAngle(0),
147 m_labelsAngle(0),
148 m_shadesVisible(false),
148 m_shadesVisible(false),
149 m_shadesOpacity(1.0),
149 m_shadesOpacity(1.0),
150 m_min(0),
150 m_min(0),
151 m_max(0),
151 m_max(0),
152 m_ticksCount(5),
152 m_ticksCount(5),
153 m_niceNumbers(false)
153 m_niceNumbers(false)
154 {
154 {
155
155
156 }
156 }
157
157
158 /*!
158 /*!
159 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
159 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
160 */
160 */
161
161
162 QChartAxis::~QChartAxis()
162 QChartAxis::~QChartAxis()
163 {
163 {
164 }
164 }
165
165
166 /*!
166 /*!
167 Sets \a pen used to draw axis line and ticks.
167 Sets \a pen used to draw axis line and ticks.
168 */
168 */
169 void QChartAxis::setAxisPen(const QPen& pen)
169 void QChartAxis::setAxisPen(const QPen &pen)
170 {
170 {
171 if (pen != m_axisPen) {
171 if (pen != m_axisPen) {
172 m_axisPen=pen;
172 m_axisPen = pen;
173 emit updated();
173 emit updated();
174 }
174 }
175 }
175 }
176
176
177 /*!
177 /*!
178 Sets if axis and ticks are \a visible.
178 Sets if axis and ticks are \a visible.
179 */
179 */
180 void QChartAxis::setAxisVisible(bool visible)
180 void QChartAxis::setAxisVisible(bool visible)
181 {
181 {
182 if (m_axisVisible!=visible) {
182 if (m_axisVisible != visible) {
183 m_axisVisible=visible;
183 m_axisVisible = visible;
184 emit updated();
184 emit updated();
185 }
185 }
186 }
186 }
187
187
188 /*!
188 /*!
189 Sets if grid line is \a visible.
189 Sets if grid line is \a visible.
190 */
190 */
191 void QChartAxis::setGridLineVisible(bool visible)
191 void QChartAxis::setGridLineVisible(bool visible)
192 {
192 {
193 if (m_gridLineVisible!=visible) {
193 if (m_gridLineVisible != visible) {
194 m_gridLineVisible=visible;
194 m_gridLineVisible = visible;
195 emit updated();
195 emit updated();
196 }
196 }
197 }
197 }
198
198
199 /*!
199 /*!
200 Sets \a pen used to draw grid line.
200 Sets \a pen used to draw grid line.
201 */
201 */
202 void QChartAxis::setGridLinePen(const QPen& pen)
202 void QChartAxis::setGridLinePen(const QPen &pen)
203 {
203 {
204 if (m_gridLinePen!=pen) {
204 if (m_gridLinePen != pen) {
205 m_gridLinePen=pen;
205 m_gridLinePen = pen;
206 emit updated();
206 emit updated();
207 }
207 }
208 }
208 }
209
209
210 /*!
210 /*!
211 Sets if axis' labels are \a visible.
211 Sets if axis' labels are \a visible.
212 */
212 */
213 void QChartAxis::setLabelsVisible(bool visible)
213 void QChartAxis::setLabelsVisible(bool visible)
214 {
214 {
215 if(m_labelsVisible!=visible) {
215 if (m_labelsVisible != visible) {
216 m_labelsVisible=visible;
216 m_labelsVisible = visible;
217 emit updated();
217 emit updated();
218 }
218 }
219 }
219 }
220
220
221 /*!
221 /*!
222 Sets \a pen used to draw labels.
222 Sets \a pen used to draw labels.
223 */
223 */
224 void QChartAxis::setLabelsPen(const QPen& pen)
224 void QChartAxis::setLabelsPen(const QPen &pen)
225 {
225 {
226 if(m_labelsPen!=pen) {
226 if (m_labelsPen != pen) {
227 m_labelsPen=pen;
227 m_labelsPen = pen;
228 emit updated();
228 emit updated();
229 }
229 }
230 }
230 }
231
231
232 /*!
232 /*!
233 Sets \a brush used to draw labels.
233 Sets \a brush used to draw labels.
234 */
234 */
235 void QChartAxis::setLabelsBrush(const QBrush& brush)
235 void QChartAxis::setLabelsBrush(const QBrush &brush)
236 {
236 {
237 if(m_labelsBrush!=brush) {
237 if (m_labelsBrush != brush) {
238 m_labelsBrush=brush;
238 m_labelsBrush = brush;
239 emit updated();
239 emit updated();
240 }
240 }
241 }
241 }
242
242
243 /*!
243 /*!
244 Sets \a font used to draw labels.
244 Sets \a font used to draw labels.
245 */
245 */
246 void QChartAxis::setLabelsFont(const QFont& font)
246 void QChartAxis::setLabelsFont(const QFont &font)
247 {
247 {
248 if(m_labelsFont!=font) {
248 if (m_labelsFont != font) {
249 m_labelsFont=font;
249 m_labelsFont = font;
250 emit updated();
250 emit updated();
251 }
251 }
252 }
252 }
253
253
254 /*!
254 /*!
255 Sets \a angle for all the labels on given axis.
255 Sets \a angle for all the labels on given axis.
256 */
256 */
257 void QChartAxis::setLabelsAngle(int angle)
257 void QChartAxis::setLabelsAngle(int angle)
258 {
258 {
259 if(m_labelsAngle!=angle) {
259 if (m_labelsAngle != angle) {
260 m_labelsAngle=angle;
260 m_labelsAngle = angle;
261 emit updated();
261 emit updated();
262 }
262 }
263 }
263 }
264
264
265 /*!
265 /*!
266 Sets if shades are \a visible.
266 Sets if shades are \a visible.
267 */
267 */
268 void QChartAxis::setShadesVisible(bool visible)
268 void QChartAxis::setShadesVisible(bool visible)
269 {
269 {
270 if(m_shadesVisible!=visible) {
270 if (m_shadesVisible != visible) {
271 m_shadesVisible=visible;
271 m_shadesVisible = visible;
272 emit updated();
272 emit updated();
273 }
273 }
274 }
274 }
275
275
276 /*!
276 /*!
277 Sets \a pen used to draw shades.
277 Sets \a pen used to draw shades.
278 */
278 */
279 void QChartAxis::setShadesPen(const QPen& pen)
279 void QChartAxis::setShadesPen(const QPen &pen)
280 {
280 {
281 if(m_shadesPen!=pen) {
281 if (m_shadesPen != pen) {
282 m_shadesPen=pen;
282 m_shadesPen = pen;
283 emit updated();
283 emit updated();
284 }
284 }
285 }
285 }
286
286
287 /*!
287 /*!
288 Sets \a brush used to draw shades.
288 Sets \a brush used to draw shades.
289 */
289 */
290 void QChartAxis::setShadesBrush(const QBrush& brush)
290 void QChartAxis::setShadesBrush(const QBrush &brush)
291 {
291 {
292 if(m_shadesBrush!=brush) {
292 if (m_shadesBrush != brush) {
293 m_shadesBrush=brush;
293 m_shadesBrush = brush;
294 emit updated();
294 emit updated();
295 }
295 }
296 }
296 }
297
297
298 /*!
298 /*!
299 Sets \a opacity of the shades.
299 Sets \a opacity of the shades.
300 */
300 */
301 void QChartAxis::setShadesOpacity(qreal opacity)
301 void QChartAxis::setShadesOpacity(qreal opacity)
302 {
302 {
303 if(m_shadesOpacity!=opacity) {
303 if (m_shadesOpacity != opacity) {
304 m_shadesOpacity=opacity;
304 m_shadesOpacity=opacity;
305 emit updated();
305 emit updated();
306 }
306 }
307 }
307 }
308
308
309 /*!
309 /*!
310 Sets \a min value on the axis.
310 Sets \a min value on the axis.
311 */
311 */
312 void QChartAxis::setMin(qreal min)
312 void QChartAxis::setMin(qreal min)
313 {
313 {
314 setRange(min,m_max);
314 setRange(min,m_max);
315 }
315 }
316
316
317 /*!
317 /*!
318 Sets \a max value on the axis.
318 Sets \a max value on the axis.
319 */
319 */
320 void QChartAxis::setMax(qreal max)
320 void QChartAxis::setMax(qreal max)
321 {
321 {
322 setRange(m_min,max);
322 setRange(m_min,max);
323 }
323 }
324
324
325 /*!
325 /*!
326 Sets range from \a min to \a max on the axis.
326 Sets range from \a min to \a max on the axis.
327 */
327 */
328 void QChartAxis::setRange(qreal min, qreal max)
328 void QChartAxis::setRange(qreal min, qreal max)
329 {
329 {
330
331
332 bool changed = false;
330 bool changed = false;
333 if(m_min!=min) {
331 if (m_min != min) {
334 m_min=min;
332 m_min = min;
335 changed=true;
333 changed = true;
336 emit minChanged(min);
334 emit minChanged(min);
337 }
335 }
338
336
339 if(m_max!=max) {
337 if (m_max != max) {
340 m_max=max;
338 m_max = max;
341 changed=true;
339 changed = true;
342 emit maxChanged(max);
340 emit maxChanged(max);
343 }
341 }
344
342
345 if(changed) {
343 if (changed) {
346 emit rangeChanged(m_min,m_max);
344 emit rangeChanged(m_min,m_max);
347 emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers);
345 emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers);
348 }
346 }
349 }
347 }
350
348
351 /*!
349 /*!
352 Sets \a count for ticks on the axis.
350 Sets \a count for ticks on the axis.
353 */
351 */
354 void QChartAxis::setTicksCount(int count)
352 void QChartAxis::setTicksCount(int count)
355 {
353 {
356 if(m_ticksCount!=count) {
354 if (m_ticksCount != count) {
357 m_ticksCount=count;
355 m_ticksCount = count;
358 emit ticksCountChanged(count);
356 emit ticksCountChanged(count);
359 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
357 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
360 }
358 }
361 }
359 }
362
360
363 /*!
361 /*!
364 Sets axis, shades, labels and grid lines to be visible.
362 Sets axis, shades, labels and grid lines to be visible.
365 */
363 */
366 void QChartAxis::show()
364 void QChartAxis::show()
367 {
365 {
368 m_axisVisible=true;
366 m_axisVisible=true;
369 m_gridLineVisible=true;
367 m_gridLineVisible=true;
370 m_labelsVisible=true;
368 m_labelsVisible=true;
371 m_shadesVisible=true;
369 m_shadesVisible=true;
372 emit updated();
370 emit updated();
373 }
371 }
374
372
375 /*!
373 /*!
376 Sets axis, shades, labels and grid lines to not be visible.
374 Sets axis, shades, labels and grid lines to not be visible.
377 */
375 */
378 void QChartAxis::hide()
376 void QChartAxis::hide()
379 {
377 {
380 m_axisVisible=false;
378 m_axisVisible = false;
381 m_gridLineVisible=false;
379 m_gridLineVisible = false;
382 m_labelsVisible=false;
380 m_labelsVisible = false;
383 m_shadesVisible=false;
381 m_shadesVisible = false;
384 emit updated();
382 emit updated();
385 }
383 }
386
384
387 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count)
385 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count)
388 {
386 {
389 setRange(min,max);
387 setRange(min,max);
390 setTicksCount(count);
388 setTicksCount(count);
391 }
389 }
392
390
393 void QChartAxis::setNiceNumbers(bool enabled)
391 void QChartAxis::setNiceNumbers(bool enabled)
394 {
392 {
395 if(m_niceNumbers!=enabled){
393 if (m_niceNumbers != enabled){
396 m_niceNumbers=enabled;
394 m_niceNumbers = enabled;
397 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
395 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
398 }
396 }
399 }
397 }
400
398
401 #include "moc_qchartaxis.cpp"
399 #include "moc_qchartaxis.cpp"
402
400
403 QTCOMMERCIALCHART_END_NAMESPACE
401 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,62 +1,62
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(const QBarCategories& categories)
16 void QChartAxisCategories::insert(const QBarCategories &categories)
17 {
17 {
18 int i=1;
18 int i=1;
19 foreach(QString string , categories){
19 foreach (QString string , categories) {
20 m_map.insert(i,string);
20 m_map.insert(i,string);
21 i++;
21 i++;
22 }
22 }
23 emit updated();
23 emit updated();
24 }
24 }
25
25
26 void QChartAxisCategories::insert(qreal value,QString label)
26 void QChartAxisCategories::insert(qreal value,QString label)
27 {
27 {
28 m_map.insert(value,label);
28 m_map.insert(value,label);
29 emit updated();
29 emit updated();
30 }
30 }
31
31
32 void QChartAxisCategories::remove(qreal value)
32 void QChartAxisCategories::remove(qreal value)
33 {
33 {
34 m_map.remove(value);
34 m_map.remove(value);
35 emit updated();
35 emit updated();
36 }
36 }
37
37
38 void QChartAxisCategories::clear()
38 void QChartAxisCategories::clear()
39 {
39 {
40 m_map.clear();
40 m_map.clear();
41 emit updated();
41 emit updated();
42 }
42 }
43
43
44 int QChartAxisCategories::count()
44 int QChartAxisCategories::count()
45 {
45 {
46 return m_map.count();
46 return m_map.count();
47 emit updated();
47 emit updated();
48 }
48 }
49
49
50 QList<qreal> QChartAxisCategories::values() const
50 QList<qreal> QChartAxisCategories::values() const
51 {
51 {
52 return m_map.keys();
52 return m_map.keys();
53 }
53 }
54
54
55 QString QChartAxisCategories::label(qreal value) const
55 QString QChartAxisCategories::label(qreal value) const
56 {
56 {
57 return m_map.value(value);
57 return m_map.value(value);
58 }
58 }
59
59
60 #include "moc_qchartaxiscategories.cpp"
60 #include "moc_qchartaxiscategories.cpp"
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now