mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Fix legends for ensemble plots
This commit is contained in:
parent
281fa24a2d
commit
0692ea28ad
@ -105,7 +105,7 @@ void RimWellRftEnsembleCurveSet::setColorMode( ColorMode mode )
|
||||
void RimWellRftEnsembleCurveSet::initializeLegend()
|
||||
{
|
||||
auto ensembleParam = m_ensemble->ensembleParameter( m_ensembleParameter );
|
||||
m_ensembleLegendConfig->setTitle( m_ensemble->name() + ":\n" + m_ensembleParameter );
|
||||
m_ensembleLegendConfig->setTitle( m_ensemble->name() + "\n" + m_ensembleParameter );
|
||||
RimEnsembleCurveSetColorManager::initializeLegendConfig( m_ensembleLegendConfig, ensembleParam );
|
||||
}
|
||||
|
||||
|
@ -897,6 +897,7 @@ void RimEnsembleCurveSet::updateCurveColors()
|
||||
plot->viewer()->overlayMargins() );
|
||||
}
|
||||
m_legendOverlayFrame->setContentFrame( m_legendConfig->makeLegendFrame() );
|
||||
plot->viewer()->addOverlayFrame( m_legendOverlayFrame );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,11 +41,13 @@ QSize RiuAbstractLegendFrame::sizeHint() const
|
||||
layoutInfo( &layout );
|
||||
|
||||
QFontMetrics fontMetrics( this->font() );
|
||||
QStringList titleLines = m_title.split( "\n", QString::SkipEmptyParts );
|
||||
QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title );
|
||||
|
||||
int preferredContentHeight = titleLines.size() * layout.lineSpacing + labelCount() * layout.lineSpacing;
|
||||
int preferredContentHeight = titleRect.height() + labelCount() * layout.lineSpacing;
|
||||
int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom();
|
||||
|
||||
int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right();
|
||||
|
||||
int maxTickTextWidth = 0;
|
||||
for ( int i = 0; i < labelCount(); ++i )
|
||||
{
|
||||
@ -57,7 +59,7 @@ QSize RiuAbstractLegendFrame::sizeHint() const
|
||||
int preferredWidth = layout.tickEndX + layout.margins.left() + layout.margins.right() + layout.tickTextLeadSpace +
|
||||
maxTickTextWidth;
|
||||
|
||||
preferredWidth = std::max( preferredWidth, fontMetrics.boundingRect( m_title ).width() );
|
||||
preferredWidth = std::max( preferredWidth, titleWidth );
|
||||
preferredWidth = std::min( preferredWidth, 400 );
|
||||
|
||||
return QSize( preferredWidth, preferredHeight );
|
||||
@ -72,10 +74,11 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
|
||||
layoutInfo( &layout );
|
||||
|
||||
QFontMetrics fontMetrics( this->font() );
|
||||
QStringList titleLines = m_title.split( "\n", QString::SkipEmptyParts );
|
||||
QRect titleRect = fontMetrics.boundingRect( QRect( 0, 0, 200, 200 ), Qt::AlignLeft, m_title );
|
||||
|
||||
int preferredContentHeight = titleLines.size() * layout.lineSpacing + 2 * layout.lineSpacing;
|
||||
int preferredContentHeight = titleRect.height() + 2 * layout.lineSpacing;
|
||||
int preferredHeight = preferredContentHeight + layout.margins.top() + layout.margins.bottom();
|
||||
int titleWidth = titleRect.width() + layout.margins.left() + layout.margins.right();
|
||||
|
||||
int firstTextWidth = fontMetrics.boundingRect( label( 0 ) ).width();
|
||||
int lastTextWidth = fontMetrics.boundingRect( label( labelCount() - 1 ) ).width();
|
||||
@ -84,7 +87,7 @@ QSize RiuAbstractLegendFrame::minimumSizeHint() const
|
||||
int preferredWidth = layout.tickEndX + layout.margins.left() + layout.margins.right() + layout.tickTextLeadSpace +
|
||||
maxTickTextWidth;
|
||||
|
||||
preferredWidth = std::max( preferredWidth, fontMetrics.boundingRect( m_title ).width() );
|
||||
preferredWidth = std::max( preferredWidth, titleWidth );
|
||||
preferredWidth = std::min( preferredWidth, 400 );
|
||||
|
||||
return QSize( preferredWidth, preferredHeight );
|
||||
@ -100,10 +103,11 @@ void RiuAbstractLegendFrame::renderTo( QPainter* painter, const QRect& targetRec
|
||||
|
||||
painter->save();
|
||||
painter->translate( targetRect.topLeft() );
|
||||
QPoint titlePos( layout.margins.left(), layout.margins.top() + layout.lineSpacing / 2 );
|
||||
painter->drawText( titlePos, m_title );
|
||||
|
||||
QStringList titleLines = m_title.split( "\n", QString::SkipEmptyParts );
|
||||
QPoint titlePos( layout.margins.left(), layout.margins.top() );
|
||||
QFontMetrics fontMetrics( this->font() );
|
||||
QRect boundingRect = fontMetrics.boundingRect( targetRect, Qt::AlignLeft, m_title );
|
||||
boundingRect.moveTo( titlePos );
|
||||
painter->drawText( boundingRect, m_title );
|
||||
|
||||
std::vector<std::pair<QPoint, QString>> visibleTickLabels = visibleLabels( layout );
|
||||
for ( auto tickLabel : visibleTickLabels )
|
||||
|
@ -112,8 +112,12 @@ RiuDraggableOverlayFrame::AnchorCorner RiuDraggableOverlayFrame::anchorCorner()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuDraggableOverlayFrame::sizeHint() const
|
||||
{
|
||||
QSize contentSize = m_contentFrame->sizeHint();
|
||||
return QSize( contentSize.width() + 2, contentSize.height() + 2 );
|
||||
if ( m_contentFrame )
|
||||
{
|
||||
QSize contentSize = m_contentFrame->sizeHint();
|
||||
return QSize( contentSize.width() + 2, contentSize.height() + 2 );
|
||||
}
|
||||
return QSize( 0, 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -121,6 +125,10 @@ QSize RiuDraggableOverlayFrame::sizeHint() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuDraggableOverlayFrame::minimumSizeHint() const
|
||||
{
|
||||
QSize contentSize = m_contentFrame->minimumSizeHint();
|
||||
return QSize( contentSize.width() + 2, contentSize.height() + 2 );
|
||||
if ( m_contentFrame )
|
||||
{
|
||||
QSize contentSize = m_contentFrame->minimumSizeHint();
|
||||
return QSize( contentSize.width() + 2, contentSize.height() + 2 );
|
||||
}
|
||||
return QSize( 0, 0 );
|
||||
}
|
||||
|
@ -160,12 +160,10 @@ int RiuScalarMapperLegendFrame::rectCount() const
|
||||
void RiuScalarMapperLegendFrame::renderRect( QPainter* painter, const LayoutInfo& layout, int rectIndex ) const
|
||||
{
|
||||
int rectIndexFromBottom = rectCount() - rectIndex - 1;
|
||||
cvf::Color3ub startColor = m_scalarMapper->mapToColor(
|
||||
m_scalarMapper->domainValue( m_tickValues[rectIndexFromBottom] ) );
|
||||
cvf::Color3ub endColor = m_scalarMapper->mapToColor(
|
||||
m_scalarMapper->domainValue( m_tickValues[rectIndexFromBottom + 1] ) );
|
||||
QColor startQColor( startColor.r(), startColor.g(), startColor.b() );
|
||||
QColor endQColor( endColor.r(), endColor.g(), endColor.b() );
|
||||
cvf::Color3ub startColor = m_scalarMapper->mapToColor( m_tickValues[rectIndexFromBottom] );
|
||||
cvf::Color3ub endColor = m_scalarMapper->mapToColor( m_tickValues[rectIndexFromBottom + 1] );
|
||||
QColor startQColor( startColor.r(), startColor.g(), startColor.b() );
|
||||
QColor endQColor( endColor.r(), endColor.g(), endColor.b() );
|
||||
|
||||
QRectF gradientRect( QPointF( layout.tickStartX,
|
||||
layout.colorBarRect.bottom() - layout.tickYPixelPos[rectIndexFromBottom] + 1 ),
|
||||
|
Loading…
Reference in New Issue
Block a user