547QMetaPropertyBuilder QMetaObjectBuilder::addProperty(
const QMetaProperty &prototype)
549 QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName(), prototype.metaType());
550 property.setReadable(prototype.isReadable());
551 property.setWritable(prototype.isWritable());
552 property.setResettable(prototype.isResettable());
553 property.setDesignable(prototype.isDesignable());
554 property.setScriptable(prototype.isScriptable());
555 property.setStored(prototype.isStored());
556 property.setUser(prototype.isUser());
557 property.setStdCppSet(prototype.hasStdCppSet());
558 property.setEnumOrFlag(prototype.isEnumType());
559 property.setConstant(prototype.isConstant());
560 property.setFinal(prototype.isFinal());
561 property.setRevision(prototype.revision());
562 if (prototype.hasNotifySignal()) {
564 QMetaMethod method = prototype.notifySignal();
565 int index = indexOfMethod(method.methodSignature());
567 index = addMethod(method).index();
568 d->properties[property._index].notifySignal = index;
653void QMetaObjectBuilder::addMetaObject(
const QMetaObject *prototype,
654 QMetaObjectBuilder::AddMembers members)
659 if ((members & ClassName) != 0)
660 d->className = prototype->className();
662 if ((members & SuperClass) != 0)
663 d->superClass = prototype->superClass();
665 if ((members & (Methods | Signals | Slots)) != 0) {
666 for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
667 QMetaMethod method = prototype->method(index);
668 if (method.methodType() != QMetaMethod::Signal) {
669 if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
671 if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
673 if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
676 if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
678 }
else if (method.methodType() == QMetaMethod::Signal &&
679 (members & Signals) != 0) {
681 }
else if (method.methodType() == QMetaMethod::Slot &&
682 (members & Slots) != 0) {
688 if ((members & Constructors) != 0) {
689 for (index = 0; index < prototype->constructorCount(); ++index)
690 addConstructor(prototype->constructor(index));
693 if ((members & Properties) != 0) {
694 for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
695 addProperty(prototype->property(index));
698 if ((members & Enumerators) != 0) {
699 for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
700 addEnumerator(prototype->enumerator(index));
703 if ((members & ClassInfos) != 0) {
704 for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
705 QMetaClassInfo ci = prototype->classInfo(index);
706 addClassInfo(ci.name(), ci.value());
710 if ((members & RelatedMetaObjects) != 0) {
711 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 2);
712 const auto *objects = prototype->d.relatedMetaObjects;
714 while (*objects !=
nullptr) {
715 addRelatedMetaObject(*objects);
721 if ((members & StaticMetacall) != 0) {
722 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 6);
723 if (prototype->d.static_metacall)
724 setStaticMetacallFunction(prototype->d.static_metacall);
1152 Q_UNUSED(expectedSize);
1161 QMetaObject *meta =
reinterpret_cast<QMetaObject *>(buf);
1162 size +=
sizeof(QMetaObject);
1165 meta->d.superdata = d->superClass;
1166 meta->d.relatedMetaObjects =
nullptr;
1167 meta->d.extradata =
nullptr;
1168 meta->d.metaTypes =
nullptr;
1169 meta->d.static_metacall = d->staticMetacallFunction;
1177 int methodParametersDataSize = aggregateParameterCount(d->methods)
1178 + aggregateParameterCount(d->constructors);
1182 pmeta->flags = d->flags.toInt() | AllocatedMetaObject;
1188 dataIndex += 2 * d->classInfoNames.size();
1193 paramsIndex = dataIndex;
1194 dataIndex += methodParametersDataSize;
1208 dataIndex += 2 *
int(d->classInfoNames.size());
1210 paramsIndex = dataIndex;
1211 dataIndex += methodParametersDataSize;
1218 enumIndex = dataIndex;
1219 for (
const auto &enumerator : d->enumerators) {
1220 dataIndex += 2 * enumerator.keys.size();
1221 if (enumerator.flags & EnumIs64Bit)
1222 dataIndex += enumerator.keys.size();
1229 int *data =
reinterpret_cast<
int *>(pmeta);
1230 size += dataIndex *
sizeof(
int);
1231 ALIGN(size,
void *);
1232 [[maybe_unused]]
char *str =
reinterpret_cast<
char *>(buf + size);
1234 meta->d.stringdata =
reinterpret_cast<
const uint *>(str);
1235 meta->d.data =
reinterpret_cast<uint *>(data);
1245 for (index = 0; index < d->classInfoNames.size(); ++index) {
1246 [[maybe_unused]]
int name = strings.enter(d->classInfoNames[index]);
1247 [[maybe_unused]]
int value = strings.enter(d->classInfoValues[index]);
1249 data[dataIndex] = name;
1250 data[dataIndex + 1] = value;
1258 int parameterMetaTypesIndex =
int(d->properties.size()) +
int(d->enumerators.size()) + 1;
1259 for (
const auto &method : d->methods) {
1260 [[maybe_unused]]
int name = strings.enter(method.name());
1261 int argc = method.parameterCount();
1262 [[maybe_unused]]
int tag = strings.enter(method.tag);
1263 [[maybe_unused]]
int attrs = method.attributes;
1264 if (method.revision)
1266 if constexpr (mode == Construct) {
1267 data[dataIndex] = name;
1268 data[dataIndex + 1] = argc;
1269 data[dataIndex + 2] = paramsIndex;
1270 data[dataIndex + 3] = tag;
1271 data[dataIndex + 4] = attrs;
1272 data[dataIndex + 5] = parameterMetaTypesIndex;
1273 if (method.methodType() == QMetaMethod::Signal)
1274 pmeta->signalCount++;
1276 dataIndex += QMetaObjectPrivate::IntsPerMethod;
1277 paramsIndex += 1 + argc * 2;
1278 parameterMetaTypesIndex += 1 + argc;
1281 auto getTypeInfo = [&](
const auto &typeName) {
1282 if (isBuiltinType(typeName))
1283 return QMetaType::fromName(typeName).id();
1285 if constexpr (std::is_same_v<
decltype(typeName),
const QByteArrayView &>)
1286 index = strings.enter(QByteArray::fromRawData(typeName.constData(), typeName.size()));
1288 index = strings.enter(typeName);
1289 return int(IsUnresolvedType | index);
1294 for (
int x = 0; x < 2; ++x) {
1295 const std::vector<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors;
1296 for (
const auto &method : methods) {
1297 if (method.revision) {
1298 if constexpr (mode == Construct)
1299 data[dataIndex] = method.revision;
1303 [[maybe_unused]]
int typeInfo = getTypeInfo(method.returnType);
1304 if constexpr (mode == Construct)
1305 data[dataIndex] = typeInfo;
1308 const QList<QByteArrayView> paramTypeNames = method.parameterTypes();
1309 for (
auto typeName : paramTypeNames) {
1310 [[maybe_unused]]
int typeInfo = getTypeInfo(typeName);
1311 if constexpr (mode == Construct)
1312 data[dataIndex] = typeInfo;
1316 QList<QByteArray> paramNames = method.parameterNames;
1317 if (
const auto paramCount = paramTypeNames.size(); paramNames.size() < paramCount)
1318 paramNames.resize(paramCount);
1319 for (
const auto &name : std::as_const(paramNames)) {
1320 [[maybe_unused]]
int stringIndex = strings.enter(name);
1321 if constexpr (mode == Construct)
1322 data[dataIndex] = stringIndex;
1330 for (QMetaPropertyBuilderPrivate &prop : d->properties) {
1331 [[maybe_unused]]
int name = strings.enter(prop.name);
1334 if (!prop.metaType.isValid())
1335 prop.metaType = QMetaType::fromName(prop.type);
1336 [[maybe_unused]]
const int typeInfo = prop.metaType.isValid()
1337 ? prop.metaType.id()
1338 : IsUnresolvedType | strings.enter(prop.type);
1340 [[maybe_unused]]
int flags = prop.flags;
1342 if (isBuiltinType(prop.type))
1343 flags |= EnumOrFlag;
1345 if constexpr (mode == Construct) {
1346 data[dataIndex] = name;
1347 data[dataIndex + 1] = typeInfo;
1348 data[dataIndex + 2] = flags;
1349 data[dataIndex + 3] = prop.notifySignal;
1350 data[dataIndex + 4] = prop.revision;
1352 dataIndex += QMetaObjectPrivate::IntsPerProperty;
1357 for (
const auto &enumerator : d->enumerators) {
1358 [[maybe_unused]]
int name = strings.enter(enumerator.name);
1359 [[maybe_unused]]
int enumName = strings.enter(enumerator.enumName);
1360 int count = enumerator.keys.size();
1361 if constexpr (mode == Construct) {
1362 data[dataIndex] = name;
1363 data[dataIndex + 1] = enumName;
1364 data[dataIndex + 2] = enumerator.flags.toInt();
1365 data[dataIndex + 3] = count;
1366 data[dataIndex + 4] = enumIndex;
1368 for (
int key = 0; key < count; ++key) {
1369 [[maybe_unused]]
int keyIndex = strings.enter(enumerator.keys[key]);
1370 if constexpr (mode == Construct) {
1371 data[enumIndex + 0] = keyIndex;
1372 data[enumIndex + 1] = uint(enumerator.values[key]);
1376 bool is64Bit = enumerator.flags.testAnyFlags(EnumIs64Bit);
1377 for (
int key = 0; is64Bit && key < count; ++key) {
1378 if constexpr (mode == Construct) {
1379 data[enumIndex] = uint(enumerator.values[key] >> 32);
1383 dataIndex += QMetaObjectPrivate::IntsPerEnum;
1388 for (
const auto &ctor : d->constructors) {
1389 [[maybe_unused]]
int name = strings.enter(ctor.name());
1390 int argc = ctor.parameterCount();
1391 [[maybe_unused]]
int tag = strings.enter(ctor.tag);
1392 [[maybe_unused]]
int attrs = ctor.attributes;
1393 if constexpr (mode == Construct) {
1394 data[dataIndex] = name;
1395 data[dataIndex + 1] = argc;
1396 data[dataIndex + 2] = paramsIndex;
1397 data[dataIndex + 3] = tag;
1398 data[dataIndex + 4] = attrs;
1399 data[dataIndex + 5] = parameterMetaTypesIndex;
1401 dataIndex += QMetaObjectPrivate::IntsPerMethod;
1402 paramsIndex += 1 + argc * 2;
1405 parameterMetaTypesIndex += argc;
1408 size += strings.blobSize();
1410 if constexpr (mode == Construct)
1411 strings.writeBlob(str);
1415 data[enumIndex] = 0;
1418 if (d->relatedMetaObjects.size() > 0) {
1419 using SuperData = QMetaObject::SuperData;
1420 ALIGN(size, SuperData);
1421 auto objects =
reinterpret_cast<SuperData *>(buf + size);
1423 meta->d.relatedMetaObjects = objects;
1424 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1425 objects[index] = d->relatedMetaObjects[index];
1426 objects[index] =
nullptr;
1428 size +=
sizeof(SuperData) * (d->relatedMetaObjects.size() + 1);
1431 ALIGN(size, QtPrivate::QMetaTypeInterface *);
1432 auto types =
reinterpret_cast<
const QtPrivate::QMetaTypeInterface **>(buf + size);
1434 meta->d.metaTypes = types;
1435 for (
const auto &prop : d->properties) {
1436 QMetaType mt = prop.metaType;
1437 *types = mt.iface();
1441 for (
const auto &enumerator: d->enumerators) {
1442 QMetaType mt = enumerator.metaType;
1444 *types = mt.iface();
1451 for (
const auto &method: d->methods) {
1452 QMetaType mt(QMetaType::fromName(method.returnType).id());
1453 *types =
reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
1455 for (
auto parameterType: method.parameterTypes()) {
1456 QMetaType mt = QMetaType::fromName(parameterType);
1457 *types = mt.iface();
1461 for (
const auto &constructor : d->constructors) {
1462 for (
auto parameterType : constructor.parameterTypes()) {
1463 QMetaType mt = QMetaType::fromName(parameterType);
1464 *types = mt.iface();
1470 size +=
sizeof(QMetaType) * parameterMetaTypesIndex;
1473 ALIGN(size,
void *);
1474 Q_ASSERT(!buf || size == expectedSize);