Minor improvements to plot titles and margins

This commit is contained in:
Gaute Lindkvist 2020-01-17 08:11:01 +01:00
parent c72532eb4e
commit 23bf2c50d9
4 changed files with 35 additions and 23 deletions

View File

@ -159,7 +159,7 @@ void RiuMultiPlotPage::insertPlot( RiuQwtPlotWidget* plotWidget, size_t index )
QString subTitleText = plotWidget->plotTitle();
QLabel* subTitle = new QLabel( subTitleText );
subTitle->setAlignment( Qt::AlignHCenter );
subTitle->setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
subTitle->setWordWrap( true );
subTitle->setVisible( false );
m_subTitles.insert( static_cast<int>( index ), subTitle );
@ -653,10 +653,12 @@ int RiuMultiPlotPage::alignCanvasTops()
for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex )
{
int row = visibleIndex / rowAndColumnCount.second;
QFont font = m_plotWidgets[visibleIndex]->axisFont( QwtPlot::xTop );
maxExtents[row] = std::max( maxExtents[row],
plotWidgets[visibleIndex]->axisScaleDraw( QwtPlot::xTop )->extent( font ) );
if ( plotWidgets[visibleIndex]->axisEnabled( QwtPlot::xTop ) )
{
QFont font = m_plotWidgets[visibleIndex]->axisFont( QwtPlot::xTop );
maxExtents[row] = std::max( maxExtents[row],
plotWidgets[visibleIndex]->axisScaleDraw( QwtPlot::xTop )->extent( font ) );
}
}
for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex )

View File

@ -70,26 +70,33 @@ QSize RiuQwtPlotLegend::sizeHint() const
{
int numColumns = m_columnCount;
int numRows = legendLayout->itemCount() / numColumns;
if ( legendLayout->itemCount() % numColumns ) numRows++;
int width = numColumns * legendLayout->maxItemWidth();
int maxHeight = 0;
for ( unsigned int i = 0; i < legendLayout->itemCount(); ++i )
if ( numRows == 0 )
{
auto itemSize = legendLayout->itemAt( i )->sizeHint();
maxHeight = std::max( maxHeight, itemSize.height() );
return QSize( 0, 0 );
}
QMargins margins = legendLayout->contentsMargins();
int totalSpacing = ( numRows + 2 ) * legendLayout->spacing() + margins.top() + margins.bottom();
else
{
if ( legendLayout->itemCount() % numColumns ) numRows++;
int height = maxHeight * numRows + totalSpacing;
int width = numColumns * legendLayout->maxItemWidth();
QSize layoutSize( width, height );
QSize frameSize = layoutSize + QSize( 2 * frameWidth(), 2 * frameWidth() );
int maxHeight = 0;
for ( unsigned int i = 0; i < legendLayout->itemCount(); ++i )
{
auto itemSize = legendLayout->itemAt( i )->sizeHint();
maxHeight = std::max( maxHeight, itemSize.height() );
}
QMargins margins = legendLayout->contentsMargins();
int totalSpacing = ( numRows + 2 ) * legendLayout->spacing() + margins.top() + margins.bottom();
fullSizeHint.setWidth( std::max( fullSizeHint.width(), frameSize.width() ) );
fullSizeHint.setHeight( std::max( fullSizeHint.height(), frameSize.height() ) );
int height = maxHeight * numRows + totalSpacing;
QSize layoutSize( width, height );
QSize frameSize = layoutSize + QSize( 2 * frameWidth(), 2 * frameWidth() );
fullSizeHint.setWidth( std::max( fullSizeHint.width(), frameSize.width() ) );
fullSizeHint.setHeight( std::max( fullSizeHint.height(), frameSize.height() ) );
}
}
return fullSizeHint;
}

View File

@ -43,8 +43,8 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
plot->setAutoFillBackground( true );
plot->setCanvasBackground( Qt::white );
plot->plotLayout()->setCanvasMargin( 0, -1 );
plot->canvas()->setContentsMargins( 1, 1, 1, 1 );
QFrame* canvasFrame = dynamic_cast<QFrame*>( plot->canvas() );
canvasFrame->setFrameShape( QFrame::Box );
@ -90,7 +90,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
plot->canvas()->setMouseTracking( true );
plot->plotLayout()->setAlignCanvasToScales( true );
plot->setContentsMargins( 2, 2, 2, 2 );
plot->setContentsMargins( 1, 1, 1, 1 );
// Store the pointer address as an object name. This way each plot can be identified uniquely for CSS-stylesheets
QString objectName = QString( "%1" ).arg( reinterpret_cast<uint64_t>( plot ) );
@ -112,6 +112,8 @@ void RiuQwtPlotTools::setDefaultAxes( QwtPlot* plot )
plot->axisWidget( QwtPlot::xBottom )->setMargin( 0 );
plot->axisWidget( QwtPlot::yLeft )->setMargin( 0 );
plot->axisWidget( QwtPlot::xTop )->setMargin( 0 );
plot->axisWidget( QwtPlot::yRight )->setMargin( 0 );
plot->setAxisMaxMinor( QwtPlot::xBottom, 2 );
plot->setAxisMaxMinor( QwtPlot::yLeft, 3 );

View File

@ -46,6 +46,7 @@
#include "qwt_scale_widget.h"
#include "qwt_symbol.h"
#include "qwt_text.h"
#include "qwt_text_label.h"
#include <QDebug>
#include <QDrag>
@ -178,7 +179,7 @@ void RiuQwtPlotWidget::setAxisFontsAndAlignment( QwtPlot::Axis axis,
axisTitleFont.setPixelSize( RiaFontCache::pointSizeToPixelSize( titleFontSize ) );
axisTitleFont.setBold( titleBold );
axisTitle.setFont( axisTitleFont );
axisTitle.setRenderFlags( alignment );
axisTitle.setRenderFlags( alignment | Qt::TextWordWrap );
setAxisTitle( axis, axisTitle );
}