mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Fix track widths and canvas top alignment
This commit is contained in:
parent
81cb97ead7
commit
5cfd840025
@ -211,6 +211,7 @@ void RimWellLogPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
|||||||
changedField == &m_depthAxisGridVisibility )
|
changedField == &m_depthAxisGridVisibility )
|
||||||
{
|
{
|
||||||
updateTracks();
|
updateTracks();
|
||||||
|
if ( m_viewer ) m_viewer->updateChildrenLayout();
|
||||||
}
|
}
|
||||||
else if ( changedField == &m_showTitleInPlot )
|
else if ( changedField == &m_showTitleInPlot )
|
||||||
{
|
{
|
||||||
|
@ -481,7 +481,7 @@ void RimWellLogTrack::updateParentPlotLayout()
|
|||||||
RiuWellLogPlot* wellLogPlotViewer = dynamic_cast<RiuWellLogPlot*>( wellLogPlot->viewWidget() );
|
RiuWellLogPlot* wellLogPlotViewer = dynamic_cast<RiuWellLogPlot*>( wellLogPlot->viewWidget() );
|
||||||
if ( wellLogPlotViewer )
|
if ( wellLogPlotViewer )
|
||||||
{
|
{
|
||||||
wellLogPlotViewer->update();
|
wellLogPlotViewer->updateChildrenLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,10 @@ public:
|
|||||||
};
|
};
|
||||||
enum WidthScaleFactor
|
enum WidthScaleFactor
|
||||||
{
|
{
|
||||||
EXTRA_NARROW_TRACK = 2,
|
EXTRA_NARROW_TRACK = 3,
|
||||||
NARROW_TRACK = 3,
|
NARROW_TRACK = 4,
|
||||||
NORMAL_TRACK = 4,
|
NORMAL_TRACK = 5,
|
||||||
WIDE_TRACK = 6,
|
WIDE_TRACK = 7,
|
||||||
EXTRA_WIDE_TRACK = 10
|
EXTRA_WIDE_TRACK = 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ RiuWellLogPlot::RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent
|
|||||||
m_plotDefinition = plotDefinition;
|
m_plotDefinition = plotDefinition;
|
||||||
|
|
||||||
m_layout = new QVBoxLayout( this );
|
m_layout = new QVBoxLayout( this );
|
||||||
|
m_layout->setMargin( 0 );
|
||||||
|
m_layout->setSpacing( 2 );
|
||||||
|
|
||||||
m_plotTitle = createTitleLabel();
|
m_plotTitle = createTitleLabel();
|
||||||
m_layout->addWidget( m_plotTitle );
|
m_layout->addWidget( m_plotTitle );
|
||||||
@ -69,6 +71,8 @@ RiuWellLogPlot::RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent
|
|||||||
m_plotLayout->addWidget( m_plotFrame, 1 );
|
m_plotLayout->addWidget( m_plotFrame, 1 );
|
||||||
|
|
||||||
m_trackLayout = new QGridLayout( m_plotFrame );
|
m_trackLayout = new QGridLayout( m_plotFrame );
|
||||||
|
m_trackLayout->setMargin( 0 );
|
||||||
|
m_trackLayout->setSpacing( 2 );
|
||||||
|
|
||||||
QPalette newPalette( palette() );
|
QPalette newPalette( palette() );
|
||||||
newPalette.setColor( QPalette::Background, Qt::white );
|
newPalette.setColor( QPalette::Background, Qt::white );
|
||||||
@ -192,7 +196,7 @@ void RiuWellLogPlot::setDepthZoomAndReplot( double minDepth, double maxDepth )
|
|||||||
void RiuWellLogPlot::setPlotTitle( const QString& plotTitle )
|
void RiuWellLogPlot::setPlotTitle( const QString& plotTitle )
|
||||||
{
|
{
|
||||||
m_plotTitle->setText( plotTitle );
|
m_plotTitle->setText( plotTitle );
|
||||||
this->update();
|
this->updateChildrenLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -224,9 +228,62 @@ QSize RiuWellLogPlot::preferredSize() const
|
|||||||
void RiuWellLogPlot::setTitleVisible( bool visible )
|
void RiuWellLogPlot::setTitleVisible( bool visible )
|
||||||
{
|
{
|
||||||
m_plotTitle->setVisible( visible );
|
m_plotTitle->setVisible( visible );
|
||||||
|
this->updateChildrenLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuWellLogPlot::updateChildrenLayout()
|
||||||
|
{
|
||||||
|
int trackCount = m_trackPlots.size();
|
||||||
|
int numTracksAlreadyShown = 0;
|
||||||
|
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
|
||||||
|
{
|
||||||
|
if ( m_plotDefinition->areTrackLegendsVisible() && m_trackPlots[tIdx]->isVisible() )
|
||||||
|
{
|
||||||
|
int legendColumns = 1;
|
||||||
|
if ( m_plotDefinition->areTrackLegendsHorizontal() )
|
||||||
|
{
|
||||||
|
legendColumns = 0; // unlimited
|
||||||
|
}
|
||||||
|
m_legends[tIdx]->setMaxColumns( legendColumns );
|
||||||
|
m_legends[tIdx]->show();
|
||||||
|
|
||||||
|
m_trackPlots[tIdx]->enableDepthAxisLabelsAndTitle( numTracksAlreadyShown == 0 );
|
||||||
|
numTracksAlreadyShown++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_legends[tIdx]->hide();
|
||||||
|
}
|
||||||
|
RiuWellLogTrack* riuTrack = m_trackPlots[tIdx];
|
||||||
|
m_trackLayout->setColumnStretch( tIdx, riuTrack->widthScaleFactor() );
|
||||||
|
}
|
||||||
|
|
||||||
|
alignCanvasTops();
|
||||||
this->update();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuWellLogPlot::showEvent( QShowEvent* )
|
||||||
|
{
|
||||||
|
updateChildrenLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuWellLogPlot::changeEvent( QEvent* event )
|
||||||
|
{
|
||||||
|
if ( event->type() == QEvent::WindowStateChange )
|
||||||
|
{
|
||||||
|
updateChildrenLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -251,17 +308,17 @@ void RiuWellLogPlot::contextMenuEvent( QContextMenuEvent* event )
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QSize RiuWellLogPlot::sizeHint() const
|
void RiuWellLogPlot::keyPressEvent( QKeyEvent* keyEvent )
|
||||||
{
|
{
|
||||||
return QSize( 1, 1 );
|
m_plotDefinition->handleKeyPressEvent( keyEvent );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuWellLogPlot::keyPressEvent( QKeyEvent* keyEvent )
|
QSize RiuWellLogPlot::sizeHint() const
|
||||||
{
|
{
|
||||||
m_plotDefinition->handleKeyPressEvent( keyEvent );
|
return QSize( 1, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -302,6 +359,45 @@ void RiuWellLogPlot::updateScrollBar( double minDepth, double maxDepth )
|
|||||||
m_scrollBar->blockSignals( false );
|
m_scrollBar->blockSignals( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuWellLogPlot::alignCanvasTops()
|
||||||
|
{
|
||||||
|
CVF_ASSERT( m_legends.size() == m_trackPlots.size() );
|
||||||
|
|
||||||
|
int maxCanvasOffset = 0;
|
||||||
|
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
|
||||||
|
{
|
||||||
|
if ( m_trackPlots[tIdx]->isVisible() )
|
||||||
|
{
|
||||||
|
// Hack to align QWT plots. See below.
|
||||||
|
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
|
||||||
|
int canvasMargins = m_trackPlots[tIdx]->plotLayout()->canvasMargin( QwtPlot::xTop );
|
||||||
|
maxCanvasOffset = std::max( maxCanvasOffset, static_cast<int>( canvasRect.top() + canvasMargins ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
|
||||||
|
{
|
||||||
|
if ( m_trackPlots[tIdx]->isVisible() )
|
||||||
|
{
|
||||||
|
// Hack to align QWT plots which doesn't have an x-axis with the other tracks.
|
||||||
|
// Since they are missing the axis, QWT will shift them upwards.
|
||||||
|
// So we shift the plot downwards and resize to match the others.
|
||||||
|
// TODO: Look into subclassing QwtPlotLayout instead.
|
||||||
|
QRectF canvasRect = m_trackPlots[tIdx]->plotLayout()->canvasRect();
|
||||||
|
int canvasMargins = m_trackPlots[tIdx]->plotLayout()->canvasMargin( QwtPlot::xTop );
|
||||||
|
int myCanvasOffset = static_cast<int>( canvasRect.top() ) + canvasMargins;
|
||||||
|
int canvasShift = std::max( 0, maxCanvasOffset - myCanvasOffset );
|
||||||
|
|
||||||
|
QMargins margins = m_trackPlots[tIdx]->contentsMargins();
|
||||||
|
margins.setTop( margins.top() + canvasShift );
|
||||||
|
m_trackPlots[tIdx]->setContentsMargins( margins );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -67,19 +67,22 @@ public:
|
|||||||
|
|
||||||
void setTitleVisible( bool visible );
|
void setTitleVisible( bool visible );
|
||||||
|
|
||||||
protected:
|
public slots:
|
||||||
void contextMenuEvent( QContextMenuEvent* ) override;
|
void updateChildrenLayout();
|
||||||
QSize sizeHint() const override;
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent( QShowEvent* ) override;
|
||||||
|
void changeEvent( QEvent* event ) override;
|
||||||
|
void contextMenuEvent( QContextMenuEvent* ) override;
|
||||||
void keyPressEvent( QKeyEvent* keyEvent ) override;
|
void keyPressEvent( QKeyEvent* keyEvent ) override;
|
||||||
|
|
||||||
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
QLabel* createTitleLabel() const;
|
QLabel* createTitleLabel() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateScrollBar( double minDepth, double maxDepth );
|
void updateScrollBar( double minDepth, double maxDepth );
|
||||||
// std::map<int, int> calculateTrackWidthsToMatchFrame( int frameWidth ) const;
|
void alignCanvasTops();
|
||||||
// void placeChildWidgets( int frameHeight, int frameWidth );
|
|
||||||
// void positionTitle( int frameWidth );
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotSetMinDepth( int value );
|
void slotSetMinDepth( int value );
|
||||||
|
Loading…
Reference in New Issue
Block a user