diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2014-09-29 17:19:36 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2014-10-03 21:18:41 +0200 |
commit | 7b26f6a1746419161a8f875e341b3e31220f4141 (patch) | |
tree | f784e568015e1f7f199abb388b97fefdb158c84e /src/render/io/gltfparser.cpp | |
parent | c16689bb1ccf31416df7b8c69fe032898cf87dec (diff) |
QNode refactoring
Move almost everything to private classes.
Assimp loading restored.
All examples working.
QNode hierachy is now handled through QObject::setParent, addChild,
removeChild are part of the private api.
Note: commented QChangeArbiter unit tests as they can no longer work with this
patch and will restore them when QChangeArbiter will have been made private.
Task-number: QTBUG-41470
Task-number: QTBUG-41523
Change-Id: I4430974b3aa7f3744c38714b451b122e0cb4d0c9
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/io/gltfparser.cpp')
-rw-r--r-- | src/render/io/gltfparser.cpp | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp index 35c21563c..d74a4756e 100644 --- a/src/render/io/gltfparser.cpp +++ b/src/render/io/gltfparser.cpp @@ -204,6 +204,8 @@ const QString KEY_INTERNAL_FORMAT = QStringLiteral("internalFormat"); } // of anonymous namespace +class GLTFParserMeshPrivate; + class GLTFParserMesh : public QAbstractMesh { Q_OBJECT @@ -222,13 +224,27 @@ private: public: explicit GLTFParserMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; void setData(QMeshDataPtr data); QAbstractMeshFunctorPtr meshFunctor() const Q_DECL_OVERRIDE; private: + GLTFParserMesh *doClone() const Q_DECL_OVERRIDE; + Q_DECLARE_PRIVATE(GLTFParserMesh) +}; + +class GLTFParserMeshPrivate : public QAbstractMeshPrivate +{ +public: + + GLTFParserMeshPrivate(GLTFParserMesh *qq) + : QAbstractMeshPrivate(qq) + { + } + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + + Q_DECLARE_PUBLIC(GLTFParserMesh) QMeshDataPtr m_meshData; - GLTFParserMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; }; GLTFParser::GLTFParser() : AbstractSceneParser(), @@ -337,8 +353,7 @@ QEntity* GLTFParser::scene(QString id) QEntity* child = node(nodeName); if (!child) continue; - - sceneEntity->addChild(child); + child->setParent(sceneEntity); } return sceneEntity; @@ -362,7 +377,7 @@ QEntity* GLTFParser::node(QString id) QEntity* child = node(c.toString()); if (!child) continue; - result->addChild(child); + child->setParent(result); } } @@ -395,7 +410,7 @@ QEntity* GLTFParser::node(QString id) // need to make a child entity per material foreach (QString matId, materialDict.keys()) { QEntity* subEntity(new QEntity); - result->addChild(subEntity); + subEntity->setParent(result); subEntity->addComponent(material(matId)); foreach (GLTFParserMesh* m, materialDict.value(matId)) @@ -990,36 +1005,36 @@ QVariant GLTFParser::parameterValueFromJSON(QParameter* p, QJsonValue val) return QVariant(); } -GLTFParserMesh::GLTFParserMesh(QNode *parent) - : QAbstractMesh(parent) +void GLTFParserMeshPrivate::copy(const QNodePrivate *ref) { + QAbstractMeshPrivate::copy(ref); + const GLTFParserMeshPrivate *gltfMesh = static_cast<const GLTFParserMeshPrivate *>(ref); + m_meshData = gltfMesh->m_meshData; } -void GLTFParserMesh::copy(const QNode *ref) +GLTFParserMesh::GLTFParserMesh(QNode *parent) + : QAbstractMesh(*new GLTFParserMeshPrivate(this), parent) { - QAbstractMesh::copy(ref); - const GLTFParserMesh *gltfMesh = qobject_cast<const GLTFParserMesh *>(ref); - if (gltfMesh != Q_NULLPTR) { - m_meshData = gltfMesh->m_meshData; - } } + void GLTFParserMesh::setData(QMeshDataPtr data) { - m_meshData = data; + Q_D(GLTFParserMesh); + d->m_meshData = data; QAbstractMesh::setDirty(this); } QAbstractMeshFunctorPtr GLTFParserMesh::meshFunctor() const { - return QAbstractMeshFunctorPtr(new GLTFParserMeshFunctor(m_meshData)); + Q_D(const GLTFParserMesh); + return QAbstractMeshFunctorPtr(new GLTFParserMeshFunctor(d->m_meshData)); } -GLTFParserMesh *GLTFParserMesh::doClone(bool isClone) const +GLTFParserMesh *GLTFParserMesh::doClone() const { GLTFParserMesh *clone = new GLTFParserMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } |