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

@@ -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();