Skip to content

Commit

Permalink
(#396) Handling scroll wheel event to zoom all well log trace plots
Browse files Browse the repository at this point in the history
  • Loading branch information
palhagen committed Sep 1, 2015
1 parent 8485e76 commit ba1b2ec
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
30 changes: 25 additions & 5 deletions ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
7 changes: 5 additions & 2 deletions ApplicationCode/ProjectDataModel/RimWellLogPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ class RimWellLogPlot : public caf::PdmObject

RiuWellLogPlot* viewer();

void zoomDepth(double zoomFactor);

protected:

// Overridden PDM methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);

private:
void updateViewerWidget();
void setDepthRange(double minimumDepth, double maximumDepth);

virtual caf::PdmFieldHandle* objectToggleField();

private:
QPointer<RiuWellLogPlot> m_viewer;

caf::PdmField<double> minimumDepth;
caf::PdmField<double> maximumDepth;
caf::PdmField<double> m_minimumDepth;
caf::PdmField<double> m_maximumDepth;
};
32 changes: 31 additions & 1 deletion ApplicationCode/UserInterface/RiuWellLogPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@
#include "cvfAssert.h"

#include <QHBoxLayout>
#include <QWheelEvent>

#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);

Expand Down Expand Up @@ -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();
}
10 changes: 8 additions & 2 deletions ApplicationCode/UserInterface/RiuWellLogPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

class RimWellLogPlot;
class RiuWellLogTracePlot;

class QHBoxLayout;
class QWheelEvent;

//==================================================================================================
//
Expand All @@ -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<RiuWellLogTracePlot*> m_tracePlots;
RimWellLogPlot* m_dataModelPlot;
};

0 comments on commit ba1b2ec

Please sign in to comment.