#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:
Magne Sjaastad
2019-05-03 11:11:39 +02:00
parent fe0624e304
commit 088b5513a7
6 changed files with 29 additions and 32 deletions

View File

@@ -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;