From a54f42bb13ad653a275ce7a75ba78411a9ca9fcf 2013-10-31 11:28:32 From: Titta Heikkala Date: 2013-10-31 11:28:32 Subject: [PATCH] Fix pie chart label truncation Adjust the pie label truncation so that the label is not divided into several rows, instead it's truncated correctly. Task-number: QTRD-2522 Change-Id: I6c0de83b5d7eef8af3a7caaee62bb2f4b674def6 Reviewed-by: Miikka Heikkinen --- diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp index 79999da..3b5bed7 100644 --- a/src/piechart/piesliceitem.cpp +++ b/src/piechart/piesliceitem.cpp @@ -135,7 +135,6 @@ void PieSliceItem::updateGeometry() if (m_data.m_isLabelVisible) { // text rect - QFontMetricsF fm(m_data.m_labelFont); m_labelTextRect = ChartPresenter::textBoundingRect(m_data.m_labelFont, m_data.m_labelText, 0); @@ -162,16 +161,14 @@ void PieSliceItem::updateGeometry() if (m_labelTextRect.right() > parentItem()->boundingRect().right()) m_labelTextRect.setRight(parentItem()->boundingRect().right()); - if (fm.width(m_data.m_labelText) > m_labelTextRect.width()) { - label = ChartPresenter::truncatedText(m_data.m_labelFont, m_data.m_labelText, - qreal(0.0), m_labelTextRect.width(), - m_labelTextRect.height(), m_labelTextRect); - m_labelArmPath = labelArmPath(armStart, centerAngle, - m_data.m_radius * m_data.m_labelArmLengthFactor, - m_labelTextRect.width(), &labelTextStart); + label = ChartPresenter::truncatedText(m_data.m_labelFont, m_data.m_labelText, + qreal(0.0), m_labelTextRect.width(), + m_labelTextRect.height(), m_labelTextRect); + m_labelArmPath = labelArmPath(armStart, centerAngle, + m_data.m_radius * m_data.m_labelArmLengthFactor, + m_labelTextRect.width(), &labelTextStart); + m_labelTextRect.moveBottomLeft(labelTextStart); - m_labelTextRect.moveBottomLeft(labelTextStart); - } m_labelItem->setTextWidth(m_labelTextRect.width() + m_labelItem->document()->documentMargin()); m_labelItem->setHtml(label); @@ -193,7 +190,7 @@ void PieSliceItem::updateGeometry() textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); } m_labelItem->setPos(textCenter.x() - m_labelItem->boundingRect().width() / 2, - textCenter.y() - fm.height() / 2); + textCenter.y() - m_labelTextRect.height() / 2); QPointF labelCenter = m_labelItem->boundingRect().center(); m_labelItem->setTransformOriginPoint(labelCenter);