Skip to content

Refactor PdmValueFieldSpecialization: fix isEqual inconsistency and consolidate redundant base classes #834

@magnesj

Description

@magnesj

Description

Replace the PdmValueFieldSpecialization<T> policy class pattern with ADL-based free functions (pdmToVariant / pdmFromVariant / pdmVariantEqual). This removes the centralized cafInternal* specialization header and allows each type to declare its own serialization next to its own declaration. It also eliminates the two redundant base classes and fixes the incorrect isEqual implementations inherited from PdmValueFieldSpecializationDefaults.

ADL design

// Default implementations — work for any Qt-metatype-registered type
namespace caf {
    template <typename T>
    QVariant pdmToVariant( const T& value ) { return QVariant::fromValue( value ); }

    template <typename T>
    void pdmFromVariant( const QVariant& v, T& out ) { out = v.value<T>(); }

    template <typename T>
    bool pdmVariantEqual( const QVariant& a, const QVariant& b ) { return a.value<T>() == b.value<T>(); }
}

Each type provides overloads in its own header. PdmDataValueField and PdmProxyValueField call these via using caf::pdmToVariant to enable ADL. pdmVariantEqual uses if constexpr to handle containers, PdmPointer, and AppEnum, with full specializations for FilePath, float, double, and cvf types.


Steps

  • Add cafPdmFieldTraits.h with default pdmToVariant / pdmFromVariant / pdmVariantEqual — commit 1ecc456
  • Add overloads for AppEnum<T> in cafPdmFieldTraits.h — commit 1ecc456
  • Add overloads for FilePath in cafPdmFieldTraits.h — commit 1ecc456
  • Add overloads for std::vector<T> (delegating element-wise to pdmVariantEqual) — commit 1ecc456
  • Add overloads for std::pair<T,U> — commit 1ecc456
  • Add overloads for PdmPointer<T> — commit 1ecc456
  • Add overloads for float and double (pdmVariantEqual with epsilon) — commit 1ecc456
  • Add overloads for cvf::Vec3d, cvf::Mat4d, cvf::Color3f, cvf::Mat3d in their respective cafPdmCvf headers — commit 77e5b03
  • Switch PdmDataValueField and PdmProxyValueField to call the free functions — commit f02fbee
  • Switch UI framework (cafInternalPdmFieldTypeSpecializations.h, cafInternalPdmUiFieldCapability.inl) to call free functions — commit 411b98f
  • Update all remaining call sites (unit tests, application code, UI editors) — commits 77e5b03, f02fbee, 1ffbc4b
  • Remove cafInternalPdmValueFieldSpecializations.h and update CMakeLists.txt — commit 1ffbc4b

Files affected

  • Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmFieldTraits.h (new)
  • Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafInternalPdmValueFieldSpecializations.h (deleted)
  • Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmDataValueField.h
  • Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmProxyValueField.h
  • Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmFieldTypeSpecializations.h
  • Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiFieldCapability.inl
  • Fwk/AppFwk/cafPdmCvf/cafPdmCoreVec3d.h
  • Fwk/AppFwk/cafPdmCvf/cafPdmCoreMat4d.h
  • Fwk/AppFwk/cafPdmCvf/cafPdmCoreColor3f.h
  • Fwk/AppFwk/cafPdmCvf/cafPdmMat3d/cafPdmCoreMat3d.h

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions