mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4929 Fix legend fonts in Summary plot
This commit is contained in:
parent
4bce02c375
commit
625feaf36c
@ -464,8 +464,13 @@ void RimGridCrossPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField
|
||||
const QVariant& oldValue,
|
||||
const QVariant& newValue )
|
||||
{
|
||||
if ( changedField == &m_showLegend )
|
||||
{
|
||||
m_plotWidget->setLegendVisible( m_showLegend() );
|
||||
}
|
||||
if ( changedField == &m_legendFontSize )
|
||||
{
|
||||
m_plotWidget->setLegendFontSize( m_legendFontSize() );
|
||||
for ( auto dataSet : m_crossPlotDataSets )
|
||||
{
|
||||
dataSet->updateLegendIcons();
|
||||
@ -541,20 +546,8 @@ void RimGridCrossPlot::updatePlot()
|
||||
dataSet->setParentQwtPlotNoReplot( m_plotWidget );
|
||||
}
|
||||
|
||||
if ( m_showLegend() )
|
||||
{
|
||||
// Will be released in plot destructor or when a new legend is set
|
||||
QwtLegend* legend = new QwtLegend( m_plotWidget );
|
||||
|
||||
auto font = legend->font();
|
||||
font.setPointSize( m_legendFontSize() );
|
||||
legend->setFont( font );
|
||||
m_plotWidget->insertLegend( legend, QwtPlot::BottomLegend );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_plotWidget->insertLegend( nullptr );
|
||||
}
|
||||
m_plotWidget->setLegendVisible( m_showLegend() );
|
||||
m_plotWidget->setLegendFontSize( m_legendFontSize() );
|
||||
m_plotWidget->updateLegendSizesToMatchPlot();
|
||||
m_plotWidget->scheduleReplot();
|
||||
}
|
||||
|
@ -1381,13 +1381,22 @@ void RimSummaryPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
{
|
||||
RimViewWindow::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
|
||||
if ( changedField == &m_description || changedField == &m_showPlotTitle || changedField == &m_showLegend ||
|
||||
changedField == &m_legendFontSize || changedField == &m_useAutoPlotTitle )
|
||||
if ( changedField == &m_description || changedField == &m_showPlotTitle || changedField == &m_useAutoPlotTitle )
|
||||
{
|
||||
updatePlotTitle();
|
||||
updateConnectedEditors();
|
||||
}
|
||||
|
||||
if ( changedField == &m_showLegend )
|
||||
{
|
||||
if ( m_plotWidget ) m_plotWidget->setLegendVisible( m_showLegend );
|
||||
}
|
||||
|
||||
if ( changedField == &m_legendFontSize )
|
||||
{
|
||||
if ( m_plotWidget ) m_plotWidget->setLegendFontSize( m_legendFontSize() );
|
||||
}
|
||||
|
||||
if ( changedField == &m_useAutoPlotTitle && !m_useAutoPlotTitle )
|
||||
{
|
||||
// When auto name of plot is turned off, update the auto name for all curves
|
||||
@ -1504,7 +1513,12 @@ void RimSummaryPlot::onLoadDataAndUpdate()
|
||||
curve->loadDataAndUpdate( false );
|
||||
}
|
||||
|
||||
if ( m_plotWidget ) m_plotWidget->updateLegend();
|
||||
if ( m_plotWidget )
|
||||
{
|
||||
m_plotWidget->setLegendVisible( m_showLegend );
|
||||
m_plotWidget->setLegendFontSize( m_legendFontSize() );
|
||||
m_plotWidget->updateLegend();
|
||||
}
|
||||
this->updateAxes();
|
||||
|
||||
m_textCurveSetEditor->updateTextFilter();
|
||||
@ -1799,21 +1813,6 @@ void RimSummaryPlot::updateMdiWindowTitle()
|
||||
{
|
||||
m_plotWidget->setTitle( "" );
|
||||
}
|
||||
|
||||
if ( m_showLegend )
|
||||
{
|
||||
// Will be released in plot destructor or when a new legend is set
|
||||
QwtLegend* legend = new QwtLegend( m_plotWidget );
|
||||
|
||||
auto font = legend->font();
|
||||
font.setPointSize( m_legendFontSize() );
|
||||
legend->setFont( font );
|
||||
m_plotWidget->insertLegend( legend, QwtPlot::BottomLegend );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_plotWidget->insertLegend( nullptr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include "RimPlotAxisProperties.h"
|
||||
#include "RiuPlotAnnotationTool.h"
|
||||
|
||||
#include "qwt_legend.h"
|
||||
#include "qwt_legend_label.h"
|
||||
#include "qwt_plot_panner.h"
|
||||
#include "qwt_scale_draw.h"
|
||||
#include "qwt_scale_widget.h"
|
||||
@ -104,6 +106,8 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimPlotInterface* plotDefinition, QWid
|
||||
|
||||
this->installEventFilter( this );
|
||||
this->canvas()->installEventFilter( this );
|
||||
|
||||
setLegendVisible( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -243,6 +247,42 @@ RimViewWindow* RiuGridCrossQwtPlot::ownerViewWindow() const
|
||||
return dynamic_cast<RimViewWindow*>( plotDefinition() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridCrossQwtPlot::setLegendFontSize( int fontSize )
|
||||
{
|
||||
if ( legend() )
|
||||
{
|
||||
QFont font = legend()->font();
|
||||
font.setPointSize( fontSize );
|
||||
legend()->setFont( font );
|
||||
// Set font size for all existing labels
|
||||
QList<QwtLegendLabel*> labels = legend()->findChildren<QwtLegendLabel*>();
|
||||
for ( QwtLegendLabel* label : labels )
|
||||
{
|
||||
label->setFont( font );
|
||||
}
|
||||
}
|
||||
updateInfoBoxLayout();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridCrossQwtPlot::setLegendVisible( bool visible )
|
||||
{
|
||||
if ( visible )
|
||||
{
|
||||
QwtLegend* legend = new QwtLegend( this );
|
||||
this->insertLegend( legend, BottomLegend );
|
||||
}
|
||||
else
|
||||
{
|
||||
this->insertLegend( nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -291,9 +331,9 @@ void RiuGridCrossQwtPlot::updateInfoBoxLayout()
|
||||
if ( !infoText.empty() )
|
||||
{
|
||||
m_infoBox->label()->setText( infoText.join( "\n" ) );
|
||||
QFont font = m_infoBox->font();
|
||||
QFont font = m_infoBox->label()->font();
|
||||
font.setPointSize( crossPlot->legendFontSize() );
|
||||
m_infoBox->setFont( font );
|
||||
m_infoBox->label()->setFont( font );
|
||||
m_infoBox->adjustSize();
|
||||
QRect infoRect = m_infoBox->frameGeometry();
|
||||
QRect canvasRect = canvas()->frameGeometry();
|
||||
|
@ -60,6 +60,9 @@ public:
|
||||
|
||||
RimViewWindow* ownerViewWindow() const override;
|
||||
|
||||
void setLegendFontSize( int fontSize );
|
||||
void setLegendVisible( bool visible );
|
||||
|
||||
protected:
|
||||
void updateLayout() override;
|
||||
void updateInfoBoxLayout();
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "qwt_date_scale_engine.h"
|
||||
#include "qwt_interval.h"
|
||||
#include "qwt_legend.h"
|
||||
#include "qwt_legend_label.h"
|
||||
#include "qwt_plot_curve.h"
|
||||
#include "qwt_plot_panner.h"
|
||||
#include "qwt_plot_zoomer.h"
|
||||
@ -128,6 +129,8 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimPlotInterface* plotDefinition, QWidget*
|
||||
|
||||
this->installEventFilter( this );
|
||||
this->canvas()->installEventFilter( this );
|
||||
|
||||
setLegendVisible( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -204,6 +207,41 @@ RimViewWindow* RiuSummaryQwtPlot::ownerViewWindow() const
|
||||
return dynamic_cast<RimViewWindow*>( plotDefinition() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::setLegendFontSize( int fontSize )
|
||||
{
|
||||
if ( legend() )
|
||||
{
|
||||
QFont font = legend()->font();
|
||||
font.setPointSize( fontSize );
|
||||
legend()->setFont( font );
|
||||
// Set font size for all existing labels
|
||||
QList<QwtLegendLabel*> labels = legend()->findChildren<QwtLegendLabel*>();
|
||||
for ( QwtLegendLabel* label : labels )
|
||||
{
|
||||
label->setFont( font );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::setLegendVisible( bool visible )
|
||||
{
|
||||
if ( visible )
|
||||
{
|
||||
QwtLegend* legend = new QwtLegend( this );
|
||||
this->insertLegend( legend, BottomLegend );
|
||||
}
|
||||
else
|
||||
{
|
||||
this->insertLegend( nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -247,11 +285,6 @@ void RiuSummaryQwtPlot::setDefaults()
|
||||
QString timeFormat = RiaApplication::instance()->preferences()->timeFormat();
|
||||
|
||||
useDateBasedTimeAxis( dateFormat, timeFormat );
|
||||
|
||||
// The legend will be deleted in the destructor of the plot or when
|
||||
// another legend is inserted.
|
||||
QwtLegend* legend = new QwtLegend( this );
|
||||
this->insertLegend( legend, BottomLegend );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -55,6 +55,9 @@ public:
|
||||
|
||||
RimViewWindow* ownerViewWindow() const override;
|
||||
|
||||
void setLegendFontSize( int fontSize );
|
||||
void setLegendVisible( bool visible );
|
||||
|
||||
protected:
|
||||
void keyPressEvent( QKeyEvent* ) override;
|
||||
void contextMenuEvent( QContextMenuEvent* ) override;
|
||||
|
Loading…
Reference in New Issue
Block a user