mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 16:44:39 +03:00
ChartItem: from now chart labels will rotate only if not enough space to draw them horizontally
This commit is contained in:
parent
e9e98292f2
commit
6eb30918e5
@ -800,22 +800,36 @@ void VerticalBarChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VerticalBarChart::paintLabels(QPainter *painter, QRectF labelsRect)
|
||||
{
|
||||
painter->save();
|
||||
qreal hStep = (labelsRect.width() / valuesCount());
|
||||
|
||||
if (!m_chartItem->labels().isEmpty()){
|
||||
painter->rotate(270);
|
||||
painter->translate(-(labelsRect.top()+labelsRect.height()),labelsRect.left());
|
||||
foreach (QString label, m_chartItem->labels()) {
|
||||
painter->drawText(QRectF(QPoint(0,0),
|
||||
QSize(labelsRect.height()-4,hStep)),Qt::AlignVCenter|Qt::AlignRight,label);
|
||||
painter->translate(0,hStep);
|
||||
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 (rotateLabels){
|
||||
painter->rotate(270);
|
||||
painter->translate( -(labelsRect.top()+labelsRect.height()), labelsRect.left() );
|
||||
foreach (QString label, m_chartItem->labels()) {
|
||||
painter->drawText(QRectF(QPoint(0,0),
|
||||
QSize(labelsRect.height()-4, hStep)), Qt::AlignVCenter | Qt::AlignRight, label);
|
||||
painter->translate(0,hStep);
|
||||
}
|
||||
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->rotate(-270);
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user