1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "private/qmetaobjectbuilder_p.h"
47 \class QMetaObjectBuilder
49 \brief The QMetaObjectBuilder class supports building QMetaObject objects at runtime.
54 \enum QMetaObjectBuilder::AddMember
55 This enum defines which members of QMetaObject should be copied by QMetaObjectBuilder::addMetaObject()
57 \value ClassName Add the class name.
58 \value SuperClass Add the super class.
59 \value Methods Add methods that aren't signals or slots.
60 \value Signals Add signals.
61 \value Slots Add slots.
62 \value Constructors Add constructors.
63 \value Properties Add properties.
64 \value Enumerators Add enumerators.
65 \value ClassInfos Add items of class information.
66 \value RelatedMetaObjects Add related meta objects.
67 \value StaticMetacall Add the static metacall function.
68 \value PublicMethods Add public methods (ignored for signals).
69 \value ProtectedMethods Add protected methods (ignored for signals).
70 \value PrivateMethods All private methods (ignored for signals).
71 \value AllMembers Add all members.
72 \value AllPrimaryMembers Add everything except the class name, super class, and static metacall function.
75 // copied from moc's generator.cpp
76 uint qvariant_nameToType(const char* name)
81 if (strcmp(name, "QVariant") == 0)
83 if (strcmp(name, "QCString") == 0)
84 return QMetaType::QByteArray;
85 if (strcmp(name, "Q_LLONG") == 0)
86 return QMetaType::LongLong;
87 if (strcmp(name, "Q_ULLONG") == 0)
88 return QMetaType::ULongLong;
89 if (strcmp(name, "QIconSet") == 0)
90 return QMetaType::QIcon;
92 uint tp = QMetaType::type(name);
93 return tp < QMetaType::User ? tp : 0;
97 Returns true if the type is a QVariant types.
99 bool isVariantType(const char* type)
101 return qvariant_nameToType(type) != 0;
104 // copied from qmetaobject.cpp
105 // do not touch without touching the moc as well
107 Invalid = 0x00000000,
108 Readable = 0x00000001,
109 Writable = 0x00000002,
110 Resettable = 0x00000004,
111 EnumOrFlag = 0x00000008,
112 StdCppSet = 0x00000100,
113 // Override = 0x00000200,
114 Designable = 0x00001000,
115 ResolveDesignable = 0x00002000,
116 Scriptable = 0x00004000,
117 ResolveScriptable = 0x00008000,
119 ResolveStored = 0x00020000,
120 Editable = 0x00040000,
121 ResolveEditable = 0x00080000,
123 ResolveUser = 0x00200000,
125 Revisioned = 0x00800000
129 AccessPrivate = 0x00,
130 AccessProtected = 0x01,
132 AccessMask = 0x03, //mask
137 MethodConstructor = 0x0c,
138 MethodTypeMask = 0x0c,
140 MethodCompatibility = 0x10,
142 MethodScriptable = 0x40,
143 MethodRevisioned = 0x80
146 struct QMetaObjectPrivate
150 int classInfoCount, classInfoData;
151 int methodCount, methodData;
152 int propertyCount, propertyData;
153 int enumeratorCount, enumeratorData;
154 int constructorCount, constructorData;
158 static inline const QMetaObjectPrivate *priv(const uint* data)
159 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
160 // end of copied lines from qmetaobject.cpp
162 class QMetaMethodBuilderPrivate
165 QMetaMethodBuilderPrivate
166 (QMetaMethod::MethodType _methodType,
167 const QByteArray& _signature,
168 const QByteArray& _returnType = QByteArray(),
169 QMetaMethod::Access _access = QMetaMethod::Public)
170 : signature(QMetaObject::normalizedSignature(_signature.constData())),
171 returnType(QMetaObject::normalizedType(_returnType)),
172 attributes(((int)_access) | (((int)_methodType) << 2))
176 QByteArray signature;
177 QByteArray returnType;
178 QList<QByteArray> parameterNames;
182 QMetaMethod::MethodType methodType() const
184 return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2);
187 QMetaMethod::Access access() const
189 return (QMetaMethod::Access)(attributes & AccessMask);
192 void setAccess(QMetaMethod::Access value)
194 attributes = ((attributes & ~AccessMask) | (int)value);
198 class QMetaPropertyBuilderPrivate
201 QMetaPropertyBuilderPrivate
202 (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1)
204 type(QMetaObject::normalizedType(_type.constData())),
205 flags(Readable | Writable | Scriptable), notifySignal(-1)
207 if (notifierIdx >= 0) {
209 notifySignal = notifierIdx;
218 bool flag(int f) const
220 return ((flags & f) != 0);
223 void setFlag(int f, bool value)
232 class QMetaEnumBuilderPrivate
235 QMetaEnumBuilderPrivate(const QByteArray& _name)
236 : name(_name), isFlag(false)
242 QList<QByteArray> keys;
246 class QMetaObjectBuilderPrivate
249 QMetaObjectBuilderPrivate()
252 superClass = &QObject::staticMetaObject;
253 staticMetacallFunction = 0;
256 QByteArray className;
257 const QMetaObject *superClass;
258 QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction;
259 QList<QMetaMethodBuilderPrivate> methods;
260 QList<QMetaMethodBuilderPrivate> constructors;
261 QList<QMetaPropertyBuilderPrivate> properties;
262 QList<QByteArray> classInfoNames;
263 QList<QByteArray> classInfoValues;
264 QList<QMetaEnumBuilderPrivate> enumerators;
265 #ifdef Q_NO_DATA_RELOCATION
266 QList<QMetaObjectAccessor> relatedMetaObjects;
268 QList<const QMetaObject *> relatedMetaObjects;
274 Constructs a new QMetaObjectBuilder.
276 QMetaObjectBuilder::QMetaObjectBuilder()
278 d = new QMetaObjectBuilderPrivate();
282 Constructs a new QMetaObjectBuilder which is a copy of the
283 meta object information in \a prototype. Note: the super class
284 contents for \a prototype are not copied, only the immediate
285 class that is defined by \a prototype.
287 The \a members parameter indicates which members of \a prototype
288 should be added. The default is AllMembers.
292 QMetaObjectBuilder::QMetaObjectBuilder
293 (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
295 d = new QMetaObjectBuilderPrivate();
296 addMetaObject(prototype, members);
300 Destroys this meta object builder.
302 QMetaObjectBuilder::~QMetaObjectBuilder()
308 Returns the name of the class being constructed by this
309 meta object builder. The default value is an empty QByteArray.
311 \sa setClassName(), superClass()
313 QByteArray QMetaObjectBuilder::className() const
319 Sets the \a name of the class being constructed by this
322 \sa className(), setSuperClass()
324 void QMetaObjectBuilder::setClassName(const QByteArray& name)
330 Returns the superclass meta object of the class being constructed
331 by this meta object builder. The default value is the meta object
334 \sa setSuperClass(), className()
336 const QMetaObject *QMetaObjectBuilder::superClass() const
338 return d->superClass;
342 Sets the superclass meta object of the class being constructed
343 by this meta object builder to \a meta. The \a meta parameter
346 \sa superClass(), setClassName()
348 void QMetaObjectBuilder::setSuperClass(const QMetaObject *meta)
351 d->superClass = meta;
355 Returns the flags of the class being constructed by this meta object
360 QMetaObjectBuilder::MetaObjectFlags QMetaObjectBuilder::flags() const
362 return (QMetaObjectBuilder::MetaObjectFlags)d->flags;
366 Sets the \a flags of the class being constructed by this meta object
371 void QMetaObjectBuilder::setFlags(MetaObjectFlags flags)
377 Returns the number of methods in this class, excluding the number
378 of methods in the base class. These include signals and slots
379 as well as normal member functions.
381 \sa addMethod(), method(), removeMethod(), indexOfMethod()
383 int QMetaObjectBuilder::methodCount() const
385 return d->methods.size();
389 Returns the number of constructors in this class.
391 \sa addConstructor(), constructor(), removeConstructor(), indexOfConstructor()
393 int QMetaObjectBuilder::constructorCount() const
395 return d->constructors.size();
399 Returns the number of properties in this class, excluding the number
400 of properties in the base class.
402 \sa addProperty(), property(), removeProperty(), indexOfProperty()
404 int QMetaObjectBuilder::propertyCount() const
406 return d->properties.size();
410 Returns the number of enumerators in this class, excluding the
411 number of enumerators in the base class.
413 \sa addEnumerator(), enumerator(), removeEnumerator()
414 \sa indexOfEnumerator()
416 int QMetaObjectBuilder::enumeratorCount() const
418 return d->enumerators.size();
422 Returns the number of items of class information in this class,
423 exclusing the number of items of class information in the base class.
425 \sa addClassInfo(), classInfoName(), classInfoValue(), removeClassInfo()
426 \sa indexOfClassInfo()
428 int QMetaObjectBuilder::classInfoCount() const
430 return d->classInfoNames.size();
434 Returns the number of related meta objects that are associated
437 Related meta objects are used when resolving the enumerated type
438 associated with a property, where the enumerated type is in a
439 different class from the property.
441 \sa addRelatedMetaObject(), relatedMetaObject()
442 \sa removeRelatedMetaObject()
444 int QMetaObjectBuilder::relatedMetaObjectCount() const
446 return d->relatedMetaObjects.size();
450 Adds a new public method to this class with the specified \a signature.
451 Returns an object that can be used to adjust the other attributes
452 of the method. The \a signature will be normalized before it is
455 \sa method(), methodCount(), removeMethod(), indexOfMethod()
457 QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature)
459 int index = d->methods.size();
460 d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature));
461 return QMetaMethodBuilder(this, index);
465 Adds a new public method to this class with the specified
466 \a signature and \a returnType. Returns an object that can be
467 used to adjust the other attributes of the method. The \a signature
468 and \a returnType will be normalized before they are added to
469 the class. If \a returnType is empty, then it indicates that
470 the method has \c{void} as its return type.
472 \sa method(), methodCount(), removeMethod(), indexOfMethod()
474 QMetaMethodBuilder QMetaObjectBuilder::addMethod
475 (const QByteArray& signature, const QByteArray& returnType)
477 int index = d->methods.size();
478 d->methods.append(QMetaMethodBuilderPrivate
479 (QMetaMethod::Method, signature, returnType));
480 return QMetaMethodBuilder(this, index);
484 Adds a new public method to this class that has the same information as
485 \a prototype. This is used to clone the methods of an existing
486 QMetaObject. Returns an object that can be used to adjust the
487 attributes of the method.
489 This function will detect if \a prototype is an ordinary method,
490 signal, slot, or constructor and act accordingly.
492 \sa method(), methodCount(), removeMethod(), indexOfMethod()
494 QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype)
496 QMetaMethodBuilder method;
497 if (prototype.methodType() == QMetaMethod::Method)
498 method = addMethod(prototype.signature());
499 else if (prototype.methodType() == QMetaMethod::Signal)
500 method = addSignal(prototype.signature());
501 else if (prototype.methodType() == QMetaMethod::Slot)
502 method = addSlot(prototype.signature());
503 else if (prototype.methodType() == QMetaMethod::Constructor)
504 method = addConstructor(prototype.signature());
505 method.setReturnType(prototype.typeName());
506 method.setParameterNames(prototype.parameterNames());
507 method.setTag(prototype.tag());
508 method.setAccess(prototype.access());
509 method.setAttributes(prototype.attributes());
514 Adds a new public slot to this class with the specified \a signature.
515 Returns an object that can be used to adjust the other attributes
516 of the slot. The \a signature will be normalized before it is
519 \sa addMethod(), addSignal(), indexOfSlot()
521 QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature)
523 int index = d->methods.size();
524 d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature));
525 return QMetaMethodBuilder(this, index);
529 Adds a new signal to this class with the specified \a signature.
530 Returns an object that can be used to adjust the other attributes
531 of the signal. The \a signature will be normalized before it is
534 \sa addMethod(), addSlot(), indexOfSignal()
536 QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature)
538 int index = d->methods.size();
539 d->methods.append(QMetaMethodBuilderPrivate
540 (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected));
541 return QMetaMethodBuilder(this, index);
545 Adds a new constructor to this class with the specified \a signature.
546 Returns an object that can be used to adjust the other attributes
547 of the constructor. The \a signature will be normalized before it is
550 \sa constructor(), constructorCount(), removeConstructor()
551 \sa indexOfConstructor()
553 QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature)
555 int index = d->constructors.size();
556 d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature));
557 return QMetaMethodBuilder(this, -(index + 1));
561 Adds a new constructor to this class that has the same information as
562 \a prototype. This is used to clone the constructors of an existing
563 QMetaObject. Returns an object that can be used to adjust the
564 attributes of the constructor.
566 This function requires that \a prototype be a constructor.
568 \sa constructor(), constructorCount(), removeConstructor()
569 \sa indexOfConstructor()
571 QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype)
573 Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor);
574 QMetaMethodBuilder ctor = addConstructor(prototype.signature());
575 ctor.setReturnType(prototype.typeName());
576 ctor.setParameterNames(prototype.parameterNames());
577 ctor.setTag(prototype.tag());
578 ctor.setAccess(prototype.access());
579 ctor.setAttributes(prototype.attributes());
584 Adds a new readable/writable property to this class with the
585 specified \a name and \a type. Returns an object that can be used
586 to adjust the other attributes of the property. The \a type will
587 be normalized before it is added to the class. \a notifierId will
588 be registered as the property's \e notify signal.
590 \sa property(), propertyCount(), removeProperty(), indexOfProperty()
592 QMetaPropertyBuilder QMetaObjectBuilder::addProperty
593 (const QByteArray& name, const QByteArray& type, int notifierId)
595 int index = d->properties.size();
596 d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId));
597 return QMetaPropertyBuilder(this, index);
601 Adds a new property to this class that has the same information as
602 \a prototype. This is used to clone the properties of an existing
603 QMetaObject. Returns an object that can be used to adjust the
604 attributes of the property.
606 \sa property(), propertyCount(), removeProperty(), indexOfProperty()
608 QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& prototype)
610 QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName());
611 property.setReadable(prototype.isReadable());
612 property.setWritable(prototype.isWritable());
613 property.setResettable(prototype.isResettable());
614 property.setDesignable(prototype.isDesignable());
615 property.setScriptable(prototype.isScriptable());
616 property.setStored(prototype.isStored());
617 property.setEditable(prototype.isEditable());
618 property.setUser(prototype.isUser());
619 property.setStdCppSet(prototype.hasStdCppSet());
620 property.setEnumOrFlag(prototype.isEnumType());
621 if (prototype.hasNotifySignal()) {
622 // Find an existing method for the notify signal, or add a new one.
623 QMetaMethod method = prototype.notifySignal();
624 int index = indexOfMethod(method.signature());
626 index = addMethod(method).index();
627 d->properties[property._index].notifySignal = index;
628 d->properties[property._index].setFlag(Notify, true);
634 Adds a new enumerator to this class with the specified
635 \a name. Returns an object that can be used to adjust
636 the other attributes of the enumerator.
638 \sa enumerator(), enumeratorCount(), removeEnumerator(),
639 \sa indexOfEnumerator()
641 QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name)
643 int index = d->enumerators.size();
644 d->enumerators.append(QMetaEnumBuilderPrivate(name));
645 return QMetaEnumBuilder(this, index);
649 Adds a new enumerator to this class that has the same information as
650 \a prototype. This is used to clone the enumerators of an existing
651 QMetaObject. Returns an object that can be used to adjust the
652 attributes of the enumerator.
654 \sa enumerator(), enumeratorCount(), removeEnumerator(),
655 \sa indexOfEnumerator()
657 QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype)
659 QMetaEnumBuilder en = addEnumerator(prototype.name());
660 en.setIsFlag(prototype.isFlag());
661 int count = prototype.keyCount();
662 for (int index = 0; index < count; ++index)
663 en.addKey(prototype.key(index), prototype.value(index));
668 Adds \a name and \a value as an item of class information to this class.
669 Returns the index of the new item of class information.
671 \sa classInfoCount(), classInfoName(), classInfoValue(), removeClassInfo()
672 \sa indexOfClassInfo()
674 int QMetaObjectBuilder::addClassInfo(const QByteArray& name, const QByteArray& value)
676 int index = d->classInfoNames.size();
677 d->classInfoNames += name;
678 d->classInfoValues += value;
683 Adds \a meta to this class as a related meta object. Returns
684 the index of the new related meta object entry.
686 Related meta objects are used when resolving the enumerated type
687 associated with a property, where the enumerated type is in a
688 different class from the property.
690 \sa relatedMetaObjectCount(), relatedMetaObject()
691 \sa removeRelatedMetaObject()
693 #ifdef Q_NO_DATA_RELOCATION
694 int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObjectAccessor &meta)
696 int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObject *meta)
700 int index = d->relatedMetaObjects.size();
701 d->relatedMetaObjects.append(meta);
706 Adds the contents of \a prototype to this meta object builder.
707 This function is useful for cloning the contents of an existing QMetaObject.
709 The \a members parameter indicates which members of \a prototype
710 should be added. The default is AllMembers.
712 void QMetaObjectBuilder::addMetaObject
713 (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
718 if ((members & ClassName) != 0)
719 d->className = prototype->className();
721 if ((members & SuperClass) != 0)
722 d->superClass = prototype->superClass();
724 if ((members & (Methods | Signals | Slots)) != 0) {
725 for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
726 QMetaMethod method = prototype->method(index);
727 if (method.methodType() != QMetaMethod::Signal) {
728 if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
730 if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
732 if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
735 if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
737 } else if (method.methodType() == QMetaMethod::Signal &&
738 (members & Signals) != 0) {
740 } else if (method.methodType() == QMetaMethod::Slot &&
741 (members & Slots) != 0) {
747 if ((members & Constructors) != 0) {
748 for (index = 0; index < prototype->constructorCount(); ++index)
749 addConstructor(prototype->constructor(index));
752 if ((members & Properties) != 0) {
753 for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
754 addProperty(prototype->property(index));
757 if ((members & Enumerators) != 0) {
758 for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
759 addEnumerator(prototype->enumerator(index));
762 if ((members & ClassInfos) != 0) {
763 for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
764 QMetaClassInfo ci = prototype->classInfo(index);
765 addClassInfo(ci.name(), ci.value());
769 if ((members & RelatedMetaObjects) != 0) {
770 #ifdef Q_NO_DATA_RELOCATION
771 const QMetaObjectAccessor *objects = 0;
773 const QMetaObject **objects;
774 if (priv(prototype->d.data)->revision < 2) {
775 objects = (const QMetaObject **)(prototype->d.extradata);
779 const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata);
781 objects = extra->objects;
786 while (*objects != 0) {
787 addRelatedMetaObject(*objects);
793 if ((members & StaticMetacall) != 0) {
794 if (priv(prototype->d.data)->revision >= 6) {
795 const QMetaObjectExtraData *extra =
796 (const QMetaObjectExtraData *)(prototype->d.extradata);
797 if (extra && extra->static_metacall)
798 setStaticMetacallFunction(extra->static_metacall);
804 Returns the method at \a index in this class.
806 \sa methodCount(), addMethod(), removeMethod(), indexOfMethod()
808 QMetaMethodBuilder QMetaObjectBuilder::method(int index) const
810 if (index >= 0 && index < d->methods.size())
811 return QMetaMethodBuilder(this, index);
813 return QMetaMethodBuilder();
817 Returns the constructor at \a index in this class.
819 \sa methodCount(), addMethod(), removeMethod(), indexOfConstructor()
821 QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const
823 if (index >= 0 && index < d->constructors.size())
824 return QMetaMethodBuilder(this, -(index + 1));
826 return QMetaMethodBuilder();
830 Returns the property at \a index in this class.
832 \sa methodCount(), addMethod(), removeMethod(), indexOfProperty()
834 QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const
836 if (index >= 0 && index < d->properties.size())
837 return QMetaPropertyBuilder(this, index);
839 return QMetaPropertyBuilder();
843 Returns the enumerator at \a index in this class.
845 \sa enumeratorCount(), addEnumerator(), removeEnumerator()
846 \sa indexOfEnumerator()
848 QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const
850 if (index >= 0 && index < d->enumerators.size())
851 return QMetaEnumBuilder(this, index);
853 return QMetaEnumBuilder();
857 Returns the related meta object at \a index in this class.
859 Related meta objects are used when resolving the enumerated type
860 associated with a property, where the enumerated type is in a
861 different class from the property.
863 \sa relatedMetaObjectCount(), addRelatedMetaObject()
864 \sa removeRelatedMetaObject()
866 const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const
868 if (index >= 0 && index < d->relatedMetaObjects.size())
869 #ifdef Q_NO_DATA_RELOCATION
870 return &((*(d->relatedMetaObjects[index]))());
872 return d->relatedMetaObjects[index];
879 Returns the name of the item of class information at \a index
882 \sa classInfoCount(), addClassInfo(), classInfoValue(), removeClassInfo()
883 \sa indexOfClassInfo()
885 QByteArray QMetaObjectBuilder::classInfoName(int index) const
887 if (index >= 0 && index < d->classInfoNames.size())
888 return d->classInfoNames[index];
894 Returns the value of the item of class information at \a index
897 \sa classInfoCount(), addClassInfo(), classInfoName(), removeClassInfo()
898 \sa indexOfClassInfo()
900 QByteArray QMetaObjectBuilder::classInfoValue(int index) const
902 if (index >= 0 && index < d->classInfoValues.size())
903 return d->classInfoValues[index];
909 Removes the method at \a index from this class. The indices of
910 all following methods will be adjusted downwards by 1. If the
911 method is registered as a notify signal on a property, then the
912 notify signal will be removed from the property.
914 \sa methodCount(), addMethod(), method(), indexOfMethod()
916 void QMetaObjectBuilder::removeMethod(int index)
918 if (index >= 0 && index < d->methods.size()) {
919 d->methods.removeAt(index);
920 for (int prop = 0; prop < d->properties.size(); ++prop) {
921 // Adjust the indices of property notify signal references.
922 if (d->properties[prop].notifySignal == index) {
923 d->properties[prop].notifySignal = -1;
924 d->properties[prop].setFlag(Notify, false);
925 } else if (d->properties[prop].notifySignal > index)
926 (d->properties[prop].notifySignal)--;
932 Removes the constructor at \a index from this class. The indices of
933 all following constructors will be adjusted downwards by 1.
935 \sa constructorCount(), addConstructor(), constructor()
936 \sa indexOfConstructor()
938 void QMetaObjectBuilder::removeConstructor(int index)
940 if (index >= 0 && index < d->constructors.size())
941 d->constructors.removeAt(index);
945 Removes the property at \a index from this class. The indices of
946 all following properties will be adjusted downwards by 1.
948 \sa propertyCount(), addProperty(), property(), indexOfProperty()
950 void QMetaObjectBuilder::removeProperty(int index)
952 if (index >= 0 && index < d->properties.size())
953 d->properties.removeAt(index);
957 Removes the enumerator at \a index from this class. The indices of
958 all following enumerators will be adjusted downwards by 1.
960 \sa enumertorCount(), addEnumerator(), enumerator()
961 \sa indexOfEnumerator()
963 void QMetaObjectBuilder::removeEnumerator(int index)
965 if (index >= 0 && index < d->enumerators.size())
966 d->enumerators.removeAt(index);
970 Removes the item of class information at \a index from this class.
971 The indices of all following items will be adjusted downwards by 1.
973 \sa classInfoCount(), addClassInfo(), classInfoName(), classInfoValue()
974 \sa indexOfClassInfo()
976 void QMetaObjectBuilder::removeClassInfo(int index)
978 if (index >= 0 && index < d->classInfoNames.size()) {
979 d->classInfoNames.removeAt(index);
980 d->classInfoValues.removeAt(index);
985 Removes the related meta object at \a index from this class.
986 The indices of all following related meta objects will be adjusted
989 Related meta objects are used when resolving the enumerated type
990 associated with a property, where the enumerated type is in a
991 different class from the property.
993 \sa relatedMetaObjectCount(), addRelatedMetaObject()
994 \sa relatedMetaObject()
996 void QMetaObjectBuilder::removeRelatedMetaObject(int index)
998 if (index >= 0 && index < d->relatedMetaObjects.size())
999 d->relatedMetaObjects.removeAt(index);
1003 Finds a method with the specified \a signature and returns its index;
1004 otherwise returns -1. The \a signature will be normalized by this method.
1006 \sa method(), methodCount(), addMethod(), removeMethod()
1008 int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature)
1010 QByteArray sig = QMetaObject::normalizedSignature(signature);
1011 for (int index = 0; index < d->methods.size(); ++index) {
1012 if (sig == d->methods[index].signature)
1019 Finds a signal with the specified \a signature and returns its index;
1020 otherwise returns -1. The \a signature will be normalized by this method.
1022 \sa indexOfMethod(), indexOfSlot()
1024 int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature)
1026 QByteArray sig = QMetaObject::normalizedSignature(signature);
1027 for (int index = 0; index < d->methods.size(); ++index) {
1028 if (sig == d->methods[index].signature &&
1029 d->methods[index].methodType() == QMetaMethod::Signal)
1036 Finds a slot with the specified \a signature and returns its index;
1037 otherwise returns -1. The \a signature will be normalized by this method.
1039 \sa indexOfMethod(), indexOfSignal()
1041 int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature)
1043 QByteArray sig = QMetaObject::normalizedSignature(signature);
1044 for (int index = 0; index < d->methods.size(); ++index) {
1045 if (sig == d->methods[index].signature &&
1046 d->methods[index].methodType() == QMetaMethod::Slot)
1053 Finds a constructor with the specified \a signature and returns its index;
1054 otherwise returns -1. The \a signature will be normalized by this method.
1056 \sa constructor(), constructorCount(), addConstructor(), removeConstructor()
1058 int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature)
1060 QByteArray sig = QMetaObject::normalizedSignature(signature);
1061 for (int index = 0; index < d->constructors.size(); ++index) {
1062 if (sig == d->constructors[index].signature)
1069 Finds a property with the specified \a name and returns its index;
1070 otherwise returns -1.
1072 \sa property(), propertyCount(), addProperty(), removeProperty()
1074 int QMetaObjectBuilder::indexOfProperty(const QByteArray& name)
1076 for (int index = 0; index < d->properties.size(); ++index) {
1077 if (name == d->properties[index].name)
1084 Finds an enumerator with the specified \a name and returns its index;
1085 otherwise returns -1.
1087 \sa enumertor(), enumeratorCount(), addEnumerator(), removeEnumerator()
1089 int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name)
1091 for (int index = 0; index < d->enumerators.size(); ++index) {
1092 if (name == d->enumerators[index].name)
1099 Finds an item of class information with the specified \a name and
1100 returns its index; otherwise returns -1.
1102 \sa classInfoName(), classInfoValue(), classInfoCount(), addClassInfo()
1103 \sa removeClassInfo()
1105 int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name)
1107 for (int index = 0; index < d->classInfoNames.size(); ++index) {
1108 if (name == d->classInfoNames[index])
1114 // Align on a specific type boundary.
1115 #define ALIGN(size,type) \
1116 (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)
1118 // Build a string into a QMetaObject representation. Returns the
1119 // position in the string table where the string was placed.
1120 static int buildString
1121 (char *buf, char *str, int *offset, const QByteArray& value, int empty)
1123 if (value.size() == 0 && empty >= 0)
1126 memcpy(str + *offset, value.constData(), value.size());
1127 str[*offset + value.size()] = '\0';
1130 *offset += value.size() + 1;
1134 // Build the parameter array string for a method.
1135 static QByteArray buildParameterNames
1136 (const QByteArray& signature, const QList<QByteArray>& parameterNames)
1138 // If the parameter name list is specified, then concatenate them.
1139 if (!parameterNames.isEmpty()) {
1142 foreach (const QByteArray &name, parameterNames) {
1152 // Count commas in the signature, excluding those inside template arguments.
1153 int index = signature.indexOf('(');
1155 return QByteArray();
1157 if (index >= signature.size())
1158 return QByteArray();
1159 if (signature[index] == ')')
1160 return QByteArray();
1163 while (index < signature.size() && signature[index] != ',') {
1164 char ch = signature[index++];
1169 else if (ch == ',' && brackets <= 0)
1172 return QByteArray(count - 1, ',');
1175 // Build a QMetaObject in "buf" based on the information in "d".
1176 // If "buf" is null, then return the number of bytes needed to
1177 // build the QMetaObject. Returns -1 if the metaobject if
1178 // relocatable is set, but the metaobject contains extradata.
1179 static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
1186 bool hasNotifySignals = false;
1189 (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction))
1192 // Create the main QMetaObject structure at the start of the buffer.
1193 QMetaObject *meta = reinterpret_cast<QMetaObject *>(buf);
1194 size += sizeof(QMetaObject);
1197 if (!relocatable) meta->d.superdata = d->superClass;
1198 meta->d.extradata = 0;
1201 // Populate the QMetaObjectPrivate structure.
1202 QMetaObjectPrivate *pmeta
1203 = reinterpret_cast<QMetaObjectPrivate *>(buf + size);
1204 int pmetaSize = size;
1205 dataIndex = 13; // Number of fields in the QMetaObjectPrivate.
1206 for (index = 0; index < d->properties.size(); ++index) {
1207 if (d->properties[index].notifySignal != -1) {
1208 hasNotifySignals = true;
1213 pmeta->revision = 3;
1214 pmeta->flags = d->flags;
1215 pmeta->className = 0; // Class name is always the first string.
1217 pmeta->classInfoCount = d->classInfoNames.size();
1218 pmeta->classInfoData = dataIndex;
1219 dataIndex += 2 * d->classInfoNames.size();
1221 pmeta->methodCount = d->methods.size();
1222 pmeta->methodData = dataIndex;
1223 dataIndex += 5 * d->methods.size();
1225 pmeta->propertyCount = d->properties.size();
1226 pmeta->propertyData = dataIndex;
1227 dataIndex += 3 * d->properties.size();
1228 if (hasNotifySignals)
1229 dataIndex += d->properties.size();
1231 pmeta->enumeratorCount = d->enumerators.size();
1232 pmeta->enumeratorData = dataIndex;
1233 dataIndex += 4 * d->enumerators.size();
1235 pmeta->constructorCount = d->constructors.size();
1236 pmeta->constructorData = dataIndex;
1237 dataIndex += 5 * d->constructors.size();
1239 dataIndex += 2 * d->classInfoNames.size();
1240 dataIndex += 5 * d->methods.size();
1241 dataIndex += 3 * d->properties.size();
1242 if (hasNotifySignals)
1243 dataIndex += d->properties.size();
1244 dataIndex += 4 * d->enumerators.size();
1245 dataIndex += 5 * d->constructors.size();
1248 // Allocate space for the enumerator key names and values.
1249 enumIndex = dataIndex;
1250 for (index = 0; index < d->enumerators.size(); ++index) {
1251 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1252 dataIndex += 2 * enumerator->keys.size();
1255 // Zero terminator at the end of the data offset table.
1258 // Find the start of the data and string tables.
1259 int *data = reinterpret_cast<int *>(pmeta);
1260 size += dataIndex * sizeof(int);
1261 char *str = reinterpret_cast<char *>(buf + size);
1264 meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size);
1265 meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize);
1267 meta->d.stringdata = str;
1268 meta->d.data = reinterpret_cast<uint *>(data);
1272 // Reset the current data position to just past the QMetaObjectPrivate.
1275 // Add the class name to the string table.
1277 buildString(buf, str, &offset, d->className, -1);
1279 // Add a common empty string, which is used to indicate "void"
1280 // method returns, empty tag strings, etc.
1281 int empty = buildString(buf, str, &offset, QByteArray(), -1);
1283 // Output the class infos,
1284 for (index = 0; index < d->classInfoNames.size(); ++index) {
1285 int name = buildString(buf, str, &offset, d->classInfoNames[index], empty);
1286 int value = buildString(buf, str, &offset, d->classInfoValues[index], empty);
1288 data[dataIndex] = name;
1289 data[dataIndex + 1] = value;
1294 // Output the methods in the class.
1295 for (index = 0; index < d->methods.size(); ++index) {
1296 QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1297 int sig = buildString(buf, str, &offset, method->signature, empty);
1299 QByteArray names = buildParameterNames
1300 (method->signature, method->parameterNames);
1301 params = buildString(buf, str, &offset, names, empty);
1302 int ret = buildString(buf, str, &offset, method->returnType, empty);
1303 int tag = buildString(buf, str, &offset, method->tag, empty);
1304 int attrs = method->attributes;
1306 data[dataIndex] = sig;
1307 data[dataIndex + 1] = params;
1308 data[dataIndex + 2] = ret;
1309 data[dataIndex + 3] = tag;
1310 data[dataIndex + 4] = attrs;
1315 // Output the properties in the class.
1316 for (index = 0; index < d->properties.size(); ++index) {
1317 QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
1318 int name = buildString(buf, str, &offset, prop->name, empty);
1319 int type = buildString(buf, str, &offset, prop->type, empty);
1320 int flags = prop->flags;
1322 if (!isVariantType(prop->type)) {
1323 flags |= EnumOrFlag;
1325 flags |= qvariant_nameToType(prop->type) << 24;
1329 data[dataIndex] = name;
1330 data[dataIndex + 1] = type;
1331 data[dataIndex + 2] = flags;
1335 if (hasNotifySignals) {
1336 for (index = 0; index < d->properties.size(); ++index) {
1337 QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
1339 if (prop->notifySignal != -1)
1340 data[dataIndex] = prop->notifySignal;
1342 data[dataIndex] = 0;
1348 // Output the enumerators in the class.
1349 for (index = 0; index < d->enumerators.size(); ++index) {
1350 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1351 int name = buildString(buf, str, &offset, enumerator->name, empty);
1352 int isFlag = (int)(enumerator->isFlag);
1353 int count = enumerator->keys.size();
1354 int enumOffset = enumIndex;
1356 data[dataIndex] = name;
1357 data[dataIndex + 1] = isFlag;
1358 data[dataIndex + 2] = count;
1359 data[dataIndex + 3] = enumOffset;
1361 for (int key = 0; key < count; ++key) {
1362 int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty);
1364 data[enumOffset++] = keyIndex;
1365 data[enumOffset++] = enumerator->values[key];
1369 enumIndex += 2 * count;
1372 // Output the constructors in the class.
1373 for (index = 0; index < d->constructors.size(); ++index) {
1374 QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1375 int sig = buildString(buf, str, &offset, method->signature, empty);
1377 QByteArray names = buildParameterNames
1378 (method->signature, method->parameterNames);
1379 params = buildString(buf, str, &offset, names, empty);
1380 int ret = buildString(buf, str, &offset, method->returnType, empty);
1381 int tag = buildString(buf, str, &offset, method->tag, empty);
1382 int attrs = method->attributes;
1384 data[dataIndex] = sig;
1385 data[dataIndex + 1] = params;
1386 data[dataIndex + 2] = ret;
1387 data[dataIndex + 3] = tag;
1388 data[dataIndex + 4] = attrs;
1393 // One more empty string to act as a terminator.
1394 buildString(buf, str, &offset, QByteArray(), -1);
1397 // Output the zero terminator in the data array.
1399 data[enumIndex] = 0;
1401 // Create the extradata block if we need one.
1402 if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) {
1403 ALIGN(size, QMetaObject **);
1404 ALIGN(size, QMetaObjectBuilder::StaticMetacallFunction);
1405 QMetaObjectExtraData *extra =
1406 reinterpret_cast<QMetaObjectExtraData *>(buf + size);
1407 size += sizeof(QMetaObjectExtraData);
1408 ALIGN(size, QMetaObject *);
1409 #ifdef Q_NO_DATA_RELOCATION
1410 QMetaObjectAccessor *objects =
1411 reinterpret_cast<QMetaObjectAccessor *>(buf + size);
1413 const QMetaObject **objects =
1414 reinterpret_cast<const QMetaObject **>(buf + size);
1417 if (d->relatedMetaObjects.size() > 0) {
1418 extra->objects = objects;
1419 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1420 objects[index] = d->relatedMetaObjects[index];
1425 extra->static_metacall = d->staticMetacallFunction;
1426 meta->d.extradata = reinterpret_cast<void *>(extra);
1428 if (d->relatedMetaObjects.size() > 0)
1429 size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1);
1432 // Align the final size and return it.
1433 ALIGN(size, void *);
1438 Converts this meta object builder into a concrete QMetaObject.
1439 The return value should be deallocated using qFree() once it
1440 is no longer needed.
1442 The returned meta object is a snapshot of the state of the
1443 QMetaObjectBuilder. Any further modifications to the QMetaObjectBuilder
1444 will not be reflected in previous meta objects returned by
1447 QMetaObject *QMetaObjectBuilder::toMetaObject() const
1449 int size = buildMetaObject(d, 0, false);
1450 char *buf = reinterpret_cast<char *>(qMalloc(size));
1451 buildMetaObject(d, buf, false);
1452 return reinterpret_cast<QMetaObject *>(buf);
1458 Converts this meta object builder into relocatable data. This data can
1459 be stored, copied and later passed to fromRelocatableData() to create a
1460 concrete QMetaObject.
1462 The data is specific to the architecture on which it was created, but is not
1463 specific to the process that created it. Not all meta object builder's can
1464 be converted to data in this way. If \a ok is provided, it will be set to
1465 true if the conversion succeeds, and false otherwise. If a
1466 staticMetacallFunction() or any relatedMetaObject()'s are specified the
1467 conversion to relocatable data will fail.
1469 QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const
1471 int size = buildMetaObject(d, 0, true);
1473 if (ok) *ok = false;
1474 return QByteArray();
1479 char *buf = data.data();
1480 buildMetaObject(d, buf, true);
1488 Sets the \a data returned from toRelocatableData() onto a concrete
1489 QMetaObject instance, \a output. As the meta object's super class is not
1490 saved in the relocatable data, it must be passed as \a superClass.
1492 void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output,
1493 const QMetaObject *superclass,
1494 const QByteArray &data)
1499 const char *buf = data.constData();
1500 const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf);
1502 quintptr stringdataOffset = (quintptr)dataMo->d.stringdata;
1503 quintptr dataOffset = (quintptr)dataMo->d.data;
1505 output->d.superdata = superclass;
1506 output->d.stringdata = buf + stringdataOffset;
1507 output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
1511 \typedef QMetaObjectBuilder::StaticMetacallFunction
1513 Typedef for static metacall functions. The three parameters are
1514 the call type value, the constructor index, and the
1515 array of parameters.
1519 Returns the static metacall function to use to construct objects
1520 of this class. The default value is null.
1522 \sa setStaticMetacallFunction()
1524 QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const
1526 return d->staticMetacallFunction;
1530 Sets the static metacall function to use to construct objects
1531 of this class to \a value. The default value is null.
1533 \sa staticMetacallFunction()
1535 void QMetaObjectBuilder::setStaticMetacallFunction
1536 (QMetaObjectBuilder::StaticMetacallFunction value)
1538 d->staticMetacallFunction = value;
1541 #ifndef QT_NO_DATASTREAM
1544 Serializes the contents of the meta object builder onto \a stream.
1548 void QMetaObjectBuilder::serialize(QDataStream& stream) const
1552 // Write the class and super class names.
1553 stream << d->className;
1555 stream << QByteArray(d->superClass->className());
1557 stream << QByteArray();
1559 // Write the counts for each type of class member.
1560 stream << d->classInfoNames.size();
1561 stream << d->methods.size();
1562 stream << d->properties.size();
1563 stream << d->enumerators.size();
1564 stream << d->constructors.size();
1565 stream << d->relatedMetaObjects.size();
1567 // Write the items of class information.
1568 for (index = 0; index < d->classInfoNames.size(); ++index) {
1569 stream << d->classInfoNames[index];
1570 stream << d->classInfoValues[index];
1573 // Write the methods.
1574 for (index = 0; index < d->methods.size(); ++index) {
1575 const QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1576 stream << method->signature;
1577 stream << method->returnType;
1578 stream << method->parameterNames;
1579 stream << method->tag;
1580 stream << method->attributes;
1583 // Write the properties.
1584 for (index = 0; index < d->properties.size(); ++index) {
1585 const QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1586 stream << property->name;
1587 stream << property->type;
1588 stream << property->flags;
1589 stream << property->notifySignal;
1592 // Write the enumerators.
1593 for (index = 0; index < d->enumerators.size(); ++index) {
1594 const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1595 stream << enumerator->name;
1596 stream << enumerator->isFlag;
1597 stream << enumerator->keys;
1598 stream << enumerator->values;
1601 // Write the constructors.
1602 for (index = 0; index < d->constructors.size(); ++index) {
1603 const QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1604 stream << method->signature;
1605 stream << method->returnType;
1606 stream << method->parameterNames;
1607 stream << method->tag;
1608 stream << method->attributes;
1611 // Write the related meta objects.
1612 #ifdef Q_NO_DATA_RELOCATION
1613 //### What do we do here?
1615 for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
1616 const QMetaObject *meta = d->relatedMetaObjects[index];
1617 stream << QByteArray(meta->className());
1621 // Add an extra empty QByteArray for additional data in future versions.
1622 // This should help maintain backwards compatibility, allowing older
1623 // versions to read newer data.
1624 stream << QByteArray();
1627 // Resolve a class name using the name reference map.
1628 static const QMetaObject *resolveClassName
1629 (const QMap<QByteArray, const QMetaObject *>& references,
1630 const QByteArray& name)
1632 if (name == QByteArray("QObject"))
1633 return &QObject::staticMetaObject;
1635 return references.value(name, 0);
1639 Deserializes a meta object builder from \a stream into
1640 this meta object builder.
1642 The \a references parameter specifies a mapping from class names
1643 to QMetaObject instances for resolving the super class name and
1644 related meta objects in the object that is deserialized.
1645 The meta object for QObject is implicitly added to \a references
1646 and does not need to be supplied.
1648 The QDataStream::status() value on \a stream will be set to
1649 QDataStream::ReadCorruptData if the input data is corrupt.
1650 The status will be set to QDataStream::ReadPastEnd if the
1651 input was exhausted before the full meta object was read.
1655 void QMetaObjectBuilder::deserialize
1656 (QDataStream& stream,
1657 const QMap<QByteArray, const QMetaObject *>& references)
1660 const QMetaObject *cl;
1663 // Clear all members in the builder to their default states.
1664 d->className.clear();
1665 d->superClass = &QObject::staticMetaObject;
1666 d->classInfoNames.clear();
1667 d->classInfoValues.clear();
1669 d->properties.clear();
1670 d->enumerators.clear();
1671 d->constructors.clear();
1672 d->relatedMetaObjects.clear();
1673 d->staticMetacallFunction = 0;
1675 // Read the class and super class names.
1676 stream >> d->className;
1678 if (name.isEmpty()) {
1680 } else if ((cl = resolveClassName(references, name)) != 0) {
1683 stream.setStatus(QDataStream::ReadCorruptData);
1687 // Read the counts for each type of class member.
1688 int classInfoCount, methodCount, propertyCount;
1689 int enumeratorCount, constructorCount, relatedMetaObjectCount;
1690 stream >> classInfoCount;
1691 stream >> methodCount;
1692 stream >> propertyCount;
1693 stream >> enumeratorCount;
1694 stream >> constructorCount;
1695 stream >> relatedMetaObjectCount;
1696 if (classInfoCount < 0 || methodCount < 0 ||
1697 propertyCount < 0 || enumeratorCount < 0 ||
1698 constructorCount < 0 || relatedMetaObjectCount < 0) {
1699 stream.setStatus(QDataStream::ReadCorruptData);
1703 // Read the items of class information.
1704 for (index = 0; index < classInfoCount; ++index) {
1705 if (stream.status() != QDataStream::Ok)
1710 addClassInfo(name, value);
1713 // Read the member methods.
1714 for (index = 0; index < methodCount; ++index) {
1715 if (stream.status() != QDataStream::Ok)
1719 QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1720 stream >> method->returnType;
1721 stream >> method->parameterNames;
1722 stream >> method->tag;
1723 stream >> method->attributes;
1724 if (method->methodType() == QMetaMethod::Constructor) {
1725 // Cannot add a constructor in this set of methods.
1726 stream.setStatus(QDataStream::ReadCorruptData);
1731 // Read the properties.
1732 for (index = 0; index < propertyCount; ++index) {
1733 if (stream.status() != QDataStream::Ok)
1738 addProperty(name, type);
1739 QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1740 stream >> property->flags;
1741 stream >> property->notifySignal;
1742 if (property->notifySignal < -1 ||
1743 property->notifySignal >= d->methods.size()) {
1744 // Notify signal method index is out of range.
1745 stream.setStatus(QDataStream::ReadCorruptData);
1748 if (property->notifySignal >= 0 &&
1749 d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) {
1750 // Notify signal method index does not refer to a signal.
1751 stream.setStatus(QDataStream::ReadCorruptData);
1756 // Read the enumerators.
1757 for (index = 0; index < enumeratorCount; ++index) {
1758 if (stream.status() != QDataStream::Ok)
1761 addEnumerator(name);
1762 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1763 stream >> enumerator->isFlag;
1764 stream >> enumerator->keys;
1765 stream >> enumerator->values;
1766 if (enumerator->keys.size() != enumerator->values.size()) {
1767 // Mismatch between number of keys and number of values.
1768 stream.setStatus(QDataStream::ReadCorruptData);
1773 // Read the constructor methods.
1774 for (index = 0; index < constructorCount; ++index) {
1775 if (stream.status() != QDataStream::Ok)
1778 addConstructor(name);
1779 QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1780 stream >> method->returnType;
1781 stream >> method->parameterNames;
1782 stream >> method->tag;
1783 stream >> method->attributes;
1784 if (method->methodType() != QMetaMethod::Constructor) {
1785 // The type must be Constructor.
1786 stream.setStatus(QDataStream::ReadCorruptData);
1791 // Read the related meta objects.
1792 #ifdef Q_NO_DATA_RELOCATION
1793 //### What do we do here
1795 for (index = 0; index < relatedMetaObjectCount; ++index) {
1796 if (stream.status() != QDataStream::Ok)
1799 cl = resolveClassName(references, name);
1801 stream.setStatus(QDataStream::ReadCorruptData);
1804 addRelatedMetaObject(cl);
1808 // Read the extra data block, which is reserved for future use.
1812 #endif // !QT_NO_DATASTREAM
1815 \class QMetaMethodBuilder
1817 \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder.
1820 QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const
1822 // Positive indices indicate methods, negative indices indicate constructors.
1823 if (_mobj && _index >= 0 && _index < _mobj->d->methods.size())
1824 return &(_mobj->d->methods[_index]);
1825 else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size())
1826 return &(_mobj->d->constructors[(-_index) - 1]);
1832 \fn QMetaMethodBuilder::QMetaMethodBuilder()
1837 Returns the index of this method within its QMetaObjectBuilder.
1839 int QMetaMethodBuilder::index() const
1842 return _index; // Method, signal, or slot
1844 return (-_index) - 1; // Constructor
1848 Returns the type of this method (signal, slot, method, or constructor).
1850 QMetaMethod::MethodType QMetaMethodBuilder::methodType() const
1852 QMetaMethodBuilderPrivate *d = d_func();
1854 return d->methodType();
1856 return QMetaMethod::Method;
1860 Returns the signature of this method.
1862 \sa parameterNames(), returnType()
1864 QByteArray QMetaMethodBuilder::signature() const
1866 QMetaMethodBuilderPrivate *d = d_func();
1868 return d->signature;
1870 return QByteArray();
1874 Returns the return type for this method; empty if the method's
1875 return type is \c{void}.
1877 \sa setReturnType(), signature()
1879 QByteArray QMetaMethodBuilder::returnType() const
1881 QMetaMethodBuilderPrivate *d = d_func();
1883 return d->returnType;
1885 return QByteArray();
1889 Sets the return type for this method to \a value. If \a value
1890 is empty, then the method's return type is \c{void}. The \a value
1891 will be normalized before it is added to the method.
1893 \sa returnType(), signature()
1895 void QMetaMethodBuilder::setReturnType(const QByteArray& value)
1897 QMetaMethodBuilderPrivate *d = d_func();
1899 d->returnType = QMetaObject::normalizedType(value);
1903 Returns the list of parameter names for this method.
1905 \sa setParameterNames()
1907 QList<QByteArray> QMetaMethodBuilder::parameterNames() const
1909 QMetaMethodBuilderPrivate *d = d_func();
1911 return d->parameterNames;
1913 return QList<QByteArray>();
1917 Sets the list of parameter names for this method to \a value.
1919 \sa parameterNames()
1921 void QMetaMethodBuilder::setParameterNames(const QList<QByteArray>& value)
1923 QMetaMethodBuilderPrivate *d = d_func();
1925 d->parameterNames = value;
1929 Returns the tag associated with this method.
1933 QByteArray QMetaMethodBuilder::tag() const
1935 QMetaMethodBuilderPrivate *d = d_func();
1939 return QByteArray();
1943 Sets the tag associated with this method to \a value.
1947 void QMetaMethodBuilder::setTag(const QByteArray& value)
1949 QMetaMethodBuilderPrivate *d = d_func();
1955 Returns the access specification of this method (private, protected,
1956 or public). The default value is QMetaMethod::Public for methods,
1957 slots, and constructors. The default value is QMetaMethod::Protected
1962 QMetaMethod::Access QMetaMethodBuilder::access() const
1964 QMetaMethodBuilderPrivate *d = d_func();
1968 return QMetaMethod::Public;
1972 Sets the access specification of this method (private, protected,
1973 or public) to \a value. If the method is a signal, this function
1978 void QMetaMethodBuilder::setAccess(QMetaMethod::Access value)
1980 QMetaMethodBuilderPrivate *d = d_func();
1981 if (d && d->methodType() != QMetaMethod::Signal)
1982 d->setAccess(value);
1986 Returns the additional attributes for this method.
1990 int QMetaMethodBuilder::attributes() const
1992 QMetaMethodBuilderPrivate *d = d_func();
1994 return (d->attributes >> 4);
2000 Sets the additional attributes for this method to \a value.
2004 void QMetaMethodBuilder::setAttributes(int value)
2006 QMetaMethodBuilderPrivate *d = d_func();
2008 d->attributes = ((d->attributes & 0x0f) | (value << 4));
2012 \class QMetaPropertyBuilder
2014 \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder.
2017 QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const
2019 if (_mobj && _index >= 0 && _index < _mobj->d->properties.size())
2020 return &(_mobj->d->properties[_index]);
2026 \fn QMetaPropertyBuilder::QMetaPropertyBuilder()
2031 \fn int QMetaPropertyBuilder::index() const
2033 Returns the index of this property within its QMetaObjectBuilder.
2037 Returns the name associated with this property.
2041 QByteArray QMetaPropertyBuilder::name() const
2043 QMetaPropertyBuilderPrivate *d = d_func();
2047 return QByteArray();
2051 Returns the type associated with this property.
2055 QByteArray QMetaPropertyBuilder::type() const
2057 QMetaPropertyBuilderPrivate *d = d_func();
2061 return QByteArray();
2065 Returns true if this property has a notify signal; false otherwise.
2067 \sa notifySignal(), setNotifySignal(), removeNotifySignal()
2069 bool QMetaPropertyBuilder::hasNotifySignal() const
2071 QMetaPropertyBuilderPrivate *d = d_func();
2073 return d->flag(Notify);
2079 Returns the notify signal associated with this property.
2081 \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal()
2083 QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const
2085 QMetaPropertyBuilderPrivate *d = d_func();
2086 if (d && d->notifySignal >= 0)
2087 return QMetaMethodBuilder(_mobj, d->notifySignal);
2089 return QMetaMethodBuilder();
2093 Sets the notify signal associated with this property to \a value.
2095 \sa hasNotifySignal(), notifySignal(), removeNotifySignal()
2097 void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
2099 QMetaPropertyBuilderPrivate *d = d_func();
2102 d->notifySignal = value._index;
2103 d->setFlag(Notify, true);
2105 d->notifySignal = -1;
2106 d->setFlag(Notify, false);
2112 Removes the notify signal from this property.
2114 \sa hasNotifySignal(), notifySignal(), setNotifySignal()
2116 void QMetaPropertyBuilder::removeNotifySignal()
2118 QMetaPropertyBuilderPrivate *d = d_func();
2120 d->notifySignal = -1;
2121 d->setFlag(Notify, false);
2126 Returns true if this property is readable; otherwise returns false.
2127 The default value is true.
2129 \sa setReadable(), isWritable()
2131 bool QMetaPropertyBuilder::isReadable() const
2133 QMetaPropertyBuilderPrivate *d = d_func();
2135 return d->flag(Readable);
2141 Returns true if this property is writable; otherwise returns false.
2142 The default value is true.
2144 \sa setWritable(), isReadable()
2146 bool QMetaPropertyBuilder::isWritable() const
2148 QMetaPropertyBuilderPrivate *d = d_func();
2150 return d->flag(Writable);
2156 Returns true if this property can be reset to a default value; otherwise
2157 returns false. The default value is false.
2161 bool QMetaPropertyBuilder::isResettable() const
2163 QMetaPropertyBuilderPrivate *d = d_func();
2165 return d->flag(Resettable);
2171 Returns true if this property is designable; otherwise returns false.
2172 This default value is false.
2174 \sa setDesignable(), isScriptable(), isStored()
2176 bool QMetaPropertyBuilder::isDesignable() const
2178 QMetaPropertyBuilderPrivate *d = d_func();
2180 return d->flag(Designable);
2186 Returns true if the property is scriptable; otherwise returns false.
2187 This default value is true.
2189 \sa setScriptable(), isDesignable(), isStored()
2191 bool QMetaPropertyBuilder::isScriptable() const
2193 QMetaPropertyBuilderPrivate *d = d_func();
2195 return d->flag(Scriptable);
2201 Returns true if the property is stored; otherwise returns false.
2202 This default value is false.
2204 \sa setStored(), isDesignable(), isScriptable()
2206 bool QMetaPropertyBuilder::isStored() const
2208 QMetaPropertyBuilderPrivate *d = d_func();
2210 return d->flag(Stored);
2216 Returns true if the property is editable; otherwise returns false.
2217 This default value is false.
2219 \sa setEditable(), isDesignable(), isScriptable(), isStored()
2221 bool QMetaPropertyBuilder::isEditable() const
2223 QMetaPropertyBuilderPrivate *d = d_func();
2225 return d->flag(Editable);
2231 Returns true if this property is designated as the \c USER
2232 property, i.e., the one that the user can edit or that is
2233 significant in some other way. Otherwise it returns
2234 false. This default value is false.
2236 \sa setUser(), isDesignable(), isScriptable()
2238 bool QMetaPropertyBuilder::isUser() const
2240 QMetaPropertyBuilderPrivate *d = d_func();
2242 return d->flag(User);
2248 Returns true if the property has a C++ setter function that
2249 follows Qt's standard "name" / "setName" pattern. Designer and uic
2250 query hasStdCppSet() in order to avoid expensive
2251 QObject::setProperty() calls. All properties in Qt [should] follow
2252 this pattern. The default value is false.
2256 bool QMetaPropertyBuilder::hasStdCppSet() const
2258 QMetaPropertyBuilderPrivate *d = d_func();
2260 return d->flag(StdCppSet);
2266 Returns true if the property is an enumerator or flag type;
2267 otherwise returns false. This default value is false.
2271 bool QMetaPropertyBuilder::isEnumOrFlag() const
2273 QMetaPropertyBuilderPrivate *d = d_func();
2275 return d->flag(EnumOrFlag);
2281 Sets this property to readable if \a value is true.
2283 \sa isReadable(), setWritable()
2285 void QMetaPropertyBuilder::setReadable(bool value)
2287 QMetaPropertyBuilderPrivate *d = d_func();
2289 d->setFlag(Readable, value);
2293 Sets this property to writable if \a value is true.
2295 \sa isWritable(), setReadable()
2297 void QMetaPropertyBuilder::setWritable(bool value)
2299 QMetaPropertyBuilderPrivate *d = d_func();
2301 d->setFlag(Writable, value);
2305 Sets this property to resettable if \a value is true.
2309 void QMetaPropertyBuilder::setResettable(bool value)
2311 QMetaPropertyBuilderPrivate *d = d_func();
2313 d->setFlag(Resettable, value);
2317 Sets this property to designable if \a value is true.
2319 \sa isDesignable(), setScriptable(), setStored()
2321 void QMetaPropertyBuilder::setDesignable(bool value)
2323 QMetaPropertyBuilderPrivate *d = d_func();
2325 d->setFlag(Designable, value);
2329 Sets this property to scriptable if \a value is true.
2331 \sa isScriptable(), setDesignable(), setStored()
2333 void QMetaPropertyBuilder::setScriptable(bool value)
2335 QMetaPropertyBuilderPrivate *d = d_func();
2337 d->setFlag(Scriptable, value);
2341 Sets this property to storable if \a value is true.
2343 \sa isStored(), setDesignable(), setScriptable()
2345 void QMetaPropertyBuilder::setStored(bool value)
2347 QMetaPropertyBuilderPrivate *d = d_func();
2349 d->setFlag(Stored, value);
2353 Sets this property to editable if \a value is true.
2355 \sa isEditable(), setDesignable(), setScriptable(), setStored()
2357 void QMetaPropertyBuilder::setEditable(bool value)
2359 QMetaPropertyBuilderPrivate *d = d_func();
2361 d->setFlag(Editable, value);
2365 Sets the \c USER flag on this property to \a value.
2367 \sa isUser(), setDesignable(), setScriptable()
2369 void QMetaPropertyBuilder::setUser(bool value)
2371 QMetaPropertyBuilderPrivate *d = d_func();
2373 d->setFlag(User, value);
2377 Sets the C++ setter flag on this property to \a value, which is
2378 true if the property has a C++ setter function that follows Qt's
2379 standard "name" / "setName" pattern.
2383 void QMetaPropertyBuilder::setStdCppSet(bool value)
2385 QMetaPropertyBuilderPrivate *d = d_func();
2387 d->setFlag(StdCppSet, value);
2391 Sets this property to be of an enumerator or flag type if
2396 void QMetaPropertyBuilder::setEnumOrFlag(bool value)
2398 QMetaPropertyBuilderPrivate *d = d_func();
2400 d->setFlag(EnumOrFlag, value);
2404 \class QMetaEnumBuilder
2406 \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder.
2409 QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const
2411 if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size())
2412 return &(_mobj->d->enumerators[_index]);
2418 \fn QMetaEnumBuilder::QMetaEnumBuilder()
2423 \fn int QMetaEnumBuilder::index() const
2425 Returns the index of this enumerator within its QMetaObjectBuilder.
2429 Returns the name of the enumerator (without the scope).
2431 QByteArray QMetaEnumBuilder::name() const
2433 QMetaEnumBuilderPrivate *d = d_func();
2437 return QByteArray();
2441 Returns true if this enumerator is used as a flag; otherwise returns
2446 bool QMetaEnumBuilder::isFlag() const
2448 QMetaEnumBuilderPrivate *d = d_func();
2456 Sets this enumerator to be used as a flag if \a value is true.
2460 void QMetaEnumBuilder::setIsFlag(bool value)
2462 QMetaEnumBuilderPrivate *d = d_func();
2468 Returns the number of keys.
2472 int QMetaEnumBuilder::keyCount() const
2474 QMetaEnumBuilderPrivate *d = d_func();
2476 return d->keys.size();
2482 Returns the key with the given \a index, or an empty QByteArray
2483 if no such key exists.
2485 \sa keyCount(), addKey(), value()
2487 QByteArray QMetaEnumBuilder::key(int index) const
2489 QMetaEnumBuilderPrivate *d = d_func();
2490 if (d && index >= 0 && index < d->keys.size())
2491 return d->keys[index];
2493 return QByteArray();
2497 Returns the value with the given \a index; or returns -1 if there
2500 \sa keyCount(), addKey(), key()
2502 int QMetaEnumBuilder::value(int index) const
2504 QMetaEnumBuilderPrivate *d = d_func();
2505 if (d && index >= 0 && index < d->keys.size())
2506 return d->values[index];
2512 Adds a new key called \a name to this enumerator, associated
2513 with \a value. Returns the index of the new key.
2515 \sa keyCount(), key(), value(), removeKey()
2517 int QMetaEnumBuilder::addKey(const QByteArray& name, int value)
2519 QMetaEnumBuilderPrivate *d = d_func();
2521 int index = d->keys.size();
2531 Removes the key at \a index from this enumerator.
2535 void QMetaEnumBuilder::removeKey(int index)
2537 QMetaEnumBuilderPrivate *d = d_func();
2538 if (d && index >= 0 && index < d->keys.size()) {
2539 d->keys.removeAt(index);
2540 d->values.removeAt(index);