diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2016-05-04 12:23:32 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-04 15:32:52 +0000 |
commit | 7fa8b1523a0791a159c594687c89af7ae621752a (patch) | |
tree | 37d514632251ca22ba9713226a877de88ea2e663 /src/quick3d/quick3drender/items | |
parent | 2339fb571f1ca2e5d9057cccbb5989841c524dea (diff) |
Get rid of QLayer::names
Don't reinvent a variable naming system (string based global variables
even) and instead use pointer to QLayer instance everywhere, even with
QLayerFilter.
The wave and deferred-renderer-cpp examples have been ported to the new
API.
Change-Id: I82a858770954a8743a5c3d2ce0c463e62844871f
Task-number: QTBUG-51440
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drender/items')
-rw-r--r-- | src/quick3d/quick3drender/items/items.pri | 2 | ||||
-rw-r--r-- | src/quick3d/quick3drender/items/quick3dlayerfilter.cpp | 107 | ||||
-rw-r--r-- | src/quick3d/quick3drender/items/quick3dlayerfilter_p.h | 90 |
3 files changed, 199 insertions, 0 deletions
diff --git a/src/quick3d/quick3drender/items/items.pri b/src/quick3d/quick3drender/items/items.pri index 85cfa3f71..82fbdebc0 100644 --- a/src/quick3d/quick3drender/items/items.pri +++ b/src/quick3d/quick3drender/items/items.pri @@ -3,6 +3,7 @@ HEADERS += \ $$PWD/quick3dbuffer_p.h \ $$PWD/quick3deffect_p.h \ $$PWD/quick3dgeometry_p.h \ + $$PWD/quick3dlayerfilter_p.h \ $$PWD/quick3dmaterial_p.h \ $$PWD/quick3drenderpass_p.h \ $$PWD/quick3drenderpassfilter_p.h \ @@ -22,6 +23,7 @@ SOURCES += \ $$PWD/quick3drenderpassfilter.cpp \ $$PWD/quick3dtechniquefilter.cpp \ $$PWD/quick3dviewport.cpp \ + $$PWD/quick3dlayerfilter.cpp \ $$PWD/quick3dmaterial.cpp \ $$PWD/quick3dtechnique.cpp \ $$PWD/quick3deffect.cpp \ diff --git a/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp b/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp new file mode 100644 index 000000000..754f420d5 --- /dev/null +++ b/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3dlayerfilter_p.h" +#include <Qt3DRender/qtexture.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +namespace Quick { + +Quick3DLayerFilter::Quick3DLayerFilter(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<QLayer> Quick3DLayerFilter::qmlLayers() +{ + return QQmlListProperty<QLayer>(this, 0, + &Quick3DLayerFilter::appendLayer, + &Quick3DLayerFilter::layerCount, + &Quick3DLayerFilter::layerAt, + &Quick3DLayerFilter::clearLayers); +} + +void Quick3DLayerFilter::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer) +{ + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + filter->parentFilter()->addLayer(layer); + } +} + +QLayer *Quick3DLayerFilter::layerAt(QQmlListProperty<QLayer> *list, int index) +{ + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + return filter->parentFilter()->layers().at(index); + } + return 0; +} + +int Quick3DLayerFilter::layerCount(QQmlListProperty<QLayer> *list) +{ + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + return filter->parentFilter()->layers().count(); + } + return 0; +} + +void Quick3DLayerFilter::clearLayers(QQmlListProperty<QLayer> *list) +{ + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + Q_FOREACH (QLayer *layer, filter->parentFilter()->layers()) { + filter->parentFilter()->removeLayer(layer); + } + } +} + +} // Quick + +} // namespace Render + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h b/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h new file mode 100644 index 000000000..b2e7e2d11 --- /dev/null +++ b/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_QUICK_QUICK3DLAYERFILTER_P_H +#define QT3DRENDER_RENDER_QUICK_QUICK3DLAYERFILTER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DQuickRender/private/qt3dquickrender_global_p.h> +#include <Qt3DRender/qlayerfilter.h> +#include <Qt3DRender/qlayer.h> +#include <QQmlListProperty> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { +namespace Quick { + +class QT3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DLayerFilter : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DRender::QLayer> layers READ qmlLayers) + +public: + explicit Quick3DLayerFilter(QObject *parent = 0); + + inline QLayerFilter *parentFilter() const { return qobject_cast<QLayerFilter*>(parent()); } + + QQmlListProperty<QLayer> qmlLayers(); + +private: + static void appendLayer(QQmlListProperty<QLayer> *list, QLayer *bar); + static QLayer *layerAt(QQmlListProperty<QLayer> *list, int index); + static int layerCount(QQmlListProperty<QLayer> *list); + static void clearLayers(QQmlListProperty<QLayer> *list); +}; + +} // namespace Quick +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_QUICK_QUICK3DLAYERFILTER_P_H |