#4929 Fix legend fonts in Summary plot

This commit is contained in:
Gaute Lindkvist
2019-10-25 15:24:53 +02:00
parent 4bce02c375
commit 625feaf36c
6 changed files with 110 additions and 39 deletions

View File

@@ -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();

View File

@@ -60,6 +60,9 @@ public:
RimViewWindow* ownerViewWindow() const override;
void setLegendFontSize( int fontSize );
void setLegendVisible( bool visible );
protected:
void updateLayout() override;
void updateInfoBoxLayout();

View File

@@ -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 );
}
//--------------------------------------------------------------------------------------------------

View File

@@ -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;