Example #1
0
    void checkPropertyUpdates()
    {
        // GIVEN
        QScopedPointer<Qt3DRender::QFrameGraph> frameGraph(new Qt3DRender::QFrameGraph());
        TestArbiter arbiter(frameGraph.data());

        // WHEN
        MyFrameGraphNode *activeFrameGraph1 = new MyFrameGraphNode();
        frameGraph->setActiveFrameGraph(activeFrameGraph1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        Qt3DCore::QScenePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "activeFrameGraph");
        QCOMPARE(change->subjectId(), frameGraph->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), activeFrameGraph1->id());
        QCOMPARE(change->type(), Qt3DCore::NodeUpdated);

        arbiter.events.clear();

        // WHEN
        frameGraph->setActiveFrameGraph(activeFrameGraph1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 0);

        // WHEN
        MyFrameGraphNode *activeFrameGraph2 = new MyFrameGraphNode();
        frameGraph->setActiveFrameGraph(activeFrameGraph2);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "activeFrameGraph");
        QCOMPARE(change->subjectId(), frameGraph->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), activeFrameGraph2->id());
        QCOMPARE(change->type(), Qt3DCore::NodeUpdated);

        arbiter.events.clear();

        // WHEN
        frameGraph->setActiveFrameGraph(Q_NULLPTR);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "activeFrameGraph");
        QCOMPARE(change->subjectId(), frameGraph->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), Qt3DCore::QNodeId());
        QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
    }
    void checkPropertyUpdates()
    {
        // GIVEN
        QScopedPointer<Qt3DRender::QTechniqueFilter> techniqueFilter(new Qt3DRender::QTechniqueFilter());
        TestArbiter arbiter(techniqueFilter.data());

        // WHEN
        Qt3DRender::QParameter *param1 = new Qt3DRender::QParameter();
        techniqueFilter->addParameter(param1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        Qt3DCore::QScenePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "parameter");
        QCOMPARE(change->subjectId(),techniqueFilter->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), param1->id());
        QCOMPARE(change->type(), Qt3DCore::NodeAdded);

        arbiter.events.clear();

        // WHEN
        techniqueFilter->addParameter(param1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 0);

        // WHEN
        techniqueFilter->removeParameter(param1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "parameter");
        QCOMPARE(change->subjectId(), techniqueFilter->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), param1->id());
        QCOMPARE(change->type(), Qt3DCore::NodeRemoved);

        arbiter.events.clear();

        // WHEN
        Qt3DRender::QAnnotation *annotation1 = new Qt3DRender::QAnnotation();
        techniqueFilter->addRequirement(annotation1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "require");
        QCOMPARE(change->subjectId(),techniqueFilter->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), annotation1->id());
        QCOMPARE(change->type(), Qt3DCore::NodeAdded);

        arbiter.events.clear();

        // WHEN
        techniqueFilter->addRequirement(annotation1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 0);

        // WHEN
        techniqueFilter->removeRequirement(annotation1);
        QCoreApplication::processEvents();

        // THEN
        QCOMPARE(arbiter.events.size(), 1);
        change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>();
        QCOMPARE(change->propertyName(), "require");
        QCOMPARE(change->subjectId(), techniqueFilter->id());
        QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), annotation1->id());
        QCOMPARE(change->type(), Qt3DCore::NodeRemoved);

        arbiter.events.clear();
    }