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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 memset(buf, 0, size);
1456 buildMetaObject(d, buf, false);
1457 return reinterpret_cast<QMetaObject *>(buf);
1463 Converts this meta object builder into relocatable data. This data can
1464 be stored, copied and later passed to fromRelocatableData() to create a
1465 concrete QMetaObject.
1467 The data is specific to the architecture on which it was created, but is not
1468 specific to the process that created it. Not all meta object builder's can
1469 be converted to data in this way. If \a ok is provided, it will be set to
1470 true if the conversion succeeds, and false otherwise. If a
1471 staticMetacallFunction() or any relatedMetaObject()'s are specified the
1472 conversion to relocatable data will fail.
1474 QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const
1476 int size = buildMetaObject(d, 0, true);
1478 if (ok) *ok = false;
1479 return QByteArray();
1484 char *buf = data.data();
1485 memset(buf, 0, size);
1486 buildMetaObject(d, buf, true);
1494 Sets the \a data returned from toRelocatableData() onto a concrete
1495 QMetaObject instance, \a output. As the meta object's super class is not
1496 saved in the relocatable data, it must be passed as \a superClass.
1498 void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output,
1499 const QMetaObject *superclass,
1500 const QByteArray &data)
1505 const char *buf = data.constData();
1506 const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf);
1508 quintptr stringdataOffset = (quintptr)dataMo->d.stringdata;
1509 quintptr dataOffset = (quintptr)dataMo->d.data;
1511 output->d.superdata = superclass;
1512 output->d.stringdata = buf + stringdataOffset;
1513 output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
1517 \typedef QMetaObjectBuilder::StaticMetacallFunction
1519 Typedef for static metacall functions. The three parameters are
1520 the call type value, the constructor index, and the
1521 array of parameters.
1525 Returns the static metacall function to use to construct objects
1526 of this class. The default value is null.
1528 \sa setStaticMetacallFunction()
1530 QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const
1532 return d->staticMetacallFunction;
1536 Sets the static metacall function to use to construct objects
1537 of this class to \a value. The default value is null.
1539 \sa staticMetacallFunction()
1541 void QMetaObjectBuilder::setStaticMetacallFunction
1542 (QMetaObjectBuilder::StaticMetacallFunction value)
1544 d->staticMetacallFunction = value;
1547 #ifndef QT_NO_DATASTREAM
1550 Serializes the contents of the meta object builder onto \a stream.
1554 void QMetaObjectBuilder::serialize(QDataStream& stream) const
1558 // Write the class and super class names.
1559 stream << d->className;
1561 stream << QByteArray(d->superClass->className());
1563 stream << QByteArray();
1565 // Write the counts for each type of class member.
1566 stream << d->classInfoNames.size();
1567 stream << d->methods.size();
1568 stream << d->properties.size();
1569 stream << d->enumerators.size();
1570 stream << d->constructors.size();
1571 stream << d->relatedMetaObjects.size();
1573 // Write the items of class information.
1574 for (index = 0; index < d->classInfoNames.size(); ++index) {
1575 stream << d->classInfoNames[index];
1576 stream << d->classInfoValues[index];
1579 // Write the methods.
1580 for (index = 0; index < d->methods.size(); ++index) {
1581 const QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1582 stream << method->signature;
1583 stream << method->returnType;
1584 stream << method->parameterNames;
1585 stream << method->tag;
1586 stream << method->attributes;
1589 // Write the properties.
1590 for (index = 0; index < d->properties.size(); ++index) {
1591 const QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1592 stream << property->name;
1593 stream << property->type;
1594 stream << property->flags;
1595 stream << property->notifySignal;
1598 // Write the enumerators.
1599 for (index = 0; index < d->enumerators.size(); ++index) {
1600 const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1601 stream << enumerator->name;
1602 stream << enumerator->isFlag;
1603 stream << enumerator->keys;
1604 stream << enumerator->values;
1607 // Write the constructors.
1608 for (index = 0; index < d->constructors.size(); ++index) {
1609 const QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1610 stream << method->signature;
1611 stream << method->returnType;
1612 stream << method->parameterNames;
1613 stream << method->tag;
1614 stream << method->attributes;
1617 // Write the related meta objects.
1618 #ifdef Q_NO_DATA_RELOCATION
1619 //### What do we do here?
1621 for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
1622 const QMetaObject *meta = d->relatedMetaObjects[index];
1623 stream << QByteArray(meta->className());
1627 // Add an extra empty QByteArray for additional data in future versions.
1628 // This should help maintain backwards compatibility, allowing older
1629 // versions to read newer data.
1630 stream << QByteArray();
1633 // Resolve a class name using the name reference map.
1634 static const QMetaObject *resolveClassName
1635 (const QMap<QByteArray, const QMetaObject *>& references,
1636 const QByteArray& name)
1638 if (name == QByteArray("QObject"))
1639 return &QObject::staticMetaObject;
1641 return references.value(name, 0);
1645 Deserializes a meta object builder from \a stream into
1646 this meta object builder.
1648 The \a references parameter specifies a mapping from class names
1649 to QMetaObject instances for resolving the super class name and
1650 related meta objects in the object that is deserialized.
1651 The meta object for QObject is implicitly added to \a references
1652 and does not need to be supplied.
1654 The QDataStream::status() value on \a stream will be set to
1655 QDataStream::ReadCorruptData if the input data is corrupt.
1656 The status will be set to QDataStream::ReadPastEnd if the
1657 input was exhausted before the full meta object was read.
1661 void QMetaObjectBuilder::deserialize
1662 (QDataStream& stream,
1663 const QMap<QByteArray, const QMetaObject *>& references)
1666 const QMetaObject *cl;
1669 // Clear all members in the builder to their default states.
1670 d->className.clear();
1671 d->superClass = &QObject::staticMetaObject;
1672 d->classInfoNames.clear();
1673 d->classInfoValues.clear();
1675 d->properties.clear();
1676 d->enumerators.clear();
1677 d->constructors.clear();
1678 d->relatedMetaObjects.clear();
1679 d->staticMetacallFunction = 0;
1681 // Read the class and super class names.
1682 stream >> d->className;
1684 if (name.isEmpty()) {
1686 } else if ((cl = resolveClassName(references, name)) != 0) {
1689 stream.setStatus(QDataStream::ReadCorruptData);
1693 // Read the counts for each type of class member.
1694 int classInfoCount, methodCount, propertyCount;
1695 int enumeratorCount, constructorCount, relatedMetaObjectCount;
1696 stream >> classInfoCount;
1697 stream >> methodCount;
1698 stream >> propertyCount;
1699 stream >> enumeratorCount;
1700 stream >> constructorCount;
1701 stream >> relatedMetaObjectCount;
1702 if (classInfoCount < 0 || methodCount < 0 ||
1703 propertyCount < 0 || enumeratorCount < 0 ||
1704 constructorCount < 0 || relatedMetaObjectCount < 0) {
1705 stream.setStatus(QDataStream::ReadCorruptData);
1709 // Read the items of class information.
1710 for (index = 0; index < classInfoCount; ++index) {
1711 if (stream.status() != QDataStream::Ok)
1716 addClassInfo(name, value);
1719 // Read the member methods.
1720 for (index = 0; index < methodCount; ++index) {
1721 if (stream.status() != QDataStream::Ok)
1725 QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1726 stream >> method->returnType;
1727 stream >> method->parameterNames;
1728 stream >> method->tag;
1729 stream >> method->attributes;
1730 if (method->methodType() == QMetaMethod::Constructor) {
1731 // Cannot add a constructor in this set of methods.
1732 stream.setStatus(QDataStream::ReadCorruptData);
1737 // Read the properties.
1738 for (index = 0; index < propertyCount; ++index) {
1739 if (stream.status() != QDataStream::Ok)
1744 addProperty(name, type);
1745 QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1746 stream >> property->flags;
1747 stream >> property->notifySignal;
1748 if (property->notifySignal < -1 ||
1749 property->notifySignal >= d->methods.size()) {
1750 // Notify signal method index is out of range.
1751 stream.setStatus(QDataStream::ReadCorruptData);
1754 if (property->notifySignal >= 0 &&
1755 d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) {
1756 // Notify signal method index does not refer to a signal.
1757 stream.setStatus(QDataStream::ReadCorruptData);
1762 // Read the enumerators.
1763 for (index = 0; index < enumeratorCount; ++index) {
1764 if (stream.status() != QDataStream::Ok)
1767 addEnumerator(name);
1768 QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1769 stream >> enumerator->isFlag;
1770 stream >> enumerator->keys;
1771 stream >> enumerator->values;
1772 if (enumerator->keys.size() != enumerator->values.size()) {
1773 // Mismatch between number of keys and number of values.
1774 stream.setStatus(QDataStream::ReadCorruptData);
1779 // Read the constructor methods.
1780 for (index = 0; index < constructorCount; ++index) {
1781 if (stream.status() != QDataStream::Ok)
1784 addConstructor(name);
1785 QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1786 stream >> method->returnType;
1787 stream >> method->parameterNames;
1788 stream >> method->tag;
1789 stream >> method->attributes;
1790 if (method->methodType() != QMetaMethod::Constructor) {
1791 // The type must be Constructor.
1792 stream.setStatus(QDataStream::ReadCorruptData);
1797 // Read the related meta objects.
1798 #ifdef Q_NO_DATA_RELOCATION
1799 //### What do we do here
1801 for (index = 0; index < relatedMetaObjectCount; ++index) {
1802 if (stream.status() != QDataStream::Ok)
1805 cl = resolveClassName(references, name);
1807 stream.setStatus(QDataStream::ReadCorruptData);
1810 addRelatedMetaObject(cl);
1814 // Read the extra data block, which is reserved for future use.
1818 #endif // !QT_NO_DATASTREAM
1821 \class QMetaMethodBuilder
1823 \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder.
1826 QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const
1828 // Positive indices indicate methods, negative indices indicate constructors.
1829 if (_mobj && _index >= 0 && _index < _mobj->d->methods.size())
1830 return &(_mobj->d->methods[_index]);
1831 else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size())
1832 return &(_mobj->d->constructors[(-_index) - 1]);
1838 \fn QMetaMethodBuilder::QMetaMethodBuilder()
1843 Returns the index of this method within its QMetaObjectBuilder.
1845 int QMetaMethodBuilder::index() const
1848 return _index; // Method, signal, or slot
1850 return (-_index) - 1; // Constructor
1854 Returns the type of this method (signal, slot, method, or constructor).
1856 QMetaMethod::MethodType QMetaMethodBuilder::methodType() const
1858 QMetaMethodBuilderPrivate *d = d_func();
1860 return d->methodType();
1862 return QMetaMethod::Method;
1866 Returns the signature of this method.
1868 \sa parameterNames(), returnType()
1870 QByteArray QMetaMethodBuilder::signature() const
1872 QMetaMethodBuilderPrivate *d = d_func();
1874 return d->signature;
1876 return QByteArray();
1880 Returns the return type for this method; empty if the method's
1881 return type is \c{void}.
1883 \sa setReturnType(), signature()
1885 QByteArray QMetaMethodBuilder::returnType() const
1887 QMetaMethodBuilderPrivate *d = d_func();
1889 return d->returnType;
1891 return QByteArray();
1895 Sets the return type for this method to \a value. If \a value
1896 is empty, then the method's return type is \c{void}. The \a value
1897 will be normalized before it is added to the method.
1899 \sa returnType(), signature()
1901 void QMetaMethodBuilder::setReturnType(const QByteArray& value)
1903 QMetaMethodBuilderPrivate *d = d_func();
1905 d->returnType = QMetaObject::normalizedType(value);
1909 Returns the list of parameter names for this method.
1911 \sa setParameterNames()
1913 QList<QByteArray> QMetaMethodBuilder::parameterNames() const
1915 QMetaMethodBuilderPrivate *d = d_func();
1917 return d->parameterNames;
1919 return QList<QByteArray>();
1923 Sets the list of parameter names for this method to \a value.
1925 \sa parameterNames()
1927 void QMetaMethodBuilder::setParameterNames(const QList<QByteArray>& value)
1929 QMetaMethodBuilderPrivate *d = d_func();
1931 d->parameterNames = value;
1935 Returns the tag associated with this method.
1939 QByteArray QMetaMethodBuilder::tag() const
1941 QMetaMethodBuilderPrivate *d = d_func();
1945 return QByteArray();
1949 Sets the tag associated with this method to \a value.
1953 void QMetaMethodBuilder::setTag(const QByteArray& value)
1955 QMetaMethodBuilderPrivate *d = d_func();
1961 Returns the access specification of this method (private, protected,
1962 or public). The default value is QMetaMethod::Public for methods,
1963 slots, and constructors. The default value is QMetaMethod::Protected
1968 QMetaMethod::Access QMetaMethodBuilder::access() const
1970 QMetaMethodBuilderPrivate *d = d_func();
1974 return QMetaMethod::Public;
1978 Sets the access specification of this method (private, protected,
1979 or public) to \a value. If the method is a signal, this function
1984 void QMetaMethodBuilder::setAccess(QMetaMethod::Access value)
1986 QMetaMethodBuilderPrivate *d = d_func();
1987 if (d && d->methodType() != QMetaMethod::Signal)
1988 d->setAccess(value);
1992 Returns the additional attributes for this method.
1996 int QMetaMethodBuilder::attributes() const
1998 QMetaMethodBuilderPrivate *d = d_func();
2000 return (d->attributes >> 4);
2006 Sets the additional attributes for this method to \a value.
2010 void QMetaMethodBuilder::setAttributes(int value)
2012 QMetaMethodBuilderPrivate *d = d_func();
2014 d->attributes = ((d->attributes & 0x0f) | (value << 4));
2018 \class QMetaPropertyBuilder
2020 \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder.
2023 QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const
2025 if (_mobj && _index >= 0 && _index < _mobj->d->properties.size())
2026 return &(_mobj->d->properties[_index]);
2032 \fn QMetaPropertyBuilder::QMetaPropertyBuilder()
2037 \fn int QMetaPropertyBuilder::index() const
2039 Returns the index of this property within its QMetaObjectBuilder.
2043 Returns the name associated with this property.
2047 QByteArray QMetaPropertyBuilder::name() const
2049 QMetaPropertyBuilderPrivate *d = d_func();
2053 return QByteArray();
2057 Returns the type associated with this property.
2061 QByteArray QMetaPropertyBuilder::type() const
2063 QMetaPropertyBuilderPrivate *d = d_func();
2067 return QByteArray();
2071 Returns true if this property has a notify signal; false otherwise.
2073 \sa notifySignal(), setNotifySignal(), removeNotifySignal()
2075 bool QMetaPropertyBuilder::hasNotifySignal() const
2077 QMetaPropertyBuilderPrivate *d = d_func();
2079 return d->flag(Notify);
2085 Returns the notify signal associated with this property.
2087 \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal()
2089 QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const
2091 QMetaPropertyBuilderPrivate *d = d_func();
2092 if (d && d->notifySignal >= 0)
2093 return QMetaMethodBuilder(_mobj, d->notifySignal);
2095 return QMetaMethodBuilder();
2099 Sets the notify signal associated with this property to \a value.
2101 \sa hasNotifySignal(), notifySignal(), removeNotifySignal()
2103 void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
2105 QMetaPropertyBuilderPrivate *d = d_func();
2108 d->notifySignal = value._index;
2109 d->setFlag(Notify, true);
2111 d->notifySignal = -1;
2112 d->setFlag(Notify, false);
2118 Removes the notify signal from this property.
2120 \sa hasNotifySignal(), notifySignal(), setNotifySignal()
2122 void QMetaPropertyBuilder::removeNotifySignal()
2124 QMetaPropertyBuilderPrivate *d = d_func();
2126 d->notifySignal = -1;
2127 d->setFlag(Notify, false);
2132 Returns true if this property is readable; otherwise returns false.
2133 The default value is true.
2135 \sa setReadable(), isWritable()
2137 bool QMetaPropertyBuilder::isReadable() const
2139 QMetaPropertyBuilderPrivate *d = d_func();
2141 return d->flag(Readable);
2147 Returns true if this property is writable; otherwise returns false.
2148 The default value is true.
2150 \sa setWritable(), isReadable()
2152 bool QMetaPropertyBuilder::isWritable() const
2154 QMetaPropertyBuilderPrivate *d = d_func();
2156 return d->flag(Writable);
2162 Returns true if this property can be reset to a default value; otherwise
2163 returns false. The default value is false.
2167 bool QMetaPropertyBuilder::isResettable() const
2169 QMetaPropertyBuilderPrivate *d = d_func();
2171 return d->flag(Resettable);
2177 Returns true if this property is designable; otherwise returns false.
2178 This default value is false.
2180 \sa setDesignable(), isScriptable(), isStored()
2182 bool QMetaPropertyBuilder::isDesignable() const
2184 QMetaPropertyBuilderPrivate *d = d_func();
2186 return d->flag(Designable);
2192 Returns true if the property is scriptable; otherwise returns false.
2193 This default value is true.
2195 \sa setScriptable(), isDesignable(), isStored()
2197 bool QMetaPropertyBuilder::isScriptable() const
2199 QMetaPropertyBuilderPrivate *d = d_func();
2201 return d->flag(Scriptable);
2207 Returns true if the property is stored; otherwise returns false.
2208 This default value is false.
2210 \sa setStored(), isDesignable(), isScriptable()
2212 bool QMetaPropertyBuilder::isStored() const
2214 QMetaPropertyBuilderPrivate *d = d_func();
2216 return d->flag(Stored);
2222 Returns true if the property is editable; otherwise returns false.
2223 This default value is false.
2225 \sa setEditable(), isDesignable(), isScriptable(), isStored()
2227 bool QMetaPropertyBuilder::isEditable() const
2229 QMetaPropertyBuilderPrivate *d = d_func();
2231 return d->flag(Editable);
2237 Returns true if this property is designated as the \c USER
2238 property, i.e., the one that the user can edit or that is
2239 significant in some other way. Otherwise it returns
2240 false. This default value is false.
2242 \sa setUser(), isDesignable(), isScriptable()
2244 bool QMetaPropertyBuilder::isUser() const
2246 QMetaPropertyBuilderPrivate *d = d_func();
2248 return d->flag(User);
2254 Returns true if the property has a C++ setter function that
2255 follows Qt's standard "name" / "setName" pattern. Designer and uic
2256 query hasStdCppSet() in order to avoid expensive
2257 QObject::setProperty() calls. All properties in Qt [should] follow
2258 this pattern. The default value is false.
2262 bool QMetaPropertyBuilder::hasStdCppSet() const
2264 QMetaPropertyBuilderPrivate *d = d_func();
2266 return d->flag(StdCppSet);
2272 Returns true if the property is an enumerator or flag type;
2273 otherwise returns false. This default value is false.
2277 bool QMetaPropertyBuilder::isEnumOrFlag() const
2279 QMetaPropertyBuilderPrivate *d = d_func();
2281 return d->flag(EnumOrFlag);
2287 Returns true if the property is constant; otherwise returns false.
2288 The default value is false.
2290 bool QMetaPropertyBuilder::isConstant() const
2292 QMetaPropertyBuilderPrivate *d = d_func();
2294 return d->flag(Constant);
2300 Returns true if the property is final; otherwise returns false.
2301 The default value is false.
2303 bool QMetaPropertyBuilder::isFinal() const
2305 QMetaPropertyBuilderPrivate *d = d_func();
2307 return d->flag(Final);
2313 Sets this property to readable if \a value is true.
2315 \sa isReadable(), setWritable()
2317 void QMetaPropertyBuilder::setReadable(bool value)
2319 QMetaPropertyBuilderPrivate *d = d_func();
2321 d->setFlag(Readable, value);
2325 Sets this property to writable if \a value is true.
2327 \sa isWritable(), setReadable()
2329 void QMetaPropertyBuilder::setWritable(bool value)
2331 QMetaPropertyBuilderPrivate *d = d_func();
2333 d->setFlag(Writable, value);
2337 Sets this property to resettable if \a value is true.
2341 void QMetaPropertyBuilder::setResettable(bool value)
2343 QMetaPropertyBuilderPrivate *d = d_func();
2345 d->setFlag(Resettable, value);
2349 Sets this property to designable if \a value is true.
2351 \sa isDesignable(), setScriptable(), setStored()
2353 void QMetaPropertyBuilder::setDesignable(bool value)
2355 QMetaPropertyBuilderPrivate *d = d_func();
2357 d->setFlag(Designable, value);
2361 Sets this property to scriptable if \a value is true.
2363 \sa isScriptable(), setDesignable(), setStored()
2365 void QMetaPropertyBuilder::setScriptable(bool value)
2367 QMetaPropertyBuilderPrivate *d = d_func();
2369 d->setFlag(Scriptable, value);
2373 Sets this property to storable if \a value is true.
2375 \sa isStored(), setDesignable(), setScriptable()
2377 void QMetaPropertyBuilder::setStored(bool value)
2379 QMetaPropertyBuilderPrivate *d = d_func();
2381 d->setFlag(Stored, value);
2385 Sets this property to editable if \a value is true.
2387 \sa isEditable(), setDesignable(), setScriptable(), setStored()
2389 void QMetaPropertyBuilder::setEditable(bool value)
2391 QMetaPropertyBuilderPrivate *d = d_func();
2393 d->setFlag(Editable, value);
2397 Sets the \c USER flag on this property to \a value.
2399 \sa isUser(), setDesignable(), setScriptable()
2401 void QMetaPropertyBuilder::setUser(bool value)
2403 QMetaPropertyBuilderPrivate *d = d_func();
2405 d->setFlag(User, value);
2409 Sets the C++ setter flag on this property to \a value, which is
2410 true if the property has a C++ setter function that follows Qt's
2411 standard "name" / "setName" pattern.
2415 void QMetaPropertyBuilder::setStdCppSet(bool value)
2417 QMetaPropertyBuilderPrivate *d = d_func();
2419 d->setFlag(StdCppSet, value);
2423 Sets this property to be of an enumerator or flag type if
2428 void QMetaPropertyBuilder::setEnumOrFlag(bool value)
2430 QMetaPropertyBuilderPrivate *d = d_func();
2432 d->setFlag(EnumOrFlag, value);
2436 Sets the \c CONSTANT flag on this property to \a value.
2440 void QMetaPropertyBuilder::setConstant(bool value)
2442 QMetaPropertyBuilderPrivate *d = d_func();
2444 d->setFlag(Constant, value);
2448 Sets the \c FINAL flag on this property to \a value.
2452 void QMetaPropertyBuilder::setFinal(bool value)
2454 QMetaPropertyBuilderPrivate *d = d_func();
2456 d->setFlag(Final, value);
2461 \class QMetaEnumBuilder
2463 \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder.
2466 QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const
2468 if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size())
2469 return &(_mobj->d->enumerators[_index]);
2475 \fn QMetaEnumBuilder::QMetaEnumBuilder()
2480 \fn int QMetaEnumBuilder::index() const
2482 Returns the index of this enumerator within its QMetaObjectBuilder.
2486 Returns the name of the enumerator (without the scope).
2488 QByteArray QMetaEnumBuilder::name() const
2490 QMetaEnumBuilderPrivate *d = d_func();
2494 return QByteArray();
2498 Returns true if this enumerator is used as a flag; otherwise returns
2503 bool QMetaEnumBuilder::isFlag() const
2505 QMetaEnumBuilderPrivate *d = d_func();
2513 Sets this enumerator to be used as a flag if \a value is true.
2517 void QMetaEnumBuilder::setIsFlag(bool value)
2519 QMetaEnumBuilderPrivate *d = d_func();
2525 Returns the number of keys.
2529 int QMetaEnumBuilder::keyCount() const
2531 QMetaEnumBuilderPrivate *d = d_func();
2533 return d->keys.size();
2539 Returns the key with the given \a index, or an empty QByteArray
2540 if no such key exists.
2542 \sa keyCount(), addKey(), value()
2544 QByteArray QMetaEnumBuilder::key(int index) const
2546 QMetaEnumBuilderPrivate *d = d_func();
2547 if (d && index >= 0 && index < d->keys.size())
2548 return d->keys[index];
2550 return QByteArray();
2554 Returns the value with the given \a index; or returns -1 if there
2557 \sa keyCount(), addKey(), key()
2559 int QMetaEnumBuilder::value(int index) const
2561 QMetaEnumBuilderPrivate *d = d_func();
2562 if (d && index >= 0 && index < d->keys.size())
2563 return d->values[index];
2569 Adds a new key called \a name to this enumerator, associated
2570 with \a value. Returns the index of the new key.
2572 \sa keyCount(), key(), value(), removeKey()
2574 int QMetaEnumBuilder::addKey(const QByteArray& name, int value)
2576 QMetaEnumBuilderPrivate *d = d_func();
2578 int index = d->keys.size();
2588 Removes the key at \a index from this enumerator.
2592 void QMetaEnumBuilder::removeKey(int index)
2594 QMetaEnumBuilderPrivate *d = d_func();
2595 if (d && index >= 0 && index < d->keys.size()) {
2596 d->keys.removeAt(index);
2597 d->values.removeAt(index);