0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 17:14:40 +03:00

ChartItem: from now chart labels will rotate only if not enough space to draw them horizontally

This commit is contained in:
Arin Alexander 2020-01-09 21:26:25 +03:00
parent e9e98292f2
commit 6eb30918e5

View File

@ -800,22 +800,36 @@ void VerticalBarChart::paintSerialLines(QPainter* painter, QRectF barsRect)
painter->restore(); painter->restore();
} }
void VerticalBarChart::paintLabels(QPainter *painter, QRectF labelsRect) void VerticalBarChart::paintLabels(QPainter *painter, QRectF labelsRect)
{ {
painter->save(); painter->save();
qreal hStep = (labelsRect.width() / valuesCount()); qreal hStep = (labelsRect.width() / valuesCount());
bool rotateLabels = false;
QFontMetrics fm = painter->fontMetrics();
foreach(QString label, m_chartItem->labels()){
if (fm.width(label) > hStep){
rotateLabels = true;
break;
}
}
if (!m_chartItem->labels().isEmpty()){ if (!m_chartItem->labels().isEmpty()){
if (rotateLabels){
painter->rotate(270); painter->rotate(270);
painter->translate(-(labelsRect.top()+labelsRect.height()),labelsRect.left()); painter->translate( -(labelsRect.top()+labelsRect.height()), labelsRect.left() );
foreach (QString label, m_chartItem->labels()) { foreach (QString label, m_chartItem->labels()) {
painter->drawText(QRectF(QPoint(0,0), painter->drawText(QRectF(QPoint(0,0),
QSize(labelsRect.height()-4,hStep)),Qt::AlignVCenter|Qt::AlignRight,label); QSize(labelsRect.height()-4, hStep)), Qt::AlignVCenter | Qt::AlignRight, label);
painter->translate(0,hStep); painter->translate(0,hStep);
} }
painter->rotate(-270); painter->rotate(-270);
} else {
painter->translate( labelsRect.left(), labelsRect.top() );
foreach (QString label, m_chartItem->labels()) {
painter->drawText(QRectF(QPoint(0, 4),
QSize(hStep, labelsRect.height()-4)), Qt::AlignHCenter | Qt::AlignTop, label);
painter->translate(hStep, 0);
}
}
} }
painter->restore(); painter->restore();
} }