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