mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#13243 Always recreate non-field labels and buttons
This commit is contained in:
1 parent
569d4dfc93
commit
760137730b
2 files changed
+33
-128
No files matched your search
@@ -178,7 +178,7 @@ int caf::PdmUiFormLayoutObjectEditor::recursivelyConfigureAndUpdateUiOrderingInG
|
||||
}
|
||||
else if ( auto* label = dynamic_cast<PdmUiLabel*>( currentItem ) )
|
||||
{
|
||||
if ( auto qLabel = findOrCreateLabel( containerWidgetWithGridLayout, label, uiConfigName ) )
|
||||
if ( auto qLabel = createLabel( containerWidgetWithGridLayout, *label, uiConfigName ) )
|
||||
{
|
||||
parentLayout->addWidget( qLabel, currentRowIndex, currentColumn, 1, itemColumnSpan, Qt::AlignTop );
|
||||
currentColumn += itemColumnSpan;
|
||||
@@ -191,7 +191,7 @@ int caf::PdmUiFormLayoutObjectEditor::recursivelyConfigureAndUpdateUiOrderingInG
|
||||
}
|
||||
else if ( auto* button = dynamic_cast<PdmUiButton*>( currentItem ) )
|
||||
{
|
||||
if ( auto qButton = findOrCreateButton( containerWidgetWithGridLayout, button, uiConfigName ) )
|
||||
if ( auto qButton = createButton( containerWidgetWithGridLayout, *button, uiConfigName ) )
|
||||
{
|
||||
parentLayout->addWidget( qButton, currentRowIndex, currentColumn, 1, itemColumnSpan, button->alignment() );
|
||||
currentColumn += itemColumnSpan;
|
||||
@@ -433,104 +433,44 @@ QMinimizePanel* caf::PdmUiFormLayoutObjectEditor::findOrCreateGroupBox( QWidget*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QLabel* caf::PdmUiFormLayoutObjectEditor::findOrCreateLabel( QWidget* parent, PdmUiLabel* label, const QString& uiConfigName )
|
||||
QLabel* caf::PdmUiFormLayoutObjectEditor::createLabel( QWidget* parent, const PdmUiLabel& label, const QString& uiConfigName )
|
||||
{
|
||||
QString labelKey = label->uiName( uiConfigName );
|
||||
QLabel* qLabel = nullptr;
|
||||
QLabel* qLabel = new QLabel( parent );
|
||||
qLabel->setText( label.uiName( uiConfigName ) );
|
||||
qLabel->setWordWrap( true );
|
||||
|
||||
// Find or create label
|
||||
auto it = m_labels.find( labelKey );
|
||||
if ( it == m_labels.end() )
|
||||
{
|
||||
auto newLabelIt = m_newLabels.find( labelKey );
|
||||
if ( newLabelIt != m_newLabels.end() )
|
||||
{
|
||||
auto message = "Detected duplicate label with text: " + labelKey;
|
||||
CAF_PDM_LOG_ERROR( QString( "UI Form Layout Editor: %1. This may cause layout issues. Ensure unique label "
|
||||
"texts in PdmUiOrdering." )
|
||||
.arg( message ) );
|
||||
}
|
||||
|
||||
qLabel = new QLabel( parent );
|
||||
qLabel->setText( label->uiName( uiConfigName ) );
|
||||
qLabel->setWordWrap( true );
|
||||
qLabel->setObjectName( labelKey );
|
||||
|
||||
m_newLabels[labelKey] = qLabel;
|
||||
}
|
||||
else
|
||||
{
|
||||
qLabel = it->second;
|
||||
CAF_ASSERT( qLabel );
|
||||
m_newLabels[labelKey] = qLabel;
|
||||
}
|
||||
|
||||
// Update the text to support dynamic label content
|
||||
qLabel->setText( label->uiName( uiConfigName ) );
|
||||
m_labels.push_back( qLabel );
|
||||
return qLabel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QPushButton* caf::PdmUiFormLayoutObjectEditor::findOrCreateButton( QWidget* parent,
|
||||
PdmUiButton* button,
|
||||
const QString& uiConfigName )
|
||||
QPushButton* caf::PdmUiFormLayoutObjectEditor::createButton( QWidget* parent,
|
||||
const PdmUiButton& button,
|
||||
const QString& uiConfigName )
|
||||
{
|
||||
QString buttonKey = button->uiName( uiConfigName );
|
||||
QPushButton* qButton = nullptr;
|
||||
QPushButton* qButton = new QPushButton( parent );
|
||||
qButton->setText( button.uiName( uiConfigName ) );
|
||||
|
||||
// Find or create button
|
||||
auto it = m_buttons.find( buttonKey );
|
||||
if ( it == m_buttons.end() )
|
||||
{
|
||||
auto newButtonIt = m_newButtons.find( buttonKey );
|
||||
if ( newButtonIt != m_newButtons.end() )
|
||||
{
|
||||
auto message = "Detected duplicate button with text: " + buttonKey;
|
||||
CAF_PDM_LOG_ERROR( QString( "UI Form Layout Editor: %1. This may cause layout issues. Ensure unique button "
|
||||
"texts in PdmUiOrdering." )
|
||||
.arg( message ) );
|
||||
}
|
||||
// Set size policy to size the button to its content rather than fill available space
|
||||
qButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
|
||||
|
||||
qButton = new QPushButton( parent );
|
||||
qButton->setText( button->uiName( uiConfigName ) );
|
||||
qButton->setObjectName( buttonKey );
|
||||
|
||||
// Set size policy to size the button to its content rather than fill available space
|
||||
qButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
|
||||
|
||||
// Set icon if available
|
||||
auto icon = button->uiIcon( uiConfigName );
|
||||
if ( icon && !icon->isNull() )
|
||||
{
|
||||
qButton->setIcon( *icon );
|
||||
}
|
||||
|
||||
// Connect callback if available
|
||||
auto callback = button->clickCallback();
|
||||
if ( callback )
|
||||
{
|
||||
QObject::connect( qButton, &QPushButton::clicked, [callback]() { callback(); } );
|
||||
}
|
||||
|
||||
m_newButtons[buttonKey] = qButton;
|
||||
}
|
||||
else
|
||||
{
|
||||
qButton = it->second;
|
||||
CAF_ASSERT( qButton );
|
||||
m_newButtons[buttonKey] = qButton;
|
||||
}
|
||||
|
||||
// Update the text and icon to support dynamic button content
|
||||
qButton->setText( button->uiName( uiConfigName ) );
|
||||
auto icon = button->uiIcon( uiConfigName );
|
||||
// Set icon if available
|
||||
auto icon = button.uiIcon( uiConfigName );
|
||||
if ( icon && !icon->isNull() )
|
||||
{
|
||||
qButton->setIcon( *icon );
|
||||
}
|
||||
|
||||
// Connect callback if available
|
||||
auto callback = button.clickCallback();
|
||||
if ( callback )
|
||||
{
|
||||
QObject::connect( qButton, &QPushButton::clicked, [callback]() { callback(); } );
|
||||
}
|
||||
|
||||
m_buttons.push_back( qButton );
|
||||
return qButton;
|
||||
}
|
||||
|
||||
@@ -667,8 +607,6 @@ void caf::PdmUiFormLayoutObjectEditor::cleanupBeforeSettingPdmObject()
|
||||
m_fieldViews.clear();
|
||||
|
||||
m_newGroupBoxes.clear();
|
||||
m_newLabels.clear();
|
||||
m_newButtons.clear();
|
||||
|
||||
std::map<QString, QPointer<QMinimizePanel>>::iterator groupIt;
|
||||
for ( groupIt = m_groupBoxes.begin(); groupIt != m_groupBoxes.end(); ++groupIt )
|
||||
@@ -686,28 +624,22 @@ void caf::PdmUiFormLayoutObjectEditor::cleanupBeforeSettingPdmObject()
|
||||
|
||||
m_groupBoxes.clear();
|
||||
|
||||
std::map<QString, QPointer<QLabel>>::iterator labelIt;
|
||||
for ( labelIt = m_labels.begin(); labelIt != m_labels.end(); ++labelIt )
|
||||
for ( auto& label : m_labels )
|
||||
{
|
||||
QLabel* label = labelIt->second;
|
||||
if ( label )
|
||||
{
|
||||
delete label;
|
||||
}
|
||||
}
|
||||
|
||||
m_labels.clear();
|
||||
|
||||
std::map<QString, QPointer<QPushButton>>::iterator buttonIt;
|
||||
for ( buttonIt = m_buttons.begin(); buttonIt != m_buttons.end(); ++buttonIt )
|
||||
for ( auto& button : m_buttons )
|
||||
{
|
||||
QPushButton* button = buttonIt->second;
|
||||
if ( button )
|
||||
{
|
||||
delete button;
|
||||
}
|
||||
}
|
||||
|
||||
m_buttons.clear();
|
||||
|
||||
// Note: Layouts are now managed by Qt's parent-child ownership system.
|
||||
@@ -735,8 +667,6 @@ void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi( const QString& uiCo
|
||||
|
||||
// Set all group Boxes to be unvisited
|
||||
m_newGroupBoxes.clear();
|
||||
m_newLabels.clear();
|
||||
m_newButtons.clear();
|
||||
|
||||
recursivelyConfigureAndUpdateTopLevelUiOrdering( config, uiConfigName );
|
||||
|
||||
@@ -774,32 +704,6 @@ void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi( const QString& uiCo
|
||||
}
|
||||
m_groupBoxes = m_newGroupBoxes;
|
||||
|
||||
// Clean up unused labels
|
||||
std::map<QString, QPointer<QLabel>>::iterator labelMapIt;
|
||||
for ( labelMapIt = m_labels.begin(); labelMapIt != m_labels.end(); ++labelMapIt )
|
||||
{
|
||||
std::map<QString, QPointer<QLabel>>::iterator it = m_newLabels.find( labelMapIt->first );
|
||||
if ( it == m_newLabels.end() )
|
||||
{
|
||||
// The old label is not present anymore, get rid of it
|
||||
if ( !labelMapIt->second.isNull() ) delete labelMapIt->second;
|
||||
}
|
||||
}
|
||||
m_labels = m_newLabels;
|
||||
|
||||
// Clean up unused buttons
|
||||
std::map<QString, QPointer<QPushButton>>::iterator buttonMapIt;
|
||||
for ( buttonMapIt = m_buttons.begin(); buttonMapIt != m_buttons.end(); ++buttonMapIt )
|
||||
{
|
||||
std::map<QString, QPointer<QPushButton>>::iterator it = m_newButtons.find( buttonMapIt->first );
|
||||
if ( it == m_newButtons.end() )
|
||||
{
|
||||
// The old button is not present anymore, get rid of it
|
||||
if ( !buttonMapIt->second.isNull() ) delete buttonMapIt->second;
|
||||
}
|
||||
}
|
||||
m_buttons = m_newButtons;
|
||||
|
||||
// Notify pdm object when widgets have been created
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj( pdmObject() );
|
||||
if ( uiObject )
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class QMinimizePanel;
|
||||
class QGridLayout;
|
||||
@@ -90,8 +91,6 @@ protected:
|
||||
int itemColumnSpan );
|
||||
|
||||
QMinimizePanel* findOrCreateGroupBox( QWidget* parent, PdmUiGroup* group, const QString& uiConfigName );
|
||||
QLabel* findOrCreateLabel( QWidget* parent, PdmUiLabel* label, const QString& uiConfigName );
|
||||
QPushButton* findOrCreateButton( QWidget* parent, PdmUiButton* button, const QString& uiConfigName );
|
||||
PdmUiFieldEditorHandle* findOrCreateFieldEditor( QWidget* parent, PdmUiFieldHandle* field, const QString& uiConfigName );
|
||||
|
||||
static void ensureWidgetContainsEmptyGridLayout( QWidget* containerWidget, QMargins contentMargins = QMargins() );
|
||||
@@ -109,16 +108,18 @@ private:
|
||||
std::set<QString>* fieldKeywordNames,
|
||||
std::set<QString>* groupNames );
|
||||
|
||||
QLabel* createLabel( QWidget* parent, const PdmUiLabel& label, const QString& uiConfigName );
|
||||
QPushButton* createButton( QWidget* parent, const PdmUiButton& button, const QString& uiConfigName );
|
||||
|
||||
private:
|
||||
std::map<PdmFieldHandle*, PdmUiFieldEditorHandle*> m_fieldViews;
|
||||
std::set<PdmFieldHandle*> m_usedFields; ///< used temporarily to store the new(complete) set of used fields
|
||||
std::map<QString, QPointer<QMinimizePanel>> m_groupBoxes;
|
||||
std::map<QString, QPointer<QMinimizePanel>> m_newGroupBoxes; ///< used temporarily to store the new(complete) set of
|
||||
///< group boxes
|
||||
std::map<QString, QPointer<QLabel>> m_labels;
|
||||
std::map<QString, QPointer<QLabel>> m_newLabels; ///< used temporarily to store the new(complete) set of labels
|
||||
std::map<QString, QPointer<QPushButton>> m_buttons;
|
||||
std::map<QString, QPointer<QPushButton>> m_newButtons; ///< used temporarily to store the new(complete) set of buttons
|
||||
std::vector<QPointer<QLabel>> m_labels;
|
||||
std::vector<QPointer<QPushButton>> m_buttons;
|
||||
|
||||
std::map<QString, std::map<QString, bool>> m_objectKeywordGroupUiNameExpandedState;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user