#1883 AppFwk : Move UiFieldEditorHelper to separate file

This commit is contained in:
Magne Sjaastad 2017-09-12 07:09:16 +02:00
parent cb7d0ada8e
commit 7e43c4e666
8 changed files with 156 additions and 61 deletions

View File

@ -42,18 +42,17 @@
#include "cafPdmProxyValueField.h"
#include "cafPdmUiCheckBoxEditor.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiDateEditor.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiFieldEditorHelper.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiListEditor.h"
#include "cafPdmUiOrdering.h"
#include "cafPdmUiDateEditor.h"
#include <QGridLayout>
#include <QWidget>
#include <QDate>
#include <QDateTime>
#include "cafPdmUiDefaultObjectEditor.h"
namespace caf

View File

@ -93,7 +93,8 @@ set( PROJECT_FILES
cafPdmUiTreeSelectionEditor.cpp
cafPdmUiTreeSelectionQModel.h
cafPdmUiTreeSelectionQModel.cpp
cafPdmUiFieldEditorHelper.h
cafPdmUiFieldEditorHelper.cpp
# object editors
cafPdmUiDefaultObjectEditor.cpp

View File

@ -34,7 +34,6 @@
//
//##################################################################################################
#include "cafPdmUiDefaultObjectEditor.h"
#include "cafPdmProxyValueField.h"
@ -215,50 +214,5 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 (fieldTypeName.indexOf("PdmPtrArrayField") != -1)
{
fieldTypeName = caf::PdmUiListEditor::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);
CAF_ASSERT(useOptionsOnly); // Not supported
if (!options.empty())
{
fieldTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName();
}
}
fieldEditor = caf::Factory<PdmUiFieldEditorHandle, QString>::instance()->create(fieldTypeName);
}
return fieldEditor;
}
} // end namespace caf

View File

@ -40,24 +40,18 @@
#include "cafPdmUiWidgetBasedObjectEditor.h"
#include <QPointer>
#include <QString>
class QGridLayout;
class QString;
namespace caf
{
class PdmUiFieldEditorHandle;
class PdmUiItem;
class PdmUiGroup;
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

@ -0,0 +1,90 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2017 Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafPdmUiFieldEditorHelper.h"
#include "cafClassTypeName.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiListEditor.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmUiFieldEditorHandle* caf::PdmUiFieldEditorHelper::fieldEditorForField(caf::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 (fieldTypeName.indexOf("PdmPtrArrayField") != -1)
{
fieldTypeName = caf::PdmUiListEditor::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);
CAF_ASSERT(useOptionsOnly); // Not supported
if (!options.empty())
{
fieldTypeName = caf::PdmUiComboBoxEditor::uiEditorTypeName();
}
}
fieldEditor = caf::Factory<PdmUiFieldEditorHandle, QString>::instance()->create(fieldTypeName);
}
return fieldEditor;
}

View File

@ -0,0 +1,57 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2017 Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
class QString;
namespace caf
{
class PdmUiFieldEditorHandle;
class PdmUiFieldHandle;
//==================================================================================================
///
//==================================================================================================
class PdmUiFieldEditorHelper
{
public:
static PdmUiFieldEditorHandle* fieldEditorForField(PdmUiFieldHandle* fieldHandle, const QString& uiConfigName);
};
} // end namespace caf

View File

@ -42,7 +42,7 @@
#include "cafPdmObject.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiCommandSystemProxy.h"
#include "cafPdmUiDefaultObjectEditor.h"
#include "cafPdmUiFieldEditorHelper.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiTableItemEditor.h"
#include "cafSelectionManager.h"

View File

@ -39,6 +39,8 @@
#include "cafPdmObjectHandle.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiFieldEditorHelper.h"
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiObjectHandle.h"
#include "cafPdmUiOrdering.h"
#include "cafPdmXmlObjectHandle.h"
@ -47,8 +49,6 @@
#include <QGridLayout>
#include <QFrame>
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiDefaultObjectEditor.h"
//--------------------------------------------------------------------------------------------------
///