(#466) Clicking a plot curve selects the item in the project tree view

This commit is contained in:
Pål Hagen 2015-09-17 11:34:03 +02:00
parent ce6c33fa09
commit ca375d90ea
5 changed files with 72 additions and 0 deletions

View File

@ -47,6 +47,9 @@ public:
void setPlot(RiuWellLogTracePlot* plot);
void detachCurve();
QwtPlotCurve* plotCurve() const { return m_plotCurve; }
virtual void updatePlotData();
protected:

View File

@ -232,3 +232,19 @@ void RimWellLogPlotTrace::updateAxisRangesAndReplot()
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogPlotCurve* RimWellLogPlotTrace::curveDefinitionFromCurve(const QwtPlotCurve* curve) const
{
for (size_t idx = 0; idx < curves.size(); idx++)
{
if (curves[idx]->plotCurve() == curve)
{
return curves[idx];
}
}
return NULL;
}

View File

@ -30,6 +30,8 @@
class RimWellLogPlotCurve;
class RiuWellLogTracePlot;
class QwtPlotCurve;
//==================================================================================================
///
///
@ -53,6 +55,8 @@ public:
void updateAxisRangesAndReplot();
RiuWellLogTracePlot* viewer();
RimWellLogPlotCurve* curveDefinitionFromCurve(const QwtPlotCurve* curve) const;
protected:

View File

@ -21,6 +21,7 @@
#include "RimWellLogPlot.h"
#include "RimWellLogPlotTrace.h"
#include "RimWellLogPlotCurve.h"
#include "RiuMainWindow.h"
@ -32,8 +33,10 @@
#include "qwt_plot_layout.h"
#include "qwt_scale_draw.h"
#include "qwt_text.h"
#include "qwt_plot_curve.h"
#include <QWheelEvent>
#include <QMouseEvent>
#include <QFont>
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
@ -190,6 +193,17 @@ bool RiuWellLogTracePlot::eventFilter(QObject* watched, QEvent* event)
event->accept();
return true;
}
else
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (mouseEvent)
{
if (mouseEvent->button() == Qt::LeftButton)
{
selectClosestCurve(mouseEvent->pos());
}
}
}
}
return QwtPlot::eventFilter(watched, event);
@ -205,3 +219,37 @@ void RiuWellLogTracePlot::focusInEvent(QFocusEvent* event)
RiuMainWindow::instance()->projectTreeView()->selectAsCurrentItem(m_plotTraceDefinition);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogTracePlot::selectClosestCurve(const QPoint& pos)
{
QwtPlotCurve* closestCurve = NULL;
double distMin = DBL_MAX;
const QwtPlotItemList& itmList = itemList();
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++)
{
if ((*it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
{
QwtPlotCurve* candidateCurve = static_cast<QwtPlotCurve*>(*it);
double dist;
int idx = candidateCurve->closestPoint(pos, &dist);
if (dist < distMin)
{
closestCurve = candidateCurve;
distMin = dist;
}
}
}
if (closestCurve)
{
RimWellLogPlotCurve* selectedCurve = m_plotTraceDefinition->curveDefinitionFromCurve(closestCurve);
if (selectedCurve)
{
RiuMainWindow::instance()->projectTreeView()->selectAsCurrentItem(selectedCurve);
}
}
}

View File

@ -49,6 +49,7 @@ protected:
private:
void setDefaults();
void selectClosestCurve(const QPoint& pos);
private:
RimWellLogPlotTrace* m_plotTraceDefinition;