Further improvements to well log plot legends

This commit is contained in:
Gaute Lindkvist 2019-11-28 19:30:55 +01:00
parent 330f2ea62a
commit 5eaef4390c
4 changed files with 29 additions and 58 deletions

View File

@ -155,12 +155,11 @@ void RiuMultiPlotWindow::insertPlot( RiuQwtPlotWidget* plotWidget, size_t index
int legendColumns = 1;
if ( m_plotDefinition->legendsHorizontal() )
{
legendColumns = 0; // unlimited
legendColumns = 4; // unlimited
}
legend->setMaxColumns( legendColumns );
legend->horizontalScrollBar()->setVisible( false );
legend->verticalScrollBar()->setVisible( false );
legend->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
legend->connect( plotWidget,
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
SLOT( updateLegend( const QVariant&, const QList<QwtLegendData>& ) ) );
@ -169,7 +168,6 @@ void RiuMultiPlotWindow::insertPlot( RiuQwtPlotWidget* plotWidget, size_t index
legend->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
plotWidget->updateLegend();
m_legends.insert( static_cast<int>( index ), legend );
m_legendColumns.insert( static_cast<int>( index ), -1 );
scheduleUpdate();
}
@ -190,7 +188,6 @@ void RiuMultiPlotWindow::removePlot( RiuQwtPlotWidget* plotWidget )
RiuQwtPlotLegend* legend = m_legends[plotWidgetIdx];
legend->setParent( nullptr );
m_legends.removeAt( plotWidgetIdx );
m_legendColumns.removeAt( plotWidgetIdx );
delete legend;
QLabel* subTitle = m_subTitles[plotWidgetIdx];
@ -316,35 +313,6 @@ QLabel* RiuMultiPlotWindow::createTitleLabel() const
return plotTitle;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotWindow::resizeEvent( QResizeEvent* event )
{
QWidget::resizeEvent( event );
bool needsUpdate = false;
for ( int i = 0; i < m_legends.size(); ++i )
{
if ( m_legends[i]->isVisible() )
{
int columnCount = m_legends[i]->columnCount();
if ( columnCount != m_legendColumns[i] )
{
int oldColumnCount = m_legendColumns[i];
m_legendColumns[i] = columnCount;
if ( oldColumnCount != -1 )
{
needsUpdate = true;
}
}
}
}
if ( needsUpdate )
{
scheduleUpdate();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -613,11 +581,9 @@ void RiuMultiPlotWindow::reinsertPlotWidgets()
int legendColumns = 1;
if ( m_plotDefinition->legendsHorizontal() )
{
legendColumns = 0; // unlimited
legendColumns = 4; // unlimited
}
legends[visibleIndex]->setMaxColumns( legendColumns );
int minimumHeight = legends[visibleIndex]->heightForWidth( plotWidgets[visibleIndex]->width() );
legends[visibleIndex]->setMinimumHeight( minimumHeight );
QFont legendFont = legends[visibleIndex]->font();
legendFont.setPointSize( m_plotDefinition->legendFontSize() );
legends[visibleIndex]->setFont( legendFont );
@ -651,6 +617,7 @@ int RiuMultiPlotWindow::alignCanvasTops()
CVF_ASSERT( m_legends.size() == m_plotWidgets.size() );
QList<QPointer<RiuQwtPlotWidget>> plotWidgets = visiblePlotWidgets();
QList<QPointer<RiuQwtPlotLegend>> legends = visibleLegends();
if ( plotWidgets.empty() ) return 0;
auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() );
@ -670,6 +637,7 @@ int RiuMultiPlotWindow::alignCanvasTops()
{
int row = visibleIndex / rowAndColumnCount.second;
plotWidgets[visibleIndex]->axisScaleDraw( QwtPlot::xTop )->setMinimumExtent( maxExtents[row] );
legends[visibleIndex]->adjustSize();
}
return maxExtents[0];
}

View File

@ -82,7 +82,6 @@ protected:
void contextMenuEvent( QContextMenuEvent* ) override;
QLabel* createTitleLabel() const;
void resizeEvent( QResizeEvent* event ) override;
void showEvent( QShowEvent* event ) override;
void dragEnterEvent( QDragEnterEvent* event ) override;
void dragMoveEvent( QDragMoveEvent* event ) override;
@ -120,7 +119,6 @@ protected:
QPointer<QFrame> m_plotWidgetFrame;
QPointer<QGridLayout> m_gridLayout;
QPointer<QLabel> m_plotTitle;
QList<int> m_legendColumns;
QList<QPointer<QLabel>> m_subTitles;
QList<QPointer<RiuQwtPlotLegend>> m_legends;
QList<QPointer<RiuQwtPlotWidget>> m_plotWidgets;

View File

@ -29,7 +29,7 @@
//--------------------------------------------------------------------------------------------------
RiuQwtPlotLegend::RiuQwtPlotLegend( QWidget* parent /*= nullptr */ )
: QwtLegend( parent )
, m_columnCount( -1 )
, m_columnCount( 1 )
{
}
@ -43,16 +43,13 @@ void RiuQwtPlotLegend::resizeEvent( QResizeEvent* event )
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
if ( legendLayout )
{
m_columnCount = legendLayout->columnsForWidth( size.width() );
}
}
int left, right, top, bottom;
getContentsMargins( &left, &top, &right, &bottom );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiuQwtPlotLegend::columnCount() const
{
return m_columnCount;
m_columnCount = std::max( 1, (int)legendLayout->columnsForWidth( size.width() - left - right ) );
updateGeometry();
}
}
//--------------------------------------------------------------------------------------------------
@ -65,18 +62,28 @@ QSize RiuQwtPlotLegend::sizeHint() const
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
if ( legendLayout )
{
int rowCount = std::max( 1, (int)std::ceil( legendLayout->itemCount() / (double)std::max( m_columnCount, 1 ) ) );
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 )
{
auto itemSize = legendLayout->itemAt( i )->sizeHint();
int width = itemSize.width();
fullSizeHint.setWidth( std::max( fullSizeHint.width(), width ) );
maxHeight = std::max( maxHeight, itemSize.height() );
maxHeight = std::max( maxHeight, itemSize.height() );
}
int totalSpacing = ( rowCount + 1 ) * legendLayout->spacing();
fullSizeHint.setHeight(
std::max( fullSizeHint.height(), static_cast<int>( maxHeight * rowCount + totalSpacing + 4 ) ) );
QMargins margins = legendLayout->contentsMargins();
int totalSpacing = ( numRows + 1 ) * 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;
}

View File

@ -25,9 +25,7 @@ class RiuQwtPlotLegend : public QwtLegend
public:
RiuQwtPlotLegend( QWidget* parent = nullptr );
void resizeEvent( QResizeEvent* event );
int columnCount() const;
QSize sizeHint() const override;
public slots:
void updateLegend( const QVariant&, const QList<QwtLegendData>& ) override;
@ -35,5 +33,5 @@ signals:
void legendUpdated();
private:
mutable int m_columnCount;
int m_columnCount;
};