From df9206658a1d3e385c649fc35085bb50b487fb98 2016-04-05 07:50:07 From: Miikka Heikkinen Date: 2016-04-05 07:50:07 Subject: [PATCH] Fix clearing the chart title Task-number: QTBUG-51725 Change-Id: Idf5c52052f385fb2d07201ac8844415a1b7841ed Reviewed-by: Tomi Korpipää Reviewed-by: Miikka Heikkinen --- diff --git a/src/charts/charttitle.cpp b/src/charts/charttitle.cpp index 24c2f31..e78d6d6 100644 --- a/src/charts/charttitle.cpp +++ b/src/charts/charttitle.cpp @@ -52,10 +52,15 @@ QString ChartTitle::text() const void ChartTitle::setGeometry(const QRectF &rect) { QRectF truncatedRect; - QGraphicsTextItem::setHtml(ChartPresenter::truncatedText(font(), m_text, qreal(0.0), - rect.width(), rect.height(), - truncatedRect)); - QGraphicsTextItem::setTextWidth(truncatedRect.width()); + if (m_text.isEmpty()) { + QGraphicsTextItem::setHtml(m_text); + QGraphicsTextItem::setTextWidth(0.0); + } else { + QGraphicsTextItem::setHtml(ChartPresenter::truncatedText(font(), m_text, qreal(0.0), + rect.width(), rect.height(), + truncatedRect)); + QGraphicsTextItem::setTextWidth(truncatedRect.width()); + } setPos(rect.topLeft()); } diff --git a/src/charts/layout/abstractchartlayout.cpp b/src/charts/layout/abstractchartlayout.cpp index e113d52..2ca0883 100644 --- a/src/charts/layout/abstractchartlayout.cpp +++ b/src/charts/layout/abstractchartlayout.cpp @@ -57,7 +57,7 @@ void AbstractChartLayout::setGeometry(const QRectF &rect) contentGeometry = calculateContentGeometry(contentGeometry); - if (title && title->isVisible() && !title->text().isEmpty()) + if (title && title->isVisible()) contentGeometry = calculateTitleGeometry(contentGeometry, title); if (legend->isAttachedToChart() && legend->isVisible()) @@ -159,11 +159,15 @@ QRectF AbstractChartLayout::calculateLegendMinimum(const QRectF &geometry, QLege QRectF AbstractChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const { title->setGeometry(geometry); - // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases - QPointF center((geometry.center() - title->boundingRect().center()).toPoint()); - - title->setPos(center.x(), title->pos().y()); - return geometry.adjusted(0, title->boundingRect().height()+1, 0, 0); + if (title->text().isEmpty()) { + return geometry; + } else { + // Round to full pixel via QPoint to avoid one pixel clipping on the edge in some cases + QPointF center((geometry.center() - title->boundingRect().center()).toPoint()); + + title->setPos(center.x(), title->pos().y()); + return geometry.adjusted(0, title->boundingRect().height() + 1, 0, 0); + } } QRectF AbstractChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const