From 477bbc361e58834792681ac6740f09588017b6b3 2012-03-27 14:24:32 From: sauimone Date: 2012-03-27 14:24:32 Subject: [PATCH] more minor code review fixes --- diff --git a/src/axis/axisitem.cpp b/src/axis/axisitem.cpp index af2e0a7..a27c884 100644 --- a/src/axis/axisitem.cpp +++ b/src/axis/axisitem.cpp @@ -10,18 +10,17 @@ static int label_padding = 5; QTCOMMERCIALCHART_BEGIN_NAMESPACE -Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) : -Chart(presenter), -m_chartAxis(axis), -m_type(type), -m_labelsAngle(0), -m_grid(presenter->rootItem()), -m_shades(presenter->rootItem()), -m_labels(presenter->rootItem()), -m_axis(presenter->rootItem()), -m_min(0), -m_max(0), -m_ticksCount(0) +Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) : Chart(presenter), + m_chartAxis(axis), + m_type(type), + m_labelsAngle(0), + m_grid(presenter->rootItem()), + m_shades(presenter->rootItem()), + m_labels(presenter->rootItem()), + m_axis(presenter->rootItem()), + m_min(0), + m_max(0), + m_ticksCount(0) { //initial initialization m_axis.setZValue(ChartPresenter::AxisZValue); @@ -30,8 +29,8 @@ m_ticksCount(0) m_shades.setZValue(ChartPresenter::ShadesZValue); m_grid.setZValue(ChartPresenter::GridZValue); - QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); - QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); + connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); + connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); handleAxisUpdated(); } @@ -43,13 +42,13 @@ Axis::~Axis() void Axis::createItems(int count) { - if(m_axis.children().size()==0) - m_axis.addToGroup(new AxisItem(this)); + if (m_axis.children().size()==0) + m_axis.addToGroup(new AxisItem(this)); for (int i = 0; i < count; ++i) { - m_grid.addToGroup(new QGraphicsLineItem()); - m_labels.addToGroup(new QGraphicsSimpleTextItem()); - m_axis.addToGroup(new QGraphicsLineItem()); - if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem()); + m_grid.addToGroup(new QGraphicsLineItem()); + m_labels.addToGroup(new QGraphicsSimpleTextItem()); + m_axis.addToGroup(new QGraphicsLineItem()); + if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem()); } } @@ -61,7 +60,7 @@ void Axis::deleteItems(int count) QList axis = m_axis.childItems(); for (int i = 0; i < count; ++i) { - if(lines.size()%2 && lines.size()>1) delete(shades.takeLast()); + if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); delete(lines.takeLast()); delete(labels.takeLast()); delete(axis.takeLast()); @@ -70,10 +69,11 @@ void Axis::deleteItems(int count) void Axis::updateLayout(QVector& layout) { - if(animator()){ - animator()->updateLayout(this,layout); + if (animator()) { + animator()->updateLayout(this,layout); + } else { + setLayout(layout); } - else setLayout(layout); } 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 bool category = categories->count()>0; - if(!category) { + if (!category) { int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); for(int i=0; i< ticks; i++) { qreal value = min + (i * (max - min)/ (ticks-1)); labels << QString::number(value,'f',n); } - } - else { + } else { QList values = categories->values(); - for(int i=0; i< ticks; i++) { + for (int i=0; i< ticks; i++) { qreal value = (min + (i * (max - min)/ (ticks-1))); int j=0; - for(; j value) break; } - if(j!=0) value=values.at(j-1); + if (j!=0) value=values.at(j-1); QString label = categories->label(value); labels << label; @@ -160,49 +159,49 @@ void Axis::setLabelsAngle(int angle) m_labelsAngle=angle; } -void Axis::setLabelsPen(const QPen& pen) +void Axis::setLabelsPen(const QPen &pen) { foreach(QGraphicsItem* item , m_labels.childItems()) { static_cast(item)->setPen(pen); } } -void Axis::setLabelsBrush(const QBrush& brush) +void Axis::setLabelsBrush(const QBrush &brush) { foreach(QGraphicsItem* item , m_labels.childItems()) { static_cast(item)->setBrush(brush); } } -void Axis::setLabelsFont(const QFont& font) +void Axis::setLabelsFont(const QFont &font) { foreach(QGraphicsItem* item , m_labels.childItems()) { static_cast(item)->setFont(font); } } -void Axis::setShadesBrush(const QBrush& brush) +void Axis::setShadesBrush(const QBrush &brush) { foreach(QGraphicsItem* item , m_shades.childItems()) { static_cast(item)->setBrush(brush); } } -void Axis::setShadesPen(const QPen& pen) +void Axis::setShadesPen(const QPen &pen) { foreach(QGraphicsItem* item , m_shades.childItems()) { static_cast(item)->setPen(pen); } } -void Axis::setAxisPen(const QPen& pen) +void Axis::setAxisPen(const QPen &pen) { foreach(QGraphicsItem* item , m_axis.childItems()) { static_cast(item)->setPen(pen); } } -void Axis::setGridPen(const QPen& pen) +void Axis::setGridPen(const QPen &pen) { foreach(QGraphicsItem* item , m_grid.childItems()) { static_cast(item)->setPen(pen); @@ -244,7 +243,7 @@ void Axis::setLayout(QVector& layout) { int diff = m_layoutVector.size() - layout.size(); - if(diff>0) { + if (diff>0) { deleteItems(diff); } else if(diff<0) { @@ -353,34 +352,29 @@ void Axis::handleAxisCategoriesUpdated() void Axis::handleAxisUpdated() { - if(isEmpty()) return; + if (isEmpty()) return; - if(m_chartAxis->isAxisVisible()) { + if (m_chartAxis->isAxisVisible()) { setAxisOpacity(100); - } - else { + } else { setAxisOpacity(0); } if(m_chartAxis->isGridLineVisible()) { setGridOpacity(100); - } - else { + } else { setGridOpacity(0); } - if(m_chartAxis->labelsVisible()) - { + if(m_chartAxis->labelsVisible()) { setLabelsOpacity(100); - } - else { + } else { setLabelsOpacity(0); } - if(m_chartAxis->shadesVisible()) { + if (m_chartAxis->shadesVisible()) { setShadesOpacity(m_chartAxis->shadesOpacity()); - } - else { + } else { setShadesOpacity(0); } @@ -403,7 +397,7 @@ void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) m_max = max; m_ticksCount= tickCount; - if(isEmpty()) return; + if (isEmpty()) return; QVector layout = calculateLayout(); updateLayout(layout); @@ -412,7 +406,7 @@ void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) void Axis::handleGeometryChanged(const QRectF& rect) { m_rect = rect; - if(isEmpty()) return; + if (isEmpty()) return; QVector layout = calculateLayout(); updateLayout(layout); } diff --git a/src/axis/axisitem_p.h b/src/axis/axisitem_p.h index 11e1b1b..68b7689 100644 --- a/src/axis/axisitem_p.h +++ b/src/axis/axisitem_p.h @@ -15,7 +15,7 @@ class Axis : public Chart public: enum AxisType{X_AXIS,Y_AXIS}; - Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type = X_AXIS); + Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS); ~Axis(); AxisType axisType() const {return m_type;}; @@ -35,15 +35,15 @@ public: void setLabelsAngle(int angle); int labelsAngle()const { return m_labelsAngle; } - void setShadesBrush(const QBrush& brush); - void setShadesPen(const QPen& pen); + void setShadesBrush(const QBrush &brush); + void setShadesPen(const QPen &pen); - void setAxisPen(const QPen& pen); - void setGridPen(const QPen& pen); + void setAxisPen(const QPen &pen); + void setGridPen(const QPen &pen); - void setLabelsPen(const QPen& pen); - void setLabelsBrush(const QBrush& brush); - void setLabelsFont(const QFont& font); + void setLabelsPen(const QPen &pen); + void setLabelsBrush(const QBrush &brush); + void setLabelsFont(const QFont &font); inline QRectF geometry() const { return m_rect; } inline QVector layout() { return m_layoutVector;}; @@ -52,7 +52,7 @@ public slots: void handleAxisUpdated(); void handleAxisCategoriesUpdated(); void handleRangeChanged(qreal min , qreal max,int tickCount); - void handleGeometryChanged(const QRectF& size); + void handleGeometryChanged(const QRectF &size); private: @@ -61,10 +61,10 @@ private: void deleteItems(int count); QVector calculateLayout() const; - void updateLayout(QVector& layout); - void setLayout(QVector& layout); + void updateLayout(QVector &layout); + void setLayout(QVector &layout); - bool createLabels(QStringList& labels,qreal min, qreal max,int ticks) const; + bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; void axisSelected(); private: @@ -91,7 +91,7 @@ class AxisItem: public QGraphicsLineItem { public: - AxisItem(Axis* axis,QGraphicsItem* parent=0):QGraphicsLineItem(parent),m_axis(axis){}; + AxisItem(Axis *axis, QGraphicsItem *parent=0) : QGraphicsLineItem(parent), m_axis(axis) {}; protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/axis/qchartaxis.h b/src/axis/qchartaxis.h index c453a7c..7b7907f 100644 --- a/src/axis/qchartaxis.h +++ b/src/axis/qchartaxis.h @@ -13,29 +13,29 @@ class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject Q_OBJECT public: - QChartAxis(QObject* parent =0); + QChartAxis(QObject *parent =0); ~QChartAxis(); //axis handling bool isAxisVisible() const { return m_axisVisible;}; void setAxisVisible(bool visible); - void setAxisPen(const QPen& pen); + void setAxisPen(const QPen &pen); QPen axisPen() const { return m_axisPen;}; //grid handling bool isGridLineVisible() const { return m_gridLineVisible;}; void setGridLineVisible(bool visible); - void setGridLinePen(const QPen& pen); + void setGridLinePen(const QPen &pen); QPen gridLinePen() const {return m_gridLinePen;} //labels handling bool labelsVisible() const { return m_labelsVisible;}; void setLabelsVisible(bool visible); - void setLabelsPen(const QPen& pen); + void setLabelsPen(const QPen &pen); QPen labelsPen() const { return m_labelsPen;} - void setLabelsBrush(const QBrush& brush); + void setLabelsBrush(const QBrush &brush); QBrush labelsBrush() const { return m_labelsBrush;} - void setLabelsFont(const QFont& font); + void setLabelsFont(const QFont &font); QFont labelsFont() const { return m_labelsFont;} void setLabelsAngle(int angle); int labelsAngle() const { return m_labelsAngle;}; @@ -43,9 +43,9 @@ public: //shades handling bool shadesVisible() const { return m_shadesVisible;}; void setShadesVisible(bool visible); - void setShadesPen(const QPen& pen); + void setShadesPen(const QPen &pen); QPen shadesPen() const { return m_shadesPen;} - void setShadesBrush(const QBrush& brush); + void setShadesBrush(const QBrush &brush); QBrush shadesBrush() const { return m_shadesBrush;} void setShadesOpacity(qreal opacity); qreal shadesOpacity() const { return m_shadesOpacity;} diff --git a/src/axis/qchartaxiscategories.h b/src/axis/qchartaxiscategories.h index 149a0b3..c268910 100644 --- a/src/axis/qchartaxiscategories.h +++ b/src/axis/qchartaxiscategories.h @@ -14,7 +14,7 @@ private: public: ~QChartAxisCategories(); - void insert(const QBarCategories& category); + void insert(const QBarCategories &category); void insert(qreal value,QString label); void remove(qreal value); QList values() const;