From 23dc25e6ce182ac5cbc13aa2b676ca7c01511ffc 2013-09-04 06:58:29 From: Titta Heikkala Date: 2013-09-04 06:58:29 Subject: [PATCH] Fix ChartView visibility change drawing New geometry for the ChartPresenter is calculated only when the chart is visible. The geometry is set for the layout always. If the visibility of a series changes then the layout of the legend is only invalidated in case the chart is visible. This removes unnecessary delay of the legend drawing when the chart is set visible. Task-number: QTRD-2064 Change-Id: I78e6da3b859af9becf4f5059e9c02981c79f6d64 Reviewed-by: Miikka Heikkinen --- diff --git a/src/layout/abstractchartlayout.cpp b/src/layout/abstractchartlayout.cpp index de7ca55..85995f2 100644 --- a/src/layout/abstractchartlayout.cpp +++ b/src/layout/abstractchartlayout.cpp @@ -46,28 +46,30 @@ void AbstractChartLayout::setGeometry(const QRectF &rect) if (!rect.isValid()) return; - QList axes = m_presenter->axisItems(); - ChartTitle *title = m_presenter->titleElement(); - QLegend *legend = m_presenter->legend(); - ChartBackground *background = m_presenter->backgroundElement(); + if (m_presenter->chart()->isVisible()) { + QList axes = m_presenter->axisItems(); + ChartTitle *title = m_presenter->titleElement(); + QLegend *legend = m_presenter->legend(); + ChartBackground *background = m_presenter->backgroundElement(); - QRectF contentGeometry = calculateBackgroundGeometry(rect, background); + QRectF contentGeometry = calculateBackgroundGeometry(rect, background); - contentGeometry = calculateContentGeometry(contentGeometry); + contentGeometry = calculateContentGeometry(contentGeometry); - if (title && title->isVisible()) - contentGeometry = calculateTitleGeometry(contentGeometry, title); + if (title && title->isVisible()) + contentGeometry = calculateTitleGeometry(contentGeometry, title); - if (legend->isAttachedToChart() && legend->isVisible()) - contentGeometry = calculateLegendGeometry(contentGeometry, legend); + if (legend->isAttachedToChart() && legend->isVisible()) + contentGeometry = calculateLegendGeometry(contentGeometry, legend); - contentGeometry = calculateAxisGeometry(contentGeometry, axes); + contentGeometry = calculateAxisGeometry(contentGeometry, axes); - m_presenter->setGeometry(contentGeometry); - if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian) - static_cast(m_presenter->plotAreaElement())->setRect(contentGeometry); - else - static_cast(m_presenter->plotAreaElement())->setRect(contentGeometry); + m_presenter->setGeometry(contentGeometry); + if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian) + static_cast(m_presenter->plotAreaElement())->setRect(contentGeometry); + else + static_cast(m_presenter->plotAreaElement())->setRect(contentGeometry); + } QGraphicsLayout::setGeometry(rect); } diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 2faacd3..e5c9549 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -518,7 +518,9 @@ void QLegendPrivate::handleSeriesVisibleChanged() marker->setVisible(series->isVisible()); } } - m_layout->invalidate(); + + if (m_chart->isVisible()) + m_layout->invalidate(); } void QLegendPrivate::handleCountChanged()