Uninitialized memory is compared.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qmetaobjectbuilder.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "private/qmetaobjectbuilder_p.h"
43
44 QT_BEGIN_NAMESPACE
45
46 /*!
47     \class QMetaObjectBuilder
48     \internal
49     \brief The QMetaObjectBuilder class supports building QMetaObject objects at runtime.
50
51 */
52
53 /*!
54     \enum QMetaObjectBuilder::AddMember
55     This enum defines which members of QMetaObject should be copied by QMetaObjectBuilder::addMetaObject()
56
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.
73 */
74
75 // copied from moc's generator.cpp
76 uint qvariant_nameToType(const char* name)
77 {
78     if (!name)
79         return 0;
80
81     if (strcmp(name, "QVariant") == 0)
82         return 0xffffffff;
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;
91
92     uint tp = QMetaType::type(name);
93     return tp < QMetaType::User ? tp : 0;
94 }
95
96 /*
97   Returns true if the type is a QVariant types.
98 */
99 bool isVariantType(const char* type)
100 {
101     return qvariant_nameToType(type) != 0;
102 }
103
104 // copied from qmetaobject.cpp
105 // do not touch without touching the moc as well
106 enum PropertyFlags  {
107     Invalid = 0x00000000,
108     Readable = 0x00000001,
109     Writable = 0x00000002,
110     Resettable = 0x00000004,
111     EnumOrFlag = 0x00000008,
112     StdCppSet = 0x00000100,
113 //    Override = 0x00000200,
114     Designable = 0x00001000,
115     ResolveDesignable = 0x00002000,
116     Scriptable = 0x00004000,
117     ResolveScriptable = 0x00008000,
118     Stored = 0x00010000,
119     ResolveStored = 0x00020000,
120     Editable = 0x00040000,
121     ResolveEditable = 0x00080000,
122     User = 0x00100000,
123     ResolveUser = 0x00200000,
124     Notify = 0x00400000,
125     Revisioned = 0x00800000
126 };
127
128 enum MethodFlags  {
129     AccessPrivate = 0x00,
130     AccessProtected = 0x01,
131     AccessPublic = 0x02,
132     AccessMask = 0x03, //mask
133
134     MethodMethod = 0x00,
135     MethodSignal = 0x04,
136     MethodSlot = 0x08,
137     MethodConstructor = 0x0c,
138     MethodTypeMask = 0x0c,
139
140     MethodCompatibility = 0x10,
141     MethodCloned = 0x20,
142     MethodScriptable = 0x40,
143     MethodRevisioned = 0x80
144 };
145
146 struct QMetaObjectPrivate
147 {
148     int revision;
149     int className;
150     int classInfoCount, classInfoData;
151     int methodCount, methodData;
152     int propertyCount, propertyData;
153     int enumeratorCount, enumeratorData;
154     int constructorCount, constructorData;
155     int flags;
156 };
157
158 static inline const QMetaObjectPrivate *priv(const uint* data)
159 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
160 // end of copied lines from qmetaobject.cpp
161
162 class QMetaMethodBuilderPrivate
163 {
164 public:
165     QMetaMethodBuilderPrivate
166             (QMetaMethod::MethodType _methodType,
167              const QByteArray& _signature,
168              const QByteArray& _returnType = QByteArray(),
169              QMetaMethod::Access _access = QMetaMethod::Public)
170         : signature(QMetaObject::normalizedSignature(_signature.constData())),
171           returnType(QMetaObject::normalizedType(_returnType)),
172           attributes(((int)_access) | (((int)_methodType) << 2))
173     {
174     }
175
176     QByteArray signature;
177     QByteArray returnType;
178     QList<QByteArray> parameterNames;
179     QByteArray tag;
180     int attributes;
181
182     QMetaMethod::MethodType methodType() const
183     {
184         return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2);
185     }
186
187     QMetaMethod::Access access() const
188     {
189         return (QMetaMethod::Access)(attributes & AccessMask);
190     }
191
192     void setAccess(QMetaMethod::Access value)
193     {
194         attributes = ((attributes & ~AccessMask) | (int)value);
195     }
196 };
197
198 class QMetaPropertyBuilderPrivate
199 {
200 public:
201     QMetaPropertyBuilderPrivate
202             (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1)
203         : name(_name),
204           type(QMetaObject::normalizedType(_type.constData())),
205           flags(Readable | Writable | Scriptable), notifySignal(-1)
206     {
207         if (notifierIdx >= 0) {
208             flags |= Notify;
209             notifySignal = notifierIdx;
210         }
211     }
212
213     QByteArray name;
214     QByteArray type;
215     int flags;
216     int notifySignal;
217
218     bool flag(int f) const
219     {
220         return ((flags & f) != 0);
221     }
222
223     void setFlag(int f, bool value)
224     {
225         if (value)
226             flags |= f;
227         else
228             flags &= ~f;
229     }
230 };
231
232 class QMetaEnumBuilderPrivate
233 {
234 public:
235     QMetaEnumBuilderPrivate(const QByteArray& _name)
236         : name(_name), isFlag(false)
237     {
238     }
239
240     QByteArray name;
241     bool isFlag;
242     QList<QByteArray> keys;
243     QList<int> values;
244 };
245
246 class QMetaObjectBuilderPrivate
247 {
248 public:
249     QMetaObjectBuilderPrivate()
250         : flags(0)
251     {
252         superClass = &QObject::staticMetaObject;
253         staticMetacallFunction = 0;
254     }
255
256     QByteArray className;
257     const QMetaObject *superClass;
258     QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction;
259     QList<QMetaMethodBuilderPrivate> methods;
260     QList<QMetaMethodBuilderPrivate> constructors;
261     QList<QMetaPropertyBuilderPrivate> properties;
262     QList<QByteArray> classInfoNames;
263     QList<QByteArray> classInfoValues;
264     QList<QMetaEnumBuilderPrivate> enumerators;
265 #ifdef Q_NO_DATA_RELOCATION
266     QList<QMetaObjectAccessor> relatedMetaObjects;
267 #else
268     QList<const QMetaObject *> relatedMetaObjects;
269 #endif
270     int flags;
271 };
272
273 /*!
274     Constructs a new QMetaObjectBuilder.
275 */
276 QMetaObjectBuilder::QMetaObjectBuilder()
277 {
278     d = new QMetaObjectBuilderPrivate();
279 }
280
281 /*!
282     Constructs a new QMetaObjectBuilder which is a copy of the
283     meta object information in \a prototype.  Note: the super class
284     contents for \a prototype are not copied, only the immediate
285     class that is defined by \a prototype.
286
287     The \a members parameter indicates which members of \a prototype
288     should be added.  The default is AllMembers.
289
290     \sa addMetaObject()
291 */
292 QMetaObjectBuilder::QMetaObjectBuilder
293     (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
294 {
295     d = new QMetaObjectBuilderPrivate();
296     addMetaObject(prototype, members);
297 }
298
299 /*!
300     Destroys this meta object builder.
301 */
302 QMetaObjectBuilder::~QMetaObjectBuilder()
303 {
304     delete d;
305 }
306
307 /*!
308     Returns the name of the class being constructed by this
309     meta object builder.  The default value is an empty QByteArray.
310
311     \sa setClassName(), superClass()
312 */
313 QByteArray QMetaObjectBuilder::className() const
314 {
315     return d->className;
316 }
317
318 /*!
319     Sets the \a name of the class being constructed by this
320     meta object builder.
321
322     \sa className(), setSuperClass()
323 */
324 void QMetaObjectBuilder::setClassName(const QByteArray& name)
325 {
326     d->className = name;
327 }
328
329 /*!
330     Returns the superclass meta object of the class being constructed
331     by this meta object builder.  The default value is the meta object
332     for QObject.
333
334     \sa setSuperClass(), className()
335 */
336 const QMetaObject *QMetaObjectBuilder::superClass() const
337 {
338     return d->superClass;
339 }
340
341 /*!
342     Sets the superclass meta object of the class being constructed
343     by this meta object builder to \a meta.  The \a meta parameter
344     must not be null.
345
346     \sa superClass(), setClassName()
347 */
348 void QMetaObjectBuilder::setSuperClass(const QMetaObject *meta)
349 {
350     Q_ASSERT(meta);
351     d->superClass = meta;
352 }
353
354 /*!
355     Returns the flags of the class being constructed by this meta object
356     builder.
357
358     \sa setFlags()
359 */
360 QMetaObjectBuilder::MetaObjectFlags QMetaObjectBuilder::flags() const
361 {
362     return (QMetaObjectBuilder::MetaObjectFlags)d->flags;
363 }
364
365 /*!
366     Sets the \a flags of the class being constructed by this meta object
367     builder.
368
369     \sa flags()
370 */
371 void QMetaObjectBuilder::setFlags(MetaObjectFlags flags)
372 {
373     d->flags = flags;
374 }
375
376 /*!
377     Returns the number of methods in this class, excluding the number
378     of methods in the base class.  These include signals and slots
379     as well as normal member functions.
380
381     \sa addMethod(), method(), removeMethod(), indexOfMethod()
382 */
383 int QMetaObjectBuilder::methodCount() const
384 {
385     return d->methods.size();
386 }
387
388 /*!
389     Returns the number of constructors in this class.
390
391     \sa addConstructor(), constructor(), removeConstructor(), indexOfConstructor()
392 */
393 int QMetaObjectBuilder::constructorCount() const
394 {
395     return d->constructors.size();
396 }
397
398 /*!
399     Returns the number of properties in this class, excluding the number
400     of properties in the base class.
401
402     \sa addProperty(), property(), removeProperty(), indexOfProperty()
403 */
404 int QMetaObjectBuilder::propertyCount() const
405 {
406     return d->properties.size();
407 }
408
409 /*!
410     Returns the number of enumerators in this class, excluding the
411     number of enumerators in the base class.
412
413     \sa addEnumerator(), enumerator(), removeEnumerator()
414     \sa indexOfEnumerator()
415 */
416 int QMetaObjectBuilder::enumeratorCount() const
417 {
418     return d->enumerators.size();
419 }
420
421 /*!
422     Returns the number of items of class information in this class,
423     exclusing the number of items of class information in the base class.
424
425     \sa addClassInfo(), classInfoName(), classInfoValue(), removeClassInfo()
426     \sa indexOfClassInfo()
427 */
428 int QMetaObjectBuilder::classInfoCount() const
429 {
430     return d->classInfoNames.size();
431 }
432
433 /*!
434     Returns the number of related meta objects that are associated
435     with this class.
436
437     Related meta objects are used when resolving the enumerated type
438     associated with a property, where the enumerated type is in a
439     different class from the property.
440
441     \sa addRelatedMetaObject(), relatedMetaObject()
442     \sa removeRelatedMetaObject()
443 */
444 int QMetaObjectBuilder::relatedMetaObjectCount() const
445 {
446     return d->relatedMetaObjects.size();
447 }
448
449 /*!
450     Adds a new public method to this class with the specified \a signature.
451     Returns an object that can be used to adjust the other attributes
452     of the method.  The \a signature will be normalized before it is
453     added to the class.
454
455     \sa method(), methodCount(), removeMethod(), indexOfMethod()
456 */
457 QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature)
458 {
459     int index = d->methods.size();
460     d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature));
461     return QMetaMethodBuilder(this, index);
462 }
463
464 /*!
465     Adds a new public method to this class with the specified
466     \a signature and \a returnType.  Returns an object that can be
467     used to adjust the other attributes of the method.  The \a signature
468     and \a returnType will be normalized before they are added to
469     the class.  If \a returnType is empty, then it indicates that
470     the method has \c{void} as its return type.
471
472     \sa method(), methodCount(), removeMethod(), indexOfMethod()
473 */
474 QMetaMethodBuilder QMetaObjectBuilder::addMethod
475     (const QByteArray& signature, const QByteArray& returnType)
476 {
477     int index = d->methods.size();
478     d->methods.append(QMetaMethodBuilderPrivate
479         (QMetaMethod::Method, signature, returnType));
480     return QMetaMethodBuilder(this, index);
481 }
482
483 /*!
484     Adds a new public method to this class that has the same information as
485     \a prototype.  This is used to clone the methods of an existing
486     QMetaObject.  Returns an object that can be used to adjust the
487     attributes of the method.
488
489     This function will detect if \a prototype is an ordinary method,
490     signal, slot, or constructor and act accordingly.
491
492     \sa method(), methodCount(), removeMethod(), indexOfMethod()
493 */
494 QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype)
495 {
496     QMetaMethodBuilder method;
497     if (prototype.methodType() == QMetaMethod::Method)
498         method = addMethod(prototype.signature());
499     else if (prototype.methodType() == QMetaMethod::Signal)
500         method = addSignal(prototype.signature());
501     else if (prototype.methodType() == QMetaMethod::Slot)
502         method = addSlot(prototype.signature());
503     else if (prototype.methodType() == QMetaMethod::Constructor)
504         method = addConstructor(prototype.signature());
505     method.setReturnType(prototype.typeName());
506     method.setParameterNames(prototype.parameterNames());
507     method.setTag(prototype.tag());
508     method.setAccess(prototype.access());
509     method.setAttributes(prototype.attributes());
510     return method;
511 }
512
513 /*!
514     Adds a new public slot to this class with the specified \a signature.
515     Returns an object that can be used to adjust the other attributes
516     of the slot.  The \a signature will be normalized before it is
517     added to the class.
518
519     \sa addMethod(), addSignal(), indexOfSlot()
520 */
521 QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature)
522 {
523     int index = d->methods.size();
524     d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature));
525     return QMetaMethodBuilder(this, index);
526 }
527
528 /*!
529     Adds a new signal to this class with the specified \a signature.
530     Returns an object that can be used to adjust the other attributes
531     of the signal.  The \a signature will be normalized before it is
532     added to the class.
533
534     \sa addMethod(), addSlot(), indexOfSignal()
535 */
536 QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature)
537 {
538     int index = d->methods.size();
539     d->methods.append(QMetaMethodBuilderPrivate
540         (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected));
541     return QMetaMethodBuilder(this, index);
542 }
543
544 /*!
545     Adds a new constructor to this class with the specified \a signature.
546     Returns an object that can be used to adjust the other attributes
547     of the constructor.  The \a signature will be normalized before it is
548     added to the class.
549
550     \sa constructor(), constructorCount(), removeConstructor()
551     \sa indexOfConstructor()
552 */
553 QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature)
554 {
555     int index = d->constructors.size();
556     d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature));
557     return QMetaMethodBuilder(this, -(index + 1));
558 }
559
560 /*!
561     Adds a new constructor to this class that has the same information as
562     \a prototype.  This is used to clone the constructors of an existing
563     QMetaObject.  Returns an object that can be used to adjust the
564     attributes of the constructor.
565
566     This function requires that \a prototype be a constructor.
567
568     \sa constructor(), constructorCount(), removeConstructor()
569     \sa indexOfConstructor()
570 */
571 QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype)
572 {
573     Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor);
574     QMetaMethodBuilder ctor = addConstructor(prototype.signature());
575     ctor.setReturnType(prototype.typeName());
576     ctor.setParameterNames(prototype.parameterNames());
577     ctor.setTag(prototype.tag());
578     ctor.setAccess(prototype.access());
579     ctor.setAttributes(prototype.attributes());
580     return ctor;
581 }
582
583 /*!
584     Adds a new readable/writable property to this class with the
585     specified \a name and \a type.  Returns an object that can be used
586     to adjust the other attributes of the property.  The \a type will
587     be normalized before it is added to the class. \a notifierId will
588     be registered as the property's \e notify signal.
589
590     \sa property(), propertyCount(), removeProperty(), indexOfProperty()
591 */
592 QMetaPropertyBuilder QMetaObjectBuilder::addProperty
593     (const QByteArray& name, const QByteArray& type, int notifierId)
594 {
595     int index = d->properties.size();
596     d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId));
597     return QMetaPropertyBuilder(this, index);
598 }
599
600 /*!
601     Adds a new property to this class that has the same information as
602     \a prototype.  This is used to clone the properties of an existing
603     QMetaObject.  Returns an object that can be used to adjust the
604     attributes of the property.
605
606     \sa property(), propertyCount(), removeProperty(), indexOfProperty()
607 */
608 QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& prototype)
609 {
610     QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName());
611     property.setReadable(prototype.isReadable());
612     property.setWritable(prototype.isWritable());
613     property.setResettable(prototype.isResettable());
614     property.setDesignable(prototype.isDesignable());
615     property.setScriptable(prototype.isScriptable());
616     property.setStored(prototype.isStored());
617     property.setEditable(prototype.isEditable());
618     property.setUser(prototype.isUser());
619     property.setStdCppSet(prototype.hasStdCppSet());
620     property.setEnumOrFlag(prototype.isEnumType());
621     if (prototype.hasNotifySignal()) {
622         // Find an existing method for the notify signal, or add a new one.
623         QMetaMethod method = prototype.notifySignal();
624         int index = indexOfMethod(method.signature());
625         if (index == -1)
626             index = addMethod(method).index();
627         d->properties[property._index].notifySignal = index;
628         d->properties[property._index].setFlag(Notify, true);
629     }
630     return property;
631 }
632
633 /*!
634     Adds a new enumerator to this class with the specified
635     \a name.  Returns an object that can be used to adjust
636     the other attributes of the enumerator.
637
638     \sa enumerator(), enumeratorCount(), removeEnumerator(),
639     \sa indexOfEnumerator()
640 */
641 QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name)
642 {
643     int index = d->enumerators.size();
644     d->enumerators.append(QMetaEnumBuilderPrivate(name));
645     return QMetaEnumBuilder(this, index);
646 }
647
648 /*!
649     Adds a new enumerator to this class that has the same information as
650     \a prototype.  This is used to clone the enumerators of an existing
651     QMetaObject.  Returns an object that can be used to adjust the
652     attributes of the enumerator.
653
654     \sa enumerator(), enumeratorCount(), removeEnumerator(),
655     \sa indexOfEnumerator()
656 */
657 QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype)
658 {
659     QMetaEnumBuilder en = addEnumerator(prototype.name());
660     en.setIsFlag(prototype.isFlag());
661     int count = prototype.keyCount();
662     for (int index = 0; index < count; ++index)
663         en.addKey(prototype.key(index), prototype.value(index));
664     return en;
665 }
666
667 /*!
668     Adds \a name and \a value as an item of class information to this class.
669     Returns the index of the new item of class information.
670
671     \sa classInfoCount(), classInfoName(), classInfoValue(), removeClassInfo()
672     \sa indexOfClassInfo()
673 */
674 int QMetaObjectBuilder::addClassInfo(const QByteArray& name, const QByteArray& value)
675 {
676     int index = d->classInfoNames.size();
677     d->classInfoNames += name;
678     d->classInfoValues += value;
679     return index;
680 }
681
682 /*!
683     Adds \a meta to this class as a related meta object.  Returns
684     the index of the new related meta object entry.
685
686     Related meta objects are used when resolving the enumerated type
687     associated with a property, where the enumerated type is in a
688     different class from the property.
689
690     \sa relatedMetaObjectCount(), relatedMetaObject()
691     \sa removeRelatedMetaObject()
692 */
693 #ifdef Q_NO_DATA_RELOCATION
694 int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObjectAccessor &meta)
695 #else
696 int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObject *meta)
697 #endif
698 {
699     Q_ASSERT(meta);
700     int index = d->relatedMetaObjects.size();
701     d->relatedMetaObjects.append(meta);
702     return index;
703 }
704
705 /*!
706     Adds the contents of \a prototype to this meta object builder.
707     This function is useful for cloning the contents of an existing QMetaObject.
708
709     The \a members parameter indicates which members of \a prototype
710     should be added.  The default is AllMembers.
711 */
712 void QMetaObjectBuilder::addMetaObject
713         (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
714 {
715     Q_ASSERT(prototype);
716     int index;
717
718     if ((members & ClassName) != 0)
719         d->className = prototype->className();
720
721     if ((members & SuperClass) != 0)
722         d->superClass = prototype->superClass();
723
724     if ((members & (Methods | Signals | Slots)) != 0) {
725         for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
726             QMetaMethod method = prototype->method(index);
727             if (method.methodType() != QMetaMethod::Signal) {
728                 if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
729                     continue;
730                 if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
731                     continue;
732                 if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
733                     continue;
734             }
735             if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
736                 addMethod(method);
737             } else if (method.methodType() == QMetaMethod::Signal &&
738                        (members & Signals) != 0) {
739                 addMethod(method);
740             } else if (method.methodType() == QMetaMethod::Slot &&
741                        (members & Slots) != 0) {
742                 addMethod(method);
743             }
744         }
745     }
746
747     if ((members & Constructors) != 0) {
748         for (index = 0; index < prototype->constructorCount(); ++index)
749             addConstructor(prototype->constructor(index));
750     }
751
752     if ((members & Properties) != 0) {
753         for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
754             addProperty(prototype->property(index));
755     }
756
757     if ((members & Enumerators) != 0) {
758         for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
759             addEnumerator(prototype->enumerator(index));
760     }
761
762     if ((members & ClassInfos) != 0) {
763         for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
764             QMetaClassInfo ci = prototype->classInfo(index);
765             addClassInfo(ci.name(), ci.value());
766         }
767     }
768
769     if ((members & RelatedMetaObjects) != 0) {
770 #ifdef Q_NO_DATA_RELOCATION
771         const QMetaObjectAccessor *objects = 0;
772 #else
773         const QMetaObject **objects;
774         if (priv(prototype->d.data)->revision < 2) {
775             objects = (const QMetaObject **)(prototype->d.extradata);
776         } else
777 #endif
778         {
779             const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata);
780             if (extra)
781                 objects = extra->objects;
782             else
783                 objects = 0;
784         }
785         if (objects) {
786             while (*objects != 0) {
787                 addRelatedMetaObject(*objects);
788                 ++objects;
789             }
790         }
791     }
792
793     if ((members & StaticMetacall) != 0) {
794         if (priv(prototype->d.data)->revision >= 6) {
795             const QMetaObjectExtraData *extra =
796                 (const QMetaObjectExtraData *)(prototype->d.extradata);
797             if (extra && extra->static_metacall)
798                 setStaticMetacallFunction(extra->static_metacall);
799         }
800     }
801 }
802
803 /*!
804     Returns the method at \a index in this class.
805
806     \sa methodCount(), addMethod(), removeMethod(), indexOfMethod()
807 */
808 QMetaMethodBuilder QMetaObjectBuilder::method(int index) const
809 {
810     if (index >= 0 && index < d->methods.size())
811         return QMetaMethodBuilder(this, index);
812     else
813         return QMetaMethodBuilder();
814 }
815
816 /*!
817     Returns the constructor at \a index in this class.
818
819     \sa methodCount(), addMethod(), removeMethod(), indexOfConstructor()
820 */
821 QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const
822 {
823     if (index >= 0 && index < d->constructors.size())
824         return QMetaMethodBuilder(this, -(index + 1));
825     else
826         return QMetaMethodBuilder();
827 }
828
829 /*!
830     Returns the property at \a index in this class.
831
832     \sa methodCount(), addMethod(), removeMethod(), indexOfProperty()
833 */
834 QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const
835 {
836     if (index >= 0 && index < d->properties.size())
837         return QMetaPropertyBuilder(this, index);
838     else
839         return QMetaPropertyBuilder();
840 }
841
842 /*!
843     Returns the enumerator at \a index in this class.
844
845     \sa enumeratorCount(), addEnumerator(), removeEnumerator()
846     \sa indexOfEnumerator()
847 */
848 QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const
849 {
850     if (index >= 0 && index < d->enumerators.size())
851         return QMetaEnumBuilder(this, index);
852     else
853         return QMetaEnumBuilder();
854 }
855
856 /*!
857     Returns the related meta object at \a index in this class.
858
859     Related meta objects are used when resolving the enumerated type
860     associated with a property, where the enumerated type is in a
861     different class from the property.
862
863     \sa relatedMetaObjectCount(), addRelatedMetaObject()
864     \sa removeRelatedMetaObject()
865 */
866 const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const
867 {
868     if (index >= 0 && index < d->relatedMetaObjects.size())
869 #ifdef Q_NO_DATA_RELOCATION
870         return &((*(d->relatedMetaObjects[index]))());
871 #else
872         return d->relatedMetaObjects[index];
873 #endif
874     else
875         return 0;
876 }
877
878 /*!
879     Returns the name of the item of class information at \a index
880     in this class.
881
882     \sa classInfoCount(), addClassInfo(), classInfoValue(), removeClassInfo()
883     \sa indexOfClassInfo()
884 */
885 QByteArray QMetaObjectBuilder::classInfoName(int index) const
886 {
887     if (index >= 0 && index < d->classInfoNames.size())
888         return d->classInfoNames[index]; 
889     else
890         return QByteArray();
891 }
892
893 /*!
894     Returns the value of the item of class information at \a index
895     in this class.
896
897     \sa classInfoCount(), addClassInfo(), classInfoName(), removeClassInfo()
898     \sa indexOfClassInfo()
899 */
900 QByteArray QMetaObjectBuilder::classInfoValue(int index) const
901 {
902     if (index >= 0 && index < d->classInfoValues.size())
903         return d->classInfoValues[index]; 
904     else
905         return QByteArray();
906 }
907
908 /*!
909     Removes the method at \a index from this class.  The indices of
910     all following methods will be adjusted downwards by 1.  If the
911     method is registered as a notify signal on a property, then the
912     notify signal will be removed from the property.
913
914     \sa methodCount(), addMethod(), method(), indexOfMethod()
915 */
916 void QMetaObjectBuilder::removeMethod(int index)
917 {
918     if (index >= 0 && index < d->methods.size()) {
919         d->methods.removeAt(index);
920         for (int prop = 0; prop < d->properties.size(); ++prop) {
921             // Adjust the indices of property notify signal references.
922             if (d->properties[prop].notifySignal == index) {
923                 d->properties[prop].notifySignal = -1;
924                 d->properties[prop].setFlag(Notify, false);
925             } else if (d->properties[prop].notifySignal > index)
926                 (d->properties[prop].notifySignal)--;
927         }
928     }
929 }
930
931 /*!
932     Removes the constructor at \a index from this class.  The indices of
933     all following constructors will be adjusted downwards by 1.
934
935     \sa constructorCount(), addConstructor(), constructor()
936     \sa indexOfConstructor()
937 */
938 void QMetaObjectBuilder::removeConstructor(int index)
939 {
940     if (index >= 0 && index < d->constructors.size())
941         d->constructors.removeAt(index);
942 }
943
944 /*!
945     Removes the property at \a index from this class.  The indices of
946     all following properties will be adjusted downwards by 1.
947
948     \sa propertyCount(), addProperty(), property(), indexOfProperty()
949 */
950 void QMetaObjectBuilder::removeProperty(int index)
951 {
952     if (index >= 0 && index < d->properties.size())
953         d->properties.removeAt(index);
954 }
955
956 /*!
957     Removes the enumerator at \a index from this class.  The indices of
958     all following enumerators will be adjusted downwards by 1.
959
960     \sa enumertorCount(), addEnumerator(), enumerator()
961     \sa indexOfEnumerator()
962 */
963 void QMetaObjectBuilder::removeEnumerator(int index)
964 {
965     if (index >= 0 && index < d->enumerators.size())
966         d->enumerators.removeAt(index);
967 }
968
969 /*!
970     Removes the item of class information at \a index from this class.
971     The indices of all following items will be adjusted downwards by 1.
972
973     \sa classInfoCount(), addClassInfo(), classInfoName(), classInfoValue()
974     \sa indexOfClassInfo()
975 */
976 void QMetaObjectBuilder::removeClassInfo(int index)
977 {
978     if (index >= 0 && index < d->classInfoNames.size()) {
979         d->classInfoNames.removeAt(index);
980         d->classInfoValues.removeAt(index);
981     }
982 }
983
984 /*!
985     Removes the related meta object at \a index from this class.
986     The indices of all following related meta objects will be adjusted
987     downwards by 1.
988
989     Related meta objects are used when resolving the enumerated type
990     associated with a property, where the enumerated type is in a
991     different class from the property.
992
993     \sa relatedMetaObjectCount(), addRelatedMetaObject()
994     \sa relatedMetaObject()
995 */
996 void QMetaObjectBuilder::removeRelatedMetaObject(int index)
997 {
998     if (index >= 0 && index < d->relatedMetaObjects.size())
999         d->relatedMetaObjects.removeAt(index);
1000 }
1001
1002 /*!
1003     Finds a method with the specified \a signature and returns its index;
1004     otherwise returns -1.  The \a signature will be normalized by this method.
1005
1006     \sa method(), methodCount(), addMethod(), removeMethod()
1007 */
1008 int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature)
1009 {
1010     QByteArray sig = QMetaObject::normalizedSignature(signature);
1011     for (int index = 0; index < d->methods.size(); ++index) {
1012         if (sig == d->methods[index].signature)
1013             return index;
1014     }
1015     return -1;
1016 }
1017
1018 /*!
1019     Finds a signal with the specified \a signature and returns its index;
1020     otherwise returns -1.  The \a signature will be normalized by this method.
1021
1022     \sa indexOfMethod(), indexOfSlot()
1023 */
1024 int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature)
1025 {
1026     QByteArray sig = QMetaObject::normalizedSignature(signature);
1027     for (int index = 0; index < d->methods.size(); ++index) {
1028         if (sig == d->methods[index].signature &&
1029                 d->methods[index].methodType() == QMetaMethod::Signal)
1030             return index;
1031     }
1032     return -1;
1033 }
1034
1035 /*!
1036     Finds a slot with the specified \a signature and returns its index;
1037     otherwise returns -1.  The \a signature will be normalized by this method.
1038
1039     \sa indexOfMethod(), indexOfSignal()
1040 */
1041 int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature)
1042 {
1043     QByteArray sig = QMetaObject::normalizedSignature(signature);
1044     for (int index = 0; index < d->methods.size(); ++index) {
1045         if (sig == d->methods[index].signature &&
1046                 d->methods[index].methodType() == QMetaMethod::Slot)
1047             return index;
1048     }
1049     return -1;
1050 }
1051
1052 /*!
1053     Finds a constructor with the specified \a signature and returns its index;
1054     otherwise returns -1.  The \a signature will be normalized by this method.
1055
1056     \sa constructor(), constructorCount(), addConstructor(), removeConstructor()
1057 */
1058 int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature)
1059 {
1060     QByteArray sig = QMetaObject::normalizedSignature(signature);
1061     for (int index = 0; index < d->constructors.size(); ++index) {
1062         if (sig == d->constructors[index].signature)
1063             return index;
1064     }
1065     return -1;
1066 }
1067
1068 /*!
1069     Finds a property with the specified \a name and returns its index;
1070     otherwise returns -1.
1071
1072     \sa property(), propertyCount(), addProperty(), removeProperty()
1073 */
1074 int QMetaObjectBuilder::indexOfProperty(const QByteArray& name)
1075 {
1076     for (int index = 0; index < d->properties.size(); ++index) {
1077         if (name == d->properties[index].name)
1078             return index;
1079     }
1080     return -1;
1081 }
1082
1083 /*!
1084     Finds an enumerator with the specified \a name and returns its index;
1085     otherwise returns -1.
1086
1087     \sa enumertor(), enumeratorCount(), addEnumerator(), removeEnumerator()
1088 */
1089 int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name)
1090 {
1091     for (int index = 0; index < d->enumerators.size(); ++index) {
1092         if (name == d->enumerators[index].name)
1093             return index;
1094     }
1095     return -1;
1096 }
1097
1098 /*!
1099     Finds an item of class information with the specified \a name and
1100     returns its index; otherwise returns -1.
1101
1102     \sa classInfoName(), classInfoValue(), classInfoCount(), addClassInfo()
1103     \sa removeClassInfo()
1104 */
1105 int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name)
1106 {
1107     for (int index = 0; index < d->classInfoNames.size(); ++index) {
1108         if (name == d->classInfoNames[index])
1109             return index;
1110     }
1111     return -1;
1112 }
1113
1114 // Align on a specific type boundary.
1115 #define ALIGN(size,type)    \
1116     (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)
1117
1118 // Build a string into a QMetaObject representation.  Returns the
1119 // position in the string table where the string was placed.
1120 static int buildString
1121     (char *buf, char *str, int *offset, const QByteArray& value, int empty)
1122 {
1123     if (value.size() == 0 && empty >= 0)
1124         return empty;
1125     if (buf) {
1126         memcpy(str + *offset, value.constData(), value.size());
1127         str[*offset + value.size()] = '\0';
1128     }
1129     int posn = *offset;
1130     *offset += value.size() + 1;
1131     return posn;
1132 }
1133
1134 // Build the parameter array string for a method.
1135 static QByteArray buildParameterNames
1136         (const QByteArray& signature, const QList<QByteArray>& parameterNames)
1137 {
1138     // If the parameter name list is specified, then concatenate them.
1139     if (!parameterNames.isEmpty()) {
1140         QByteArray names;
1141         bool first = true;
1142         foreach (const QByteArray &name, parameterNames) {
1143             if (first)
1144                 first = false;
1145             else
1146                 names += (char)',';
1147             names += name;
1148         }
1149         return names;
1150     }
1151
1152     // Count commas in the signature, excluding those inside template arguments.
1153     int index = signature.indexOf('(');
1154     if (index < 0)
1155         return QByteArray();
1156     ++index;
1157     if (index >= signature.size())
1158         return QByteArray();
1159     if (signature[index] == ')')
1160         return QByteArray();
1161     int count = 1;
1162     int brackets = 0;
1163     while (index < signature.size() && signature[index] != ',') {
1164         char ch = signature[index++];
1165         if (ch == '<')
1166             ++brackets;
1167         else if (ch == '>')
1168             --brackets;
1169         else if (ch == ',' && brackets <= 0)
1170             ++count;
1171     }
1172     return QByteArray(count - 1, ',');
1173 }
1174
1175 // Build a QMetaObject in "buf" based on the information in "d".
1176 // If "buf" is null, then return the number of bytes needed to
1177 // build the QMetaObject.  Returns -1 if the metaobject if 
1178 // relocatable is set, but the metaobject contains extradata.
1179 static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, 
1180                            bool relocatable)
1181 {
1182     int size = 0;
1183     int dataIndex;
1184     int enumIndex;
1185     int index;
1186     bool hasNotifySignals = false;
1187
1188     if (relocatable && 
1189         (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction))
1190         return -1;
1191
1192     // Create the main QMetaObject structure at the start of the buffer.
1193     QMetaObject *meta = reinterpret_cast<QMetaObject *>(buf);
1194     size += sizeof(QMetaObject);
1195     ALIGN(size, int);
1196     if (buf) {
1197         if (!relocatable) meta->d.superdata = d->superClass;
1198         meta->d.extradata = 0;
1199     }
1200
1201     // Populate the QMetaObjectPrivate structure.
1202     QMetaObjectPrivate *pmeta
1203         = reinterpret_cast<QMetaObjectPrivate *>(buf + size);
1204     int pmetaSize = size;
1205     dataIndex = 13;     // Number of fields in the QMetaObjectPrivate.
1206     for (index = 0; index < d->properties.size(); ++index) {
1207         if (d->properties[index].notifySignal != -1) {
1208             hasNotifySignals = true;
1209             break;
1210         }
1211     }
1212     if (buf) {
1213         pmeta->revision = 3;
1214         pmeta->flags = d->flags;
1215         pmeta->className = 0;   // Class name is always the first string.
1216
1217         pmeta->classInfoCount = d->classInfoNames.size();
1218         pmeta->classInfoData = dataIndex;
1219         dataIndex += 2 * d->classInfoNames.size();
1220
1221         pmeta->methodCount = d->methods.size();
1222         pmeta->methodData = dataIndex;
1223         dataIndex += 5 * d->methods.size();
1224
1225         pmeta->propertyCount = d->properties.size();
1226         pmeta->propertyData = dataIndex;
1227         dataIndex += 3 * d->properties.size();
1228         if (hasNotifySignals)
1229             dataIndex += d->properties.size();
1230
1231         pmeta->enumeratorCount = d->enumerators.size();
1232         pmeta->enumeratorData = dataIndex;
1233         dataIndex += 4 * d->enumerators.size();
1234
1235         pmeta->constructorCount = d->constructors.size();
1236         pmeta->constructorData = dataIndex;
1237         dataIndex += 5 * d->constructors.size();
1238     } else {
1239         dataIndex += 2 * d->classInfoNames.size();
1240         dataIndex += 5 * d->methods.size();
1241         dataIndex += 3 * d->properties.size();
1242         if (hasNotifySignals)
1243             dataIndex += d->properties.size();
1244         dataIndex += 4 * d->enumerators.size();
1245         dataIndex += 5 * d->constructors.size();
1246     }
1247
1248     // Allocate space for the enumerator key names and values.
1249     enumIndex = dataIndex;
1250     for (index = 0; index < d->enumerators.size(); ++index) {
1251         QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1252         dataIndex += 2 * enumerator->keys.size();
1253     }
1254
1255     // Zero terminator at the end of the data offset table.
1256     ++dataIndex;
1257
1258     // Find the start of the data and string tables.
1259     int *data = reinterpret_cast<int *>(pmeta);
1260     size += dataIndex * sizeof(int);
1261     char *str = reinterpret_cast<char *>(buf + size);
1262     if (buf) {
1263         if (relocatable) {
1264             meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size);
1265             meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize);
1266         } else {
1267             meta->d.stringdata = str;
1268             meta->d.data = reinterpret_cast<uint *>(data);
1269         }
1270     }
1271
1272     // Reset the current data position to just past the QMetaObjectPrivate.
1273     dataIndex = 13;
1274
1275     // Add the class name to the string table.
1276     int offset = 0;
1277     buildString(buf, str, &offset, d->className, -1);
1278
1279     // Add a common empty string, which is used to indicate "void"
1280     // method returns, empty tag strings, etc.
1281     int empty = buildString(buf, str, &offset, QByteArray(), -1);
1282
1283     // Output the class infos,
1284     for (index = 0; index < d->classInfoNames.size(); ++index) {
1285         int name = buildString(buf, str, &offset, d->classInfoNames[index], empty);
1286         int value = buildString(buf, str, &offset, d->classInfoValues[index], empty);
1287         if (buf) {
1288             data[dataIndex] = name;
1289             data[dataIndex + 1] = value;
1290         }
1291         dataIndex += 2;
1292     }
1293
1294     // Output the methods in the class.
1295     for (index = 0; index < d->methods.size(); ++index) {
1296         QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1297         int sig = buildString(buf, str, &offset, method->signature, empty);
1298         int params;
1299         QByteArray names = buildParameterNames
1300             (method->signature, method->parameterNames);
1301         params = buildString(buf, str, &offset, names, empty);
1302         int ret = buildString(buf, str, &offset, method->returnType, empty);
1303         int tag = buildString(buf, str, &offset, method->tag, empty);
1304         int attrs = method->attributes;
1305         if (buf) {
1306             data[dataIndex]     = sig;
1307             data[dataIndex + 1] = params;
1308             data[dataIndex + 2] = ret;
1309             data[dataIndex + 3] = tag;
1310             data[dataIndex + 4] = attrs;
1311         }
1312         dataIndex += 5;
1313     }
1314
1315     // Output the properties in the class.
1316     for (index = 0; index < d->properties.size(); ++index) {
1317         QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
1318         int name = buildString(buf, str, &offset, prop->name, empty);
1319         int type = buildString(buf, str, &offset, prop->type, empty);
1320         int flags = prop->flags;
1321
1322         if (!isVariantType(prop->type)) {
1323             flags |= EnumOrFlag;
1324         } else {
1325             flags |= qvariant_nameToType(prop->type) << 24;
1326         }
1327
1328         if (buf) {
1329             data[dataIndex]     = name;
1330             data[dataIndex + 1] = type;
1331             data[dataIndex + 2] = flags;
1332         }
1333         dataIndex += 3;
1334     }
1335     if (hasNotifySignals) {
1336         for (index = 0; index < d->properties.size(); ++index) {
1337             QMetaPropertyBuilderPrivate *prop = &(d->properties[index]);
1338             if (buf) {
1339                 if (prop->notifySignal != -1)
1340                     data[dataIndex] = prop->notifySignal;
1341                 else
1342                     data[dataIndex] = 0;
1343             }
1344             ++dataIndex;
1345         }
1346     }
1347
1348     // Output the enumerators in the class.
1349     for (index = 0; index < d->enumerators.size(); ++index) {
1350         QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1351         int name = buildString(buf, str, &offset, enumerator->name, empty);
1352         int isFlag = (int)(enumerator->isFlag);
1353         int count = enumerator->keys.size();
1354         int enumOffset = enumIndex;
1355         if (buf) {
1356             data[dataIndex]     = name;
1357             data[dataIndex + 1] = isFlag;
1358             data[dataIndex + 2] = count;
1359             data[dataIndex + 3] = enumOffset;
1360         }
1361         for (int key = 0; key < count; ++key) {
1362             int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty);
1363             if (buf) {
1364                 data[enumOffset++] = keyIndex;
1365                 data[enumOffset++] = enumerator->values[key];
1366             }
1367         }
1368         dataIndex += 4;
1369         enumIndex += 2 * count;
1370     }
1371
1372     // Output the constructors in the class.
1373     for (index = 0; index < d->constructors.size(); ++index) {
1374         QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1375         int sig = buildString(buf, str, &offset, method->signature, empty);
1376         int params;
1377         QByteArray names = buildParameterNames
1378             (method->signature, method->parameterNames);
1379         params = buildString(buf, str, &offset, names, empty);
1380         int ret = buildString(buf, str, &offset, method->returnType, empty);
1381         int tag = buildString(buf, str, &offset, method->tag, empty);
1382         int attrs = method->attributes;
1383         if (buf) {
1384             data[dataIndex]     = sig;
1385             data[dataIndex + 1] = params;
1386             data[dataIndex + 2] = ret;
1387             data[dataIndex + 3] = tag;
1388             data[dataIndex + 4] = attrs;
1389         }
1390         dataIndex += 5;
1391     }
1392
1393     // One more empty string to act as a terminator.
1394     buildString(buf, str, &offset, QByteArray(), -1);
1395     size += offset;
1396
1397     // Output the zero terminator in the data array.
1398     if (buf)
1399         data[enumIndex] = 0;
1400
1401     // Create the extradata block if we need one.
1402     if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) {
1403         ALIGN(size, QMetaObject **);
1404         ALIGN(size, QMetaObjectBuilder::StaticMetacallFunction);
1405         QMetaObjectExtraData *extra =
1406             reinterpret_cast<QMetaObjectExtraData *>(buf + size);
1407         size += sizeof(QMetaObjectExtraData);
1408         ALIGN(size, QMetaObject *);
1409 #ifdef Q_NO_DATA_RELOCATION
1410         QMetaObjectAccessor *objects =
1411             reinterpret_cast<QMetaObjectAccessor *>(buf + size);
1412 #else
1413         const QMetaObject **objects =
1414             reinterpret_cast<const QMetaObject **>(buf + size);
1415 #endif
1416         if (buf) {
1417             if (d->relatedMetaObjects.size() > 0) {
1418                 extra->objects = objects;
1419                 for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1420                     objects[index] = d->relatedMetaObjects[index];
1421                 objects[index] = 0;
1422             } else {
1423                 extra->objects = 0;
1424             }
1425             extra->static_metacall = d->staticMetacallFunction;
1426             meta->d.extradata = reinterpret_cast<void *>(extra);
1427         }
1428         if (d->relatedMetaObjects.size() > 0)
1429             size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1);
1430     }
1431
1432     // Align the final size and return it.
1433     ALIGN(size, void *);
1434     return size;
1435 }
1436
1437 /*!
1438     Converts this meta object builder into a concrete QMetaObject.
1439     The return value should be deallocated using qFree() once it
1440     is no longer needed.
1441
1442     The returned meta object is a snapshot of the state of the
1443     QMetaObjectBuilder.  Any further modifications to the QMetaObjectBuilder
1444     will not be reflected in previous meta objects returned by
1445     this method.
1446 */
1447 QMetaObject *QMetaObjectBuilder::toMetaObject() const
1448 {
1449     int size = buildMetaObject(d, 0, false);
1450     char *buf = reinterpret_cast<char *>(qMalloc(size));
1451     memset(buf, 0, size);
1452     buildMetaObject(d, buf, false);
1453     return reinterpret_cast<QMetaObject *>(buf);
1454 }
1455
1456 /*
1457     \internal
1458
1459     Converts this meta object builder into relocatable data.  This data can
1460     be stored, copied and later passed to fromRelocatableData() to create a
1461     concrete QMetaObject.
1462
1463     The data is specific to the architecture on which it was created, but is not
1464     specific to the process that created it.  Not all meta object builder's can
1465     be converted to data in this way.  If \a ok is provided, it will be set to
1466     true if the conversion succeeds, and false otherwise.  If a 
1467     staticMetacallFunction() or any relatedMetaObject()'s are specified the
1468     conversion to relocatable data will fail.
1469 */
1470 QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const
1471 {
1472     int size = buildMetaObject(d, 0, true);
1473     if (size == -1) {
1474         if (ok) *ok = false;
1475         return QByteArray();
1476     }
1477
1478     QByteArray data;
1479     data.resize(size);
1480     char *buf = data.data();
1481     memset(buf, 0, size);
1482     buildMetaObject(d, buf, true);
1483     if (ok) *ok = true;
1484     return data;
1485 }
1486
1487 /*
1488     \internal
1489
1490     Sets the \a data returned from toRelocatableData() onto a concrete 
1491     QMetaObject instance, \a output.  As the meta object's super class is not
1492     saved in the relocatable data, it must be passed as \a superClass.
1493 */
1494 void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, 
1495                                              const QMetaObject *superclass, 
1496                                              const QByteArray &data)
1497 {
1498     if (!output)
1499         return;
1500
1501     const char *buf = data.constData();
1502     const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf);
1503
1504     quintptr stringdataOffset = (quintptr)dataMo->d.stringdata;
1505     quintptr dataOffset = (quintptr)dataMo->d.data;
1506
1507     output->d.superdata = superclass;
1508     output->d.stringdata = buf + stringdataOffset;
1509     output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
1510 }
1511
1512 /*!
1513     \typedef QMetaObjectBuilder::StaticMetacallFunction
1514
1515     Typedef for static metacall functions.  The three parameters are
1516     the call type value, the constructor index, and the
1517     array of parameters.
1518 */
1519
1520 /*!
1521     Returns the static metacall function to use to construct objects
1522     of this class.  The default value is null.
1523
1524     \sa setStaticMetacallFunction()
1525 */
1526 QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const
1527 {
1528     return d->staticMetacallFunction;
1529 }
1530
1531 /*!
1532     Sets the static metacall function to use to construct objects
1533     of this class to \a value.  The default value is null.
1534
1535     \sa staticMetacallFunction()
1536 */
1537 void QMetaObjectBuilder::setStaticMetacallFunction
1538         (QMetaObjectBuilder::StaticMetacallFunction value)
1539 {
1540     d->staticMetacallFunction = value;
1541 }
1542
1543 #ifndef QT_NO_DATASTREAM
1544
1545 /*!
1546     Serializes the contents of the meta object builder onto \a stream.
1547
1548     \sa deserialize()
1549 */
1550 void QMetaObjectBuilder::serialize(QDataStream& stream) const
1551 {
1552     int index;
1553
1554     // Write the class and super class names.
1555     stream << d->className;
1556     if (d->superClass)
1557         stream << QByteArray(d->superClass->className());
1558     else
1559         stream << QByteArray();
1560
1561     // Write the counts for each type of class member.
1562     stream << d->classInfoNames.size();
1563     stream << d->methods.size();
1564     stream << d->properties.size();
1565     stream << d->enumerators.size();
1566     stream << d->constructors.size();
1567     stream << d->relatedMetaObjects.size();
1568
1569     // Write the items of class information.
1570     for (index = 0; index < d->classInfoNames.size(); ++index) {
1571         stream << d->classInfoNames[index];
1572         stream << d->classInfoValues[index];
1573     }
1574
1575     // Write the methods.
1576     for (index = 0; index < d->methods.size(); ++index) {
1577         const QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1578         stream << method->signature;
1579         stream << method->returnType;
1580         stream << method->parameterNames;
1581         stream << method->tag;
1582         stream << method->attributes;
1583     }
1584
1585     // Write the properties.
1586     for (index = 0; index < d->properties.size(); ++index) {
1587         const QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1588         stream << property->name;
1589         stream << property->type;
1590         stream << property->flags;
1591         stream << property->notifySignal;
1592     }
1593
1594     // Write the enumerators.
1595     for (index = 0; index < d->enumerators.size(); ++index) {
1596         const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1597         stream << enumerator->name;
1598         stream << enumerator->isFlag;
1599         stream << enumerator->keys;
1600         stream << enumerator->values;
1601     }
1602
1603     // Write the constructors.
1604     for (index = 0; index < d->constructors.size(); ++index) {
1605         const QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1606         stream << method->signature;
1607         stream << method->returnType;
1608         stream << method->parameterNames;
1609         stream << method->tag;
1610         stream << method->attributes;
1611     }
1612
1613     // Write the related meta objects.
1614 #ifdef Q_NO_DATA_RELOCATION
1615     //### What do we do here?
1616 #else
1617     for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
1618         const QMetaObject *meta = d->relatedMetaObjects[index];
1619         stream << QByteArray(meta->className());
1620     }
1621 #endif
1622
1623     // Add an extra empty QByteArray for additional data in future versions.
1624     // This should help maintain backwards compatibility, allowing older
1625     // versions to read newer data.
1626     stream << QByteArray();
1627 }
1628
1629 // Resolve a class name using the name reference map.
1630 static const QMetaObject *resolveClassName
1631         (const QMap<QByteArray, const QMetaObject *>& references,
1632          const QByteArray& name)
1633 {
1634     if (name == QByteArray("QObject"))
1635         return &QObject::staticMetaObject;
1636     else
1637         return references.value(name, 0);
1638 }
1639
1640 /*!
1641     Deserializes a meta object builder from \a stream into
1642     this meta object builder.
1643
1644     The \a references parameter specifies a mapping from class names
1645     to QMetaObject instances for resolving the super class name and
1646     related meta objects in the object that is deserialized.
1647     The meta object for QObject is implicitly added to \a references
1648     and does not need to be supplied.
1649
1650     The QDataStream::status() value on \a stream will be set to
1651     QDataStream::ReadCorruptData if the input data is corrupt.
1652     The status will be set to QDataStream::ReadPastEnd if the
1653     input was exhausted before the full meta object was read.
1654
1655     \sa serialize()
1656 */
1657 void QMetaObjectBuilder::deserialize
1658         (QDataStream& stream,
1659          const QMap<QByteArray, const QMetaObject *>& references)
1660 {
1661     QByteArray name;
1662     const QMetaObject *cl;
1663     int index;
1664
1665     // Clear all members in the builder to their default states.
1666     d->className.clear();
1667     d->superClass = &QObject::staticMetaObject;
1668     d->classInfoNames.clear();
1669     d->classInfoValues.clear();
1670     d->methods.clear();
1671     d->properties.clear();
1672     d->enumerators.clear();
1673     d->constructors.clear();
1674     d->relatedMetaObjects.clear();
1675     d->staticMetacallFunction = 0;
1676
1677     // Read the class and super class names.
1678     stream >> d->className;
1679     stream >> name;
1680     if (name.isEmpty()) {
1681         d->superClass = 0;
1682     } else if ((cl = resolveClassName(references, name)) != 0) {
1683         d->superClass = cl;
1684     } else {
1685         stream.setStatus(QDataStream::ReadCorruptData);
1686         return;
1687     }
1688
1689     // Read the counts for each type of class member.
1690     int classInfoCount, methodCount, propertyCount;
1691     int enumeratorCount, constructorCount, relatedMetaObjectCount;
1692     stream >> classInfoCount;
1693     stream >> methodCount;
1694     stream >> propertyCount;
1695     stream >> enumeratorCount;
1696     stream >> constructorCount;
1697     stream >> relatedMetaObjectCount;
1698     if (classInfoCount < 0 || methodCount < 0 ||
1699         propertyCount < 0 || enumeratorCount < 0 ||
1700         constructorCount < 0 || relatedMetaObjectCount < 0) {
1701         stream.setStatus(QDataStream::ReadCorruptData);
1702         return;
1703     }
1704
1705     // Read the items of class information.
1706     for (index = 0; index < classInfoCount; ++index) {
1707         if (stream.status() != QDataStream::Ok)
1708             return;
1709         QByteArray value;
1710         stream >> name;
1711         stream >> value;
1712         addClassInfo(name, value);
1713     }
1714
1715     // Read the member methods.
1716     for (index = 0; index < methodCount; ++index) {
1717         if (stream.status() != QDataStream::Ok)
1718             return;
1719         stream >> name;
1720         addMethod(name);
1721         QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1722         stream >> method->returnType;
1723         stream >> method->parameterNames;
1724         stream >> method->tag;
1725         stream >> method->attributes;
1726         if (method->methodType() == QMetaMethod::Constructor) {
1727             // Cannot add a constructor in this set of methods.
1728             stream.setStatus(QDataStream::ReadCorruptData);
1729             return;
1730         }
1731     }
1732
1733     // Read the properties.
1734     for (index = 0; index < propertyCount; ++index) {
1735         if (stream.status() != QDataStream::Ok)
1736             return;
1737         QByteArray type;
1738         stream >> name;
1739         stream >> type;
1740         addProperty(name, type);
1741         QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1742         stream >> property->flags;
1743         stream >> property->notifySignal;
1744         if (property->notifySignal < -1 ||
1745             property->notifySignal >= d->methods.size()) {
1746             // Notify signal method index is out of range.
1747             stream.setStatus(QDataStream::ReadCorruptData);
1748             return;
1749         }
1750         if (property->notifySignal >= 0 &&
1751             d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) {
1752             // Notify signal method index does not refer to a signal.
1753             stream.setStatus(QDataStream::ReadCorruptData);
1754             return;
1755         }
1756     }
1757
1758     // Read the enumerators.
1759     for (index = 0; index < enumeratorCount; ++index) {
1760         if (stream.status() != QDataStream::Ok)
1761             return;
1762         stream >> name;
1763         addEnumerator(name);
1764         QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1765         stream >> enumerator->isFlag;
1766         stream >> enumerator->keys;
1767         stream >> enumerator->values;
1768         if (enumerator->keys.size() != enumerator->values.size()) {
1769             // Mismatch between number of keys and number of values.
1770             stream.setStatus(QDataStream::ReadCorruptData);
1771             return;
1772         }
1773     }
1774
1775     // Read the constructor methods.
1776     for (index = 0; index < constructorCount; ++index) {
1777         if (stream.status() != QDataStream::Ok)
1778             return;
1779         stream >> name;
1780         addConstructor(name);
1781         QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1782         stream >> method->returnType;
1783         stream >> method->parameterNames;
1784         stream >> method->tag;
1785         stream >> method->attributes;
1786         if (method->methodType() != QMetaMethod::Constructor) {
1787             // The type must be Constructor.
1788             stream.setStatus(QDataStream::ReadCorruptData);
1789             return;
1790         }
1791     }
1792
1793     // Read the related meta objects.
1794 #ifdef Q_NO_DATA_RELOCATION
1795     //### What do we do here
1796 #else
1797     for (index = 0; index < relatedMetaObjectCount; ++index) {
1798         if (stream.status() != QDataStream::Ok)
1799             return;
1800         stream >> name;
1801         cl = resolveClassName(references, name);
1802         if (!cl) {
1803             stream.setStatus(QDataStream::ReadCorruptData);
1804             return;
1805         }
1806         addRelatedMetaObject(cl);
1807     }
1808 #endif
1809
1810     // Read the extra data block, which is reserved for future use.
1811     stream >> name;
1812 }
1813
1814 #endif // !QT_NO_DATASTREAM
1815
1816 /*!
1817     \class QMetaMethodBuilder
1818     \internal
1819     \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder.
1820 */
1821
1822 QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const
1823 {
1824     // Positive indices indicate methods, negative indices indicate constructors.
1825     if (_mobj && _index >= 0 && _index < _mobj->d->methods.size())
1826         return &(_mobj->d->methods[_index]);
1827     else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size())
1828         return &(_mobj->d->constructors[(-_index) - 1]);
1829     else
1830         return 0;
1831 }
1832
1833 /*!
1834     \fn QMetaMethodBuilder::QMetaMethodBuilder()
1835     \internal
1836 */
1837
1838 /*!
1839     Returns the index of this method within its QMetaObjectBuilder.
1840 */
1841 int QMetaMethodBuilder::index() const
1842 {
1843     if (_index >= 0)
1844         return _index;          // Method, signal, or slot
1845     else
1846         return (-_index) - 1;   // Constructor
1847 }
1848
1849 /*!
1850     Returns the type of this method (signal, slot, method, or constructor).
1851 */
1852 QMetaMethod::MethodType QMetaMethodBuilder::methodType() const
1853 {
1854     QMetaMethodBuilderPrivate *d = d_func();
1855     if (d)
1856         return d->methodType();
1857     else
1858         return QMetaMethod::Method;
1859 }
1860
1861 /*!
1862     Returns the signature of this method.
1863
1864     \sa parameterNames(), returnType()
1865 */
1866 QByteArray QMetaMethodBuilder::signature() const
1867 {
1868     QMetaMethodBuilderPrivate *d = d_func();
1869     if (d)
1870         return d->signature;
1871     else
1872         return QByteArray();
1873 }
1874
1875 /*!
1876     Returns the return type for this method; empty if the method's
1877     return type is \c{void}.
1878
1879     \sa setReturnType(), signature()
1880 */
1881 QByteArray QMetaMethodBuilder::returnType() const
1882 {
1883     QMetaMethodBuilderPrivate *d = d_func();
1884     if (d)
1885         return d->returnType;
1886     else
1887         return QByteArray();
1888 }
1889
1890 /*!
1891     Sets the return type for this method to \a value.  If \a value
1892     is empty, then the method's return type is \c{void}.  The \a value
1893     will be normalized before it is added to the method.
1894
1895     \sa returnType(), signature()
1896 */
1897 void QMetaMethodBuilder::setReturnType(const QByteArray& value)
1898 {
1899     QMetaMethodBuilderPrivate *d = d_func();
1900     if (d)
1901         d->returnType = QMetaObject::normalizedType(value);
1902 }
1903
1904 /*!
1905     Returns the list of parameter names for this method.
1906
1907     \sa setParameterNames()
1908 */
1909 QList<QByteArray> QMetaMethodBuilder::parameterNames() const
1910 {
1911     QMetaMethodBuilderPrivate *d = d_func();
1912     if (d)
1913         return d->parameterNames;
1914     else
1915         return QList<QByteArray>();
1916 }
1917
1918 /*!
1919     Sets the list of parameter names for this method to \a value.
1920
1921     \sa parameterNames()
1922 */
1923 void QMetaMethodBuilder::setParameterNames(const QList<QByteArray>& value)
1924 {
1925     QMetaMethodBuilderPrivate *d = d_func();
1926     if (d)
1927         d->parameterNames = value;
1928 }
1929
1930 /*!
1931     Returns the tag associated with this method.
1932
1933     \sa setTag()
1934 */
1935 QByteArray QMetaMethodBuilder::tag() const
1936 {
1937     QMetaMethodBuilderPrivate *d = d_func();
1938     if (d)
1939         return d->tag;
1940     else
1941         return QByteArray();
1942 }
1943
1944 /*!
1945     Sets the tag associated with this method to \a value.
1946
1947     \sa setTag()
1948 */
1949 void QMetaMethodBuilder::setTag(const QByteArray& value)
1950 {
1951     QMetaMethodBuilderPrivate *d = d_func();
1952     if (d)
1953         d->tag = value;
1954 }
1955
1956 /*!
1957     Returns the access specification of this method (private, protected,
1958     or public).  The default value is QMetaMethod::Public for methods,
1959     slots, and constructors.  The default value is QMetaMethod::Protected
1960     for signals.
1961
1962     \sa setAccess()
1963 */
1964 QMetaMethod::Access QMetaMethodBuilder::access() const
1965 {
1966     QMetaMethodBuilderPrivate *d = d_func();
1967     if (d)
1968         return d->access();
1969     else
1970         return QMetaMethod::Public;
1971 }
1972
1973 /*!
1974     Sets the access specification of this method (private, protected,
1975     or public) to \a value.  If the method is a signal, this function
1976     will be ignored.
1977
1978     \sa access()
1979 */
1980 void QMetaMethodBuilder::setAccess(QMetaMethod::Access value)
1981 {
1982     QMetaMethodBuilderPrivate *d = d_func();
1983     if (d && d->methodType() != QMetaMethod::Signal)
1984         d->setAccess(value);
1985 }
1986
1987 /*!
1988     Returns the additional attributes for this method.
1989
1990     \sa setAttributes()
1991 */
1992 int QMetaMethodBuilder::attributes() const
1993 {
1994     QMetaMethodBuilderPrivate *d = d_func();
1995     if (d)
1996         return (d->attributes >> 4);
1997     else
1998         return 0;
1999 }
2000
2001 /*!
2002     Sets the additional attributes for this method to \a value.
2003
2004     \sa attributes()
2005 */
2006 void QMetaMethodBuilder::setAttributes(int value)
2007 {
2008     QMetaMethodBuilderPrivate *d = d_func();
2009     if (d)
2010         d->attributes = ((d->attributes & 0x0f) | (value << 4));
2011 }
2012
2013 /*!
2014     \class QMetaPropertyBuilder
2015     \internal
2016     \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder.
2017 */
2018
2019 QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const
2020 {
2021     if (_mobj && _index >= 0 && _index < _mobj->d->properties.size())
2022         return &(_mobj->d->properties[_index]);
2023     else
2024         return 0;
2025 }
2026
2027 /*!
2028     \fn QMetaPropertyBuilder::QMetaPropertyBuilder()
2029     \internal
2030 */
2031
2032 /*!
2033     \fn int QMetaPropertyBuilder::index() const
2034
2035     Returns the index of this property within its QMetaObjectBuilder.
2036 */
2037
2038 /*!
2039     Returns the name associated with this property.
2040
2041     \sa type()
2042 */
2043 QByteArray QMetaPropertyBuilder::name() const
2044 {
2045     QMetaPropertyBuilderPrivate *d = d_func();
2046     if (d)
2047         return d->name;
2048     else
2049         return QByteArray();
2050 }
2051
2052 /*!
2053     Returns the type associated with this property.
2054
2055     \sa name()
2056 */
2057 QByteArray QMetaPropertyBuilder::type() const
2058 {
2059     QMetaPropertyBuilderPrivate *d = d_func();
2060     if (d)
2061         return d->type;
2062     else
2063         return QByteArray();
2064 }
2065
2066 /*!
2067     Returns true if this property has a notify signal; false otherwise.
2068
2069     \sa notifySignal(), setNotifySignal(), removeNotifySignal()
2070 */
2071 bool QMetaPropertyBuilder::hasNotifySignal() const
2072 {
2073     QMetaPropertyBuilderPrivate *d = d_func();
2074     if (d)
2075         return d->flag(Notify);
2076     else
2077         return false;
2078 }
2079
2080 /*!
2081     Returns the notify signal associated with this property.
2082
2083     \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal()
2084 */
2085 QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const
2086 {
2087     QMetaPropertyBuilderPrivate *d = d_func();
2088     if (d && d->notifySignal >= 0)
2089         return QMetaMethodBuilder(_mobj, d->notifySignal);
2090     else
2091         return QMetaMethodBuilder();
2092 }
2093
2094 /*!
2095     Sets the notify signal associated with this property to \a value.
2096
2097     \sa hasNotifySignal(), notifySignal(), removeNotifySignal()
2098 */
2099 void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
2100 {
2101     QMetaPropertyBuilderPrivate *d = d_func();
2102     if (d) {
2103         if (value._mobj) {
2104             d->notifySignal = value._index;
2105             d->setFlag(Notify, true);
2106         } else {
2107             d->notifySignal = -1;
2108             d->setFlag(Notify, false);
2109         }
2110     }
2111 }
2112
2113 /*!
2114     Removes the notify signal from this property.
2115
2116     \sa hasNotifySignal(), notifySignal(), setNotifySignal()
2117 */
2118 void QMetaPropertyBuilder::removeNotifySignal()
2119 {
2120     QMetaPropertyBuilderPrivate *d = d_func();
2121     if (d) {
2122         d->notifySignal = -1;
2123         d->setFlag(Notify, false);
2124     }
2125 }
2126
2127 /*!
2128     Returns true if this property is readable; otherwise returns false.
2129     The default value is true.
2130
2131     \sa setReadable(), isWritable()
2132 */
2133 bool QMetaPropertyBuilder::isReadable() const
2134 {
2135     QMetaPropertyBuilderPrivate *d = d_func();
2136     if (d)
2137         return d->flag(Readable);
2138     else
2139         return false;
2140 }
2141
2142 /*!
2143     Returns true if this property is writable; otherwise returns false.
2144     The default value is true.
2145
2146     \sa setWritable(), isReadable()
2147 */
2148 bool QMetaPropertyBuilder::isWritable() const
2149 {
2150     QMetaPropertyBuilderPrivate *d = d_func();
2151     if (d)
2152         return d->flag(Writable);
2153     else
2154         return false;
2155 }
2156
2157 /*!
2158     Returns true if this property can be reset to a default value; otherwise
2159     returns false.  The default value is false.
2160
2161     \sa setResettable()
2162 */
2163 bool QMetaPropertyBuilder::isResettable() const
2164 {
2165     QMetaPropertyBuilderPrivate *d = d_func();
2166     if (d)
2167         return d->flag(Resettable);
2168     else
2169         return false;
2170 }
2171
2172 /*!
2173     Returns true if this property is designable; otherwise returns false.
2174     This default value is false.
2175
2176     \sa setDesignable(), isScriptable(), isStored()
2177 */
2178 bool QMetaPropertyBuilder::isDesignable() const
2179 {
2180     QMetaPropertyBuilderPrivate *d = d_func();
2181     if (d)
2182         return d->flag(Designable);
2183     else
2184         return false;
2185 }
2186
2187 /*!
2188     Returns true if the property is scriptable; otherwise returns false.
2189     This default value is true.
2190
2191     \sa setScriptable(), isDesignable(), isStored()
2192 */
2193 bool QMetaPropertyBuilder::isScriptable() const
2194 {
2195     QMetaPropertyBuilderPrivate *d = d_func();
2196     if (d)
2197         return d->flag(Scriptable);
2198     else
2199         return false;
2200 }
2201
2202 /*!
2203     Returns true if the property is stored; otherwise returns false.
2204     This default value is false.
2205
2206     \sa setStored(), isDesignable(), isScriptable()
2207 */
2208 bool QMetaPropertyBuilder::isStored() const
2209 {
2210     QMetaPropertyBuilderPrivate *d = d_func();
2211     if (d)
2212         return d->flag(Stored);
2213     else
2214         return false;
2215 }
2216
2217 /*!
2218     Returns true if the property is editable; otherwise returns false.
2219     This default value is false.
2220
2221     \sa setEditable(), isDesignable(), isScriptable(), isStored()
2222 */
2223 bool QMetaPropertyBuilder::isEditable() const
2224 {
2225     QMetaPropertyBuilderPrivate *d = d_func();
2226     if (d)
2227         return d->flag(Editable);
2228     else
2229         return false;
2230 }
2231
2232 /*!
2233     Returns true if this property is designated as the \c USER
2234     property, i.e., the one that the user can edit or that is
2235     significant in some other way.  Otherwise it returns
2236     false.  This default value is false.
2237
2238     \sa setUser(), isDesignable(), isScriptable()
2239 */
2240 bool QMetaPropertyBuilder::isUser() const
2241 {
2242     QMetaPropertyBuilderPrivate *d = d_func();
2243     if (d)
2244         return d->flag(User);
2245     else
2246         return false;
2247 }
2248
2249 /*!
2250     Returns true if the property has a C++ setter function that
2251     follows Qt's standard "name" / "setName" pattern. Designer and uic
2252     query hasStdCppSet() in order to avoid expensive
2253     QObject::setProperty() calls. All properties in Qt [should] follow
2254     this pattern.  The default value is false.
2255
2256     \sa setStdCppSet()
2257 */
2258 bool QMetaPropertyBuilder::hasStdCppSet() const
2259 {
2260     QMetaPropertyBuilderPrivate *d = d_func();
2261     if (d)
2262         return d->flag(StdCppSet);
2263     else
2264         return false;
2265 }
2266
2267 /*!
2268     Returns true if the property is an enumerator or flag type;
2269     otherwise returns false.  This default value is false.
2270
2271     \sa setEnumOrFlag()
2272 */
2273 bool QMetaPropertyBuilder::isEnumOrFlag() const
2274 {
2275     QMetaPropertyBuilderPrivate *d = d_func();
2276     if (d)
2277         return d->flag(EnumOrFlag);
2278     else
2279         return false;
2280 }
2281
2282 /*!
2283     Sets this property to readable if \a value is true.
2284
2285     \sa isReadable(), setWritable()
2286 */
2287 void QMetaPropertyBuilder::setReadable(bool value)
2288 {
2289     QMetaPropertyBuilderPrivate *d = d_func();
2290     if (d)
2291         d->setFlag(Readable, value);
2292 }
2293
2294 /*!
2295     Sets this property to writable if \a value is true.
2296
2297     \sa isWritable(), setReadable()
2298 */
2299 void QMetaPropertyBuilder::setWritable(bool value)
2300 {
2301     QMetaPropertyBuilderPrivate *d = d_func();
2302     if (d)
2303         d->setFlag(Writable, value);
2304 }
2305
2306 /*!
2307     Sets this property to resettable if \a value is true.
2308
2309     \sa isResettable()
2310 */
2311 void QMetaPropertyBuilder::setResettable(bool value)
2312 {
2313     QMetaPropertyBuilderPrivate *d = d_func();
2314     if (d)
2315         d->setFlag(Resettable, value);
2316 }
2317
2318 /*!
2319     Sets this property to designable if \a value is true.
2320
2321     \sa isDesignable(), setScriptable(), setStored()
2322 */
2323 void QMetaPropertyBuilder::setDesignable(bool value)
2324 {
2325     QMetaPropertyBuilderPrivate *d = d_func();
2326     if (d)
2327         d->setFlag(Designable, value);
2328 }
2329
2330 /*!
2331     Sets this property to scriptable if \a value is true.
2332
2333     \sa isScriptable(), setDesignable(), setStored()
2334 */
2335 void QMetaPropertyBuilder::setScriptable(bool value)
2336 {
2337     QMetaPropertyBuilderPrivate *d = d_func();
2338     if (d)
2339         d->setFlag(Scriptable, value);
2340 }
2341
2342 /*!
2343     Sets this property to storable if \a value is true.
2344
2345     \sa isStored(), setDesignable(), setScriptable()
2346 */
2347 void QMetaPropertyBuilder::setStored(bool value)
2348 {
2349     QMetaPropertyBuilderPrivate *d = d_func();
2350     if (d)
2351         d->setFlag(Stored, value);
2352 }
2353
2354 /*!
2355     Sets this property to editable if \a value is true.
2356
2357     \sa isEditable(), setDesignable(), setScriptable(), setStored()
2358 */
2359 void QMetaPropertyBuilder::setEditable(bool value)
2360 {
2361     QMetaPropertyBuilderPrivate *d = d_func();
2362     if (d)
2363         d->setFlag(Editable, value);
2364 }
2365
2366 /*!
2367     Sets the \c USER flag on this property to \a value.
2368
2369     \sa isUser(), setDesignable(), setScriptable()
2370 */
2371 void QMetaPropertyBuilder::setUser(bool value)
2372 {
2373     QMetaPropertyBuilderPrivate *d = d_func();
2374     if (d)
2375         d->setFlag(User, value);
2376 }
2377
2378 /*!
2379     Sets the C++ setter flag on this property to \a value, which is
2380     true if the property has a C++ setter function that follows Qt's
2381     standard "name" / "setName" pattern.
2382
2383     \sa hasStdCppSet()
2384 */
2385 void QMetaPropertyBuilder::setStdCppSet(bool value)
2386 {
2387     QMetaPropertyBuilderPrivate *d = d_func();
2388     if (d)
2389         d->setFlag(StdCppSet, value);
2390 }
2391
2392 /*!
2393     Sets this property to be of an enumerator or flag type if
2394     \a value is true.
2395
2396     \sa isEnumOrFlag()
2397 */
2398 void QMetaPropertyBuilder::setEnumOrFlag(bool value)
2399 {
2400     QMetaPropertyBuilderPrivate *d = d_func();
2401     if (d)
2402         d->setFlag(EnumOrFlag, value);
2403 }
2404
2405 /*!
2406     \class QMetaEnumBuilder
2407     \internal
2408     \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder.
2409 */
2410
2411 QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const
2412 {
2413     if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size())
2414         return &(_mobj->d->enumerators[_index]);
2415     else
2416         return 0;
2417 }
2418
2419 /*!
2420     \fn QMetaEnumBuilder::QMetaEnumBuilder()
2421     \internal
2422 */
2423
2424 /*!
2425     \fn int QMetaEnumBuilder::index() const
2426
2427     Returns the index of this enumerator within its QMetaObjectBuilder.
2428 */
2429
2430 /*!
2431     Returns the name of the enumerator (without the scope).
2432 */
2433 QByteArray QMetaEnumBuilder::name() const
2434 {
2435     QMetaEnumBuilderPrivate *d = d_func();
2436     if (d)
2437         return d->name;
2438     else
2439         return QByteArray();
2440 }
2441
2442 /*!
2443     Returns true if this enumerator is used as a flag; otherwise returns
2444     false.
2445
2446     \sa setIsFlag()
2447 */
2448 bool QMetaEnumBuilder::isFlag() const
2449 {
2450     QMetaEnumBuilderPrivate *d = d_func();
2451     if (d)
2452         return d->isFlag;
2453     else
2454         return false;
2455 }
2456
2457 /*!
2458     Sets this enumerator to be used as a flag if \a value is true.
2459
2460     \sa isFlag()
2461 */
2462 void QMetaEnumBuilder::setIsFlag(bool value)
2463 {
2464     QMetaEnumBuilderPrivate *d = d_func();
2465     if (d)
2466         d->isFlag = value;
2467 }
2468
2469 /*!
2470     Returns the number of keys.
2471
2472     \sa key(), addKey()
2473 */
2474 int QMetaEnumBuilder::keyCount() const
2475 {
2476     QMetaEnumBuilderPrivate *d = d_func();
2477     if (d)
2478         return d->keys.size();
2479     else
2480         return 0;
2481 }
2482
2483 /*!
2484     Returns the key with the given \a index, or an empty QByteArray
2485     if no such key exists.
2486
2487     \sa keyCount(), addKey(), value()
2488 */
2489 QByteArray QMetaEnumBuilder::key(int index) const
2490 {
2491     QMetaEnumBuilderPrivate *d = d_func();
2492     if (d && index >= 0 && index < d->keys.size())
2493         return d->keys[index];
2494     else
2495         return QByteArray();
2496 }
2497
2498 /*!
2499     Returns the value with the given \a index; or returns -1 if there
2500     is no such value.
2501
2502     \sa keyCount(), addKey(), key()
2503 */
2504 int QMetaEnumBuilder::value(int index) const
2505 {
2506     QMetaEnumBuilderPrivate *d = d_func();
2507     if (d && index >= 0 && index < d->keys.size())
2508         return d->values[index];
2509     else
2510         return -1;
2511 }
2512
2513 /*!
2514     Adds a new key called \a name to this enumerator, associated
2515     with \a value.  Returns the index of the new key.
2516
2517     \sa keyCount(), key(), value(), removeKey()
2518 */
2519 int QMetaEnumBuilder::addKey(const QByteArray& name, int value)
2520 {
2521     QMetaEnumBuilderPrivate *d = d_func();
2522     if (d) {
2523         int index = d->keys.size();
2524         d->keys += name;
2525         d->values += value;
2526         return index;
2527     } else {
2528         return -1;
2529     }
2530 }
2531
2532 /*!
2533     Removes the key at \a index from this enumerator.
2534
2535     \sa addKey()
2536 */
2537 void QMetaEnumBuilder::removeKey(int index)
2538 {
2539     QMetaEnumBuilderPrivate *d = d_func();
2540     if (d && index >= 0 && index < d->keys.size()) {
2541         d->keys.removeAt(index);
2542         d->values.removeAt(index);
2543     }
2544 }
2545
2546 QT_END_NAMESPACE