AppFwk : Added static method used to create field editors. Always create comboBox for PdmPtrFields

This commit is contained in:
Magne Sjaastad 2016-12-14 14:52:49 +01:00
parent 69695ffa32
commit 55895fb8d8
3 changed files with 51 additions and 52 deletions

View File

@ -70,6 +70,7 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector<int>);
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector<unsigned int>);
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector<float>);
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -259,32 +260,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
if (it == m_fieldViews.end())
{
// If editor type is specified, find in factory
if ( !uiItems[i]->uiEditorTypeName(uiConfigName).isEmpty() )
{
fieldEditor = caf::Factory<PdmUiFieldEditorHandle, QString>::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<PdmOptionItemInfo> options = field->valueOptions( &useOptionsOnly);
if (!options.empty())
{
editorTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName();
}
}
fieldEditor = caf::Factory<PdmUiFieldEditorHandle, QString>::instance()->create(editorTypeName);
}
fieldEditor = PdmUiFieldEditorHelper::fieldEditorForField(field, uiConfigName);
if (fieldEditor)
{
@ -428,5 +404,44 @@ void PdmUiDefaultObjectEditor::recursiveVerifyUniqueNames(const std::vector<PdmU
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmUiFieldEditorHandle* PdmUiFieldEditorHelper::fieldEditorForField(PdmUiFieldHandle* field, const QString& uiConfigName)
{
caf::PdmUiFieldEditorHandle* fieldEditor = NULL;
// If editor type is specified, find in factory
if (!field->uiEditorTypeName(uiConfigName).isEmpty())
{
fieldEditor = caf::Factory<PdmUiFieldEditorHandle, QString>::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<PdmOptionItemInfo> options = field->valueOptions(&useOptionsOnly);
if (!options.empty())
{
fieldTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName();
}
}
fieldEditor = caf::Factory<PdmUiFieldEditorHandle, QString>::instance()->create(fieldTypeName);
}
return fieldEditor;
}
} // end namespace caf

View File

@ -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
//==================================================================================================

View File

@ -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<PdmUiFieldEditorHandle, QString>::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<PdmOptionItemInfo> options = field->valueOptions( &useOptionsOnly);
if (!options.empty())
{
editorTypeName = PdmUiComboBoxEditor::uiEditorTypeName();
}
}
fieldEditor = Factory<PdmUiFieldEditorHandle, QString>::instance()->create(editorTypeName);
}
fieldEditor = PdmUiFieldEditorHelper::fieldEditorForField(field, configName);
if (fieldEditor)
{