diff options
author | Mathias Hasselmann <mathias.hasselmann@kdab.com> | 2013-11-06 22:37:50 +0100 |
---|---|---|
committer | Mathias Hasselmann <mathias.hasselmann@kdab.com> | 2013-11-06 22:37:50 +0100 |
commit | c2bbf169b37d75a300592a1fd7cc8fb1e3a2ae8f (patch) | |
tree | 577346bf8e596625052c2298023bd8e96a08059a | |
parent | 6f8033b52e59cfcf1d76d70875eb7495cfeccb49 (diff) |
Use proper children list type
-rw-r--r-- | src/QuickStreamer/item.cpp | 68 | ||||
-rw-r--r-- | src/QuickStreamer/plugin.cpp | 1 |
2 files changed, 38 insertions, 31 deletions
diff --git a/src/QuickStreamer/item.cpp b/src/QuickStreamer/item.cpp index 0425fda..e757dda 100644 --- a/src/QuickStreamer/item.cpp +++ b/src/QuickStreamer/item.cpp @@ -12,8 +12,7 @@ namespace QQuickStreamer { namespace Private { -typedef QQmlListProperty<QObject> ItemList; -// FIXME typedef QQmlListProperty<Item> ItemList; +typedef QQmlListProperty<Item> ElementList; struct PropertyInfo { @@ -282,28 +281,28 @@ static void writeNothing(Item *item, const QByteArray &name, const void *) G_OBJECT_TYPE_NAME(item->target()), name.constData()); } -static void appendChild(ItemList *list, QObject *child) +static void appendChild(ElementList *list, Item *child) { - auto *const parentItem = static_cast<Item *>(list->object); - auto *const childItem = static_cast<Item *>(child); + auto *const parent = static_cast<Item *>(list->object); - gst_bin_add(GST_BIN(parentItem->target()), - GST_ELEMENT(childItem->target())); + gst_bin_add(GST_BIN(parent->target()), + GST_ELEMENT(child->target())); } -static int countChildren(ItemList *list) +static int countChildren(ElementList *list) { auto *const parentItem = static_cast<Item *>(list->object); return GST_BIN_NUMCHILDREN(parentItem->target()); } -static QObject *childAt(ItemList *list, int offset) +static Item *childAt(ElementList *list, int offset) { // FIXME: need to store the wrapper object somewhere qDebug() << Q_FUNC_INFO; + return Q_NULLPTR; } -static void clearChildren(ItemList *list) +static void clearChildren(ElementList *list) { auto *const parentItem = static_cast<Item *>(list->object); auto *const elementBin = GST_BIN(parentItem->target()); @@ -314,8 +313,8 @@ static void clearChildren(ItemList *list) static void readChildren(Item *item, void *value) { - *static_cast<ItemList *>(value) = - ItemList(item, Q_NULLPTR, &appendChild, &countChildren, &childAt, &clearChildren); + *static_cast<ElementList *>(value) = + ElementList(item, Q_NULLPTR, &appendChild, &countChildren, &childAt, &clearChildren); } static void readState(Item *item, void *value) @@ -376,19 +375,8 @@ struct TypeInfo : &QObject::staticMetaObject); // FIXME : itemMetaObject); - if (g_type_is_a(type, GST_TYPE_BIN)) { - auto notifier = objectBuilder.addSignal(QByteArrayLiteral("childrenChanged()")); - auto property = objectBuilder.addProperty(QByteArrayLiteral("children"), - QByteArrayLiteral("QQmlListProperty<QObject>"), -// FIXME QByteArrayLiteral("QQmlListProperty<QQuickStreamer::Item>"), - notifier.index()); - - property.setReadable(true); - property.setWritable(false); - - typeInfo->properties.append({Q_NULLPTR, readChildren, Q_NULLPTR}); - objectBuilder.addClassInfo(QByteArrayLiteral("DefaultProperty"), property.name()); - } + static const auto elementListTypeName = QByteArrayLiteral("QQmlListProperty<GstElement>"); + static const auto elementListTypeId = qRegisterNormalizedMetaType<ElementList>(elementListTypeName); if (type == GST_TYPE_ELEMENT) { auto stateEnum = objectBuilder.addEnumerator(QByteArrayLiteral("State")); @@ -397,6 +385,8 @@ struct TypeInfo stateEnum.addKey(QByteArrayLiteral("Ready"), static_cast<int>(GST_STATE_READY)); stateEnum.addKey(QByteArrayLiteral("Paused"), static_cast<int>(GST_STATE_PAUSED)); stateEnum.addKey(QByteArrayLiteral("Playing"), static_cast<int>(GST_STATE_PLAYING)); + + qRegisterNormalizedMetaType<ElementList>("QQmlListProperty<GstElement>"); } if (g_type_is_a(type, GST_TYPE_ELEMENT)) { @@ -404,8 +394,7 @@ struct TypeInfo auto notifier = objectBuilder.addSignal(QByteArrayLiteral("stateChanged()")); auto property = objectBuilder.addProperty(QByteArrayLiteral("state"), - //QByteArrayLiteral("int"), // FIXME - QByteArrayLiteral("GstElement::State"), // FIXME + QByteArrayLiteral("GstElement::State"), notifier.index()); property.setReadable(true); @@ -414,6 +403,20 @@ struct TypeInfo typeInfo->properties.append({Q_NULLPTR, readState, writeState}); } + + if (g_type_is_a(type, GST_TYPE_BIN)) { + auto notifier = objectBuilder.addSignal(QByteArrayLiteral("childrenChanged()")); + auto property = objectBuilder.addProperty(QByteArrayLiteral("children"), + elementListTypeName, + notifier.index()); + + property.setReadable(true); + property.setWritable(false); + + typeInfo->properties.append({Q_NULLPTR, readChildren, Q_NULLPTR}); + objectBuilder.addClassInfo(QByteArrayLiteral("DefaultProperty"), property.name()); + } + const auto gobject_class = static_cast<GObjectClass *>(g_type_class_ref(type)); uint nPSpecs = 0; @@ -491,16 +494,19 @@ struct TypeInfo const static int MAJOR_VERSION = 1; const static int MINOR_VERSION = 0; - auto listName = QByteArrayLiteral("QQmlListProperty<") + objectBuilder.className() + '>'; + // Check if this is GstElement or below + const bool abstractType = g_type_is_a(GST_TYPE_ELEMENT, type); QQmlPrivate::RegisterType qmlType = { 1, typeId, - 0, // FIXME: qRegisterNormalizedMetaType<ItemList>(listName.constData()), + type == GST_TYPE_ELEMENT ? elementListTypeId : 0, sizeof(Item), - metaTypePads.createInto, - QString(), + abstractType ? Q_NULLPTR : metaTypePads.createInto, + abstractType ? QStringLiteral("%1 is an abstract type"). + arg(QString::fromLatin1(typeInfo->elementName)) + : QString(), NAMESPACE_URI, MAJOR_VERSION, MINOR_VERSION, typeInfo->elementName, diff --git a/src/QuickStreamer/plugin.cpp b/src/QuickStreamer/plugin.cpp index fd10f2f..936eb68 100644 --- a/src/QuickStreamer/plugin.cpp +++ b/src/QuickStreamer/plugin.cpp @@ -30,6 +30,7 @@ void Plugin::registerTypes(const char *uri) Item::registerObjectClass(GST_TYPE_BIN); Item::registerObjectClass(GST_TYPE_PIPELINE); + Item::registerObjectClass(GST_TYPE_PAD); auto *const elements = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_ANY, GST_RANK_NONE); |