Merge pull request #4686 from OPM/system-refactor-welllogplot

#4665 System refactor welllogplot
This commit is contained in:
Gaute Lindkvist
2019-09-10 08:26:32 +02:00
committed by GitHub
39 changed files with 544 additions and 1340 deletions

View File

@@ -58,8 +58,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuFemTimeHistoryResultAccessor.h
${CMAKE_CURRENT_LIST_DIR}/RiuEditPerforationCollectionWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuAdvancedSnapshotExportWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellAllocationPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellRftPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellPltPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuFlowCharacteristicsPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuNightchartsWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuMessagePanel.h
@@ -144,8 +142,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuFemTimeHistoryResultAccessor.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuEditPerforationCollectionWidget.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuAdvancedSnapshotExportWidget.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuWellAllocationPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuWellRftPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuWellPltPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuFlowCharacteristicsPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuNightchartsWidget.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuMessagePanel.cpp
@@ -210,8 +206,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuCvfOverlayItemWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuEditPerforationCollectionWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuAdvancedSnapshotExportWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellAllocationPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellRftPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellPltPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuFlowCharacteristicsPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuNightchartsWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuMessagePanel.h

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -21,11 +21,11 @@
#include "RiaApplication.h"
#include "RimContextCommandBuilder.h"
#include "RimTofAccumulatedPhaseFractionsPlot.h"
#include "RimTotalWellAllocationPlot.h"
#include "RimWellAllocationPlot.h"
#include "RimWellLogPlot.h"
#include "RimWellLogTrack.h"
#include "RimTofAccumulatedPhaseFractionsPlot.h"
#include "RiuContextMenuLauncher.h"
#include "RiuNightchartsWidget.h"
@@ -38,73 +38,76 @@
#include <QLabel>
#include <QMenu>
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RiuWellAllocationPlot::RiuWellAllocationPlot( RimWellAllocationPlot* plotDefinition, QWidget* parent )
: QFrame( parent )
, m_plotDefinition( plotDefinition )
RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefinition, QWidget* parent)
: QFrame(parent)
, m_plotDefinition(plotDefinition)
{
Q_ASSERT( m_plotDefinition );
Q_ASSERT(m_plotDefinition);
QVBoxLayout* mainLayout = new QVBoxLayout();
this->setLayout( mainLayout );
this->layout()->setMargin( 0 );
this->layout()->setSpacing( 2 );
this->setLayout(mainLayout);
this->layout()->setMargin(0);
this->layout()->setSpacing(2);
m_titleLabel = new QLabel( this );
new RiuPlotObjectPicker( m_titleLabel, m_plotDefinition->accumulatedWellFlowPlot() );
m_titleLabel = new QLabel(this);
new RiuPlotObjectPicker(m_titleLabel, m_plotDefinition->accumulatedWellFlowPlot());
QFont font = m_titleLabel->font();
font.setPointSize( 14 );
font.setBold( true );
m_titleLabel->setFont( font );
font.setPointSize(14);
font.setBold(true);
m_titleLabel->setFont(font);
// White background
QPalette pal = this->palette();
pal.setColor( QPalette::Background, Qt::white );
this->setAutoFillBackground( true );
this->setPalette( pal );
pal.setColor(QPalette::Background, Qt::white);
this->setAutoFillBackground(true);
this->setPalette(pal);
mainLayout->addWidget( m_titleLabel, 0, Qt::AlignCenter );
mainLayout->addWidget(m_titleLabel, 0, Qt::AlignCenter);
auto plotWidgetsLayout = new QHBoxLayout();
auto rightColumnLayout = new QVBoxLayout();
mainLayout->addLayout( plotWidgetsLayout );
plotWidgetsLayout->addLayout( rightColumnLayout );
m_legendWidget = new RiuNightchartsWidget( this );
new RiuPlotObjectPicker( m_legendWidget, m_plotDefinition->plotLegend() );
mainLayout->addLayout(plotWidgetsLayout);
plotWidgetsLayout->addLayout(rightColumnLayout);
m_legendWidget = new RiuNightchartsWidget(this);
new RiuPlotObjectPicker(m_legendWidget, m_plotDefinition->plotLegend());
caf::CmdFeatureMenuBuilder menuBuilder;
menuBuilder << "RicShowTotalAllocationDataFeature";
new RiuContextMenuLauncher( m_legendWidget, menuBuilder );
new RiuContextMenuLauncher(m_legendWidget, menuBuilder);
rightColumnLayout->addWidget( m_legendWidget );
m_legendWidget->showPie( false );
rightColumnLayout->addWidget(m_legendWidget);
m_legendWidget->showPie(false);
QWidget* totalFlowAllocationWidget = m_plotDefinition->totalWellFlowPlot()->createViewWidget( this );
new RiuPlotObjectPicker( totalFlowAllocationWidget, m_plotDefinition->totalWellFlowPlot() );
new RiuContextMenuLauncher( totalFlowAllocationWidget, menuBuilder );
QWidget* totalFlowAllocationWidget = m_plotDefinition->totalWellFlowPlot()->createViewWidget(this);
new RiuPlotObjectPicker(totalFlowAllocationWidget, m_plotDefinition->totalWellFlowPlot());
new RiuContextMenuLauncher(totalFlowAllocationWidget, menuBuilder);
rightColumnLayout->addWidget( totalFlowAllocationWidget, Qt::AlignTop );
rightColumnLayout->addWidget( m_plotDefinition->tofAccumulatedPhaseFractionsPlot()->createViewWidget( this ),
Qt::AlignTop );
rightColumnLayout->addWidget(totalFlowAllocationWidget, Qt::AlignTop);
rightColumnLayout->addWidget(m_plotDefinition->tofAccumulatedPhaseFractionsPlot()->createViewWidget(this), Qt::AlignTop);
rightColumnLayout->addStretch();
QWidget* wellFlowWidget = m_plotDefinition->accumulatedWellFlowPlot()->createPlotWidget();
plotWidgetsLayout->addWidget( wellFlowWidget );
plotWidgetsLayout->addWidget(wellFlowWidget);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RiuWellAllocationPlot::~RiuWellAllocationPlot() {}
RiuWellAllocationPlot::~RiuWellAllocationPlot()
{
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RimWellAllocationPlot* RiuWellAllocationPlot::ownerPlotDefinition()
{
@@ -112,7 +115,7 @@ RimWellAllocationPlot* RiuWellAllocationPlot::ownerPlotDefinition()
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuWellAllocationPlot::ownerViewWindow() const
{
@@ -120,89 +123,96 @@ RimViewWindow* RiuWellAllocationPlot::ownerViewWindow() const
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::showTitle( const QString& title )
void RiuWellAllocationPlot::showTitle(const QString& title)
{
m_titleLabel->show();
m_titleLabel->setText( title );
m_titleLabel->setText(title);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::hideTitle()
{
m_titleLabel->hide();
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::showLegend( bool doShow )
void RiuWellAllocationPlot::showLegend(bool doShow)
{
if ( doShow )
if (doShow)
m_legendWidget->show();
else
m_legendWidget->hide();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::addLegendItem( const QString& name, const cvf::Color3f& color, float value )
{
QColor sliceColor( color.rByte(), color.gByte(), color.bByte() );
m_legendWidget->addItem( name, sliceColor, value );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::addLegendItem(const QString& name, const cvf::Color3f& color, float value)
{
QColor sliceColor(color.rByte(), color.gByte(), color.bByte());
m_legendWidget->addItem(name, sliceColor, value);
m_legendWidget->updateGeometry();
m_legendWidget->update();
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::clearLegend()
{
m_legendWidget->clear();
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellAllocationPlot::minimumSizeHint() const
{
return QSize( 0, 100 );
return QSize(0, 100);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::contextMenuEvent( QContextMenuEvent* event )
void RiuWellAllocationPlot::contextMenuEvent(QContextMenuEvent* event)
{
QMenu menu;
QMenu menu;
caf::CmdFeatureMenuBuilder menuBuilder;
menuBuilder << "RicShowContributingWellsFromPlotFeature";
menuBuilder.appendToMenu( &menu );
menuBuilder.appendToMenu(&menu);
if ( menu.actions().size() > 0 )
if (menu.actions().size() > 0)
{
menu.exec( event->globalPos() );
menu.exec(event->globalPos());
}
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellAllocationPlot::sizeHint() const
{
return QSize( 0, 0 );
return QSize(0, 0);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::setDefaults() {}
void RiuWellAllocationPlot::setDefaults()
{
}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -22,8 +22,8 @@
#include "cafPdmPointer.h"
#include <QFrame>
#include <QPointer>
#include <QFrame>
#include "RiuInterfaceToViewWindow.h"
@@ -32,9 +32,8 @@ class RiuNightchartsWidget;
class QLabel;
namespace cvf
{
class Color3f;
namespace cvf {
class Color3f;
}
//==================================================================================================
@@ -45,31 +44,31 @@ class Color3f;
class RiuWellAllocationPlot : public QFrame, public RiuInterfaceToViewWindow
{
Q_OBJECT;
public:
RiuWellAllocationPlot( RimWellAllocationPlot* plotDefinition, QWidget* parent = nullptr );
RiuWellAllocationPlot(RimWellAllocationPlot* plotDefinition, QWidget* parent = nullptr);
~RiuWellAllocationPlot() override;
RimWellAllocationPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
RimWellAllocationPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
void showTitle(const QString& title);
void hideTitle();
void showLegend(bool doShow);
void addLegendItem(const QString& name, const cvf::Color3f& color, float value);
void clearLegend();
void showTitle( const QString& title );
void hideTitle();
void showLegend( bool doShow );
void addLegendItem( const QString& name, const cvf::Color3f& color, float value );
void clearLegend();
protected:
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
void contextMenuEvent( QContextMenuEvent* ) override;
void contextMenuEvent(QContextMenuEvent *) override;
private:
void setDefaults();
void setDefaults();
private:
caf::PdmPointer<RimWellAllocationPlot> m_plotDefinition;
QPointer<RiuNightchartsWidget> m_legendWidget;
QPointer<QLabel> m_titleLabel;
QPointer<RiuNightchartsWidget> m_legendWidget;
QPointer<QLabel> m_titleLabel;
};

View File

@@ -27,6 +27,7 @@
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "RiuPlotObjectPicker.h"
#include "RiuWellLogTrack.h"
#include "cafCmdFeatureMenuBuilder.h"
@@ -51,27 +52,46 @@
//--------------------------------------------------------------------------------------------------
RiuWellLogPlot::RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent )
: QWidget( parent )
, m_scheduleUpdateChildrenLayoutTimer( nullptr )
{
Q_ASSERT( plotDefinition );
m_plotDefinition = plotDefinition;
m_layout = new QVBoxLayout( this );
m_layout->setMargin( 0 );
m_layout->setSpacing( 2 );
m_plotTitle = createTitleLabel();
m_layout->addWidget( m_plotTitle );
m_plotLayout = new QHBoxLayout;
m_layout->addLayout( m_plotLayout );
m_plotFrame = new QFrame;
m_plotFrame->setVisible( true );
m_plotLayout->addWidget( m_plotFrame, 1 );
m_trackLayout = new QGridLayout( m_plotFrame );
m_trackLayout->setMargin( 0 );
m_trackLayout->setSpacing( 2 );
QPalette newPalette( palette() );
newPalette.setColor( QPalette::Background, Qt::white );
setPalette( newPalette );
setAutoFillBackground( true );
m_plotTitle = new QLabel( "PLOT TITLE HERE", this );
QFont font = m_plotTitle->font();
font.setPointSize( 14 );
font.setBold( true );
m_plotTitle->setFont( font );
m_plotTitle->hide();
m_scrollBar = new QScrollBar( this );
m_scrollBarLayout = new QVBoxLayout;
m_scrollBarLayout->setContentsMargins( 0, 50, 0, 0 );
m_plotLayout->addLayout( m_scrollBarLayout );
m_scrollBar = new QScrollBar( nullptr );
m_scrollBar->setOrientation( Qt::Vertical );
m_scrollBar->setVisible( true );
m_scrollBarLayout->addWidget( m_scrollBar, 0 );
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
this->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
setFocusPolicy( Qt::StrongFocus );
@@ -103,11 +123,9 @@ void RiuWellLogPlot::addTrackPlot( RiuWellLogTrack* trackPlot )
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::insertTrackPlot( RiuWellLogTrack* trackPlot, size_t index )
{
trackPlot->setParent( this );
m_trackPlots.insert( static_cast<int>( index ), trackPlot );
QwtLegend* legend = new QwtLegend( this );
QwtLegend* legend = new QwtLegend( nullptr );
int legendColumns = 1;
if ( m_plotDefinition->areTrackLegendsHorizontal() )
{
@@ -124,9 +142,9 @@ void RiuWellLogPlot::insertTrackPlot( RiuWellLogTrack* trackPlot, size_t index )
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() ) );
m_trackLayout->addWidget( legend, 0, static_cast<int>( index ) );
m_trackLayout->addWidget( trackPlot, 1, static_cast<int>( index ) );
m_trackLayout->setRowStretch( 1, 1 );
if ( !m_plotDefinition->areTrackLegendsVisible() )
{
@@ -209,6 +227,68 @@ QSize RiuWellLogPlot::preferredSize() const
return QSize( std::max( titleWidth, sumTrackWidth ), titleHeight + maxTrackHeight );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::setTitleVisible( bool visible )
{
m_plotTitle->setVisible( visible );
this->updateChildrenLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::updateChildrenLayout()
{
int trackCount = m_trackPlots.size();
int numTracksAlreadyShown = 0;
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
{
if ( m_plotDefinition->areTrackLegendsVisible() && m_trackPlots[tIdx]->isVisible() )
{
int legendColumns = 1;
if ( m_plotDefinition->areTrackLegendsHorizontal() )
{
legendColumns = 0; // unlimited
}
m_legends[tIdx]->setMaxColumns( legendColumns );
m_legends[tIdx]->show();
m_trackPlots[tIdx]->enableDepthAxisLabelsAndTitle( numTracksAlreadyShown == 0 );
numTracksAlreadyShown++;
}
else
{
m_legends[tIdx]->hide();
}
RiuWellLogTrack* riuTrack = m_trackPlots[tIdx];
m_trackLayout->setColumnStretch( tIdx, riuTrack->widthScaleFactor() );
}
alignCanvasTops();
this->update();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::showEvent( QShowEvent* )
{
updateChildrenLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::changeEvent( QEvent* event )
{
if ( event->type() == QEvent::WindowStateChange )
{
updateChildrenLayout();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -230,6 +310,14 @@ void RiuWellLogPlot::contextMenuEvent( QContextMenuEvent* event )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::keyPressEvent( QKeyEvent* keyEvent )
{
m_plotDefinition->handleKeyPressEvent( keyEvent );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -241,9 +329,16 @@ QSize RiuWellLogPlot::sizeHint() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::keyPressEvent( QKeyEvent* keyEvent )
QLabel* RiuWellLogPlot::createTitleLabel() const
{
m_plotDefinition->handleKeyPressEvent( keyEvent );
QLabel* plotTitle = new QLabel( "PLOT TITLE HERE", nullptr );
QFont font = plotTitle->font();
font.setPointSize( 14 );
font.setBold( true );
plotTitle->setFont( font );
plotTitle->setVisible( m_plotDefinition->isPlotTitleVisible() );
plotTitle->setAlignment( Qt::AlignHCenter );
return plotTitle;
}
//--------------------------------------------------------------------------------------------------
@@ -263,12 +358,56 @@ void RiuWellLogPlot::updateScrollBar( double minDepth, double maxDepth )
m_scrollBar->setRange( (int)availableMinDepth, (int)( ( availableMaxDepth - visibleDepth ) ) );
m_scrollBar->setPageStep( (int)visibleDepth );
m_scrollBar->setValue( (int)minDepth );
m_scrollBar->setVisible( true );
}
m_scrollBar->blockSignals( false );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::alignCanvasTops()
{
CVF_ASSERT( m_legends.size() == m_trackPlots.size() );
int maxCanvasOffset = 0;
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
// Hack to align QWT plots. See below.
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
int canvasMargins = m_trackPlots[tIdx]->plotLayout()->canvasMargin( QwtPlot::xTop );
maxCanvasOffset = std::max( maxCanvasOffset, static_cast<int>( canvasRect.top() + canvasMargins ) );
}
}
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
// 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.
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
int canvasMargins = m_trackPlots[tIdx]->plotLayout()->canvasMargin( QwtPlot::xTop );
int myCanvasOffset = static_cast<int>( canvasRect.top() ) + canvasMargins;
int canvasShift = std::max( 0, maxCanvasOffset - myCanvasOffset );
QMargins margins = m_trackPlots[tIdx]->contentsMargins();
margins.setTop( margins.top() + canvasShift );
m_trackPlots[tIdx]->setContentsMargins( margins );
}
}
if ( m_trackLayout->columnCount() > 0 && m_trackLayout->rowCount() > 0 )
{
int legendHeight = m_trackLayout->cellRect( 0, 0 ).height();
m_scrollBarLayout->setContentsMargins( 0, legendHeight, 0, 0 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -298,265 +437,3 @@ RimViewWindow* RiuWellLogPlot::ownerViewWindow() const
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::resizeEvent( QResizeEvent* event )
{
int height = event->size().height();
int width = event->size().width();
placeChildWidgets( height, width );
QWidget::resizeEvent( event );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<int, int> RiuWellLogPlot::calculateTrackWidthsToMatchFrame( int frameWidth ) const
{
int trackCount = m_trackPlots.size();
int visibleTrackCount = 0;
int firstTrackAxisOffset = 0; // Account for first track having the y-axis labels and markers
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
if ( visibleTrackCount == 0 )
{
firstTrackAxisOffset = static_cast<int>( m_trackPlots[tIdx]->plotLayout()->canvasRect().left() );
}
else if ( visibleTrackCount == 1 )
{
// The others axes also have markers, and so we need to subtract for this to get the shift due to labels and title
int otherTrackAxisOffset = static_cast<int>( m_trackPlots[tIdx]->plotLayout()->canvasRect().left() );
firstTrackAxisOffset -= otherTrackAxisOffset;
}
++visibleTrackCount;
}
}
int scrollBarWidth = 0;
if ( m_scrollBar->isVisible() ) scrollBarWidth = m_scrollBar->sizeHint().width();
std::map<int, int> trackWidths;
if ( visibleTrackCount )
{
int totalTrackWidth = ( frameWidth - firstTrackAxisOffset - scrollBarWidth );
int trackWidthExtra = ( frameWidth - firstTrackAxisOffset - scrollBarWidth ) % visibleTrackCount;
int totalWidthWeights = 0;
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
totalWidthWeights += m_trackPlots[tIdx]->widthScaleFactor();
}
}
bool firstVisible = true;
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
int realTrackWidth = ( totalTrackWidth * m_trackPlots[tIdx]->widthScaleFactor() ) / totalWidthWeights;
if ( firstVisible )
{
realTrackWidth += firstTrackAxisOffset;
firstVisible = false;
}
if ( trackWidthExtra > 0 )
{
realTrackWidth += 1;
--trackWidthExtra;
}
trackWidths[tIdx] = realTrackWidth;
}
}
}
return trackWidths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::placeChildWidgets( int frameHeight, int frameWidth )
{
CVF_ASSERT( m_legends.size() == m_trackPlots.size() );
positionTitle( frameWidth );
const int trackPadding = 2;
std::map<int, int> trackWidths = calculateTrackWidthsToMatchFrame( frameWidth );
size_t visibleTrackCount = trackWidths.size();
int maxLegendHeight = 0;
if ( m_plotDefinition && m_plotDefinition->areTrackLegendsVisible() )
{
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
int legendHeight = m_legends[tIdx]->heightForWidth( trackWidths[tIdx] - 2 * trackPadding );
if ( legendHeight > maxLegendHeight ) maxLegendHeight = legendHeight;
}
}
}
int titleHeight = 0;
if ( m_plotTitle && m_plotTitle->isVisible() )
{
titleHeight = m_plotTitle->height() + 10;
}
int trackHeight = frameHeight - maxLegendHeight - titleHeight;
int trackX = 0;
if ( visibleTrackCount )
{
int maxCanvasOffset = 0;
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
// Hack to align QWT plots. See below.
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
maxCanvasOffset = std::max( maxCanvasOffset, static_cast<int>( canvasRect.top() ) );
}
}
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
int adjustedVerticalPosition = titleHeight + maxLegendHeight + 10;
int adjustedTrackHeight = trackHeight;
{
// 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.
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 );
adjustedVerticalPosition += canvasShift - myMargins;
adjustedTrackHeight -= canvasShift;
}
int realTrackWidth = trackWidths[tIdx];
m_legends[tIdx]->setGeometry( trackX + trackPadding,
titleHeight,
realTrackWidth - 2 * trackPadding,
maxLegendHeight );
m_trackPlots[tIdx]->setGeometry( trackX + trackPadding,
adjustedVerticalPosition,
realTrackWidth - 2 * trackPadding,
adjustedTrackHeight );
trackX += realTrackWidth;
}
}
}
if ( m_scrollBar->isVisible() )
{
m_scrollBar->setGeometry( trackX, titleHeight + maxLegendHeight, m_scrollBar->sizeHint().width(), trackHeight );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::positionTitle( int frameWidth )
{
if ( m_plotDefinition && m_plotDefinition->isPlotTitleVisible() )
{
int textWidth = m_plotTitle->sizeHint().width();
m_plotTitle->setGeometry( frameWidth / 2 - textWidth / 2, 0, textWidth, m_plotTitle->sizeHint().height() );
m_plotTitle->show();
}
else
{
m_plotTitle->hide();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::updateChildrenLayout()
{
int trackCount = m_trackPlots.size();
int numTracksAlreadyShown = 0;
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
int legendColumns = 1;
if ( m_plotDefinition->areTrackLegendsHorizontal() )
{
legendColumns = 0; // unlimited
}
m_legends[tIdx]->setMaxColumns( legendColumns );
m_legends[tIdx]->show();
m_trackPlots[tIdx]->enableDepthAxisLabelsAndTitle( numTracksAlreadyShown == 0 );
numTracksAlreadyShown++;
}
else
{
m_legends[tIdx]->hide();
}
}
placeChildWidgets( this->height(), this->width() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::showEvent( QShowEvent* )
{
updateChildrenLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::changeEvent( QEvent* event )
{
if ( event->type() == QEvent::WindowStateChange )
{
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()
{
if ( !m_scheduleUpdateChildrenLayoutTimer )
{
m_scheduleUpdateChildrenLayoutTimer = new QTimer( this );
connect( m_scheduleUpdateChildrenLayoutTimer, SIGNAL( timeout() ), this, SLOT( updateChildrenLayout() ) );
}
if ( !m_scheduleUpdateChildrenLayoutTimer->isActive() )
{
m_scheduleUpdateChildrenLayoutTimer->setSingleShot( true );
m_scheduleUpdateChildrenLayoutTimer->start( 100 );
}
}

View File

@@ -23,6 +23,9 @@
#include "cafPdmPointer.h"
#include <QFrame>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QList>
#include <QPointer>
#include <QWidget>
@@ -48,6 +51,7 @@ class RiuWellLogPlot : public QWidget, public RiuInterfaceToViewWindow
public:
RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent = nullptr );
~RiuWellLogPlot() override;
RimWellLogPlot* ownerPlotDefinition();
@@ -60,33 +64,38 @@ public:
void setDepthZoomAndReplot( double minDepth, double maxDepth );
void setPlotTitle( const QString& plotTitle );
virtual QSize preferredSize() const;
void setTitleVisible( bool visible );
public slots:
void updateChildrenLayout();
protected:
void resizeEvent( QResizeEvent* event ) override;
void showEvent( QShowEvent* ) override;
void changeEvent( QEvent* ) override;
void contextMenuEvent( QContextMenuEvent* ) override;
QSize sizeHint() const override;
void showEvent( QShowEvent* ) override;
void changeEvent( QEvent* event ) override;
void contextMenuEvent( QContextMenuEvent* ) override;
void keyPressEvent( QKeyEvent* keyEvent ) override;
QSize sizeHint() const override;
QLabel* createTitleLabel() const;
private:
void updateScrollBar( double minDepth, double maxDepth );
std::map<int, int> calculateTrackWidthsToMatchFrame( int frameWidth ) const;
void placeChildWidgets( int frameHeight, int frameWidth );
void positionTitle( int frameWidth );
void updateScrollBar( double minDepth, double maxDepth );
void alignCanvasTops();
private slots:
void slotSetMinDepth( int value );
void scheduleUpdateChildrenLayout();
private:
QLabel* m_plotTitle;
protected:
QPointer<QVBoxLayout> m_layout;
QPointer<QHBoxLayout> m_plotLayout;
QPointer<QFrame> m_plotFrame;
QPointer<QGridLayout> m_trackLayout;
QPointer<QLabel> m_plotTitle;
QPointer<QVBoxLayout> m_scrollBarLayout;
QScrollBar* m_scrollBar;
QList<QPointer<QwtLegend>> m_legends;
QList<QPointer<RiuWellLogTrack>> m_trackPlots;
caf::PdmPointer<RimWellLogPlot> m_plotDefinition;
QTimer* m_scheduleUpdateChildrenLayoutTimer;
};

View File

@@ -1,146 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 "RiuWellPltPlot.h"
#include "RiaApplication.h"
#include "RimContextCommandBuilder.h"
#include "RimTofAccumulatedPhaseFractionsPlot.h"
#include "RimTotalWellAllocationPlot.h"
#include "RimWellLogPlot.h"
#include "RimWellLogTrack.h"
#include "RimWellPltPlot.h"
#include "RiuContextMenuLauncher.h"
#include "RiuNightchartsWidget.h"
#include "RiuPlotObjectPicker.h"
#include "cvfColor3.h"
#include <QBoxLayout>
#include <QContextMenuEvent>
#include <QLabel>
#include <QMenu>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPltPlot::RiuWellPltPlot( RimWellPltPlot* plotDefinition, QWidget* parent )
: QFrame( parent )
, m_plotDefinition( plotDefinition )
{
Q_ASSERT( m_plotDefinition );
QVBoxLayout* mainLayout = new QVBoxLayout();
this->setLayout( mainLayout );
this->layout()->setMargin( 0 );
this->layout()->setSpacing( 2 );
m_titleLabel = new QLabel( this );
new RiuPlotObjectPicker( m_titleLabel, m_plotDefinition->wellLogPlot() );
QFont font = m_titleLabel->font();
font.setPointSize( 14 );
font.setBold( true );
m_titleLabel->setFont( font );
// White background
QPalette pal = this->palette();
pal.setColor( QPalette::Background, Qt::white );
this->setAutoFillBackground( true );
this->setPalette( pal );
mainLayout->addWidget( m_titleLabel, 0, Qt::AlignCenter );
auto plotWidgetsLayout = new QHBoxLayout();
auto rightColumnLayout = new QVBoxLayout();
mainLayout->addLayout( plotWidgetsLayout );
plotWidgetsLayout->addLayout( rightColumnLayout );
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createPlotWidget();
plotWidgetsLayout->addWidget( wellFlowWidget );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPltPlot::~RiuWellPltPlot() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPltPlot* RiuWellPltPlot::ownerPlotDefinition()
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuWellPltPlot::ownerViewWindow() const
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellPltPlot::showTitle( const QString& title )
{
m_titleLabel->show();
m_titleLabel->setText( title );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellPltPlot::hideTitle()
{
m_titleLabel->hide();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellPltPlot::minimumSizeHint() const
{
return QSize( 0, 100 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellPltPlot::contextMenuEvent( QContextMenuEvent* event ) {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellPltPlot::sizeHint() const
{
return QSize( 0, 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellPltPlot::setDefaults() {}

View File

@@ -1,71 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "qwt_plot.h"
#include "cafPdmPointer.h"
#include <QFrame>
#include <QPointer>
#include "RiuInterfaceToViewWindow.h"
class RimWellPltPlot;
class RiuNightchartsWidget;
class QLabel;
namespace cvf
{
class Color3f;
}
//==================================================================================================
//
//
//
//==================================================================================================
class RiuWellPltPlot : public QFrame, public RiuInterfaceToViewWindow
{
Q_OBJECT;
public:
RiuWellPltPlot( RimWellPltPlot* plotDefinition, QWidget* parent = nullptr );
~RiuWellPltPlot() override;
RimWellPltPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
void showTitle( const QString& title );
void hideTitle();
protected:
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
void contextMenuEvent( QContextMenuEvent* ) override;
private:
void setDefaults();
private:
caf::PdmPointer<RimWellPltPlot> m_plotDefinition;
QPointer<QLabel> m_titleLabel;
};

View File

@@ -1,146 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 "RiuWellRftPlot.h"
#include "RiaApplication.h"
#include "RimContextCommandBuilder.h"
#include "RimTofAccumulatedPhaseFractionsPlot.h"
#include "RimTotalWellAllocationPlot.h"
#include "RimWellLogPlot.h"
#include "RimWellLogTrack.h"
#include "RimWellRftPlot.h"
#include "RiuContextMenuLauncher.h"
#include "RiuNightchartsWidget.h"
#include "RiuPlotObjectPicker.h"
#include "cvfColor3.h"
#include <QBoxLayout>
#include <QContextMenuEvent>
#include <QLabel>
#include <QMenu>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellRftPlot::RiuWellRftPlot( RimWellRftPlot* plotDefinition, QWidget* parent )
: QFrame( parent )
, m_plotDefinition( plotDefinition )
{
Q_ASSERT( m_plotDefinition );
QVBoxLayout* mainLayout = new QVBoxLayout();
this->setLayout( mainLayout );
this->layout()->setMargin( 0 );
this->layout()->setSpacing( 2 );
m_titleLabel = new QLabel( this );
new RiuPlotObjectPicker( m_titleLabel, m_plotDefinition->wellLogPlot() );
QFont font = m_titleLabel->font();
font.setPointSize( 14 );
font.setBold( true );
m_titleLabel->setFont( font );
// White background
QPalette pal = this->palette();
pal.setColor( QPalette::Background, Qt::white );
this->setAutoFillBackground( true );
this->setPalette( pal );
mainLayout->addWidget( m_titleLabel, 0, Qt::AlignCenter );
auto plotWidgetsLayout = new QHBoxLayout();
auto rightColumnLayout = new QVBoxLayout();
mainLayout->addLayout( plotWidgetsLayout );
plotWidgetsLayout->addLayout( rightColumnLayout );
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createPlotWidget();
plotWidgetsLayout->addWidget( wellFlowWidget );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellRftPlot::~RiuWellRftPlot() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellRftPlot* RiuWellRftPlot::ownerPlotDefinition()
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuWellRftPlot::ownerViewWindow() const
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellRftPlot::showTitle( const QString& title )
{
m_titleLabel->show();
m_titleLabel->setText( title );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellRftPlot::hideTitle()
{
m_titleLabel->hide();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellRftPlot::minimumSizeHint() const
{
return QSize( 0, 100 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellRftPlot::contextMenuEvent( QContextMenuEvent* event ) {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellRftPlot::sizeHint() const
{
return QSize( 0, 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellRftPlot::setDefaults() {}

View File

@@ -1,71 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "qwt_plot.h"
#include "cafPdmPointer.h"
#include <QFrame>
#include <QPointer>
#include "RiuInterfaceToViewWindow.h"
class RimWellRftPlot;
class RiuNightchartsWidget;
class QLabel;
namespace cvf
{
class Color3f;
}
//==================================================================================================
//
//
//
//==================================================================================================
class RiuWellRftPlot : public QFrame, public RiuInterfaceToViewWindow
{
Q_OBJECT;
public:
RiuWellRftPlot( RimWellRftPlot* plotDefinition, QWidget* parent = nullptr );
~RiuWellRftPlot() override;
RimWellRftPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
void showTitle( const QString& title );
void hideTitle();
protected:
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
void contextMenuEvent( QContextMenuEvent* ) override;
private:
void setDefaults();
private:
caf::PdmPointer<RimWellRftPlot> m_plotDefinition;
QPointer<QLabel> m_titleLabel;
};