22 #ifndef GRANTLEE_METATYPE_H 23 #define GRANTLEE_METATYPE_H 25 #include "grantlee_templates_export.h" 29 #include <QtCore/QVariant> 50 class GRANTLEE_TEMPLATES_EXPORT MetaType
56 typedef QVariant ( *LookupFunction )(
const QVariant &,
const QString & );
61 static void registerLookUpOperator(
int id, LookupFunction f );
66 static void internalLock();
71 static void internalUnlock();
76 static QVariant lookup(
const QVariant &
object,
const QString &property );
81 static bool lookupAlreadyRegistered(
int id );
94 template<
typename RealType,
typename HandleAs>
97 static QVariant doLookUp(
const QVariant &
object,
const QString &property )
99 typedef typename Grantlee::TypeAccessor<RealType> Accessor;
100 return Accessor::lookUp(
object.value<RealType>(), property );
104 template<
typename RealType,
typename HandleAs>
105 struct LookupTrait<RealType&, HandleAs&>
107 static QVariant doLookUp(
const QVariant &
object,
const QString &property )
109 typedef typename Grantlee::TypeAccessor<HandleAs&> Accessor;
110 return Accessor::lookUp(
object.value<HandleAs>(), property );
114 template<
typename RealType,
typename HandleAs>
115 static int doRegister(
int id )
117 if ( MetaType::lookupAlreadyRegistered(
id ) )
120 QVariant ( *lf )(
const QVariant&,
const QString& ) = LookupTrait<RealType, HandleAs>::doLookUp;
122 MetaType::registerLookUpOperator(
id, reinterpret_cast<MetaType::LookupFunction>( lf ) );
130 template<
typename RealType,
typename HandleAs>
131 struct InternalRegisterType
134 const int id = qMetaTypeId<RealType>();
135 return doRegister<RealType&, HandleAs&>( id );
139 template<
typename RealType,
typename HandleAs>
140 struct InternalRegisterType<RealType*, HandleAs*>
143 const int id = qMetaTypeId<RealType*>();
144 return doRegister<RealType*, HandleAs*>( id );
185 template<
typename RealType,
typename HandleAs>
188 MetaType::internalLock();
190 const int id = InternalRegisterType<RealType, HandleAs>::doReg();
192 MetaType::internalUnlock();
204 template<
typename Type>
207 return registerMetaType<Type, Type>();
218 #define GRANTLEE_BEGIN_LOOKUP(Type) \ 222 inline QVariant TypeAccessor<Type&>::lookUp( const Type &object, const QString &property ) \ 230 #define GRANTLEE_BEGIN_LOOKUP_PTR(Type) \ 234 inline QVariant TypeAccessor<Type*>::lookUp( const Type * const object, const QString &property ) \ 242 #define GRANTLEE_END_LOOKUP \ 247 #endif // #define GRANTLEE_METATYPE_H int registerMetaType()
Registers the type RealType with the metatype system.
The Grantlee namespace holds all public Grantlee API.