Move legend control methods to RiuQwtPlotWidget

This commit is contained in:
Jacob Støren
2020-02-25 15:59:07 +01:00
parent 66d98b3d23
commit ba1a538bb9
4 changed files with 39 additions and 39 deletions

View File

@@ -35,6 +35,7 @@
#include "cafAssert.h"
#include "qwt_legend.h"
#include "qwt_legend_label.h"
#include "qwt_plot_canvas.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_grid.h"
@@ -237,6 +238,41 @@ bool RiuQwtPlotWidget::plotTitleEnabled() const
return m_plotTitleEnabled;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setLegendFontSize( int fontSize )
{
if ( legend() )
{
QFont font = legend()->font();
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( 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 RiuQwtPlotWidget::setLegendVisible( bool visible )
{
if ( visible )
{
QwtLegend* legend = new QwtLegend( this );
this->insertLegend( legend, BottomLegend );
}
else
{
this->insertLegend( nullptr );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -84,6 +84,9 @@ public:
void setPlotTitleEnabled( bool enabled );
bool plotTitleEnabled() const;
void setLegendFontSize( int fontSize );
void setLegendVisible( bool visible );
QwtInterval axisRange( QwtPlot::Axis axis );
void setAxisRange( QwtPlot::Axis axis, double min, double max );

View File

@@ -155,41 +155,6 @@ void RiuSummaryQwtPlot::useTimeBasedTimeAxis()
setAxisScaleDraw( QwtPlot::xBottom, new QwtScaleDraw() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setLegendFontSize( int fontSize )
{
if ( legend() )
{
QFont font = legend()->font();
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( 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 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -52,10 +52,6 @@ public:
RiaQDateTimeTools::TimeFormatComponents timeComponents = RiaQDateTimeTools::TIME_FORMAT_UNSPECIFIED );
void useTimeBasedTimeAxis();
void setLegendFontSize( int fontSize );
void setLegendVisible( bool visible );
void setAxisIsLogarithmic( QwtPlot::Axis axis, bool logarithmic );
signals: