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