Fix ADL lookup for cvf pdmToVariant/pdmFromVariant overloads

Move pdmToVariant/pdmFromVariant overloads for cvf::Color3f, Vec3d, Mat4d, and
Mat3d from namespace caf to namespace cvf. Templates in
cafInternalPdmFieldTypeSpecializations.h use "using caf::pdmToVariant" followed
by an unqualified call, so ADL searches the argument's namespace (cvf). With the
overloads only in caf, the default template was selected, causing cvf::Color3f to
be stored raw in a QVariant instead of as QColor — breaking color field editing
and producing QVariant::save warnings.

All call sites now use the unqualified "using caf::pdmXxx; pdmXxx(value)" pattern
so ADL finds the correct overload without depending on cvf:: as a visible prefix.
Add AdlVariantTest to cafPdmCoreColor3fTest.cpp that exercises this exact pattern.

Adds caf::toVariant<T> and caf::fromVariant<T> to cafPdmFieldTraits.h as
thin wrappers that encapsulate the ADL two-step internally. Client code can
now call caf::toVariant(x) directly instead of requiring a using-declaration
at every call site.
This commit is contained in:
Magne Sjaastad authored and GitHub committed 2026-04-08 23:12:49 +02:00
1 parent 700549fb3b
commit e8223485b1
13 files changed
+107 -38

No files matched your search

@@ -520,7 +520,7 @@ void RimWellPathGeometryDef::fieldChangedByUi( const caf::PdmFieldHandle* change
linkedDefs.end() );
cvf::Vec3d oldPos;
caf::pdmFromVariant( oldValue, oldPos );
caf::fromVariant( oldValue, oldPos );
auto delta = m_referencePointUtmXyd() - oldPos;