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