#786 Picking curves selects the curve

This commit is contained in:
Jacob Støren 2016-06-22 11:34:26 +02:00
parent 58391efef1
commit eec539b793
6 changed files with 143 additions and 0 deletions

View File

@ -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_CURVECOLORS[] =
{

View File

@ -55,6 +55,8 @@ public:
void setParentQwtPlot(QwtPlot* plot);
void detachQwtCurves();
RimSummaryCurve* findRimCurveFromQwtCurve(const QwtPlotCurve* qwtCurve) const;
private:
void syncCurvesFromUiSelection();
void syncUiSelectionFromCurves();

View File

@ -240,3 +240,25 @@ void RimSummaryPlot::detachAllCurves()
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;
}

View File

@ -31,6 +31,7 @@
class RiuSummaryQwtPlot;
class RimSummaryCurve;
class RimSummaryCurveFilter;
class QwtPlotCurve;
//==================================================================================================
///
@ -47,6 +48,8 @@ public:
void setDescription(const QString& description);
void addCurve(RimSummaryCurve* curve);
void addCurveFilter(RimSummaryCurveFilter* curveFilter);
RimSummaryCurve* findRimCurveFromQwtCurve(const QwtPlotCurve* curve) const;
void loadDataAndUpdate();
void handleViewerDeletion();

View File

@ -26,6 +26,9 @@
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.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.
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);
}
}
}

View File

@ -39,8 +39,12 @@ public:
RimSummaryPlot* ownerPlotDefinition();
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);
private:
void setDefaults();
void selectClosestCurve(const QPoint& pos);
private:
QwtPlotGrid* m_grid;