mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
More robust legend rendering in Well Log Plots
This commit is contained in:
@@ -159,11 +159,12 @@ void RiuMultiPlotWindow::insertPlot( RiuQwtPlotWidget* plotWidget, size_t index
|
||||
}
|
||||
legend->setMaxColumns( legendColumns );
|
||||
legend->horizontalScrollBar()->setVisible( false );
|
||||
legend->verticalScrollBar()->setVisible( true );
|
||||
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>& ) ) );
|
||||
QObject::connect( legend, SIGNAL( legendUpdated() ), this, SLOT( onLegendUpdated() ) );
|
||||
|
||||
legend->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
|
||||
plotWidget->updateLegend();
|
||||
@@ -340,7 +341,7 @@ void RiuMultiPlotWindow::resizeEvent( QResizeEvent* event )
|
||||
}
|
||||
if ( needsUpdate )
|
||||
{
|
||||
performUpdate();
|
||||
scheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,6 +549,14 @@ void RiuMultiPlotWindow::performUpdate()
|
||||
alignCanvasTops();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMultiPlotWindow::onLegendUpdated()
|
||||
{
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -594,6 +603,11 @@ void RiuMultiPlotWindow::reinsertPlotWidgets()
|
||||
|
||||
subTitles[visibleIndex]->setVisible( m_plotDefinition->showPlotTitles() );
|
||||
|
||||
plotWidgets[visibleIndex]->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, showYAxis( row, column ) );
|
||||
plotWidgets[visibleIndex]->setAxisTitleEnabled( QwtPlot::yLeft, showYAxis( row, column ) );
|
||||
|
||||
plotWidgets[visibleIndex]->show();
|
||||
|
||||
if ( m_plotDefinition->legendsVisible() )
|
||||
{
|
||||
int legendColumns = 1;
|
||||
@@ -614,11 +628,6 @@ void RiuMultiPlotWindow::reinsertPlotWidgets()
|
||||
legends[visibleIndex]->hide();
|
||||
}
|
||||
|
||||
plotWidgets[visibleIndex]->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, showYAxis( row, column ) );
|
||||
plotWidgets[visibleIndex]->setAxisTitleEnabled( QwtPlot::yLeft, showYAxis( row, column ) );
|
||||
|
||||
plotWidgets[visibleIndex]->show();
|
||||
|
||||
// Set basic row and column stretches
|
||||
for ( int r = row; r < row + rowSpan; ++r )
|
||||
{
|
||||
|
||||
@@ -42,6 +42,7 @@ class RiuQwtPlotWidget;
|
||||
class QFocusEvent;
|
||||
class QLabel;
|
||||
class QScrollBar;
|
||||
class QwtLegendData;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -111,6 +112,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
virtual void performUpdate();
|
||||
void onLegendUpdated();
|
||||
|
||||
protected:
|
||||
QPointer<QVBoxLayout> m_layout;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "qwt_dyngrid_layout.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QResizeEvent>
|
||||
|
||||
#include <utility>
|
||||
@@ -53,3 +54,38 @@ int RiuQwtPlotLegend::columnCount() const
|
||||
{
|
||||
return m_columnCount;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuQwtPlotLegend::sizeHint() const
|
||||
{
|
||||
QSize fullSizeHint = QwtLegend::sizeHint();
|
||||
// Update width
|
||||
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 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() );
|
||||
}
|
||||
int totalSpacing = ( rowCount + 1 ) * legendLayout->spacing();
|
||||
fullSizeHint.setHeight(
|
||||
std::max( fullSizeHint.height(), static_cast<int>( maxHeight * rowCount + totalSpacing + 4 ) ) );
|
||||
}
|
||||
return fullSizeHint;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotLegend::updateLegend( const QVariant& variant, const QList<QwtLegendData>& legendItems )
|
||||
{
|
||||
QwtLegend::updateLegend( variant, legendItems );
|
||||
emit legendUpdated();
|
||||
}
|
||||
|
||||
@@ -24,8 +24,15 @@ class RiuQwtPlotLegend : public QwtLegend
|
||||
Q_OBJECT
|
||||
public:
|
||||
RiuQwtPlotLegend( QWidget* parent = nullptr );
|
||||
void resizeEvent( QResizeEvent* event );
|
||||
int columnCount() const;
|
||||
void resizeEvent( QResizeEvent* event );
|
||||
int columnCount() const;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
public slots:
|
||||
void updateLegend( const QVariant&, const QList<QwtLegendData>& ) override;
|
||||
|
||||
signals:
|
||||
void legendUpdated();
|
||||
|
||||
private:
|
||||
mutable int m_columnCount;
|
||||
|
||||
Reference in New Issue
Block a user