From 79dc9c599f412117d04cb1ba8c0c9af93bb0b9de Mon Sep 17 00:00:00 2001 From: Titta Heikkala Date: Fri, 18 Sep 2015 14:23:28 +0300 Subject: Fixed bar label visibility Label for bars with zero value is not shown. This is done to avoid overlapping labels. Change-Id: Ife30c04e8ae4d9ac9df1209967cc3cd3ecb76a4f Task-number: QTRD-3695 Reviewed-by: Miikka Heikkinen --- src/charts/barchart/abstractbarchartitem.cpp | 13 +++++++++---- .../horizontal/percent/horizontalpercentbarchartitem.cpp | 15 ++++++++++----- src/charts/barchart/qbarset.cpp | 2 ++ .../barchart/vertical/percent/percentbarchartitem.cpp | 15 ++++++++++----- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/charts/barchart/abstractbarchartitem.cpp b/src/charts/barchart/abstractbarchartitem.cpp index ea0e9a04..6f8ecb71 100644 --- a/src/charts/barchart/abstractbarchartitem.cpp +++ b/src/charts/barchart/abstractbarchartitem.cpp @@ -225,12 +225,17 @@ void AbstractBarChartItem::handleUpdatedBars() QGraphicsTextItem *label = m_labels.at(itemIndex); QString valueLabel; if (presenter()) { // At startup presenter is not yet set, yet somehow update comes - if (m_series->labelsFormat().isEmpty()) { - valueLabel = presenter()->numberToString(barSet->value(category)); + if (barSet->value(category) == 0) { + label->setVisible(false); } else { - valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, + label->setVisible(true); + if (m_series->labelsFormat().isEmpty()) { + valueLabel = presenter()->numberToString(barSet->value(category)); + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, presenter()->numberToString(barSet->value(category))); + } } } label->setHtml(valueLabel); diff --git a/src/charts/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp b/src/charts/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp index 62400865..62db806a 100644 --- a/src/charts/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp +++ b/src/charts/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp @@ -116,12 +116,17 @@ void HorizontalPercentBarChartItem::handleUpdatedBars() qreal p = m_series->d_func()->percentageAt(set, category) * 100.0; QString vString(presenter()->numberToString(p, 'f', 0)); QString valueLabel; - if (m_series->labelsFormat().isEmpty()) { - vString.append(QStringLiteral("%")); - valueLabel = vString; + if (p == 0) { + label->setVisible(false); } else { - valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, vString); + label->setVisible(true); + if (m_series->labelsFormat().isEmpty()) { + vString.append(QStringLiteral("%")); + valueLabel = vString; + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, vString); + } } label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); diff --git a/src/charts/barchart/qbarset.cpp b/src/charts/barchart/qbarset.cpp index d6194b7d..4eb1cdbe 100644 --- a/src/charts/barchart/qbarset.cpp +++ b/src/charts/barchart/qbarset.cpp @@ -32,6 +32,7 @@ QT_CHARTS_BEGIN_NAMESPACE First value of set is assumed to belong to first category, second to second category and so on. If set has fewer values than there are categories, then the missing values are assumed to be at the end of set. For missing values in middle of a set, numerical value of zero is used. + Labels for zero value sets are not shown. \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries */ @@ -46,6 +47,7 @@ QT_CHARTS_BEGIN_NAMESPACE First value of set is assumed to belong to first category, second to second category and so on. If set has fewer values than there are categories, then the missing values are assumed to be at the end of set. For missing values in middle of a set, numerical value of zero is used. + Labels for zero value sets are not shown. \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries */ diff --git a/src/charts/barchart/vertical/percent/percentbarchartitem.cpp b/src/charts/barchart/vertical/percent/percentbarchartitem.cpp index fbde59ab..6a998df3 100644 --- a/src/charts/barchart/vertical/percent/percentbarchartitem.cpp +++ b/src/charts/barchart/vertical/percent/percentbarchartitem.cpp @@ -121,12 +121,17 @@ void PercentBarChartItem::handleUpdatedBars() qreal p = m_series->d_func()->percentageAt(set, category) * 100.0; QString vString(presenter()->numberToString(p, 'f', 0)); QString valueLabel; - if (m_series->labelsFormat().isEmpty()) { - vString.append(QStringLiteral("%")); - valueLabel = vString; + if (p == 0) { + label->setVisible(false); } else { - valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, vString); + label->setVisible(true); + if (m_series->labelsFormat().isEmpty()) { + vString.append(QStringLiteral("%")); + valueLabel = vString; + } else { + valueLabel = m_series->labelsFormat(); + valueLabel.replace(valueTag, vString); + } } label->setHtml(valueLabel); label->setFont(barSet->m_labelFont); -- cgit v1.2.3