Regression test fixes (#9068)

* Make sure font size is updated correctly
* Hide empty sub titles
* Do not categorize as water cut if no curves are visible
* Propagate settings from single summary plot to summary multi plot
This commit is contained in:
Magne Sjaastad
2022-06-21 14:40:54 +02:00
committed by GitHub
parent b4e3586e2c
commit 8aaf98823a
11 changed files with 110 additions and 51 deletions

View File

@@ -37,6 +37,7 @@ RiuAbstractLegendFrame::RiuAbstractLegendFrame( QWidget* parent, const QString&
, m_title( title )
{
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
updateFontSize();
}
//--------------------------------------------------------------------------------------------------
@@ -69,7 +70,7 @@ QSize RiuAbstractLegendFrame::sizeHint() const
preferredWidth = std::max( preferredWidth, titleWidth );
preferredWidth = std::min( preferredWidth, 200 );
return QSize( preferredWidth, preferredHeight );
return { preferredWidth, preferredHeight };
}
//--------------------------------------------------------------------------------------------------
@@ -81,11 +82,21 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
layoutInfo( &layout );
QFontMetrics fontMetrics( this->font() );
QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft | Qt::TextWordWrap, m_title );
int preferredContentHeight = titleRect.height() + 2 * layout.lineSpacing + 1.0 * layout.lineSpacing;
int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom();
int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right();
int preferredHeight = 0;
int titleWidth = 0;
QStringList tokens = m_title.split( "\n" );
for ( const auto& s : tokens )
{
QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, s );
int preferredContentHeight = titleRect.height() + 2 * layout.lineSpacing + 1.0 * layout.lineSpacing;
int candidateHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom();
int candidateTitleWidth = titleRect.width() + layout.margins.left() + layout.margins.right();
preferredHeight = std::max( preferredHeight, candidateHeight );
titleWidth = std::max( titleWidth, candidateTitleWidth );
}
int firstTextWidth = fontMetrics.boundingRect( label( 0 ) ).width();
int lastTextWidth = fontMetrics.boundingRect( label( labelCount() - 1 ) ).width();
@@ -97,7 +108,7 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
preferredWidth = std::max( preferredWidth, titleWidth );
preferredWidth = std::min( preferredWidth, 400 );
return QSize( preferredWidth, preferredHeight );
return { preferredWidth, preferredHeight };
}
//--------------------------------------------------------------------------------------------------
@@ -105,9 +116,7 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
//--------------------------------------------------------------------------------------------------
void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRect )
{
QFont font = this->font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( RiaPreferences::current()->defaultPlotFontSize() ) );
this->setFont( font );
updateFontSize();
QColor textColor = RiuGuiTheme::getColorByVariableName( "textColor" );
@@ -135,7 +144,7 @@ void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRec
}
std::vector<std::pair<QRect, QString>> visibleTickLabels = visibleLabels( layout );
for ( auto tickLabel : visibleTickLabels )
for ( const auto& tickLabel : visibleTickLabels )
{
painter->save();
painter->translate( tickLabel.first.topLeft() );
@@ -154,8 +163,6 @@ void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRec
renderRect( painter, layout, i );
}
painter->drawRect( layout.colorBarRect );
// painter->drawLine( QPointF( layout.tickMidX, layout.tickYPixelPos->get( i ) ),
// QPointF( layout.tickMidX, layout.tickYPixelPos->get( i + 1 ) ) );
painter->restore();
}
@@ -187,7 +194,7 @@ std::vector<std::pair<QRect, QString>> RiuAbstractLegendFrame::visibleLabels( co
QString valueString = label( i );
lastRect = rect;
visibleTickLabels.push_back( { rect, valueString } );
visibleTickLabels.emplace_back( rect, valueString );
}
return visibleTickLabels;
}

View File

