summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3drenderer
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire.ecortex@kdab.com>2014-12-04 11:54:55 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-12-12 14:17:39 +0100
commit87401507ec111dc1b6bf252a8662d90d5caae523 (patch)
tree425b1a632b798e68d6cb1a95119cde7914a3dcc0 /src/quick3d/quick3drenderer
parent634285f5e0c2555bd108f5f8ed979a0a18505429 (diff)
Quick3DShaderDataArray
QML allows property var array: [] of simple types only. We can't use a var property to store an array of ShaderDataObject so Quick3DShaderDataArray was introduce to overcome that issue. It contains a QQmlListProperty<Quick3DShaderData>. This is only needed for QML, in C++ providing a QVariantList of QShaderData is enough. Change-Id: I768f5189252c219c5a1718b4c4da128bbaff008e Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drenderer')
-rw-r--r--src/quick3d/quick3drenderer/items/items.pri6
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dshaderdataarray.cpp121
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dshaderdataarray.h93
3 files changed, 218 insertions, 2 deletions
diff --git a/src/quick3d/quick3drenderer/items/items.pri b/src/quick3d/quick3drenderer/items/items.pri
index b00ef0560..b3b1c742a 100644
--- a/src/quick3d/quick3drenderer/items/items.pri
+++ b/src/quick3d/quick3drenderer/items/items.pri
@@ -14,7 +14,8 @@ HEADERS += \
$$PWD/quick3dsortmethod.h \
$$PWD/quick3dparameter_p.h \
$$PWD/quick3dparameter.h \
- $$PWD/quick3dshaderdata.h
+ $$PWD/quick3dshaderdata.h \
+ $$PWD/quick3dshaderdataarray.h
SOURCES += \
$$PWD/quick3drenderpassfilter.cpp \
@@ -31,6 +32,7 @@ SOURCES += \
$$PWD/quick3dframegraphitem.cpp \
$$PWD/quick3dsortmethod.cpp \
$$PWD/quick3dparameter.cpp \
- $$PWD/quick3dshaderdata.cpp
+ $$PWD/quick3dshaderdata.cpp \
+ $$PWD/quick3dshaderdataarray.cpp
INCLUDEPATH += $$PWD
diff --git a/src/quick3d/quick3drenderer/items/quick3dshaderdataarray.cpp b/src/quick3d/quick3drenderer/items/quick3dshaderdataarray.cpp
new file mode 100644
index 000000000..6fe166688
--- /dev/null
+++ b/src/quick3d/quick3drenderer/items/quick3dshaderdataarray.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "quick3dshaderdataarray.h"
+#include <private/qshaderdata_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+namespace Quick {
+
+class Quick3DShaderDataArrayPrivate : public QNodePrivate
+{
+public:
+ Quick3DShaderDataArrayPrivate(Quick3DShaderDataArray *qq)
+ : QNodePrivate(qq)
+ {}
+
+ QList<Quick3DShaderData *> m_values;
+};
+
+Quick3DShaderDataArray::Quick3DShaderDataArray(QNode *parent)
+ : QNode(*new Quick3DShaderDataArrayPrivate(this), parent)
+{
+}
+
+QQmlListProperty<Quick3DShaderData> Quick3DShaderDataArray::valuesList()
+{
+ return QQmlListProperty<Quick3DShaderData>(this, 0,
+ &Quick3DShaderDataArray::appendValue,
+ &Quick3DShaderDataArray::valueCount,
+ &Quick3DShaderDataArray::valueAt,
+ &Quick3DShaderDataArray::clearValues);
+}
+
+QList<Quick3DShaderData *> Quick3DShaderDataArray::values() const
+{
+ Q_D(const Quick3DShaderDataArray);
+ return d->m_values;
+}
+
+void Quick3DShaderDataArray::copy(const QNode *ref)
+{
+ QNode::copy(ref);
+ const Quick3DShaderDataArray *dataArray = static_cast<const Quick3DShaderDataArray *>(ref);
+ Q_FOREACH (Quick3DShaderData *v, dataArray->d_func()->m_values)
+ d_func()->m_values.append(static_cast<Quick3DShaderData *>(QNode::clone(v)));
+}
+
+void Quick3DShaderDataArray::appendValue(QQmlListProperty<Quick3DShaderData> *list, Quick3DShaderData *bar)
+{
+ Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object);
+ static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar);
+}
+
+Quick3DShaderData *Quick3DShaderDataArray::valueAt(QQmlListProperty<Quick3DShaderData> *list, int index)
+{
+ Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object);
+ return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index);
+}
+
+int Quick3DShaderDataArray::valueCount(QQmlListProperty<Quick3DShaderData> *list)
+{
+ Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object);
+ return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.count();
+}
+
+void Quick3DShaderDataArray::clearValues(QQmlListProperty<Quick3DShaderData> *list)
+{
+ Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object);
+ static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.clear();
+}
+
+} // Quick
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quick3drenderer/items/quick3dshaderdataarray.h b/src/quick3d/quick3drenderer/items/quick3dshaderdataarray.h
new file mode 100644
index 000000000..710d16519
--- /dev/null
+++ b/src/quick3d/quick3drenderer/items/quick3dshaderdataarray.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_RENDER_QUICK_QUICK3DSHADERDATAARRAY_H
+#define QT3D_RENDER_QUICK_QUICK3DSHADERDATAARRAY_H
+
+#include <Qt3DCore/qnode.h>
+#include <Qt3DQuickRenderer/qt3dquickrenderer_global.h>
+#include <Qt3DQuickRenderer/quick3dshaderdata.h>
+#include <QQmlListProperty>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+namespace Quick {
+
+class Quick3DShaderDataArrayPrivate;
+class Quick3DShaderData;
+
+class QT3DQUICKRENDERERSHARED_EXPORT Quick3DShaderDataArray : public QNode
+{
+ Q_OBJECT
+ Q_PROPERTY(QQmlListProperty<Qt3D::Render::Quick::Quick3DShaderData> values READ valuesList)
+ Q_CLASSINFO("DefaultProperty", "values")
+public:
+ explicit Quick3DShaderDataArray(QNode *parent = 0);
+ QQmlListProperty<Quick3DShaderData> valuesList();
+ QList<Quick3DShaderData *> values() const;
+
+protected:
+ void copy(const QNode *ref) Q_DECL_OVERRIDE;
+
+private:
+ static void appendValue(QQmlListProperty<Quick3DShaderData> *list, Quick3DShaderData *bar);
+ static Quick3DShaderData *valueAt(QQmlListProperty<Quick3DShaderData> *list, int index);
+ static int valueCount(QQmlListProperty<Quick3DShaderData> *list);
+ static void clearValues(QQmlListProperty<Quick3DShaderData> *list);
+ Q_DECLARE_PRIVATE(Quick3DShaderDataArray)
+ QT3D_CLONEABLE(Quick3DShaderDataArray)
+};
+
+} // Quick
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3D::Render::Quick::Quick3DShaderDataArray *)
+
+#endif // QT3D_RENDER_QUICK_QUICK3DSHADERDATAARRAY_H