diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2014-06-03 09:41:50 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-06-04 09:37:50 +0200 |
commit | a3f16ce00dc564c38bc812e97a0c98be14604364 (patch) | |
tree | bf7dc5015c4a8f0ff19f95db69b7ea9bf0e1413c | |
parent | ecf6d3848f8d3c4a356181b840c33a02428ab3c4 (diff) |
Quick3DEffect extension of Effect/QAbstractEffect
This raises an interesting issue as there is no way to register and extended
type along with a custom qml parser using the QML public API (it seems
possible privately).
Change-Id: I5bf9a43ccd989e954e9393d9a97b90fb33de71dc
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | examples/simple-qml/main.qml | 8 | ||||
-rw-r--r-- | src/core/core-components/qabstracteffect.cpp | 5 | ||||
-rw-r--r-- | src/core/core-components/qabstracteffect.h | 16 | ||||
-rw-r--r-- | src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp | 2 | ||||
-rw-r--r-- | src/quick3d/imports/render/qt3dquick3drenderplugin.cpp | 4 | ||||
-rw-r--r-- | src/quick3d/quick3drenderer/items/quick3deffect.cpp | 24 | ||||
-rw-r--r-- | src/quick3d/quick3drenderer/items/quick3deffect.h | 11 | ||||
-rw-r--r-- | src/render/frontend/effect.cpp | 6 | ||||
-rw-r--r-- | src/render/frontend/effect.h | 7 |
9 files changed, 42 insertions, 41 deletions
diff --git a/examples/simple-qml/main.qml b/examples/simple-qml/main.qml index f79f6cd1b..2f1228389 100644 --- a/examples/simple-qml/main.qml +++ b/examples/simple-qml/main.qml @@ -222,9 +222,13 @@ Node { // effect: adsEffect effect : Effect { - customproperty : "red" - ambient : "orange" +// customproperty : "red" +// ambient : "orange" + Node + { + + } } diff --git a/src/core/core-components/qabstracteffect.cpp b/src/core/core-components/qabstracteffect.cpp index ff0bdbdb4..d4481a3f4 100644 --- a/src/core/core-components/qabstracteffect.cpp +++ b/src/core/core-components/qabstracteffect.cpp @@ -46,8 +46,9 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -QAbstractEffect::QAbstractEffect() - : QObservable() +QAbstractEffect::QAbstractEffect(Node *parent) + : Node(parent) + , QObservable() , d_ptr(new QAbstractEffectPrivate(this)) { qRegisterMetaType<Qt3D::QAbstractEffect*>(); diff --git a/src/core/core-components/qabstracteffect.h b/src/core/core-components/qabstracteffect.h index c9f0b325f..a6b5b8219 100644 --- a/src/core/core-components/qabstracteffect.h +++ b/src/core/core-components/qabstracteffect.h @@ -65,12 +65,16 @@ public : QAbstractEffect *q_ptr; }; +// TO DO : Abstract doesn't apply but that might evolve as we further define +// the class + class QT3DCORESHARED_EXPORT QAbstractEffect - : public QObservable + : public Node + , public QObservable { - + Q_OBJECT public: - QAbstractEffect(); + explicit QAbstractEffect(Node *parent = 0); virtual void addTechnique(QAbstractTechnique *t); virtual void removeTechnique(QAbstractTechnique *t); @@ -79,8 +83,8 @@ public: void clearTechniques(); - // Signal - virtual void techniquesChanged() = 0; +Q_SIGNALS: + void techniquesChanged(); private: Q_DECLARE_PRIVATE(QAbstractEffect) @@ -89,8 +93,6 @@ private: } // Qt3D -Q_DECLARE_INTERFACE(Qt3D::QAbstractEffect, "org.qt-project.Qt3D.Effect/2.0") - QT_END_NAMESPACE Q_DECLARE_METATYPE(Qt3D::QAbstractEffect*) diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp index a9739729d..c75a387f3 100644 --- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp +++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp @@ -61,12 +61,12 @@ QT_BEGIN_NAMESPACE void Qt3DQuick3DCorePlugin::registerTypes(const char *uri) { - qmlRegisterInterface<Qt3D::QAbstractEffect>("QAbstractEffect"); qmlRegisterUncreatableType<Qt3D::Component>(uri, 2, 0, "Component", ""); qmlRegisterUncreatableType<Qt3D::QAbstractMesh>(uri, 2, 0, "QAbstractMesh", ""); qmlRegisterUncreatableType<Qt3D::QAbstractMaterial>(uri, 2, 0, "QAbstractMaterial", ""); qmlRegisterUncreatableType<Qt3D::QAbstractTechnique>(uri, 2, 0, "QAbstractTechnique", ""); qmlRegisterUncreatableType<Qt3D::QAbstractRenderPass>(uri, 2, 0, "QAbstractRenderPass", ""); + qmlRegisterUncreatableType<Qt3D::QAbstractEffect>(uri, 2, 0, "QAbstractEffect", ""); qmlRegisterType<Qt3D::Quick::Quick3DConfiguration>(uri, 2, 0, "Configuration"); qmlRegisterExtendedType<Qt3D::Entity, Qt3D::Quick::Quick3DEntity>(uri, 2, 0, "Entity"); diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp index a71f7a1ce..556b73dd1 100644 --- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp +++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp @@ -56,6 +56,7 @@ #include <Qt3DRenderer/framegraph.h> #include <Qt3DRenderer/technique.h> #include <Qt3DRenderer/cameraselector.h> +#include <Qt3DRenderer/effect.h> #include <Qt3DQuickRenderer/quick3dtechnique.h> #include <Qt3DQuickRenderer/quick3dmaterial.h> #include <Qt3DQuickRenderer/quick3dtechniquefilter.h> @@ -73,7 +74,8 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri) { qmlRegisterInterface<Qt3D::Render::QAbstractScene>("QAbstractScene"); qmlRegisterExtendedType<Qt3D::Scene, Qt3D::Render::Quick::Quick3DScene>(uri, 2, 0, "Scene"); - qmlRegisterCustomType<Qt3D::Render::Quick::Quick3DEffect>(uri, 2, 0, "Effect", new Qt3D::Render::Quick::ShaderPropertyParser()); +// qmlRegisterCustomType<Qt3D::Effect>(uri, 2, 0, "Effect", new Qt3D::Render::Quick::ShaderPropertyParser()); + qmlRegisterExtendedType<Qt3D::Effect, Qt3D::Render::Quick::Quick3DEffect>(uri, 2, 0, "Effect"); qmlRegisterExtendedType<Qt3D::Technique, Qt3D::Render::Quick::Quick3DTechnique>(uri, 2, 0, "Technique"); qmlRegisterType<Qt3D::TechniqueCriterion>(uri, 2, 0, "TechniqueCriterion"); qmlRegisterType<Qt3D::Tag>(uri, 2, 0, "Tag"); diff --git a/src/quick3d/quick3drenderer/items/quick3deffect.cpp b/src/quick3d/quick3drenderer/items/quick3deffect.cpp index 2c0d1bce3..fb09731c6 100644 --- a/src/quick3d/quick3drenderer/items/quick3deffect.cpp +++ b/src/quick3d/quick3drenderer/items/quick3deffect.cpp @@ -49,9 +49,8 @@ namespace Render { namespace Quick { -Quick3DEffect::Quick3DEffect(Node *parent) - : Qt3D::Quick::Quick3DNode(parent), - QAbstractEffect() +Quick3DEffect::Quick3DEffect(QObject *parent) + : QObject(parent) { } @@ -66,35 +65,36 @@ QQmlListProperty<Technique> Quick3DEffect::techniqueList() void Quick3DEffect::appendTechnique(QQmlListProperty<Technique> *list, Technique *bar) { - QAbstractEffect *eff = qobject_cast<QAbstractEffect*>(list->object); + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); if (eff) - eff->addTechnique(bar); + eff->parentEffect()->addTechnique(bar); } +// TO DO : Return a QAbstractTechnique once properly defined Technique *Quick3DEffect::techniqueAt(QQmlListProperty<Technique> *list, int index) { - QAbstractEffect *eff = qobject_cast<QAbstractEffect*>(list->object); + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); if (eff) - return qobject_cast<Technique*>(eff->techniques().at(index)); + return qobject_cast<Technique*>(eff->parentEffect()->techniques().at(index)); return Q_NULLPTR; } int Quick3DEffect::techniqueCount(QQmlListProperty<Technique> *list) { - QAbstractEffect *eff = qobject_cast<QAbstractEffect*>(list->object); + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); if (eff) - return eff->techniques().count(); + return eff->parentEffect()->techniques().count(); return 0; } void Quick3DEffect::clearTechniqueList(QQmlListProperty<Technique> *list) { - QAbstractEffect *eff = qobject_cast<QAbstractEffect*>(list->object); + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); if (eff) { // Ownership of techniques is handled by the QmlEngine so we shouldn't class clearTechniques // which deletes techniques - Q_FOREACH (QAbstractTechnique *tech, eff->techniques()) - eff->removeTechnique(tech); + Q_FOREACH (QAbstractTechnique *tech, eff->parentEffect()->techniques()) + eff->parentEffect()->removeTechnique(tech); } } diff --git a/src/quick3d/quick3drenderer/items/quick3deffect.h b/src/quick3d/quick3drenderer/items/quick3deffect.h index c2f6c319b..4dc7e4ebb 100644 --- a/src/quick3d/quick3drenderer/items/quick3deffect.h +++ b/src/quick3d/quick3drenderer/items/quick3deffect.h @@ -43,7 +43,6 @@ #define QT3D_RENDER_QUICK_QUICK3DEFFECT_H #include <Qt3DQuickRenderer/qt3dquickrenderer_global.h> -#include <Qt3DQuick/quick3dnode.h> #include <Qt3DCore/qabstracteffect.h> #include <QQmlListProperty> #include <Qt3DRenderer/technique.h> @@ -57,19 +56,17 @@ namespace Render { namespace Quick { -class QT3DQUICKRENDERERSHARED_EXPORT Quick3DEffect : public Qt3D::Quick::Quick3DNode, public QAbstractEffect +class QT3DQUICKRENDERERSHARED_EXPORT Quick3DEffect : public QObject { Q_OBJECT - Q_INTERFACES(Qt3D::QAbstractEffect) Q_PROPERTY(QQmlListProperty<Qt3D::Technique> techniques READ techniqueList) public: - explicit Quick3DEffect(Node *parent = 0); + explicit Quick3DEffect(QObject *parent = 0); - QQmlListProperty<Qt3D::Technique> techniqueList(); + inline QAbstractEffect *parentEffect() const { return qobject_cast<QAbstractEffect*>(parent()); } -Q_SIGNALS: - void techniquesChanged() Q_DECL_OVERRIDE; + QQmlListProperty<Qt3D::Technique> techniqueList(); private: static void appendTechnique(QQmlListProperty<Technique> *list, Technique *bar); diff --git a/src/render/frontend/effect.cpp b/src/render/frontend/effect.cpp index ab13c1115..6c70766c9 100644 --- a/src/render/frontend/effect.cpp +++ b/src/render/frontend/effect.cpp @@ -48,8 +48,7 @@ namespace Qt3D { Effect::Effect(Node *parent) - : Node(parent) - , QAbstractEffect() + : QAbstractEffect(parent) { } @@ -57,7 +56,8 @@ void Effect::addTechnique(QAbstractTechnique *t) { // In the C++ API we are responsible for setting the parent // Qml API is automatically handled by the Qml Engine - t->setParent(this); + if (!t->parent()) + t->setParent(this); QAbstractEffect::addTechnique(t); } diff --git a/src/render/frontend/effect.h b/src/render/frontend/effect.h index bf29e4d54..fee10f1c3 100644 --- a/src/render/frontend/effect.h +++ b/src/render/frontend/effect.h @@ -52,19 +52,14 @@ QT_BEGIN_NAMESPACE namespace Qt3D { class QT3DRENDERERSHARED_EXPORT Effect - : public Node - , public QAbstractEffect + : public QAbstractEffect { Q_OBJECT - Q_INTERFACES(Qt3D::QAbstractEffect) public: explicit Effect(Node *parent = 0); void addTechnique(QAbstractTechnique *t) Q_DECL_OVERRIDE; void removeTechnique(QAbstractTechnique *t) Q_DECL_OVERRIDE; - -Q_SIGNALS: - void techniquesChanged() Q_DECL_OVERRIDE; }; } // Qt3D |