558QMetaPropertyBuilder QMetaObjectBuilder::addProperty(
const QMetaProperty &prototype)
560 QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName(), prototype.metaType());
561 property.setReadable(prototype.isReadable());
562 property.setWritable(prototype.isWritable());
563 property.setResettable(prototype.isResettable());
564 property.setDesignable(prototype.isDesignable());
565 property.setScriptable(prototype.isScriptable());
566 property.setStored(prototype.isStored());
567 property.setUser(prototype.isUser());
568 property.setStdCppSet(prototype.hasStdCppSet());
569 property.setEnumOrFlag(prototype.isEnumType());
570 property.setConstant(prototype.isConstant());
571 property.setFinal(prototype.isFinal());
572 property.setVirtual(prototype.isVirtual());
573 property.setOverride(prototype.isOverride());
574 property.setRevision(prototype.revision());
575 if (prototype.hasNotifySignal()) {
577 QMetaMethod method = prototype.notifySignal();
578 const QByteArray signature = method.methodSignature();
579 int index = indexOfSignal(signature);
581 index = addSignal(signature).index();
582 d->properties[property._index].notifySignal = index;
667void QMetaObjectBuilder::addMetaObject(
const QMetaObject *prototype,
668 QMetaObjectBuilder::AddMembers members)
673 if ((members & ClassName) != 0)
674 d->className = prototype->className();
676 if ((members & SuperClass) != 0)
677 d->superClass = prototype->superClass();
679 if ((members & (Methods | Signals | Slots)) != 0) {
680 for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
681 QMetaMethod method = prototype->method(index);
682 if (method.methodType() != QMetaMethod::Signal) {
683 switch (method.access()) {
684 case QMetaMethod::Public:
685 if ((members & PublicMethods) == 0)
688 case QMetaMethod::Private:
689 if ((members & PrivateMethods) == 0)
692 case QMetaMethod::Protected:
693 if ((members & ProtectedMethods) == 0)
698 switch (method.methodType()) {
699 case QMetaMethod::Method:
700 if (members & Methods)
703 case QMetaMethod::Signal:
704 if (members & Signals)
707 case QMetaMethod::Slot:
711 case QMetaMethod::Constructor:
717 if ((members & Constructors) != 0) {
718 for (index = 0; index < prototype->constructorCount(); ++index)
719 addConstructor(prototype->constructor(index));
722 if ((members & Properties) != 0) {
723 for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
724 addProperty(prototype->property(index));
727 if ((members & Enumerators) != 0) {
728 for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
729 addEnumerator(prototype->enumerator(index));
732 if ((members & ClassInfos) != 0) {
733 for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
734 QMetaClassInfo ci = prototype->classInfo(index);
735 addClassInfo(ci.name(), ci.value());
739 if ((members & RelatedMetaObjects) != 0) {
740 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 2);
741 const auto *objects = prototype->d.relatedMetaObjects;
743 while (*objects !=
nullptr) {
744 addRelatedMetaObject(*objects);
750 if ((members & StaticMetacall) != 0) {
751 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 6);
752 if (prototype->d.static_metacall)
753 setStaticMetacallFunction(prototype->d.static_metacall);
1219 Q_UNUSED(expectedSize);
1228 QMetaObject *meta =
reinterpret_cast<QMetaObject *>(buf);
1229 size +=
sizeof(QMetaObject);
1232 meta->d.superdata = d->superClass;
1233 meta->d.relatedMetaObjects =
nullptr;
1234 meta->d.extradata =
nullptr;
1235 meta->d.metaTypes =
nullptr;
1236 meta->d.static_metacall = d->staticMetacallFunction;
1244 int methodParametersDataSize = aggregateParameterCount(d->methods)
1245 + aggregateParameterCount(d->signalVec)
1246 + aggregateParameterCount(d->constructors);
1250 pmeta->flags = d->flags.toInt() | AllocatedMetaObject;
1255 dataIndex += 2 * d->classInfoNames.size();
1263 paramsIndex = dataIndex;
1264 dataIndex += methodParametersDataSize;
1278 dataIndex += 2 *
int(d->classInfoNames.size());
1279 const auto method_count =
int(d->signalVec.size() + d->methods.size());
1281 paramsIndex = dataIndex;
1282 dataIndex += methodParametersDataSize;
1289 enumIndex = dataIndex;
1290 for (
const auto &enumerator : d->enumerators) {
1291 dataIndex += 2 * enumerator.keys.size();
1292 if (enumerator.flags & EnumIs64Bit)
1293 dataIndex += enumerator.keys.size();
1300 int *data =
reinterpret_cast<
int *>(pmeta);
1301 size += dataIndex *
sizeof(
int);
1302 ALIGN(size,
void *);
1303 [[maybe_unused]]
char *str =
reinterpret_cast<
char *>(buf + size);
1305 meta->d.stringdata =
reinterpret_cast<
const uint *>(str);
1306 meta->d.data =
reinterpret_cast<uint *>(data);
1316 for (index = 0; index < d->classInfoNames.size(); ++index) {
1317 [[maybe_unused]]
int name = strings.enter(d->classInfoNames[index]);
1318 [[maybe_unused]]
int value = strings.enter(d->classInfoValues[index]);
1320 data[dataIndex] = name;
1321 data[dataIndex + 1] = value;
1329 int parameterMetaTypesIndex =
int(d->properties.size()) +
int(d->enumerators.size()) + 1;
1331 auto add_method = [&](
const auto &method) {
1332 [[maybe_unused]]
int name = strings.enter(method.name());
1333 int argc = method.parameterCount();
1334 [[maybe_unused]]
int tag = strings.enter(method.tag);
1335 [[maybe_unused]]
int attrs = method.attributes;
1336 if (method.revision)
1339 data[dataIndex] = name;
1340 data[dataIndex + 1] = argc;
1341 data[dataIndex + 2] = paramsIndex;
1342 data[dataIndex + 3] = tag;
1343 data[dataIndex + 4] = attrs;
1344 data[dataIndex + 5] = parameterMetaTypesIndex;
1347 paramsIndex += 1 + argc * 2;
1348 parameterMetaTypesIndex += 1 + argc;
1352 for (
const auto &signal : d->signalVec)
1356 for (
const auto &method : d->methods)
1359 auto getTypeInfo = [&](
const auto &typeName) {
1360 if (isBuiltinType(typeName))
1361 return QMetaType::fromName(typeName).rawId();
1363 if constexpr (std::is_same_v<
decltype(typeName),
const QByteArrayView &>)
1364 index = strings.enter(QByteArray::fromRawData(typeName.constData(), typeName.size()));
1366 index = strings.enter(typeName);
1367 return int(IsUnresolvedType | index);
1372 auto processMethodParameters = [&](
const auto &methods) {
1373 for (
const auto &method : methods) {
1374 if (method.revision) {
1376 data[dataIndex] = method.revision;
1380 [[maybe_unused]]
int typeInfo = getTypeInfo(method.returnType);
1382 data[dataIndex] = typeInfo;
1385 const QList<QByteArrayView> paramTypeNames = method.parameterTypes();
1386 for (
auto typeName : paramTypeNames) {
1387 [[maybe_unused]]
int typeInfo = getTypeInfo(typeName);
1388 if constexpr (mode == Construct)
1389 data[dataIndex] = typeInfo;
1393 QList<QByteArray> paramNames = method.parameterNames;
1394 if (
const auto paramCount = paramTypeNames.size(); paramNames.size() < paramCount)
1395 paramNames.resize(paramCount);
1396 for (
const auto &name : std::as_const(paramNames)) {
1397 [[maybe_unused]]
int stringIndex = strings.enter(name);
1398 if constexpr (mode == Construct)
1399 data[dataIndex] = stringIndex;
1404 processMethodParameters(d->signalVec);
1405 processMethodParameters(d->methods);
1406 processMethodParameters(d->constructors);
1410 for (QMetaPropertyBuilderPrivate &prop : d->properties) {
1411 [[maybe_unused]]
int name = strings.enter(prop.name);
1414 if (!prop.metaType.isValid())
1415 prop.metaType = QMetaType::fromName(prop.type);
1416 [[maybe_unused]]
const int typeInfo = prop.metaType.isValid()
1417 ? prop.metaType.id()
1418 : IsUnresolvedType | strings.enter(prop.type);
1420 [[maybe_unused]]
int flags = prop.flags;
1422 if (!isBuiltinType(prop.type))
1423 flags |= EnumOrFlag;
1425 if constexpr (mode == Construct) {
1426 data[dataIndex] = name;
1427 data[dataIndex + 1] = typeInfo;
1428 data[dataIndex + 2] = flags;
1429 data[dataIndex + 3] = prop.notifySignal;
1430 data[dataIndex + 4] = prop.revision;
1432 dataIndex += QMetaObjectPrivate::IntsPerProperty;
1437 for (
const auto &enumerator : d->enumerators) {
1438 [[maybe_unused]]
int name = strings.enter(enumerator.name);
1439 [[maybe_unused]]
int enumName = strings.enter(enumerator.enumName);
1440 int count = enumerator.keys.size();
1441 if constexpr (mode == Construct) {
1442 data[dataIndex] = name;
1443 data[dataIndex + 1] = enumName;
1444 data[dataIndex + 2] = enumerator.flags.toInt();
1445 data[dataIndex + 3] = count;
1446 data[dataIndex + 4] = enumIndex;
1448 for (
int key = 0; key < count; ++key) {
1449 [[maybe_unused]]
int keyIndex = strings.enter(enumerator.keys[key]);
1450 if constexpr (mode == Construct) {
1451 data[enumIndex + 0] = keyIndex;
1452 data[enumIndex + 1] = uint(enumerator.values[key]);
1456 bool is64Bit = enumerator.flags.testAnyFlags(EnumIs64Bit);
1457 for (
int key = 0; is64Bit && key < count; ++key) {
1458 if constexpr (mode == Construct) {
1459 data[enumIndex] = uint(enumerator.values[key] >> 32);
1463 dataIndex += QMetaObjectPrivate::IntsPerEnum;
1468 for (
const auto &ctor : d->constructors) {
1469 [[maybe_unused]]
int name = strings.enter(ctor.name());
1470 int argc = ctor.parameterCount();
1471 [[maybe_unused]]
int tag = strings.enter(ctor.tag);
1472 [[maybe_unused]]
int attrs = ctor.attributes;
1473 if constexpr (mode == Construct) {
1474 data[dataIndex] = name;
1475 data[dataIndex + 1] = argc;
1476 data[dataIndex + 2] = paramsIndex;
1477 data[dataIndex + 3] = tag;
1478 data[dataIndex + 4] = attrs;
1479 data[dataIndex + 5] = parameterMetaTypesIndex;
1481 dataIndex += QMetaObjectPrivate::IntsPerMethod;
1482 paramsIndex += 1 + argc * 2;
1485 parameterMetaTypesIndex += argc;
1488 size += strings.blobSize();
1490 if constexpr (mode == Construct)
1491 strings.writeBlob(str);
1495 data[enumIndex] = 0;
1498 if (d->relatedMetaObjects.size() > 0) {
1499 using SuperData = QMetaObject::SuperData;
1500 ALIGN(size, SuperData);
1501 auto objects =
reinterpret_cast<SuperData *>(buf + size);
1503 meta->d.relatedMetaObjects = objects;
1504 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1505 objects[index] = d->relatedMetaObjects[index];
1506 objects[index] =
nullptr;
1508 size +=
sizeof(SuperData) * (d->relatedMetaObjects.size() + 1);
1511 ALIGN(size, QtPrivate::QMetaTypeInterface *);
1512 auto types =
reinterpret_cast<
const QtPrivate::QMetaTypeInterface **>(buf + size);
1514 meta->d.metaTypes = types;
1515 for (
const auto &prop : d->properties) {
1516 QMetaType mt = prop.metaType;
1517 *types = mt.iface();
1521 for (
const auto &enumerator: d->enumerators) {
1522 QMetaType mt = enumerator.metaType;
1524 *types = mt.iface();
1532 auto addMetaTypes = [&](
const auto &method) {
1533 QMetaType mt(QMetaType::fromName(method.returnType).rawId());
1534 *types =
reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
1536 for (
auto parameterType: method.parameterTypes()) {
1537 QMetaType mt = QMetaType::fromName(parameterType);
1538 *types = mt.iface();
1542 for (
const auto &method : d->signalVec)
1543 addMetaTypes(method);
1544 for (
const auto &method : d->methods)
1545 addMetaTypes(method);
1547 for (
const auto &constructor : d->constructors) {
1548 for (
auto parameterType : constructor.parameterTypes()) {
1549 QMetaType mt = QMetaType::fromName(parameterType);
1550 *types = mt.iface();
1556 size +=
sizeof(QMetaType) * parameterMetaTypesIndex;
1559 ALIGN(size,
void *);
1560 Q_ASSERT(!buf || size == expectedSize);