Fix legend update and remove Qt warnings

This commit is contained in:
Gaute Lindkvist 2019-10-04 10:26:55 +02:00
parent 09388b22c8
commit 10e55d3e5f
2 changed files with 31 additions and 23 deletions

View File

@ -32,7 +32,6 @@
#include "RiuWellLogTrack.h" #include "RiuWellLogTrack.h"
#include "cafCmdFeatureMenuBuilder.h" #include "cafCmdFeatureMenuBuilder.h"
#include "cafQShortenedLabel.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
#include "cvfAssert.h" #include "cvfAssert.h"
@ -95,7 +94,7 @@ RiuWellLogPlot::RiuWellLogPlot( RimWellLogPlot* plotDefinition, QWidget* parent
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition ); new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
this->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
connect( m_scrollBar, SIGNAL( valueChanged( int ) ), this, SLOT( slotSetMinDepth( int ) ) ); connect( m_scrollBar, SIGNAL( valueChanged( int ) ), this, SLOT( slotSetMinDepth( int ) ) );
@ -135,7 +134,6 @@ void RiuWellLogPlot::insertTrackPlot( RiuWellLogTrack* trackPlot, size_t index )
legendColumns = 0; // unlimited legendColumns = 0; // unlimited
} }
legend->setMaxColumns( legendColumns ); legend->setMaxColumns( legendColumns );
legend->horizontalScrollBar()->setVisible( false ); legend->horizontalScrollBar()->setVisible( false );
legend->verticalScrollBar()->setVisible( false ); legend->verticalScrollBar()->setVisible( false );
@ -261,10 +259,9 @@ void RiuWellLogPlot::keyPressEvent( QKeyEvent* keyEvent )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::QShortenedLabel* RiuWellLogPlot::createTitleLabel() const QLabel* RiuWellLogPlot::createTitleLabel() const
{ {
caf::QShortenedLabel* plotTitle = new caf::QShortenedLabel( nullptr ); QLabel* plotTitle = new QLabel( "PLOT TITLE HERE", nullptr );
plotTitle->setText( "PLOT TITLE HERE" );
RiaApplication* app = RiaApplication::instance(); RiaApplication* app = RiaApplication::instance();
@ -277,10 +274,19 @@ caf::QShortenedLabel* RiuWellLogPlot::createTitleLabel() const
plotTitle->setVisible( m_plotDefinition->isPlotTitleVisible() ); plotTitle->setVisible( m_plotDefinition->isPlotTitleVisible() );
plotTitle->setAlignment( Qt::AlignHCenter ); plotTitle->setAlignment( Qt::AlignHCenter );
plotTitle->setWordWrap( true ); plotTitle->setWordWrap( true );
plotTitle->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred ); plotTitle->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
return plotTitle; return plotTitle;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::resizeEvent( QResizeEvent* event )
{
QWidget::resizeEvent( event );
updateChildrenLayout();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -341,15 +347,21 @@ void RiuWellLogPlot::reinsertTracks()
{ {
if ( m_trackPlots[tIdx]->isRimTrackVisible() ) if ( m_trackPlots[tIdx]->isRimTrackVisible() )
{ {
m_trackLayout->addWidget( m_legends[tIdx], 0, static_cast<int>( visibleIndex ) );
m_trackLayout->addWidget( m_trackPlots[tIdx], 1, static_cast<int>( visibleIndex ) );
if ( m_plotDefinition->areTrackLegendsVisible() ) if ( m_plotDefinition->areTrackLegendsVisible() )
{ {
m_trackPlots[tIdx]->updateLegend();
int legendColumns = 1; int legendColumns = 1;
if ( m_plotDefinition->areTrackLegendsHorizontal() ) if ( m_plotDefinition->areTrackLegendsHorizontal() )
{ {
legendColumns = 0; // unlimited legendColumns = 0; // unlimited
} }
m_legends[tIdx]->setMaxColumns( legendColumns ); m_legends[tIdx]->setMaxColumns( legendColumns );
m_trackPlots[tIdx]->updateLegend();
int minimumHeight = m_legends[tIdx]->heightForWidth( m_trackPlots[tIdx]->width() );
m_legends[tIdx]->setMinimumHeight( minimumHeight );
m_legends[tIdx]->show(); m_legends[tIdx]->show();
} }
else else
@ -361,10 +373,12 @@ void RiuWellLogPlot::reinsertTracks()
m_trackPlots[tIdx]->enableDepthAxisLabelsAndTicks( visibleIndex == 0 ); m_trackPlots[tIdx]->enableDepthAxisLabelsAndTicks( visibleIndex == 0 );
m_trackPlots[tIdx]->show(); m_trackPlots[tIdx]->show();
m_trackLayout->addWidget( m_legends[tIdx], 0, static_cast<int>( visibleIndex ) ); int widthScaleFactor = m_trackPlots[tIdx]->widthScaleFactor();
m_trackLayout->addWidget( m_trackPlots[tIdx], 1, static_cast<int>( visibleIndex ) ); if ( visibleIndex == 0 )
{
m_trackLayout->setColumnStretch( visibleIndex++, m_trackPlots[tIdx]->widthScaleFactor() ); widthScaleFactor += 1; // Give it a bit extra room due to depth axis
}
m_trackLayout->setColumnStretch( visibleIndex, widthScaleFactor );
m_trackLayout->setRowStretch( 1, 1 ); m_trackLayout->setRowStretch( 1, 1 );
visibleIndex++; visibleIndex++;
} }
@ -387,10 +401,6 @@ void RiuWellLogPlot::clearTrackLayout()
while ( ( item = m_trackLayout->takeAt( 0 ) ) != 0 ) while ( ( item = m_trackLayout->takeAt( 0 ) ) != 0 )
{ {
} }
QWidget().setLayout( m_trackLayout );
QPointer<QGridLayout> newGridLayout = new QGridLayout( m_trackFrame );
m_trackLayout.swap( newGridLayout );
newGridLayout->deleteLater();
} }
} }

