diff --git a/src/piechart/piechartitem.cpp b/src/piechart/piechartitem.cpp index c061087..49fa8e8 100644 --- a/src/piechart/piechartitem.cpp +++ b/src/piechart/piechartitem.cpp @@ -43,10 +43,10 @@ PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) connect(d, SIGNAL(piePositionChanged()), this, SLOT(updateLayout())); connect(d, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); - QTimer::singleShot(0, this, SLOT(initialize())); // TODO: get rid of this - // Note: the following does not affect as long as the item does not have anything to paint setZValue(ChartPresenter::PieSeriesZValue); + + // Note: will not create slice items until we have a proper rectangle to draw on. } PieChartItem::~PieChartItem() @@ -59,6 +59,11 @@ void PieChartItem::handleGeometryChanged(const QRectF& rect) prepareGeometryChange(); m_rect = rect; updateLayout(); + + // This is for delayed initialization of the slice items during startup. + // It ensures that startup animation originates from the correct position. + if (m_sliceItems.isEmpty()) + handleSlicesAdded(m_series->slices()); } void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) @@ -86,11 +91,6 @@ void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) // does not apply to pie } -void PieChartItem::initialize() -{ - handleSlicesAdded(m_series->slices()); -} - void PieChartItem::updateLayout() { // find pie center coordinates @@ -122,6 +122,10 @@ void PieChartItem::updateLayout() void PieChartItem::handleSlicesAdded(QList slices) { + // delay creating slice items until there is a proper rectangle + if (!m_rect.isValid() && m_sliceItems.isEmpty()) + return; + presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); bool startupAnimation = m_sliceItems.isEmpty(); diff --git a/src/piechart/piechartitem_p.h b/src/piechart/piechartitem_p.h index d00b94a..1808d84 100644 --- a/src/piechart/piechartitem_p.h +++ b/src/piechart/piechartitem_p.h @@ -49,7 +49,6 @@ public Q_SLOTS: virtual void rangeXChanged(qreal min, qreal max, int tickXCount); virtual void rangeYChanged(qreal min, qreal max, int tickYCount); - void initialize(); void updateLayout(); void handleSlicesAdded(QList slices); void handleSlicesRemoved(QList slices);