#4195 Grid Cross Plot: Add annotation item to axis

This commit is contained in:
Magne Sjaastad 2019-03-12 16:05:58 +01:00
parent edc6dad0f7
commit 15f2a76ee1
8 changed files with 198 additions and 8 deletions

View File

@ -129,6 +129,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimScaleLegendConfig.h
${CMAKE_CURRENT_LIST_DIR}/RimReloadCaseTools.h
${CMAKE_CURRENT_LIST_DIR}/RimRiuQwtPlotOwnerInterface.h
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisProperties.h
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.h
)
@ -261,6 +262,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimViewNameConfig.cpp
${CMAKE_CURRENT_LIST_DIR}/RimScaleLegendConfig.cpp
${CMAKE_CURRENT_LIST_DIR}/RimReloadCaseTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisProperties.cpp
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -279,6 +279,10 @@ void RimGridCrossPlot::updateAxisDisplay()
{
updateAxisInQwt(RiaDefines::PLOT_AXIS_BOTTOM);
updateAxisInQwt(RiaDefines::PLOT_AXIS_LEFT);
m_qwtPlot->updateAnnotationObjects(m_xAxisProperties);
m_qwtPlot->updateAnnotationObjects(m_yAxisProperties);
m_qwtPlot->replot();
}

View File

