Working clicking on Tornado Plots

This commit is contained in:
Gaute Lindkvist 2020-05-05 12:43:44 +02:00
parent 70685b73b4
commit 3240c24f2c
13 changed files with 95 additions and 63 deletions

View File

@ -26,6 +26,7 @@ ${SOURCE_GROUP_SOURCE_FILES}
)
list(APPEND QT_MOC_HEADERS
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlot.h
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationMatrixPlot.h
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationReportPlot.h
)

View File

@ -549,7 +549,7 @@ void RimCorrelationMatrixPlot::updateLegend()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationMatrixPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle )
void RimCorrelationMatrixPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex )
{
CorrelationMatrixShapeItem* matrixItem = dynamic_cast<CorrelationMatrixShapeItem*>( plotItem );
if ( matrixItem )

View File

@ -71,7 +71,7 @@ private:
void createMatrix();
void updatePlotTitle() override;
void updateLegend() override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle ) override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex ) override;
private:
caf::PdmField<CorrelationFactorEnum> m_correlationFactor;

View File

@ -39,6 +39,8 @@
#include "cafPdmUiComboBoxEditor.h"
#include "qwt_plot_barchart.h"
#include <limits>
#include <map>
#include <set>
@ -295,6 +297,26 @@ void RimCorrelationPlot::updatePlotTitle()
m_plotWidget->setPlotTitleFontSize( isMdiWindow() ? 8 : 10 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex )
{
QwtPlotBarChart* barChart = dynamic_cast<QwtPlotBarChart*>( plotItem );
if ( barChart && !curveDefinitions().empty() )
{
auto curveDef = curveDefinitions().front();
auto barTitle = barChart->title();
for ( auto param : ensembleParameters() )
{
if ( barTitle.text() == param.name )
{
emit tornadoItemSelected( param, curveDef );
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -18,7 +18,9 @@
#pragma once
#include "RiaSummaryCurveDefinition.h"
#include "RimAbstractCorrelationPlot.h"
#include "RimSummaryCaseCollection.h"
#include "cafAppEnum.h"
#include <QDateTime>
@ -32,6 +34,7 @@ class RiuGroupedBarChartBuilder;
//==================================================================================================
class RimCorrelationPlot : public RimAbstractCorrelationPlot
{
Q_OBJECT;
CAF_PDM_HEADER_INIT;
public:
@ -55,6 +58,9 @@ public:
bool sortByAbsoluteValues() const;
void setSortByAbsoluteValues( bool sortByAbsoluteValues );
signals:
void tornadoItemSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& curveDef );
private:
// Overridden PDM methods
@ -71,6 +77,7 @@ private:
// Private methods
void addDataToChartBuilder( RiuGroupedBarChartBuilder& chartBuilder );
void updatePlotTitle() override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex ) override;
private:
caf::PdmField<CorrelationFactorEnum> m_correlationFactor;

View File

@ -65,7 +65,11 @@ RimCorrelationReportPlot::RimCorrelationReportPlot()
this->connect( m_correlationMatrixPlot(),
SIGNAL( matrixCellSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ),
SLOT( onMatrixCellSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ) );
SLOT( onDataSelection( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ) );
this->connect( m_correlationPlot(),
SIGNAL( tornadoItemSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ),
SLOT( onDataSelection( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ) );
}
//--------------------------------------------------------------------------------------------------
@ -304,8 +308,7 @@ void RimCorrelationReportPlot::childFieldChangedByUi( const caf::PdmFieldHandle*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationReportPlot::onMatrixCellSelected( const EnsembleParameter& param,
const RiaSummaryCurveDefinition& curveDef )
void RimCorrelationReportPlot::onDataSelection( const EnsembleParameter& param, const RiaSummaryCurveDefinition& curveDef )
{
m_correlationPlot->setCurveDefinitions( { curveDef } );
m_correlationPlot->loadDataAndUpdate();

View File

@ -74,7 +74,7 @@ private:
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
private slots:
void onMatrixCellSelected( const EnsembleParameter& param, const RiaSummaryCurveDefinition& curveDef );
void onDataSelection( const EnsembleParameter& param, const RiaSummaryCurveDefinition& curveDef );
private:
caf::PdmProxyValueField<QString> m_plotWindowTitle;

View File

@ -163,8 +163,8 @@ void RimPlot::attachPlotWidgetSignals( RimPlot* plot, RiuQwtPlotWidget* plotWidg
plot->connect( plotWidget, SIGNAL( plotSelected( bool ) ), SLOT( onPlotSelected( bool ) ) );
plot->connect( plotWidget, SIGNAL( axisSelected( int, bool ) ), SLOT( onAxisSelected( int, bool ) ) );
plot->connect( plotWidget,
SIGNAL( plotItemSelected( QwtPlotItem*, bool ) ),
SLOT( onPlotItemSelected( QwtPlotItem*, bool ) ) );
SIGNAL( plotItemSelected( QwtPlotItem*, bool, int ) ),
SLOT( onPlotItemSelected( QwtPlotItem*, bool, int ) ) );
plot->connect( plotWidget, SIGNAL( onKeyPressEvent( QKeyEvent* ) ), SLOT( onKeyPressEvent( QKeyEvent* ) ) );
plot->connect( plotWidget, SIGNAL( onWheelEvent( QWheelEvent* ) ), SLOT( onWheelEvent( QWheelEvent* ) ) );
plot->connect( plotWidget, SIGNAL( destroyed() ), SLOT( onViewerDestroyed() ) );
@ -199,7 +199,7 @@ void RimPlot::onPlotSelected( bool toggle )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle )
void RimPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex )
{
QwtPlotCurve* curve = dynamic_cast<QwtPlotCurve*>( plotItem );
if ( curve )

View File

@ -105,7 +105,7 @@ private:
private slots:
void onPlotSelected( bool toggle );
virtual void onAxisSelected( int axis, bool toggle ) {}
virtual void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle );
virtual void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex );
void onViewerDestroyed();
void onKeyPressEvent( QKeyEvent* event );
void onWheelEvent( QWheelEvent* event );

View File

@ -84,6 +84,9 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimGridCrossPlot* plot, QWidget* paren
connect( m_zoomerLeft, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
connect( m_zoomerRight, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );
connect( this,
SIGNAL( plotItemSelected( QwtPlotItem*, bool, int ) ),
SLOT( onPlotItemSelected( QwtPlotItem*, bool, int ) ) );
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>( new RiuPlotAnnotationTool() );
m_selectedPointMarker = new QwtPlotMarker;
@ -189,35 +192,36 @@ void RiuGridCrossQwtPlot::contextMenuEvent( QContextMenuEvent* event )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::selectPoint( QwtPlotCurve* curve, int pointNumber )
void RiuGridCrossQwtPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int pointNumber )
{
QPointF sample = curve->sample( pointNumber );
m_selectedPointMarker->setValue( sample );
m_selectedPointMarker->setAxes( QwtPlot::xBottom, QwtPlot::yLeft );
m_selectedPointMarker->attach( this );
QString curveName, xAxisName, yAxisName;
if ( curveText( curve, &curveName, &xAxisName, &yAxisName ) )
if ( pointNumber == -1 )
m_selectedPointMarker->detach();
else
{
QString labelFormat( "<div style=\"margin: 4px;\"><b>%1:</b><br/>%2 = %3, %4 = %5</div>" );
QString labelString =
labelFormat.arg( curveName ).arg( xAxisName ).arg( sample.x() ).arg( yAxisName ).arg( sample.y() );
QwtText curveLabel( labelString, QwtText::RichText );
curveLabel.setBackgroundBrush( QBrush( QColor( 250, 250, 250, 220 ) ) );
curveLabel.setPaintAttribute( QwtText::PaintBackground );
curveLabel.setBorderPen( QPen( Qt::black, 1.0 ) );
curveLabel.setBorderRadius( 2.0 );
m_selectedPointMarker->setLabel( curveLabel );
QwtPlotCurve* curve = dynamic_cast<QwtPlotCurve*>( plotItem );
if ( curve )
{
QPointF sample = curve->sample( pointNumber );
m_selectedPointMarker->setValue( sample );
m_selectedPointMarker->setAxes( QwtPlot::xBottom, QwtPlot::yLeft );
m_selectedPointMarker->attach( this );
QString curveName, xAxisName, yAxisName;
if ( curveText( curve, &curveName, &xAxisName, &yAxisName ) )
{
QString labelFormat( "<div style=\"margin: 4px;\"><b>%1:</b><br/>%2 = %3, %4 = %5</div>" );
QString labelString =
labelFormat.arg( curveName ).arg( xAxisName ).arg( sample.x() ).arg( yAxisName ).arg( sample.y() );
QwtText curveLabel( labelString, QwtText::RichText );
curveLabel.setBackgroundBrush( QBrush( QColor( 250, 250, 250, 220 ) ) );
curveLabel.setPaintAttribute( QwtText::PaintBackground );
curveLabel.setBorderPen( QPen( Qt::black, 1.0 ) );
curveLabel.setBorderRadius( 2.0 );
m_selectedPointMarker->setLabel( curveLabel );
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::clearPointSelection()
{
m_selectedPointMarker->detach();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -67,14 +67,13 @@ signals:
protected:
void contextMenuEvent( QContextMenuEvent* ) override;
void selectPoint( QwtPlotCurve* curve, int pointNumber ) override;
void clearPointSelection() override;
bool curveText( const QwtPlotCurve* curve, QString* curveTitle, QString* xParamName, QString* yParamName ) const;
bool isZoomerActive() const override;
void endZoomOperations() override;
private slots:
void onZoomedSlot();
void onPlotItemSelected( QwtPlotItem* selectedItem, bool toggleItem, int sampleIndex );
private:
std::unique_ptr<RiuPlotAnnotationTool> m_annotationTool;

View File

@ -36,6 +36,7 @@
#include "qwt_legend.h"
#include "qwt_legend_label.h"
#include "qwt_plot_barchart.h"
#include "qwt_plot_canvas.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_grid.h"
@ -741,20 +742,6 @@ QSize RiuQwtPlotWidget::minimumSizeHint() const
return QSize( 0, 0 );
}
//--------------------------------------------------------------------------------------------------
/// Empty default implementation
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::selectPoint( QwtPlotCurve* curve, int pointNumber )
{
}
//--------------------------------------------------------------------------------------------------
/// Empty default implementation
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::clearPointSelection()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -983,13 +970,32 @@ void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItem
else if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotShape )
{
QwtPlotShapeItem* shapeItem = static_cast<QwtPlotShapeItem*>( *it );
QPoint scalePos( invTransform( xBottom, pos.x() ), invTransform( yLeft, pos.y() ) );
QPointF scalePos( invTransform( xBottom, pos.x() ), invTransform( yLeft, pos.y() ) );
if ( shapeItem->shape().boundingRect().contains( scalePos ) )
{
closestItem = *it;
distMin = 0.0;
}
}
else if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotBarChart )
{
QwtPlotBarChart* barChart = static_cast<QwtPlotBarChart*>( *it );
QPointF scalePos( invTransform( xBottom, pos.x() ), invTransform( yLeft, pos.y() ) );
bool horizontal = barChart->orientation() == Qt::Horizontal;
for ( size_t i = 0; i < barChart->dataSize(); ++i )
{
QPointF samplePoint = barChart->sample( i );
double dist = horizontal ? std::abs( samplePoint.x() - scalePos.y() )
: std::abs( samplePoint.x() - scalePos.x() );
if ( dist < distMin )
{
closestItem = *it;
closestCurvePoint = (int)i;
distMin = dist;
}
}
}
}
RiuPlotMainWindowTools::showPlotMainWindow();
@ -998,16 +1004,8 @@ void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItem
{
// TODO: highlight all selected curves
highlightPlotItem( closestItem );
emit plotItemSelected( closestItem, toggleItemInSelection );
emit plotItemSelected( closestItem, toggleItemInSelection, distMin < 10 ? closestCurvePoint : -1 );
if ( distMin < 10 && ( closestItem )->rtti() == QwtPlotItem::Rtti_PlotCurve )
{
selectPoint( static_cast<QwtPlotCurve*>( closestItem ), closestCurvePoint );
}
else
{
clearPointSelection();
}
scheduleReplot();
}
else

View File

@ -136,7 +136,7 @@ public:
signals:
void plotSelected( bool toggleSelection );
void axisSelected( int axisId, bool toggleSelection );
void plotItemSelected( QwtPlotItem* plotItem, bool toggleSelection );
void plotItemSelected( QwtPlotItem* plotItem, bool toggleSelection, int sampleIndex );
void onKeyPressEvent( QKeyEvent* event );
void onWheelEvent( QWheelEvent* event );
@ -153,8 +153,6 @@ protected:
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
virtual void selectPoint( QwtPlotCurve* curve, int pointNumber );
virtual void clearPointSelection();
virtual bool isZoomerActive() const;
virtual void endZoomOperations();