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-10-11 08:54:19 -05:00
|
|
|
#include "RimPlotInterface.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
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-11 08:54:19 -05:00
|
|
|
RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimPlotInterface* plotDefinition, QWidget* parent /*= nullptr*/ )
|
|
|
|
: RiuQwtPlotWidget( plotDefinition, 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 );
|
|
|
|
m_zoomerLeft->setMousePattern( QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::ShiftModifier );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
m_zoomerRight->setMousePattern( QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::ShiftModifier );
|
|
|
|
|
|
|
|
// 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() ) );
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>( new RiuPlotAnnotationTool() );
|
|
|
|
m_infoBox = new RiuDraggableOverlayFrame( this, canvas() );
|
|
|
|
|
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
|
2019-09-06 03:40:57 -05:00
|
|
|
QwtSymbol* mySymbol = new QwtSymbol( QwtSymbol::Ellipse,
|
|
|
|
QBrush( QColor( 255, 255, 255, 50 ) ),
|
|
|
|
QPen( Qt::black, 2.0 ),
|
|
|
|
QSize( 10, 10 ) );
|
|
|
|
m_selectedPointMarker->setSymbol( mySymbol );
|
|
|
|
m_selectedPointMarker->setLabelAlignment( Qt::AlignRight | Qt::AlignVCenter );
|
|
|
|
m_selectedPointMarker->setSpacing( 3 );
|
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
|
|
|
|
|
|
|
setLegendVisible( 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-09-06 03:40:57 -05:00
|
|
|
void RiuGridCrossQwtPlot::addOrUpdateDataSetLegend( RimGridCrossPlotDataSet* dataSet )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
|
|
|
RiuCvfOverlayItemWidget* overlayWidget = nullptr;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
auto it = m_legendWidgets.find( dataSet );
|
|
|
|
if ( it == m_legendWidgets.end() || it->second == nullptr )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
overlayWidget = new RiuCvfOverlayItemWidget( this, canvas() );
|
2019-03-29 07:17:39 -05:00
|
|
|
m_legendWidgets[dataSet] = overlayWidget;
|
2019-03-04 08:35:48 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
overlayWidget = it->second;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( overlayWidget )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
caf::TitledOverlayFrame* overlayItem = dataSet->legendConfig()->titledOverlayFrame();
|
2019-09-06 03:40:57 -05:00
|
|
|
applyFontSizeToOverlayItem( overlayItem );
|
|
|
|
resizeOverlayItemToFitPlot( overlayItem );
|
|
|
|
overlayWidget->updateFromOverlayItem( overlayItem );
|
2019-03-04 08:35:48 -06:00
|
|
|
}
|
|
|
|
this->updateLegendLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuGridCrossQwtPlot::removeDataSetLegend( RimGridCrossPlotDataSet* dataSetToShowLegendFor )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto it = m_legendWidgets.find( dataSetToShowLegendFor );
|
|
|
|
if ( it != m_legendWidgets.end() )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( it->second != nullptr )
|
2019-04-15 03:38:29 -05:00
|
|
|
{
|
|
|
|
it->second->hide();
|
|
|
|
it->second->deleteLater();
|
|
|
|
}
|
2019-03-04 08:35:48 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
m_legendWidgets.erase( it );
|
2019-03-04 08:35:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
this->updateLegendLayout();
|
|
|
|
}
|
|
|
|
|
2019-04-15 03:38:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::removeDanglingDataSetLegends()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( auto it = m_legendWidgets.begin(); it != m_legendWidgets.end(); )
|
2019-04-15 03:38:29 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( it->first.isNull() )
|
2019-04-15 03:38:29 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( it->second != nullptr )
|
2019-04-15 03:38:29 -05:00
|
|
|
{
|
|
|
|
it->second->hide();
|
|
|
|
it->second->deleteLater();
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
m_legendWidgets.erase( it++ );
|
2019-04-15 03:38:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 02:59:29 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::updateLegendSizesToMatchPlot()
|
|
|
|
{
|
2019-10-11 08:54:19 -05:00
|
|
|
RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>( plotDefinition() );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !crossPlot ) return;
|
2019-03-08 02:59:29 -06:00
|
|
|
|
|
|
|
bool anyLegendResized = false;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( RimGridCrossPlotDataSet* dataSet : crossPlot->dataSets() )
|
2019-03-08 02:59:29 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !dataSet->isChecked() || !dataSet->legendConfig()->showLegend() ) continue;
|
2019-03-08 02:59:29 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
auto pairIt = m_legendWidgets.find( dataSet );
|
|
|
|
if ( pairIt != m_legendWidgets.end() )
|
2019-03-08 02:59:29 -06:00
|
|
|
{
|
|
|
|
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::TitledOverlayFrame* overlayItem = dataSet->legendConfig()->titledOverlayFrame();
|
|
|
|
applyFontSizeToOverlayItem( overlayItem );
|
|
|
|
if ( resizeOverlayItemToFitPlot( overlayItem ) )
|
2019-03-08 02:59:29 -06:00
|
|
|
{
|
2019-03-27 09:02:12 -05:00
|
|
|
anyLegendResized = true;
|
2019-09-06 03:40:57 -05:00
|
|
|
overlayWidget->updateFromOverlayItem( overlayItem );
|
2019-03-08 02:59:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( anyLegendResized )
|
2019-03-08 02:59:29 -06:00
|
|
|
{
|
|
|
|
updateLegendLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-11 08:54:19 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimViewWindow* RiuGridCrossQwtPlot::ownerViewWindow() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<RimViewWindow*>( plotDefinition() );
|
|
|
|
}
|
|
|
|
|
2019-10-25 08:24:53 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::setLegendFontSize( int fontSize )
|
|
|
|
{
|
|
|
|
if ( legend() )
|
|
|
|
{
|
|
|
|
QFont font = legend()->font();
|
|
|
|
font.setPointSize( fontSize );
|
|
|
|
legend()->setFont( font );
|
|
|
|
// Set font size for all existing labels
|
|
|
|
QList<QwtLegendLabel*> labels = legend()->findChildren<QwtLegendLabel*>();
|
|
|
|
for ( QwtLegendLabel* label : labels )
|
|
|
|
{
|
|
|
|
label->setFont( font );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateInfoBoxLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::setLegendVisible( bool visible )
|
|
|
|
{
|
|
|
|
if ( visible )
|
|
|
|
{
|
|
|
|
QwtLegend* legend = new QwtLegend( this );
|
|
|
|
this->insertLegend( legend, BottomLegend );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->insertLegend( nullptr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 08:35:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::updateLayout()
|
|
|
|
{
|
|
|
|
QwtPlot::updateLayout();
|
2019-03-25 08:47:55 -05:00
|
|
|
updateInfoBoxLayout();
|
2019-03-04 08:35:48 -06:00
|
|
|
updateLegendLayout();
|
|
|
|
}
|
|
|
|
|
2019-03-25 08:47:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::updateInfoBoxLayout()
|
|
|
|
{
|
2019-10-11 08:54:19 -05:00
|
|
|
RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>( plotDefinition() );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !crossPlot ) return;
|
|
|
|
|
2019-03-25 08:47:55 -05:00
|
|
|
bool showInfo = false;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( crossPlot->showInfoBox() )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
|
|
|
QStringList curveInfoTexts;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( auto dataSet : crossPlot->dataSets() )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
QString curveInfoText = dataSet->infoText();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( dataSet->isChecked() && !curveInfoText.isEmpty() )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
|
|
|
curveInfoTexts += curveInfoText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QStringList infoText;
|
2019-10-09 02:21:28 -05:00
|
|
|
infoText << QString( "<b>View ID:</b> %1<br/>" ).arg( crossPlot->id() );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( curveInfoTexts.size() > 1 )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
infoText += QString( "<ol style=\"margin-top: 0px; margin-left: 15px; -qt-list-indent:0;\">" );
|
|
|
|
for ( QString curveInfoText : curveInfoTexts )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
infoText += QString( "<li>%1</li>" ).arg( curveInfoText );
|
2019-03-25 08:47:55 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
infoText += QString( "</ol>" );
|
2019-03-25 08:47:55 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( curveInfoTexts.size() > 0 )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
|
|
|
infoText += curveInfoTexts.front();
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !infoText.empty() )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
m_infoBox->label()->setText( infoText.join( "\n" ) );
|
2019-10-25 08:24:53 -05:00
|
|
|
QFont font = m_infoBox->label()->font();
|
2019-09-06 03:40:57 -05:00
|
|
|
font.setPointSize( crossPlot->legendFontSize() );
|
2019-10-25 08:24:53 -05:00
|
|
|
m_infoBox->label()->setFont( font );
|
2019-03-25 08:47:55 -05:00
|
|
|
m_infoBox->adjustSize();
|
2019-09-06 03:40:57 -05:00
|
|
|
QRect infoRect = m_infoBox->frameGeometry();
|
2019-03-25 08:47:55 -05:00
|
|
|
QRect canvasRect = canvas()->frameGeometry();
|
2019-09-06 03:40:57 -05:00
|
|
|
infoRect.moveTop( canvasRect.top() + 4 );
|
|
|
|
infoRect.moveRight( canvasRect.right() - 4 );
|
|
|
|
m_infoBox->move( infoRect.topLeft() );
|
2019-03-25 08:47:55 -05:00
|
|
|
showInfo = true;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( showInfo )
|
2019-03-25 08:47:55 -05:00
|
|
|
{
|
|
|
|
m_infoBox->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_infoBox->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 08:35:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::updateLegendLayout()
|
|
|
|
{
|
|
|
|
const int spacing = 5;
|
|
|
|
int startMarginX = this->canvas()->pos().x() + spacing;
|
|
|
|
int startMarginY = this->canvas()->pos().y() + spacing;
|
|
|
|
|
|
|
|
int xpos = startMarginX;
|
|
|
|
int ypos = startMarginY;
|
|
|
|
int maxColumnWidth = 0;
|
|
|
|
|
2019-04-15 03:38:29 -05:00
|
|
|
removeDanglingDataSetLegends();
|
|
|
|
|
2019-10-11 08:54:19 -05:00
|
|
|
RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>( plotDefinition() );
|
2019-03-04 08:35:48 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !crossPlot ) return;
|
2019-03-04 08:35:48 -06:00
|
|
|
|
|
|
|
std::set<QString> legendTypes;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( RimGridCrossPlotDataSet* dataSet : crossPlot->dataSets() )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( dataSet->isChecked() && dataSet->groupingEnabled() && dataSet->legendConfig()->showLegend() )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto pairIt = m_legendWidgets.find( dataSet );
|
|
|
|
if ( pairIt != m_legendWidgets.end() )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-04-12 11:31:57 -05:00
|
|
|
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
|
|
|
|
|
|
|
|
// Show only one copy of each legend type
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !legendTypes.count( dataSet->groupParameter() ) )
|
2019-03-04 08:35:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( ypos + overlayWidget->height() + spacing > this->canvas()->height() )
|
2019-04-12 11:31:57 -05:00
|
|
|
{
|
|
|
|
xpos += spacing + maxColumnWidth;
|
2019-09-06 03:40:57 -05:00
|
|
|
ypos = startMarginY;
|
2019-04-12 11:31:57 -05:00
|
|
|
maxColumnWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
overlayWidget->show();
|
2019-09-06 03:40:57 -05:00
|
|
|
overlayWidget->move( xpos, ypos );
|
2019-04-12 11:31:57 -05:00
|
|
|
|
|
|
|
ypos += pairIt->second->height() + spacing;
|
2019-09-06 03:40:57 -05:00
|
|
|
maxColumnWidth = std::max( maxColumnWidth, pairIt->second->width() );
|
|
|
|
legendTypes.insert( dataSet->groupParameter() );
|
2019-03-04 08:35:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-07 12:00:38 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RiuGridCrossQwtPlot::resizeEvent( QResizeEvent* e )
|
2019-03-07 12:00:38 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QwtPlot::resizeEvent( e );
|
2019-03-08 02:59:29 -06:00
|
|
|
updateLegendSizesToMatchPlot();
|
2019-03-07 12:00:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RiuGridCrossQwtPlot::resizeOverlayItemToFitPlot( caf::TitledOverlayFrame* overlayItem )
|
2019-03-07 12:00:38 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QSize plotSize = this->canvas()->contentsRect().size();
|
2019-03-27 09:02:12 -05:00
|
|
|
cvf::Vec2ui existingRenderSize = overlayItem->renderSize();
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Vec2ui legendSize = overlayItem->preferredSize();
|
2019-03-07 12:00:38 -06:00
|
|
|
|
|
|
|
bool sizeAltered = false;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( plotSize.width() > 0 && (double)legendSize.x() > 0.9 * plotSize.width() )
|
2019-03-07 12:00:38 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
legendSize.x() = ( plotSize.width() * 9 ) / 10;
|
2019-03-12 10:05:58 -05:00
|
|
|
sizeAltered = true;
|
2019-03-07 12:00:38 -06:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( plotSize.height() > 0 && (double)legendSize.y() > 0.9 * plotSize.height() )
|
2019-03-07 12:00:38 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
legendSize.y() = ( plotSize.height() * 9 ) / 10;
|
2019-03-12 10:05:58 -05:00
|
|
|
sizeAltered = true;
|
2019-03-07 12:00:38 -06:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
overlayItem->setRenderSize( legendSize );
|
2019-03-27 09:02:12 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( legendSize.x() != existingRenderSize.x() || legendSize.y() != existingRenderSize.y() )
|
2019-03-27 09:02:12 -05:00
|
|
|
{
|
|
|
|
sizeAltered = true;
|
|
|
|
}
|
|
|
|
|
2019-03-07 12:00:38 -06:00
|
|
|
return sizeAltered;
|
|
|
|
}
|
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;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->setSelectedItem( ownerViewWindow() );
|
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
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-11 08:54:19 -05:00
|
|
|
void RiuGridCrossQwtPlot::selectPoint( QwtPlotCurve* curve, int pointNumber )
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
2019-10-11 08:54:19 -05:00
|
|
|
QPointF sample = curve->sample( pointNumber );
|
2019-09-06 03:40:57 -05:00
|
|
|
m_selectedPointMarker->setValue( sample );
|
|
|
|
m_selectedPointMarker->setAxes( QwtPlot::xBottom, QwtPlot::yLeft );
|
|
|
|
m_selectedPointMarker->attach( this );
|
2019-03-27 09:17:52 -05:00
|
|
|
QString curveName, xAxisName, yAxisName;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( curveText( curve, &curveName, &xAxisName, &yAxisName ) )
|
2019-03-27 09:17:52 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-11 08:54:19 -05:00
|
|
|
void RiuGridCrossQwtPlot::clearPointSelection()
|
2019-03-26 05:33:55 -05:00
|
|
|
{
|
|
|
|
m_selectedPointMarker->detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05: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-09-06 03:40:57 -05:00
|
|
|
void RiuGridCrossQwtPlot::applyFontSizeToOverlayItem( caf::TitledOverlayFrame* overlayItem )
|
2019-04-10 09:13:40 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimGridCrossPlot* crossPlot = static_cast<RimGridCrossPlot*>( ownerViewWindow() );
|
|
|
|
int fontSize = crossPlot->legendFontSize();
|
|
|
|
cvf::ref<cvf::Font> cafFont = RiaFontCache::getFont( RiaFontCache::fontSizeEnumFromPointSize( fontSize ) );
|
|
|
|
overlayItem->setFont( cafFont.p() );
|
2019-04-10 09:13:40 -05:00
|
|
|
}
|
2019-10-11 08:54:19 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuGridCrossQwtPlot::onZoomedSlot()
|
|
|
|
{
|
|
|
|
plotDefinition()->updateZoomFromQwt();
|
|
|
|
}
|