@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimPlotAxisAnnotation.h"
CAF_PDM_SOURCE_INIT(RimPlotAxisAnnotation, "RimPlotAxisAnnotation");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotAxisAnnotation::RimPlotAxisAnnotation()
{
CAF_PDM_InitObject("Plot Axis Annotation", ":/LeftAxis16x16.png", "", "");
CAF_PDM_InitField(&m_isActive, "Active", true, "Active", "", "", "");
m_isActive.uiCapability()->setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_name, "Name", "Name", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_value, "Value", "Value", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotAxisAnnotation::setName(const QString& name)
{
m_name = name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotAxisAnnotation::setValue(double value)
{
m_value = value;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPlotAxisAnnotation::name() const
{
return m_name();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimPlotAxisAnnotation::value() const
{
return m_value();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimPlotAxisAnnotation::userDescriptionField()
{
return &m_name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimPlotAxisAnnotation::objectToggleField()
{
return &m_isActive;
}

View File

@ -0,0 +1,52 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafAppEnum.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include <QString>
//==================================================================================================
///
///
//==================================================================================================
class RimPlotAxisAnnotation : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimPlotAxisAnnotation();
void setName(const QString& name);
void setValue(double value);
QString name() const;
double value() const;
caf::PdmFieldHandle* userDescriptionField() override;
caf::PdmFieldHandle* objectToggleField() override;
private:
caf::PdmField<bool> m_isActive;
caf::PdmField<QString> m_name;
caf::PdmField<double> m_value;
};

View File

@ -22,6 +22,7 @@
#include "RiaDefines.h"
#include "RimRiuQwtPlotOwnerInterface.h"
#include "RimPlotAxisAnnotation.h"
#include "cafPdmUiSliderEditor.h"
@ -90,6 +91,11 @@ RimPlotAxisProperties::RimPlotAxisProperties()
CAF_PDM_InitField(&isLogarithmicScaleEnabled, "LogarithmicScale", false, "Logarithmic Scale", "", "", "");
CAF_PDM_InitField(&m_isAxisInverted, "AxisInverted", false, "Invert Axis", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_annotations, "Annotations", "", "", "", "");
m_annotations.uiCapability()->setUiHidden(true);
m_annotations.push_back(new RimPlotAxisAnnotation);
updateOptionSensitivity();
}
// clang-format on
@ -289,6 +295,14 @@ bool RimPlotAxisProperties::isAxisInverted() const
return m_isAxisInverted();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotAxisAnnotation*> RimPlotAxisProperties::annotations() const
{
return m_annotations.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -30,6 +30,8 @@
#include <QString>
class RimPlotAxisAnnotation;
//==================================================================================================
///
///
@ -67,6 +69,8 @@ public:
void setAutoZoom(bool enableAutoZoom);
bool isAxisInverted() const;
std::vector<RimPlotAxisAnnotation*> annotations() const;
caf::PdmField<QString> customTitle;
caf::PdmField<int> titleFontSize;
caf::PdmField<caf::AppEnum<AxisTitlePositionType>> titlePositionEnum;
@ -110,4 +114,6 @@ private:
QwtPlot::Axis m_axis;
bool m_enableTitleTextSettings;
caf::PdmChildArrayField<RimPlotAxisAnnotation*> m_annotations;
};

View File

@ -28,6 +28,10 @@
#include "cafSelectionManager.h"
#include "cafTitledOverlayFrame.h"
#include "RimPlotAxisProperties.h"
#include "RimPlotAxisAnnotation.h"
#include "RiuPlotAnnotationTool.h"
#include <QMenu>
#include <QResizeEvent>
@ -36,7 +40,8 @@
//--------------------------------------------------------------------------------------------------
RiuGridCrossQwtPlot::RiuGridCrossQwtPlot(RimViewWindow* ownerViewWindow, QWidget* parent /*= nullptr*/)
: RiuQwtPlot(ownerViewWindow, parent)
{
{
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>(new RiuPlotAnnotationTool());
}
//--------------------------------------------------------------------------------------------------
@ -65,7 +70,6 @@ void RiuGridCrossQwtPlot::addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* cu
caf::TitledOverlayFrame* overlayItem = curveSet->legendConfig()->titledOverlayFrame();
resizeOverlayItemToFitPlot(overlayItem);
overlayWidget->updateFromOverlayItem(overlayItem);
}
this->updateLegendLayout();
}
@ -121,6 +125,26 @@ void RiuGridCrossQwtPlot::updateLegendSizesToMatchPlot()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::updateAnnotationObjects(RimPlotAxisProperties* axisProperties)
{
std::vector<QString> names;
std::vector<double> positions;
for (auto a : axisProperties->annotations())
{
names.push_back(a->name());
positions.push_back(a->value());
}
if (!names.empty())
{
m_annotationTool->attachWellPicks(this, names, positions);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -163,7 +187,7 @@ void RiuGridCrossQwtPlot::updateLegendLayout()
if (ypos + overlayWidget->height() + spacing > this->canvas()->height())
{
xpos += spacing + maxColumnWidth;
ypos = startMarginY;
ypos = startMarginY;
maxColumnWidth = 0;
}
@ -197,21 +221,20 @@ bool RiuGridCrossQwtPlot::resizeOverlayItemToFitPlot(caf::TitledOverlayFrame* ov
bool sizeAltered = false;
if (plotSize.width() > 0 && (double) legendSize.x() > 0.9 * plotSize.width())
if (plotSize.width() > 0 && (double)legendSize.x() > 0.9 * plotSize.width())
{
legendSize.x() = (plotSize.width() * 9) / 10;
sizeAltered = true;
sizeAltered = true;
}
if (plotSize.height() > 0 && (double) legendSize.y() > 0.9 * plotSize.height())
if (plotSize.height() > 0 && (double)legendSize.y() > 0.9 * plotSize.height())
{
legendSize.y() = (plotSize.height() * 9) / 10;
sizeAltered = true;
sizeAltered = true;
}
overlayItem->setRenderSize(legendSize);
return sizeAltered;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -27,6 +27,8 @@
class RimGridCrossPlotCurveSet;
class RiuCvfOverlayItemWidget;
class RiuPlotAnnotationTool;
class RimPlotAxisProperties;
namespace caf
{
@ -47,12 +49,16 @@ public:
void addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor);
void removeCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor);
void updateLegendSizesToMatchPlot();
void updateAnnotationObjects(RimPlotAxisProperties* axisProperties);
protected:
void updateLayout() override;
void updateLegendLayout();
void resizeEvent(QResizeEvent *e) override;
bool resizeOverlayItemToFitPlot(caf::TitledOverlayFrame* overlayItem);
void contextMenuEvent(QContextMenuEvent*) override;
private:
std::map<caf::PdmPointer<RimGridCrossPlotCurveSet>, QPointer<RiuCvfOverlayItemWidget>> m_legendWidgets;
std::unique_ptr<RiuPlotAnnotationTool> m_annotationTool;
};