本文整理汇总了C++中QMetaObjectBuilder::addProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaObjectBuilder::addProperty方法的具体用法?C++ QMetaObjectBuilder::addProperty怎么用?C++ QMetaObjectBuilder::addProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaObjectBuilder
的用法示例。
在下文中一共展示了QMetaObjectBuilder::addProperty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deserializeInitDynamicPacket
void deserializeInitDynamicPacket(QDataStream &in, QMetaObjectBuilder &builder, QVariantList &values)
{
quint32 numSignals = 0;
quint32 numMethods = 0;
quint32 numProperties = 0;
in >> numSignals;
in >> numMethods;
int curIndex = 0;
for (quint32 i = 0; i < numSignals; ++i) {
QByteArray signature;
in >> signature;
++curIndex;
builder.addSignal(signature);
}
for (quint32 i = 0; i < numMethods; ++i) {
QByteArray signature, returnType;
in >> signature;
in >> returnType;
++curIndex;
const bool isVoid = returnType.isEmpty() || returnType == QByteArrayLiteral("void");
if (isVoid)
builder.addMethod(signature);
else
builder.addMethod(signature, QByteArrayLiteral("QRemoteObjectPendingCall"));
}
in >> numProperties;
const quint32 initialListSize = values.size();
if (static_cast<quint32>(values.size()) < numProperties)
values.reserve(numProperties);
else if (static_cast<quint32>(values.size()) > numProperties)
for (quint32 i = numProperties; i < initialListSize; ++i)
values.removeLast();
for (quint32 i = 0; i < numProperties; ++i) {
QByteArray name;
QByteArray typeName;
QByteArray signalName;
in >> name;
in >> typeName;
in >> signalName;
if (signalName.isEmpty())
builder.addProperty(name, typeName);
else
builder.addProperty(name, typeName, builder.indexOfSignal(signalName));
QVariant value;
in >> value;
if (i < initialListSize)
values[i] = value;
else
values.append(value);
}
}
示例2:
QMetaObject *GoValue::metaObjectFor(GoTypeInfo *typeInfo)
{
if (typeInfo->metaObject) {
return reinterpret_cast<QMetaObject *>(typeInfo->metaObject);
}
QMetaObjectBuilder mob;
mob.setSuperClass(&QObject::staticMetaObject);
mob.setClassName(typeInfo->typeName);
mob.setFlags(QMetaObjectBuilder::DynamicMetaObject);
GoMemberInfo *memberInfo;
memberInfo = typeInfo->fields;
int relativePropIndex = mob.propertyCount();
for (int i = 0; i < typeInfo->fieldsLen; i++) {
mob.addSignal("__" + QByteArray::number(relativePropIndex) + "()");
QMetaPropertyBuilder propb = mob.addProperty(memberInfo->memberName, "QVariant", relativePropIndex);
propb.setWritable(true);
memberInfo->metaIndex = relativePropIndex;
memberInfo++;
relativePropIndex++;
}
memberInfo = typeInfo->methods;
int relativeMethodIndex = mob.methodCount();
for (int i = 0; i < typeInfo->methodsLen; i++) {
if (*memberInfo->resultSignature) {
mob.addMethod(memberInfo->methodSignature, memberInfo->resultSignature);
} else {
mob.addMethod(memberInfo->methodSignature);
}
memberInfo->metaIndex = relativeMethodIndex;
memberInfo++;
relativeMethodIndex++;
}
QMetaObject *mo = mob.toMetaObject();
// Turn the relative indexes into absolute indexes.
memberInfo = typeInfo->fields;
int propOffset = mo->propertyOffset();
for (int i = 0; i < typeInfo->fieldsLen; i++) {
memberInfo->metaIndex += propOffset;
memberInfo++;
}
memberInfo = typeInfo->methods;
int methodOffset = mo->methodOffset();
for (int i = 0; i < typeInfo->methodsLen; i++) {
memberInfo->metaIndex += methodOffset;
memberInfo++;
}
typeInfo->metaObject = mo;
return mo;
}
示例3: qMakePair
QMetaObject *DosQMetaObject::createMetaObject(const QString &className,
const SignalDefinitions &signalDefinitions,
const SlotDefinitions &slotDefinitions,
const PropertyDefinitions &propertyDefinitions)
{
QMetaObjectBuilder builder;
builder.setClassName(className.toUtf8());
builder.setSuperClass(m_superClassDosMetaObject->metaObject());
for (const SignalDefinition &signal : signalDefinitions) {
QMetaMethodBuilder signalBuilder = builder.addSignal(::createSignature(signal));
signalBuilder.setReturnType(QMetaType::typeName(QMetaType::Void));
signalBuilder.setAccess(QMetaMethod::Public);
signalBuilder.setParameterNames(createParameterNames(signal));
m_signalIndexByName[signal.name] = signalBuilder.index();
}
QHash<QString, int> methodIndexByName;
for (const SlotDefinition &slot : slotDefinitions) {
QMetaMethodBuilder methodBuilder = builder.addSlot(::createSignature(slot));
methodBuilder.setReturnType(QMetaType::typeName(slot.returnType));
methodBuilder.setAttributes(QMetaMethod::Scriptable);
methodIndexByName[slot.name] = methodBuilder.index();
}
for (const PropertyDefinition &property : propertyDefinitions) {
const int writer = methodIndexByName.value(property.writeSlot, -1);
const int notifier = m_signalIndexByName.value(property.notifySignal, -1);
const QByteArray name = property.name.toUtf8();
const QByteArray typeName = QMetaObject::normalizedType(QMetaType::typeName(property.type));
QMetaPropertyBuilder propertyBuilder = builder.addProperty(name, typeName, notifier);
if (writer == -1)
propertyBuilder.setWritable(false);
if (notifier == -1)
propertyBuilder.setConstant(true);
m_propertySlots[property.name] = qMakePair(methodIndexByName.value(property.readSlot, -1),
methodIndexByName.value(property.writeSlot, -1));
}
return builder.toMetaObject();
}
示例4:
QMetaObject *metaObjectFor(GoTypeInfo *typeInfo)
{
if (typeInfo->metaObject) {
return reinterpret_cast<QMetaObject *>(typeInfo->metaObject);
}
QMetaObjectBuilder mob;
if (typeInfo->paint) {
mob.setSuperClass(&QQuickPaintedItem::staticMetaObject);
} else {
mob.setSuperClass(&QObject::staticMetaObject);
}
mob.setClassName(typeInfo->typeName);
mob.setFlags(QMetaObjectBuilder::DynamicMetaObject);
GoMemberInfo *memberInfo;
memberInfo = typeInfo->fields;
int relativePropIndex = mob.propertyCount();
for (int i = 0; i < typeInfo->fieldsLen; i++) {
mob.addSignal("__" + QByteArray::number(relativePropIndex) + "()");
const char *typeName = "QVariant";
if (memberInfo->memberType == DTListProperty) {
typeName = "QQmlListProperty<QObject>";
}
QMetaPropertyBuilder propb = mob.addProperty(memberInfo->memberName, typeName, relativePropIndex);
propb.setWritable(true);
memberInfo->metaIndex = relativePropIndex;
memberInfo++;
relativePropIndex++;
}
memberInfo = typeInfo->methods;
int relativeMethodIndex = mob.methodCount();
for (int i = 0; i < typeInfo->methodsLen; i++) {
if (*memberInfo->resultSignature) {
mob.addMethod(memberInfo->methodSignature, memberInfo->resultSignature);
} else {
mob.addMethod(memberInfo->methodSignature);
}
memberInfo->metaIndex = relativeMethodIndex;
memberInfo++;
relativeMethodIndex++;
}
// TODO Support default properties.
//mob.addClassInfo("DefaultProperty", "objects");
QMetaObject *mo = mob.toMetaObject();
// Turn the relative indexes into absolute indexes.
memberInfo = typeInfo->fields;
int propOffset = mo->propertyOffset();
for (int i = 0; i < typeInfo->fieldsLen; i++) {
memberInfo->metaIndex += propOffset;
memberInfo++;
}
memberInfo = typeInfo->methods;
int methodOffset = mo->methodOffset();
for (int i = 0; i < typeInfo->methodsLen; i++) {
memberInfo->metaIndex += methodOffset;
memberInfo++;
}
typeInfo->metaObject = mo;
return mo;
}
示例5: create_dynamic_metaobject
//.........这里部分代码省略.........
#if QT_VERSION < 0x050000
notify_signals.append(notifier_id);
flags |= 0x00400000;
#endif
}
else
{
#if QT_VERSION >= 0x050000
notifier_id = -1;
#else
notify_signals.append(0);
#endif
}
#if QT_VERSION >= 0x050000
// A Qt v5 revision 7 meta-object holds the QMetaType::Type of the type
// or its name if it is unresolved (ie. not known to the type system).
// In Qt v4 both are held. For QObject sub-classes Chimera will fall
// back to the QMetaType::QObjectStar if there is no specific meta-type
// for the sub-class. This means that, for Qt v4,
// QMetaProperty::read() can handle the type. However, Qt v5 doesn't
// know that the unresolved type is a QObject sub-class. Therefore we
// have to tell it that the property is a QObject, rather than the
// sub-class. This means that QMetaProperty.typeName() will always
// return "QObject*".
QByteArray prop_type;
if (pp->pyqtprop_parsed_type->metatype() == QMetaType::QObjectStar)
prop_type = "QObject*";
else
prop_type = pp->pyqtprop_parsed_type->name();
QMetaPropertyBuilder prop_builder = builder.addProperty(prop_name,
prop_type, notifier_id);
// Reset the defaults.
prop_builder.setReadable(false);
prop_builder.setWritable(false);
#else
// Add the property name.
data[p_offset + (p * 3) + 0] = qo->str_data.size();
qo->str_data.append(prop_name);
qo->str_data.append('\0');
// Add the name of the property type.
data[p_offset + (p * 3) + 1] = qo->str_data.size();
qo->str_data.append(pp->pyqtprop_parsed_type->name());
qo->str_data.append('\0');
// There are only 8 bits available for the type so use the special
// value if more are required.
uint metatype = pp->pyqtprop_parsed_type->metatype();
if (metatype > 0xff)
{
#if QT_VERSION >= 0x040600
// Qt assumes it is an enum.
metatype = 0;
flags |= 0x00000008;
#else
// This is the old PyQt behaviour. It may not be correct, but
// nobody has complained, and if it ain't broke...
metatype = 0xff;
#endif
}
示例6: create_dynamic_metaobject
//.........这里部分代码省略.........
// A Qt v5 revision 7 meta-object holds the QMetaType::Type of the type
// or its name if it is unresolved (ie. not known to the type system).
// In Qt v4 both are held. For QObject sub-classes Chimera will fall
// back to the QMetaType::QObjectStar if there is no specific meta-type
// for the sub-class. This means that, for Qt v4,
// QMetaProperty::read() can handle the type. However, Qt v5 doesn't
// know that the unresolved type is a QObject sub-class. Therefore we
// have to tell it that the property is a QObject, rather than the
// sub-class. This means that QMetaProperty.typeName() will always
// return "QObject*".
QByteArray prop_type;
if (pp->pyqtprop_parsed_type->metatype() == QMetaType::QObjectStar)
{
// However, if the type is a Python sub-class of QObject then we
// use the name of the Python type. This anticipates that the type
// is one that will be proxied by QML at some point.
if (pp->pyqtprop_parsed_type->typeDef() == sipType_QObject)
{
prop_type = ((PyTypeObject *)pp->pyqtprop_parsed_type->py_type())->tp_name;
prop_type.append('*');
}
else
{
prop_type = "QObject*";
}
}
else
{
prop_type = pp->pyqtprop_parsed_type->name();
}
QMetaPropertyBuilder prop_builder = builder.addProperty(prop_name,
prop_type, notifier_id);
// Reset the defaults.
prop_builder.setReadable(false);
prop_builder.setWritable(false);
// Enum or flag.
if (pp->pyqtprop_parsed_type->isEnum() || pp->pyqtprop_parsed_type->isFlag())
{
prop_builder.setEnumOrFlag(true);
}
if (pp->pyqtprop_get && PyCallable_Check(pp->pyqtprop_get))
{
// Readable.
prop_builder.setReadable(true);
}
if (pp->pyqtprop_set && PyCallable_Check(pp->pyqtprop_set))
{
// Writable.
prop_builder.setWritable(true);
// See if the name of the setter follows the Designer convention.
// If so tell the UI compilers not to use setProperty().
PyObject *setter_name_obj = PyObject_GetAttr(pp->pyqtprop_set,
qpycore_dunder_name);
if (setter_name_obj)
{
PyObject *ascii_obj = setter_name_obj;
const char *ascii = sipString_AsASCIIString(&ascii_obj);
示例7: clone
static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd)
{
// Set classname
builder.setClassName(ignoreEnd->className());
// Clone Q_CLASSINFO
for (int ii = mo->classInfoOffset(); ii < mo->classInfoCount(); ++ii) {
QMetaClassInfo info = mo->classInfo(ii);
int otherIndex = ignoreEnd->indexOfClassInfo(info.name());
if (otherIndex >= ignoreStart->classInfoOffset() + ignoreStart->classInfoCount()) {
// Skip
} else {
builder.addClassInfo(info.name(), info.value());
}
}
// Clone Q_PROPERTY
for (int ii = mo->propertyOffset(); ii < mo->propertyCount(); ++ii) {
QMetaProperty property = mo->property(ii);
int otherIndex = ignoreEnd->indexOfProperty(property.name());
if (otherIndex >= ignoreStart->propertyOffset() + ignoreStart->propertyCount()) {
builder.addProperty(QByteArray("__qml_ignore__") + property.name(), QByteArray("void"));
// Skip
} else {
builder.addProperty(property);
}
}
// Clone Q_METHODS
for (int ii = mo->methodOffset(); ii < mo->methodCount(); ++ii) {
QMetaMethod method = mo->method(ii);
// More complex - need to search name
QByteArray name = method.name();
bool found = false;
for (int ii = ignoreStart->methodOffset() + ignoreStart->methodCount();
!found && ii < ignoreEnd->methodOffset() + ignoreEnd->methodCount();
++ii) {
QMetaMethod other = ignoreEnd->method(ii);
found = name == other.name();
}
QMetaMethodBuilder m = builder.addMethod(method);
if (found) // SKIP
m.setAccess(QMetaMethod::Private);
}
// Clone Q_ENUMS
for (int ii = mo->enumeratorOffset(); ii < mo->enumeratorCount(); ++ii) {
QMetaEnum enumerator = mo->enumerator(ii);
int otherIndex = ignoreEnd->indexOfEnumerator(enumerator.name());
if (otherIndex >= ignoreStart->enumeratorOffset() + ignoreStart->enumeratorCount()) {
// Skip
} else {
builder.addEnumerator(enumerator);
}
}
}