View File

@ -36,14 +36,10 @@ class RimWellLogPlot;
class RiuWellLogTrack; class RiuWellLogTrack;
class QFocusEvent; class QFocusEvent;
class QLabel;
class QScrollBar; class QScrollBar;
class QwtLegend; class QwtLegend;
namespace caf
{
class QShortenedLabel;
}
//================================================================================================== //==================================================================================================
// //
// RiuWellLogPlot // RiuWellLogPlot
@ -78,7 +74,9 @@ protected:
void contextMenuEvent( QContextMenuEvent* ) override; void contextMenuEvent( QContextMenuEvent* ) override;
void keyPressEvent( QKeyEvent* keyEvent ) override; void keyPressEvent( QKeyEvent* keyEvent ) override;
caf::QShortenedLabel* createTitleLabel() const; QLabel* createTitleLabel() const;
void resizeEvent( QResizeEvent* event ) override;
private: private:
void updateScrollBar( double minDepth, double maxDepth ); void updateScrollBar( double minDepth, double maxDepth );
@ -94,7 +92,7 @@ protected:
QPointer<QHBoxLayout> m_plotLayout; QPointer<QHBoxLayout> m_plotLayout;
QPointer<QFrame> m_trackFrame; QPointer<QFrame> m_trackFrame;
QPointer<QGridLayout> m_trackLayout; QPointer<QGridLayout> m_trackLayout;
QPointer<caf::QShortenedLabel> m_plotTitle; QPointer<QLabel> m_plotTitle;
QPointer<QVBoxLayout> m_scrollBarLayout; QPointer<QVBoxLayout> m_scrollBarLayout;
QScrollBar* m_scrollBar; QScrollBar* m_scrollBar;
QList<QPointer<QwtLegend>> m_legends; QList<QPointer<QwtLegend>> m_legends;