mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
A hidden label is never added to a layout, so it stayed parented to the group box it was created in. When the field moved directly to another group, the old group box was deleted together with the label, and the next update hit a null label in PdmUiCheckBoxEditor. Add GroupVisibilityByEnum to cafTestApplication to reproduce the crash.
225 lines
9.3 KiB
C++
225 lines
9.3 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2017- Statoil ASA
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiuSummaryVectorSelectionWidgetCreator.h"
|
|
|
|
#include "RiuSummaryCurveDefinitionKeywords.h"
|
|
#include "RiuSummaryVectorSelectionUi.h"
|
|
|
|
#include "cafPdmUiFieldEditorHandle.h"
|
|
#include "cafPdmUiGroup.h"
|
|
|
|
#include "QMinimizePanel.h"
|
|
|
|
#include <QBoxLayout>
|
|
#include <QFrame>
|
|
#include <QSplitter>
|
|
#include <memory>
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiuSummaryVectorSelectionWidgetCreator::RiuSummaryVectorSelectionWidgetCreator()
|
|
{
|
|
m_summaryAddressSelection = std::make_unique<RiuSummaryVectorSelectionUi>();
|
|
|
|
setPdmObject( m_summaryAddressSelection.get() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiuSummaryVectorSelectionWidgetCreator::~RiuSummaryVectorSelectionWidgetCreator()
|
|
{
|
|
setPdmObject( nullptr );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiuSummaryVectorSelectionUi* RiuSummaryVectorSelectionWidgetCreator::summaryAddressSelection() const
|
|
{
|
|
return m_summaryAddressSelection.get();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiuSummaryVectorSelectionWidgetCreator::recursivelyConfigureAndUpdateTopLevelUiOrdering( const caf::PdmUiOrdering& topLevelUiOrdering,
|
|
const QString& uiConfigName )
|
|
{
|
|
if ( !m_firstRowLeftLayout || !m_firstRowRightLayout ) return;
|
|
|
|
const std::vector<caf::PdmUiItem*>& topLevelUiItems = topLevelUiOrdering.uiItems();
|
|
|
|
for ( size_t i = 0; i < topLevelUiItems.size(); ++i )
|
|
{
|
|
if ( topLevelUiItems[i]->isUiHidden( uiConfigName ) ) continue;
|
|
|
|
if ( topLevelUiItems[i]->isUiGroup() )
|
|
{
|
|
caf::PdmUiGroup* group = static_cast<caf::PdmUiGroup*>( topLevelUiItems[i] );
|
|
auto groupBox = createGroupBoxWithContent( group, uiConfigName );
|
|
|
|
bool isSources = group->keyword() == RiuSummaryCurveDefinitionKeywords::sources();
|
|
bool isSummaryTypes = group->keyword() == RiuSummaryCurveDefinitionKeywords::summaryTypes();
|
|
bool isSummaries = group->keyword() == RiuSummaryCurveDefinitionKeywords::summaries();
|
|
bool isDynamicGroup = !isSources && !isSummaryTypes && !isSummaries;
|
|
bool leftColumn = isSources || isSummaryTypes;
|
|
|
|
if ( isSummaryTypes || isDynamicGroup )
|
|
{
|
|
groupBox->setFixedWidth( 170 );
|
|
}
|
|
|
|
if ( leftColumn )
|
|
m_firstRowLeftLayout->addWidget( groupBox );
|
|
else
|
|
m_firstRowRightLayout->addWidget( groupBox );
|
|
|
|
// Add group boxes until summaries are detected
|
|
|
|
if ( group->keyword() == RiuSummaryCurveDefinitionKeywords::summaries() ) break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QWidget* RiuSummaryVectorSelectionWidgetCreator::createWidget( QWidget* parent )
|
|
{
|
|
QWidget* widget = new QWidget( parent );
|
|
|
|
QVBoxLayout* mainLayout = new QVBoxLayout();
|
|
mainLayout->setContentsMargins( 5, 5, 5, 5 );
|
|
widget->setLayout( mainLayout );
|
|
|
|
QFrame* firstRowFrame = new QFrame( widget );
|
|
QHBoxLayout* firstRowLayout = new QHBoxLayout;
|
|
firstRowLayout->setContentsMargins( 0, 0, 0, 0 );
|
|
firstRowFrame->setLayout( firstRowLayout );
|
|
|
|
QFrame* firstRowLeftFrame = new QFrame( widget );
|
|
m_firstRowLeftLayout = new QHBoxLayout;
|
|
m_firstRowLeftLayout->setContentsMargins( 0, 0, 0, 0 );
|
|
firstRowLeftFrame->setLayout( m_firstRowLeftLayout );
|
|
|
|
QFrame* firstRowRightFrame = new QFrame( widget );
|
|
m_firstRowRightLayout = new QHBoxLayout;
|
|
m_firstRowRightLayout->setContentsMargins( 0, 0, 0, 0 );
|
|
firstRowRightFrame->setLayout( m_firstRowRightLayout );
|
|
|
|
QSplitter* rowSplitter = new QSplitter( Qt::Horizontal );
|
|
rowSplitter->setContentsMargins( 0, 0, 0, 0 );
|
|
rowSplitter->setHandleWidth( 6 );
|
|
rowSplitter->setStyleSheet( "QSplitter::handle { image: url(:/SplitterV.png); }" );
|
|
rowSplitter->addWidget( firstRowLeftFrame );
|
|
rowSplitter->addWidget( firstRowRightFrame );
|
|
rowSplitter->setSizes( QList<int>() << 1 << 1 );
|
|
firstRowLayout->addWidget( rowSplitter );
|
|
|
|
mainLayout->addWidget( rowSplitter );
|
|
|
|
return widget;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiuSummaryVectorSelectionWidgetCreator::configureAndUpdateFields( int widgetStartIndex,
|
|
QBoxLayout* layout,
|
|
const std::vector<caf::PdmUiItem*>& uiItems,
|
|
const QString& uiConfigName )
|
|
{
|
|
int currentWidgetIndex = widgetStartIndex;
|
|
|
|
for ( size_t i = 0; i < uiItems.size(); ++i )
|
|
{
|
|
if ( uiItems[i]->isUiHidden( uiConfigName ) ) continue;
|
|
if ( uiItems[i]->isUiGroup() ) continue;
|
|
|
|
{
|
|
caf::PdmUiFieldHandle* field = dynamic_cast<caf::PdmUiFieldHandle*>( uiItems[i] );
|
|
|
|
caf::PdmUiFieldEditorHandle* fieldEditor = findOrCreateFieldEditor( widget(), field, uiConfigName );
|
|
|
|
if ( fieldEditor )
|
|
{
|
|
// Place the widget(s) into the correct parent and layout
|
|
QWidget* fieldCombinedWidget = fieldEditor->combinedWidget();
|
|
|
|
if ( fieldCombinedWidget )
|
|
{
|
|
fieldCombinedWidget->setParent( widget() );
|
|
layout->insertWidget( currentWidgetIndex++, fieldCombinedWidget );
|
|
}
|
|
else
|
|
{
|
|
caf::PdmUiItemInfo::LabelPosition labelPos = field->uiLabelPosition( uiConfigName );
|
|
|
|
QWidget* fieldEditorWidget = fieldEditor->editorWidget();
|
|
|
|
if ( labelPos != caf::PdmUiItemInfo::LabelPosition::HIDDEN )
|
|
{
|
|
QWidget* fieldLabelWidget = fieldEditor->labelWidget();
|
|
if ( fieldLabelWidget )
|
|
{
|
|
fieldLabelWidget->setParent( widget() );
|
|
|
|
layout->insertWidget( currentWidgetIndex++, fieldLabelWidget );
|
|
|
|
fieldLabelWidget->show();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ( auto fieldLabelWidget = fieldEditor->labelWidget() )
|
|
{
|
|
// Reparent so the label is not deleted with a previous group box
|
|
fieldLabelWidget->setParent( widget() );
|
|
fieldLabelWidget->hide();
|
|
}
|
|
}
|
|
|
|
if ( fieldEditorWidget )
|
|
{
|
|
fieldEditorWidget->setParent( widget() ); // To make sure this widget has the current
|
|
// group box as parent.
|
|
|
|
layout->insertWidget( currentWidgetIndex++, fieldEditorWidget );
|
|
}
|
|
}
|
|
|
|
fieldEditor->updateUi( uiConfigName );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QMinimizePanel* RiuSummaryVectorSelectionWidgetCreator::createGroupBoxWithContent( caf::PdmUiGroup* group, const QString& uiConfigName )
|
|
{
|
|
QMinimizePanel* groupBox = findOrCreateGroupBox( widget(), group, uiConfigName );
|
|
|
|
recursivelyConfigureAndUpdateUiOrderingInGridLayout( *group, groupBox->contentFrame(), uiConfigName );
|
|
return groupBox;
|
|
}
|