diff options
author | Marek Rosa <marek.rosa@digia.com> | 2012-09-03 11:53:32 +0300 |
---|---|---|
committer | Marek Rosa <marek.rosa@digia.com> | 2012-09-03 11:53:49 +0300 |
commit | 48e529a684ff1e83039afe3b2027117feb24fba9 (patch) | |
tree | 8d14ddf190b7f43bfd0d9615c8581f0a02a74863 /src | |
parent | c4bb266222446e425cd6723f9a0d429c77cf5176 (diff) |
QCategoryAxis: fix to grid lines drawing
Diffstat (limited to 'src')
-rw-r--r-- | src/axis/categoryaxis/chartcategoryaxisx.cpp | 30 | ||||
-rw-r--r-- | src/axis/categoryaxis/chartcategoryaxisy.cpp | 24 |
2 files changed, 32 insertions, 22 deletions
diff --git a/src/axis/categoryaxis/chartcategoryaxisx.cpp b/src/axis/categoryaxis/chartcategoryaxisx.cpp index 32f1f953..d252c5cc 100644 --- a/src/axis/categoryaxis/chartcategoryaxisx.cpp +++ b/src/axis/categoryaxis/chartcategoryaxisx.cpp @@ -72,11 +72,8 @@ void ChartCategoryAxisX::updateGeometry() if(layout.isEmpty()) return; - QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); - - QStringList ticksList = intervalAxis->categoriesLabels(); - - // createNumberLabels(ticksList,m_min,m_max,layout.size()); + QCategoryAxis *categoryAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); + QStringList ticksList = categoryAxis->categoriesLabels(); QList<QGraphicsItem *> lines = m_grid->childItems(); QList<QGraphicsItem *> labels = m_labels->childItems(); @@ -86,13 +83,13 @@ void ChartCategoryAxisX::updateGeometry() // Q_ASSERT(labels.size() == ticksList.size()); // Q_ASSERT(layout.size() == ticksList.size()); + // axis base line QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); - // qreal width = 0; for (int i = 0; i < layout.size(); ++i) { - QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); - lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); + + // label items QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); if (i < ticksList.count()) { labelItem->setText(ticksList.at(i)); @@ -105,11 +102,6 @@ void ChartCategoryAxisX::updateGeometry() else labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); - if(labelItem->pos().x() > m_rect.width() + m_rect.left() - rect.width() / 2){ - labelItem->setVisible(false); - lineItem->setVisible(false); - } - m_minWidth += rect.width(); m_minHeight = qMax(rect.height()+ label_padding, m_minHeight); @@ -117,8 +109,18 @@ void ChartCategoryAxisX::updateGeometry() QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); rectItem->setRect(layout[i - 1],m_rect.top(),layout[i]-layout[i - 1],m_rect.height()); } + + // grid lines and axis line ticks + if (layout[i] < m_rect.left() || layout[i] > m_rect.right()) + continue; + + QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); + lineItem->setPos(layout[i], m_rect.top()); + lineItem->setLine(0, 0, 0, m_rect.height()); + lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); - lineItem->setLine(layout[i],m_rect.bottom(),layout[i], m_rect.bottom() + 5); + lineItem->setPos(layout[i], m_rect.bottom()); + lineItem->setLine(0, 0, 0, 5); } } diff --git a/src/axis/categoryaxis/chartcategoryaxisy.cpp b/src/axis/categoryaxis/chartcategoryaxisy.cpp index 7412a291..43038f3b 100644 --- a/src/axis/categoryaxis/chartcategoryaxisy.cpp +++ b/src/axis/categoryaxis/chartcategoryaxisy.cpp @@ -74,9 +74,8 @@ void ChartCategoryAxisY::updateGeometry() return; } - QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); - - QStringList ticksList = intervalAxis->categoriesLabels(); + QCategoryAxis *categoryAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); + QStringList ticksList = categoryAxis->categoriesLabels(); QList<QGraphicsItem *> lines = m_grid->childItems(); QList<QGraphicsItem *> labels = m_labels->childItems(); @@ -88,12 +87,13 @@ void ChartCategoryAxisY::updateGeometry() qreal height = 2*m_rect.bottom(); + // axis base line QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); for (int i = 0; i < layout.size(); ++i) { - QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); - lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); + + // label items QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); if (i < ticksList.count()) { @@ -111,11 +111,9 @@ void ChartCategoryAxisY::updateGeometry() if(labelItem->pos().y()+rect.height()>height) { labelItem->setVisible(false); - lineItem->setVisible(false); } else { labelItem->setVisible(true); - lineItem->setVisible(true); height=labelItem->pos().y(); } @@ -126,8 +124,18 @@ void ChartCategoryAxisY::updateGeometry() QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); } + + // grid lines and axis line ticks + if (layout[i] < m_rect.left() || layout[i] > m_rect.right()) + continue; + + QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); + lineItem->setPos(m_rect.left(), layout[i]); + lineItem->setLine(0, 0, m_rect.width(), 0); + lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); - lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); + lineItem->setPos(m_rect.left(), layout[i]); + lineItem->setLine(-5, 0, 0, 0); } } |