mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#786 Picking curves selects the curve
This commit is contained in:
@@ -229,6 +229,25 @@ void RimSummaryCurveFilter::detachQwtCurves()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RimSummaryCurve* RimSummaryCurveFilter::findRimCurveFromQwtCurve(const QwtPlotCurve* qwtCurve) const
|
||||||
|
{
|
||||||
|
for(RimSummaryCurve* rimCurve: m_curves)
|
||||||
|
{
|
||||||
|
if(rimCurve->qwtPlotCurve() == qwtCurve)
|
||||||
|
{
|
||||||
|
return rimCurve;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const int RI_LOGPLOT_CURVECOLORSCOUNT = 15;
|
static const int RI_LOGPLOT_CURVECOLORSCOUNT = 15;
|
||||||
static const int RI_LOGPLOT_CURVECOLORS[] =
|
static const int RI_LOGPLOT_CURVECOLORS[] =
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ public:
|
|||||||
void setParentQwtPlot(QwtPlot* plot);
|
void setParentQwtPlot(QwtPlot* plot);
|
||||||
void detachQwtCurves();
|
void detachQwtCurves();
|
||||||
|
|
||||||
|
RimSummaryCurve* findRimCurveFromQwtCurve(const QwtPlotCurve* qwtCurve) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void syncCurvesFromUiSelection();
|
void syncCurvesFromUiSelection();
|
||||||
void syncUiSelectionFromCurves();
|
void syncUiSelectionFromCurves();
|
||||||
|
|||||||
@@ -240,3 +240,25 @@ void RimSummaryPlot::detachAllCurves()
|
|||||||
curve->detachQwtCurve();
|
curve->detachQwtCurve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RimSummaryCurve* RimSummaryPlot::findRimCurveFromQwtCurve(const QwtPlotCurve* qwtCurve) const
|
||||||
|
{
|
||||||
|
for(RimSummaryCurve* rimCurve: m_curves)
|
||||||
|
{
|
||||||
|
if(rimCurve->qwtPlotCurve() == qwtCurve)
|
||||||
|
{
|
||||||
|
return rimCurve;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RimSummaryCurveFilter* curveFilter: m_curveFilters)
|
||||||
|
{
|
||||||
|
RimSummaryCurve* foundCurve = curveFilter->findRimCurveFromQwtCurve(qwtCurve);
|
||||||
|
if (foundCurve) return foundCurve;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
class RiuSummaryQwtPlot;
|
class RiuSummaryQwtPlot;
|
||||||
class RimSummaryCurve;
|
class RimSummaryCurve;
|
||||||
class RimSummaryCurveFilter;
|
class RimSummaryCurveFilter;
|
||||||
|
class QwtPlotCurve;
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
@@ -47,6 +48,8 @@ public:
|
|||||||
void setDescription(const QString& description);
|
void setDescription(const QString& description);
|
||||||
void addCurve(RimSummaryCurve* curve);
|
void addCurve(RimSummaryCurve* curve);
|
||||||
void addCurveFilter(RimSummaryCurveFilter* curveFilter);
|
void addCurveFilter(RimSummaryCurveFilter* curveFilter);
|
||||||
|
|
||||||
|
RimSummaryCurve* findRimCurveFromQwtCurve(const QwtPlotCurve* curve) const;
|
||||||
|
|
||||||
void loadDataAndUpdate();
|
void loadDataAndUpdate();
|
||||||
void handleViewerDeletion();
|
void handleViewerDeletion();
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
#include "qwt_plot_grid.h"
|
#include "qwt_plot_grid.h"
|
||||||
#include "qwt_plot_layout.h"
|
#include "qwt_plot_layout.h"
|
||||||
#include "qwt_scale_engine.h"
|
#include "qwt_scale_engine.h"
|
||||||
|
#include <QEvent>
|
||||||
|
#include "RiuMainWindow.h"
|
||||||
|
#include "RimSummaryCurve.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@@ -124,3 +127,93 @@ void RiuSummaryQwtPlot::setDefaults()
|
|||||||
// another legend is inserted.
|
// another legend is inserted.
|
||||||
this->insertLegend(legend, BottomLegend);
|
this->insertLegend(legend, BottomLegend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RiuSummaryQwtPlot::eventFilter(QObject* watched, QEvent* event)
|
||||||
|
{
|
||||||
|
if(watched == canvas())
|
||||||
|
{
|
||||||
|
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(event);
|
||||||
|
if(wheelEvent)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
if(!m_plotDefinition)
|
||||||
|
{
|
||||||
|
return QwtPlot::eventFilter(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wheelEvent->modifiers() & Qt::ControlModifier)
|
||||||
|
{
|
||||||
|
QwtScaleMap scaleMap = canvasMap(QwtPlot::yLeft);
|
||||||
|
double zoomCenter = scaleMap.invTransform(wheelEvent->pos().y());
|
||||||
|
|
||||||
|
if(wheelEvent->delta() > 0)
|
||||||
|
{
|
||||||
|
plotDefinition->setDepthZoomByFactorAndCenter(RIU_SCROLLWHEEL_ZOOMFACTOR, zoomCenter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plotDefinition->setDepthZoomByFactorAndCenter(1.0/RIU_SCROLLWHEEL_ZOOMFACTOR, zoomCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plotDefinition->panDepth(wheelEvent->delta() < 0 ? RIU_SCROLLWHEEL_PANFACTOR : -RIU_SCROLLWHEEL_PANFACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||||||
|
if(mouseEvent)
|
||||||
|
{
|
||||||
|
if(mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonRelease)
|
||||||
|
{
|
||||||
|
selectClosestCurve(mouseEvent->pos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QwtPlot::eventFilter(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuSummaryQwtPlot::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;
|
||||||
|
candidateCurve->closestPoint(pos, &dist);
|
||||||
|
if(dist < distMin)
|
||||||
|
{
|
||||||
|
closestCurve = candidateCurve;
|
||||||
|
distMin = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(closestCurve && distMin < 20)
|
||||||
|
{
|
||||||
|
RimSummaryCurve* selectedCurve = m_plotDefinition->findRimCurveFromQwtCurve(closestCurve);
|
||||||
|
if(selectedCurve)
|
||||||
|
{
|
||||||
|
RiuMainWindow::instance()->selectAsCurrentItem(selectedCurve);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,8 +39,12 @@ public:
|
|||||||
|
|
||||||
RimSummaryPlot* ownerPlotDefinition();
|
RimSummaryPlot* ownerPlotDefinition();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDefaults();
|
void setDefaults();
|
||||||
|
void selectClosestCurve(const QPoint& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QwtPlotGrid* m_grid;
|
QwtPlotGrid* m_grid;
|
||||||
|
|||||||
Reference in New Issue
Block a user