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