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.setVirtual(prototype.isVirtual());
562 property.setOverride(prototype.isOverride());
563 property.setRevision(prototype.revision());
564 if (prototype.hasNotifySignal()) {
566 QMetaMethod method = prototype.notifySignal();
567 int index = indexOfMethod(method.methodSignature());
569 index = addMethod(method).index();
570 d->properties[property._index].notifySignal = index;
655void QMetaObjectBuilder::addMetaObject(
const QMetaObject *prototype,
656 QMetaObjectBuilder::AddMembers members)
661 if ((members & ClassName) != 0)
662 d->className = prototype->className();
664 if ((members & SuperClass) != 0)
665 d->superClass = prototype->superClass();
667 if ((members & (Methods | Signals | Slots)) != 0) {
668 for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
669 QMetaMethod method = prototype->method(index);
670 if (method.methodType() != QMetaMethod::Signal) {
671 if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
673 if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
675 if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
678 if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
680 }
else if (method.methodType() == QMetaMethod::Signal &&
681 (members & Signals) != 0) {
683 }
else if (method.methodType() == QMetaMethod::Slot &&
684 (members & Slots) != 0) {
690 if ((members & Constructors) != 0) {
691 for (index = 0; index < prototype->constructorCount(); ++index)
692 addConstructor(prototype->constructor(index));
695 if ((members & Properties) != 0) {
696 for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
697 addProperty(prototype->property(index));
700 if ((members & Enumerators) != 0) {
701 for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
702 addEnumerator(prototype->enumerator(index));
705 if ((members & ClassInfos) != 0) {
706 for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
707 QMetaClassInfo ci = prototype->classInfo(index);
708 addClassInfo(ci.name(), ci.value());
712 if ((members & RelatedMetaObjects) != 0) {
713 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 2);
714 const auto *objects = prototype->d.relatedMetaObjects;
716 while (*objects !=
nullptr) {
717 addRelatedMetaObject(*objects);
723 if ((members & StaticMetacall) != 0) {
724 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 6);
725 if (prototype->d.static_metacall)
726 setStaticMetacallFunction(prototype->d.static_metacall);
1154 Q_UNUSED(expectedSize);
1163 QMetaObject *meta =
reinterpret_cast<QMetaObject *>(buf);
1164 size +=
sizeof(QMetaObject);
1167 meta->d.superdata = d->superClass;
1168 meta->d.relatedMetaObjects =
nullptr;
1169 meta->d.extradata =
nullptr;
1170 meta->d.metaTypes =
nullptr;
1171 meta->d.static_metacall = d->staticMetacallFunction;
1179 int methodParametersDataSize = aggregateParameterCount(d->methods)
1180 + aggregateParameterCount(d->constructors);
1184 pmeta->flags = d->flags.toInt() | AllocatedMetaObject;
1191 dataIndex += 2 * d->classInfoNames.size();
1196 paramsIndex = dataIndex;
1197 dataIndex += methodParametersDataSize;
1211 dataIndex += 2 *
int(d->classInfoNames.size());
1213 paramsIndex = dataIndex;
1214 dataIndex += methodParametersDataSize;
1221 enumIndex = dataIndex;
1222 for (
const auto &enumerator : d->enumerators) {
1223 dataIndex += 2 * enumerator.keys.size();
1224 if (enumerator.flags & EnumIs64Bit)
1225 dataIndex += enumerator.keys.size();
1232 int *data =
reinterpret_cast<
int *>(pmeta);
1233 size += dataIndex *
sizeof(
int);
1234 ALIGN(size,
void *);
1235 [[maybe_unused]]
char *str =
reinterpret_cast<
char *>(buf + size);
1237 meta->d.stringdata =
reinterpret_cast<
const uint *>(str);
1238 meta->d.data =
reinterpret_cast<uint *>(data);
1248 for (index = 0; index < d->classInfoNames.size(); ++index) {
1249 [[maybe_unused]]
int name = strings.enter(d->classInfoNames[index]);
1250 [[maybe_unused]]
int value = strings.enter(d->classInfoValues[index]);
1252 data[dataIndex] = name;
1253 data[dataIndex + 1] = value;
1261 int parameterMetaTypesIndex =
int(d->properties.size()) +
int(d->enumerators.size()) + 1;
1262 for (
const auto &method : d->methods) {
1263 [[maybe_unused]]
int name = strings.enter(method.name());
1264 int argc = method.parameterCount();
1265 [[maybe_unused]]
int tag = strings.enter(method.tag);
1266 [[maybe_unused]]
int attrs = method.attributes;
1267 if (method.revision)
1269 if constexpr (mode == Construct) {
1270 data[dataIndex] = name;
1271 data[dataIndex + 1] = argc;
1272 data[dataIndex + 2] = paramsIndex;
1273 data[dataIndex + 3] = tag;
1274 data[dataIndex + 4] = attrs;
1275 data[dataIndex + 5] = parameterMetaTypesIndex;
1276 if (method.methodType() == QMetaMethod::Signal)
1277 pmeta->signalCount++;
1279 dataIndex += QMetaObjectPrivate::IntsPerMethod;
1280 paramsIndex += 1 + argc * 2;
1281 parameterMetaTypesIndex += 1 + argc;
1284 auto getTypeInfo = [&](
const auto &typeName) {
1285 if (isBuiltinType(typeName))
1286 return QMetaType::fromName(typeName).id();
1288 if constexpr (std::is_same_v<
decltype(typeName),
const QByteArrayView &>)
1289 index = strings.enter(QByteArray::fromRawData(typeName.constData(), typeName.size()));
1291 index = strings.enter(typeName);
1292 return int(IsUnresolvedType | index);
1297 for (
int x = 0; x < 2; ++x) {
1298 const std::vector<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors;
1299 for (
const auto &method : methods) {
1300 if (method.revision) {
1301 if constexpr (mode == Construct)
1302 data[dataIndex] = method.revision;
1306 [[maybe_unused]]
int typeInfo = getTypeInfo(method.returnType);
1307 if constexpr (mode == Construct)
1308 data[dataIndex] = typeInfo;
1311 const QList<QByteArrayView> paramTypeNames = method.parameterTypes();
1312 for (
auto typeName : paramTypeNames) {
1313 [[maybe_unused]]
int typeInfo = getTypeInfo(typeName);
1314 if constexpr (mode == Construct)
1315 data[dataIndex] = typeInfo;
1319 QList<QByteArray> paramNames = method.parameterNames;
1320 if (
const auto paramCount = paramTypeNames.size(); paramNames.size() < paramCount)
1321 paramNames.resize(paramCount);
1322 for (
const auto &name : std::as_const(paramNames)) {
1323 [[maybe_unused]]
int stringIndex = strings.enter(name);
1324 if constexpr (mode == Construct)
1325 data[dataIndex] = stringIndex;
1333 for (QMetaPropertyBuilderPrivate &prop : d->properties) {
1334 [[maybe_unused]]
int name = strings.enter(prop.name);
1337 if (!prop.metaType.isValid())
1338 prop.metaType = QMetaType::fromName(prop.type);
1339 [[maybe_unused]]
const int typeInfo = prop.metaType.isValid()
1340 ? prop.metaType.id()
1341 : IsUnresolvedType | strings.enter(prop.type);
1343 [[maybe_unused]]
int flags = prop.flags;
1345 if (!isBuiltinType(prop.type))
1346 flags |= EnumOrFlag;
1348 if constexpr (mode == Construct) {
1349 data[dataIndex] = name;
1350 data[dataIndex + 1] = typeInfo;
1351 data[dataIndex + 2] = flags;
1352 data[dataIndex + 3] = prop.notifySignal;
1353 data[dataIndex + 4] = prop.revision;
1355 dataIndex += QMetaObjectPrivate::IntsPerProperty;
1360 for (
const auto &enumerator : d->enumerators) {
1361 [[maybe_unused]]
int name = strings.enter(enumerator.name);
1362 [[maybe_unused]]
int enumName = strings.enter(enumerator.enumName);
1363 int count = enumerator.keys.size();
1364 if constexpr (mode == Construct) {
1365 data[dataIndex] = name;
1366 data[dataIndex + 1] = enumName;
1367 data[dataIndex + 2] = enumerator.flags.toInt();
1368 data[dataIndex + 3] = count;
1369 data[dataIndex + 4] = enumIndex;
1371 for (
int key = 0; key < count; ++key) {
1372 [[maybe_unused]]
int keyIndex = strings.enter(enumerator.keys[key]);
1373 if constexpr (mode == Construct) {
1374 data[enumIndex + 0] = keyIndex;
1375 data[enumIndex + 1] = uint(enumerator.values[key]);
1379 bool is64Bit = enumerator.flags.testAnyFlags(EnumIs64Bit);
1380 for (
int key = 0; is64Bit && key < count; ++key) {
1381 if constexpr (mode == Construct) {
1382 data[enumIndex] = uint(enumerator.values[key] >> 32);
1386 dataIndex += QMetaObjectPrivate::IntsPerEnum;
1391 for (
const auto &ctor : d->constructors) {
1392 [[maybe_unused]]
int name = strings.enter(ctor.name());
1393 int argc = ctor.parameterCount();
1394 [[maybe_unused]]
int tag = strings.enter(ctor.tag);
1395 [[maybe_unused]]
int attrs = ctor.attributes;
1396 if constexpr (mode == Construct) {
1397 data[dataIndex] = name;
1398 data[dataIndex + 1] = argc;
1399 data[dataIndex + 2] = paramsIndex;
1400 data[dataIndex + 3] = tag;
1401 data[dataIndex + 4] = attrs;
1402 data[dataIndex + 5] = parameterMetaTypesIndex;
1404 dataIndex += QMetaObjectPrivate::IntsPerMethod;
1405 paramsIndex += 1 + argc * 2;
1408 parameterMetaTypesIndex += argc;
1411 size += strings.blobSize();
1413 if constexpr (mode == Construct)
1414 strings.writeBlob(str);
1418 data[enumIndex] = 0;
1421 if (d->relatedMetaObjects.size() > 0) {
1422 using SuperData = QMetaObject::SuperData;
1423 ALIGN(size, SuperData);
1424 auto objects =
reinterpret_cast<SuperData *>(buf + size);
1426 meta->d.relatedMetaObjects = objects;
1427 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1428 objects[index] = d->relatedMetaObjects[index];
1429 objects[index] =
nullptr;
1431 size +=
sizeof(SuperData) * (d->relatedMetaObjects.size() + 1);
1434 ALIGN(size, QtPrivate::QMetaTypeInterface *);
1435 auto types =
reinterpret_cast<
const QtPrivate::QMetaTypeInterface **>(buf + size);
1437 meta->d.metaTypes = types;
1438 for (
const auto &prop : d->properties) {
1439 QMetaType mt = prop.metaType;
1440 *types = mt.iface();
1444 for (
const auto &enumerator: d->enumerators) {
1445 QMetaType mt = enumerator.metaType;
1447 *types = mt.iface();
1454 for (
const auto &method: d->methods) {
1455 QMetaType mt(QMetaType::fromName(method.returnType).id());
1456 *types =
reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
1458 for (
auto parameterType: method.parameterTypes()) {
1459 QMetaType mt = QMetaType::fromName(parameterType);
1460 *types = mt.iface();
1464 for (
const auto &constructor : d->constructors) {
1465 for (
auto parameterType : constructor.parameterTypes()) {
1466 QMetaType mt = QMetaType::fromName(parameterType);
1467 *types = mt.iface();
1473 size +=
sizeof(QMetaType) * parameterMetaTypesIndex;
1476 ALIGN(size,
void *);
1477 Q_ASSERT(!buf || size == expectedSize);