| 1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "sortcriterion_p.h" |
| 5 | #include <Qt3DCore/qnodepropertychange.h> |
| 6 | #include <QVariant> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace Qt3DRender { |
| 11 | namespace Render { |
| 12 | |
| 13 | using namespace Qt3DCore; |
| 14 | |
| 15 | SortCriterion::SortCriterion() |
| 16 | : BackendNode() |
| 17 | , m_type(QSortCriterion::StateChangeCost) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | void SortCriterion::cleanup() |
| 22 | { |
| 23 | QBackendNode::setEnabled(false); |
| 24 | } |
| 25 | |
| 26 | void SortCriterion::updateFromPeer(Qt3DCore::QNode *peer) |
| 27 | { |
| 28 | QSortCriterion *criterion = static_cast<QSortCriterion *>(peer); |
| 29 | m_type = criterion->sort(); |
| 30 | } |
| 31 | |
| 32 | QSortCriterion::SortType SortCriterion::sortType() const |
| 33 | { |
| 34 | return m_type; |
| 35 | } |
| 36 | |
| 37 | void SortCriterion::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) |
| 38 | { |
| 39 | QNodePropertyChangePtr propertyChange = qSharedPointerCast<QNodePropertyChange>(e); |
| 40 | if (e->type() == NodeUpdated && propertyChange->propertyName() == QByteArrayLiteral("sort")) { |
| 41 | m_type = static_cast<QSortCriterion::SortType>(propertyChange->value().toInt()); |
| 42 | } |
| 43 | markDirty(AbstractRenderer::AllDirty); |
| 44 | |
| 45 | BackendNode::sceneChangeEvent(e); |
| 46 | } |
| 47 | |
| 48 | } // namespace Render |
| 49 | } // namespace Qt3DRender |
| 50 | |
| 51 | QT_END_NAMESPACE |