summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Hasselmann <mathias.hasselmann@kdab.com>2013-11-06 23:40:05 +0100
committerMathias Hasselmann <mathias.hasselmann@kdab.com>2013-11-06 23:40:05 +0100
commitddcc65b5430b20a4425b1ceacd1550b08da4b68a (patch)
tree300c7ef92427d56ad456e2de4bd3012f3ed8d1fd
parent6eeba4f47a619f68b361f11a7a763657a2a4cb4f (diff)
Implement ElementList::childAt()
-rw-r--r--src/QuickStreamer/item.cpp19
-rw-r--r--tests/tst_qml/tst_quickstreamer.qml16
2 files changed, 29 insertions, 6 deletions
diff --git a/src/QuickStreamer/item.cpp b/src/QuickStreamer/item.cpp
index 53aef4b..ddc986d 100644
--- a/src/QuickStreamer/item.cpp
+++ b/src/QuickStreamer/item.cpp
@@ -12,6 +12,8 @@
namespace QQuickStreamer {
namespace Private {
+static const GQuark quickStreamItemQuark = g_quark_from_static_string("quick-streamer-item-quark");
+
class ObjectLocker
{
public:
@@ -326,9 +328,17 @@ public:
static Item *childAt(QQmlListProperty<Item> *list, int offset)
{
- // FIXME: need to store the wrapper object somewhere
- qDebug() << Q_FUNC_INFO;
- return Q_NULLPTR;
+ auto *const parent = static_cast<Item *>(list->object);
+ ObjectLocker locker(parent->target());
+
+ const int n = GST_BIN_NUMCHILDREN(parent->target());
+
+ auto *const child = offset >= 0 && offset < n
+ ? g_list_nth_data(GST_BIN_CHILDREN(parent->target()), n - offset - 1)
+ : Q_NULLPTR;
+
+ return static_cast<Item *>(child ? g_object_get_qdata(G_OBJECT(child), quickStreamItemQuark)
+ : Q_NULLPTR);
}
static void clearChildren(QQmlListProperty<Item> *list)
@@ -641,14 +651,17 @@ QHash<GType, TypeInfo *> TypeInfo::cache;
using Private::TypeInfo;
using Private::toCamelCase;
+using Private::quickStreamItemQuark;
Item::Item(GstObject *target, QObject *parent)
: QObject(parent)
, m_target(target)
{
Q_ASSERT(m_target != Q_NULLPTR);
+ Q_ASSERT(g_object_get_qdata(G_OBJECT(m_target), quickStreamItemQuark) == Q_NULLPTR);
g_object_ref_sink(m_target);
+ g_object_set_qdata(G_OBJECT(m_target), quickStreamItemQuark, this);
auto notifyCallback = reinterpret_cast<GCallback>(&Item::emitPropertyChanged);
g_signal_connect_swapped(target, "notify", notifyCallback, this);
diff --git a/tests/tst_qml/tst_quickstreamer.qml b/tests/tst_qml/tst_quickstreamer.qml
index 7b289a5..6ce8dc5 100644
--- a/tests/tst_qml/tst_quickstreamer.qml
+++ b/tests/tst_qml/tst_quickstreamer.qml
@@ -18,12 +18,22 @@ TestCase {
}
}
- function test_properties()
+ function test_nameProperty()
{
- console.log([pipeline.name, appSink.name, appSource.name])
-
compare(pipeline.name, "pipeline0")
compare(appSink.name, "appsink0")
compare(appSource.name, "brouhaha")
}
+
+ function test_children()
+ {
+ console.log(pipeline.children)
+
+ compare(pipeline.children.length, 2)
+ compare(pipeline.children[0], appSource)
+ compare(pipeline.children[1], appSink)
+
+ compare(appSink.children, undefined)
+ compare(appSource.children, undefined)
+ }
}