mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1006 Add support for toggling legend and don't show legend for curves without a name
This commit is contained in:
@@ -428,6 +428,7 @@ void RimGridTimeHistoryCurve::defineUiOrdering(QString uiConfigName, caf::PdmUiO
|
||||
}
|
||||
|
||||
uiOrdering.add(&m_plotAxis);
|
||||
uiOrdering.add(&m_showLegend);
|
||||
|
||||
caf::PdmUiGroup* appearanceGroup = uiOrdering.addNewGroup("Appearance");
|
||||
RimPlotCurve::appearanceUiOrdering(*appearanceGroup);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ public:
|
||||
QString curveName() const { return m_curveName; }
|
||||
|
||||
void updateCurveVisibility();
|
||||
void updateLegendVisibility();
|
||||
|
||||
void showLegend(bool show);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -107,6 +110,7 @@ protected:
|
||||
caf::PdmField<bool> m_showCurve;
|
||||
caf::PdmField<QString> m_curveName;
|
||||
caf::PdmField<QString> m_customCurveName;
|
||||
caf::PdmField<bool> m_showLegend;
|
||||
|
||||
caf::PdmField<bool> m_isUsingAutoName;
|
||||
caf::PdmField<cvf::Color3f> m_curveColor;
|
||||
|
||||
@@ -446,6 +446,7 @@ void RimSummaryCurve::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
|
||||
curveVarSelectionGroup->add(&m_uiFilterResultSelection);
|
||||
|
||||
uiOrdering.add(&m_plotAxis);
|
||||
uiOrdering.add(&m_showLegend);
|
||||
|
||||
caf::PdmUiGroup* appearanceGroup = uiOrdering.addNewGroup("Appearance");
|
||||
RimPlotCurve::appearanceUiOrdering(*appearanceGroup);
|
||||
|
||||
@@ -112,6 +112,7 @@ RimSummaryCurveFilter::RimSummaryCurveFilter()
|
||||
CAF_PDM_InitFieldNoDefault(&m_regionAppearanceType, "RegionAppearanceType", "Region", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_plotAxis, "PlotAxis", "Axis", "", "", "");
|
||||
CAF_PDM_InitField(&m_showLegend, "ShowLegend", true, "Contribute To Legend", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_curveNameConfig, "SummaryCurveNameConfig", "SummaryCurveNameConfig", "", "", "");
|
||||
m_curveNameConfig.uiCapability()->setUiHidden(true);
|
||||
@@ -197,6 +198,7 @@ void RimSummaryCurveFilter::defineUiOrdering(QString uiConfigName, caf::PdmUiOrd
|
||||
curveVarSelectionGroup->add(&m_uiFilterResultMultiSelection);
|
||||
|
||||
uiOrdering.add(&m_plotAxis);
|
||||
uiOrdering.add(&m_showLegend);
|
||||
|
||||
caf::PdmUiGroup* appearanceGroup = uiOrdering.addNewGroup("Appearance settings");
|
||||
appearanceGroup->setCollapsedByDefault(true);
|
||||
@@ -271,6 +273,13 @@ void RimSummaryCurveFilter::fieldChangedByUi(const caf::PdmFieldHandle* changedF
|
||||
|
||||
plotNeedsRedraw = true;
|
||||
}
|
||||
else if (changedField == &m_showLegend)
|
||||
{
|
||||
for (size_t i = 0; i < m_curves().size(); ++i)
|
||||
{
|
||||
m_curves()[i]->showLegend(m_showLegend());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plotNeedsRedraw = true;
|
||||
|
||||
@@ -110,6 +110,7 @@ private:
|
||||
caf::PdmChildArrayField<RimSummaryCurve*> m_curves;
|
||||
|
||||
caf::PdmField< caf::AppEnum< RimDefines::PlotAxis > > m_plotAxis;
|
||||
caf::PdmField<bool> m_showLegend;
|
||||
|
||||
|
||||
// Filter fields
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "cvfColor3.h"
|
||||
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
#include "cafPdmUiCheckBoxEditor.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
@@ -43,6 +44,8 @@
|
||||
|
||||
#include "qwt_plot_curve.h"
|
||||
#include "qwt_plot_renderer.h"
|
||||
#include "qwt_abstract_legend.h"
|
||||
#include "qwt_legend.h"
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimSummaryPlot, "SummaryPlot");
|
||||
@@ -56,6 +59,9 @@ RimSummaryPlot::RimSummaryPlot()
|
||||
|
||||
CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Summary Plot"), "Name", "", "", "");
|
||||
CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", "");
|
||||
m_showPlotTitle.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
CAF_PDM_InitField(&m_showLegend, "ShowLegend", true, "Show Legend", "", "", "");
|
||||
m_showLegend.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_curveFilters, "SummaryCurveFilters", "", "", "", "");
|
||||
m_curveFilters.uiCapability()->setUiTreeHidden(true);
|
||||
@@ -693,7 +699,8 @@ void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
|
||||
RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue);
|
||||
|
||||
if (changedField == &m_userName ||
|
||||
changedField == &m_showPlotTitle)
|
||||
changedField == &m_showPlotTitle ||
|
||||
changedField == &m_showLegend)
|
||||
{
|
||||
updateMdiWindowTitle();
|
||||
}
|
||||
@@ -896,6 +903,18 @@ void RimSummaryPlot::updateMdiWindowTitle()
|
||||
{
|
||||
m_qwtPlot->setTitle("");
|
||||
}
|
||||
|
||||
|
||||
if (m_showLegend)
|
||||
{
|
||||
// Will be released in plot destructor or when a new legend is set
|
||||
QwtLegend* legend = new QwtLegend(m_qwtPlot);
|
||||
m_qwtPlot->insertLegend(legend, QwtPlot::BottomLegend);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlot->insertLegend(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,3 +976,18 @@ size_t RimSummaryPlot::curveCount() const
|
||||
{
|
||||
return m_summaryCurves.size() + m_gridTimeHistoryCurves.size();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryPlot::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
|
||||
{
|
||||
if (field == &m_showLegend || field == &m_showPlotTitle)
|
||||
{
|
||||
caf::PdmUiCheckBoxEditorAttribute* myAttr = static_cast<caf::PdmUiCheckBoxEditorAttribute*>(attribute);
|
||||
if (myAttr)
|
||||
{
|
||||
myAttr->m_useNativeCheckBoxLabel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ protected:
|
||||
virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; }
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||
virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override;
|
||||
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
|
||||
|
||||
virtual QImage snapshotWindowContent() override;
|
||||
|
||||
@@ -118,6 +119,7 @@ private:
|
||||
|
||||
private:
|
||||
caf::PdmField<bool> m_showPlotTitle;
|
||||
caf::PdmField<bool> m_showLegend;
|
||||
caf::PdmField<QString> m_userName;
|
||||
|
||||
caf::PdmChildArrayField<RimGridTimeHistoryCurve*> m_gridTimeHistoryCurves;
|
||||
|
||||
Reference in New Issue
Block a user