From 90623e3ccbeba4f498b3ce5c1b6c88f1122df434 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 20 Jul 2015 09:10:08 +0200 Subject: Functors: remove dynamic_cast Introduce a QAbstractFunctor class which QAbstractMeshFunctor and QTextureDataFunctor subclass Make all QAbstractFunctor subclasses implement an id() function (using QT3D_FUNCTOR(Class)). Use this id to compare to other QAbstractMeshFunctor and eventually static_cast into right type if possible using the functor_cast member function. Change-Id: Iface956e6cd818cbef204d8fa7bf2bc23c6ffa3f Reviewed-by: Sean Harmer --- src/render/io/gltfparser.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/render/io/gltfparser.cpp') diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp index 745180e56..0cff55016 100644 --- a/src/render/io/gltfparser.cpp +++ b/src/render/io/gltfparser.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include @@ -203,29 +203,28 @@ const QString KEY_INTERNAL_FORMAT = QStringLiteral("internalFormat"); class GLTFParserMeshPrivate; -class GLTFParserMesh : public QAbstractMesh +class GLTFParserMeshFunctor : public QAbstractMeshFunctor { - Q_OBJECT +public: + explicit GLTFParserMeshFunctor(QMeshDataPtr meshData = QMeshDataPtr()); + QMeshDataPtr operator ()() Q_DECL_OVERRIDE; + bool operator ==(const QAbstractMeshFunctor &other) const Q_DECL_OVERRIDE; + QT3D_FUNCTOR(GLTFParserMeshFunctor) private: - class GLTFParserMeshFunctor : public QAbstractMeshFunctor - { - public: - explicit GLTFParserMeshFunctor(QMeshDataPtr meshData); - QMeshDataPtr operator ()() Q_DECL_OVERRIDE; - bool operator ==(const QAbstractMeshFunctor &other) const Q_DECL_OVERRIDE; - - private: - QMeshDataPtr m_meshData; - }; + QMeshDataPtr m_meshData; +}; +class GLTFParserMesh : public QAbstractMesh +{ + Q_OBJECT public: explicit GLTFParserMesh(QNode *parent = 0); void setData(QMeshDataPtr data); - QAbstractMeshFunctorPtr meshFunctor() const Q_DECL_OVERRIDE; + QAbstractMeshFunctorPtr meshFunctor() const Q_DECL_FINAL; protected: - void copy(const QNode *ref) Q_DECL_OVERRIDE; + void copy(const QNode *ref) Q_DECL_FINAL; private: QT3D_CLONEABLE(GLTFParserMesh) @@ -1030,18 +1029,18 @@ QAbstractMeshFunctorPtr GLTFParserMesh::meshFunctor() const return QAbstractMeshFunctorPtr(new GLTFParserMeshFunctor(d->m_meshData)); } -GLTFParserMesh::GLTFParserMeshFunctor::GLTFParserMeshFunctor(QMeshDataPtr meshData) +GLTFParserMeshFunctor::GLTFParserMeshFunctor(QMeshDataPtr meshData) : QAbstractMeshFunctor() , m_meshData(meshData) { } -QMeshDataPtr GLTFParserMesh::GLTFParserMeshFunctor::operator ()() +QMeshDataPtr GLTFParserMeshFunctor::operator ()() { return m_meshData; } -bool GLTFParserMesh::GLTFParserMeshFunctor::operator ==(const QAbstractMeshFunctor &) const +bool GLTFParserMeshFunctor::operator ==(const QAbstractMeshFunctor &) const { return false; } @@ -1050,4 +1049,6 @@ bool GLTFParserMesh::GLTFParserMeshFunctor::operator ==(const QAbstractMeshFunct QT_END_NAMESPACE +Q_DECLARE_METATYPE(Qt3D::GLTFParserMeshFunctor) + #include "gltfparser.moc" -- cgit v1.2.3