summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@digia.com>2013-08-12 12:12:09 +0300
committerTitta Heikkala <titta.heikkala@digia.com>2013-08-12 13:46:53 +0300
commit1427ecd2e3911e1a2fc325a2973e85a310bfb944 (patch)
tree3e3031317a33b2eaf0568d815da1a19e926a83f9 /src
parent504bb5e5bca57f2ba6fdd9fea0bd6b9b24cd98bd (diff)
Fix pie chart label clipping
The text rectangle for a label in a pie chart is adjusted so that it fits into the chart. The text is also truncated if there's not enough space for a label when the label is positioned outside the slice. Task-number: QTRD-1929 Change-Id: I86b722fbb0c8f7047bca8611b88871a8f7464ec1 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/piechart/piesliceitem.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp
index e2cc1e4f..b0de3f73 100644
--- a/src/piechart/piesliceitem.cpp
+++ b/src/piechart/piesliceitem.cpp
@@ -85,11 +85,20 @@ void PieSliceItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
painter->setBrush(m_data.m_labelBrush);
painter->setFont(m_data.m_labelFont);
+ QFontMetricsF fm(m_data.m_labelFont);
+ QString label = m_data.m_labelText;
+ QRectF labelBoundingRect;
+
switch (m_data.m_labelPosition) {
case QPieSlice::LabelOutside:
painter->setClipRect(parentItem()->boundingRect());
painter->strokePath(m_labelArmPath, m_data.m_labelBrush.color());
- painter->drawText(m_labelTextRect, Qt::AlignCenter, m_data.m_labelText);
+ 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(),
+ Qt::Horizontal, labelBoundingRect);
+ }
+ painter->drawText(m_labelTextRect, Qt::AlignCenter, label);
break;
case QPieSlice::LabelInsideHorizontal:
painter->setClipPath(m_slicePath);
@@ -165,6 +174,10 @@ void PieSliceItem::updateGeometry()
switch (m_data.m_labelPosition) {
case QPieSlice::LabelOutside:
m_labelTextRect.moveBottomLeft(labelTextStart);
+ if (m_labelTextRect.left() < 0)
+ m_labelTextRect.setLeft(0);
+ if (m_labelTextRect.right() > parentItem()->boundingRect().right())
+ m_labelTextRect.setRight(parentItem()->boundingRect().right());
break;
case QPieSlice::LabelInsideHorizontal:
case QPieSlice::LabelInsideTangential: {