diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp index aaed0a4..0591618 100644 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp +++ b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp @@ -27,10 +27,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter), +ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter,true), m_categoriesAxis(axis) { - setLabelBetweenTicks(true); + } ChartBarCategoryAxisX::~ChartBarCategoryAxisX() diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp index 843d73c..8637b4e 100644 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp +++ b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp @@ -26,10 +26,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter), +ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter,true), m_categoriesAxis(axis) { - setLabelBetweenTicks(true); } ChartBarCategoryAxisY::~ChartBarCategoryAxisY() diff --git a/src/axis/categoryaxis/chartcategoryaxisx.cpp b/src/axis/categoryaxis/chartcategoryaxisx.cpp index aaf1aab..a2d426e 100644 --- a/src/axis/categoryaxis/chartcategoryaxisx.cpp +++ b/src/axis/categoryaxis/chartcategoryaxisx.cpp @@ -28,10 +28,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter), +ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis,ChartPresenter *presenter) : HorizontalAxis(axis,presenter,true), m_axis(axis) { - setLabelBetweenTicks(true); } ChartCategoryAxisX::~ChartCategoryAxisX() diff --git a/src/axis/categoryaxis/chartcategoryaxisy.cpp b/src/axis/categoryaxis/chartcategoryaxisy.cpp index 8294d73..5aeb138 100644 --- a/src/axis/categoryaxis/chartcategoryaxisy.cpp +++ b/src/axis/categoryaxis/chartcategoryaxisy.cpp @@ -28,10 +28,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter), +ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis,ChartPresenter *presenter) : VerticalAxis(axis,presenter,true), m_axis(axis) { - setLabelBetweenTicks(true); } ChartCategoryAxisY::~ChartCategoryAxisY() diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index da7acac..87a8c80 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -32,7 +32,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartElement(presenter), +ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter, bool intervalAxis) : ChartElement(presenter), m_chartAxis(axis), m_labelsAngle(0), m_grid(new QGraphicsItemGroup(presenter->rootItem())), @@ -44,7 +44,7 @@ ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartEleme m_max(0), m_animation(0), m_labelPadding(5), - m_labelBetween(false) + m_intervalAxis(intervalAxis) { //initial initialization m_arrow->setZValue(ChartPresenter::AxisZValue); @@ -78,7 +78,7 @@ void ChartAxis::createItems(int count) { if (m_arrow->children().size() == 0) m_arrow->addToGroup(new AxisItem(this,presenter()->rootItem())); - if (m_grid->children().size() == 0){ + if (m_intervalAxis && m_grid->children().size() == 0){ for(int i = 0 ; i < 2 ;i ++) m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); } @@ -415,11 +415,6 @@ void ChartAxis::axisSelected() //TODO: axis clicked; } -void ChartAxis::setLabelBetweenTicks(bool enabled) -{ - m_labelBetween=enabled; -} - Qt::Orientation ChartAxis::orientation() const { return m_chartAxis->orientation(); diff --git a/src/axis/chartaxis_p.h b/src/axis/chartaxis_p.h index 10b0dae..f4fede6 100644 --- a/src/axis/chartaxis_p.h +++ b/src/axis/chartaxis_p.h @@ -48,7 +48,7 @@ class ChartAxis : public ChartElement, public QGraphicsLayoutItem Q_INTERFACES(QGraphicsLayoutItem) public: - ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter); + ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); ~ChartAxis(); void setArrowOpacity(qreal opacity); @@ -106,8 +106,8 @@ public: void setLabels(const QStringList& labels); QStringList labels() const { return m_labelsList; } - void setLabelBetweenTicks(bool enabled); - bool labelBetweenTicks() const { return m_labelBetween; } + //this flag indicates that axis is used to show intervals it means labels are in between ticks + bool intervalAxis() const { return m_intervalAxis; } virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; @@ -156,7 +156,7 @@ private: QString m_titleText; int m_labelPadding; QStringList m_labelsList; - bool m_labelBetween; + bool m_intervalAxis; friend class AxisAnimation; friend class AxisItem; diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index 032d9ba..756f68a 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -25,7 +25,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter):ChartAxis(axis,presenter) +HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter,bool intervalAxis):ChartAxis(axis,presenter,intervalAxis) { } @@ -86,7 +86,7 @@ void HorizontalAxis::updateGeometry() tickItem->setLine(layout[i],axisRect.top(),layout[i],axisRect.top() + labelPadding()); } - if(labelBetweenTicks()&& i+1!=layout.size()) { + if(intervalAxis()&& i+1!=layout.size()) { const qreal delta = (layout[i+1] - layout[i])/2; labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); } @@ -117,14 +117,14 @@ void HorizontalAxis::updateGeometry() if (x < gridRect.left() || x > gridRect.right()) { gridItem->setVisible(false); tickItem->setVisible(false); - if( labelBetweenTicks() && ( labelItem->pos().x() < gridRect.left() || labelItem->pos().x() + rect.width() > gridRect.right())) + if( intervalAxis() && ( labelItem->pos().x() < gridRect.left() || labelItem->pos().x() + rect.width() > gridRect.right())) labelItem->setVisible(false); } } //begin/end grid line in case labels between - if(labelBetweenTicks()) { + if(intervalAxis()) { QGraphicsLineItem *gridLine; gridLine = static_cast(lines.at(layout.size())); gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); diff --git a/src/axis/horizontalaxis_p.h b/src/axis/horizontalaxis_p.h index 488ba5c..a8c20f6 100644 --- a/src/axis/horizontalaxis_p.h +++ b/src/axis/horizontalaxis_p.h @@ -37,7 +37,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class HorizontalAxis : public ChartAxis { public: - HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter); + HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter,bool intervalAxis = false); ~HorizontalAxis(); protected: void updateGeometry(); diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index f15bd7e..76b39ae 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -24,7 +24,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -VerticalAxis::VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter):ChartAxis(axis,presenter) +VerticalAxis::VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis):ChartAxis(axis,presenter,intervalAxis) { } @@ -98,7 +98,7 @@ void VerticalAxis::updateGeometry() labelItem->setPos( axisRect.left() + labelPadding() , layout[i]-center.y()); tickItem->setLine( axisRect.left(),layout[i], axisRect.left()+ labelPadding(),layout[i]); } - if(labelBetweenTicks()&& i+1!=layout.size()) { + if(intervalAxis()&& i+1!=layout.size()) { const qreal delta = (layout[i+1] - layout[i])/2; labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); } @@ -128,13 +128,13 @@ void VerticalAxis::updateGeometry() if (y < gridRect.top() || y > gridRect.bottom()) { gridItem->setVisible(false); tickItem->setVisible(false); - if( labelBetweenTicks() && ( labelItem->pos().y() < gridRect.top() || labelItem->pos().y() + rect.height() > gridRect.bottom())) + if( intervalAxis() && ( labelItem->pos().y() < gridRect.top() || labelItem->pos().y() + rect.height() > gridRect.bottom())) labelItem->setVisible(false); } } //begin/end grid line in case labels between - if(labelBetweenTicks()) { + if(intervalAxis()) { QGraphicsLineItem *gridLine; gridLine = static_cast(lines.at(layout.size())); gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top()); diff --git a/src/axis/verticalaxis_p.h b/src/axis/verticalaxis_p.h index e095e44..942f942 100644 --- a/src/axis/verticalaxis_p.h +++ b/src/axis/verticalaxis_p.h @@ -37,7 +37,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class VerticalAxis : public ChartAxis { public: - VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter); + VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); ~VerticalAxis(); protected: void updateGeometry();