Skip to content

Commit

Permalink
Qt6: Avoid insertWidget, use addWidget
Browse files Browse the repository at this point in the history
In Qt6, the insertWidget function checks if the index parameter is valid based on current widgets present in the layout. This is error prone, and use addWidget to avoid manual counting of index.

There are some places where insertWidget is still used, but it will require more work to fix these.
  • Loading branch information
magnesj committed Oct 22, 2024
1 parent df09133 commit 09b6eb7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ApplicationLibCode/Commands/RicCalculatorWidgetCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ QWidget* RicCalculatorWidgetCreator::createWidget( QWidget* parent )
rowSplitter->setContentsMargins( 0, 0, 0, 0 );
rowSplitter->setHandleWidth( 6 );
rowSplitter->setStyleSheet( "QSplitter::handle { image: url(:/SplitterV.png); }" );
rowSplitter->insertWidget( 0, firstRowLeftFrame );
rowSplitter->insertWidget( 1, firstRowRightFrame );
rowSplitter->addWidget( firstRowLeftFrame );
rowSplitter->addWidget( firstRowRightFrame );
rowSplitter->setSizes( QList<int>() << 1 << 1 );
firstRowLayout->addWidget( rowSplitter );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ void RicSummaryPlotEditorWidgetCreator::recursivelyConfigureAndUpdateTopLevelUiO

caf::PdmUiGroup* appearanceGroup = findGroupByKeyword( topLevelUiItems, RiuSummaryCurveDefinitionKeywords::appearance(), uiConfigName );
auto appearanceGroupBox = createGroupBoxWithContent( appearanceGroup, uiConfigName );
m_lowerLeftLayout->insertWidget( 0, appearanceGroupBox );
m_lowerLeftLayout->addWidget( appearanceGroupBox );

caf::PdmUiGroup* nameConfigGroup = findGroupByKeyword( topLevelUiItems, RiuSummaryCurveDefinitionKeywords::nameConfig(), uiConfigName );
auto nameConfigGroupBox = createGroupBoxWithContent( nameConfigGroup, uiConfigName );
m_lowerLeftLayout->insertWidget( 1, nameConfigGroupBox );
m_lowerLeftLayout->addWidget( nameConfigGroupBox );

QMinimizePanel* curveGroup = getOrCreateCurveTreeGroup();
m_lowerLeftLayout->insertWidget( 2, curveGroup, 1 );
m_lowerLeftLayout->addWidget( curveGroup, 1 );
m_lowerLeftLayout->addStretch( 0 );
m_lowerRightLayout->insertWidget( 0, getOrCreatePlotWidget() );
m_lowerRightLayout->addWidget( getOrCreatePlotWidget() );

// Fields at bottom of dialog
configureAndUpdateFields( 1, m_bottomFieldLayout, topLevelUiItems, uiConfigName );
Expand Down Expand Up @@ -155,8 +155,8 @@ QWidget* RicSummaryPlotEditorWidgetCreator::createWidget( QWidget* parent )
m_firstColumnSplitter->setHandleWidth( 6 );
m_firstColumnSplitter->setStyleSheet( "QSplitter::handle { image: url(:/SplitterH.png); }" );

m_firstColumnSplitter->insertWidget( 0, firstRowFrame );
m_firstColumnSplitter->insertWidget( 1, secondRowFrame );
m_firstColumnSplitter->addWidget( firstRowFrame );
m_firstColumnSplitter->addWidget( secondRowFrame );

const int firstRowPixelHeight = 500;
const int secondRowPixelHeight = 300;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ QWidget* RiuSummaryVectorSelectionWidgetCreator::createWidget( QWidget* parent )
rowSplitter->setContentsMargins( 0, 0, 0, 0 );
rowSplitter->setHandleWidth( 6 );
rowSplitter->setStyleSheet( "QSplitter::handle { image: url(:/SplitterV.png); }" );
rowSplitter->insertWidget( 0, firstRowLeftFrame );
rowSplitter->insertWidget( 1, firstRowRightFrame );
rowSplitter->addWidget( firstRowLeftFrame );
rowSplitter->addWidget( firstRowRightFrame );
rowSplitter->setSizes( QList<int>() << 1 << 1 );
firstRowLayout->addWidget( rowSplitter );

Expand Down
6 changes: 3 additions & 3 deletions Fwk/AppFwk/cafUserInterface/cafPdmUiComboBoxEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void PdmUiComboBoxEditor::configureAndUpdateUi( const QString& uiConfigName )
m_nextItemButton->setToolTip( "Next" );
}

m_layout->insertWidget( 1, m_previousItemButton );
m_layout->insertWidget( 2, m_nextItemButton );
m_layout->addWidget( m_previousItemButton );
m_layout->addWidget( m_nextItemButton );

{
QIcon toolButtonIcon;
Expand Down Expand Up @@ -283,7 +283,7 @@ void PdmUiComboBoxEditor::configureAndUpdateUi( const QString& uiConfigName )
QString tooltipText = uiField()->isAutoValueEnabled() ? UiAppearanceSettings::globaleValueButtonText()
: UiAppearanceSettings::localValueButtonText();
m_autoValueToolButton->setToolTip( tooltipText );
m_layout->insertWidget( 3, m_autoValueToolButton );
m_layout->addWidget(m_autoValueToolButton );
m_autoValueToolButton->show();
}
else
Expand Down
2 changes: 1 addition & 1 deletion Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void PdmUiLineEditor::configureAndUpdateUi( const QString& uiConfigName )
: UiAppearanceSettings::localValueButtonText();
m_autoValueToolButton->setToolTip( tooltipText );

m_layout->insertWidget( 1, m_autoValueToolButton );
m_layout->addWidget( m_autoValueToolButton );
m_autoValueToolButton->show();
}
else
Expand Down
2 changes: 1 addition & 1 deletion Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void PdmUiPropertyView::showProperties( PdmObjectHandle* object )

CAF_ASSERT( propertyWidget );

this->m_placeHolderLayout->insertWidget( 0, propertyWidget );
this->m_placeHolderLayout->addWidget( propertyWidget );

// Add stretch to make sure the property widget is not stretched
this->m_placeHolderLayout->insertStretch( -1, 1 );
Expand Down

0 comments on commit 09b6eb7

Please sign in to comment.