From ea8e9f62638effecc8633cadc51eca69b0dd85cd 2012-03-28 07:36:29 From: sauimone Date: 2012-03-28 07:36:29 Subject: [PATCH] minor code review fixes --- diff --git a/src/axis/axisitem.cpp b/src/axis/axisitem.cpp index a27c884..7461bb7 100644 --- a/src/axis/axisitem.cpp +++ b/src/axis/axisitem.cpp @@ -10,7 +10,7 @@ static int label_padding = 5; QTCOMMERCIALCHART_BEGIN_NAMESPACE -Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) : Chart(presenter), +Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter), m_chartAxis(axis), m_type(type), m_labelsAngle(0), @@ -42,13 +42,13 @@ Axis::~Axis() void Axis::createItems(int count) { - if (m_axis.children().size()==0) + 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()); + if ((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem()); } } @@ -67,7 +67,7 @@ void Axis::deleteItems(int count) } } -void Axis::updateLayout(QVector& layout) +void Axis::updateLayout(QVector &layout) { if (animator()) { animator()->updateLayout(this,layout); @@ -76,7 +76,7 @@ void Axis::updateLayout(QVector& layout) } } -bool Axis::createLabels(QStringList& labels,qreal min, qreal max,int ticks) const +bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const { Q_ASSERT(max>=min); Q_ASSERT(ticks>1); @@ -87,7 +87,7 @@ bool Axis::createLabels(QStringList& labels,qreal min, qreal max,int ticks) cons if (!category) { int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); - for(int i=0; i< ticks; i++) { + for (int i=0; i< ticks; i++) { qreal value = min + (i * (max - min)/ (ticks-1)); labels << QString::number(value,'f',n); } @@ -239,18 +239,17 @@ QVector Axis::calculateLayout() const return points; } -void Axis::setLayout(QVector& layout) +void Axis::setLayout(QVector &layout) { int diff = m_layoutVector.size() - layout.size(); if (diff>0) { deleteItems(diff); - } - else if(diff<0) { + } else if (diff<0) { createItems(-diff); } - if(diff!=0) handleAxisUpdated(); + if( diff!=0) handleAxisUpdated(); QStringList ticksList; @@ -275,19 +274,19 @@ void Axis::setLayout(QVector& layout) QGraphicsLineItem *lineItem = static_cast(lines.at(i)); lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); - if(!categories){ + if (!categories) { labelItem->setText(ticksList.at(i)); QPointF center = labelItem->boundingRect().center(); labelItem->setTransformOriginPoint(center.x(), center.y()); labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); - }else if(i>0){ + } else if(i>0) { labelItem->setText(ticksList.at(i)); QPointF center = labelItem->boundingRect().center(); labelItem->setTransformOriginPoint(center.x(), center.y()); labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); } - if((i+1)%2 && i>1) { + if ((i+1)%2 && i>1) { QGraphicsRectItem *rectItem = static_cast(shades.at(i/2-1)); rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); } @@ -307,19 +306,19 @@ void Axis::setLayout(QVector& layout) lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); - if(!categories){ + if (!categories) { labelItem->setText(ticksList.at(i)); QPointF center = labelItem->boundingRect().center(); labelItem->setTransformOriginPoint(center.x(), center.y()); labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y()); - } else if(i>0){ + } else if (i>0) { labelItem->setText(ticksList.at(i)); QPointF center = labelItem->boundingRect().center(); labelItem->setTransformOriginPoint(center.x(), center.y()); labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); } - if((i+1)%2 && i>1) { + if ((i+1)%2 && i>1) { QGraphicsRectItem *rectItem = static_cast(shades.at(i/2-1)); rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); } @@ -329,7 +328,7 @@ void Axis::setLayout(QVector& layout) } break; default: - qDebug()<<"Unknown axis type"; + qDebug()<<"Unknown axis type"; break; } @@ -345,7 +344,7 @@ bool Axis::isEmpty() void Axis::handleAxisCategoriesUpdated() { - if(isEmpty()) return; + if (isEmpty()) return; updateLayout(m_layoutVector); } @@ -360,13 +359,13 @@ void Axis::handleAxisUpdated() setAxisOpacity(0); } - if(m_chartAxis->isGridLineVisible()) { + if (m_chartAxis->isGridLineVisible()) { setGridOpacity(100); } else { setGridOpacity(0); } - if(m_chartAxis->labelsVisible()) { + if (m_chartAxis->labelsVisible()) { setLabelsOpacity(100); } else { setLabelsOpacity(0); @@ -391,7 +390,7 @@ void Axis::handleAxisUpdated() void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) { - if(min==max || tickCount<2) return; + if (min==max || tickCount<2) return; m_min = min; m_max = max; @@ -403,7 +402,7 @@ void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) } -void Axis::handleGeometryChanged(const QRectF& rect) +void Axis::handleGeometryChanged(const QRectF &rect) { m_rect = rect; if (isEmpty()) return; diff --git a/src/axis/qchartaxis.cpp b/src/axis/qchartaxis.cpp index 65216d7..1b93f63 100644 --- a/src/axis/qchartaxis.cpp +++ b/src/axis/qchartaxis.cpp @@ -140,17 +140,17 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QChatView or QChart when axis added. */ -QChartAxis::QChartAxis(QObject* parent):QObject(parent), -m_axisVisible(true), -m_gridLineVisible(true), -m_labelsVisible(true), -m_labelsAngle(0), -m_shadesVisible(false), -m_shadesOpacity(1.0), -m_min(0), -m_max(0), -m_ticksCount(5), -m_niceNumbers(false) +QChartAxis::QChartAxis(QObject *parent) : QObject(parent), + m_axisVisible(true), + m_gridLineVisible(true), + m_labelsVisible(true), + m_labelsAngle(0), + m_shadesVisible(false), + m_shadesOpacity(1.0), + m_min(0), + m_max(0), + m_ticksCount(5), + m_niceNumbers(false) { } @@ -166,11 +166,11 @@ QChartAxis::~QChartAxis() /*! Sets \a pen used to draw axis line and ticks. */ -void QChartAxis::setAxisPen(const QPen& pen) +void QChartAxis::setAxisPen(const QPen &pen) { if (pen != m_axisPen) { - m_axisPen=pen; - emit updated(); + m_axisPen = pen; + emit updated(); } } @@ -179,9 +179,9 @@ void QChartAxis::setAxisPen(const QPen& pen) */ void QChartAxis::setAxisVisible(bool visible) { - if (m_axisVisible!=visible) { - m_axisVisible=visible; - emit updated(); + if (m_axisVisible != visible) { + m_axisVisible = visible; + emit updated(); } } @@ -190,20 +190,20 @@ void QChartAxis::setAxisVisible(bool visible) */ void QChartAxis::setGridLineVisible(bool visible) { - if (m_gridLineVisible!=visible) { - m_gridLineVisible=visible; - emit updated(); + if (m_gridLineVisible != visible) { + m_gridLineVisible = visible; + emit updated(); } } /*! Sets \a pen used to draw grid line. */ -void QChartAxis::setGridLinePen(const QPen& pen) +void QChartAxis::setGridLinePen(const QPen &pen) { - if (m_gridLinePen!=pen) { - m_gridLinePen=pen; - emit updated(); + if (m_gridLinePen != pen) { + m_gridLinePen = pen; + emit updated(); } } @@ -212,42 +212,42 @@ void QChartAxis::setGridLinePen(const QPen& pen) */ void QChartAxis::setLabelsVisible(bool visible) { - if(m_labelsVisible!=visible) { - m_labelsVisible=visible; - emit updated(); + if (m_labelsVisible != visible) { + m_labelsVisible = visible; + emit updated(); } } /*! Sets \a pen used to draw labels. */ -void QChartAxis::setLabelsPen(const QPen& pen) +void QChartAxis::setLabelsPen(const QPen &pen) { - if(m_labelsPen!=pen) { - m_labelsPen=pen; - emit updated(); + if (m_labelsPen != pen) { + m_labelsPen = pen; + emit updated(); } } /*! Sets \a brush used to draw labels. */ -void QChartAxis::setLabelsBrush(const QBrush& brush) +void QChartAxis::setLabelsBrush(const QBrush &brush) { - if(m_labelsBrush!=brush) { - m_labelsBrush=brush; - emit updated(); + if (m_labelsBrush != brush) { + m_labelsBrush = brush; + emit updated(); } } /*! Sets \a font used to draw labels. */ -void QChartAxis::setLabelsFont(const QFont& font) +void QChartAxis::setLabelsFont(const QFont &font) { - if(m_labelsFont!=font) { - m_labelsFont=font; - emit updated(); + if (m_labelsFont != font) { + m_labelsFont = font; + emit updated(); } } @@ -256,9 +256,9 @@ void QChartAxis::setLabelsFont(const QFont& font) */ void QChartAxis::setLabelsAngle(int angle) { - if(m_labelsAngle!=angle) { - m_labelsAngle=angle; - emit updated(); + if (m_labelsAngle != angle) { + m_labelsAngle = angle; + emit updated(); } } @@ -267,31 +267,31 @@ void QChartAxis::setLabelsAngle(int angle) */ void QChartAxis::setShadesVisible(bool visible) { - if(m_shadesVisible!=visible) { - m_shadesVisible=visible; - emit updated(); + if (m_shadesVisible != visible) { + m_shadesVisible = visible; + emit updated(); } } /*! Sets \a pen used to draw shades. */ -void QChartAxis::setShadesPen(const QPen& pen) +void QChartAxis::setShadesPen(const QPen &pen) { - if(m_shadesPen!=pen) { - m_shadesPen=pen; - emit updated(); + if (m_shadesPen != pen) { + m_shadesPen = pen; + emit updated(); } } /*! Sets \a brush used to draw shades. */ -void QChartAxis::setShadesBrush(const QBrush& brush) +void QChartAxis::setShadesBrush(const QBrush &brush) { - if(m_shadesBrush!=brush) { - m_shadesBrush=brush; - emit updated(); + if (m_shadesBrush != brush) { + m_shadesBrush = brush; + emit updated(); } } @@ -300,7 +300,7 @@ void QChartAxis::setShadesBrush(const QBrush& brush) */ void QChartAxis::setShadesOpacity(qreal opacity) { - if(m_shadesOpacity!=opacity) { + if (m_shadesOpacity != opacity) { m_shadesOpacity=opacity; emit updated(); } @@ -327,22 +327,20 @@ void QChartAxis::setMax(qreal max) */ void QChartAxis::setRange(qreal min, qreal max) { - - bool changed = false; - if(m_min!=min) { - m_min=min; - changed=true; + if (m_min != min) { + m_min = min; + changed = true; emit minChanged(min); } - if(m_max!=max) { - m_max=max; - changed=true; + if (m_max != max) { + m_max = max; + changed = true; emit maxChanged(max); } - if(changed) { + if (changed) { emit rangeChanged(m_min,m_max); emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers); } @@ -353,8 +351,8 @@ void QChartAxis::setRange(qreal min, qreal max) */ void QChartAxis::setTicksCount(int count) { - if(m_ticksCount!=count) { - m_ticksCount=count; + if (m_ticksCount != count) { + m_ticksCount = count; emit ticksCountChanged(count); emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); } @@ -377,10 +375,10 @@ void QChartAxis::show() */ void QChartAxis::hide() { - m_axisVisible=false; - m_gridLineVisible=false; - m_labelsVisible=false; - m_shadesVisible=false; + m_axisVisible = false; + m_gridLineVisible = false; + m_labelsVisible = false; + m_shadesVisible = false; emit updated(); } @@ -392,8 +390,8 @@ void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count) void QChartAxis::setNiceNumbers(bool enabled) { - if(m_niceNumbers!=enabled){ - m_niceNumbers=enabled; + if (m_niceNumbers != enabled){ + m_niceNumbers = enabled; emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); } } diff --git a/src/axis/qchartaxiscategories.cpp b/src/axis/qchartaxiscategories.cpp index 6b336a3..07024b0 100644 --- a/src/axis/qchartaxiscategories.cpp +++ b/src/axis/qchartaxiscategories.cpp @@ -13,10 +13,10 @@ QChartAxisCategories::~QChartAxisCategories() // TODO Auto-generated destructor stub } -void QChartAxisCategories::insert(const QBarCategories& categories) +void QChartAxisCategories::insert(const QBarCategories &categories) { int i=1; - foreach(QString string , categories){ + foreach (QString string , categories) { m_map.insert(i,string); i++; }