diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2013-11-18 12:43:13 +0100 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2013-11-18 12:46:09 +0100 |
commit | 0b989bae42739f289be46b44e9a62318e21f9f03 (patch) | |
tree | 737a97379246357c41e22ee46600056502fe2494 | |
parent | 05fb95d9bdab45a411746ceb6ac0ce5e3f958d7b (diff) | |
download | qtquickstreamer-wip.tar.gz qtquickstreamer-wip.tar.xz |
WIP: allow other objects with gstElement propertywip
-rw-r--r-- | src/QuickStreamer/item.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/QuickStreamer/item.cpp b/src/QuickStreamer/item.cpp index 3656e61..70f3b06 100644 --- a/src/QuickStreamer/item.cpp +++ b/src/QuickStreamer/item.cpp @@ -492,11 +492,11 @@ static void writeNothing(Item *item, const QByteArray &name, const void *) G_OBJECT_TYPE_NAME(item->target()), name.constData()); } -class ElementList : public QQmlListProperty<Item> +class ElementList : public QQmlListProperty<QObject> { public: explicit ElementList(Item *item = Q_NULLPTR) - : QQmlListProperty<Item>(item, Q_NULLPTR, + : QQmlListProperty<QObject>(item, Q_NULLPTR, &ElementList::appendChild, &ElementList::countChildren, &ElementList::childAt, @@ -504,13 +504,15 @@ public: { } - static void appendChild(QQmlListProperty<Item> *list, Item *child) + static void appendChild(QQmlListProperty<QObject> *list, QObject *child) { auto *const parent = static_cast<Item *>(list->object); - gst_bin_add(GST_BIN(parent->target()), GST_ELEMENT(child->target())); + GstElement *target = getTarget(child); + if (target) + gst_bin_add(GST_BIN(parent->target()), target); } - static int countChildren(QQmlListProperty<Item> *list) + static int countChildren(QQmlListProperty<QObject> *list) { auto *const parent = static_cast<Item *>(list->object); ObjectLocker locker(parent->target()); @@ -518,7 +520,7 @@ public: return GST_BIN_NUMCHILDREN(parent->target()); } - static Item *childAt(QQmlListProperty<Item> *list, int offset) + static QObject *childAt(QQmlListProperty<QObject> *list, int offset) { auto *const parent = static_cast<Item *>(list->object); ObjectLocker locker(parent->target()); @@ -529,10 +531,10 @@ public: ? 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), ITEM_DATA_QUARK) : Q_NULLPTR); + return static_cast<QObject *>(child ? g_object_get_qdata(G_OBJECT(child), ITEM_DATA_QUARK) : Q_NULLPTR); } - static void clearChildren(QQmlListProperty<Item> *list) + static void clearChildren(QQmlListProperty<QObject> *list) { auto *const parent = static_cast<Item *>(list->object); auto *const elementBin = GST_BIN(parent->target()); @@ -541,6 +543,20 @@ public: while (elementBin->children) gst_bin_remove(elementBin, GST_ELEMENT(elementBin->children->data)); } + +private: + static GstElement *getTarget(QObject *object) + { + if (Item *item = qobject_cast<Item*>(object)) + return GST_ELEMENT(item->target()); + if (object->metaObject()->indexOfProperty("gstElement") != -1) { + GstElement *target = reinterpret_cast<GstElement*>(object->property("gstElement").value<void*>()); + if (g_object_get_qdata(G_OBJECT(target), ITEM_DATA_QUARK) == Q_NULLPTR) + qWarning("child with 'gstElement' property but without GObject qdata!"); + return target; + } + return Q_NULLPTR; + } }; static void readChildren(Item *item, void *value) @@ -646,7 +662,7 @@ struct TypeInfo if (type == GST_TYPE_BIN) { static const auto propertyName = QByteArrayLiteral("children"); typeInfo->addProperty({ Q_NULLPTR, readChildren, Q_NULLPTR }, - propertyName, elementListTypeName, &objectBuilder); + propertyName, "QQmlListProperty<QObject>", &objectBuilder); objectBuilder.addClassInfo(QByteArrayLiteral("DefaultProperty"), propertyName); } |