544QMetaPropertyBuilder QMetaObjectBuilder::addProperty(
const QMetaProperty &prototype)
546 QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName(), prototype.metaType());
547 property.setReadable(prototype.isReadable());
548 property.setWritable(prototype.isWritable());
549 property.setResettable(prototype.isResettable());
550 property.setDesignable(prototype.isDesignable());
551 property.setScriptable(prototype.isScriptable());
552 property.setStored(prototype.isStored());
553 property.setUser(prototype.isUser());
554 property.setStdCppSet(prototype.hasStdCppSet());
555 property.setEnumOrFlag(prototype.isEnumType());
556 property.setConstant(prototype.isConstant());
557 property.setFinal(prototype.isFinal());
558 property.setRevision(prototype.revision());
559 if (prototype.hasNotifySignal()) {
561 QMetaMethod method = prototype.notifySignal();
562 int index = indexOfMethod(method.methodSignature());
564 index = addMethod(method).index();
565 d->properties[property._index].notifySignal = index;
650void QMetaObjectBuilder::addMetaObject(
const QMetaObject *prototype,
651 QMetaObjectBuilder::AddMembers members)
656 if ((members & ClassName) != 0)
657 d->className = prototype->className();
659 if ((members & SuperClass) != 0)
660 d->superClass = prototype->superClass();
662 if ((members & (Methods | Signals | Slots)) != 0) {
663 for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
664 QMetaMethod method = prototype->method(index);
665 if (method.methodType() != QMetaMethod::Signal) {
666 if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
668 if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
670 if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
673 if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
675 }
else if (method.methodType() == QMetaMethod::Signal &&
676 (members & Signals) != 0) {
678 }
else if (method.methodType() == QMetaMethod::Slot &&
679 (members & Slots) != 0) {
685 if ((members & Constructors) != 0) {
686 for (index = 0; index < prototype->constructorCount(); ++index)
687 addConstructor(prototype->constructor(index));
690 if ((members & Properties) != 0) {
691 for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
692 addProperty(prototype->property(index));
695 if ((members & Enumerators) != 0) {
696 for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
697 addEnumerator(prototype->enumerator(index));
700 if ((members & ClassInfos) != 0) {
701 for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
702 QMetaClassInfo ci = prototype->classInfo(index);
703 addClassInfo(ci.name(), ci.value());
707 if ((members & RelatedMetaObjects) != 0) {
708 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 2);
709 const auto *objects = prototype->d.relatedMetaObjects;
711 while (*objects !=
nullptr) {
712 addRelatedMetaObject(*objects);
718 if ((members & StaticMetacall) != 0) {
719 Q_ASSERT(qmobPriv(prototype->d.data)->revision >= 6);
720 if (prototype->d.static_metacall)
721 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;
1283 for (
int x = 0; x < 2; ++x) {
1284 const std::vector<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors;
1285 for (
const auto &method : methods) {
1286 if (method.revision) {
1287 if constexpr (mode == Construct)
1288 data[dataIndex] = method.revision;
1292 const QList<QByteArray> paramTypeNames = method.parameterTypes();
1293 int paramCount = paramTypeNames.size();
1294 for (
int i = -1; i < paramCount; ++i) {
1295 const QByteArray &typeName = (i < 0) ? method.returnType : paramTypeNames.at(i);
1296 [[maybe_unused]]
int typeInfo;
1297 if (QtPrivate::isBuiltinType(typeName))
1298 typeInfo = QMetaType::fromName(typeName).id();
1300 typeInfo = IsUnresolvedType | strings.enter(typeName);
1301 if constexpr (mode == Construct)
1302 data[dataIndex] = typeInfo;
1306 QList<QByteArray> paramNames = method.parameterNames;
1307 while (paramNames.size() < paramCount)
1308 paramNames.append(QByteArray());
1309 for (
int i = 0; i < paramCount; ++i) {
1310 [[maybe_unused]]
int stringIndex = strings.enter(paramNames.at(i));
1311 if constexpr (mode == Construct)
1312 data[dataIndex] = stringIndex;
1320 for (QMetaPropertyBuilderPrivate &prop : d->properties) {
1321 [[maybe_unused]]
int name = strings.enter(prop.name);
1324 if (!prop.metaType.isValid())
1325 prop.metaType = QMetaType::fromName(prop.type);
1326 [[maybe_unused]]
const int typeInfo = prop.metaType.isValid()
1327 ? prop.metaType.id()
1328 : IsUnresolvedType | strings.enter(prop.type);
1330 [[maybe_unused]]
int flags = prop.flags;
1332 if (!QtPrivate::isBuiltinType(prop.type))
1333 flags |= EnumOrFlag;
1335 if constexpr (mode == Construct) {
1336 data[dataIndex] = name;
1337 data[dataIndex + 1] = typeInfo;
1338 data[dataIndex + 2] = flags;
1339 data[dataIndex + 3] = prop.notifySignal;
1340 data[dataIndex + 4] = prop.revision;
1342 dataIndex += QMetaObjectPrivate::IntsPerProperty;
1347 for (
const auto &enumerator : d->enumerators) {
1348 [[maybe_unused]]
int name = strings.enter(enumerator.name);
1349 [[maybe_unused]]
int enumName = strings.enter(enumerator.enumName);
1350 int count = enumerator.keys.size();
1351 if constexpr (mode == Construct) {
1352 data[dataIndex] = name;
1353 data[dataIndex + 1] = enumName;
1354 data[dataIndex + 2] = enumerator.flags.toInt();
1355 data[dataIndex + 3] = count;
1356 data[dataIndex + 4] = enumIndex;
1358 for (
int key = 0; key < count; ++key) {
1359 [[maybe_unused]]
int keyIndex = strings.enter(enumerator.keys[key]);
1360 if constexpr (mode == Construct) {
1361 data[enumIndex + 0] = keyIndex;
1362 data[enumIndex + 1] = uint(enumerator.values[key]);
1366 bool is64Bit = enumerator.flags.testAnyFlags(EnumIs64Bit);
1367 for (
int key = 0; is64Bit && key < count; ++key) {
1368 if constexpr (mode == Construct) {
1369 data[enumIndex] = uint(enumerator.values[key] >> 32);
1373 dataIndex += QMetaObjectPrivate::IntsPerEnum;
1378 for (
const auto &ctor : d->constructors) {
1379 [[maybe_unused]]
int name = strings.enter(ctor.name());
1380 int argc = ctor.parameterCount();
1381 [[maybe_unused]]
int tag = strings.enter(ctor.tag);
1382 [[maybe_unused]]
int attrs = ctor.attributes;
1383 if constexpr (mode == Construct) {
1384 data[dataIndex] = name;
1385 data[dataIndex + 1] = argc;
1386 data[dataIndex + 2] = paramsIndex;
1387 data[dataIndex + 3] = tag;
1388 data[dataIndex + 4] = attrs;
1389 data[dataIndex + 5] = parameterMetaTypesIndex;
1391 dataIndex += QMetaObjectPrivate::IntsPerMethod;
1392 paramsIndex += 1 + argc * 2;
1395 parameterMetaTypesIndex += argc;
1398 size += strings.blobSize();
1400 if constexpr (mode == Construct)
1401 strings.writeBlob(str);
1405 data[enumIndex] = 0;
1408 if (d->relatedMetaObjects.size() > 0) {
1409 using SuperData = QMetaObject::SuperData;
1410 ALIGN(size, SuperData);
1411 auto objects =
reinterpret_cast<SuperData *>(buf + size);
1413 meta->d.relatedMetaObjects = objects;
1414 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1415 objects[index] = d->relatedMetaObjects[index];
1416 objects[index] =
nullptr;
1418 size +=
sizeof(SuperData) * (d->relatedMetaObjects.size() + 1);
1421 ALIGN(size, QtPrivate::QMetaTypeInterface *);
1422 auto types =
reinterpret_cast<
const QtPrivate::QMetaTypeInterface **>(buf + size);
1424 meta->d.metaTypes = types;
1425 for (
const auto &prop : d->properties) {
1426 QMetaType mt = prop.metaType;
1427 *types = mt.iface();
1431 for (
const auto &enumerator: d->enumerators) {
1432 QMetaType mt = enumerator.metaType;
1434 *types = mt.iface();
1441 for (
const auto &method: d->methods) {
1442 QMetaType mt(QMetaType::fromName(method.returnType).id());
1443 *types =
reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
1445 for (
const auto ¶meterType: method.parameterTypes()) {
1446 QMetaType mt = QMetaType::fromName(parameterType);
1447 *types = mt.iface();
1451 for (
const auto &constructor : d->constructors) {
1452 for (
const auto ¶meterType : constructor.parameterTypes()) {
1453 QMetaType mt = QMetaType::fromName(parameterType);
1454 *types = mt.iface();
1460 size +=
sizeof(QMetaType) * parameterMetaTypesIndex;
1463 ALIGN(size,
void *);
1464 Q_ASSERT(!buf || size == expectedSize);