#4336 Fix deletion of grid cross plot legends

This commit is contained in:
Gaute Lindkvist 2019-04-15 10:38:29 +02:00
parent 6f7a75f5c2
commit f9e3db6aa6
2 changed files with 31 additions and 1 deletions

View File

@ -112,7 +112,11 @@ void RiuGridCrossQwtPlot::removeDataSetLegend(RimGridCrossPlotDataSet* dataSetTo
auto it = m_legendWidgets.find(dataSetToShowLegendFor);
if (it != m_legendWidgets.end())
{
if (it->second != nullptr) it->second->deleteLater();
if (it->second != nullptr)
{
it->second->hide();
it->second->deleteLater();
}
m_legendWidgets.erase(it);
}
@ -120,6 +124,29 @@ void RiuGridCrossQwtPlot::removeDataSetLegend(RimGridCrossPlotDataSet* dataSetTo
this->updateLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::removeDanglingDataSetLegends()
{
for (auto it = m_legendWidgets.begin(); it != m_legendWidgets.end();)
{
if (it->first.isNull())
{
if (it->second != nullptr)
{
it->second->hide();
it->second->deleteLater();
}
m_legendWidgets.erase(it++);
}
else
{
++it;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -248,6 +275,8 @@ void RiuGridCrossQwtPlot::updateLegendLayout()
int ypos = startMarginY;
int maxColumnWidth = 0;
removeDanglingDataSetLegends();
RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>(ownerPlotDefinition());
if (!crossPlot) return;

View File

@ -52,6 +52,7 @@ public:
~RiuGridCrossQwtPlot();
void addOrUpdateDataSetLegend(RimGridCrossPlotDataSet* dataSetToShowLegendFor);
void removeDataSetLegend(RimGridCrossPlotDataSet* dataSetToShowLegendFor);
void removeDanglingDataSetLegends();
void updateLegendSizesToMatchPlot();
void updateAnnotationObjects(RimPlotAxisProperties* axisProperties);