From 55895fb8d89489383d0ad1a89ad73a1bb4f2107f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 14 Dec 2016 14:52:49 +0100 Subject: [PATCH] AppFwk : Added static method used to create field editors. Always create comboBox for PdmPtrFields --- .../cafPdmUiDefaultObjectEditor.cpp | 67 ++++++++++++------- .../cafPdmUiDefaultObjectEditor.h | 8 +++ .../cafPdmUiTableViewModel.cpp | 28 +------- 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 9b542389c6..a67100b185 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -70,6 +70,7 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -259,32 +260,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

uiEditorTypeName(uiConfigName).isEmpty() ) - { - fieldEditor = caf::Factory::instance()->create(field->uiEditorTypeName(uiConfigName)); - } - else - { - // Find the default field editor - - QString editorTypeName = qStringTypeName(*(field->fieldHandle())); - - // Handle a single value field with valueOptions: Make a combobox - - if (field->toUiBasedQVariant().type() != QVariant::List) - { - bool useOptionsOnly = true; - QList options = field->valueOptions( &useOptionsOnly); - - if (!options.empty()) - { - editorTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName(); - } - } - - fieldEditor = caf::Factory::instance()->create(editorTypeName); - } + fieldEditor = PdmUiFieldEditorHelper::fieldEditorForField(field, uiConfigName); if (fieldEditor) { @@ -428,5 +404,44 @@ void PdmUiDefaultObjectEditor::recursiveVerifyUniqueNames(const std::vectoruiEditorTypeName(uiConfigName).isEmpty()) + { + fieldEditor = caf::Factory::instance()->create(field->uiEditorTypeName(uiConfigName)); + } + else + { + // Find the default field editor + QString fieldTypeName = qStringTypeName(*(field->fieldHandle())); + + if (fieldTypeName.indexOf("PdmPtrField") != -1) + { + fieldTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName(); + } + else if (field->toUiBasedQVariant().type() != QVariant::List) + { + // Handle a single value field with valueOptions: Make a combobox + + bool useOptionsOnly = true; + QList options = field->valueOptions(&useOptionsOnly); + + if (!options.empty()) + { + fieldTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName(); + } + } + + fieldEditor = caf::Factory::instance()->create(fieldTypeName); + } + + return fieldEditor; +} } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h index 6ac2e42adf..20ec008b0a 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h @@ -53,6 +53,14 @@ namespace caf class PdmUiFieldEditorHandle; class PdmUiItem; + +class PdmUiFieldEditorHelper +{ +public: + static PdmUiFieldEditorHandle* fieldEditorForField(PdmUiFieldHandle* fieldHandle, const QString& uiConfigName); +}; + + //================================================================================================== /// The default editor for PdmObjects. Manages the field editors in a gridlayout vertically //================================================================================================== diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTableViewModel.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTableViewModel.cpp index c01d9d4b32..c47655e838 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTableViewModel.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTableViewModel.cpp @@ -42,6 +42,7 @@ #include "cafPdmObject.h" #include "cafPdmUiComboBoxEditor.h" #include "cafPdmUiCommandSystemProxy.h" +#include "cafPdmUiDefaultObjectEditor.h" #include "cafPdmUiLineEditor.h" #include "cafPdmUiTableItemEditor.h" #include "cafSelectionManager.h" @@ -317,32 +318,7 @@ void PdmUiTableViewModel::setPdmData(PdmChildArrayFieldHandle* listField, const if (it == m_fieldEditors.end()) { - // If editor type is specified, find in factory - if ( !uiItems[i]->uiEditorTypeName(configName).isEmpty() ) - { - fieldEditor = Factory::instance()->create(field->uiEditorTypeName(configName)); - } - else - { - // Find the default field editor - - QString editorTypeName = qStringTypeName(*(field->fieldHandle())); - - // Handle a single value field with valueOptions: Make a combobox - - if (field->uiValue().type() != QVariant::List) - { - bool useOptionsOnly = true; - QList options = field->valueOptions( &useOptionsOnly); - - if (!options.empty()) - { - editorTypeName = PdmUiComboBoxEditor::uiEditorTypeName(); - } - } - - fieldEditor = Factory::instance()->create(editorTypeName); - } + fieldEditor = PdmUiFieldEditorHelper::fieldEditorForField(field, configName); if (fieldEditor) {