Fix minor memory leak when recreating buttons

This commit is contained in:
2022-02-14 12:55:24 +01:00
parent 816a6b7df8
commit 487ef6cb4e

View File

@@ -232,7 +232,10 @@ void SelectedTracePlotLineModel::recreateCollapseButtons(TracePlot *tracePlot,
{
// Remove old buttons
for (auto button : collapseButtons)
{
button->hide();
button->deleteLater();
}
collapseButtons.clear();
@@ -243,7 +246,7 @@ void SelectedTracePlotLineModel::recreateCollapseButtons(TracePlot *tracePlot,
QPushButton *collapseButton = new QPushButton(tracePlot);
unsigned int yVal = [&]()
unsigned int yVal = [node]()
{
if (node->data.collapsed)
return node->data.yVal;
@@ -270,7 +273,9 @@ void SelectedTracePlotLineModel::recreateCollapseButtons(TracePlot *tracePlot,
recreateCollapseButtons(tracePlot, customLabelScaleDraw);
};
connect(customLabelScaleDraw, &CustomLabelScaleDraw::scaleRedraw, this, repositionButton);
// Important: The context of the connection is `collapseButton` as it should be disconnected when the button
// ceases to exist.
connect(customLabelScaleDraw, &CustomLabelScaleDraw::scaleRedraw, collapseButton, repositionButton);
connect(collapseButton, &QPushButton::pressed, this, toggleCollapsed);
connect(collapseButton, &QPushButton::pressed, tracePlot, &TracePlot::recreateCollapseButtons);