@@ -41,6 +41,16 @@ RiuAbstractOverlayContentFrame::~RiuAbstractOverlayContentFrame()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuAbstractOverlayContentFrame::updateFontSize()
{
QFont font = this->font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( RiaPreferences::current()->defaultPlotFontSize() ) );
this->setFont( font );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -52,9 +62,7 @@ RiuTextOverlayContentFrame::RiuTextOverlayContentFrame( QWidget* parent /*= null
m_textLabel = new QLabel;
layout->addWidget( m_textLabel );
QFont font = m_textLabel->font();
caf::FontTools::pointSizeToPixelSize( RiaPreferences::current()->defaultPlotFontSize() );
m_textLabel->setFont( font );
updateLabelFont();
}
//--------------------------------------------------------------------------------------------------
@@ -70,6 +78,8 @@ void RiuTextOverlayContentFrame::setText( const QString& text )
//--------------------------------------------------------------------------------------------------
void RiuTextOverlayContentFrame::renderTo( QPainter* painter, const QRect& targetRect )
{
updateLabelFont();
painter->save();
painter->translate( targetRect.topLeft() + QPoint( this->contentsMargins().left(), this->contentsMargins().top() ) );
painter->setFont( m_textLabel->font() );
@@ -81,3 +91,13 @@ void RiuTextOverlayContentFrame::renderTo( QPainter* painter, const QRect& targe
painter->restore();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuTextOverlayContentFrame::updateLabelFont()
{
QFont font = m_textLabel->font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( RiaPreferences::current()->defaultPlotFontSize() ) );
m_textLabel->setFont( font );
}

View File

@@ -31,6 +31,9 @@ public:
~RiuAbstractOverlayContentFrame() override;
virtual void renderTo( QPainter* painter, const QRect& targetRect ) = 0;
protected:
void updateFontSize();
};
class RiuTextOverlayContentFrame : public RiuAbstractOverlayContentFrame
@@ -42,6 +45,9 @@ public:
void setText( const QString& text );
void renderTo( QPainter* painter, const QRect& targetRect ) override;
private:
void updateLabelFont();
private:
QPointer<QLabel> m_textLabel;
};

View File

@@ -103,7 +103,8 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
auto summaryPlot = dynamic_cast<RimSummaryPlot*>( plotWidget->plotDefinition() );
if ( summaryPlot ) m_summaryMultiPlot->setLayoutInfo( summaryPlot, row, col );
subTitles[visibleIndex]->setVisible( m_showSubTitles );
bool isSubTitleVisible = m_showSubTitles && !subTitles[visibleIndex]->text().isEmpty();
subTitles[visibleIndex]->setVisible( isSubTitleVisible );
QFont subTitleFont = subTitles[visibleIndex]->font();
subTitleFont.setPixelSize( m_subTitleFontPixelSize );
subTitles[visibleIndex]->setFont( subTitleFont );

View File

@@ -31,8 +31,6 @@
#include <cmath>
//#include <mathml/qwt_mathml_text_engine.h>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -94,9 +92,7 @@ QSize RiuTextContentFrame::minimumSizeHint() const
//--------------------------------------------------------------------------------------------------
void RiuTextContentFrame::renderTo( QPainter* painter, const QRect& targetRect )
{
QFont font = this->font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( RiaPreferences::current()->defaultPlotFontSize() ) );
this->setFont( font );
updateFontSize();
QColor textColor = RiuGuiTheme::getColorByVariableName( "textColor" );
@@ -128,18 +124,6 @@ void RiuTextContentFrame::renderTo( QPainter* painter, const QRect& targetRect )
painter->translate( QPoint( layout.margins.left(), layout.margins.top() + layout.lineSpacing * 2 ) );
painter->setPen( QPen( textColor ) );
/*
QwtMathMLTextEngine textEngine = QwtMathMLTextEngine();
textEngine.draw( painter,
QRect( targetRect.left() + layout.margins.left(),
targetRect.top() + layout.margins.top() + layout.lineSpacing * 2,
targetRect.width() - layout.margins.left() - layout.margins.right(),
targetRect.height() - layout.margins.top() - layout.margins.bottom() -
layout.margins.top() + layout.lineSpacing * 2 ),
Qt::AlignLeft,
m_text );
*/
QTextDocument td;
td.setDocumentMargin( 0.0 );
td.setDefaultFont( this->font() );