##// 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 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) :
13 Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) : Chart(presenter),
14 Chart(presenter),
14 m_chartAxis(axis),
15 m_chartAxis(axis),
15 m_type(type),
16 m_type(type),
16 m_labelsAngle(0),
17 m_labelsAngle(0),
17 m_grid(presenter->rootItem()),
18 m_grid(presenter->rootItem()),
18 m_shades(presenter->rootItem()),
19 m_shades(presenter->rootItem()),
19 m_labels(presenter->rootItem()),
20 m_labels(presenter->rootItem()),
20 m_axis(presenter->rootItem()),
21 m_axis(presenter->rootItem()),
21 m_min(0),
22 m_min(0),
22 m_max(0),
23 m_max(0),
23 m_ticksCount(0)
24 m_ticksCount(0)
25 {
24 {
26 //initial initialization
25 //initial initialization
27 m_axis.setZValue(ChartPresenter::AxisZValue);
26 m_axis.setZValue(ChartPresenter::AxisZValue);
@@ -30,8 +29,8 m_ticksCount(0)
30 m_shades.setZValue(ChartPresenter::ShadesZValue);
29 m_shades.setZValue(ChartPresenter::ShadesZValue);
31 m_grid.setZValue(ChartPresenter::GridZValue);
30 m_grid.setZValue(ChartPresenter::GridZValue);
32
31
33 QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
32 connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
34 QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
33 connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
35
34
36 handleAxisUpdated();
35 handleAxisUpdated();
37 }
36 }
@@ -43,13 +42,13 Axis::~Axis()
43 void Axis::createItems(int count)
42 void Axis::createItems(int count)
44 {
43 {
45
44
46 if(m_axis.children().size()==0)
45 if (m_axis.children().size()==0)
47 m_axis.addToGroup(new AxisItem(this));
46 m_axis.addToGroup(new AxisItem(this));
48 for (int i = 0; i < count; ++i) {
47 for (int i = 0; i < count; ++i) {
49 m_grid.addToGroup(new QGraphicsLineItem());
48 m_grid.addToGroup(new QGraphicsLineItem());
50 m_labels.addToGroup(new QGraphicsSimpleTextItem());
49 m_labels.addToGroup(new QGraphicsSimpleTextItem());
51 m_axis.addToGroup(new QGraphicsLineItem());
50 m_axis.addToGroup(new QGraphicsLineItem());
52 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());
53 }
52 }
54 }
53 }
55
54
@@ -61,7 +60,7 void Axis::deleteItems(int count)
61 QList<QGraphicsItem *> axis = m_axis.childItems();
60 QList<QGraphicsItem *> axis = m_axis.childItems();
62
61
63 for (int i = 0; i < count; ++i) {
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 delete(lines.takeLast());
64 delete(lines.takeLast());
66 delete(labels.takeLast());
65 delete(labels.takeLast());
67 delete(axis.takeLast());
66 delete(axis.takeLast());
@@ -70,10 +69,11 void Axis::deleteItems(int count)
70
69
71 void Axis::updateLayout(QVector<qreal>& layout)
70 void Axis::updateLayout(QVector<qreal>& layout)
72 {
71 {
73 if(animator()){
72 if (animator()) {
74 animator()->updateLayout(this,layout);
73 animator()->updateLayout(this,layout);
74 } else {
75 setLayout(layout);
75 }
76 }
76 else setLayout(layout);
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
@@ -85,22 +85,21 bool Axis::createLabels(QStringList& labels,qreal min, qreal max,int ticks) cons
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 }
94 } else {
95 else {
96 QList<qreal> values = categories->values();
95 QList<qreal> values = categories->values();
97 for(int i=0; i< ticks; i++) {
96 for (int i=0; i< ticks; i++) {
98 qreal value = (min + (i * (max - min)/ (ticks-1)));
97 qreal value = (min + (i * (max - min)/ (ticks-1)));
99 int j=0;
98 int j=0;
100 for(; j<values.count(); j++){
99 for (; j<values.count(); j++) {
101 if (values.at(j) > value) break;
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 QString label = categories->label(value);
104 QString label = categories->label(value);
106 labels << label;
105 labels << label;
@@ -160,49 +159,49 void Axis::setLabelsAngle(int angle)
160 m_labelsAngle=angle;
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 foreach(QGraphicsItem* item , m_labels.childItems()) {
164 foreach(QGraphicsItem* item , m_labels.childItems()) {
166 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
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 foreach(QGraphicsItem* item , m_labels.childItems()) {
171 foreach(QGraphicsItem* item , m_labels.childItems()) {
173 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
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 foreach(QGraphicsItem* item , m_labels.childItems()) {
178 foreach(QGraphicsItem* item , m_labels.childItems()) {
180 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
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 foreach(QGraphicsItem* item , m_shades.childItems()) {
185 foreach(QGraphicsItem* item , m_shades.childItems()) {
187 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
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 foreach(QGraphicsItem* item , m_shades.childItems()) {
192 foreach(QGraphicsItem* item , m_shades.childItems()) {
194 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
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 foreach(QGraphicsItem* item , m_axis.childItems()) {
199 foreach(QGraphicsItem* item , m_axis.childItems()) {
201 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
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 foreach(QGraphicsItem* item , m_grid.childItems()) {
206 foreach(QGraphicsItem* item , m_grid.childItems()) {
208 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
207 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
@@ -244,7 +243,7 void Axis::setLayout(QVector<qreal>& layout)
244 {
243 {
245 int diff = m_layoutVector.size() - layout.size();
244 int diff = m_layoutVector.size() - layout.size();
246
245
247 if(diff>0) {
246 if (diff>0) {
248 deleteItems(diff);
247 deleteItems(diff);
249 }
248 }
250 else if(diff<0) {
249 else if(diff<0) {
@@ -353,34 +352,29 void Axis::handleAxisCategoriesUpdated()
353 void Axis::handleAxisUpdated()
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 setAxisOpacity(100);
358 setAxisOpacity(100);
360 }
359 } else {
361 else {
362 setAxisOpacity(0);
360 setAxisOpacity(0);
363 }
361 }
364
362
365 if(m_chartAxis->isGridLineVisible()) {
363 if(m_chartAxis->isGridLineVisible()) {
366 setGridOpacity(100);
364 setGridOpacity(100);
367 }
365 } else {
368 else {
369 setGridOpacity(0);
366 setGridOpacity(0);
370 }
367 }
371
368
372 if(m_chartAxis->labelsVisible())
369 if(m_chartAxis->labelsVisible()) {
373 {
374 setLabelsOpacity(100);
370 setLabelsOpacity(100);
375 }
371 } else {
376 else {
377 setLabelsOpacity(0);
372 setLabelsOpacity(0);
378 }
373 }
379
374
380 if(m_chartAxis->shadesVisible()) {
375 if (m_chartAxis->shadesVisible()) {
381 setShadesOpacity(m_chartAxis->shadesOpacity());
376 setShadesOpacity(m_chartAxis->shadesOpacity());
382 }
377 } else {
383 else {
384 setShadesOpacity(0);
378 setShadesOpacity(0);
385 }
379 }
386
380
@@ -403,7 +397,7 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
403 m_max = max;
397 m_max = max;
404 m_ticksCount= tickCount;
398 m_ticksCount= tickCount;
405
399
406 if(isEmpty()) return;
400 if (isEmpty()) return;
407 QVector<qreal> layout = calculateLayout();
401 QVector<qreal> layout = calculateLayout();
408 updateLayout(layout);
402 updateLayout(layout);
409
403
@@ -412,7 +406,7 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
412 void Axis::handleGeometryChanged(const QRectF& rect)
406 void Axis::handleGeometryChanged(const QRectF& rect)
413 {
407 {
414 m_rect = rect;
408 m_rect = rect;
415 if(isEmpty()) return;
409 if (isEmpty()) return;
416 QVector<qreal> layout = calculateLayout();
410 QVector<qreal> layout = calculateLayout();
417 updateLayout(layout);
411 updateLayout(layout);
418 }
412 }
@@ -15,7 +15,7 class Axis : public Chart
15 public:
15 public:
16 enum AxisType{X_AXIS,Y_AXIS};
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 ~Axis();
19 ~Axis();
20
20
21 AxisType axisType() const {return m_type;};
21 AxisType axisType() const {return m_type;};
@@ -35,15 +35,15 public:
35 void setLabelsAngle(int angle);
35 void setLabelsAngle(int angle);
36 int labelsAngle()const { return m_labelsAngle; }
36 int labelsAngle()const { return m_labelsAngle; }
37
37
38 void setShadesBrush(const QBrush& brush);
38 void setShadesBrush(const QBrush &brush);
39 void setShadesPen(const QPen& pen);
39 void setShadesPen(const QPen &pen);
40
40
41 void setAxisPen(const QPen& pen);
41 void setAxisPen(const QPen &pen);
42 void setGridPen(const QPen& pen);
42 void setGridPen(const QPen &pen);
43
43
44 void setLabelsPen(const QPen& pen);
44 void setLabelsPen(const QPen &pen);
45 void setLabelsBrush(const QBrush& brush);
45 void setLabelsBrush(const QBrush &brush);
46 void setLabelsFont(const QFont& font);
46 void setLabelsFont(const QFont &font);
47
47
48 inline QRectF geometry() const { return m_rect; }
48 inline QRectF geometry() const { return m_rect; }
49 inline QVector<qreal> layout() { return m_layoutVector;};
49 inline QVector<qreal> layout() { return m_layoutVector;};
@@ -52,7 +52,7 public slots:
52 void handleAxisUpdated();
52 void handleAxisUpdated();
53 void handleAxisCategoriesUpdated();
53 void handleAxisCategoriesUpdated();
54 void handleRangeChanged(qreal min , qreal max,int tickCount);
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 private:
58 private:
@@ -61,10 +61,10 private:
61 void deleteItems(int count);
61 void deleteItems(int count);
62
62
63 QVector<qreal> calculateLayout() const;
63 QVector<qreal> calculateLayout() const;
64 void updateLayout(QVector<qreal>& layout);
64 void updateLayout(QVector<qreal> &layout);
65 void setLayout(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 void axisSelected();
68 void axisSelected();
69
69
70 private:
70 private:
@@ -91,7 +91,7 class AxisItem: public QGraphicsLineItem
91 {
91 {
92 public:
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 protected:
96 protected:
97 void mousePressEvent(QGraphicsSceneMouseEvent *event)
97 void mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -13,29 +13,29 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
13 Q_OBJECT
13 Q_OBJECT
14 public:
14 public:
15
15
16 QChartAxis(QObject* parent =0);
16 QChartAxis(QObject *parent =0);
17 ~QChartAxis();
17 ~QChartAxis();
18
18
19 //axis handling
19 //axis handling
20 bool isAxisVisible() const { return m_axisVisible;};
20 bool isAxisVisible() const { return m_axisVisible;};
21 void setAxisVisible(bool visible);
21 void setAxisVisible(bool visible);
22 void setAxisPen(const QPen& pen);
22 void setAxisPen(const QPen &pen);
23 QPen axisPen() const { return m_axisPen;};
23 QPen axisPen() const { return m_axisPen;};
24
24
25 //grid handling
25 //grid handling
26 bool isGridLineVisible() const { return m_gridLineVisible;};
26 bool isGridLineVisible() const { return m_gridLineVisible;};
27 void setGridLineVisible(bool visible);
27 void setGridLineVisible(bool visible);
28 void setGridLinePen(const QPen& pen);
28 void setGridLinePen(const QPen &pen);
29 QPen gridLinePen() const {return m_gridLinePen;}
29 QPen gridLinePen() const {return m_gridLinePen;}
30
30
31 //labels handling
31 //labels handling
32 bool labelsVisible() const { return m_labelsVisible;};
32 bool labelsVisible() const { return m_labelsVisible;};
33 void setLabelsVisible(bool visible);
33 void setLabelsVisible(bool visible);
34 void setLabelsPen(const QPen& pen);
34 void setLabelsPen(const QPen &pen);
35 QPen labelsPen() const { return m_labelsPen;}
35 QPen labelsPen() const { return m_labelsPen;}
36 void setLabelsBrush(const QBrush& brush);
36 void setLabelsBrush(const QBrush &brush);
37 QBrush labelsBrush() const { return m_labelsBrush;}
37 QBrush labelsBrush() const { return m_labelsBrush;}
38 void setLabelsFont(const QFont& font);
38 void setLabelsFont(const QFont &font);
39 QFont labelsFont() const { return m_labelsFont;}
39 QFont labelsFont() const { return m_labelsFont;}
40 void setLabelsAngle(int angle);
40 void setLabelsAngle(int angle);
41 int labelsAngle() const { return m_labelsAngle;};
41 int labelsAngle() const { return m_labelsAngle;};
@@ -43,9 +43,9 public:
43 //shades handling
43 //shades handling
44 bool shadesVisible() const { return m_shadesVisible;};
44 bool shadesVisible() const { return m_shadesVisible;};
45 void setShadesVisible(bool visible);
45 void setShadesVisible(bool visible);
46 void setShadesPen(const QPen& pen);
46 void setShadesPen(const QPen &pen);
47 QPen shadesPen() const { return m_shadesPen;}
47 QPen shadesPen() const { return m_shadesPen;}
48 void setShadesBrush(const QBrush& brush);
48 void setShadesBrush(const QBrush &brush);
49 QBrush shadesBrush() const { return m_shadesBrush;}
49 QBrush shadesBrush() const { return m_shadesBrush;}
50 void setShadesOpacity(qreal opacity);
50 void setShadesOpacity(qreal opacity);
51 qreal shadesOpacity() const { return m_shadesOpacity;}
51 qreal shadesOpacity() const { return m_shadesOpacity;}
@@ -14,7 +14,7 private:
14 public:
14 public:
15 ~QChartAxisCategories();
15 ~QChartAxisCategories();
16
16
17 void insert(const QBarCategories& category);
17 void insert(const QBarCategories &category);
18 void insert(qreal value,QString label);
18 void insert(qreal value,QString label);
19 void remove(qreal value);
19 void remove(qreal value);
20 QList<qreal> values() const;
20 QList<qreal> values() const;
General Comments 0
You need to be logged in to leave comments. Login now