mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 22:50:25 -05:00
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:
1 parent
700549fb3b
commit
e8223485b1
13 files changed
+107
-38
No files matched your search
@@ -120,6 +120,29 @@ void pdmFromVariant( const QVariant& v, std::optional<T>& out )
|
||||
out = underlying;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
/// toVariant / fromVariant — public API wrappers
|
||||
///
|
||||
/// Simple qualified-call entry points that encapsulate the ADL two-step internally.
|
||||
/// Prefer these over calling pdmToVariant/pdmFromVariant with a using-declaration at the call site.
|
||||
/// Custom types are still extended by adding pdmToVariant/pdmFromVariant overloads in the type's
|
||||
/// own namespace; these wrappers just hide that detail from callers.
|
||||
//==================================================================================================
|
||||
|
||||
template <typename T>
|
||||
QVariant toVariant( const T& value )
|
||||
{
|
||||
using caf::pdmToVariant;
|
||||
return pdmToVariant( value );
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void fromVariant( const QVariant& v, T& out )
|
||||
{
|
||||
using caf::pdmFromVariant;
|
||||
pdmFromVariant( v, out );
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
/// PdmVariantEqualImpl<T>
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user