mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4388 AppFwk : Remove problematic setUiField() calls
setUiField() call used to keep track of which fields that is retained when updating an editor. Replace this workflow with a set of the ones that are used, and use this set to clean up unused editors afterwards.
This commit is contained in:
parent
fe0624e304
commit
088b5513a7
@ -47,7 +47,7 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmUiFieldEditorHandle* caf::PdmUiFieldEditorHelper::fieldEditorForField(caf::PdmUiFieldHandle* field, const QString& uiConfigName)
|
||||
caf::PdmUiFieldEditorHandle* caf::PdmUiFieldEditorHelper::createFieldEditorForField(caf::PdmUiFieldHandle* field, const QString& uiConfigName)
|
||||
{
|
||||
caf::PdmUiFieldEditorHandle* fieldEditor = nullptr;
|
||||
|
||||
|
@ -50,7 +50,7 @@ namespace caf
|
||||
class PdmUiFieldEditorHelper
|
||||
{
|
||||
public:
|
||||
static PdmUiFieldEditorHandle* fieldEditorForField(PdmUiFieldHandle* fieldHandle, const QString& uiConfigName);
|
||||
static PdmUiFieldEditorHandle* createFieldEditorForField(PdmUiFieldHandle* fieldHandle, const QString& uiConfigName);
|
||||
};
|
||||
|
||||
|
||||
|
@ -176,16 +176,18 @@ int caf::PdmUiFormLayoutObjectEditor::recursivelyConfigureAndUpdateUiOrderingInG
|
||||
}
|
||||
else
|
||||
{
|
||||
// Also assign required item space that isn't taken up by field and label
|
||||
spareColumnsToAssign += minimumItemColumnSpan - (minimumLabelColumnSpan + minimumFieldColumnSpan);
|
||||
|
||||
PdmUiFieldEditorHandle* fieldEditor = nullptr;
|
||||
PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*>(currentItem);
|
||||
|
||||
PdmUiFieldEditorHandle* fieldEditor = findOrCreateFieldEditor(containerWidgetWithGridLayout, field, uiConfigName);
|
||||
if (field) fieldEditor = findOrCreateFieldEditor(containerWidgetWithGridLayout, field, uiConfigName);
|
||||
|
||||
if (fieldEditor)
|
||||
{
|
||||
fieldEditor->setUiField(field);
|
||||
// Mark this field as used in the editor
|
||||
m_usedFields.insert(field->fieldHandle());
|
||||
|
||||
// Also assign required item space that isn't taken up by field and label
|
||||
spareColumnsToAssign += minimumItemColumnSpan - (minimumLabelColumnSpan + minimumFieldColumnSpan);
|
||||
|
||||
// Place the widget(s) into the correct parent and layout
|
||||
QWidget* fieldCombinedWidget = fieldEditor->combinedWidget();
|
||||
@ -390,11 +392,12 @@ caf::PdmUiFieldEditorHandle* caf::PdmUiFormLayoutObjectEditor::findOrCreateField
|
||||
|
||||
if (it == m_fieldViews.end())
|
||||
{
|
||||
fieldEditor = PdmUiFieldEditorHelper::fieldEditorForField(field, uiConfigName);
|
||||
fieldEditor = PdmUiFieldEditorHelper::createFieldEditorForField(field, uiConfigName);
|
||||
|
||||
if (fieldEditor)
|
||||
{
|
||||
m_fieldViews[field->fieldHandle()] = fieldEditor;
|
||||
fieldEditor->setUiField(field);
|
||||
fieldEditor->createWidgets(parent);
|
||||
}
|
||||
else
|
||||
@ -497,11 +500,8 @@ void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi(const QString& uiCon
|
||||
}
|
||||
|
||||
// Set all fieldViews to be unvisited
|
||||
std::map<PdmFieldHandle*, PdmUiFieldEditorHandle*>::iterator it;
|
||||
for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it)
|
||||
{
|
||||
it->second->setUiField(nullptr);
|
||||
}
|
||||
|
||||
m_usedFields.clear();
|
||||
|
||||
// Set all group Boxes to be unvisited
|
||||
m_newGroupBoxes.clear();
|
||||
@ -511,13 +511,13 @@ void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi(const QString& uiCon
|
||||
// Remove all fieldViews not mentioned by the configuration from the layout
|
||||
|
||||
std::vector<PdmFieldHandle*> fvhToRemoveFromMap;
|
||||
for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it)
|
||||
for (auto oldFvIt = m_fieldViews.begin(); oldFvIt != m_fieldViews.end(); ++oldFvIt)
|
||||
{
|
||||
if (it->second->uiField() == nullptr)
|
||||
if (m_usedFields.count(oldFvIt->first) == 0)
|
||||
{
|
||||
PdmUiFieldEditorHandle* fvh = it->second;
|
||||
delete fvh;
|
||||
fvhToRemoveFromMap.push_back(it->first);
|
||||
// The old field editor is not present anymore, get rid of it
|
||||
delete oldFvIt->second;
|
||||
fvhToRemoveFromMap.push_back(oldFvIt->first);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,7 @@ private:
|
||||
|
||||
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, std::map<QString, bool> > m_objectKeywordGroupUiNameExpandedState;
|
||||
|
@ -396,12 +396,8 @@ void PdmUiTableViewQModel::setArrayFieldAndBuildEditors(PdmChildArrayFieldHandle
|
||||
|
||||
const std::vector<PdmUiItem*>& uiItems = configForFirstObject.uiItems();
|
||||
|
||||
// Set all fieldViews to be unvisited
|
||||
std::map<QString, PdmUiFieldEditorHandle*>::iterator it;
|
||||
for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it)
|
||||
{
|
||||
it->second->setUiField(nullptr);
|
||||
}
|
||||
|
||||
std::set<QString> usedFieldKeywords;
|
||||
|
||||
m_modelColumnIndexToFieldIndex.clear();
|
||||
|
||||
@ -416,14 +412,15 @@ void PdmUiTableViewQModel::setArrayFieldAndBuildEditors(PdmChildArrayFieldHandle
|
||||
PdmUiFieldEditorHandle* fieldEditor = nullptr;
|
||||
|
||||
// Find or create FieldEditor
|
||||
it = m_fieldEditors.find(field->fieldHandle()->keyword());
|
||||
auto it = m_fieldEditors.find(field->fieldHandle()->keyword());
|
||||
|
||||
if (it == m_fieldEditors.end())
|
||||
{
|
||||
fieldEditor = PdmUiFieldEditorHelper::fieldEditorForField(field, configName);
|
||||
fieldEditor = PdmUiFieldEditorHelper::createFieldEditorForField(field, configName);
|
||||
|
||||
if (fieldEditor)
|
||||
{
|
||||
fieldEditor->setUiField(field);
|
||||
m_fieldEditors[field->fieldHandle()->keyword()] = fieldEditor;
|
||||
}
|
||||
}
|
||||
@ -434,7 +431,7 @@ void PdmUiTableViewQModel::setArrayFieldAndBuildEditors(PdmChildArrayFieldHandle
|
||||
|
||||
if (fieldEditor)
|
||||
{
|
||||
fieldEditor->setUiField(field);
|
||||
usedFieldKeywords.insert(field->fieldHandle()->keyword());
|
||||
|
||||
//TODO: Create/update is not required at this point, as UI is recreated in getEditorWidgetAndTransferOwnership()
|
||||
// Can be moved, but a move will require changes in PdmUiFieldEditorHandle
|
||||
@ -447,13 +444,12 @@ void PdmUiTableViewQModel::setArrayFieldAndBuildEditors(PdmChildArrayFieldHandle
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Remove all fieldViews not mentioned by the configuration from the layout
|
||||
|
||||
std::vector< QString > fvhToRemoveFromMap;
|
||||
for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it)
|
||||
for (auto it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it)
|
||||
{
|
||||
if (it->second->uiField() == nullptr)
|
||||
if (usedFieldKeywords.count(it->first) == 0)
|
||||
{
|
||||
PdmUiFieldEditorHandle* fvh = it->second;
|
||||
delete fvh;
|
||||
|
@ -147,7 +147,7 @@ void PdmUiToolBarEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldEditor = caf::PdmUiFieldEditorHelper::fieldEditorForField(field->uiCapability(), uiConfigName);
|
||||
fieldEditor = caf::PdmUiFieldEditorHelper::createFieldEditorForField(field->uiCapability(), uiConfigName);
|
||||
|
||||
addSpace = true;
|
||||
}
|
||||
@ -156,6 +156,7 @@ void PdmUiToolBarEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
if (fieldEditor)
|
||||
{
|
||||
m_fieldViews[field->keyword()] = fieldEditor;
|
||||
fieldEditor->setUiField(uiFieldHandle);
|
||||
fieldEditor->createWidgets(nullptr);
|
||||
m_actions.push_back(m_toolbar->addWidget(fieldEditor->editorWidget()));
|
||||
|
||||
@ -166,7 +167,6 @@ void PdmUiToolBarEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
m_toolbar->addWidget(widget);
|
||||
}
|
||||
|
||||
fieldEditor->setUiField(uiFieldHandle);
|
||||
fieldEditor->updateUi(uiConfigName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user