diff options
Diffstat (limited to 'src/barchart/vertical/stacked/stackedbarchartitem.cpp')
-rw-r--r-- | src/barchart/vertical/stacked/stackedbarchartitem.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp index 7c118709..82329194 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp +++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp @@ -29,6 +29,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : AbstractBarChartItem(series, item) { + connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), + this, SLOT(handleLabelsPositionChanged())); + connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); } void StackedBarChartItem::initializeLayout() @@ -102,6 +105,32 @@ QVector<QRectF> StackedBarChartItem::calculateLayout() return layout; } +void StackedBarChartItem::handleLabelsPositionChanged() +{ + positionLabels(); +} + +void StackedBarChartItem::positionLabels() +{ + for (int i = 0; i < m_layout.count(); i++) { + QGraphicsTextItem *label = m_labels.at(i); + qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); + qreal yPos = 0; + + if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) + yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) + yPos = m_layout.at(i).top(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) + yPos = m_layout.at(i).bottom() - label->boundingRect().height(); + else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) + yPos = m_layout.at(i).top() - label->boundingRect().height(); + + label->setPos(xPos, yPos); + label->setZValue(zValue() + 1); + } +} + #include "moc_stackedbarchartitem_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE |