mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Further improvements to well log plot legends
This commit is contained in:
parent
330f2ea62a
commit
5eaef4390c
@ -155,12 +155,11 @@ void RiuMultiPlotWindow::insertPlot( RiuQwtPlotWidget* plotWidget, size_t index
|
|||||||
int legendColumns = 1;
|
int legendColumns = 1;
|
||||||
if ( m_plotDefinition->legendsHorizontal() )
|
if ( m_plotDefinition->legendsHorizontal() )
|
||||||
{
|
{
|
||||||
legendColumns = 0; // unlimited
|
legendColumns = 4; // unlimited
|
||||||
}
|
}
|
||||||
legend->setMaxColumns( legendColumns );
|
legend->setMaxColumns( legendColumns );
|
||||||
legend->horizontalScrollBar()->setVisible( false );
|
legend->horizontalScrollBar()->setVisible( false );
|
||||||
legend->verticalScrollBar()->setVisible( false );
|
legend->verticalScrollBar()->setVisible( false );
|
||||||
legend->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
|
|
||||||
legend->connect( plotWidget,
|
legend->connect( plotWidget,
|
||||||
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
|
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
|
||||||
SLOT( updateLegend( 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 );
|
legend->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
|
||||||
plotWidget->updateLegend();
|
plotWidget->updateLegend();
|
||||||
m_legends.insert( static_cast<int>( index ), legend );
|
m_legends.insert( static_cast<int>( index ), legend );
|
||||||
m_legendColumns.insert( static_cast<int>( index ), -1 );
|
|
||||||
|
|
||||||
scheduleUpdate();
|
scheduleUpdate();
|
||||||
}
|
}
|
||||||
@ -190,7 +188,6 @@ void RiuMultiPlotWindow::removePlot( RiuQwtPlotWidget* plotWidget )
|
|||||||
RiuQwtPlotLegend* legend = m_legends[plotWidgetIdx];
|
RiuQwtPlotLegend* legend = m_legends[plotWidgetIdx];
|
||||||
legend->setParent( nullptr );
|
legend->setParent( nullptr );
|
||||||
m_legends.removeAt( plotWidgetIdx );
|
m_legends.removeAt( plotWidgetIdx );
|
||||||
m_legendColumns.removeAt( plotWidgetIdx );
|
|
||||||
delete legend;
|
delete legend;
|
||||||
|
|
||||||
QLabel* subTitle = m_subTitles[plotWidgetIdx];
|
QLabel* subTitle = m_subTitles[plotWidgetIdx];
|
||||||
@ -316,35 +313,6 @@ QLabel* RiuMultiPlotWindow::createTitleLabel() const
|
|||||||
return plotTitle;
|
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;
|
int legendColumns = 1;
|
||||||
if ( m_plotDefinition->legendsHorizontal() )
|
if ( m_plotDefinition->legendsHorizontal() )
|
||||||
{
|
{
|
||||||
legendColumns = 0; // unlimited
|
legendColumns = 4; // unlimited
|
||||||
}
|
}
|
||||||
legends[visibleIndex]->setMaxColumns( legendColumns );
|
legends[visibleIndex]->setMaxColumns( legendColumns );
|
||||||
int minimumHeight = legends[visibleIndex]->heightForWidth( plotWidgets[visibleIndex]->width() );
|
|
||||||
legends[visibleIndex]->setMinimumHeight( minimumHeight );
|
|
||||||
QFont legendFont = legends[visibleIndex]->font();
|
QFont legendFont = legends[visibleIndex]->font();
|
||||||
legendFont.setPointSize( m_plotDefinition->legendFontSize() );
|
legendFont.setPointSize( m_plotDefinition->legendFontSize() );
|
||||||
legends[visibleIndex]->setFont( legendFont );
|
legends[visibleIndex]->setFont( legendFont );
|
||||||
@ -651,6 +617,7 @@ int RiuMultiPlotWindow::alignCanvasTops()
|
|||||||
CVF_ASSERT( m_legends.size() == m_plotWidgets.size() );
|
CVF_ASSERT( m_legends.size() == m_plotWidgets.size() );
|
||||||
|
|
||||||
QList<QPointer<RiuQwtPlotWidget>> plotWidgets = visiblePlotWidgets();
|
QList<QPointer<RiuQwtPlotWidget>> plotWidgets = visiblePlotWidgets();
|
||||||
|
QList<QPointer<RiuQwtPlotLegend>> legends = visibleLegends();
|
||||||
if ( plotWidgets.empty() ) return 0;
|
if ( plotWidgets.empty() ) return 0;
|
||||||
|
|
||||||
auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() );
|
auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() );
|
||||||
@ -670,6 +637,7 @@ int RiuMultiPlotWindow::alignCanvasTops()
|
|||||||
{
|
{
|
||||||
int row = visibleIndex / rowAndColumnCount.second;
|
int row = visibleIndex / rowAndColumnCount.second;
|
||||||
plotWidgets[visibleIndex]->axisScaleDraw( QwtPlot::xTop )->setMinimumExtent( maxExtents[row] );
|
plotWidgets[visibleIndex]->axisScaleDraw( QwtPlot::xTop )->setMinimumExtent( maxExtents[row] );
|
||||||
|
legends[visibleIndex]->adjustSize();
|
||||||
}
|
}
|
||||||
return maxExtents[0];
|
return maxExtents[0];
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,6 @@ protected:
|
|||||||
void contextMenuEvent( QContextMenuEvent* ) override;
|
void contextMenuEvent( QContextMenuEvent* ) override;
|
||||||
QLabel* createTitleLabel() const;
|
QLabel* createTitleLabel() const;
|
||||||
|
|
||||||
void resizeEvent( QResizeEvent* event ) override;
|
|
||||||
void showEvent( QShowEvent* event ) override;
|
void showEvent( QShowEvent* event ) override;
|
||||||
void dragEnterEvent( QDragEnterEvent* event ) override;
|
void dragEnterEvent( QDragEnterEvent* event ) override;
|
||||||
void dragMoveEvent( QDragMoveEvent* event ) override;
|
void dragMoveEvent( QDragMoveEvent* event ) override;
|
||||||
@ -120,7 +119,6 @@ protected:
|
|||||||
QPointer<QFrame> m_plotWidgetFrame;
|
QPointer<QFrame> m_plotWidgetFrame;
|
||||||
QPointer<QGridLayout> m_gridLayout;
|
QPointer<QGridLayout> m_gridLayout;
|
||||||
QPointer<QLabel> m_plotTitle;
|
QPointer<QLabel> m_plotTitle;
|
||||||
QList<int> m_legendColumns;
|
|
||||||
QList<QPointer<QLabel>> m_subTitles;
|
QList<QPointer<QLabel>> m_subTitles;
|
||||||
QList<QPointer<RiuQwtPlotLegend>> m_legends;
|
QList<QPointer<RiuQwtPlotLegend>> m_legends;
|
||||||
QList<QPointer<RiuQwtPlotWidget>> m_plotWidgets;
|
QList<QPointer<RiuQwtPlotWidget>> m_plotWidgets;
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RiuQwtPlotLegend::RiuQwtPlotLegend( QWidget* parent /*= nullptr */ )
|
RiuQwtPlotLegend::RiuQwtPlotLegend( QWidget* parent /*= nullptr */ )
|
||||||
: QwtLegend( parent )
|
: 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() );
|
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
|
||||||
if ( legendLayout )
|
if ( legendLayout )
|
||||||
{
|
{
|
||||||
m_columnCount = legendLayout->columnsForWidth( size.width() );
|
int left, right, top, bottom;
|
||||||
}
|
getContentsMargins( &left, &top, &right, &bottom );
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
m_columnCount = std::max( 1, (int)legendLayout->columnsForWidth( size.width() - left - right ) );
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
updateGeometry();
|
||||||
int RiuQwtPlotLegend::columnCount() const
|
}
|
||||||
{
|
|
||||||
return m_columnCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -65,18 +62,28 @@ QSize RiuQwtPlotLegend::sizeHint() const
|
|||||||
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
|
const QwtDynGridLayout* legendLayout = qobject_cast<QwtDynGridLayout*>( contentsWidget()->layout() );
|
||||||
if ( legendLayout )
|
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;
|
int maxHeight = 0;
|
||||||
for ( unsigned int i = 0; i < legendLayout->itemCount(); ++i )
|
for ( unsigned int i = 0; i < legendLayout->itemCount(); ++i )
|
||||||
{
|
{
|
||||||
auto itemSize = legendLayout->itemAt( i )->sizeHint();
|
auto itemSize = legendLayout->itemAt( i )->sizeHint();
|
||||||
int width = itemSize.width();
|
maxHeight = std::max( maxHeight, itemSize.height() );
|
||||||
fullSizeHint.setWidth( std::max( fullSizeHint.width(), width ) );
|
|
||||||
maxHeight = std::max( maxHeight, itemSize.height() );
|
|
||||||
}
|
}
|
||||||
int totalSpacing = ( rowCount + 1 ) * legendLayout->spacing();
|
QMargins margins = legendLayout->contentsMargins();
|
||||||
fullSizeHint.setHeight(
|
int totalSpacing = ( numRows + 1 ) * legendLayout->spacing() + margins.top() + margins.bottom();
|
||||||
std::max( fullSizeHint.height(), static_cast<int>( maxHeight * rowCount + totalSpacing + 4 ) ) );
|
|
||||||
|
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;
|
return fullSizeHint;
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,7 @@ class RiuQwtPlotLegend : public QwtLegend
|
|||||||
public:
|
public:
|
||||||
RiuQwtPlotLegend( QWidget* parent = nullptr );
|
RiuQwtPlotLegend( QWidget* parent = nullptr );
|
||||||
void resizeEvent( QResizeEvent* event );
|
void resizeEvent( QResizeEvent* event );
|
||||||
int columnCount() const;
|
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLegend( const QVariant&, const QList<QwtLegendData>& ) override;
|
void updateLegend( const QVariant&, const QList<QwtLegendData>& ) override;
|
||||||
|
|
||||||
@ -35,5 +33,5 @@ signals:
|
|||||||
void legendUpdated();
|
void legendUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable int m_columnCount;
|
int m_columnCount;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user