mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#466) Clicking a plot curve selects the item in the project tree view
This commit is contained in:
parent
ce6c33fa09
commit
ca375d90ea
@ -47,6 +47,9 @@ public:
|
||||
|
||||
void setPlot(RiuWellLogTracePlot* plot);
|
||||
void detachCurve();
|
||||
|
||||
QwtPlotCurve* plotCurve() const { return m_plotCurve; }
|
||||
|
||||
virtual void updatePlotData();
|
||||
|
||||
protected:
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -30,6 +30,8 @@
|
||||
class RimWellLogPlotCurve;
|
||||
class RiuWellLogTracePlot;
|
||||
|
||||
class QwtPlotCurve;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
@ -54,6 +56,8 @@ public:
|
||||
|
||||
RiuWellLogTracePlot* viewer();
|
||||
|
||||
RimWellLogPlotCurve* curveDefinitionFromCurve(const QwtPlotCurve* curve) const;
|
||||
|
||||
protected:
|
||||
|
||||
// Overridden PDM methods
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ protected:
|
||||
|
||||
private:
|
||||
void setDefaults();
|
||||
void selectClosestCurve(const QPoint& pos);
|
||||
|
||||
private:
|
||||
RimWellLogPlotTrace* m_plotTraceDefinition;
|
||||
|
Loading…
Reference in New Issue
Block a user