#pragma once #include #include #include namespace caf { template class PdmDataValueField; class PdmOptionItemInfo; class PdmObjectHandle; //================================================================================================== /// A proxy class that implements the Gui interface of fields /// /// This class collects methods that need specialization when introducing a new type in a PdmField. /// Having those methods in a separate class makes it possible to "partially specialize" the methods /// for container classes etc. since partial specialization of template functions is not C++ as of yet. /// /// When introducing a new type in a PdmField, you might need to implement a (partial)specialization /// of this class. //================================================================================================== template class PdmUiFieldSpecialization { public: static QVariant convert( const T& value ) { /// Convert the field value into a QVariant return QVariant::fromValue( value ); } static void setFromVariant( const QVariant& variantValue, T& value ) { /// Set the field value from a QVariant value = variantValue.value(); } /// Check equality between QVariants that carries a Field Value. /// The == operator will normally work, but does not support custom types in the QVariant /// See http://qt-project.org/doc/qt-4.8/qvariant.html#operator-eq-eq-64 /// This is needed for the lookup regarding OptionValues static bool isDataElementEqual( const QVariant& variantValue, const QVariant& variantValue2 ) { if ( variantValue.typeId() > QMetaType::User ) { return ( variantValue.value() == variantValue2.value() ); } else { return variantValue == variantValue2; } } /// Methods to get a list of options for a field, specialized for AppEnum static QList valueOptions( const T& ) { return QList(); } /// Methods to retrieve the possible PdmObject pointed to by a field static void childObjects( const PdmDataValueField&, std::vector* ) {} }; } // End of namespace caf #include "cafInternalPdmFieldTypeSpecializations.h"