2017-02-13 01:40:27 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-09-06 06:17:36 -05:00
|
|
|
//
|
2017-02-13 01:40:27 -06:00
|
|
|
// 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.
|
2019-09-06 06:17:36 -05:00
|
|
|
//
|
2017-02-13 01:40:27 -06:00
|
|
|
// 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.
|
2019-09-06 06:17:36 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-02-13 01:40:27 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiuWellLogPlot.h"
|
|
|
|
|
2018-06-29 04:29:18 -05:00
|
|
|
#include "RiaApplication.h"
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
#include "RimContextCommandBuilder.h"
|
2017-02-13 01:40:27 -06:00
|
|
|
#include "RimWellLogPlot.h"
|
|
|
|
#include "RimWellLogTrack.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-02-13 01:40:27 -06:00
|
|
|
#include "RiuMainWindow.h"
|
2018-06-29 04:29:18 -05:00
|
|
|
#include "RiuPlotMainWindow.h"
|
2019-09-04 13:18:18 -05:00
|
|
|
#include "RiuPlotObjectPicker.h"
|
2017-02-13 01:40:27 -06:00
|
|
|
#include "RiuWellLogTrack.h"
|
|
|
|
|
2017-11-18 18:12:39 -06:00
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
2019-09-06 06:17:36 -05:00
|
|
|
#include "cafSelectionManager.h"
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
#include "cvfAssert.h"
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
#include "qwt_legend.h"
|
2018-06-26 04:01:21 -05:00
|
|
|
#include "qwt_plot_layout.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-02-13 01:40:27 -06:00
|
|
|
#include <QFocusEvent>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QMdiSubWindow>
|
2018-06-26 03:24:29 -05:00
|
|
|
#include <QMenu>
|
2017-02-13 01:40:27 -06:00
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2019-01-10 09:16:49 -06:00
|
|
|
#include <cmath>
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
RiuWellLogPlot::RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
, m_scheduleUpdateChildrenLayoutTimer( nullptr )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
Q_ASSERT( plotDefinition );
|
2017-02-13 01:40:27 -06:00
|
|
|
m_plotDefinition = plotDefinition;
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
QPalette newPalette( palette() );
|
|
|
|
newPalette.setColor( QPalette::Background, Qt::white );
|
|
|
|
setPalette( newPalette );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
setAutoFillBackground( true );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotTitle = new QLabel( "PLOT TITLE HERE", this );
|
|
|
|
QFont font = m_plotTitle->font();
|
|
|
|
font.setPointSize( 14 );
|
|
|
|
font.setBold( true );
|
|
|
|
m_plotTitle->setFont( font );
|
2018-06-26 03:24:29 -05:00
|
|
|
m_plotTitle->hide();
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scrollBar = new QScrollBar( this );
|
|
|
|
m_scrollBar->setOrientation( Qt::Vertical );
|
|
|
|
m_scrollBar->setVisible( true );
|
|
|
|
|
|
|
|
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
this->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
|
2019-09-04 13:25:41 -05:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
setFocusPolicy( Qt::StrongFocus );
|
|
|
|
connect( m_scrollBar, SIGNAL( valueChanged( int ) ), this, SLOT( slotSetMinDepth( int ) ) );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuWellLogPlot::~RiuWellLogPlot()
|
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_plotDefinition )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
m_plotDefinition->detachAllCurves();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::addTrackPlot( RiuWellLogTrack* trackPlot )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
// Insert the plot to the left of the scroll bar
|
2019-09-06 06:17:36 -05:00
|
|
|
insertTrackPlot( trackPlot, m_trackPlots.size() );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::insertTrackPlot( RiuWellLogTrack* trackPlot, size_t index )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
trackPlot->setParent( this );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
m_trackPlots.insert( static_cast<int>( index ), trackPlot );
|
|
|
|
|
|
|
|
QwtLegend* legend = new QwtLegend( this );
|
|
|
|
int legendColumns = 1;
|
|
|
|
if ( m_plotDefinition->areTrackLegendsHorizontal() )
|
2018-06-26 04:38:07 -05:00
|
|
|
{
|
|
|
|
legendColumns = 0; // unlimited
|
|
|
|
}
|
2019-09-06 06:17:36 -05:00
|
|
|
legend->setMaxColumns( legendColumns );
|
|
|
|
|
|
|
|
legend->horizontalScrollBar()->setVisible( false );
|
|
|
|
legend->verticalScrollBar()->setVisible( false );
|
|
|
|
|
|
|
|
legend->connect( trackPlot,
|
|
|
|
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
|
|
|
|
SLOT( updateLegend( const QVariant&, const QList<QwtLegendData>& ) ) );
|
|
|
|
legend->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
|
|
|
|
m_legends.insert( static_cast<int>( index ), legend );
|
|
|
|
|
|
|
|
this->connect( trackPlot,
|
|
|
|
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
|
|
|
|
SLOT( scheduleUpdateChildrenLayout() ) );
|
|
|
|
|
|
|
|
if ( !m_plotDefinition->areTrackLegendsVisible() )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
legend->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
trackPlot->updateLegend();
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( trackPlot->isRimTrackVisible() )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
trackPlot->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trackPlot->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::removeTrackPlot( RiuWellLogTrack* trackPlot )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( !trackPlot ) return;
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
int trackIdx = m_trackPlots.indexOf( trackPlot );
|
|
|
|
CVF_ASSERT( trackIdx >= 0 );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
m_trackPlots.removeAt( trackIdx );
|
|
|
|
trackPlot->setParent( nullptr );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
QwtLegend* legend = m_legends[trackIdx];
|
2019-09-06 06:17:36 -05:00
|
|
|
m_legends.removeAt( trackIdx );
|
2017-02-13 01:40:27 -06:00
|
|
|
delete legend;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::setDepthZoomAndReplot( double minDepth, double maxDepth )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tpIdx = 0; tpIdx < m_trackPlots.count(); tpIdx++ )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_trackPlots[tpIdx]->setDepthZoom( minDepth, maxDepth );
|
2017-02-13 01:40:27 -06:00
|
|
|
m_trackPlots[tpIdx]->replot();
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
updateScrollBar( minDepth, maxDepth );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
2018-06-26 03:24:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::setPlotTitle( const QString& plotTitle )
|
2018-06-26 03:24:29 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotTitle->setText( plotTitle );
|
2018-06-26 03:24:29 -05:00
|
|
|
this->updateChildrenLayout();
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-07-03 05:54:51 -05:00
|
|
|
QSize RiuWellLogPlot::preferredSize() const
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2018-07-03 05:54:51 -05:00
|
|
|
int titleWidth = 0;
|
|
|
|
int titleHeight = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_plotTitle && m_plotTitle->isVisible() )
|
2018-07-03 05:54:51 -05:00
|
|
|
{
|
|
|
|
titleWidth = m_plotTitle->width();
|
|
|
|
titleHeight = m_plotTitle->height() + 10;
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
int sumTrackWidth = 0;
|
2018-07-03 05:54:51 -05:00
|
|
|
int maxTrackHeight = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( QPointer<RiuWellLogTrack> track : m_trackPlots )
|
2018-07-03 05:54:51 -05:00
|
|
|
{
|
|
|
|
sumTrackWidth += track->width();
|
2019-09-06 06:17:36 -05:00
|
|
|
maxTrackHeight = std::max( maxTrackHeight, track->height() );
|
2018-07-03 05:54:51 -05:00
|
|
|
}
|
2019-09-06 06:17:36 -05:00
|
|
|
return QSize( std::max( titleWidth, sumTrackWidth ), titleHeight + maxTrackHeight );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
2019-09-04 08:51:44 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuWellLogPlot::showTitle()
|
|
|
|
{
|
|
|
|
m_plotTitle->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuWellLogPlot::hideTitle()
|
|
|
|
{
|
|
|
|
m_plotTitle->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::contextMenuEvent( QContextMenuEvent* event )
|
2017-03-16 02:23:27 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
QMenu menu;
|
2017-11-18 18:12:39 -06:00
|
|
|
caf::CmdFeatureMenuBuilder menuBuilder;
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
caf::SelectionManager::instance()->setSelectedItem( ownerPlotDefinition() );
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-11-18 18:12:39 -06:00
|
|
|
menuBuilder << "RicShowPlotDataFeature";
|
|
|
|
menuBuilder << "RicShowContributingWellsFromPlotFeature";
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
menuBuilder.appendToMenu( &menu );
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( menu.actions().size() > 0 )
|
2017-03-16 02:23:27 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
menu.exec( event->globalPos() );
|
2017-03-16 02:23:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 05:54:51 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize RiuWellLogPlot::sizeHint() const
|
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
return QSize( 1, 1 );
|
2018-07-03 05:54:51 -05:00
|
|
|
}
|
|
|
|
|
2018-09-05 04:04:42 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::keyPressEvent( QKeyEvent* keyEvent )
|
2018-09-05 04:04:42 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotDefinition->handleKeyPressEvent( keyEvent );
|
2018-09-05 04:04:42 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::updateScrollBar( double minDepth, double maxDepth )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
double availableMinDepth;
|
|
|
|
double availableMaxDepth;
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotDefinition->availableDepthRange( &availableMinDepth, &availableMaxDepth );
|
|
|
|
availableMaxDepth += 0.01 * ( availableMaxDepth - availableMinDepth );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
double visibleDepth = maxDepth - minDepth;
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scrollBar->blockSignals( true );
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scrollBar->setRange( (int)availableMinDepth, (int)( ( availableMaxDepth - visibleDepth ) ) );
|
|
|
|
m_scrollBar->setPageStep( (int)visibleDepth );
|
|
|
|
m_scrollBar->setValue( (int)minDepth );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scrollBar->setVisible( true );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scrollBar->blockSignals( false );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::slotSetMinDepth( int value )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
double minimumDepth;
|
|
|
|
double maximumDepth;
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotDefinition->depthZoomMinMax( &minimumDepth, &maximumDepth );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
double delta = value - minimumDepth;
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotDefinition->setDepthZoomMinMax( minimumDepth + delta, maximumDepth + delta );
|
|
|
|
m_plotDefinition->setDepthAutoZoom( false );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimWellLogPlot* RiuWellLogPlot::ownerPlotDefinition()
|
|
|
|
{
|
|
|
|
return m_plotDefinition;
|
|
|
|
}
|
|
|
|
|
2017-03-31 02:17:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-03-31 02:17:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimViewWindow* RiuWellLogPlot::ownerViewWindow() const
|
|
|
|
{
|
|
|
|
return m_plotDefinition;
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::resizeEvent( QResizeEvent* event )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
int height = event->size().height();
|
|
|
|
int width = event->size().width();
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
placeChildWidgets( height, width );
|
|
|
|
QWidget::resizeEvent( event );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-06-26 04:18:24 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
std::map<int, int> RiuWellLogPlot::calculateTrackWidthsToMatchFrame( int frameWidth ) const
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
int trackCount = m_trackPlots.size();
|
2019-09-06 06:17:36 -05:00
|
|
|
|
|
|
|
int visibleTrackCount = 0;
|
2018-06-26 09:23:06 -05:00
|
|
|
int firstTrackAxisOffset = 0; // Account for first track having the y-axis labels and markers
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
2018-06-26 09:23:06 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( visibleTrackCount == 0 )
|
2018-06-26 09:23:06 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
firstTrackAxisOffset = static_cast<int>( m_trackPlots[tIdx]->plotLayout()->canvasRect().left() );
|
2018-06-26 09:23:06 -05:00
|
|
|
}
|
2019-09-06 06:17:36 -05:00
|
|
|
else if ( visibleTrackCount == 1 )
|
2018-07-03 05:54:51 -05:00
|
|
|
{
|
|
|
|
// The others axes also have markers, and so we need to subtract for this to get the shift due to labels and title
|
2019-09-06 06:17:36 -05:00
|
|
|
int otherTrackAxisOffset = static_cast<int>( m_trackPlots[tIdx]->plotLayout()->canvasRect().left() );
|
2018-07-03 05:54:51 -05:00
|
|
|
firstTrackAxisOffset -= otherTrackAxisOffset;
|
|
|
|
}
|
2019-09-06 06:17:36 -05:00
|
|
|
++visibleTrackCount;
|
2018-06-26 09:23:06 -05:00
|
|
|
}
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int scrollBarWidth = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_scrollBar->isVisible() ) scrollBarWidth = m_scrollBar->sizeHint().width();
|
|
|
|
|
2018-06-26 04:18:24 -05:00
|
|
|
std::map<int, int> trackWidths;
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( visibleTrackCount )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
int totalTrackWidth = ( frameWidth - firstTrackAxisOffset - scrollBarWidth );
|
|
|
|
int trackWidthExtra = ( frameWidth - firstTrackAxisOffset - scrollBarWidth ) % visibleTrackCount;
|
2018-06-26 04:18:24 -05:00
|
|
|
|
|
|
|
int totalWidthWeights = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
|
|
|
totalWidthWeights += m_trackPlots[tIdx]->widthScaleFactor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 09:23:06 -05:00
|
|
|
bool firstVisible = true;
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
int realTrackWidth = ( totalTrackWidth * m_trackPlots[tIdx]->widthScaleFactor() ) / totalWidthWeights;
|
|
|
|
|
|
|
|
if ( firstVisible )
|
2018-06-26 09:23:06 -05:00
|
|
|
{
|
|
|
|
realTrackWidth += firstTrackAxisOffset;
|
|
|
|
firstVisible = false;
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( trackWidthExtra > 0 )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
|
|
|
realTrackWidth += 1;
|
|
|
|
--trackWidthExtra;
|
|
|
|
}
|
|
|
|
|
|
|
|
trackWidths[tIdx] = realTrackWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return trackWidths;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2018-06-26 04:18:24 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::placeChildWidgets( int frameHeight, int frameWidth )
|
2018-06-26 04:18:24 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
CVF_ASSERT( m_legends.size() == m_trackPlots.size() );
|
2018-06-26 04:18:24 -05:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
positionTitle( frameWidth );
|
2018-06-26 08:35:13 -05:00
|
|
|
|
2018-07-09 01:54:59 -05:00
|
|
|
const int trackPadding = 2;
|
2018-06-26 04:18:24 -05:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
std::map<int, int> trackWidths = calculateTrackWidthsToMatchFrame( frameWidth );
|
|
|
|
size_t visibleTrackCount = trackWidths.size();
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
int maxLegendHeight = 0;
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_plotDefinition && m_plotDefinition->areTrackLegendsVisible() )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2018-06-26 04:18:24 -05:00
|
|
|
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
int legendHeight = m_legends[tIdx]->heightForWidth( trackWidths[tIdx] - 2 * trackPadding );
|
2017-02-13 01:40:27 -06:00
|
|
|
if ( legendHeight > maxLegendHeight ) maxLegendHeight = legendHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 03:24:29 -05:00
|
|
|
int titleHeight = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_plotTitle && m_plotTitle->isVisible() )
|
2018-06-26 03:24:29 -05:00
|
|
|
{
|
2019-09-06 05:16:41 -05:00
|
|
|
titleHeight = m_plotTitle->height() + 2;
|
2018-06-26 03:24:29 -05:00
|
|
|
}
|
|
|
|
|
2018-06-27 04:42:51 -05:00
|
|
|
int trackHeight = frameHeight - maxLegendHeight - titleHeight;
|
2019-09-06 06:17:36 -05:00
|
|
|
int trackX = 0;
|
2017-02-13 01:40:27 -06:00
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( visibleTrackCount )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2018-06-26 04:01:21 -05:00
|
|
|
int maxCanvasOffset = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
|
2018-06-26 04:01:21 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
2018-06-26 04:01:21 -05:00
|
|
|
{
|
|
|
|
// Hack to align QWT plots. See below.
|
|
|
|
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
|
2019-09-06 06:17:36 -05:00
|
|
|
maxCanvasOffset = std::max( maxCanvasOffset, static_cast<int>( canvasRect.top() ) );
|
2018-06-26 04:01:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2018-06-26 04:01:21 -05:00
|
|
|
int adjustedVerticalPosition = titleHeight + maxLegendHeight + 10;
|
2019-09-06 06:17:36 -05:00
|
|
|
int adjustedTrackHeight = trackHeight;
|
2018-06-26 04:01:21 -05:00
|
|
|
{
|
|
|
|
// Hack to align QWT plots which doesn't have an x-axis with the other tracks.
|
|
|
|
// Since they are missing the axis, QWT will shift them upwards.
|
|
|
|
// So we shift the plot downwards and resize to match the others.
|
|
|
|
// TODO: Look into subclassing QwtPlotLayout instead.
|
2019-09-06 06:17:36 -05:00
|
|
|
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
|
|
|
|
int myCanvasOffset = static_cast<int>( canvasRect.top() );
|
|
|
|
int myMargins = m_trackPlots[tIdx]->plotLayout()->canvasMargin( QwtPlot::xTop );
|
|
|
|
int canvasShift = std::max( 0, maxCanvasOffset - myCanvasOffset );
|
2018-06-26 04:01:21 -05:00
|
|
|
adjustedVerticalPosition += canvasShift - myMargins;
|
|
|
|
adjustedTrackHeight -= canvasShift;
|
|
|
|
}
|
2018-06-26 04:18:24 -05:00
|
|
|
|
|
|
|
int realTrackWidth = trackWidths[tIdx];
|
2019-09-06 06:17:36 -05:00
|
|
|
m_legends[tIdx]->setGeometry( trackX + trackPadding,
|
|
|
|
titleHeight,
|
|
|
|
realTrackWidth - 2 * trackPadding,
|
|
|
|
maxLegendHeight );
|
|
|
|
m_trackPlots[tIdx]->setGeometry( trackX + trackPadding,
|
|
|
|
adjustedVerticalPosition,
|
|
|
|
realTrackWidth - 2 * trackPadding,
|
|
|
|
adjustedTrackHeight );
|
2017-02-13 01:40:27 -06:00
|
|
|
|
|
|
|
trackX += realTrackWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_scrollBar->isVisible() )
|
2018-06-26 03:24:29 -05:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scrollBar->setGeometry( trackX, titleHeight + maxLegendHeight, m_scrollBar->sizeHint().width(), trackHeight );
|
2018-06-26 03:24:29 -05:00
|
|
|
}
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-06-26 08:35:13 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::positionTitle( int frameWidth )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_plotDefinition && m_plotDefinition->isPlotTitleVisible() )
|
2018-06-26 03:24:29 -05:00
|
|
|
{
|
2018-06-26 08:35:13 -05:00
|
|
|
int textWidth = m_plotTitle->sizeHint().width();
|
2019-09-06 06:17:36 -05:00
|
|
|
m_plotTitle->setGeometry( frameWidth / 2 - textWidth / 2, 0, textWidth, m_plotTitle->sizeHint().height() );
|
2018-06-26 03:24:29 -05:00
|
|
|
m_plotTitle->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_plotTitle->hide();
|
|
|
|
}
|
2018-06-26 08:35:13 -05:00
|
|
|
}
|
2018-06-26 03:24:29 -05:00
|
|
|
|
2018-06-26 08:35:13 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2018-06-26 08:35:13 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuWellLogPlot::updateChildrenLayout()
|
2019-09-06 06:17:36 -05:00
|
|
|
{
|
|
|
|
int trackCount = m_trackPlots.size();
|
2018-06-26 03:38:44 -05:00
|
|
|
int numTracksAlreadyShown = 0;
|
2019-09-06 06:17:36 -05:00
|
|
|
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_trackPlots[tIdx]->isVisible() )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2018-06-26 04:38:07 -05:00
|
|
|
int legendColumns = 1;
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( m_plotDefinition->areTrackLegendsHorizontal() )
|
2018-06-26 04:38:07 -05:00
|
|
|
{
|
|
|
|
legendColumns = 0; // unlimited
|
|
|
|
}
|
2019-09-06 06:17:36 -05:00
|
|
|
m_legends[tIdx]->setMaxColumns( legendColumns );
|
2018-06-26 04:38:07 -05:00
|
|
|
m_legends[tIdx]->show();
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
m_trackPlots[tIdx]->enableDepthAxisLabelsAndTitle( numTracksAlreadyShown == 0 );
|
2018-06-26 04:38:07 -05:00
|
|
|
numTracksAlreadyShown++;
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_legends[tIdx]->hide();
|
2018-06-26 04:18:24 -05:00
|
|
|
}
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
placeChildWidgets( this->height(), this->width() );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::showEvent( QShowEvent* )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
updateChildrenLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
///
|
2017-02-13 01:40:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 06:17:36 -05:00
|
|
|
void RiuWellLogPlot::changeEvent( QEvent* event )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( event->type() == QEvent::WindowStateChange )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
|
|
|
updateChildrenLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Schedule an update of the widget positions
|
|
|
|
/// Will happen just a bit after the event loop is entered
|
|
|
|
/// Used to delay the positioning to after the legend widgets is actually updated.
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuWellLogPlot::scheduleUpdateChildrenLayout()
|
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( !m_scheduleUpdateChildrenLayoutTimer )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scheduleUpdateChildrenLayoutTimer = new QTimer( this );
|
|
|
|
connect( m_scheduleUpdateChildrenLayoutTimer, SIGNAL( timeout() ), this, SLOT( updateChildrenLayout() ) );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 06:17:36 -05:00
|
|
|
if ( !m_scheduleUpdateChildrenLayoutTimer->isActive() )
|
2017-02-13 01:40:27 -06:00
|
|
|
{
|
2019-09-06 06:17:36 -05:00
|
|
|
m_scheduleUpdateChildrenLayoutTimer->setSingleShot( true );
|
|
|
|
m_scheduleUpdateChildrenLayoutTimer->start( 100 );
|
2017-02-13 01:40:27 -06:00
|
|
|
}
|
|
|
|
}
|