From 8e20d47d8440630a1a6f2e1617fff4dbd8f04d2d 2014-11-27 09:00:28 From: Titta Heikkala Date: 2014-11-27 09:00:28 Subject: [PATCH] Fix QLogValueAxis update Reverting previous fix. Instead fix the update so that the axis arrow and title are updated for logarithmic axis even when the layout is empty. The logarithmic axis is special case as it can have zero ticks where the other axises have to have at least two. Change-Id: I47d49e83b713994d4b01e022df5badcb5d947095 Task-number: QTRD-3431 Reviewed-by: Miikka Heikkinen --- diff --git a/src/charts/axis/horizontalaxis.cpp b/src/charts/axis/horizontalaxis.cpp index 1323382..de15fcb 100644 --- a/src/charts/axis/horizontalaxis.cpp +++ b/src/charts/axis/horizontalaxis.cpp @@ -37,14 +37,12 @@ void HorizontalAxis::updateGeometry() { const QVector &layout = ChartAxisElement::layout(); - if (layout.isEmpty()) + if (layout.isEmpty() && axis()->type() != QAbstractAxis::AxisTypeLogValue) return; QStringList labelList = labels(); - QList lines = gridItems(); QList labels = labelItems(); - QList shades = shadeItems(); QList arrow = arrowItems(); QGraphicsTextItem *title = titleItem(); @@ -90,6 +88,12 @@ void HorizontalAxis::updateGeometry() availableSpace -= titleBoundingRect.height(); } + if (layout.isEmpty() && axis()->type() == QAbstractAxis::AxisTypeLogValue) + return; + + QList lines = gridItems(); + QList shades = shadeItems(); + for (int i = 0; i < layout.size(); ++i) { //items QGraphicsLineItem *gridItem = static_cast(lines.at(i)); diff --git a/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp b/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp index 33d1213..30d1a6b 100644 --- a/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp +++ b/src/charts/axis/logvalueaxis/chartlogvalueaxisx.cpp @@ -48,10 +48,10 @@ QVector ChartLogValueAxisX::calculateLayout() const qreal ceilEdge = ceil(leftEdge); int tickCount = qAbs(ceil(logMax) - ceil(logMin)); - points.resize(tickCount + 1); + points.resize(tickCount); const QRectF &gridRect = gridGeometry(); const qreal deltaX = gridRect.width() / qAbs(logMax - logMin); - for (int i = 0; i <= tickCount; ++i) + for (int i = 0; i < tickCount; ++i) points[i] = (ceilEdge + qreal(i)) * deltaX - leftEdge * deltaX + gridRect.left(); return points; @@ -60,8 +60,6 @@ QVector ChartLogValueAxisX::calculateLayout() const void ChartLogValueAxisX::updateGeometry() { const QVector& layout = ChartAxisElement::layout(); - if (layout.isEmpty()) - return; setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); HorizontalAxis::updateGeometry(); } diff --git a/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp b/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp index 341dee8..0fc7329 100644 --- a/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp +++ b/src/charts/axis/logvalueaxis/chartlogvalueaxisy.cpp @@ -47,10 +47,10 @@ QVector ChartLogValueAxisY::calculateLayout() const qreal ceilEdge = ceil(leftEdge); int tickCount = qAbs(ceil(logMax) - ceil(logMin)); - points.resize(tickCount + 1); + points.resize(tickCount); const QRectF &gridRect = gridGeometry(); const qreal deltaY = gridRect.height() / qAbs(logMax - logMin); - for (int i = 0; i <= tickCount; ++i) + for (int i = 0; i < tickCount; ++i) points[i] = (ceilEdge + qreal(i)) * -deltaY - leftEdge * -deltaY + gridRect.bottom(); return points; @@ -60,8 +60,6 @@ QVector ChartLogValueAxisY::calculateLayout() const void ChartLogValueAxisY::updateGeometry() { const QVector &layout = ChartAxisElement::layout(); - if (layout.isEmpty()) - return; setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat())); VerticalAxis::updateGeometry(); } diff --git a/src/charts/axis/verticalaxis.cpp b/src/charts/axis/verticalaxis.cpp index 294e1a5..ddea15c 100644 --- a/src/charts/axis/verticalaxis.cpp +++ b/src/charts/axis/verticalaxis.cpp @@ -36,14 +36,12 @@ void VerticalAxis::updateGeometry() { const QVector &layout = ChartAxisElement::layout(); - if (layout.isEmpty()) + if (layout.isEmpty() && axis()->type() != QAbstractAxis::AxisTypeLogValue) return; QStringList labelList = labels(); - QList lines = gridItems(); QList labels = labelItems(); - QList shades = shadeItems(); QList arrow = arrowItems(); QGraphicsTextItem *title = titleItem(); @@ -55,7 +53,6 @@ void VerticalAxis::updateGeometry() qreal height = axisRect.bottom(); - //arrow QGraphicsLineItem *arrowItem = static_cast(arrow.at(0)); @@ -93,6 +90,12 @@ void VerticalAxis::updateGeometry() availableSpace -= titleBoundingRect.height(); } + if (layout.isEmpty() && axis()->type() == QAbstractAxis::AxisTypeLogValue) + return; + + QList lines = gridItems(); + QList shades = shadeItems(); + for (int i = 0; i < layout.size(); ++i) { //items QGraphicsLineItem *gridItem = static_cast(lines.at(i));