From 77b53b7a51e4780228dc387c195298aef4088289 2013-03-21 09:14:29 From: Miikka Heikkinen Date: 2013-03-21 09:14:29 Subject: [PATCH] Prevent drawing shades off-chart Task-number: QTRD-1931 Task-number: QTRD-1935 Reviewed-by: Mika Salmela --- diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index 95b786d..9dcd775 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -164,7 +164,13 @@ void HorizontalAxis::updateGeometry() //shades if ((i + 1) % 2 && i > 1) { QGraphicsRectItem *rectItem = static_cast(shades.at(i / 2 - 1)); - rectItem->setRect(layout[i - 1], gridRect.top(), layout[i] - layout[i - 1], gridRect.height()); + qreal leftBound = qMax(layout[i - 1], gridRect.left()); + qreal rightBound = qMin(layout[i], gridRect.right()); + rectItem->setRect(leftBound, gridRect.top(), rightBound - leftBound, gridRect.height()); + if (rectItem->rect().width() <= 0.0) + rectItem->setVisible(false); + else + rectItem->setVisible(true); } // check if the grid line and the axis tick should be shown diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 38a6107..d3c5efa 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -175,7 +175,13 @@ void VerticalAxis::updateGeometry() //shades if ((i + 1) % 2 && i > 1) { QGraphicsRectItem *rectItem = static_cast(shades.at(i / 2 - 1)); - rectItem->setRect(gridRect.left(), layout[i], gridRect.width(), layout[i - 1] - layout[i]); + qreal lowerBound = qMin(layout[i - 1], gridRect.bottom()); + qreal upperBound = qMax(layout[i], gridRect.top()); + rectItem->setRect(gridRect.left(), upperBound, gridRect.width(), lowerBound - upperBound); + if (rectItem->rect().height() <= 0.0) + rectItem->setVisible(false); + else + rectItem->setVisible(true); } // check if the grid line and the axis tick should be shown