Commit c92732fd authored by Volker Krause's avatar Volker Krause
Browse files

Don't leak line series of area plots

This fixes dangling line series crashing when the model they still listen
to resets.
parent a86cbe81
......@@ -116,9 +116,9 @@ void AnalyticsView::setRESTClient(RESTClient* client)
void AnalyticsView::setProduct(const Product& product)
{
m_chart->setModel(nullptr);
m_dataModel->setProduct(product);
m_chart->setModel(nullptr);
ui->chartType->clear();
m_aggregatedDataModel->clear();
qDeleteAll(m_aggregationModels);
......
......@@ -70,8 +70,10 @@ void Chart::setModel(QAbstractItemModel* model)
disconnect(m_model, &QAbstractItemModel::modelReset, this, &Chart::modelReset);
m_model = model;
if (!model)
if (!model) {
m_chart->removeAllSeries();
return;
}
connect(m_model, &QAbstractItemModel::modelReset, this, &Chart::modelReset);
modelReset();
......@@ -111,7 +113,7 @@ void Chart::modelReset()
} else {
QLineSeries *prevSeries = nullptr;
for (int i = 1; i < colCount; ++i) {
auto series = new QLineSeries(this);
auto series = new QLineSeries;
auto mapper = new QVXYModelMapper(series);
mapper->setModel(m_model);
......@@ -121,6 +123,7 @@ void Chart::modelReset()
mapper->setSeries(series);
auto areaSeries = new QAreaSeries(series, prevSeries);
series->setParent(areaSeries); // otherwise series isn't deleted by removeAllSeries!
areaSeries->setName(m_model->headerData(i, Qt::Horizontal).toString().toHtmlEscaped());
m_chart->addSeries(areaSeries);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment