src/declarative/qml/qmetaobjectbuilder_p.h
changeset 30 5dc02b23752f
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 #ifndef QMETAOBJECTBUILDER_H
       
    43 #define QMETAOBJECTBUILDER_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists for the convenience
       
    50 // of moc.  This header file may change from version to version without notice,
       
    51 // or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include <QtCore/qobject.h>
       
    57 #include <QtCore/qmetaobject.h>
       
    58 #include <QtCore/qdatastream.h>
       
    59 #include <QtCore/qmap.h>
       
    60 
       
    61 QT_BEGIN_NAMESPACE
       
    62 
       
    63 class QMetaObjectBuilderPrivate;
       
    64 class QMetaMethodBuilder;
       
    65 class QMetaMethodBuilderPrivate;
       
    66 class QMetaPropertyBuilder;
       
    67 class QMetaPropertyBuilderPrivate;
       
    68 class QMetaEnumBuilder;
       
    69 class QMetaEnumBuilderPrivate;
       
    70 
       
    71 class Q_DECLARATIVE_EXPORT QMetaObjectBuilder
       
    72 {
       
    73 public:
       
    74     enum AddMember
       
    75     {
       
    76         ClassName               = 0x00000001,
       
    77         SuperClass              = 0x00000002,
       
    78         Methods                 = 0x00000004,
       
    79         Signals                 = 0x00000008,
       
    80         Slots                   = 0x00000010,
       
    81         Constructors            = 0x00000020,
       
    82         Properties              = 0x00000040,
       
    83         Enumerators             = 0x00000080,
       
    84         ClassInfos              = 0x00000100,
       
    85         RelatedMetaObjects      = 0x00000200,
       
    86         StaticMetacall          = 0x00000400,
       
    87         PublicMethods           = 0x00000800,
       
    88         ProtectedMethods        = 0x00001000,
       
    89         PrivateMethods          = 0x00002000,
       
    90         AllMembers              = 0x7FFFFFFF,
       
    91         AllPrimaryMembers       = 0x7FFFFBFC
       
    92     };
       
    93     Q_DECLARE_FLAGS(AddMembers, AddMember)
       
    94 
       
    95     enum MetaObjectFlag {
       
    96         DynamicMetaObject = 0x01
       
    97     };
       
    98     Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag)
       
    99 
       
   100     QMetaObjectBuilder();
       
   101     explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers);
       
   102     virtual ~QMetaObjectBuilder();
       
   103 
       
   104     QByteArray className() const;
       
   105     void setClassName(const QByteArray& name);
       
   106 
       
   107     const QMetaObject *superClass() const;
       
   108     void setSuperClass(const QMetaObject *meta);
       
   109 
       
   110     MetaObjectFlags flags() const;
       
   111     void setFlags(MetaObjectFlags);
       
   112 
       
   113     int methodCount() const;
       
   114     int constructorCount() const;
       
   115     int propertyCount() const;
       
   116     int enumeratorCount() const;
       
   117     int classInfoCount() const;
       
   118     int relatedMetaObjectCount() const;
       
   119 
       
   120     QMetaMethodBuilder addMethod(const QByteArray& signature);
       
   121     QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType);
       
   122     QMetaMethodBuilder addMethod(const QMetaMethod& prototype);
       
   123 
       
   124     QMetaMethodBuilder addSlot(const QByteArray& signature);
       
   125     QMetaMethodBuilder addSignal(const QByteArray& signature);
       
   126 
       
   127     QMetaMethodBuilder addConstructor(const QByteArray& signature);
       
   128     QMetaMethodBuilder addConstructor(const QMetaMethod& prototype);
       
   129 
       
   130     QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1);
       
   131     QMetaPropertyBuilder addProperty(const QMetaProperty& prototype);
       
   132 
       
   133     QMetaEnumBuilder addEnumerator(const QByteArray& name);
       
   134     QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype);
       
   135 
       
   136     int addClassInfo(const QByteArray& name, const QByteArray& value);
       
   137 
       
   138 #ifdef Q_NO_DATA_RELOCATION
       
   139     int addRelatedMetaObject(const QMetaObjectAccessor &meta);
       
   140 #else
       
   141     int addRelatedMetaObject(const QMetaObject *meta);
       
   142 #endif
       
   143 
       
   144     void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers);
       
   145 
       
   146     QMetaMethodBuilder method(int index) const;
       
   147     QMetaMethodBuilder constructor(int index) const;
       
   148     QMetaPropertyBuilder property(int index) const;
       
   149     QMetaEnumBuilder enumerator(int index) const;
       
   150     const QMetaObject *relatedMetaObject(int index) const;
       
   151 
       
   152     QByteArray classInfoName(int index) const;
       
   153     QByteArray classInfoValue(int index) const;
       
   154 
       
   155     void removeMethod(int index);
       
   156     void removeConstructor(int index);
       
   157     void removeProperty(int index);
       
   158     void removeEnumerator(int index);
       
   159     void removeClassInfo(int index);
       
   160     void removeRelatedMetaObject(int index);
       
   161 
       
   162     int indexOfMethod(const QByteArray& signature);
       
   163     int indexOfSignal(const QByteArray& signature);
       
   164     int indexOfSlot(const QByteArray& signature);
       
   165     int indexOfConstructor(const QByteArray& signature);
       
   166     int indexOfProperty(const QByteArray& name);
       
   167     int indexOfEnumerator(const QByteArray& name);
       
   168     int indexOfClassInfo(const QByteArray& name);
       
   169 
       
   170     typedef int (*StaticMetacallFunction)(QMetaObject::Call, int, void **);
       
   171 
       
   172     QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const;
       
   173     void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value);
       
   174 
       
   175     QMetaObject *toMetaObject() const;
       
   176     QByteArray toRelocatableData(bool * = 0) const;
       
   177     static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &);
       
   178 
       
   179 #ifndef QT_NO_DATASTREAM
       
   180     void serialize(QDataStream& stream) const;
       
   181     void deserialize
       
   182         (QDataStream& stream,
       
   183          const QMap<QByteArray, const QMetaObject *>& references);
       
   184 #endif
       
   185 
       
   186 private:
       
   187     Q_DISABLE_COPY(QMetaObjectBuilder)
       
   188 
       
   189     QMetaObjectBuilderPrivate *d;
       
   190 
       
   191     friend class QMetaMethodBuilder;
       
   192     friend class QMetaPropertyBuilder;
       
   193     friend class QMetaEnumBuilder;
       
   194 };
       
   195 
       
   196 class Q_DECLARATIVE_EXPORT QMetaMethodBuilder
       
   197 {
       
   198 public:
       
   199     QMetaMethodBuilder() : _mobj(0), _index(0) {}
       
   200 
       
   201     int index() const;
       
   202 
       
   203     QMetaMethod::MethodType methodType() const;
       
   204     QByteArray signature() const;
       
   205 
       
   206     QByteArray returnType() const;
       
   207     void setReturnType(const QByteArray& value);
       
   208 
       
   209     QList<QByteArray> parameterNames() const;
       
   210     void setParameterNames(const QList<QByteArray>& value);
       
   211 
       
   212     QByteArray tag() const;
       
   213     void setTag(const QByteArray& value);
       
   214 
       
   215     QMetaMethod::Access access() const;
       
   216     void setAccess(QMetaMethod::Access value);
       
   217 
       
   218     int attributes() const;
       
   219     void setAttributes(int value);
       
   220 
       
   221 private:
       
   222     const QMetaObjectBuilder *_mobj;
       
   223     int _index;
       
   224 
       
   225     friend class QMetaObjectBuilder;
       
   226     friend class QMetaPropertyBuilder;
       
   227 
       
   228     QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index)
       
   229         : _mobj(mobj), _index(index) {}
       
   230 
       
   231     QMetaMethodBuilderPrivate *d_func() const;
       
   232 };
       
   233 
       
   234 class Q_DECLARATIVE_EXPORT QMetaPropertyBuilder
       
   235 {
       
   236 public:
       
   237     QMetaPropertyBuilder() : _mobj(0), _index(0) {}
       
   238 
       
   239     int index() const { return _index; }
       
   240 
       
   241     QByteArray name() const;
       
   242     QByteArray type() const;
       
   243 
       
   244     bool hasNotifySignal() const;
       
   245     QMetaMethodBuilder notifySignal() const;
       
   246     void setNotifySignal(const QMetaMethodBuilder& value);
       
   247     void removeNotifySignal();
       
   248 
       
   249     bool isReadable() const;
       
   250     bool isWritable() const;
       
   251     bool isResettable() const;
       
   252     bool isDesignable() const;
       
   253     bool isScriptable() const;
       
   254     bool isStored() const;
       
   255     bool isEditable() const;
       
   256     bool isUser() const;
       
   257     bool hasStdCppSet() const;
       
   258     bool isEnumOrFlag() const;
       
   259     bool isDynamic() const;
       
   260 
       
   261     void setReadable(bool value);
       
   262     void setWritable(bool value);
       
   263     void setResettable(bool value);
       
   264     void setDesignable(bool value);
       
   265     void setScriptable(bool value);
       
   266     void setStored(bool value);
       
   267     void setEditable(bool value);
       
   268     void setUser(bool value);
       
   269     void setStdCppSet(bool value);
       
   270     void setEnumOrFlag(bool value);
       
   271     void setDynamic(bool value);
       
   272 
       
   273 private:
       
   274     const QMetaObjectBuilder *_mobj;
       
   275     int _index;
       
   276 
       
   277     friend class QMetaObjectBuilder;
       
   278 
       
   279     QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index)
       
   280         : _mobj(mobj), _index(index) {}
       
   281 
       
   282     QMetaPropertyBuilderPrivate *d_func() const;
       
   283 };
       
   284 
       
   285 class Q_DECLARATIVE_EXPORT QMetaEnumBuilder
       
   286 {
       
   287 public:
       
   288     QMetaEnumBuilder() : _mobj(0), _index(0) {}
       
   289 
       
   290     int index() const { return _index; }
       
   291 
       
   292     QByteArray name() const;
       
   293 
       
   294     bool isFlag() const;
       
   295     void setIsFlag(bool value);
       
   296 
       
   297     int keyCount() const;
       
   298     QByteArray key(int index) const;
       
   299     int value(int index) const;
       
   300 
       
   301     int addKey(const QByteArray& name, int value);
       
   302     void removeKey(int index);
       
   303 
       
   304 private:
       
   305     const QMetaObjectBuilder *_mobj;
       
   306     int _index;
       
   307 
       
   308     friend class QMetaObjectBuilder;
       
   309 
       
   310     QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index)
       
   311         : _mobj(mobj), _index(index) {}
       
   312 
       
   313     QMetaEnumBuilderPrivate *d_func() const;
       
   314 };
       
   315 
       
   316 Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers)
       
   317 Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::MetaObjectFlags)
       
   318 
       
   319 QT_END_NAMESPACE
       
   320 
       
   321 #endif