diff --git a/src/charts/axis/cartesianchartaxis.cpp b/src/charts/axis/cartesianchartaxis.cpp index 399662e..ecdb0e5 100644 --- a/src/charts/axis/cartesianchartaxis.cpp +++ b/src/charts/axis/cartesianchartaxis.cpp @@ -56,6 +56,10 @@ void CartesianChartAxis::createItems(int count) QGraphicsLineItem *item = new QGraphicsLineItem(this); item->setPen(axis()->gridLinePen()); gridGroup()->addToGroup(item); + QGraphicsRectItem *shades = new QGraphicsRectItem(this); + shades->setPen(axis()->shadesPen()); + shades->setBrush(axis()->shadesBrush()); + shadeGroup()->addToGroup(shades); } } @@ -78,14 +82,13 @@ void CartesianChartAxis::createItems(int count) gridGroup()->addToGroup(grid); labelGroup()->addToGroup(label); - if ((gridItems().size()) % 2 && gridItems().size() > 2) { - QGraphicsRectItem* shades = new QGraphicsRectItem(this); + if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) { + QGraphicsRectItem *shades = new QGraphicsRectItem(this); shades->setPen(axis()->shadesPen()); shades->setBrush(axis()->shadesBrush()); shadeGroup()->addToGroup(shades); } } - } void CartesianChartAxis::deleteItems(int count) @@ -96,7 +99,7 @@ void CartesianChartAxis::deleteItems(int count) QList axis = arrowItems(); for (int i = 0; i < count; ++i) { - if (lines.size() % 2 && lines.size() > 1) + if (lines.size() == 1 || (((lines.size() + 1) % 2) && lines.size() > 0)) delete(shades.takeLast()); delete(lines.takeLast()); delete(labels.takeLast()); diff --git a/src/charts/axis/horizontalaxis.cpp b/src/charts/axis/horizontalaxis.cpp index 8e3bb97..c727d54 100644 --- a/src/charts/axis/horizontalaxis.cpp +++ b/src/charts/axis/horizontalaxis.cpp @@ -161,15 +161,30 @@ void HorizontalAxis::updateGeometry() } //shades - if ((i + 1) % 2 && i > 1) { - QGraphicsRectItem *rectItem = static_cast(shades.at(i / 2 - 1)); - 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); + QGraphicsRectItem *shadeItem = 0; + if (i == 0) + shadeItem = static_cast(shades.at(0)); + else if (i % 2) + shadeItem = static_cast(shades.at((i / 2) + 1)); + if (shadeItem) { + qreal leftBound; + qreal rightBound; + if (i == 0) { + leftBound = gridRect.left(); + rightBound = layout[0]; + } else { + leftBound = layout[i]; + if (i == layout.size() - 1) + rightBound = gridRect.right(); + else + rightBound = qMin(layout[i + 1], gridRect.right()); + } + shadeItem->setRect(leftBound, gridRect.top(), rightBound - leftBound, + gridRect.height()); + if (shadeItem->rect().width() <= 0.0) + shadeItem->setVisible(false); else - rectItem->setVisible(true); + shadeItem->setVisible(true); } // check if the grid line and the axis tick should be shown diff --git a/src/charts/axis/verticalaxis.cpp b/src/charts/axis/verticalaxis.cpp index 484ca1f..445ab25 100644 --- a/src/charts/axis/verticalaxis.cpp +++ b/src/charts/axis/verticalaxis.cpp @@ -165,15 +165,31 @@ void VerticalAxis::updateGeometry() } //shades - if ((i + 1) % 2 && i > 1) { - QGraphicsRectItem *rectItem = static_cast(shades.at(i / 2 - 1)); - 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); + QGraphicsRectItem *shadeItem = 0; + if (i == 0) + shadeItem = static_cast(shades.at(0)); + else if (i % 2) + shadeItem = static_cast(shades.at((i / 2) + 1)); + if (shadeItem) { + qreal lowerBound; + qreal upperBound; + if (i == 0) { + lowerBound = gridRect.bottom(); + upperBound = layout[0]; + } else { + lowerBound = layout[i]; + if (i == layout.size() - 1) + upperBound = gridRect.top(); + else + upperBound = qMax(layout[i + 1], gridRect.top()); + + } + shadeItem->setRect(gridRect.left(), upperBound, gridRect.width(), + lowerBound - upperBound); + if (shadeItem->rect().height() <= 0.0) + shadeItem->setVisible(false); else - rectItem->setVisible(true); + shadeItem->setVisible(true); } // check if the grid line and the axis tick should be shown