From ba1b2ec110560bb9cce1abdfb8c27f375aa613ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Hagen?= Date: Tue, 1 Sep 2015 11:14:58 +0200 Subject: [PATCH] (#396) Handling scroll wheel event to zoom all well log trace plots --- .../ProjectDataModel/RimWellLogPlot.cpp | 30 ++++++++++++++--- .../ProjectDataModel/RimWellLogPlot.h | 7 ++-- .../UserInterface/RiuWellLogPlot.cpp | 32 ++++++++++++++++++- .../UserInterface/RiuWellLogPlot.h | 10 ++++-- 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index 2fd884197c..9a5604a213 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -43,8 +43,8 @@ RimWellLogPlot::RimWellLogPlot() CAF_PDM_InitField(&showWindow, "ShowWindow", true, "Show well log plot", "", "", ""); showWindow.uiCapability()->setUiHidden(true); - CAF_PDM_InitField(&minimumDepth, "MinimumDepth", 0.0, "Set minimum depth", "", "", ""); - CAF_PDM_InitField(&maximumDepth, "MaximumDepth", 1000.0, "Set maximum depth", "", "", ""); + CAF_PDM_InitField(&m_minimumDepth, "MinimumDepth", 0.0, "Set minimum depth", "", "", ""); + CAF_PDM_InitField(&m_maximumDepth, "MaximumDepth", 1000.0, "Set maximum depth", "", "", ""); CAF_PDM_InitFieldNoDefault(&traces, "Traces", "", "", "", ""); traces.uiCapability()->setUiHidden(true); @@ -71,7 +71,7 @@ void RimWellLogPlot::updateViewerWidget() bool isViewerCreated = false; if (!m_viewer) { - m_viewer = new RiuWellLogPlot(RiuMainWindow::instance()); + m_viewer = new RiuWellLogPlot(this, RiuMainWindow::instance()); RiuMainWindow::instance()->addWellLogViewer(m_viewer); isViewerCreated = true; @@ -116,9 +116,9 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } } } - else if (changedField == &minimumDepth || changedField == &maximumDepth) + else if (changedField == &m_minimumDepth || changedField == &m_maximumDepth) { - m_viewer->setDepthRange(minimumDepth, maximumDepth); + m_viewer->setDepthRange(m_minimumDepth, m_maximumDepth); } } @@ -154,3 +154,23 @@ RiuWellLogPlot* RimWellLogPlot::viewer() { return m_viewer; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellLogPlot::zoomDepth(double zoomFactor) +{ + double center = (m_maximumDepth + m_minimumDepth)/2; + double newHalfDepth = zoomFactor*(m_maximumDepth - m_minimumDepth)/2; + + double newMinimum = center - newHalfDepth; + double newMaximum = center + newHalfDepth; + + m_minimumDepth = newMinimum; + m_maximumDepth = newMaximum; + + m_minimumDepth.uiCapability()->updateConnectedEditors(); + m_maximumDepth.uiCapability()->updateConnectedEditors(); + + m_viewer->setDepthRange(m_minimumDepth, m_maximumDepth); +} diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h index eff1cc5bba..c9d52157c8 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h @@ -47,6 +47,8 @@ class RimWellLogPlot : public caf::PdmObject RiuWellLogPlot* viewer(); + void zoomDepth(double zoomFactor); + protected: // Overridden PDM methods @@ -54,12 +56,13 @@ class RimWellLogPlot : public caf::PdmObject private: void updateViewerWidget(); + void setDepthRange(double minimumDepth, double maximumDepth); virtual caf::PdmFieldHandle* objectToggleField(); private: QPointer m_viewer; - caf::PdmField minimumDepth; - caf::PdmField maximumDepth; + caf::PdmField m_minimumDepth; + caf::PdmField m_maximumDepth; }; diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp index b3352e7290..1de0094f6c 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp @@ -27,13 +27,19 @@ #include "cvfAssert.h" #include +#include + +#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.05 //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuWellLogPlot::RiuWellLogPlot(QWidget* parent) +RiuWellLogPlot::RiuWellLogPlot(RimWellLogPlot* dataModelPlot, QWidget* parent) : QWidget(parent) { + Q_ASSERT(dataModelPlot); + m_dataModelPlot = dataModelPlot; + m_layout = new QHBoxLayout(this); m_layout->setMargin(0); @@ -70,3 +76,27 @@ void RiuWellLogPlot::setDepthRange(double minDepth, double maxDepth) m_tracePlots[tpIdx]->setDepthRange(minDepth, maxDepth); } } + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuWellLogPlot::wheelEvent(QWheelEvent* event) +{ + if (!m_dataModelPlot) + { + QWidget::wheelEvent(event); + return; + } + + if (event->delta() > 0) + { + m_dataModelPlot->zoomDepth(RIU_SCROLLWHEEL_ZOOMFACTOR); + } + else + { + m_dataModelPlot->zoomDepth(1.0/RIU_SCROLLWHEEL_ZOOMFACTOR); + } + + event->accept(); +} diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.h b/ApplicationCode/UserInterface/RiuWellLogPlot.h index 45e85d5f87..567e661760 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.h +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.h @@ -24,7 +24,9 @@ class RimWellLogPlot; class RiuWellLogTracePlot; + class QHBoxLayout; +class QWheelEvent; //================================================================================================== // @@ -36,18 +38,22 @@ class RiuWellLogPlot : public QWidget Q_OBJECT public: - RiuWellLogPlot(QWidget* parent = NULL); + RiuWellLogPlot(RimWellLogPlot* dataModelPlot, QWidget* parent = NULL); virtual ~RiuWellLogPlot(); RiuWellLogTracePlot* createTracePlot(); void setDepthRange(double minDepth, double maxDepth); +protected: + void wheelEvent(QWheelEvent* event); + private: void setDefults(); private: - QHBoxLayout* m_layout; + QHBoxLayout* m_layout; QList m_tracePlots; + RimWellLogPlot* m_dataModelPlot; };