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_p.h
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 Constant = 0x00000400,
116 Designable = 0x00001000,
117 ResolveDesignable = 0x00002000,
118 Scriptable = 0x00004000,
119 ResolveScriptable = 0x00008000,
121 ResolveStored = 0x00020000,
122 Editable = 0x00040000,
123 ResolveEditable = 0x00080000,
125 ResolveUser = 0x00200000,
127 Revisioned = 0x00800000
131 AccessPrivate = 0x00,
132 AccessProtected = 0x01,
134 AccessMask = 0x03, //mask
139 MethodConstructor = 0x0c,
140 MethodTypeMask = 0x0c,
142 MethodCompatibility = 0x10,
144 MethodScriptable = 0x40,
145 MethodRevisioned = 0x80
148 struct QMetaObjectPrivate
152 int classInfoCount, classInfoData;
153 int methodCount, methodData;
154 int propertyCount, propertyData;
155 int enumeratorCount, enumeratorData;
156 int constructorCount, constructorData;
160 static inline const QMetaObjectPrivate *priv(const uint* data)
161 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
162 // end of copied lines from qmetaobject.cpp
164 class QMetaMethodBuilderPrivate
167 QMetaMethodBuilderPrivate
168 (QMetaMethod::MethodType _methodType,
169 const QByteArray& _signature,
170 const QByteArray& _returnType = QByteArray(),
171 QMetaMethod::Access _access = QMetaMethod::Public)
172 : signature(QMetaObject::normalizedSignature(_signature.constData())),
173 returnType(QMetaObject::normalizedType(_returnType)),
174 attributes(((int)_access) | (((int)_methodType) << 2))
178 QByteArray signature;
179 QByteArray returnType;
180 QList<QByteArray> parameterNames;
184 QMetaMethod::MethodType methodType() const
186 return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2);
189 QMetaMethod::Access access() const
191 return (QMetaMethod::Access)(attributes & AccessMask);
194 void setAccess(QMetaMethod::Access value)
196 attributes = ((attributes & ~AccessMask) | (int)value);
200 class QMetaPropertyBuilderPrivate
203 QMetaPropertyBuilderPrivate
204 (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1)
206 type(QMetaObject::normalizedType(_type.constData())),
207 flags(Readable | Writable | Scriptable), notifySignal(-1)
209 if (notifierIdx >= 0) {
211 notifySignal = notifierIdx;
220 bool flag(int f) const
222 return ((flags & f) != 0);
225 void setFlag(int f, bool value)
234 class QMetaEnumBuilderPrivate
237 QMetaEnumBuilderPrivate(const QByteArray& _name)
238 : name(_name), isFlag(false)
244 QList<QByteArray> keys;
248 class QMetaObjectBuilderPrivate
251 QMetaObjectBuilderPrivate()
254 superClass = &QObject::staticMetaObject;
255 staticMetacallFunction = 0;
258 QByteArray className;
259 const QMetaObject *superClass;
260 QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction;
261 QList<QMetaMethodBuilderPrivate> methods;
262 QList<QMetaMethodBuilderPrivate> constructors;
263 QList<QMetaPropertyBuilderPrivate> properties;
264 QList<QByteArray> classInfoNames;
265 QList<QByteArray> classInfoValues;
266 QList<QMetaEnumBuilderPrivate> enumerators;
267 #ifdef Q_NO_DATA_RELOCATION
268 QList<QMetaObjectAccessor> relatedMetaObjects;
270 QList<const QMetaObject *> relatedMetaObjects;
276 Constructs a new QMetaObjectBuilder.
278 QMetaObjectBuilder::QMetaObjectBuilder()
280 d = new QMetaObjectBuilderPrivate();
284 Constructs a new QMetaObjectBuilder which is a copy of the
285 meta object information in \a prototype. Note: the super class
286 contents for \a prototype are not copied, only the immediate
287 class that is defined by \a prototype.
289 The \a members parameter indicates which members of \a prototype
290 should be added. The default is AllMembers.
294 QMetaObjectBuilder::QMetaObjectBuilder
295 (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
297 d = new QMetaObjectBuilderPrivate();
298 addMetaObject(prototype, members);
302 Destroys this meta object builder.
304 QMetaObjectBuilder::~QMetaObjectBuilder()
310 Returns the name of the class being constructed by this
311 meta object builder. The default value is an empty QByteArray.
313 \sa setClassName(), superClass()
315 QByteArray QMetaObjectBuilder::className() const
321 Sets the \a name of the class being constructed by this
324 \sa className(), setSuperClass()
326 void QMetaObjectBuilder::setClassName(const QByteArray& name)
332 Returns the superclass meta object of the class being constructed
333 by this meta object builder. The default value is the meta object
336 \sa setSuperClass(), className()
338 const QMetaObject *QMetaObjectBuilder::superClass() const
340 return d->superClass;
344 Sets the superclass meta object of the class being constructed
345 by this meta object builder to \a meta. The \a meta parameter
348 \sa superClass(), setClassName()
350 void QMetaObjectBuilder::setSuperClass(const QMetaObject *meta)
353 d->superClass = meta;
357 Returns the flags of the class being constructed by this meta object
362 QMetaObjectBuilder::MetaObjectFlags QMetaObjectBuilder::flags() const
364 return (QMetaObjectBuilder::MetaObjectFlags)d->flags;
368 Sets the \a flags of the class being constructed by this meta object
373 void QMetaObjectBuilder::setFlags(MetaObjectFlags flags)
379 Returns the number of methods in this class, excluding the number
380 of methods in the base class. These include signals and slots
381 as well as normal member functions.
383 \sa addMethod(), method(), removeMethod(), indexOfMethod()
385 int QMetaObjectBuilder::methodCount() const
387 return d->methods.size();
391 Returns the number of constructors in this class.
393 \sa addConstructor(), constructor(), removeConstructor(), indexOfConstructor()
395 int QMetaObjectBuilder::constructorCount() const
397 return d->constructors.size();
401 Returns the number of properties in this class, excluding the number
402 of properties in the base class.
404 \sa addProperty(), property(), removeProperty(), indexOfProperty()
406 int QMetaObjectBuilder::propertyCount() const
408 return d->properties.size();
412 Returns the number of enumerators in this class, excluding the
413 number of enumerators in the base class.
415 \sa addEnumerator(), enumerator(), removeEnumerator()
416 \sa indexOfEnumerator()
418 int QMetaObjectBuilder::enumeratorCount() const
420 return d->enumerators.size();
424 Returns the number of items of class information in this class,
425 exclusing the number of items of class information in the base class.
427 \sa addClassInfo(), classInfoName(), classInfoValue(), removeClassInfo()
428 \sa indexOfClassInfo()
430 int QMetaObjectBuilder::classInfoCount() const
432 return d->classInfoNames.size();
436 Returns the number of related meta objects that are associated
439 Related meta objects are used when resolving the enumerated type
440 associated with a property, where the enumerated type is in a
441 different class from the property.
443 \sa addRelatedMetaObject(), relatedMetaObject()
444 \sa removeRelatedMetaObject()
446 int QMetaObjectBuilder::relatedMetaObjectCount() const
448 return d->relatedMetaObjects.size();
452 Adds a new public method to this class with the specified \a signature.
453 Returns an object that can be used to adjust the other attributes
454 of the method. The \a signature will be normalized before it is
457 \sa method(), methodCount(), removeMethod(), indexOfMethod()
459 QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature)
461 int index = d->methods.size();
462 d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature));
463 return QMetaMethodBuilder(this, index);
467 Adds a new public method to this class with the specified
468 \a signature and \a returnType. Returns an object that can be
469 used to adjust the other attributes of the method. The \a signature
470 and \a returnType will be normalized before they are added to
471 the class. If \a returnType is empty, then it indicates that
472 the method has \c{void} as its return type.
474 \sa method(), methodCount(), removeMethod(), indexOfMethod()
476 QMetaMethodBuilder QMetaObjectBuilder::addMethod
477 (const QByteArray& signature, const QByteArray& returnType)
479 int index = d->methods.size();
480 d->methods.append(QMetaMethodBuilderPrivate
481 (QMetaMethod::Method, signature, returnType));
482 return QMetaMethodBuilder(this, index);
486 Adds a new public method to this class that has the same information as
487 \a prototype. This is used to clone the methods of an existing
488 QMetaObject. Returns an object that can be used to adjust the
489 attributes of the method.
491 This function will detect if \a prototype is an ordinary method,
492 signal, slot, or constructor and act accordingly.
494 \sa method(), methodCount(), removeMethod(), indexOfMethod()
496 QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype)
498 QMetaMethodBuilder method;
499 if (prototype.methodType() == QMetaMethod::Method)
500 method = addMethod(prototype.signature());
501 else if (prototype.methodType() == QMetaMethod::Signal)
502 method = addSignal(prototype.signature());
503 else if (prototype.methodType() == QMetaMethod::Slot)
504 method = addSlot(prototype.signature());
505 else if (prototype.methodType() == QMetaMethod::Constructor)
506 method = addConstructor(prototype.signature());
507 method.setReturnType(prototype.typeName());
508 method.setParameterNames(prototype.parameterNames());
509 method.setTag(prototype.tag());
510 method.setAccess(prototype.access());
511 method.setAttributes(prototype.attributes());
516 Adds a new public slot to this class with the specified \a signature.
517 Returns an object that can be used to adjust the other attributes
518 of the slot. The \a signature will be normalized before it is
521 \sa addMethod(), addSignal(), indexOfSlot()
523 QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature)
525 int index = d->methods.size();
526 d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature));
527 return QMetaMethodBuilder(this, index);
531 Adds a new signal to this class with the specified \a signature.
532 Returns an object that can be used to adjust the other attributes
533 of the signal. The \a signature will be normalized before it is
536 \sa addMethod(), addSlot(), indexOfSignal()
538 QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature)
540 int index = d->methods.size();
541 d->methods.append(QMetaMethodBuilderPrivate
542 (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected));
543 return QMetaMethodBuilder(this, index);
547 Adds a new constructor to this class with the specified \a signature.
548 Returns an object that can be used to adjust the other attributes
549 of the constructor. The \a signature will be normalized before it is
552 \sa constructor(), constructorCount(), removeConstructor()
553 \sa indexOfConstructor()
555 QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature)
557 int index = d->constructors.size();
558 d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature));
559 return QMetaMethodBuilder(this, -(index + 1));
563 Adds a new constructor to this class that has the same information as
564 \a prototype. This is used to clone the constructors of an existing
565 QMetaObject. Returns an object that can be used to adjust the
566 attributes of the constructor.
568 This function requires that \a prototype be a constructor.
570 \sa constructor(), constructorCount(), removeConstructor()
571 \sa indexOfConstructor()
573 QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype)
575 Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor);
576 QMetaMethodBuilder ctor = addConstructor(prototype.signature());
577 ctor.setReturnType(prototype.typeName());
578 ctor.setParameterNames(prototype.parameterNames());
579 ctor.setTag(prototype.tag());
580 ctor.setAccess(prototype.access());
581 ctor.setAttributes(prototype.attributes());
586 Adds a new readable/writable property to this class with the
587 specified \a name and \a type. Returns an object that can be used
588 to adjust the other attributes of the property. The \a type will
589 be normalized before it is added to the class. \a notifierId will
590 be registered as the property's \e notify signal.
592 \sa property(), propertyCount(), removeProperty(), indexOfProperty()
594 QMetaPropertyBuilder QMetaObjectBuilder::addProperty
595 (const QByteArray& name, const QByteArray& type, int notifierId)
597 int index = d->properties.size();
598 d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId));
599 return QMetaPropertyBuilder(this, index);
603 Adds a new property to this class that has the same information as
604 \a prototype. This is used to clone the properties of an existing
605 QMetaObject. Returns an object that can be used to adjust the
606 attributes of the property.
608 \sa property(), propertyCount(), removeProperty(), indexOfProperty()
610 QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& prototype)
612 QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName());
613 property.setReadable(prototype.isReadable());
614 property.setWritable(prototype.isWritable());
615 property.setResettable(prototype.isResettable());
616 property.setDesignable(prototype.isDesignable());
617 property.setScriptable(prototype.isScriptable());
618 property.setStored(prototype.isStored());
619 property.setEditable(prototype.isEditable());
620 property.setUser(prototype.isUser());
621 property.setStdCppSet(prototype.hasStdCppSet());
622 property.setEnumOrFlag(prototype.isEnumType());
623 property.setConstant(prototype.isConstant());
624 property.setFinal(prototype.isFinal());
625 if (prototype.hasNotifySignal()) {
626 // Find an existing method for the notify signal, or add a new one.
627 QMetaMethod method = prototype.notifySignal();
628 int index = indexOfMethod(method.signature());
630 index = addMethod(method).index();
631 d->properties[property._index].notifySignal = index;
632 d->properties[property._index].setFlag(Notify, true);
638 Adds a new enumerator to this class with the specified
639 \a name. Returns an object that can be used to adjust
640 the other attributes of the enumerator.
642 \sa enumerator(), enumeratorCount(), removeEnumerator(),
643 \sa indexOfEnumerator()
645 QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name)
647 int index = d->enumerators.size();
648 d->enumerators.append(QMetaEnumBuilderPrivate(name));
649 return QMetaEnumBuilder(this, index);
653 Adds a new enumerator to this class that has the same information as
654 \a prototype. This is used to clone the enumerators of an existing
655 QMetaObject. Returns an object that can be used to adjust the
656 attributes of the enumerator.
658 \sa enumerator(), enumeratorCount(), removeEnumerator(),
659 \sa indexOfEnumerator()
661 QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype)
663 QMetaEnumBuilder en = addEnumerator(prototype.name());
664 en.setIsFlag(prototype.isFlag());
665 int count = prototype.keyCount();
666 for (int index = 0; index < count; ++index)
667 en.addKey(prototype.key(index), prototype.value(index));
672 Adds \a name and \a value as an item of class information to this class.
673 Returns the index of the new item of class information.
675 \sa classInfoCount(), classInfoName(), classInfoValue(), removeClassInfo()
676 \sa indexOfClassInfo()
678 int QMetaObjectBuilder::addClassInfo(const QByteArray& name, const QByteArray& value)
680 int index = d->classInfoNames.size();
681 d->classInfoNames += name;
682 d->classInfoValues += value;
687 Adds \a meta to this class as a related meta object. Returns
688 the index of the new related meta object entry.
690 Related meta objects are used when resolving the enumerated type
691 associated with a property, where the enumerated type is in a
692 different class from the property.
694 \sa relatedMetaObjectCount(), relatedMetaObject()
695 \sa removeRelatedMetaObject()
697 #ifdef Q_NO_DATA_RELOCATION
698 int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObjectAccessor &meta)
700 int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObject *meta)
704 int index = d->relatedMetaObjects.size();
705 d->relatedMetaObjects.append(meta);
710 Adds the contents of \a prototype to this meta object builder.
711 This function is useful for cloning the contents of an existing QMetaObject.
713 The \a members parameter indicates which members of \a prototype
714 should be added. The default is AllMembers.
716 void QMetaObjectBuilder::addMetaObject
717 (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
722 if ((members & ClassName) != 0)
723 d->className = prototype->className();
725 if ((members & SuperClass) != 0)
726 d->superClass = prototype->superClass();
728 if ((members & (Methods | Signals | Slots)) != 0) {
729 for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
730 QMetaMethod method = prototype->method(index);
731 if (method.methodType() != QMetaMethod::Signal) {
732 if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
734 if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
736 if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
739 if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
741 } else if (method.methodType() == QMetaMethod::Signal &&
742 (members & Signals) != 0) {
744 } else if (method.methodType() == QMetaMethod::Slot &&
745 (members & Slots) != 0) {
751 if ((members & Constructors) != 0) {
752 for (index = 0; index < prototype->constructorCount(); ++index)
753 addConstructor(prototype->constructor(index));
756 if ((members & Properties) != 0) {
757 for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
758 addProperty(prototype->property(index));
761 if ((members & Enumerators) != 0) {
762 for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
763 addEnumerator(prototype->enumerator(index));
766 if ((members & ClassInfos) != 0) {
767 for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
768 QMetaClassInfo ci = prototype->classInfo(index);
769 addClassInfo(ci.name(), ci.value());
773 if ((members & RelatedMetaObjects) != 0) {
774 #ifdef Q_NO_DATA_RELOCATION
775 const QMetaObjectAccessor *objects = 0;
777 const QMetaObject **objects;
778 if (priv(prototype->d.data)->revision < 2) {
779 objects = (const QMetaObject **)(prototype->d.extradata);
783 const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata);
785 objects = extra->objects;
790 while (*objects != 0) {
791 addRelatedMetaObject(*objects);
797 if ((members & StaticMetacall) != 0) {
798 if (priv(prototype->d.data)->revision >= 6) {
799 const QMetaObjectExtraData *extra =
800 (const QMetaObjectExtraData *)(prototype->d.extradata);
801 if (extra && extra->static_metacall)
802 setStaticMetacallFunction(extra->static_metacall);
808 Returns the method at \a index in this class.
810 \sa methodCount(), addMethod(), removeMethod(), indexOfMethod()
812 QMetaMethodBuilder QMetaObjectBuilder::method(int index) const
814 if (index >= 0 && index < d->methods.size())
815 return QMetaMethodBuilder(this, index);
817 return QMetaMethodBuilder();
821 Returns the constructor at \a index in this class.
823 \sa methodCount(), addMethod(), removeMethod(), indexOfConstructor()
825 QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const
827 if (index >= 0 && index < d->constructors.size())
828 return QMetaMethodBuilder(this, -(index + 1));
830 return QMetaMethodBuilder();
834 Returns the property at \a index in this class.
836 \sa methodCount(), addMethod(), removeMethod(), indexOfProperty()
838 QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const
840 if (index >= 0 && index < d->properties.size())
841 return QMetaPropertyBuilder(this, index);
843 return QMetaPropertyBuilder();
847 Returns the enumerator at \a index in this class.
849 \sa enumeratorCount(), addEnumerator(), removeEnumerator()
850 \sa indexOfEnumerator()
852 QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const
854 if (index >= 0 && index < d->enumerators.size())
855 return QMetaEnumBuilder(this, index);
857 return QMetaEnumBuilder();
861 Returns the related meta object at \a index in this class.
863 Related meta objects are used when resolving the enumerated type
864 associated with a property, where the enumerated type is in a
865 different class from the property.
867 \sa relatedMetaObjectCount(), addRelatedMetaObject()
868 \sa removeRelatedMetaObject()
870 const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const
872 if (index >= 0 && index < d->relatedMetaObjects.size())
873 #ifdef Q_NO_DATA_RELOCATION
874 return &((*(d->relatedMetaObjects[index]))());
876 return d->relatedMetaObjects[index];
883 Returns the name of the item of class information at \a index
886 \sa classInfoCount(), addClassInfo(), classInfoValue(), removeClassInfo()
887 \sa indexOfClassInfo()
889 QByteArray QMetaObjectBuilder::classInfoName(int index) const
891 if (index >= 0 && index < d->classInfoNames.size())
892 return d->classInfoNames[index];
898 Returns the value of the item of class information at \a index
901 \sa classInfoCount(), addClassInfo(), classInfoName(), removeClassInfo()
902 \sa indexOfClassInfo()
904 QByteArray QMetaObjectBuilder::classInfoValue(int index) const
906 if (index >= 0 && index < d->classInfoValues.size())
907 return d->classInfoValues[index];
913 Removes the method at \a index from this class. The indices of
914 all following methods will be adjusted downwards by 1. If the
915 method is registered as a notify signal on a property, then the
916 notify signal will be removed from the property.
918 \sa methodCount(), addMethod(), method(), indexOfMethod()
920 void QMetaObjectBuilder::removeMethod(int index)
922 if (index >= 0 && index < d->methods.size()) {
923 d->methods.removeAt(index);
924 for (int prop = 0; prop < d->properties.size(); ++prop) {
925 // Adjust the indices of property notify signal references.
926 if (d->properties[prop].notifySignal == index) {
927 d->properties[prop].notifySignal = -1;
928 d->properties[prop].setFlag(Notify, false);
929 } else if (d->properties[prop].notifySignal > index)
930 (d->properties[prop].notifySignal)--;
936 Removes the constructor at \a index from this class. The indices of
937 all following constructors will be adjusted downwards by 1.
939 \sa constructorCount(), addConstructor(), constructor()
940 \sa indexOfConstructor()
942 void QMetaObjectBuilder::removeConstructor(int index)
944 if (index >= 0 && index < d->constructors.size())
945 d->constructors.removeAt(index);
949 Removes the property at \a index from this class. The indices of
950 all following properties will be adjusted downwards by 1.
952 \sa propertyCount(), addProperty(), property(), indexOfProperty()
954 void QMetaObjectBuilder::removeProperty(int index)
956 if (index >= 0 && index < d->properties.size())
957 d->properties.removeAt(index);
961 Removes the enumerator at \a index from this class. The indices of
962 all following enumerators will be adjusted downwards by 1.
964 \sa enumertorCount(), addEnumerator(), enumerator()
965 \sa indexOfEnumerator()
967 void QMetaObjectBuilder::removeEnumerator(int index)
969 if (index >= 0 && index < d->enumerators.size())
970 d->enumerators.removeAt(index);
974 Removes the item of class information at \a index from this class.
975 The indices of all following items will be adjusted downwards by 1.
977 \sa classInfoCount(), addClassInfo(), classInfoName(), classInfoValue()
978 \sa indexOfClassInfo()
980 void QMetaObjectBuilder::removeClassInfo(int index)
982 if (index >= 0 && index < d->classInfoNames.size()) {
983 d->classInfoNames.removeAt(index);
984 d->classInfoValues.removeAt(index);
989 Removes the related meta object at \a index from this class.
990 The indices of all following related meta objects will be adjusted
993 Related meta objects are used when resolving the enumerated type
994 associated with a property, where the enumerated type is in a
995 different class from the property.
997 \sa relatedMetaObjectCount(), addRelatedMetaObject()
998 \sa relatedMetaObject()
1000 void QMetaObjectBuilder::removeRelatedMetaObject(int index)
1002 if (index >= 0 && index < d->relatedMetaObjects.size())
1003 d->relatedMetaObjects.removeAt(index);
1007 Finds a method with the specified \a signature and returns its index;
1008 otherwise returns -1. The \a signature will be normalized by this method.
1010 \sa method(), methodCount(), addMethod(), removeMethod()
1012 int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature)
1014 QByteArray sig = QMetaObject::normalizedSignature(signature);
1015 for (int index = 0; index < d->methods.size(); ++index) {
1016 if (sig == d->methods[index].signature)
1023 Finds a signal with the specified \a signature and returns its index;
1024 otherwise returns -1. The \a signature will be normalized by this method.
1026 \sa indexOfMethod(), indexOfSlot()
1028 int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature)
1030 QByteArray sig = QMetaObject::normalizedSignature(signature);
1031 for (int index = 0; index < d->methods.size(); ++index) {
1032 if (sig == d->methods[index].signature &&
1033 d->methods[index].methodType() == QMetaMethod::Signal)
1040 Finds a slot with the specified \a signature and returns its index;
1041 otherwise returns -1. The \a signature will be normalized by this method.
1043 \sa indexOfMethod(), indexOfSignal()
1045 int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature)
1047 QByteArray sig = QMetaObject::normalizedSignature(signature);
1048 for (int index = 0; index < d->methods.size(); ++index) {
1049 if (sig == d->methods[index].signature &&
1050 d->methods[index].methodType() == QMetaMethod::Slot)
1057 Finds a constructor with the specified \a signature and returns its index;
1058 otherwise returns -1. The \a signature will be normalized by this method.
1060 \sa constructor(), constructorCount(), addConstructor(), removeConstructor()
1062 int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature)
1064 QByteArray sig = QMetaObject::normalizedSignature(signature);
1065 for (int index = 0; index < d->constructors.size(); ++index) {
1066 if (sig == d->constructors[index].signature)
1073 Finds a property with the specified \a name and returns its index;
1074 otherwise returns -1.
1076 \sa property(), propertyCount(), addProperty(), removeProperty()
1078 int QMetaObjectBuilder::indexOfProperty(const QByteArray& name)
1080 for (int index = 0; index < d->properties.size(); ++index) {
1081 if (name == d->properties[index].name)
1088 Finds an enumerator with the specified \a name and returns its index;
1089 otherwise returns -1.
1091 \sa enumertor(), enumeratorCount(), addEnumerator(), removeEnumerator()
1093 int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name)
1095 for (int index = 0; index < d->enumerators.size(); ++index) {
1096 if (name == d->enumerators[index].name)
1103 Finds an item of class information with the specified \a name and
1104 returns its index; otherwise returns -1.
1106 \sa classInfoName(), classInfoValue(), classInfoCount(), addClassInfo()
1107 \sa removeClassInfo()
1109 int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name)
1111 for (int index = 0; index < d->classInfoNames.size(); ++index) {
1112 if (name == d->classInfoNames[index])
1118 // Align on a specific type boundary.
1119 #define ALIGN(size,type) \
1120 (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)
1122 // Build a string into a QMetaObject representation. Returns the
1123 // position in the string table where the string was placed.
1124 static int buildString
1125 (char *buf, char *str, int *offset, const QByteArray& value, int empty)
1127 if (value.size() == 0 && empty >= 0)
1130 memcpy(str + *offset, value.constData(), value.size());
1131 str[*offset + value.size()] = '\0';
1134 *offset += value.size() + 1;
1138 // Build the parameter array string for a method.
1139 static QByteArray buildParameterNames
1140 (const QByteArray& signature, const QList<QByteArray>& parameterNames)
1142 // If the parameter name list is specified, then concatenate them.
1143 if (!parameterNames.isEmpty()) {
1146 foreach (const QByteArray &name, parameterNames) {
1156 // Count commas in the signature, excluding those inside template arguments.
1157 int index = signature.indexOf('(');
1159 return QByteArray();
1161 if (index >= signature.size())
1162 return QByteArray();
1163 if (signature[index] == ')')
1164 return QByteArray();
1167 while (index < signature.size() && signature[index] != ',') {
1168 char ch = signature[index++];
1173 else if (ch == ',' && brackets <= 0)
1176 return QByteArray(count - 1, ',');
1179 // Build a QMetaObject in "buf" based on the information in "d".
1180 // If "buf" is null, then return the number of bytes needed to
1181 // build the QMetaObject. Returns -1 if the metaobject if
1182 // relocatable is set, but the metaobject contains extradata.
1183 static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
1190 bool hasNotifySignals = false;
1193 (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction))
1196 // Create the main QMetaObject structure at the start of the buffer.
1197 QMetaObject *meta = reinterpret_cast<QMetaObject *>(buf);
1198 size += sizeof(QMetaObject);
1201 if (!relocatable) meta->d.superdata = d->superClass;
1202 meta->d.extradata = 0;
1205 // Populate the QMetaObjectPrivate structure.
1206 QMetaObjectPrivate *pmeta
1207 = reinterpret_cast<QMetaObjectPrivate *>(buf + size);
1208 int pmetaSize = size;
1209 dataIndex = 13; // Number of fields in the QMetaObjectPrivate.
1210 for (index = 0; index < d->properties.size(); ++index) {
1211 if (d->properties[index].notifySignal != -1) {
1212 hasNotifySignals = true;
1217 pmeta->revision = 3;
1218 pmeta->flags = d->flags;
1219 pmeta->className = 0; // Class name is always the first string.
1221 pmeta->classInfoCount = d->classInfoNames.size();
1222 pmeta->classInfoData = dataIndex;
1223 dataIndex += 2 * d->classInfoNames.size();
1225 pmeta->methodCount = d->methods.size();
1226 pmeta->methodData = dataIndex;
1227 dataIndex += 5 * d->methods.size();
1229 pmeta->propertyCount = d->properties.size();
1230 pmeta->propertyData = dataIndex;
1231 dataIndex += 3 * d->properties.size();
1232 if (hasNotifySignals)
1233 dataIndex += d->properties.size();
1235 pmeta->enumeratorCount = d->enumerators.size();
1236 pmeta->enumeratorData = dataIndex;
1237 dataIndex += 4 * d->enumerators.size();
1239 pmeta->constructorCount = d->constructors.size();
1240 pmeta->constructorData = dataIndex;
1241 dataIndex += 5 * d->constructors.size();
1243 dataIndex += 2 * d->classInfoNames.size();
1244 dataIndex += 5 * d->methods.size();
1245 dataIndex += 3 * d->properties.size();
1246 if (hasNotifySignals)
1247 dataIndex += d->properties.size();
1248 dataIndex += 4 * d->enumerators.size();
1249 dataIndex += 5 * d->constructors.size();
1252 // Allocate space for the enumerator key names and values.
1253 enumIndex = dataIndex;
1254 for (index = 0; index < d->enumerators.size(); ++index) {
1255 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1256 dataIndex += 2 * enumerator->keys.size();
1259 // Zero terminator at the end of the data offset table.
1262 // Find the start of the data and string tables.
1263 int *data = reinterpret_cast<int *>(pmeta);
1264 size += dataIndex * sizeof(int);
1265 char *str = reinterpret_cast<char *>(buf + size);
1268 meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size);
1269 meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize);
1271 meta->d.stringdata = str;
1272 meta->d.data = reinterpret_cast<uint *>(data);
1276 // Reset the current data position to just past the QMetaObjectPrivate.
1279 // Add the class name to the string table.
1281 buildString(buf, str, &offset, d->className, -1);
1283 // Add a common empty string, which is used to indicate "void"
1284 // method returns, empty tag strings, etc.
1285 int empty = buildString(buf, str, &offset, QByteArray(), -1);
1287 // Output the class infos,
1288 for (index = 0; index < d->classInfoNames.size(); ++index) {
1289 int name = buildString(buf, str, &offset, d->classInfoNames[index], empty);
1290 int value = buildString(buf, str, &offset, d->classInfoValues[index], empty);
1292 data[dataIndex] = name;
1293 data[dataIndex + 1] = value;
1298 // Output the methods in the class.
1299 for (index = 0; index < d->methods.size(); ++index) {
1300 QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1301 int sig = buildString(buf, str, &offset, method->signature, empty);
1303 QByteArray names = buildParameterNames
1304 (method->signature, method->parameterNames);
1305 params = buildString(buf, str, &offset, names, empty);
1306 int ret = buildString(buf, str, &offset, method->returnType, empty);
1307 int tag = buildString(buf, str, &offset, method->tag, empty);
1308 int attrs = method->attributes;
1310 data[dataIndex] = sig;
1311 data[dataIndex + 1] = params;
1312 data[dataIndex + 2] = ret;
1313 data[dataIndex + 3] = tag;
1314 data[dataIndex + 4] = attrs;
1319 // Output the properties in the class.
1320 for (index = 0; index < d->properties.size(); ++index) {
1321 QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
1322 int name = buildString(buf, str, &offset, prop->name, empty);
1323 int type = buildString(buf, str, &offset, prop->type, empty);
1324 int flags = prop->flags;
1326 if (!isVariantType(prop->type)) {
1327 flags |= EnumOrFlag;
1329 flags |= qvariant_nameToType(prop->type) << 24;
1333 data[dataIndex] = name;
1334 data[dataIndex + 1] = type;
1335 data[dataIndex + 2] = flags;
1339 if (hasNotifySignals) {
1340 for (index = 0; index < d->properties.size(); ++index) {
1341 QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
1343 if (prop->notifySignal != -1)
1344 data[dataIndex] = prop->notifySignal;
1346 data[dataIndex] = 0;
1352 // Output the enumerators in the class.
1353 for (index = 0; index < d->enumerators.size(); ++index) {
1354 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1355 int name = buildString(buf, str, &offset, enumerator->name, empty);
1356 int isFlag = (int)(enumerator->isFlag);
1357 int count = enumerator->keys.size();
1358 int enumOffset = enumIndex;
1360 data[dataIndex] = name;
1361 data[dataIndex + 1] = isFlag;
1362 data[dataIndex + 2] = count;
1363 data[dataIndex + 3] = enumOffset;
1365 for (int key = 0; key < count; ++key) {
1366 int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty);
1368 data[enumOffset++] = keyIndex;
1369 data[enumOffset++] = enumerator->values[key];
1373 enumIndex += 2 * count;
1376 // Output the constructors in the class.
1377 for (index = 0; index < d->constructors.size(); ++index) {
1378 QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1379 int sig = buildString(buf, str, &offset, method->signature, empty);
1381 QByteArray names = buildParameterNames
1382 (method->signature, method->parameterNames);
1383 params = buildString(buf, str, &offset, names, empty);
1384 int ret = buildString(buf, str, &offset, method->returnType, empty);
1385 int tag = buildString(buf, str, &offset, method->tag, empty);
1386 int attrs = method->attributes;
1388 data[dataIndex] = sig;
1389 data[dataIndex + 1] = params;
1390 data[dataIndex + 2] = ret;
1391 data[dataIndex + 3] = tag;
1392 data[dataIndex + 4] = attrs;
1397 // One more empty string to act as a terminator.
1398 buildString(buf, str, &offset, QByteArray(), -1);
1401 // Output the zero terminator in the data array.
1403 data[enumIndex] = 0;
1405 // Create the extradata block if we need one.
1406 if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) {
1407 ALIGN(size, QMetaObject **);
1408 ALIGN(size, QMetaObjectBuilder::StaticMetacallFunction);
1409 QMetaObjectExtraData *extra =
1410 reinterpret_cast<QMetaObjectExtraData *>(buf + size);
1411 size += sizeof(QMetaObjectExtraData);
1412 ALIGN(size, QMetaObject *);
1413 #ifdef Q_NO_DATA_RELOCATION
1414 QMetaObjectAccessor *objects =
1415 reinterpret_cast<QMetaObjectAccessor *>(buf + size);
1417 const QMetaObject **objects =
1418 reinterpret_cast<const QMetaObject **>(buf + size);
1421 if (d->relatedMetaObjects.size() > 0) {
1422 extra->objects = objects;
1423 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1424 objects[index] = d->relatedMetaObjects[index];
1429 extra->static_metacall = d->staticMetacallFunction;
1430 meta->d.extradata = reinterpret_cast<void *>(extra);
1432 if (d->relatedMetaObjects.size() > 0)
1433 size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1);
1436 // Align the final size and return it.
1437 ALIGN(size, void *);
1442 Converts this meta object builder into a concrete QMetaObject.
1443 The return value should be deallocated using qFree() once it
1444 is no longer needed.
1446 The returned meta object is a snapshot of the state of the
1447 QMetaObjectBuilder. Any further modifications to the QMetaObjectBuilder
1448 will not be reflected in previous meta objects returned by
1451 QMetaObject *QMetaObjectBuilder::toMetaObject() const
1453 int size = buildMetaObject(d, 0, false);
1454 char *buf = reinterpret_cast<char *>(qMalloc(size));
1455 buildMetaObject(d, buf, false);
1456 return reinterpret_cast<QMetaObject *>(buf);
1462 Converts this meta object builder into relocatable data. This data can
1463 be stored, copied and later passed to fromRelocatableData() to create a
1464 concrete QMetaObject.
1466 The data is specific to the architecture on which it was created, but is not
1467 specific to the process that created it. Not all meta object builder's can
1468 be converted to data in this way. If \a ok is provided, it will be set to
1469 true if the conversion succeeds, and false otherwise. If a
1470 staticMetacallFunction() or any relatedMetaObject()'s are specified the
1471 conversion to relocatable data will fail.
1473 QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const
1475 int size = buildMetaObject(d, 0, true);
1477 if (ok) *ok = false;
1478 return QByteArray();
1483 char *buf = data.data();
1484 buildMetaObject(d, buf, true);
1492 Sets the \a data returned from toRelocatableData() onto a concrete
1493 QMetaObject instance, \a output. As the meta object's super class is not
1494 saved in the relocatable data, it must be passed as \a superClass.
1496 void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output,
1497 const QMetaObject *superclass,
1498 const QByteArray &data)
1503 const char *buf = data.constData();
1504 const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf);
1506 quintptr stringdataOffset = (quintptr)dataMo->d.stringdata;
1507 quintptr dataOffset = (quintptr)dataMo->d.data;
1509 output->d.superdata = superclass;
1510 output->d.stringdata = buf + stringdataOffset;
1511 output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
1515 \typedef QMetaObjectBuilder::StaticMetacallFunction
1517 Typedef for static metacall functions. The three parameters are
1518 the call type value, the constructor index, and the
1519 array of parameters.
1523 Returns the static metacall function to use to construct objects
1524 of this class. The default value is null.
1526 \sa setStaticMetacallFunction()
1528 QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const
1530 return d->staticMetacallFunction;
1534 Sets the static metacall function to use to construct objects
1535 of this class to \a value. The default value is null.
1537 \sa staticMetacallFunction()
1539 void QMetaObjectBuilder::setStaticMetacallFunction
1540 (QMetaObjectBuilder::StaticMetacallFunction value)
1542 d->staticMetacallFunction = value;
1545 #ifndef QT_NO_DATASTREAM
1548 Serializes the contents of the meta object builder onto \a stream.
1552 void QMetaObjectBuilder::serialize(QDataStream& stream) const
1556 // Write the class and super class names.
1557 stream << d->className;
1559 stream << QByteArray(d->superClass->className());
1561 stream << QByteArray();
1563 // Write the counts for each type of class member.
1564 stream << d->classInfoNames.size();
1565 stream << d->methods.size();
1566 stream << d->properties.size();
1567 stream << d->enumerators.size();
1568 stream << d->constructors.size();
1569 stream << d->relatedMetaObjects.size();
1571 // Write the items of class information.
1572 for (index = 0; index < d->classInfoNames.size(); ++index) {
1573 stream << d->classInfoNames[index];
1574 stream << d->classInfoValues[index];
1577 // Write the methods.
1578 for (index = 0; index < d->methods.size(); ++index) {
1579 const QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1580 stream << method->signature;
1581 stream << method->returnType;
1582 stream << method->parameterNames;
1583 stream << method->tag;
1584 stream << method->attributes;
1587 // Write the properties.
1588 for (index = 0; index < d->properties.size(); ++index) {
1589 const QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1590 stream << property->name;
1591 stream << property->type;
1592 stream << property->flags;
1593 stream << property->notifySignal;
1596 // Write the enumerators.
1597 for (index = 0; index < d->enumerators.size(); ++index) {
1598 const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1599 stream << enumerator->name;
1600 stream << enumerator->isFlag;
1601 stream << enumerator->keys;
1602 stream << enumerator->values;
1605 // Write the constructors.
1606 for (index = 0; index < d->constructors.size(); ++index) {
1607 const QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1608 stream << method->signature;
1609 stream << method->returnType;
1610 stream << method->parameterNames;
1611 stream << method->tag;
1612 stream << method->attributes;
1615 // Write the related meta objects.
1616 #ifdef Q_NO_DATA_RELOCATION
1617 //### What do we do here?
1619 for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
1620 const QMetaObject *meta = d->relatedMetaObjects[index];
1621 stream << QByteArray(meta->className());
1625 // Add an extra empty QByteArray for additional data in future versions.
1626 // This should help maintain backwards compatibility, allowing older
1627 // versions to read newer data.
1628 stream << QByteArray();
1631 // Resolve a class name using the name reference map.
1632 static const QMetaObject *resolveClassName
1633 (const QMap<QByteArray, const QMetaObject *>& references,
1634 const QByteArray& name)
1636 if (name == QByteArray("QObject"))
1637 return &QObject::staticMetaObject;
1639 return references.value(name, 0);
1643 Deserializes a meta object builder from \a stream into
1644 this meta object builder.
1646 The \a references parameter specifies a mapping from class names
1647 to QMetaObject instances for resolving the super class name and
1648 related meta objects in the object that is deserialized.
1649 The meta object for QObject is implicitly added to \a references
1650 and does not need to be supplied.
1652 The QDataStream::status() value on \a stream will be set to
1653 QDataStream::ReadCorruptData if the input data is corrupt.
1654 The status will be set to QDataStream::ReadPastEnd if the
1655 input was exhausted before the full meta object was read.
1659 void QMetaObjectBuilder::deserialize
1660 (QDataStream& stream,
1661 const QMap<QByteArray, const QMetaObject *>& references)
1664 const QMetaObject *cl;
1667 // Clear all members in the builder to their default states.
1668 d->className.clear();
1669 d->superClass = &QObject::staticMetaObject;
1670 d->classInfoNames.clear();
1671 d->classInfoValues.clear();
1673 d->properties.clear();
1674 d->enumerators.clear();
1675 d->constructors.clear();
1676 d->relatedMetaObjects.clear();
1677 d->staticMetacallFunction = 0;
1679 // Read the class and super class names.
1680 stream >> d->className;
1682 if (name.isEmpty()) {
1684 } else if ((cl = resolveClassName(references, name)) != 0) {
1687 stream.setStatus(QDataStream::ReadCorruptData);
1691 // Read the counts for each type of class member.
1692 int classInfoCount, methodCount, propertyCount;
1693 int enumeratorCount, constructorCount, relatedMetaObjectCount;
1694 stream >> classInfoCount;
1695 stream >> methodCount;
1696 stream >> propertyCount;
1697 stream >> enumeratorCount;
1698 stream >> constructorCount;
1699 stream >> relatedMetaObjectCount;
1700 if (classInfoCount < 0 || methodCount < 0 ||
1701 propertyCount < 0 || enumeratorCount < 0 ||
1702 constructorCount < 0 || relatedMetaObjectCount < 0) {
1703 stream.setStatus(QDataStream::ReadCorruptData);
1707 // Read the items of class information.
1708 for (index = 0; index < classInfoCount; ++index) {
1709 if (stream.status() != QDataStream::Ok)
1714 addClassInfo(name, value);
1717 // Read the member methods.
1718 for (index = 0; index < methodCount; ++index) {
1719 if (stream.status() != QDataStream::Ok)
1723 QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1724 stream >> method->returnType;
1725 stream >> method->parameterNames;
1726 stream >> method->tag;
1727 stream >> method->attributes;
1728 if (method->methodType() == QMetaMethod::Constructor) {
1729 // Cannot add a constructor in this set of methods.
1730 stream.setStatus(QDataStream::ReadCorruptData);
1735 // Read the properties.
1736 for (index = 0; index < propertyCount; ++index) {
1737 if (stream.status() != QDataStream::Ok)
1742 addProperty(name, type);
1743 QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1744 stream >> property->flags;
1745 stream >> property->notifySignal;
1746 if (property->notifySignal < -1 ||
1747 property->notifySignal >= d->methods.size()) {
1748 // Notify signal method index is out of range.
1749 stream.setStatus(QDataStream::ReadCorruptData);
1752 if (property->notifySignal >= 0 &&
1753 d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) {
1754 // Notify signal method index does not refer to a signal.
1755 stream.setStatus(QDataStream::ReadCorruptData);
1760 // Read the enumerators.
1761 for (index = 0; index < enumeratorCount; ++index) {
1762 if (stream.status() != QDataStream::Ok)
1765 addEnumerator(name);
1766 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1767 stream >> enumerator->isFlag;
1768 stream >> enumerator->keys;
1769 stream >> enumerator->values;
1770 if (enumerator->keys.size() != enumerator->values.size()) {
1771 // Mismatch between number of keys and number of values.
1772 stream.setStatus(QDataStream::ReadCorruptData);
1777 // Read the constructor methods.
1778 for (index = 0; index < constructorCount; ++index) {
1779 if (stream.status() != QDataStream::Ok)
1782 addConstructor(name);
1783 QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1784 stream >> method->returnType;
1785 stream >> method->parameterNames;
1786 stream >> method->tag;
1787 stream >> method->attributes;
1788 if (method->methodType() != QMetaMethod::Constructor) {
1789 // The type must be Constructor.
1790 stream.setStatus(QDataStream::ReadCorruptData);
1795 // Read the related meta objects.
1796 #ifdef Q_NO_DATA_RELOCATION
1797 //### What do we do here
1799 for (index = 0; index < relatedMetaObjectCount; ++index) {
1800 if (stream.status() != QDataStream::Ok)
1803 cl = resolveClassName(references, name);
1805 stream.setStatus(QDataStream::ReadCorruptData);
1808 addRelatedMetaObject(cl);
1812 // Read the extra data block, which is reserved for future use.
1816 #endif // !QT_NO_DATASTREAM
1819 \class QMetaMethodBuilder
1821 \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder.
1824 QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const
1826 // Positive indices indicate methods, negative indices indicate constructors.
1827 if (_mobj && _index >= 0 && _index < _mobj->d->methods.size())
1828 return &(_mobj->d->methods[_index]);
1829 else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size())
1830 return &(_mobj->d->constructors[(-_index) - 1]);
1836 \fn QMetaMethodBuilder::QMetaMethodBuilder()
1841 Returns the index of this method within its QMetaObjectBuilder.
1843 int QMetaMethodBuilder::index() const
1846 return _index; // Method, signal, or slot
1848 return (-_index) - 1; // Constructor
1852 Returns the type of this method (signal, slot, method, or constructor).
1854 QMetaMethod::MethodType QMetaMethodBuilder::methodType() const
1856 QMetaMethodBuilderPrivate *d = d_func();
1858 return d->methodType();
1860 return QMetaMethod::Method;
1864 Returns the signature of this method.
1866 \sa parameterNames(), returnType()
1868 QByteArray QMetaMethodBuilder::signature() const
1870 QMetaMethodBuilderPrivate *d = d_func();
1872 return d->signature;
1874 return QByteArray();
1878 Returns the return type for this method; empty if the method's
1879 return type is \c{void}.
1881 \sa setReturnType(), signature()
1883 QByteArray QMetaMethodBuilder::returnType() const
1885 QMetaMethodBuilderPrivate *d = d_func();
1887 return d->returnType;
1889 return QByteArray();
1893 Sets the return type for this method to \a value. If \a value
1894 is empty, then the method's return type is \c{void}. The \a value
1895 will be normalized before it is added to the method.
1897 \sa returnType(), signature()
1899 void QMetaMethodBuilder::setReturnType(const QByteArray& value)
1901 QMetaMethodBuilderPrivate *d = d_func();
1903 d->returnType = QMetaObject::normalizedType(value);
1907 Returns the list of parameter names for this method.
1909 \sa setParameterNames()
1911 QList<QByteArray> QMetaMethodBuilder::parameterNames() const
1913 QMetaMethodBuilderPrivate *d = d_func();
1915 return d->parameterNames;
1917 return QList<QByteArray>();
1921 Sets the list of parameter names for this method to \a value.
1923 \sa parameterNames()
1925 void QMetaMethodBuilder::setParameterNames(const QList<QByteArray>& value)
1927 QMetaMethodBuilderPrivate *d = d_func();
1929 d->parameterNames = value;
1933 Returns the tag associated with this method.
1937 QByteArray QMetaMethodBuilder::tag() const
1939 QMetaMethodBuilderPrivate *d = d_func();
1943 return QByteArray();
1947 Sets the tag associated with this method to \a value.
1951 void QMetaMethodBuilder::setTag(const QByteArray& value)
1953 QMetaMethodBuilderPrivate *d = d_func();
1959 Returns the access specification of this method (private, protected,
1960 or public). The default value is QMetaMethod::Public for methods,
1961 slots, and constructors. The default value is QMetaMethod::Protected
1966 QMetaMethod::Access QMetaMethodBuilder::access() const
1968 QMetaMethodBuilderPrivate *d = d_func();
1972 return QMetaMethod::Public;
1976 Sets the access specification of this method (private, protected,
1977 or public) to \a value. If the method is a signal, this function
1982 void QMetaMethodBuilder::setAccess(QMetaMethod::Access value)
1984 QMetaMethodBuilderPrivate *d = d_func();
1985 if (d && d->methodType() != QMetaMethod::Signal)
1986 d->setAccess(value);
1990 Returns the additional attributes for this method.
1994 int QMetaMethodBuilder::attributes() const
1996 QMetaMethodBuilderPrivate *d = d_func();
1998 return (d->attributes >> 4);
2004 Sets the additional attributes for this method to \a value.
2008 void QMetaMethodBuilder::setAttributes(int value)
2010 QMetaMethodBuilderPrivate *d = d_func();
2012 d->attributes = ((d->attributes & 0x0f) | (value << 4));
2016 \class QMetaPropertyBuilder
2018 \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder.
2021 QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const
2023 if (_mobj && _index >= 0 && _index < _mobj->d->properties.size())
2024 return &(_mobj->d->properties[_index]);
2030 \fn QMetaPropertyBuilder::QMetaPropertyBuilder()
2035 \fn int QMetaPropertyBuilder::index() const
2037 Returns the index of this property within its QMetaObjectBuilder.
2041 Returns the name associated with this property.
2045 QByteArray QMetaPropertyBuilder::name() const
2047 QMetaPropertyBuilderPrivate *d = d_func();
2051 return QByteArray();
2055 Returns the type associated with this property.
2059 QByteArray QMetaPropertyBuilder::type() const
2061 QMetaPropertyBuilderPrivate *d = d_func();
2065 return QByteArray();
2069 Returns true if this property has a notify signal; false otherwise.
2071 \sa notifySignal(), setNotifySignal(), removeNotifySignal()
2073 bool QMetaPropertyBuilder::hasNotifySignal() const
2075 QMetaPropertyBuilderPrivate *d = d_func();
2077 return d->flag(Notify);
2083 Returns the notify signal associated with this property.
2085 \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal()
2087 QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const
2089 QMetaPropertyBuilderPrivate *d = d_func();
2090 if (d && d->notifySignal >= 0)
2091 return QMetaMethodBuilder(_mobj, d->notifySignal);
2093 return QMetaMethodBuilder();
2097 Sets the notify signal associated with this property to \a value.
2099 \sa hasNotifySignal(), notifySignal(), removeNotifySignal()
2101 void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
2103 QMetaPropertyBuilderPrivate *d = d_func();
2106 d->notifySignal = value._index;
2107 d->setFlag(Notify, true);
2109 d->notifySignal = -1;
2110 d->setFlag(Notify, false);
2116 Removes the notify signal from this property.
2118 \sa hasNotifySignal(), notifySignal(), setNotifySignal()
2120 void QMetaPropertyBuilder::removeNotifySignal()
2122 QMetaPropertyBuilderPrivate *d = d_func();
2124 d->notifySignal = -1;
2125 d->setFlag(Notify, false);
2130 Returns true if this property is readable; otherwise returns false.
2131 The default value is true.
2133 \sa setReadable(), isWritable()
2135 bool QMetaPropertyBuilder::isReadable() const
2137 QMetaPropertyBuilderPrivate *d = d_func();
2139 return d->flag(Readable);
2145 Returns true if this property is writable; otherwise returns false.
2146 The default value is true.
2148 \sa setWritable(), isReadable()
2150 bool QMetaPropertyBuilder::isWritable() const
2152 QMetaPropertyBuilderPrivate *d = d_func();
2154 return d->flag(Writable);
2160 Returns true if this property can be reset to a default value; otherwise
2161 returns false. The default value is false.
2165 bool QMetaPropertyBuilder::isResettable() const
2167 QMetaPropertyBuilderPrivate *d = d_func();
2169 return d->flag(Resettable);
2175 Returns true if this property is designable; otherwise returns false.
2176 This default value is false.
2178 \sa setDesignable(), isScriptable(), isStored()
2180 bool QMetaPropertyBuilder::isDesignable() const
2182 QMetaPropertyBuilderPrivate *d = d_func();
2184 return d->flag(Designable);
2190 Returns true if the property is scriptable; otherwise returns false.
2191 This default value is true.
2193 \sa setScriptable(), isDesignable(), isStored()
2195 bool QMetaPropertyBuilder::isScriptable() const
2197 QMetaPropertyBuilderPrivate *d = d_func();
2199 return d->flag(Scriptable);
2205 Returns true if the property is stored; otherwise returns false.
2206 This default value is false.
2208 \sa setStored(), isDesignable(), isScriptable()
2210 bool QMetaPropertyBuilder::isStored() const
2212 QMetaPropertyBuilderPrivate *d = d_func();
2214 return d->flag(Stored);
2220 Returns true if the property is editable; otherwise returns false.
2221 This default value is false.
2223 \sa setEditable(), isDesignable(), isScriptable(), isStored()
2225 bool QMetaPropertyBuilder::isEditable() const
2227 QMetaPropertyBuilderPrivate *d = d_func();
2229 return d->flag(Editable);
2235 Returns true if this property is designated as the \c USER
2236 property, i.e., the one that the user can edit or that is
2237 significant in some other way. Otherwise it returns
2238 false. This default value is false.
2240 \sa setUser(), isDesignable(), isScriptable()
2242 bool QMetaPropertyBuilder::isUser() const
2244 QMetaPropertyBuilderPrivate *d = d_func();
2246 return d->flag(User);
2252 Returns true if the property has a C++ setter function that
2253 follows Qt's standard "name" / "setName" pattern. Designer and uic
2254 query hasStdCppSet() in order to avoid expensive
2255 QObject::setProperty() calls. All properties in Qt [should] follow
2256 this pattern. The default value is false.
2260 bool QMetaPropertyBuilder::hasStdCppSet() const
2262 QMetaPropertyBuilderPrivate *d = d_func();
2264 return d->flag(StdCppSet);
2270 Returns true if the property is an enumerator or flag type;
2271 otherwise returns false. This default value is false.
2275 bool QMetaPropertyBuilder::isEnumOrFlag() const
2277 QMetaPropertyBuilderPrivate *d = d_func();
2279 return d->flag(EnumOrFlag);
2285 Returns true if the property is constant; otherwise returns false.
2286 The default value is false.
2288 bool QMetaPropertyBuilder::isConstant() const
2290 QMetaPropertyBuilderPrivate *d = d_func();
2292 return d->flag(Constant);
2298 Returns true if the property is final; otherwise returns false.
2299 The default value is false.
2301 bool QMetaPropertyBuilder::isFinal() const
2303 QMetaPropertyBuilderPrivate *d = d_func();
2305 return d->flag(Final);
2311 Sets this property to readable if \a value is true.
2313 \sa isReadable(), setWritable()
2315 void QMetaPropertyBuilder::setReadable(bool value)
2317 QMetaPropertyBuilderPrivate *d = d_func();
2319 d->setFlag(Readable, value);
2323 Sets this property to writable if \a value is true.
2325 \sa isWritable(), setReadable()
2327 void QMetaPropertyBuilder::setWritable(bool value)
2329 QMetaPropertyBuilderPrivate *d = d_func();
2331 d->setFlag(Writable, value);
2335 Sets this property to resettable if \a value is true.
2339 void QMetaPropertyBuilder::setResettable(bool value)
2341 QMetaPropertyBuilderPrivate *d = d_func();
2343 d->setFlag(Resettable, value);
2347 Sets this property to designable if \a value is true.
2349 \sa isDesignable(), setScriptable(), setStored()
2351 void QMetaPropertyBuilder::setDesignable(bool value)
2353 QMetaPropertyBuilderPrivate *d = d_func();
2355 d->setFlag(Designable, value);
2359 Sets this property to scriptable if \a value is true.
2361 \sa isScriptable(), setDesignable(), setStored()
2363 void QMetaPropertyBuilder::setScriptable(bool value)
2365 QMetaPropertyBuilderPrivate *d = d_func();
2367 d->setFlag(Scriptable, value);
2371 Sets this property to storable if \a value is true.
2373 \sa isStored(), setDesignable(), setScriptable()
2375 void QMetaPropertyBuilder::setStored(bool value)
2377 QMetaPropertyBuilderPrivate *d = d_func();
2379 d->setFlag(Stored, value);
2383 Sets this property to editable if \a value is true.
2385 \sa isEditable(), setDesignable(), setScriptable(), setStored()
2387 void QMetaPropertyBuilder::setEditable(bool value)
2389 QMetaPropertyBuilderPrivate *d = d_func();
2391 d->setFlag(Editable, value);
2395 Sets the \c USER flag on this property to \a value.
2397 \sa isUser(), setDesignable(), setScriptable()
2399 void QMetaPropertyBuilder::setUser(bool value)
2401 QMetaPropertyBuilderPrivate *d = d_func();
2403 d->setFlag(User, value);
2407 Sets the C++ setter flag on this property to \a value, which is
2408 true if the property has a C++ setter function that follows Qt's
2409 standard "name" / "setName" pattern.
2413 void QMetaPropertyBuilder::setStdCppSet(bool value)
2415 QMetaPropertyBuilderPrivate *d = d_func();
2417 d->setFlag(StdCppSet, value);
2421 Sets this property to be of an enumerator or flag type if
2426 void QMetaPropertyBuilder::setEnumOrFlag(bool value)
2428 QMetaPropertyBuilderPrivate *d = d_func();
2430 d->setFlag(EnumOrFlag, value);
2434 Sets the \c CONSTANT flag on this property to \a value.
2438 void QMetaPropertyBuilder::setConstant(bool value)
2440 QMetaPropertyBuilderPrivate *d = d_func();
2442 d->setFlag(Constant, value);
2446 Sets the \c FINAL flag on this property to \a value.
2450 void QMetaPropertyBuilder::setFinal(bool value)
2452 QMetaPropertyBuilderPrivate *d = d_func();
2454 d->setFlag(Final, value);
2459 \class QMetaEnumBuilder
2461 \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder.
2464 QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const
2466 if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size())
2467 return &(_mobj->d->enumerators[_index]);
2473 \fn QMetaEnumBuilder::QMetaEnumBuilder()
2478 \fn int QMetaEnumBuilder::index() const
2480 Returns the index of this enumerator within its QMetaObjectBuilder.
2484 Returns the name of the enumerator (without the scope).
2486 QByteArray QMetaEnumBuilder::name() const
2488 QMetaEnumBuilderPrivate *d = d_func();
2492 return QByteArray();
2496 Returns true if this enumerator is used as a flag; otherwise returns
2501 bool QMetaEnumBuilder::isFlag() const
2503 QMetaEnumBuilderPrivate *d = d_func();
2511 Sets this enumerator to be used as a flag if \a value is true.
2515 void QMetaEnumBuilder::setIsFlag(bool value)
2517 QMetaEnumBuilderPrivate *d = d_func();
2523 Returns the number of keys.
2527 int QMetaEnumBuilder::keyCount() const
2529 QMetaEnumBuilderPrivate *d = d_func();
2531 return d->keys.size();
2537 Returns the key with the given \a index, or an empty QByteArray
2538 if no such key exists.
2540 \sa keyCount(), addKey(), value()
2542 QByteArray QMetaEnumBuilder::key(int index) const
2544 QMetaEnumBuilderPrivate *d = d_func();
2545 if (d && index >= 0 && index < d->keys.size())
2546 return d->keys[index];
2548 return QByteArray();
2552 Returns the value with the given \a index; or returns -1 if there
2555 \sa keyCount(), addKey(), key()
2557 int QMetaEnumBuilder::value(int index) const
2559 QMetaEnumBuilderPrivate *d = d_func();
2560 if (d && index >= 0 && index < d->keys.size())
2561 return d->values[index];
2567 Adds a new key called \a name to this enumerator, associated
2568 with \a value. Returns the index of the new key.
2570 \sa keyCount(), key(), value(), removeKey()
2572 int QMetaEnumBuilder::addKey(const QByteArray& name, int value)
2574 QMetaEnumBuilderPrivate *d = d_func();
2576 int index = d->keys.size();
2586 Removes the key at \a index from this enumerator.
2590 void QMetaEnumBuilder::removeKey(int index)
2592 QMetaEnumBuilderPrivate *d = d_func();
2593 if (d && index >= 0 && index < d->keys.size()) {
2594 d->keys.removeAt(index);
2595 d->values.removeAt(index);