Better minimum width for well log tracks (#4824)

* Better minimum width for well log tracks

* Fix alignment of scrollbar in Well log plots
This commit is contained in:
Gaute Lindkvist 2019-10-07 08:32:34 +02:00 committed by GitHub
parent 3d3ad421dd
commit 4a4653a0df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 20 deletions

View File

@ -1493,6 +1493,7 @@ void RimWellLogTrack::initAfterRead()
if ( m_showFormations_OBSOLETE() && m_regionAnnotationType() == RiuPlotAnnotationTool::NO_ANNOTATIONS )
{
m_regionAnnotationType = RiuPlotAnnotationTool::FORMATION_ANNOTATIONS;
m_regionAnnotationDisplay = RiuPlotAnnotationTool::DARK_LINES;
}
}

View File

@ -82,14 +82,10 @@ RiuWellLogPlot::RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent
setAutoFillBackground( true );
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 = new QVBoxLayout;
m_scrollBarLayout->addWidget( m_scrollBar, 0 );
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
@ -223,8 +219,8 @@ void RiuWellLogPlot::setTitleVisible( bool visible )
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::updateChildrenLayout()
{
reinsertTracks();
alignCanvasTops();
reinsertTracksAndScrollbar();
alignCanvasTopsAndScrollbar();
}
//--------------------------------------------------------------------------------------------------
@ -287,6 +283,27 @@ void RiuWellLogPlot::resizeEvent( QResizeEvent* event )
updateChildrenLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::showEvent( QShowEvent* event )
{
QWidget::showEvent( event );
updateChildrenLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::changeEvent( QEvent* event )
{
QWidget::changeEvent( event );
if ( event->type() == QEvent::WindowStateChange )
{
updateChildrenLayout();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -312,7 +329,7 @@ void RiuWellLogPlot::updateScrollBar( double minDepth, double maxDepth )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::alignCanvasTops()
void RiuWellLogPlot::alignCanvasTopsAndScrollbar()
{
CVF_ASSERT( m_legends.size() == m_trackPlots.size() );
@ -333,12 +350,13 @@ void RiuWellLogPlot::alignCanvasTops()
m_trackPlots[tIdx]->axisScaleDraw( QwtPlot::xTop )->setMinimumExtent( maxExtent );
}
}
m_scrollBarLayout->setContentsMargins( 0, maxExtent, 0, 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::reinsertTracks()
void RiuWellLogPlot::reinsertTracksAndScrollbar()
{
clearTrackLayout();
@ -347,8 +365,8 @@ void RiuWellLogPlot::reinsertTracks()
{
if ( m_trackPlots[tIdx]->isRimTrackVisible() )
{
m_trackLayout->addWidget( m_legends[tIdx], 0, static_cast<int>( visibleIndex ) );
m_trackLayout->addWidget( m_trackPlots[tIdx], 1, static_cast<int>( visibleIndex ) );
m_trackLayout->addWidget( m_legends[tIdx], 0, visibleIndex );
m_trackLayout->addWidget( m_trackPlots[tIdx], 1, visibleIndex );
if ( m_plotDefinition->areTrackLegendsVisible() )
{
@ -358,7 +376,6 @@ void RiuWellLogPlot::reinsertTracks()
legendColumns = 0; // unlimited
}
m_legends[tIdx]->setMaxColumns( legendColumns );
m_trackPlots[tIdx]->updateLegend();
int minimumHeight = m_legends[tIdx]->heightForWidth( m_trackPlots[tIdx]->width() );
m_legends[tIdx]->setMinimumHeight( minimumHeight );
@ -388,6 +405,8 @@ void RiuWellLogPlot::reinsertTracks()
m_legends[tIdx]->hide();
}
}
m_trackLayout->addLayout( m_scrollBarLayout, 1, visibleIndex );
m_scrollBar->setVisible( visibleIndex > 0 );
}
//--------------------------------------------------------------------------------------------------

View File

@ -77,11 +77,13 @@ protected:
QLabel* createTitleLabel() const;
void resizeEvent( QResizeEvent* event ) override;
void showEvent( QShowEvent* event ) override;
void changeEvent( QEvent* ) override;
private:
void updateScrollBar( double minDepth, double maxDepth );
void alignCanvasTops();
void reinsertTracks();
void alignCanvasTopsAndScrollbar();
void reinsertTracksAndScrollbar();
void clearTrackLayout();
private slots:

View File

@ -87,9 +87,8 @@ void RiuWellLogTrack::setDefaults()
axisScaleEngine( QwtPlot::yLeft )->setAttribute( QwtScaleEngine::Floating, true );
setAxisScale( QwtPlot::yLeft, 1000, 0 );
setXRange( 0, 100 );
QFont font = axisFont( QwtPlot::xTop );
int lineHeight = QFontMetrics( font ).height() + axisScaleDraw( QwtPlot::xTop )->tickLength( QwtScaleDiv::MajorTick );
axisScaleDraw( QwtPlot::xTop )->setMinimumExtent( lineHeight );
axisScaleDraw( QwtPlot::xTop )->setMinimumExtent( axisExtent( QwtPlot::xTop ) );
setMinimumWidth( defaultMinimumWidth() );
}
//--------------------------------------------------------------------------------------------------
@ -119,6 +118,7 @@ void RiuWellLogTrack::setDepthTitle( const QString& title )
{
axisTitleY.setText( title );
setAxisTitle( QwtPlot::yLeft, axisTitleY );
setMinimumWidth( defaultMinimumWidth() + axisExtent( QwtPlot::yLeft ) );
}
}
@ -236,6 +236,14 @@ void RiuWellLogTrack::selectClosestCurve( const QPoint& pos )
RiuPlotMainWindowTools::selectAsCurrentItem( m_plotTrackDefinition );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiuWellLogTrack::defaultMinimumWidth()
{
return 80;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -374,3 +382,18 @@ double RiuWellLogTrack::getCurrentMinorTickInterval() const
return minorTicks.at( 1 ) - minorTicks.at( 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiuWellLogTrack::axisExtent( QwtPlot::Axis axis ) const
{
QFont tickLabelFont = axisFont( axis );
int lineExtent = static_cast<int>( std::ceil( axisScaleDraw( axis )->extent( tickLabelFont ) ) );
if ( !axisTitle( axis ).text().isEmpty() )
{
QFont titleFont = axisTitle( axis ).font();
lineExtent += QFontMetrics( titleFont ).height();
}
return lineExtent;
}

View File

@ -60,6 +60,7 @@ public:
void setAutoTickIntervalCounts( int maxMajorTickIntervalCount, int maxMinorTickIntervalCount );
double getCurrentMajorTickInterval() const;
double getCurrentMinorTickInterval() const;
int axisExtent( QwtPlot::Axis axis ) const;
protected:
bool eventFilter( QObject* watched, QEvent* event ) override;
@ -69,6 +70,7 @@ protected:
private:
void setDefaults();
void selectClosestCurve( const QPoint& pos );
static int defaultMinimumWidth();
private:
caf::PdmPointer<RimWellLogTrack> m_plotTrackDefinition;