diff options
author | Mathias Hasselmann <mathias.hasselmann@kdab.com> | 2013-11-07 15:15:30 +0100 |
---|---|---|
committer | Mathias Hasselmann <mathias.hasselmann@kdab.com> | 2013-11-07 15:15:30 +0100 |
commit | dc38aef1ab54bfab5cb3f79c035b1cc23d73d973 (patch) | |
tree | 012cb3882b1bdc11c4fe8285de1cd3c203e01df5 | |
parent | ddcc65b5430b20a4425b1ceacd1550b08da4b68a (diff) |
Sanitize property construction a bit
-rw-r--r-- | src/QuickStreamer/item.cpp | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/src/QuickStreamer/item.cpp b/src/QuickStreamer/item.cpp index ddc986d..863243a 100644 --- a/src/QuickStreamer/item.cpp +++ b/src/QuickStreamer/item.cpp @@ -400,6 +400,20 @@ struct TypeInfo return objectBuilder.toMetaObject(); } + void addProperty(const PropertyInfo &propertyInfo, + const QByteArray &propertyName, + const QByteArray &typeName, + QMetaObjectBuilder *objectBuilder) + { + auto notifierBuilder = objectBuilder->addSignal(propertyName + QByteArrayLiteral("Changed()")); + auto propertyBuilder = objectBuilder->addProperty(propertyName, typeName, notifierBuilder.index()); + + propertyBuilder.setReadable(propertyInfo.read != Q_NULLPTR); + propertyBuilder.setWritable(propertyInfo.write != Q_NULLPTR); + + properties.append(propertyInfo); + } + static const TypeInfo *create(GType type, const MetaTypePads &metaTypePads) { QScopedPointer<TypeInfo> typeInfo(new TypeInfo); @@ -426,35 +440,18 @@ struct TypeInfo 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)) { // FIXME: also add pendingState property? - - auto notifier = objectBuilder.addSignal(QByteArrayLiteral("stateChanged()")); - auto property = objectBuilder.addProperty(QByteArrayLiteral("state"), - QByteArrayLiteral("GstElement::State"), - notifier.index()); - - property.setReadable(true); - property.setWritable(true); - - typeInfo->properties.append({Q_NULLPTR, readState, writeState}); + typeInfo->addProperty({ Q_NULLPTR, readState, writeState }, + QByteArrayLiteral("state"), + QByteArrayLiteral("GstElement::State"), + &objectBuilder); } - - 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()); + if (type == GST_TYPE_BIN) { + static const auto propertyName = QByteArrayLiteral("children"); + typeInfo->addProperty({ Q_NULLPTR, readChildren, Q_NULLPTR }, + propertyName, elementListTypeName, &objectBuilder); + objectBuilder.addClassInfo(QByteArrayLiteral("DefaultProperty"), propertyName); } const auto gobject_class = static_cast<GObjectClass *>(g_type_class_ref(type)); @@ -482,22 +479,17 @@ struct TypeInfo continue; } - auto notifier = objectBuilder.addSignal(propertyName + QByteArrayLiteral("Changed()")); - auto property = objectBuilder.addProperty(propertyName, propertyType, notifier.index()); - - property.setReadable(pSpec->flags & G_PARAM_READABLE); - property.setWritable(pSpec->flags & G_PARAM_WRITABLE); - using namespace std::placeholders; - const auto readDelegate = property.isReadable() + const auto readDelegate = pSpec->flags & G_PARAM_READABLE ? bindReadDelegate(&readGObjectProperty, _1, pSpec->name, pSpec->value_type, _2) : bindReadDelegate(&readNothing, _1, pSpec->name, _2); - const auto writeDelegate = property.isWritable() + const auto writeDelegate = pSpec->flags & G_PARAM_WRITABLE ? bindWriteDelegate(&writeGObjectProperty, _1, pSpec->name, pSpec->value_type, _2) : bindWriteDelegate(&writeNothing, _1, pSpec->name, _2); - typeInfo->properties.append({pSpec->name, readDelegate, writeDelegate}); + typeInfo->addProperty({pSpec->name, readDelegate, writeDelegate}, + propertyName, propertyType, &objectBuilder); } g_free(pSpecs); |