##// END OF EJS Templates
more minor code review fixes
sauimone -
r745:477bbc361e58
parent child
Show More
@@ -10,18 +10,17 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);
@@ -30,8 +29,8 m_ticksCount(0)
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 }
@@ -43,13 +42,13 Axis::~Axis()
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
@@ -61,7 +60,7 void Axis::deleteItems(int count)
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());
@@ -70,10 +69,11 void Axis::deleteItems(int count)
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
@@ -85,22 +85,21 bool Axis::createLabels(QStringList& labels,qreal min, qreal max,int ticks) cons
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;
@@ -160,49 +159,49 void Axis::setLabelsAngle(int angle)
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);
@@ -244,7 +243,7 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) {
@@ -353,34 +352,29 void Axis::handleAxisCategoriesUpdated()
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
@@ -403,7 +397,7 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
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
@@ -412,7 +406,7 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
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 }
@@ -15,7 +15,7 class Axis : public Chart
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;};
@@ -35,15 +35,15 public:
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;};
@@ -52,7 +52,7 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:
@@ -61,10 +61,10 private:
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:
@@ -91,7 +91,7 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)
@@ -13,29 +13,29 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
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;};
@@ -43,9 +43,9 public:
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;}
@@ -14,7 +14,7 private:
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;
General Comments 0
You need to be logged in to leave comments. Login now