2019-03-04 08:35:48 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- Equinor ASA
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiuGridCrossQwtPlot.h"
|
|
|
|
|
2019-04-10 09:13:40 -05:00
|
|
|
#include "RiaFontCache.h"
|
|
|
|
|
2019-03-04 08:35:48 -06:00
|
|
|
#include "RiuCvfOverlayItemWidget.h"
|
2019-03-26 05:33:55 -05:00
|
|
|
#include "RiuQwtCurvePointTracker.h"
|
2019-10-11 08:54:19 -05:00
|
|
|
#include "RiuQwtPlotTools.h"
|
|
|
|
#include "RiuQwtPlotWheelZoomer.h"
|
|
|
|
#include "RiuQwtPlotZoomer.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RiuRimQwtPlotCurve.h"
|
2019-03-04 08:35:48 -06:00
|
|
|
#include "RiuWidgetDragger.h"
|
|
|
|
|
|
|
|
#include "RimGridCrossPlot.h"
|
2019-03-26 05:33:55 -05:00
|
|
|
#include "RimGridCrossPlotCurve.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimGridCrossPlotDataSet.h"
|
2019-11-15 03:12:19 -06:00
|
|
|
#include "RimPlot.h"
|
2019-03-04 08:35:48 -06:00
|
|
|
#include "RimRegularLegendConfig.h"
|
|
|
|
|
2019-03-11 05:39:23 -05:00
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
2019-04-10 09:13:40 -05:00
|
|
|
#include "cafFixedAtlasFont.h"
|
2019-03-11 05:39:23 -05:00
|
|
|
#include "cafSelectionManager.h"
|
2019-03-04 08:35:48 -06:00
|
|
|
#include "cafTitledOverlayFrame.h"
|
|
|
|
|
2019-03-12 10:05:58 -05:00
|
|
|
#include "RimPlotAxisAnnotation.h"
|
2019-03-22 09:11:56 -05:00
|
|
|
#include "RimPlotAxisProperties.h"
|
2019-03-12 10:05:58 -05:00
|
|
|
#include "RiuPlotAnnotationTool.h"
|
|
|
|
|
2019-10-25 08:24:53 -05:00
|
|
|
#include "qwt_legend.h"
|
|
|
|
#include "qwt_legend_label.h"
|
2019-10-11 08:54:19 -05:00
|
|
|
#include "qwt_plot_panner.h"
|
2019-10-09 02:21:28 -05:00
|
|
|
#include "qwt_scale_draw.h"
|
|
|
|
#include "qwt_scale_widget.h"
|
2019-03-26 05:33:55 -05:00
|
|
|
#include "qwt_text.h"
|
|
|
|
#include "qwt_text_engine.h"
|
|
|
|
|
2019-03-25 08:47:55 -05:00
|
|
|
#include <QLabel>
|
2019-03-11 05:39:23 -05:00
|
|
|
#include <QMenu>
|
2019-03-07 12:00:38 -06:00
|
|
|
#include <QResizeEvent>
|
2019-03-25 08:47:55 -05:00
|
|
|
#include <QVBoxLayout>
|
2019-03-07 12:00:38 -06:00
|
|
|
|
2019-03-04 08:35:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-01-16 05:32:40 -06:00
|
|
|
RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimGridCrossPlot* plot, QWidget* parent /*= nullptr*/ )
|
|
|
|
: RiuQwtPlotWidget( plot, parent )
|
2019-03-12 10:05:58 -05:00
|
|
|
{
|
2019-10-11 08:54:19 -05:00
|
|
|
// LeftButton for the zooming
|
|
|
|
m_zoomerLeft = new RiuQwtPlotZoomer( canvas() );
|
|
|
|
m_zoomerLeft->setRubberBandPen( QColor( Qt::black ) );
|
|
|
|
m_zoomerLeft->setTrackerMode( QwtPicker::AlwaysOff );
|
|
|
|
m_zoomerLeft->setTrackerPen( QColor( Qt::black ) );
|
|
|
|
m_zoomerLeft->initMousePattern( 1 );
|
|
|
|
|
|
|
|
// Attach a zoomer for the right axis
|
|
|
|
m_zoomerRight = new RiuQwtPlotZoomer( canvas() );
|
|
|
|
m_zoomerRight->setAxis( xTop, yRight );
|
|
|
|
m_zoomerRight->setTrackerMode( QwtPicker::AlwaysOff );
|
|
|
|
m_zoomerRight->initMousePattern( 1 );
|
|
|
|
|
|
|
|
// MidButton for the panning
|
|
|
|
QwtPlotPanner* panner = new QwtPlotPanner( canvas() );
|
|
|
|
panner->setMouseButton( Qt::MidButton );
|
|
|
|
|
|
|
|
auto wheelZoomer = new RiuQwtPlotWheelZoomer( this );
|
|
|
|
|
|
|
|
connect( wheelZoomer, SIGNAL( zoomUpdated() ), SLOT( onZoomedSlot() ) );
|
|
|
|
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() ) );
|
2020-05-05 05:43:44 -05:00
|
|
|
connect( this,
|
|
|
|
SIGNAL( plotItemSelected( QwtPlotItem*, bool, int ) ),
|
|
|
|
SLOT( onPlotItemSelected( QwtPlotItem*, bool, int ) ) );
|
2019-10-11 08:54:19 -05:00
|
|
|
|
2019-12-18 05:25:19 -06:00
|
|
|
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>( new RiuPlotAnnotationTool() );
|
2019-03-26 05:33:55 -05:00
|
|
|
m_selectedPointMarker = new QwtPlotMarker;
|
|
|
|
|
|
|
|
// QwtPlotMarker takes ownership of the symbol, it is deleted in destructor of QwtPlotMarker
|
2020-02-12 04:43:15 -06:00
|
|
|
QwtSymbol* mySymbol =
|
|
|
|
new QwtSymbol( QwtSymbol::Ellipse, QBrush( QColor( 255, 255, 255, 50 ) ), QPen( Qt::black, 2.0 ), QSize( 10, 10 ) );
|
2019-09-06 03:40:57 -05:00
|
|
|
m_selectedPointMarker->setSymbol( mySymbol );
|
|
|
|
m_selectedPointMarker->setLabelAlignment( Qt::AlignRight | Qt::AlignVCenter );
|
|
|
|
m_selectedPointMarker->setSpacing( 3 );
|
2019-11-05 01:31:29 -06:00
|
|
|
m_selectedPointMarker->setZ( 1000.0 ); // Make sure it ends up in front of highlighted curves.
|
2019-10-09 02:21:28 -05:00
|
|
|
|
2019-10-11 08:54:19 -05:00
|
|
|
RiuQwtPlotTools::setCommonPlotBehaviour( this );
|
|
|
|
RiuQwtPlotTools::setDefaultAxes( this );
|
|
|
|
|
|
|
|
this->installEventFilter( this );
|
|
|
|
this->canvas()->installEventFilter( this );
|
2019-10-25 08:24:53 -05:00
|
|
|
|
2019-10-31 07:48:40 -05:00
|
|
|
setInternalQwtLegendVisible( true );
|
2019-03-26 05:33:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuGridCrossQwtPlot::~RiuGridCrossQwtPlot()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_selectedPointMarker->plot() )
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
|
|
|
m_selectedPointMarker->detach();
|
|
|
|
}
|
|
|
|
delete m_selectedPointMarker;
|
2019-03-04 08:35:48 -06:00
|
|
|
}
|
|
|
|
|
2019-03-12 10:05:58 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuGridCrossQwtPlot::updateAnnotationObjects( RimPlotAxisProperties* axisProperties )
|
2019-03-12 10:05:58 -05:00
|
|
|
{
|
2019-03-22 09:11:56 -05:00
|
|
|
m_annotationTool->detachAllAnnotations();
|
2019-03-12 10:05:58 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( auto annotation : axisProperties->annotations() )
|
2019-03-12 10:05:58 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
m_annotationTool->attachAnnotationLine( this, annotation->color(), annotation->name(), annotation->value() );
|
2019-03-12 10:05:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 08:24:53 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::setLegendFontSize( int fontSize )
|
|
|
|
{
|
|
|
|
if ( legend() )
|
|
|
|
{
|
|
|
|
QFont font = legend()->font();
|
2020-01-07 07:00:51 -06:00
|
|
|
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( fontSize ) );
|
2019-10-25 08:24:53 -05:00
|
|
|
legend()->setFont( font );
|
|
|
|
// Set font size for all existing labels
|
|
|
|
QList<QwtLegendLabel*> labels = legend()->findChildren<QwtLegendLabel*>();
|
|
|
|
for ( QwtLegendLabel* label : labels )
|
|
|
|
{
|
|
|
|
label->setFont( font );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-12-18 05:25:19 -06:00
|
|
|
/// The internal qwt legend is not used in multi plot windows
|
2019-10-25 08:24:53 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-31 07:48:40 -05:00
|
|
|
void RiuGridCrossQwtPlot::setInternalQwtLegendVisible( bool visible )
|
2019-10-25 08:24:53 -05:00
|
|
|
{
|
|
|
|
if ( visible )
|
|
|
|
{
|
|
|
|
QwtLegend* legend = new QwtLegend( this );
|
|
|
|
this->insertLegend( legend, BottomLegend );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->insertLegend( nullptr );
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 05:39:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuGridCrossQwtPlot::contextMenuEvent( QContextMenuEvent* event )
|
2019-03-11 05:39:23 -05:00
|
|
|
{
|
|
|
|
QMenu menu;
|
|
|
|
caf::CmdFeatureMenuBuilder menuBuilder;
|
|
|
|
|
2020-01-16 05:32:40 -06:00
|
|
|
emit plotSelected( false );
|
2019-03-11 05:39:23 -05:00
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
menuBuilder << "RicSwapGridCrossPlotDataSetAxesFeature";
|
2019-03-12 07:48:51 -05:00
|
|
|
menuBuilder << "Separator";
|
2019-03-11 05:39:23 -05:00
|
|
|
menuBuilder << "RicShowPlotDataFeature";
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
menuBuilder.appendToMenu( &menu );
|
2019-03-11 05:39:23 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( menu.actions().size() > 0 )
|
2019-03-11 05:39:23 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
menu.exec( event->globalPos() );
|
2019-03-11 05:39:23 -05:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 05:33:55 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-05-05 05:43:44 -05:00
|
|
|
void RiuGridCrossQwtPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int pointNumber )
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
2020-05-05 05:43:44 -05:00
|
|
|
if ( pointNumber == -1 )
|
|
|
|
m_selectedPointMarker->detach();
|
|
|
|
else
|
2019-03-27 09:17:52 -05:00
|
|
|
{
|
2020-05-05 05:43:44 -05:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 09:17:52 -05:00
|
|
|
}
|
2019-03-26 05:33:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:43:15 -06:00
|
|
|
bool RiuGridCrossQwtPlot::curveText( const QwtPlotCurve* curve, QString* curveTitle, QString* xParamName, QString* yParamName ) const
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( curveTitle && xParamName && yParamName );
|
2019-03-27 09:17:52 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
auto riuCurve = dynamic_cast<const RiuRimQwtPlotCurve*>( curve );
|
|
|
|
if ( riuCurve )
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto crossPlotCurve = dynamic_cast<const RimGridCrossPlotCurve*>( riuCurve->ownerRimCurve() );
|
|
|
|
if ( crossPlotCurve )
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
2019-03-27 09:17:52 -05:00
|
|
|
*curveTitle = crossPlotCurve->curveName();
|
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
RimGridCrossPlotDataSet* dataSet = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
crossPlotCurve->firstAncestorOrThisOfType( dataSet );
|
|
|
|
if ( dataSet )
|
2019-03-27 09:17:52 -05:00
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
*xParamName = dataSet->xAxisName();
|
|
|
|
*yParamName = dataSet->yAxisName();
|
2019-03-27 09:17:52 -05:00
|
|
|
return true;
|
|
|
|
}
|
2019-03-26 05:33:55 -05:00
|
|
|
}
|
|
|
|
}
|
2019-03-27 09:17:52 -05:00
|
|
|
return false;
|
2019-03-26 05:33:55 -05:00
|
|
|
}
|
2019-04-10 09:13:40 -05:00
|
|
|
|
2019-11-05 01:27:35 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RiuGridCrossQwtPlot::isZoomerActive() const
|
|
|
|
{
|
|
|
|
return m_zoomerLeft->isActiveAndValid() || m_zoomerRight->isActiveAndValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::endZoomOperations()
|
|
|
|
{
|
|
|
|
m_zoomerLeft->endZoomOperation();
|
|
|
|
m_zoomerRight->endZoomOperation();
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:54:19 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::onZoomedSlot()
|
|
|
|
{
|
2020-01-16 05:32:40 -06:00
|
|
|
emit plotZoomed();
|
2019-10-11 08:54:19 -05:00
|
|
|
}
|