#1006 Add support for toggling legend and don't show legend for curves without a name

This commit is contained in:
Bjørnar Grip Fjær
2017-04-24 16:42:01 +02:00
parent 938c8ff69a
commit 50d9904cf7
8 changed files with 94 additions and 1 deletions

View File

@@ -90,6 +90,8 @@ RimPlotCurve::RimPlotCurve()
CAF_PDM_InitField(&m_symbolSkipPixelDistance, "SymbolSkipPxDist", 0.0f, "Symbol Skip Distance", "", "Minimum pixel distance between symbols", "");
CAF_PDM_InitField(&m_showLegend, "ShowLegend", true, "Show Legend", "", "", "");
m_qwtPlotCurve = new RiuLineSegmentQwtPlotCurve;
m_parentQwtPlot = NULL;
@@ -139,6 +141,10 @@ void RimPlotCurve::fieldChangedByUi(const caf::PdmFieldHandle* changedField, con
updateCurveName();
}
else if (changedField == &m_showLegend)
{
updateLegendVisibility();
}
if (m_parentQwtPlot) m_parentQwtPlot->replot();
}
@@ -255,6 +261,7 @@ void RimPlotCurve::updateCurveName()
}
m_qwtPlotCurve->setTitle(m_curveName);
updateLegendVisibility();
}
//--------------------------------------------------------------------------------------------------
@@ -420,3 +427,37 @@ void RimPlotCurve::setLineThickness(int thickness)
m_curveThickness = thickness;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::showLegend(bool show)
{
m_showLegend = show;
updateLegendVisibility();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateLegendVisibility()
{
if (m_showLegend()) {
if (m_curveName().isEmpty())
{
m_qwtPlotCurve->setItemAttribute(QwtPlotItem::Legend, false);
}
else
{
m_qwtPlotCurve->setItemAttribute(QwtPlotItem::Legend, true);
}
}
else
{
m_qwtPlotCurve->setItemAttribute(QwtPlotItem::Legend, false);
}
if (m_parentQwtPlot != nullptr)
{
m_parentQwtPlot->updateLegend();
}
}