Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtdeclarative
[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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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     memset(buf, 0, size);
1456     buildMetaObject(d, buf, false);
1457     return reinterpret_cast<QMetaObject *>(buf);
1458 }
1459
1460 /*
1461     \internal
1462
1463     Converts this meta object builder into relocatable data.  This data can
1464     be stored, copied and later passed to fromRelocatableData() to create a
1465     concrete QMetaObject.
1466
1467     The data is specific to the architecture on which it was created, but is not
1468     specific to the process that created it.  Not all meta object builder's can
1469     be converted to data in this way.  If \a ok is provided, it will be set to
1470     true if the conversion succeeds, and false otherwise.  If a 
1471     staticMetacallFunction() or any relatedMetaObject()'s are specified the
1472     conversion to relocatable data will fail.
1473 */
1474 QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const
1475 {
1476     int size = buildMetaObject(d, 0, true);
1477     if (size == -1) {
1478         if (ok) *ok = false;
1479         return QByteArray();
1480     }
1481
1482     QByteArray data;
1483     data.resize(size);
1484     char *buf = data.data();
1485     memset(buf, 0, size);
1486     buildMetaObject(d, buf, true);
1487     if (ok) *ok = true;
1488     return data;
1489 }
1490
1491 /*
1492     \internal
1493
1494     Sets the \a data returned from toRelocatableData() onto a concrete 
1495     QMetaObject instance, \a output.  As the meta object's super class is not
1496     saved in the relocatable data, it must be passed as \a superClass.
1497 */
1498 void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, 
1499                                              const QMetaObject *superclass, 
1500                                              const QByteArray &data)
1501 {
1502     if (!output)
1503         return;
1504
1505     const char *buf = data.constData();
1506     const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf);
1507
1508     quintptr stringdataOffset = (quintptr)dataMo->d.stringdata;
1509     quintptr dataOffset = (quintptr)dataMo->d.data;
1510
1511     output->d.superdata = superclass;
1512     output->d.stringdata = buf + stringdataOffset;
1513     output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
1514 }
1515
1516 /*!
1517     \typedef QMetaObjectBuilder::StaticMetacallFunction
1518
1519     Typedef for static metacall functions.  The three parameters are
1520     the call type value, the constructor index, and the
1521     array of parameters.
1522 */
1523
1524 /*!
1525     Returns the static metacall function to use to construct objects
1526     of this class.  The default value is null.
1527
1528     \sa setStaticMetacallFunction()
1529 */
1530 QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const
1531 {
1532     return d->staticMetacallFunction;
1533 }
1534
1535 /*!
1536     Sets the static metacall function to use to construct objects
1537     of this class to \a value.  The default value is null.
1538
1539     \sa staticMetacallFunction()
1540 */
1541 void QMetaObjectBuilder::setStaticMetacallFunction
1542         (QMetaObjectBuilder::StaticMetacallFunction value)
1543 {
1544     d->staticMetacallFunction = value;
1545 }
1546
1547 #ifndef QT_NO_DATASTREAM
1548
1549 /*!
1550     Serializes the contents of the meta object builder onto \a stream.
1551
1552     \sa deserialize()
1553 */
1554 void QMetaObjectBuilder::serialize(QDataStream& stream) const
1555 {
1556     int index;
1557
1558     // Write the class and super class names.
1559     stream << d->className;
1560     if (d->superClass)
1561         stream << QByteArray(d->superClass->className());
1562     else
1563         stream << QByteArray();
1564
1565     // Write the counts for each type of class member.
1566     stream << d->classInfoNames.size();
1567     stream << d->methods.size();
1568     stream << d->properties.size();
1569     stream << d->enumerators.size();
1570     stream << d->constructors.size();
1571     stream << d->relatedMetaObjects.size();
1572
1573     // Write the items of class information.
1574     for (index = 0; index < d->classInfoNames.size(); ++index) {
1575         stream << d->classInfoNames[index];
1576         stream << d->classInfoValues[index];
1577     }
1578
1579     // Write the methods.
1580     for (index = 0; index < d->methods.size(); ++index) {
1581         const QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1582         stream << method->signature;
1583         stream << method->returnType;
1584         stream << method->parameterNames;
1585         stream << method->tag;
1586         stream << method->attributes;
1587     }
1588
1589     // Write the properties.
1590     for (index = 0; index < d->properties.size(); ++index) {
1591         const QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1592         stream << property->name;
1593         stream << property->type;
1594         stream << property->flags;
1595         stream << property->notifySignal;
1596     }
1597
1598     // Write the enumerators.
1599     for (index = 0; index < d->enumerators.size(); ++index) {
1600         const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1601         stream << enumerator->name;
1602         stream << enumerator->isFlag;
1603         stream << enumerator->keys;
1604         stream << enumerator->values;
1605     }
1606
1607     // Write the constructors.
1608     for (index = 0; index < d->constructors.size(); ++index) {
1609         const QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1610         stream << method->signature;
1611         stream << method->returnType;
1612         stream << method->parameterNames;
1613         stream << method->tag;
1614         stream << method->attributes;
1615     }
1616
1617     // Write the related meta objects.
1618 #ifdef Q_NO_DATA_RELOCATION
1619     //### What do we do here?
1620 #else
1621     for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
1622         const QMetaObject *meta = d->relatedMetaObjects[index];
1623         stream << QByteArray(meta->className());
1624     }
1625 #endif
1626
1627     // Add an extra empty QByteArray for additional data in future versions.
1628     // This should help maintain backwards compatibility, allowing older
1629     // versions to read newer data.
1630     stream << QByteArray();
1631 }
1632
1633 // Resolve a class name using the name reference map.
1634 static const QMetaObject *resolveClassName
1635         (const QMap<QByteArray, const QMetaObject *>& references,
1636          const QByteArray& name)
1637 {
1638     if (name == QByteArray("QObject"))
1639         return &QObject::staticMetaObject;
1640     else
1641         return references.value(name, 0);
1642 }
1643
1644 /*!
1645     Deserializes a meta object builder from \a stream into
1646     this meta object builder.
1647
1648     The \a references parameter specifies a mapping from class names
1649     to QMetaObject instances for resolving the super class name and
1650     related meta objects in the object that is deserialized.
1651     The meta object for QObject is implicitly added to \a references
1652     and does not need to be supplied.
1653
1654     The QDataStream::status() value on \a stream will be set to
1655     QDataStream::ReadCorruptData if the input data is corrupt.
1656     The status will be set to QDataStream::ReadPastEnd if the
1657     input was exhausted before the full meta object was read.
1658
1659     \sa serialize()
1660 */
1661 void QMetaObjectBuilder::deserialize
1662         (QDataStream& stream,
1663          const QMap<QByteArray, const QMetaObject *>& references)
1664 {
1665     QByteArray name;
1666     const QMetaObject *cl;
1667     int index;
1668
1669     // Clear all members in the builder to their default states.
1670     d->className.clear();
1671     d->superClass = &QObject::staticMetaObject;
1672     d->classInfoNames.clear();
1673     d->classInfoValues.clear();
1674     d->methods.clear();
1675     d->properties.clear();
1676     d->enumerators.clear();
1677     d->constructors.clear();
1678     d->relatedMetaObjects.clear();
1679     d->staticMetacallFunction = 0;
1680
1681     // Read the class and super class names.
1682     stream >> d->className;
1683     stream >> name;
1684     if (name.isEmpty()) {
1685         d->superClass = 0;
1686     } else if ((cl = resolveClassName(references, name)) != 0) {
1687         d->superClass = cl;
1688     } else {
1689         stream.setStatus(QDataStream::ReadCorruptData);
1690         return;
1691     }
1692
1693     // Read the counts for each type of class member.
1694     int classInfoCount, methodCount, propertyCount;
1695     int enumeratorCount, constructorCount, relatedMetaObjectCount;
1696     stream >> classInfoCount;
1697     stream >> methodCount;
1698     stream >> propertyCount;
1699     stream >> enumeratorCount;
1700     stream >> constructorCount;
1701     stream >> relatedMetaObjectCount;
1702     if (classInfoCount < 0 || methodCount < 0 ||
1703         propertyCount < 0 || enumeratorCount < 0 ||
1704         constructorCount < 0 || relatedMetaObjectCount < 0) {
1705         stream.setStatus(QDataStream::ReadCorruptData);
1706         return;
1707     }
1708
1709     // Read the items of class information.
1710     for (index = 0; index < classInfoCount; ++index) {
1711         if (stream.status() != QDataStream::Ok)
1712             return;
1713         QByteArray value;
1714         stream >> name;
1715         stream >> value;
1716         addClassInfo(name, value);
1717     }
1718
1719     // Read the member methods.
1720     for (index = 0; index < methodCount; ++index) {
1721         if (stream.status() != QDataStream::Ok)
1722             return;
1723         stream >> name;
1724         addMethod(name);
1725         QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1726         stream >> method->returnType;
1727         stream >> method->parameterNames;
1728         stream >> method->tag;
1729         stream >> method->attributes;
1730         if (method->methodType() == QMetaMethod::Constructor) {
1731             // Cannot add a constructor in this set of methods.
1732             stream.setStatus(QDataStream::ReadCorruptData);
1733             return;
1734         }
1735     }
1736
1737     // Read the properties.
1738     for (index = 0; index < propertyCount; ++index) {
1739         if (stream.status() != QDataStream::Ok)
1740             return;
1741         QByteArray type;
1742         stream >> name;
1743         stream >> type;
1744         addProperty(name, type);
1745         QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1746         stream >> property->flags;
1747         stream >> property->notifySignal;
1748         if (property->notifySignal < -1 ||
1749             property->notifySignal >= d->methods.size()) {
1750             // Notify signal method index is out of range.
1751             stream.setStatus(QDataStream::ReadCorruptData);
1752             return;
1753         }
1754         if (property->notifySignal >= 0 &&
1755             d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) {
1756             // Notify signal method index does not refer to a signal.
1757             stream.setStatus(QDataStream::ReadCorruptData);
1758             return;
1759         }
1760     }
1761
1762     // Read the enumerators.
1763     for (index = 0; index < enumeratorCount; ++index) {
1764         if (stream.status() != QDataStream::Ok)
1765             return;
1766         stream >> name;
1767         addEnumerator(name);
1768         QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1769         stream >> enumerator->isFlag;
1770         stream >> enumerator->keys;
1771         stream >> enumerator->values;
1772         if (enumerator->keys.size() != enumerator->values.size()) {
1773             // Mismatch between number of keys and number of values.
1774             stream.setStatus(QDataStream::ReadCorruptData);
1775             return;
1776         }
1777     }
1778
1779     // Read the constructor methods.
1780     for (index = 0; index < constructorCount; ++index) {
1781         if (stream.status() != QDataStream::Ok)
1782             return;
1783         stream >> name;
1784         addConstructor(name);
1785         QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1786         stream >> method->returnType;
1787         stream >> method->parameterNames;
1788         stream >> method->tag;
1789         stream >> method->attributes;
1790         if (method->methodType() != QMetaMethod::Constructor) {
1791             // The type must be Constructor.
1792             stream.setStatus(QDataStream::ReadCorruptData);
1793             return;
1794         }
1795     }
1796
1797     // Read the related meta objects.
1798 #ifdef Q_NO_DATA_RELOCATION
1799     //### What do we do here
1800 #else
1801     for (index = 0; index < relatedMetaObjectCount; ++index) {
1802         if (stream.status() != QDataStream::Ok)
1803             return;
1804         stream >> name;
1805         cl = resolveClassName(references, name);
1806         if (!cl) {
1807             stream.setStatus(QDataStream::ReadCorruptData);
1808             return;
1809         }
1810         addRelatedMetaObject(cl);
1811     }
1812 #endif
1813
1814     // Read the extra data block, which is reserved for future use.
1815     stream >> name;
1816 }
1817
1818 #endif // !QT_NO_DATASTREAM
1819
1820 /*!
1821     \class QMetaMethodBuilder
1822     \internal
1823     \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder.
1824 */
1825
1826 QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const
1827 {
1828     // Positive indices indicate methods, negative indices indicate constructors.
1829     if (_mobj && _index >= 0 && _index < _mobj->d->methods.size())
1830         return &(_mobj->d->methods[_index]);
1831     else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size())
1832         return &(_mobj->d->constructors[(-_index) - 1]);
1833     else
1834         return 0;
1835 }
1836
1837 /*!
1838     \fn QMetaMethodBuilder::QMetaMethodBuilder()
1839     \internal
1840 */
1841
1842 /*!
1843     Returns the index of this method within its QMetaObjectBuilder.
1844 */
1845 int QMetaMethodBuilder::index() const
1846 {
1847     if (_index >= 0)
1848         return _index;          // Method, signal, or slot
1849     else
1850         return (-_index) - 1;   // Constructor
1851 }
1852
1853 /*!
1854     Returns the type of this method (signal, slot, method, or constructor).
1855 */
1856 QMetaMethod::MethodType QMetaMethodBuilder::methodType() const
1857 {
1858     QMetaMethodBuilderPrivate *d = d_func();
1859     if (d)
1860         return d->methodType();
1861     else
1862         return QMetaMethod::Method;
1863 }
1864
1865 /*!
1866     Returns the signature of this method.
1867
1868     \sa parameterNames(), returnType()
1869 */
1870 QByteArray QMetaMethodBuilder::signature() const
1871 {
1872     QMetaMethodBuilderPrivate *d = d_func();
1873     if (d)
1874         return d->signature;
1875     else
1876         return QByteArray();
1877 }
1878
1879 /*!
1880     Returns the return type for this method; empty if the method's
1881     return type is \c{void}.
1882
1883     \sa setReturnType(), signature()
1884 */
1885 QByteArray QMetaMethodBuilder::returnType() const
1886 {
1887     QMetaMethodBuilderPrivate *d = d_func();
1888     if (d)
1889         return d->returnType;
1890     else
1891         return QByteArray();
1892 }
1893
1894 /*!
1895     Sets the return type for this method to \a value.  If \a value
1896     is empty, then the method's return type is \c{void}.  The \a value
1897     will be normalized before it is added to the method.
1898
1899     \sa returnType(), signature()
1900 */
1901 void QMetaMethodBuilder::setReturnType(const QByteArray& value)
1902 {
1903     QMetaMethodBuilderPrivate *d = d_func();
1904     if (d)
1905         d->returnType = QMetaObject::normalizedType(value);
1906 }
1907
1908 /*!
1909     Returns the list of parameter names for this method.
1910
1911     \sa setParameterNames()
1912 */
1913 QList<QByteArray> QMetaMethodBuilder::parameterNames() const
1914 {
1915     QMetaMethodBuilderPrivate *d = d_func();
1916     if (d)
1917         return d->parameterNames;
1918     else
1919         return QList<QByteArray>();
1920 }
1921
1922 /*!
1923     Sets the list of parameter names for this method to \a value.
1924
1925     \sa parameterNames()
1926 */
1927 void QMetaMethodBuilder::setParameterNames(const QList<QByteArray>& value)
1928 {
1929     QMetaMethodBuilderPrivate *d = d_func();
1930     if (d)
1931         d->parameterNames = value;
1932 }
1933
1934 /*!
1935     Returns the tag associated with this method.
1936
1937     \sa setTag()
1938 */
1939 QByteArray QMetaMethodBuilder::tag() const
1940 {
1941     QMetaMethodBuilderPrivate *d = d_func();
1942     if (d)
1943         return d->tag;
1944     else
1945         return QByteArray();
1946 }
1947
1948 /*!
1949     Sets the tag associated with this method to \a value.
1950
1951     \sa setTag()
1952 */
1953 void QMetaMethodBuilder::setTag(const QByteArray& value)
1954 {
1955     QMetaMethodBuilderPrivate *d = d_func();
1956     if (d)
1957         d->tag = value;
1958 }
1959
1960 /*!
1961     Returns the access specification of this method (private, protected,
1962     or public).  The default value is QMetaMethod::Public for methods,
1963     slots, and constructors.  The default value is QMetaMethod::Protected
1964     for signals.
1965
1966     \sa setAccess()
1967 */
1968 QMetaMethod::Access QMetaMethodBuilder::access() const
1969 {
1970     QMetaMethodBuilderPrivate *d = d_func();
1971     if (d)
1972         return d->access();
1973     else
1974         return QMetaMethod::Public;
1975 }
1976
1977 /*!
1978     Sets the access specification of this method (private, protected,
1979     or public) to \a value.  If the method is a signal, this function
1980     will be ignored.
1981
1982     \sa access()
1983 */
1984 void QMetaMethodBuilder::setAccess(QMetaMethod::Access value)
1985 {
1986     QMetaMethodBuilderPrivate *d = d_func();
1987     if (d && d->methodType() != QMetaMethod::Signal)
1988         d->setAccess(value);
1989 }
1990
1991 /*!
1992     Returns the additional attributes for this method.
1993
1994     \sa setAttributes()
1995 */
1996 int QMetaMethodBuilder::attributes() const
1997 {
1998     QMetaMethodBuilderPrivate *d = d_func();
1999     if (d)
2000         return (d->attributes >> 4);
2001     else
2002         return 0;
2003 }
2004
2005 /*!
2006     Sets the additional attributes for this method to \a value.
2007
2008     \sa attributes()
2009 */
2010 void QMetaMethodBuilder::setAttributes(int value)
2011 {
2012     QMetaMethodBuilderPrivate *d = d_func();
2013     if (d)
2014         d->attributes = ((d->attributes & 0x0f) | (value << 4));
2015 }
2016
2017 /*!
2018     \class QMetaPropertyBuilder
2019     \internal
2020     \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder.
2021 */
2022
2023 QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const
2024 {
2025     if (_mobj && _index >= 0 && _index < _mobj->d->properties.size())
2026         return &(_mobj->d->properties[_index]);
2027     else
2028         return 0;
2029 }
2030
2031 /*!
2032     \fn QMetaPropertyBuilder::QMetaPropertyBuilder()
2033     \internal
2034 */
2035
2036 /*!
2037     \fn int QMetaPropertyBuilder::index() const
2038
2039     Returns the index of this property within its QMetaObjectBuilder.
2040 */
2041
2042 /*!
2043     Returns the name associated with this property.
2044
2045     \sa type()
2046 */
2047 QByteArray QMetaPropertyBuilder::name() const
2048 {
2049     QMetaPropertyBuilderPrivate *d = d_func();
2050     if (d)
2051         return d->name;
2052     else
2053         return QByteArray();
2054 }
2055
2056 /*!
2057     Returns the type associated with this property.
2058
2059     \sa name()
2060 */
2061 QByteArray QMetaPropertyBuilder::type() const
2062 {
2063     QMetaPropertyBuilderPrivate *d = d_func();
2064     if (d)
2065         return d->type;
2066     else
2067         return QByteArray();
2068 }
2069
2070 /*!
2071     Returns true if this property has a notify signal; false otherwise.
2072
2073     \sa notifySignal(), setNotifySignal(), removeNotifySignal()
2074 */
2075 bool QMetaPropertyBuilder::hasNotifySignal() const
2076 {
2077     QMetaPropertyBuilderPrivate *d = d_func();
2078     if (d)
2079         return d->flag(Notify);
2080     else
2081         return false;
2082 }
2083
2084 /*!
2085     Returns the notify signal associated with this property.
2086
2087     \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal()
2088 */
2089 QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const
2090 {
2091     QMetaPropertyBuilderPrivate *d = d_func();
2092     if (d && d->notifySignal >= 0)
2093         return QMetaMethodBuilder(_mobj, d->notifySignal);
2094     else
2095         return QMetaMethodBuilder();
2096 }
2097
2098 /*!
2099     Sets the notify signal associated with this property to \a value.
2100
2101     \sa hasNotifySignal(), notifySignal(), removeNotifySignal()
2102 */
2103 void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
2104 {
2105     QMetaPropertyBuilderPrivate *d = d_func();
2106     if (d) {
2107         if (value._mobj) {
2108             d->notifySignal = value._index;
2109             d->setFlag(Notify, true);
2110         } else {
2111             d->notifySignal = -1;
2112             d->setFlag(Notify, false);
2113         }
2114     }
2115 }
2116
2117 /*!
2118     Removes the notify signal from this property.
2119
2120     \sa hasNotifySignal(), notifySignal(), setNotifySignal()
2121 */
2122 void QMetaPropertyBuilder::removeNotifySignal()
2123 {
2124     QMetaPropertyBuilderPrivate *d = d_func();
2125     if (d) {
2126         d->notifySignal = -1;
2127         d->setFlag(Notify, false);
2128     }
2129 }
2130
2131 /*!
2132     Returns true if this property is readable; otherwise returns false.
2133     The default value is true.
2134
2135     \sa setReadable(), isWritable()
2136 */
2137 bool QMetaPropertyBuilder::isReadable() const
2138 {
2139     QMetaPropertyBuilderPrivate *d = d_func();
2140     if (d)
2141         return d->flag(Readable);
2142     else
2143         return false;
2144 }
2145
2146 /*!
2147     Returns true if this property is writable; otherwise returns false.
2148     The default value is true.
2149
2150     \sa setWritable(), isReadable()
2151 */
2152 bool QMetaPropertyBuilder::isWritable() const
2153 {
2154     QMetaPropertyBuilderPrivate *d = d_func();
2155     if (d)
2156         return d->flag(Writable);
2157     else
2158         return false;
2159 }
2160
2161 /*!
2162     Returns true if this property can be reset to a default value; otherwise
2163     returns false.  The default value is false.
2164
2165     \sa setResettable()
2166 */
2167 bool QMetaPropertyBuilder::isResettable() const
2168 {
2169     QMetaPropertyBuilderPrivate *d = d_func();
2170     if (d)
2171         return d->flag(Resettable);
2172     else
2173         return false;
2174 }
2175
2176 /*!
2177     Returns true if this property is designable; otherwise returns false.
2178     This default value is false.
2179
2180     \sa setDesignable(), isScriptable(), isStored()
2181 */
2182 bool QMetaPropertyBuilder::isDesignable() const
2183 {
2184     QMetaPropertyBuilderPrivate *d = d_func();
2185     if (d)
2186         return d->flag(Designable);
2187     else
2188         return false;
2189 }
2190
2191 /*!
2192     Returns true if the property is scriptable; otherwise returns false.
2193     This default value is true.
2194
2195     \sa setScriptable(), isDesignable(), isStored()
2196 */
2197 bool QMetaPropertyBuilder::isScriptable() const
2198 {
2199     QMetaPropertyBuilderPrivate *d = d_func();
2200     if (d)
2201         return d->flag(Scriptable);
2202     else
2203         return false;
2204 }
2205
2206 /*!
2207     Returns true if the property is stored; otherwise returns false.
2208     This default value is false.
2209
2210     \sa setStored(), isDesignable(), isScriptable()
2211 */
2212 bool QMetaPropertyBuilder::isStored() const
2213 {
2214     QMetaPropertyBuilderPrivate *d = d_func();
2215     if (d)
2216         return d->flag(Stored);
2217     else
2218         return false;
2219 }
2220
2221 /*!
2222     Returns true if the property is editable; otherwise returns false.
2223     This default value is false.
2224
2225     \sa setEditable(), isDesignable(), isScriptable(), isStored()
2226 */
2227 bool QMetaPropertyBuilder::isEditable() const
2228 {
2229     QMetaPropertyBuilderPrivate *d = d_func();
2230     if (d)
2231         return d->flag(Editable);
2232     else
2233         return false;
2234 }
2235
2236 /*!
2237     Returns true if this property is designated as the \c USER
2238     property, i.e., the one that the user can edit or that is
2239     significant in some other way.  Otherwise it returns
2240     false.  This default value is false.
2241
2242     \sa setUser(), isDesignable(), isScriptable()
2243 */
2244 bool QMetaPropertyBuilder::isUser() const
2245 {
2246     QMetaPropertyBuilderPrivate *d = d_func();
2247     if (d)
2248         return d->flag(User);
2249     else
2250         return false;
2251 }
2252
2253 /*!
2254     Returns true if the property has a C++ setter function that
2255     follows Qt's standard "name" / "setName" pattern. Designer and uic
2256     query hasStdCppSet() in order to avoid expensive
2257     QObject::setProperty() calls. All properties in Qt [should] follow
2258     this pattern.  The default value is false.
2259
2260     \sa setStdCppSet()
2261 */
2262 bool QMetaPropertyBuilder::hasStdCppSet() const
2263 {
2264     QMetaPropertyBuilderPrivate *d = d_func();
2265     if (d)
2266         return d->flag(StdCppSet);
2267     else
2268         return false;
2269 }
2270
2271 /*!
2272     Returns true if the property is an enumerator or flag type;
2273     otherwise returns false.  This default value is false.
2274
2275     \sa setEnumOrFlag()
2276 */
2277 bool QMetaPropertyBuilder::isEnumOrFlag() const
2278 {
2279     QMetaPropertyBuilderPrivate *d = d_func();
2280     if (d)
2281         return d->flag(EnumOrFlag);
2282     else
2283         return false;
2284 }
2285
2286 /*!
2287     Returns true if the property is constant; otherwise returns false.
2288     The default value is false.
2289 */
2290 bool QMetaPropertyBuilder::isConstant() const
2291 {
2292     QMetaPropertyBuilderPrivate *d = d_func();
2293     if (d)
2294         return d->flag(Constant);
2295     else
2296         return false;
2297 }
2298
2299 /*!
2300     Returns true if the property is final; otherwise returns false.
2301     The default value is false.
2302 */
2303 bool QMetaPropertyBuilder::isFinal() const
2304 {
2305     QMetaPropertyBuilderPrivate *d = d_func();
2306     if (d)
2307         return d->flag(Final);
2308     else
2309         return false;
2310 }
2311
2312 /*!
2313     Sets this property to readable if \a value is true.
2314
2315     \sa isReadable(), setWritable()
2316 */
2317 void QMetaPropertyBuilder::setReadable(bool value)
2318 {
2319     QMetaPropertyBuilderPrivate *d = d_func();
2320     if (d)
2321         d->setFlag(Readable, value);
2322 }
2323
2324 /*!
2325     Sets this property to writable if \a value is true.
2326
2327     \sa isWritable(), setReadable()
2328 */
2329 void QMetaPropertyBuilder::setWritable(bool value)
2330 {
2331     QMetaPropertyBuilderPrivate *d = d_func();
2332     if (d)
2333         d->setFlag(Writable, value);
2334 }
2335
2336 /*!
2337     Sets this property to resettable if \a value is true.
2338
2339     \sa isResettable()
2340 */
2341 void QMetaPropertyBuilder::setResettable(bool value)
2342 {
2343     QMetaPropertyBuilderPrivate *d = d_func();
2344     if (d)
2345         d->setFlag(Resettable, value);
2346 }
2347
2348 /*!
2349     Sets this property to designable if \a value is true.
2350
2351     \sa isDesignable(), setScriptable(), setStored()
2352 */
2353 void QMetaPropertyBuilder::setDesignable(bool value)
2354 {
2355     QMetaPropertyBuilderPrivate *d = d_func();
2356     if (d)
2357         d->setFlag(Designable, value);
2358 }
2359
2360 /*!
2361     Sets this property to scriptable if \a value is true.
2362
2363     \sa isScriptable(), setDesignable(), setStored()
2364 */
2365 void QMetaPropertyBuilder::setScriptable(bool value)
2366 {
2367     QMetaPropertyBuilderPrivate *d = d_func();
2368     if (d)
2369         d->setFlag(Scriptable, value);
2370 }
2371
2372 /*!
2373     Sets this property to storable if \a value is true.
2374
2375     \sa isStored(), setDesignable(), setScriptable()
2376 */
2377 void QMetaPropertyBuilder::setStored(bool value)
2378 {
2379     QMetaPropertyBuilderPrivate *d = d_func();
2380     if (d)
2381         d->setFlag(Stored, value);
2382 }
2383
2384 /*!
2385     Sets this property to editable if \a value is true.
2386
2387     \sa isEditable(), setDesignable(), setScriptable(), setStored()
2388 */
2389 void QMetaPropertyBuilder::setEditable(bool value)
2390 {
2391     QMetaPropertyBuilderPrivate *d = d_func();
2392     if (d)
2393         d->setFlag(Editable, value);
2394 }
2395
2396 /*!
2397     Sets the \c USER flag on this property to \a value.
2398
2399     \sa isUser(), setDesignable(), setScriptable()
2400 */
2401 void QMetaPropertyBuilder::setUser(bool value)
2402 {
2403     QMetaPropertyBuilderPrivate *d = d_func();
2404     if (d)
2405         d->setFlag(User, value);
2406 }
2407
2408 /*!
2409     Sets the C++ setter flag on this property to \a value, which is
2410     true if the property has a C++ setter function that follows Qt's
2411     standard "name" / "setName" pattern.
2412
2413     \sa hasStdCppSet()
2414 */
2415 void QMetaPropertyBuilder::setStdCppSet(bool value)
2416 {
2417     QMetaPropertyBuilderPrivate *d = d_func();
2418     if (d)
2419         d->setFlag(StdCppSet, value);
2420 }
2421
2422 /*!
2423     Sets this property to be of an enumerator or flag type if
2424     \a value is true.
2425
2426     \sa isEnumOrFlag()
2427 */
2428 void QMetaPropertyBuilder::setEnumOrFlag(bool value)
2429 {
2430     QMetaPropertyBuilderPrivate *d = d_func();
2431     if (d)
2432         d->setFlag(EnumOrFlag, value);
2433 }
2434
2435 /*!
2436     Sets the \c CONSTANT flag on this property to \a value.
2437
2438     \sa isConstant()
2439 */
2440 void QMetaPropertyBuilder::setConstant(bool value)
2441 {
2442     QMetaPropertyBuilderPrivate *d = d_func();
2443     if (d)
2444         d->setFlag(Constant, value);
2445 }
2446
2447 /*!
2448     Sets the \c FINAL flag on this property to \a value.
2449
2450     \sa isFinal()
2451 */
2452 void QMetaPropertyBuilder::setFinal(bool value)
2453 {
2454     QMetaPropertyBuilderPrivate *d = d_func();
2455     if (d)
2456         d->setFlag(Final, value);
2457 }
2458
2459
2460 /*!
2461     \class QMetaEnumBuilder
2462     \internal
2463     \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder.
2464 */
2465
2466 QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const
2467 {
2468     if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size())
2469         return &(_mobj->d->enumerators[_index]);
2470     else
2471         return 0;
2472 }
2473
2474 /*!
2475     \fn QMetaEnumBuilder::QMetaEnumBuilder()
2476     \internal
2477 */
2478
2479 /*!
2480     \fn int QMetaEnumBuilder::index() const
2481
2482     Returns the index of this enumerator within its QMetaObjectBuilder.
2483 */
2484
2485 /*!
2486     Returns the name of the enumerator (without the scope).
2487 */
2488 QByteArray QMetaEnumBuilder::name() const
2489 {
2490     QMetaEnumBuilderPrivate *d = d_func();
2491     if (d)
2492         return d->name;
2493     else
2494         return QByteArray();
2495 }
2496
2497 /*!
2498     Returns true if this enumerator is used as a flag; otherwise returns
2499     false.
2500
2501     \sa setIsFlag()
2502 */
2503 bool QMetaEnumBuilder::isFlag() const
2504 {
2505     QMetaEnumBuilderPrivate *d = d_func();
2506     if (d)
2507         return d->isFlag;
2508     else
2509         return false;
2510 }
2511
2512 /*!
2513     Sets this enumerator to be used as a flag if \a value is true.
2514
2515     \sa isFlag()
2516 */
2517 void QMetaEnumBuilder::setIsFlag(bool value)
2518 {
2519     QMetaEnumBuilderPrivate *d = d_func();
2520     if (d)
2521         d->isFlag = value;
2522 }
2523
2524 /*!
2525     Returns the number of keys.
2526
2527     \sa key(), addKey()
2528 */
2529 int QMetaEnumBuilder::keyCount() const
2530 {
2531     QMetaEnumBuilderPrivate *d = d_func();
2532     if (d)
2533         return d->keys.size();
2534     else
2535         return 0;
2536 }
2537
2538 /*!
2539     Returns the key with the given \a index, or an empty QByteArray
2540     if no such key exists.
2541
2542     \sa keyCount(), addKey(), value()
2543 */
2544 QByteArray QMetaEnumBuilder::key(int index) const
2545 {
2546     QMetaEnumBuilderPrivate *d = d_func();
2547     if (d && index >= 0 && index < d->keys.size())
2548         return d->keys[index];
2549     else
2550         return QByteArray();
2551 }
2552
2553 /*!
2554     Returns the value with the given \a index; or returns -1 if there
2555     is no such value.
2556
2557     \sa keyCount(), addKey(), key()
2558 */
2559 int QMetaEnumBuilder::value(int index) const
2560 {
2561     QMetaEnumBuilderPrivate *d = d_func();
2562     if (d && index >= 0 && index < d->keys.size())
2563         return d->values[index];
2564     else
2565         return -1;
2566 }
2567
2568 /*!
2569     Adds a new key called \a name to this enumerator, associated
2570     with \a value.  Returns the index of the new key.
2571
2572     \sa keyCount(), key(), value(), removeKey()
2573 */
2574 int QMetaEnumBuilder::addKey(const QByteArray& name, int value)
2575 {
2576     QMetaEnumBuilderPrivate *d = d_func();
2577     if (d) {
2578         int index = d->keys.size();
2579         d->keys += name;
2580         d->values += value;
2581         return index;
2582     } else {
2583         return -1;
2584     }
2585 }
2586
2587 /*!
2588     Removes the key at \a index from this enumerator.
2589
2590     \sa addKey()
2591 */
2592 void QMetaEnumBuilder::removeKey(int index)
2593 {
2594     QMetaEnumBuilderPrivate *d = d_func();
2595     if (d && index >= 0 && index < d->keys.size()) {
2596         d->keys.removeAt(index);
2597         d->values.removeAt(index);
2598     }
2599 }
2600
2601 QT_END_NAMESPACE