mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-02 20:30:46 -06:00
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.
82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
//##################################################################################################
|
|
//
|
|
// Custom Visualization Core library
|
|
// Copyright (C) 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
|
|
|
|
#include "cvfBase.h"
|
|
#include "cvfVector3.h"
|
|
|
|
#include "cafPdmFieldTraits.h"
|
|
|
|
#include "cafPdmXmlVec3d.h"
|
|
|
|
#include <QTextStream>
|
|
|
|
Q_DECLARE_METATYPE( cvf::Vec3d );
|
|
|
|
// pdmToVariant/pdmFromVariant in namespace cvf so ADL finds them when called via caf::toVariant/
|
|
// caf::fromVariant — ADL searches the argument's namespace (cvf) in addition to caf.
|
|
namespace cvf
|
|
{
|
|
|
|
inline QVariant pdmToVariant( const Vec3d& value )
|
|
{
|
|
QString str;
|
|
QTextStream textStream( &str );
|
|
textStream << value;
|
|
return QVariant( str );
|
|
}
|
|
|
|
inline void pdmFromVariant( const QVariant& v, Vec3d& out )
|
|
{
|
|
QString str = v.toString();
|
|
QTextStream textStream( &str );
|
|
textStream >> out;
|
|
}
|
|
|
|
} // end namespace cvf
|
|
|
|
namespace caf
|
|
{
|
|
|
|
template <>
|
|
struct PdmVariantEqualImpl<cvf::Vec3d>
|
|
{
|
|
static bool equal( const QVariant& a, const QVariant& b ) { return a.toString() == b.toString(); }
|
|
};
|
|
|
|
} // end namespace caf
|