Summary improvements

* #9424 Show vector name in curve names when history vector is present
* #9426 Curve Legend disappears when curve is unchecked
* Remove duplicate call to visibilityChanged
* Remove unused code
This commit is contained in:
Magne Sjaastad
2022-11-01 08:00:51 +01:00
committed by GitHub
parent a577545212
commit e29b310566
11 changed files with 94 additions and 65 deletions

View File

@@ -35,9 +35,9 @@
//--------------------------------------------------------------------------------------------------
RiuQwtPlotLegend::RiuQwtPlotLegend( QWidget* parent /*= nullptr */ )
: QwtLegend( parent )
, m_columnCount( 1 )
{
QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
auto* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
if ( legendLayout )
{
legendLayout->setExpandingDirections( Qt::Horizontal | Qt::Vertical );
@@ -60,11 +60,6 @@ void RiuQwtPlotLegend::resizeEvent( QResizeEvent* event )
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
if ( legendLayout )
{
QMargins margins = this->contentsMargins();
m_columnCount =
std::max( 1, (int)legendLayout->columnsForWidth( size.width() - margins.left() - margins.right() ) );
updateGeometry();
}
}
@@ -75,40 +70,41 @@ void RiuQwtPlotLegend::resizeEvent( QResizeEvent* event )
QSize RiuQwtPlotLegend::sizeHint() const
{
QSize fullSizeHint = QwtLegend::sizeHint();
// Update width
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
if ( legendLayout )
{
int numColumns = m_columnCount;
int numRows = legendLayout->itemCount() / numColumns;
QMargins margins = this->contentsMargins();
int numColumns =
std::max( 1, (int)legendLayout->columnsForWidth( fullSizeHint.width() - margins.left() - margins.right() ) );
int numRows = legendLayout->itemCount() / numColumns;
if ( numRows == 0 )
{
return QSize( 0, 0 );
return { 0, 0 };
}
else
if ( legendLayout->itemCount() % numColumns ) numRows++;
int width = numColumns * legendLayout->maxItemWidth();
int maxHeight = 0;
for ( unsigned int i = 0; i < legendLayout->itemCount(); ++i )
{
if ( legendLayout->itemCount() % numColumns ) numRows++;
int width = numColumns * legendLayout->maxItemWidth();
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();
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() ) );
auto itemSize = legendLayout->itemAt( i )->sizeHint();
maxHeight = std::max( maxHeight, itemSize.height() );
}
int totalSpacing = ( numRows + 2 ) * legendLayout->spacing() + margins.top() + margins.bottom();
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;
}