From 4e92cd61a02345e68f797fb613947f65674033c3 Mon Sep 17 00:00:00 2001 From: Filippo Cucchetto Date: Mon, 1 Dec 2014 21:02:18 +0100 Subject: [PATCH] Fixed crazy runtime error due to compilation of unneeded private Qt cpp files. --- .gitignore | 3 +- DOtherSide/DOtherSide/DOtherSide.cpp | 19 + DOtherSide/DOtherSide/DOtherSide.h | 5 + DOtherSide/DOtherSide/DOtherSide.pro | 2 +- DOtherSide/DynamicQObject/DynamicQObject.cpp | 3 - DOtherSide/DynamicQObject/DynamicQObject.h | 7 +- DOtherSide/DynamicQObject/DynamicQObject.pro | 10 +- DOtherSide/DynamicQObject/DynamicSignal.cpp | 2 - .../DynamicQObject/private/qmetaobject.cpp | 3401 ----------------- .../DynamicQObject/private/qmetaobject.h | 277 -- .../private/qmetaobject_moc_p.h | 208 - .../private/qmetaobjectbuilder.cpp | 2726 ------------- .../DynamicQObject/private/qmetatype.cpp | 2408 ------------ DOtherSide/DynamicQObject/private/qmetatype.h | 2080 ---------- .../DynamicQObject/private/qmetatype_p.h | 255 -- .../private/qmetatypeswitcher_p.h | 91 - 16 files changed, 31 insertions(+), 11466 deletions(-) delete mode 100644 DOtherSide/DynamicQObject/private/qmetaobject.cpp delete mode 100644 DOtherSide/DynamicQObject/private/qmetaobject.h delete mode 100644 DOtherSide/DynamicQObject/private/qmetaobject_moc_p.h delete mode 100644 DOtherSide/DynamicQObject/private/qmetaobjectbuilder.cpp delete mode 100644 DOtherSide/DynamicQObject/private/qmetatype.cpp delete mode 100644 DOtherSide/DynamicQObject/private/qmetatype.h delete mode 100644 DOtherSide/DynamicQObject/private/qmetatype_p.h delete mode 100644 DOtherSide/DynamicQObject/private/qmetatypeswitcher_p.h diff --git a/.gitignore b/.gitignore index 376a98d..dffdd20 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build *.pro.* *.o -.directory \ No newline at end of file +.directory +nimcache \ No newline at end of file diff --git a/DOtherSide/DOtherSide/DOtherSide.cpp b/DOtherSide/DOtherSide/DOtherSide.cpp index 7c6d092..8a71d90 100644 --- a/DOtherSide/DOtherSide/DOtherSide.cpp +++ b/DOtherSide/DOtherSide/DOtherSide.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "DynamicQObject.h" @@ -33,6 +34,23 @@ void dos_guiapplication_exec() qApp->exec(); } +void dos_qqmlapplicationengine_create(void **vptr) +{ + *vptr = new QQmlApplicationEngine(); +} + +void dos_qqmlapplicationengine_load(void *vptr, const char *filename) +{ + QQmlApplicationEngine* engine = reinterpret_cast(vptr); + engine->load(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QDir::separator() + QString(filename))); +} + +void dos_qqmlapplicationengine_delete(void* vptr) +{ + QQmlApplicationEngine* engine = reinterpret_cast(vptr); + delete engine; +} + void dos_quickview_create(void** vptr) { *vptr = new QQuickView(); @@ -177,6 +195,7 @@ void dos_qvariant_setString(void* vptr, const char* value) *variant = value; } + void dos_qobject_create(void** vptr, void* dObjectPointer, DObjectCallback dObjectCallback) { auto dynamicQObject = new DynamicQObject(); diff --git a/DOtherSide/DOtherSide/DOtherSide.h b/DOtherSide/DOtherSide/DOtherSide.h index 7de1e63..1b77043 100644 --- a/DOtherSide/DOtherSide/DOtherSide.h +++ b/DOtherSide/DOtherSide/DOtherSide.h @@ -14,6 +14,10 @@ void dos_guiapplication_create(); void dos_guiapplication_exec(); void dos_guiapplication_delete(); +void dos_qqmlapplicationengine_create(void** vptr); +void dos_qqmlapplicationengine_load(void* vptr, const char* filename); +void dos_qqmlapplicationengine_delete(void* vptr); + void dos_quickview_create(void** vptr); void dos_quickview_show(void* vptr); void dos_quickview_source(void* vptr, CharPtr& result, int& length); @@ -41,6 +45,7 @@ void dos_qvariant_setString(void* vptr, const char* value); void dos_qvariant_isnull(void *vptr, bool& isNull); void dos_qvariant_delete(void *vptr); + void dos_qobject_create(void **vptr, void *dObjectPointer, DObjectCallback dObjectCallback); void dos_qobject_slot_create(void* vptr, const char* name, int parametersCount, int* parametersMetaTypes, int* slotIndex); void dos_qobject_signal_create(void* vptr, const char* name, int parametersCount, int* parametersMetaTypes, int* signalIndex); diff --git a/DOtherSide/DOtherSide/DOtherSide.pro b/DOtherSide/DOtherSide/DOtherSide.pro index 0302b1c..dc6097f 100644 --- a/DOtherSide/DOtherSide/DOtherSide.pro +++ b/DOtherSide/DOtherSide/DOtherSide.pro @@ -8,7 +8,7 @@ QT += quick CONFIG += c++11 -QMAKE_CXXFLAGS += "-O1 -fpic" +QMAKE_CXXFLAGS += "-fpic" TARGET = DOtherSide TEMPLATE = lib diff --git a/DOtherSide/DynamicQObject/DynamicQObject.cpp b/DOtherSide/DynamicQObject/DynamicQObject.cpp index a4e7c93..af63a64 100644 --- a/DOtherSide/DynamicQObject/DynamicQObject.cpp +++ b/DOtherSide/DynamicQObject/DynamicQObject.cpp @@ -221,6 +221,3 @@ int DynamicQObject::qt_metacall(QMetaObject::Call callType, int index, void** a return -1; } - - - diff --git a/DOtherSide/DynamicQObject/DynamicQObject.h b/DOtherSide/DynamicQObject/DynamicQObject.h index 0e460d3..f84be40 100644 --- a/DOtherSide/DynamicQObject/DynamicQObject.h +++ b/DOtherSide/DynamicQObject/DynamicQObject.h @@ -1,22 +1,19 @@ #pragma once -class QMetaObject; - -#include #include +#include #include "DynamicSignal.h" #include "DynamicSlot.h" - class DynamicQObject : public QObject { typedef void (*Callback)(void*, void*, int, void **); public: DynamicQObject(QObject* parent = 0); - virtual ~DynamicQObject(); + virtual ~DynamicQObject(); void setDObjectCallback(Callback callback) { m_dObjectCallback = callback; } void setDObjectPointer(void* dObjectPointer) { m_dObjectPointer = dObjectPointer; } diff --git a/DOtherSide/DynamicQObject/DynamicQObject.pro b/DOtherSide/DynamicQObject/DynamicQObject.pro index 9b39b48..ecfc18b 100644 --- a/DOtherSide/DynamicQObject/DynamicQObject.pro +++ b/DOtherSide/DynamicQObject/DynamicQObject.pro @@ -11,22 +11,16 @@ INCLUDEPATH += private CONFIG += c++11 CONFIG += staticlib +QMAKE_CXXFLAGS += "-fpic" + # Input HEADERS += DynamicQObject.h \ private/qmetaobjectbuilder_p.h \ private/qmetaobject_p.h \ private/qobject_p.h \ - private/qmetaobject_moc_p.h \ - private/qmetaobject.h \ - private/qmetatype_p.h \ - private/qmetatype.h \ - private/qmetatypeswitcher_p.h \ DynamicSignal.h \ DynamicSlot.h SOURCES += DynamicQObject.cpp \ - private/qmetaobjectbuilder.cpp \ - private/qmetaobject.cpp \ - private/qmetatype.cpp \ DynamicSignal.cpp \ DynamicSlot.cpp diff --git a/DOtherSide/DynamicQObject/DynamicSignal.cpp b/DOtherSide/DynamicQObject/DynamicSignal.cpp index 02d7f4f..6030295 100644 --- a/DOtherSide/DynamicQObject/DynamicSignal.cpp +++ b/DOtherSide/DynamicQObject/DynamicSignal.cpp @@ -48,7 +48,6 @@ DynamicSignal& DynamicSignal::operator=(const DynamicSignal& signal) DynamicSignal::~DynamicSignal() { - } bool DynamicSignal::isValid() const @@ -89,4 +88,3 @@ void DynamicSignal::_initSignature() d->signature = signature.arg(d->name, arguments).toUtf8(); } - diff --git a/DOtherSide/DynamicQObject/private/qmetaobject.cpp b/DOtherSide/DynamicQObject/private/qmetaobject.cpp deleted file mode 100644 index bc08e52..0000000 --- a/DOtherSide/DynamicQObject/private/qmetaobject.cpp +++ /dev/null @@ -1,3401 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmetaobject.h" -#include "qmetatype.h" -#include "qobject.h" -#include "qmetaobject_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "private/qobject_p.h" -#include "private/qmetaobject_p.h" - -// for normalizeTypeInternal -#include "private/qmetaobject_moc_p.h" - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QMetaObject - \inmodule QtCore - - \brief The QMetaObject class contains meta-information about Qt - objects. - - \ingroup objectmodel - - The Qt \l{Meta-Object System} in Qt is responsible for the - signals and slots inter-object communication mechanism, runtime - type information, and the Qt property system. A single - QMetaObject instance is created for each QObject subclass that is - used in an application, and this instance stores all the - meta-information for the QObject subclass. This object is - available as QObject::metaObject(). - - This class is not normally required for application programming, - but it is useful if you write meta-applications, such as scripting - engines or GUI builders. - - The functions you are most likely to find useful are these: - \list - \li className() returns the name of a class. - \li superClass() returns the superclass's meta-object. - \li method() and methodCount() provide information - about a class's meta-methods (signals, slots and other - \l{Q_INVOKABLE}{invokable} member functions). - \li enumerator() and enumeratorCount() and provide information about - a class's enumerators. - \li propertyCount() and property() provide information about a - class's properties. - \li constructor() and constructorCount() provide information - about a class's meta-constructors. - \endlist - - The index functions indexOfConstructor(), indexOfMethod(), - indexOfEnumerator(), and indexOfProperty() map names of constructors, - member functions, enumerators, or properties to indexes in the - meta-object. For example, Qt uses indexOfMethod() internally when you - connect a signal to a slot. - - Classes can also have a list of \e{name}--\e{value} pairs of - additional class information, stored in QMetaClassInfo objects. - The number of pairs is returned by classInfoCount(), single pairs - are returned by classInfo(), and you can search for pairs with - indexOfClassInfo(). - - \sa QMetaClassInfo, QMetaEnum, QMetaMethod, QMetaProperty, QMetaType, - {Meta-Object System} -*/ - -/*! - \enum QMetaObject::Call - - \internal - - \value InvokeSlot - \value EmitSignal - \value ReadProperty - \value WriteProperty - \value ResetProperty - \value QueryPropertyDesignable - \value QueryPropertyScriptable - \value QueryPropertyStored - \value QueryPropertyEditable - \value QueryPropertyUser - \value CreateInstance -*/ - -/*! - \enum QMetaMethod::Access - - This enum describes the access level of a method, following the conventions used in C++. - - \value Private - \value Protected - \value Public -*/ - -static inline const QMetaObjectPrivate *priv(const uint* data) -{ return reinterpret_cast(data); } - -static inline const QByteArray stringData(const QMetaObject *mo, int index) -{ - Q_ASSERT(priv(mo->d.data)->revision >= 7); - const QByteArrayDataPtr data = { const_cast(&mo->d.stringdata[index]) }; - Q_ASSERT(data.ptr->ref.isStatic()); - Q_ASSERT(data.ptr->alloc == 0); - Q_ASSERT(data.ptr->capacityReserved == 0); - Q_ASSERT(data.ptr->size >= 0); - return data; -} - -static inline const char *rawStringData(const QMetaObject *mo, int index) -{ - return stringData(mo, index).data(); -} - -static inline int stringSize(const QMetaObject *mo, int index) -{ - return stringData(mo, index).size(); -} - -static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo) -{ - if (typeInfo & IsUnresolvedType) { - return stringData(mo, typeInfo & TypeNameIndexMask); - } else { - // ### Use the QMetaType::typeName() that returns QByteArray - const char *t = QMetaType::typeName(typeInfo); - return QByteArray::fromRawData(t, qstrlen(t)); - } -} - -static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo) -{ - return typeNameFromTypeInfo(mo, typeInfo).constData(); -} - -static inline int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo) -{ - if (!(typeInfo & IsUnresolvedType)) - return typeInfo; - return QMetaType::type(stringData(mo, typeInfo & TypeNameIndexMask)); -} - -class QMetaMethodPrivate : public QMetaMethod -{ -public: - static const QMetaMethodPrivate *get(const QMetaMethod *q) - { return static_cast(q); } - - inline QByteArray signature() const; - inline QByteArray name() const; - inline int typesDataIndex() const; - inline const char *rawReturnTypeName() const; - inline int returnType() const; - inline int parameterCount() const; - inline int parametersDataIndex() const; - inline uint parameterTypeInfo(int index) const; - inline int parameterType(int index) const; - inline void getParameterTypes(int *types) const; - inline QList parameterTypes() const; - inline QList parameterNames() const; - inline QByteArray tag() const; - inline int ownMethodIndex() const; - -private: - QMetaMethodPrivate(); -}; - -/*! - \since 4.5 - - Constructs a new instance of this class. You can pass up to ten arguments - (\a val0, \a val1, \a val2, \a val3, \a val4, \a val5, \a val6, \a val7, - \a val8, and \a val9) to the constructor. Returns the new object, or 0 if - no suitable constructor is available. - - Note that only constructors that are declared with the Q_INVOKABLE - modifier are made available through the meta-object system. - - \sa Q_ARG(), constructor() -*/ -QObject *QMetaObject::newInstance(QGenericArgument val0, - QGenericArgument val1, - QGenericArgument val2, - QGenericArgument val3, - QGenericArgument val4, - QGenericArgument val5, - QGenericArgument val6, - QGenericArgument val7, - QGenericArgument val8, - QGenericArgument val9) const -{ - QByteArray constructorName = className(); - { - int idx = constructorName.lastIndexOf(':'); - if (idx != -1) - constructorName.remove(0, idx+1); // remove qualified part - } - QVarLengthArray sig; - sig.append(constructorName.constData(), constructorName.length()); - sig.append('('); - - enum { MaximumParamCount = 10 }; - const char *typeNames[] = {val0.name(), val1.name(), val2.name(), val3.name(), val4.name(), - val5.name(), val6.name(), val7.name(), val8.name(), val9.name()}; - - int paramCount; - for (paramCount = 0; paramCount < MaximumParamCount; ++paramCount) { - int len = qstrlen(typeNames[paramCount]); - if (len <= 0) - break; - sig.append(typeNames[paramCount], len); - sig.append(','); - } - if (paramCount == 0) - sig.append(')'); // no parameters - else - sig[sig.size() - 1] = ')'; - sig.append('\0'); - - int idx = indexOfConstructor(sig.constData()); - if (idx < 0) { - QByteArray norm = QMetaObject::normalizedSignature(sig.constData()); - idx = indexOfConstructor(norm.constData()); - } - if (idx < 0) - return 0; - - QObject *returnValue = 0; - void *param[] = {&returnValue, val0.data(), val1.data(), val2.data(), val3.data(), val4.data(), - val5.data(), val6.data(), val7.data(), val8.data(), val9.data()}; - - if (static_metacall(CreateInstance, idx, param) >= 0) - return 0; - return returnValue; -} - -/*! - \internal -*/ -int QMetaObject::static_metacall(Call cl, int idx, void **argv) const -{ - Q_ASSERT(priv(d.data)->revision >= 6); - if (!d.static_metacall) - return 0; - d.static_metacall(0, cl, idx, argv); - return -1; -} - -/*! - \internal -*/ -int QMetaObject::metacall(QObject *object, Call cl, int idx, void **argv) -{ - if (object->d_ptr->metaObject) - return object->d_ptr->metaObject->metaCall(object, cl, idx, argv); - else - return object->qt_metacall(cl, idx, argv); -} - -/*! - Returns the class name. - - \sa superClass() -*/ -const char *QMetaObject::className() const -{ - return rawStringData(this, 0); -} - -/*! - \fn QMetaObject *QMetaObject::superClass() const - - Returns the meta-object of the superclass, or 0 if there is no - such object. - - \sa className() -*/ - -/*! - \internal - - Returns \a obj if object \a obj inherits from this - meta-object; otherwise returns 0. -*/ -QObject *QMetaObject::cast(QObject *obj) const -{ - if (obj) { - const QMetaObject *m = obj->metaObject(); - do { - if (m == this) - return obj; - } while ((m = m->d.superdata)); - } - return 0; -} - -/*! - \internal - - Returns \a obj if object \a obj inherits from this - meta-object; otherwise returns 0. -*/ -const QObject *QMetaObject::cast(const QObject *obj) const -{ - if (obj) { - const QMetaObject *m = obj->metaObject(); - do { - if (m == this) - return obj; - } while ((m = m->d.superdata)); - } - return 0; -} - -#ifndef QT_NO_TRANSLATION -/*! - \internal -*/ -QString QMetaObject::tr(const char *s, const char *c, int n) const -{ - return QCoreApplication::translate(rawStringData(this, 0), s, c, n); -} -#endif // QT_NO_TRANSLATION - -/*! - Returns the method offset for this class; i.e. the index position - of this class's first member function. - - The offset is the sum of all the methods in the class's - superclasses (which is always positive since QObject has the - deleteLater() slot and a destroyed() signal). - - \sa method(), methodCount(), indexOfMethod() -*/ -int QMetaObject::methodOffset() const -{ - int offset = 0; - const QMetaObject *m = d.superdata; - while (m) { - offset += priv(m->d.data)->methodCount; - m = m->d.superdata; - } - return offset; -} - - -/*! - Returns the enumerator offset for this class; i.e. the index - position of this class's first enumerator. - - If the class has no superclasses with enumerators, the offset is - 0; otherwise the offset is the sum of all the enumerators in the - class's superclasses. - - \sa enumerator(), enumeratorCount(), indexOfEnumerator() -*/ -int QMetaObject::enumeratorOffset() const -{ - int offset = 0; - const QMetaObject *m = d.superdata; - while (m) { - offset += priv(m->d.data)->enumeratorCount; - m = m->d.superdata; - } - return offset; -} - -/*! - Returns the property offset for this class; i.e. the index - position of this class's first property. - - The offset is the sum of all the properties in the class's - superclasses (which is always positive since QObject has the - name() property). - - \sa property(), propertyCount(), indexOfProperty() -*/ -int QMetaObject::propertyOffset() const -{ - int offset = 0; - const QMetaObject *m = d.superdata; - while (m) { - offset += priv(m->d.data)->propertyCount; - m = m->d.superdata; - } - return offset; -} - -/*! - Returns the class information offset for this class; i.e. the - index position of this class's first class information item. - - If the class has no superclasses with class information, the - offset is 0; otherwise the offset is the sum of all the class - information items in the class's superclasses. - - \sa classInfo(), classInfoCount(), indexOfClassInfo() -*/ -int QMetaObject::classInfoOffset() const -{ - int offset = 0; - const QMetaObject *m = d.superdata; - while (m) { - offset += priv(m->d.data)->classInfoCount; - m = m->d.superdata; - } - return offset; -} - -/*! - \since 4.5 - - Returns the number of constructors in this class. - - \sa constructor(), indexOfConstructor() -*/ -int QMetaObject::constructorCount() const -{ - Q_ASSERT(priv(d.data)->revision >= 2); - return priv(d.data)->constructorCount; -} - -/*! - Returns the number of methods in this class, including the number of - methods provided by each base class. These include signals and slots - as well as normal member functions. - - Use code like the following to obtain a QStringList containing the methods - specific to a given class: - - \snippet code/src_corelib_kernel_qmetaobject.cpp methodCount - - \sa method(), methodOffset(), indexOfMethod() -*/ -int QMetaObject::methodCount() const -{ - int n = priv(d.data)->methodCount; - const QMetaObject *m = d.superdata; - while (m) { - n += priv(m->d.data)->methodCount; - m = m->d.superdata; - } - return n; -} - -/*! - Returns the number of enumerators in this class. - - \sa enumerator(), enumeratorOffset(), indexOfEnumerator() -*/ -int QMetaObject::enumeratorCount() const -{ - int n = priv(d.data)->enumeratorCount; - const QMetaObject *m = d.superdata; - while (m) { - n += priv(m->d.data)->enumeratorCount; - m = m->d.superdata; - } - return n; -} - -/*! - Returns the number of properties in this class, including the number of - properties provided by each base class. - - Use code like the following to obtain a QStringList containing the properties - specific to a given class: - - \snippet code/src_corelib_kernel_qmetaobject.cpp propertyCount - - \sa property(), propertyOffset(), indexOfProperty() -*/ -int QMetaObject::propertyCount() const -{ - int n = priv(d.data)->propertyCount; - const QMetaObject *m = d.superdata; - while (m) { - n += priv(m->d.data)->propertyCount; - m = m->d.superdata; - } - return n; -} - -/*! - Returns the number of items of class information in this class. - - \sa classInfo(), classInfoOffset(), indexOfClassInfo() -*/ -int QMetaObject::classInfoCount() const -{ - int n = priv(d.data)->classInfoCount; - const QMetaObject *m = d.superdata; - while (m) { - n += priv(m->d.data)->classInfoCount; - m = m->d.superdata; - } - return n; -} - -// Returns \c true if the method defined by the given meta-object&handle -// matches the given name, argument count and argument types, otherwise -// returns \c false. -static bool methodMatch(const QMetaObject *m, int handle, - const QByteArray &name, int argc, - const QArgumentType *types) -{ - Q_ASSERT(priv(m->d.data)->revision >= 7); - if (int(m->d.data[handle + 1]) != argc) - return false; - - QByteArray temp = stringData(m, m->d.data[handle]); - - if (stringData(m, m->d.data[handle]) != name) - return false; - - int paramsIndex = m->d.data[handle + 2] + 1; - for (int i = 0; i < argc; ++i) { - uint typeInfo = m->d.data[paramsIndex + i]; - if (types[i].type()) { - if (types[i].type() != typeFromTypeInfo(m, typeInfo)) - return false; - } else { - if (types[i].name() != typeNameFromTypeInfo(m, typeInfo)) - return false; - } - } - - return true; -} - -/** -* \internal -* helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within -* the baseObject -* \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything. -*/ -template -static inline int indexOfMethodRelative(const QMetaObject **baseObject, - const QByteArray &name, int argc, - const QArgumentType *types) -{ - for (const QMetaObject *m = *baseObject; m; m = m->d.superdata) { - Q_ASSERT(priv(m->d.data)->revision >= 7); - int i = (MethodType == MethodSignal) - ? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1); - const int end = (MethodType == MethodSlot) - ? (priv(m->d.data)->signalCount) : 0; - - for (; i >= end; --i) { - int temp = priv(m->d.data)->methodData; - int handle = priv(m->d.data)->methodData + 5*i; - if (methodMatch(m, handle, name, argc, types)) { - *baseObject = m; - return i; - } - } - } - return -1; -} - - -/*! - \since 4.5 - - Finds \a constructor and returns its index; otherwise returns -1. - - Note that the \a constructor has to be in normalized form, as returned - by normalizedSignature(). - - \sa constructor(), constructorCount(), normalizedSignature() -*/ -int QMetaObject::indexOfConstructor(const char *constructor) const -{ - Q_ASSERT(priv(d.data)->revision >= 7); - QArgumentTypeArray types; - QByteArray name = QMetaObjectPrivate::decodeMethodSignature(constructor, types); - return QMetaObjectPrivate::indexOfConstructor(this, name, types.size(), types.constData()); -} - -/*! - Finds \a method and returns its index; otherwise returns -1. - - Note that the \a method has to be in normalized form, as returned - by normalizedSignature(). - - \sa method(), methodCount(), methodOffset(), normalizedSignature() -*/ -int QMetaObject::indexOfMethod(const char *method) const -{ - const QMetaObject *m = this; - int i; - Q_ASSERT(priv(m->d.data)->revision >= 7); - QArgumentTypeArray types; - QByteArray name = QMetaObjectPrivate::decodeMethodSignature(method, types); - i = indexOfMethodRelative<0>(&m, name, types.size(), types.constData()); - if (i >= 0) - i += m->methodOffset(); - return i; -} - -// Parses a string of comma-separated types into QArgumentTypes. -// No normalization of the type names is performed. -static void argumentTypesFromString(const char *str, const char *end, - QArgumentTypeArray &types) -{ - Q_ASSERT(str <= end); - while (str != end) { - if (!types.isEmpty()) - ++str; // Skip comma - const char *begin = str; - int level = 0; - while (str != end && (level > 0 || *str != ',')) { - if (*str == '<') - ++level; - else if (*str == '>') - --level; - ++str; - } - types += QArgumentType(QByteArray(begin, str - begin)); - } -} - -// Given a method \a signature (e.g. "foo(int,double)"), this function -// populates the argument \a types array and returns the method name. -QByteArray QMetaObjectPrivate::decodeMethodSignature( - const char *signature, QArgumentTypeArray &types) -{ - Q_ASSERT(signature != 0); - const char *lparens = strchr(signature, '('); - if (!lparens) - return QByteArray(); - const char *rparens = strrchr(lparens + 1, ')'); - if (!rparens || *(rparens+1)) - return QByteArray(); - int nameLength = lparens - signature; - argumentTypesFromString(lparens + 1, rparens, types); - return QByteArray::fromRawData(signature, nameLength); -} - -/*! - Finds \a signal and returns its index; otherwise returns -1. - - This is the same as indexOfMethod(), except that it will return - -1 if the method exists but isn't a signal. - - Note that the \a signal has to be in normalized form, as returned - by normalizedSignature(). - - \sa indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset() -*/ -int QMetaObject::indexOfSignal(const char *signal) const -{ - const QMetaObject *m = this; - int i; - Q_ASSERT(priv(m->d.data)->revision >= 7); - QArgumentTypeArray types; - QByteArray name = QMetaObjectPrivate::decodeMethodSignature(signal, types); - i = QMetaObjectPrivate::indexOfSignalRelative(&m, name, types.size(), types.constData()); - if (i >= 0) - i += m->methodOffset(); - return i; -} - -/*! - \internal - Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object. - - \a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found -*/ -int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, - const QByteArray &name, int argc, - const QArgumentType *types) -{ - int i = indexOfMethodRelative(baseObject, name, argc, types); -#ifndef QT_NO_DEBUG - const QMetaObject *m = *baseObject; - if (i >= 0 && m && m->d.superdata) { - int conflict = indexOfMethod(m->d.superdata, name, argc, types); - if (conflict >= 0) { - QMetaMethod conflictMethod = m->d.superdata->method(conflict); - qWarning("QMetaObject::indexOfSignal: signal %s from %s redefined in %s", - conflictMethod.methodSignature().constData(), - rawStringData(m->d.superdata, 0), rawStringData(m, 0)); - } - } - #endif - return i; -} - -/*! - Finds \a slot and returns its index; otherwise returns -1. - - This is the same as indexOfMethod(), except that it will return - -1 if the method exists but isn't a slot. - - \sa indexOfMethod(), method(), methodCount(), methodOffset() -*/ -int QMetaObject::indexOfSlot(const char *slot) const -{ - const QMetaObject *m = this; - int i; - Q_ASSERT(priv(m->d.data)->revision >= 7); - QArgumentTypeArray types; - QByteArray name = QMetaObjectPrivate::decodeMethodSignature(slot, types); - i = QMetaObjectPrivate::indexOfSlotRelative(&m, name, types.size(), types.constData()); - if (i >= 0) - i += m->methodOffset(); - return i; -} - -// same as indexOfSignalRelative but for slots. -int QMetaObjectPrivate::indexOfSlotRelative(const QMetaObject **m, - const QByteArray &name, int argc, - const QArgumentType *types) -{ - return indexOfMethodRelative(m, name, argc, types); -} - -int QMetaObjectPrivate::indexOfSignal(const QMetaObject *m, const QByteArray &name, - int argc, const QArgumentType *types) -{ - int i = indexOfSignalRelative(&m, name, argc, types); - if (i >= 0) - i += m->methodOffset(); - return i; -} - -int QMetaObjectPrivate::indexOfSlot(const QMetaObject *m, const QByteArray &name, - int argc, const QArgumentType *types) -{ - int i = indexOfSlotRelative(&m, name, argc, types); - if (i >= 0) - i += m->methodOffset(); - return i; -} - -int QMetaObjectPrivate::indexOfMethod(const QMetaObject *m, const QByteArray &name, - int argc, const QArgumentType *types) -{ - int i = indexOfMethodRelative<0>(&m, name, argc, types); - if (i >= 0) - i += m->methodOffset(); - return i; -} - -int QMetaObjectPrivate::indexOfConstructor(const QMetaObject *m, const QByteArray &name, - int argc, const QArgumentType *types) -{ - for (int i = priv(m->d.data)->constructorCount-1; i >= 0; --i) { - int handle = priv(m->d.data)->constructorData + 5*i; - if (methodMatch(m, handle, name, argc, types)) - return i; - } - return -1; -} - -/*! - \internal - \since 5.0 - - Returns the signal offset for the class \a m; i.e., the index position - of the class's first signal. - - Similar to QMetaObject::methodOffset(), but non-signal methods are - excluded. -*/ -int QMetaObjectPrivate::signalOffset(const QMetaObject *m) -{ - Q_ASSERT(m != 0); - int offset = 0; - for (m = m->d.superdata; m; m = m->d.superdata) - offset += priv(m->d.data)->signalCount; - return offset; -} - -/*! - \internal - \since 5.0 - - Returns the number of signals for the class \a m, including the signals - for the base class. - - Similar to QMetaObject::methodCount(), but non-signal methods are - excluded. -*/ -int QMetaObjectPrivate::absoluteSignalCount(const QMetaObject *m) -{ - Q_ASSERT(m != 0); - int n = priv(m->d.data)->signalCount; - for (m = m->d.superdata; m; m = m->d.superdata) - n += priv(m->d.data)->signalCount; - return n; -} - -/*! - \internal - \since 5.0 - - Returns the index of the signal method \a m. - - Similar to QMetaMethod::methodIndex(), but non-signal methods are - excluded. -*/ -int QMetaObjectPrivate::signalIndex(const QMetaMethod &m) -{ - if (!m.mobj) - return -1; - return QMetaMethodPrivate::get(&m)->ownMethodIndex() + signalOffset(m.mobj); -} - -/*! - \internal - \since 5.0 - - Returns the signal for the given meta-object \a m at \a signal_index. - - It it different from QMetaObject::method(); the index should not include - non-signal methods. -*/ -QMetaMethod QMetaObjectPrivate::signal(const QMetaObject *m, int signal_index) -{ - QMetaMethod result; - if (signal_index < 0) - return result; - Q_ASSERT(m != 0); - int i = signal_index; - i -= signalOffset(m); - if (i < 0 && m->d.superdata) - return signal(m->d.superdata, signal_index); - - if (i >= 0 && i < priv(m->d.data)->signalCount) { - result.mobj = m; - result.handle = priv(m->d.data)->methodData + 5*i; - } - return result; -} - -/*! - \internal - - Returns \c true if the \a signalTypes and \a methodTypes are - compatible; otherwise returns \c false. -*/ -bool QMetaObjectPrivate::checkConnectArgs(int signalArgc, const QArgumentType *signalTypes, - int methodArgc, const QArgumentType *methodTypes) -{ - if (signalArgc < methodArgc) - return false; - for (int i = 0; i < methodArgc; ++i) { - if (signalTypes[i] != methodTypes[i]) - return false; - } - return true; -} - -/*! - \internal - - Returns \c true if the \a signal and \a method arguments are - compatible; otherwise returns \c false. -*/ -bool QMetaObjectPrivate::checkConnectArgs(const QMetaMethodPrivate *signal, - const QMetaMethodPrivate *method) -{ - if (signal->methodType() != QMetaMethod::Signal) - return false; - if (signal->parameterCount() < method->parameterCount()) - return false; - const QMetaObject *smeta = signal->enclosingMetaObject(); - const QMetaObject *rmeta = method->enclosingMetaObject(); - for (int i = 0; i < method->parameterCount(); ++i) { - uint sourceTypeInfo = signal->parameterTypeInfo(i); - uint targetTypeInfo = method->parameterTypeInfo(i); - if ((sourceTypeInfo & IsUnresolvedType) - || (targetTypeInfo & IsUnresolvedType)) { - QByteArray sourceName = typeNameFromTypeInfo(smeta, sourceTypeInfo); - QByteArray targetName = typeNameFromTypeInfo(rmeta, targetTypeInfo); - if (sourceName != targetName) - return false; - } else { - int sourceType = typeFromTypeInfo(smeta, sourceTypeInfo); - int targetType = typeFromTypeInfo(rmeta, targetTypeInfo); - if (sourceType != targetType) - return false; - } - } - return true; -} - -static const QMetaObject *QMetaObject_findMetaObject(const QMetaObject *self, const char *name) -{ - while (self) { - if (strcmp(rawStringData(self, 0), name) == 0) - return self; - if (self->d.relatedMetaObjects) { - Q_ASSERT(priv(self->d.data)->revision >= 2); - const QMetaObject * const *e = self->d.relatedMetaObjects; - if (e) { - while (*e) { - if (const QMetaObject *m =QMetaObject_findMetaObject((*e), name)) - return m; - ++e; - } - } - } - self = self->d.superdata; - } - return self; -} - -/*! - Finds enumerator \a name and returns its index; otherwise returns - -1. - - \sa enumerator(), enumeratorCount(), enumeratorOffset() -*/ -int QMetaObject::indexOfEnumerator(const char *name) const -{ - const QMetaObject *m = this; - while (m) { - const QMetaObjectPrivate *d = priv(m->d.data); - for (int i = d->enumeratorCount - 1; i >= 0; --i) { - const char *prop = rawStringData(m, m->d.data[d->enumeratorData + 4*i]); - if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) { - i += m->enumeratorOffset(); - return i; - } - } - m = m->d.superdata; - } - return -1; -} - -/*! - Finds property \a name and returns its index; otherwise returns - -1. - - \sa property(), propertyCount(), propertyOffset() -*/ -int QMetaObject::indexOfProperty(const char *name) const -{ - const QMetaObject *m = this; - while (m) { - const QMetaObjectPrivate *d = priv(m->d.data); - for (int i = d->propertyCount-1; i >= 0; --i) { - const char *prop = rawStringData(m, m->d.data[d->propertyData + 3*i]); - if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) { - i += m->propertyOffset(); - return i; - } - } - m = m->d.superdata; - } - - Q_ASSERT(priv(this->d.data)->revision >= 3); - if (priv(this->d.data)->flags & DynamicMetaObject) { - QAbstractDynamicMetaObject *me = - const_cast(static_cast(this)); - - return me->createProperty(name, 0); - } - - return -1; -} - -/*! - Finds class information item \a name and returns its index; - otherwise returns -1. - - \sa classInfo(), classInfoCount(), classInfoOffset() -*/ -int QMetaObject::indexOfClassInfo(const char *name) const -{ - int i = -1; - const QMetaObject *m = this; - while (m && i < 0) { - for (i = priv(m->d.data)->classInfoCount-1; i >= 0; --i) - if (strcmp(name, rawStringData(m, m->d.data[priv(m->d.data)->classInfoData + 2*i])) == 0) { - i += m->classInfoOffset(); - break; - } - m = m->d.superdata; - } - return i; -} - -/*! - \since 4.5 - - Returns the meta-data for the constructor with the given \a index. - - \sa constructorCount(), newInstance() -*/ -QMetaMethod QMetaObject::constructor(int index) const -{ - int i = index; - QMetaMethod result; - Q_ASSERT(priv(d.data)->revision >= 2); - if (i >= 0 && i < priv(d.data)->constructorCount) { - result.mobj = this; - result.handle = priv(d.data)->constructorData + 5*i; - } - return result; -} - -/*! - Returns the meta-data for the method with the given \a index. - - \sa methodCount(), methodOffset(), indexOfMethod() -*/ -QMetaMethod QMetaObject::method(int index) const -{ - int i = index; - i -= methodOffset(); - if (i < 0 && d.superdata) - return d.superdata->method(index); - - QMetaMethod result; - if (i >= 0 && i < priv(d.data)->methodCount) { - result.mobj = this; - result.handle = priv(d.data)->methodData + 5*i; - } - return result; -} - -/*! - Returns the meta-data for the enumerator with the given \a index. - - \sa enumeratorCount(), enumeratorOffset(), indexOfEnumerator() -*/ -QMetaEnum QMetaObject::enumerator(int index) const -{ - int i = index; - i -= enumeratorOffset(); - if (i < 0 && d.superdata) - return d.superdata->enumerator(index); - - QMetaEnum result; - if (i >= 0 && i < priv(d.data)->enumeratorCount) { - result.mobj = this; - result.handle = priv(d.data)->enumeratorData + 4*i; - } - return result; -} - -/*! - Returns the meta-data for the property with the given \a index. - If no such property exists, a null QMetaProperty is returned. - - \sa propertyCount(), propertyOffset(), indexOfProperty() -*/ -QMetaProperty QMetaObject::property(int index) const -{ - int i = index; - i -= propertyOffset(); - if (i < 0 && d.superdata) - return d.superdata->property(index); - - QMetaProperty result; - if (i >= 0 && i < priv(d.data)->propertyCount) { - int handle = priv(d.data)->propertyData + 3*i; - int flags = d.data[handle + 2]; - result.mobj = this; - result.handle = handle; - result.idx = i; - - if (flags & EnumOrFlag) { - const char *type = rawTypeNameFromTypeInfo(this, d.data[handle + 1]); - result.menum = enumerator(indexOfEnumerator(type)); - if (!result.menum.isValid()) { - const char *enum_name = type; - const char *scope_name = rawStringData(this, 0); - char *scope_buffer = 0; - - const char *colon = strrchr(enum_name, ':'); - // ':' will always appear in pairs - Q_ASSERT(colon <= enum_name || *(colon-1) == ':'); - if (colon > enum_name) { - int len = colon-enum_name-1; - scope_buffer = (char *)malloc(len+1); - memcpy(scope_buffer, enum_name, len); - scope_buffer[len] = '\0'; - scope_name = scope_buffer; - enum_name = colon+1; - } - - const QMetaObject *scope = 0; - if (qstrcmp(scope_name, "Qt") == 0) - scope = &QObject::staticQtMetaObject; - else - scope = QMetaObject_findMetaObject(this, scope_name); - if (scope) - result.menum = scope->enumerator(scope->indexOfEnumerator(enum_name)); - if (scope_buffer) - free(scope_buffer); - } - } - } - return result; -} - -/*! - \since 4.2 - - Returns the property that has the \c USER flag set to true. - - \sa QMetaProperty::isUser() -*/ -QMetaProperty QMetaObject::userProperty() const -{ - const int propCount = propertyCount(); - for (int i = propCount - 1; i >= 0; --i) { - const QMetaProperty prop = property(i); - if (prop.isUser()) - return prop; - } - return QMetaProperty(); -} - -/*! - Returns the meta-data for the item of class information with the - given \a index. - - Example: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 0 - - \sa classInfoCount(), classInfoOffset(), indexOfClassInfo() - */ -QMetaClassInfo QMetaObject::classInfo(int index) const -{ - int i = index; - i -= classInfoOffset(); - if (i < 0 && d.superdata) - return d.superdata->classInfo(index); - - QMetaClassInfo result; - if (i >= 0 && i < priv(d.data)->classInfoCount) { - result.mobj = this; - result.handle = priv(d.data)->classInfoData + 2*i; - } - return result; -} - -/*! - Returns \c true if the \a signal and \a method arguments are - compatible; otherwise returns \c false. - - Both \a signal and \a method are expected to be normalized. - - \sa normalizedSignature() -*/ -bool QMetaObject::checkConnectArgs(const char *signal, const char *method) -{ - const char *s1 = signal; - const char *s2 = method; - while (*s1++ != '(') { } // scan to first '(' - while (*s2++ != '(') { } - if (*s2 == ')' || qstrcmp(s1,s2) == 0) // method has no args or - return true; // exact match - int s1len = qstrlen(s1); - int s2len = qstrlen(s2); - if (s2len < s1len && strncmp(s1,s2,s2len-1)==0 && s1[s2len-1]==',') - return true; // method has less args - return false; -} - -/*! - \since 5.0 - \overload - - Returns \c true if the \a signal and \a method arguments are - compatible; otherwise returns \c false. -*/ -bool QMetaObject::checkConnectArgs(const QMetaMethod &signal, - const QMetaMethod &method) -{ - return QMetaObjectPrivate::checkConnectArgs( - QMetaMethodPrivate::get(&signal), - QMetaMethodPrivate::get(&method)); -} - -static void qRemoveWhitespace(const char *s, char *d) -{ - char last = 0; - while (*s && is_space(*s)) - s++; - while (*s) { - while (*s && !is_space(*s)) - last = *d++ = *s++; - while (*s && is_space(*s)) - s++; - if (*s && ((is_ident_char(*s) && is_ident_char(last)) - || ((*s == ':') && (last == '<')))) { - last = *d++ = ' '; - } - } - *d = '\0'; -} - -static char *qNormalizeType(char *d, int &templdepth, QByteArray &result) -{ - const char *t = d; - while (*d && (templdepth - || (*d != ',' && *d != ')'))) { - if (*d == '<') - ++templdepth; - if (*d == '>') - --templdepth; - ++d; - } - // "void" should only be removed if this is part of a signature that has - // an explicit void argument; e.g., "void foo(void)" --> "void foo()" - if (strncmp("void)", t, d - t + 1) != 0) - result += normalizeTypeInternal(t, d); - - return d; -} - - -/*! - \since 4.2 - - Normalizes a \a type. - - See QMetaObject::normalizedSignature() for a description on how - Qt normalizes. - - Example: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 1 - - \sa normalizedSignature() - */ -QByteArray QMetaObject::normalizedType(const char *type) -{ - QByteArray result; - - if (!type || !*type) - return result; - - QVarLengthArray stackbuf(qstrlen(type) + 1); - qRemoveWhitespace(type, stackbuf.data()); - int templdepth = 0; - qNormalizeType(stackbuf.data(), templdepth, result); - - return result; -} - -/*! - Normalizes the signature of the given \a method. - - Qt uses normalized signatures to decide whether two given signals - and slots are compatible. Normalization reduces whitespace to a - minimum, moves 'const' to the front where appropriate, removes - 'const' from value types and replaces const references with - values. - - \sa checkConnectArgs(), normalizedType() - */ -QByteArray QMetaObject::normalizedSignature(const char *method) -{ - QByteArray result; - if (!method || !*method) - return result; - int len = int(strlen(method)); - QVarLengthArray stackbuf(len + 1); - char *d = stackbuf.data(); - qRemoveWhitespace(method, d); - - result.reserve(len); - - int argdepth = 0; - int templdepth = 0; - while (*d) { - if (argdepth == 1) { - d = qNormalizeType(d, templdepth, result); - if (!*d) //most likely an invalid signature. - break; - } - if (*d == '(') - ++argdepth; - if (*d == ')') - --argdepth; - result += *d++; - } - - return result; -} - -enum { MaximumParamCount = 11 }; // up to 10 arguments + 1 return value - -/*! - Invokes the \a member (a signal or a slot name) on the object \a - obj. Returns \c true if the member could be invoked. Returns \c false - if there is no such member or the parameters did not match. - - The invocation can be either synchronous or asynchronous, - depending on \a type: - - \list - \li If \a type is Qt::DirectConnection, the member will be invoked immediately. - - \li If \a type is Qt::QueuedConnection, - a QEvent will be sent and the member is invoked as soon as the application - enters the main event loop. - - \li If \a type is Qt::BlockingQueuedConnection, the method will be invoked in - the same way as for Qt::QueuedConnection, except that the current thread - will block until the event is delivered. Using this connection type to - communicate between objects in the same thread will lead to deadlocks. - - \li If \a type is Qt::AutoConnection, the member is invoked - synchronously if \a obj lives in the same thread as the - caller; otherwise it will invoke the member asynchronously. - \endlist - - The return value of the \a member function call is placed in \a - ret. If the invocation is asynchronous, the return value cannot - be evaluated. You can pass up to ten arguments (\a val0, \a val1, - \a val2, \a val3, \a val4, \a val5, \a val6, \a val7, \a val8, - and \a val9) to the \a member function. - - QGenericArgument and QGenericReturnArgument are internal - helper classes. Because signals and slots can be dynamically - invoked, you must enclose the arguments using the Q_ARG() and - Q_RETURN_ARG() macros. Q_ARG() takes a type name and a - const reference of that type; Q_RETURN_ARG() takes a type name - and a non-const reference. - - You only need to pass the name of the signal or slot to this function, - not the entire signature. For example, to asynchronously invoke - the \l{QThread::quit()}{quit()} slot on a - QThread, use the following code: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 2 - - With asynchronous method invocations, the parameters must be of - types that are known to Qt's meta-object system, because Qt needs - to copy the arguments to store them in an event behind the - scenes. If you try to use a queued connection and get the error - message - - \snippet code/src_corelib_kernel_qmetaobject.cpp 3 - - call qRegisterMetaType() to register the data type before you - call invokeMethod(). - - To synchronously invoke the \c compute(QString, int, double) slot on - some arbitrary object \c obj retrieve its return value: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 4 - - If the "compute" slot does not take exactly one QString, one int - and one double in the specified order, the call will fail. - - \sa Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaMethod::invoke() -*/ -bool QMetaObject::invokeMethod(QObject *obj, - const char *member, - Qt::ConnectionType type, - QGenericReturnArgument ret, - QGenericArgument val0, - QGenericArgument val1, - QGenericArgument val2, - QGenericArgument val3, - QGenericArgument val4, - QGenericArgument val5, - QGenericArgument val6, - QGenericArgument val7, - QGenericArgument val8, - QGenericArgument val9) -{ - if (!obj) - return false; - - QVarLengthArray sig; - int len = qstrlen(member); - if (len <= 0) - return false; - sig.append(member, len); - sig.append('('); - - const char *typeNames[] = {ret.name(), val0.name(), val1.name(), val2.name(), val3.name(), - val4.name(), val5.name(), val6.name(), val7.name(), val8.name(), - val9.name()}; - - int paramCount; - for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) { - len = qstrlen(typeNames[paramCount]); - if (len <= 0) - break; - sig.append(typeNames[paramCount], len); - sig.append(','); - } - if (paramCount == 1) - sig.append(')'); // no parameters - else - sig[sig.size() - 1] = ')'; - sig.append('\0'); - - const QMetaObject *meta = obj->metaObject(); - int idx = meta->indexOfMethod(sig.constData()); - if (idx < 0) { - QByteArray norm = QMetaObject::normalizedSignature(sig.constData()); - idx = meta->indexOfMethod(norm.constData()); - } - - if (idx < 0 || idx >= meta->methodCount()) { - qWarning("QMetaObject::invokeMethod: No such method %s::%s", - meta->className(), sig.constData()); - return false; - } - QMetaMethod method = meta->method(idx); - return method.invoke(obj, type, ret, - val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); -} - -/*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, - QGenericReturnArgument ret, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()); - \overload invokeMethod() - - This overload always invokes the member using the connection type Qt::AutoConnection. -*/ - -/*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, - Qt::ConnectionType type, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) - - \overload invokeMethod() - - This overload can be used if the return value of the member is of no interest. -*/ - -/*! - \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) - - \overload invokeMethod() - - This overload invokes the member using the connection type Qt::AutoConnection and - ignores return values. -*/ - -/*! - \class QMetaMethod - \inmodule QtCore - - \brief The QMetaMethod class provides meta-data about a member - function. - - \ingroup objectmodel - - A QMetaMethod has a methodType(), a methodSignature(), a list of - parameterTypes() and parameterNames(), a return typeName(), a - tag(), and an access() specifier. You can use invoke() to invoke - the method on an arbitrary QObject. - - \sa QMetaObject, QMetaEnum, QMetaProperty, {Qt's Property System} -*/ - -/*! - \enum QMetaMethod::Attributes - - \internal - - \value Compatibility - \value Cloned - \value Scriptable -*/ - -/*! - \fn bool QMetaMethod::isValid() const - \since 5.0 - - Returns \c true if this method is valid (can be introspected and - invoked), otherwise returns \c false. -*/ - -/*! \fn bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) - \since 5.0 - \relates QMetaMethod - \overload - - Returns \c true if method \a m1 is equal to method \a m2, - otherwise returns \c false. -*/ - -/*! \fn bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) - \since 5.0 - \relates QMetaMethod - \overload - - Returns \c true if method \a m1 is not equal to method \a m2, - otherwise returns \c false. -*/ - -/*! - \fn const QMetaObject *QMetaMethod::enclosingMetaObject() const - \internal -*/ - -/*! - \enum QMetaMethod::MethodType - - \value Method The function is a plain member function. - \value Signal The function is a signal. - \value Slot The function is a slot. - \value Constructor The function is a constructor. -*/ - -/*! - \fn QMetaMethod::QMetaMethod() - \internal -*/ - -/*! - \macro Q_METAMETHOD_INVOKE_MAX_ARGS - \relates QMetaMethod - - Equals maximum number of arguments available for - execution of the method via QMetaMethod::invoke() - */ - -QByteArray QMetaMethodPrivate::signature() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - QByteArray result; - result.reserve(256); - result += name(); - result += '('; - QList argTypes = parameterTypes(); - for (int i = 0; i < argTypes.size(); ++i) { - if (i) - result += ','; - result += argTypes.at(i); - } - result += ')'; - return result; -} - -QByteArray QMetaMethodPrivate::name() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return stringData(mobj, mobj->d.data[handle]); -} - -int QMetaMethodPrivate::typesDataIndex() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return mobj->d.data[handle + 2]; -} - -const char *QMetaMethodPrivate::rawReturnTypeName() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - uint typeInfo = mobj->d.data[typesDataIndex()]; - if (typeInfo & IsUnresolvedType) - return rawStringData(mobj, typeInfo & TypeNameIndexMask); - else - return QMetaType::typeName(typeInfo); -} - -int QMetaMethodPrivate::returnType() const -{ - return parameterType(-1); -} - -int QMetaMethodPrivate::parameterCount() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return mobj->d.data[handle + 1]; -} - -int QMetaMethodPrivate::parametersDataIndex() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return typesDataIndex() + 1; -} - -uint QMetaMethodPrivate::parameterTypeInfo(int index) const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return mobj->d.data[parametersDataIndex() + index]; -} - -int QMetaMethodPrivate::parameterType(int index) const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return typeFromTypeInfo(mobj, parameterTypeInfo(index)); -} - -void QMetaMethodPrivate::getParameterTypes(int *types) const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - int dataIndex = parametersDataIndex(); - int argc = parameterCount(); - for (int i = 0; i < argc; ++i) { - int id = typeFromTypeInfo(mobj, mobj->d.data[dataIndex++]); - *(types++) = id; - } -} - -QList QMetaMethodPrivate::parameterTypes() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - int argc = parameterCount(); - QList list; - list.reserve(argc); - int paramsIndex = parametersDataIndex(); - for (int i = 0; i < argc; ++i) - list += typeNameFromTypeInfo(mobj, mobj->d.data[paramsIndex + i]); - return list; -} - -QList QMetaMethodPrivate::parameterNames() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - int argc = parameterCount(); - QList list; - list.reserve(argc); - int namesIndex = parametersDataIndex() + argc; - for (int i = 0; i < argc; ++i) - list += stringData(mobj, mobj->d.data[namesIndex + i]); - return list; -} - -QByteArray QMetaMethodPrivate::tag() const -{ - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - return stringData(mobj, mobj->d.data[handle + 3]); -} - -int QMetaMethodPrivate::ownMethodIndex() const -{ - // recompute the methodIndex by reversing the arithmetic in QMetaObject::property() - return (handle - priv(mobj->d.data)->methodData) / 5; -} - -/*! - \since 5.0 - - Returns the signature of this method (e.g., - \c{setValue(double)}). - - \sa parameterTypes(), parameterNames() -*/ -QByteArray QMetaMethod::methodSignature() const -{ - if (!mobj) - return QByteArray(); - return QMetaMethodPrivate::get(this)->signature(); -} - -/*! - \since 5.0 - - Returns the name of this method. - - \sa methodSignature(), parameterCount() -*/ -QByteArray QMetaMethod::name() const -{ - if (!mobj) - return QByteArray(); - return QMetaMethodPrivate::get(this)->name(); -} - -/*! - \since 5.0 - - Returns the return type of this method. - - The return value is one of the types that are registered - with QMetaType, or QMetaType::UnknownType if the type is not registered. - - \sa parameterType(), QMetaType, typeName() -*/ -int QMetaMethod::returnType() const - { - if (!mobj) - return QMetaType::UnknownType; - return QMetaMethodPrivate::get(this)->returnType(); -} - -/*! - \since 5.0 - - Returns the number of parameters of this method. - - \sa parameterType(), parameterNames() -*/ -int QMetaMethod::parameterCount() const -{ - if (!mobj) - return 0; - return QMetaMethodPrivate::get(this)->parameterCount(); -} - -/*! - \since 5.0 - - Returns the type of the parameter at the given \a index. - - The return value is one of the types that are registered - with QMetaType, or QMetaType::UnknownType if the type is not registered. - - \sa parameterCount(), returnType(), QMetaType -*/ -int QMetaMethod::parameterType(int index) const -{ - if (!mobj || index < 0) - return QMetaType::UnknownType; - if (index >= QMetaMethodPrivate::get(this)->parameterCount()) - return QMetaType::UnknownType; - - int type = QMetaMethodPrivate::get(this)->parameterType(index); - if (type != QMetaType::UnknownType) - return type; - - void *argv[] = { &type, &index }; - mobj->static_metacall(QMetaObject::RegisterMethodArgumentMetaType, QMetaMethodPrivate::get(this)->ownMethodIndex(), argv); - if (type != -1) - return type; - return QMetaType::UnknownType; -} - -/*! - \since 5.0 - \internal - - Gets the parameter \a types of this method. The storage - for \a types must be able to hold parameterCount() items. - - \sa parameterCount(), returnType(), parameterType() -*/ -void QMetaMethod::getParameterTypes(int *types) const -{ - if (!mobj) - return; - QMetaMethodPrivate::get(this)->getParameterTypes(types); -} - -/*! - Returns a list of parameter types. - - \sa parameterNames(), methodSignature() -*/ -QList QMetaMethod::parameterTypes() const -{ - if (!mobj) - return QList(); - return QMetaMethodPrivate::get(this)->parameterTypes(); -} - -/*! - Returns a list of parameter names. - - \sa parameterTypes(), methodSignature() -*/ -QList QMetaMethod::parameterNames() const -{ - QList list; - if (!mobj) - return list; - return QMetaMethodPrivate::get(this)->parameterNames(); -} - - -/*! - Returns the return type name of this method. - - \sa returnType(), QMetaType::type() -*/ -const char *QMetaMethod::typeName() const -{ - if (!mobj) - return 0; - return QMetaMethodPrivate::get(this)->rawReturnTypeName(); -} - -/*! - Returns the tag associated with this method. - - Tags are special macros recognized by \c moc that make it - possible to add extra information about a method. - - Tag information can be added in the following - way in the function declaration: - - \code - #ifndef Q_MOC_RUN - // define the tag text - # define THISISTESTTAG - #endif - ... - private slots: - THISISTESTTAG void testFunc(); - \endcode - - and the information can be accessed by using: - - \code - MainWindow win; - win.show(); - - int functionIndex = win.metaObject()->indexOfSlot("testFunc()"); - QMetaMethod mm = metaObject()->method(functionIndex); - qDebug() << mm.tag(); // prints THISISTESTTAG - \endcode - - For the moment, \c moc will extract and record all tags, but it will not - handle any of them specially. - - \note Since Qt 5.0, \c moc expands preprocessor macros, so it is necessary - to surround the definition with \c #ifndef \c Q_MOC_RUN, as shown in the - example above. This was not required in Qt 4. The code as shown above works - with Qt 4 too. -*/ -const char *QMetaMethod::tag() const -{ - if (!mobj) - return 0; - return QMetaMethodPrivate::get(this)->tag().constData(); -} - - -/*! - \internal - */ -int QMetaMethod::attributes() const -{ - if (!mobj) - return false; - return ((mobj->d.data[handle + 4])>>4); -} - -/*! - \since 4.6 - - Returns this method's index. -*/ -int QMetaMethod::methodIndex() const -{ - if (!mobj) - return -1; - return QMetaMethodPrivate::get(this)->ownMethodIndex() + mobj->methodOffset(); -} - -// This method has been around for a while, but the documentation was marked \internal until 5.1 -/*! - \since 5.1 - Returns the method revision if one was - specified by Q_REVISION, otherwise returns 0. - */ -int QMetaMethod::revision() const -{ - if (!mobj) - return 0; - if ((QMetaMethod::Access)(mobj->d.data[handle + 4] & MethodRevisioned)) { - int offset = priv(mobj->d.data)->methodData - + priv(mobj->d.data)->methodCount * 5 - + QMetaMethodPrivate::get(this)->ownMethodIndex(); - return mobj->d.data[offset]; - } - return 0; -} - -/*! - Returns the access specification of this method (private, - protected, or public). - - Signals are always protected, meaning that you can only emit them - from the class or from a subclass. - - \sa methodType() -*/ -QMetaMethod::Access QMetaMethod::access() const -{ - if (!mobj) - return Private; - return (QMetaMethod::Access)(mobj->d.data[handle + 4] & AccessMask); -} - -/*! - Returns the type of this method (signal, slot, or method). - - \sa access() -*/ -QMetaMethod::MethodType QMetaMethod::methodType() const -{ - if (!mobj) - return QMetaMethod::Method; - return (QMetaMethod::MethodType)((mobj->d.data[handle + 4] & MethodTypeMask)>>2); -} - -/*! - \fn QMetaMethod QMetaMethod::fromSignal(PointerToMemberFunction signal) - \since 5.0 - - Returns the meta-method that corresponds to the given \a signal, or an - invalid QMetaMethod if \a signal is not a signal of the class. - - Example: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 9 -*/ - -/*! - \internal - - Implementation of the fromSignal() function. - - \a metaObject is the class's meta-object - \a signal is a pointer to a pointer to a member signal of the class -*/ -QMetaMethod QMetaMethod::fromSignalImpl(const QMetaObject *metaObject, void **signal) -{ - int i = -1; - void *args[] = { &i, signal }; - QMetaMethod result; - for (const QMetaObject *m = metaObject; m; m = m->d.superdata) { - m->static_metacall(QMetaObject::IndexOfMethod, 0, args); - if (i >= 0) { - result.mobj = m; - result.handle = priv(m->d.data)->methodData + 5*i; - break; - } - } - return result; -} - -/*! - Invokes this method on the object \a object. Returns \c true if the member could be invoked. - Returns \c false if there is no such member or the parameters did not match. - - The invocation can be either synchronous or asynchronous, depending on the - \a connectionType: - - \list - \li If \a connectionType is Qt::DirectConnection, the member will be invoked immediately. - - \li If \a connectionType is Qt::QueuedConnection, - a QEvent will be posted and the member is invoked as soon as the application - enters the main event loop. - - \li If \a connectionType is Qt::AutoConnection, the member is invoked - synchronously if \a object lives in the same thread as the - caller; otherwise it will invoke the member asynchronously. - \endlist - - The return value of this method call is placed in \a - returnValue. If the invocation is asynchronous, the return value cannot - be evaluated. You can pass up to ten arguments (\a val0, \a val1, - \a val2, \a val3, \a val4, \a val5, \a val6, \a val7, \a val8, - and \a val9) to this method call. - - QGenericArgument and QGenericReturnArgument are internal - helper classes. Because signals and slots can be dynamically - invoked, you must enclose the arguments using the Q_ARG() and - Q_RETURN_ARG() macros. Q_ARG() takes a type name and a - const reference of that type; Q_RETURN_ARG() takes a type name - and a non-const reference. - - To asynchronously invoke the - \l{QPushButton::animateClick()}{animateClick()} slot on a - QPushButton: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 6 - - With asynchronous method invocations, the parameters must be of - types that are known to Qt's meta-object system, because Qt needs - to copy the arguments to store them in an event behind the - scenes. If you try to use a queued connection and get the error - message - - \snippet code/src_corelib_kernel_qmetaobject.cpp 7 - - call qRegisterMetaType() to register the data type before you - call QMetaMethod::invoke(). - - To synchronously invoke the \c compute(QString, int, double) slot on - some arbitrary object \c obj retrieve its return value: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 8 - - QMetaObject::normalizedSignature() is used here to ensure that the format - of the signature is what invoke() expects. E.g. extra whitespace is - removed. - - If the "compute" slot does not take exactly one QString, one int - and one double in the specified order, the call will fail. - - \warning this method will not test the validity of the arguments: \a object - must be an instance of the class of the QMetaObject of which this QMetaMethod - has been constructed with. The arguments must have the same type as the ones - expected by the method, else, the behaviour is undefined. - - \sa Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaObject::invokeMethod() -*/ -bool QMetaMethod::invoke(QObject *object, - Qt::ConnectionType connectionType, - QGenericReturnArgument returnValue, - QGenericArgument val0, - QGenericArgument val1, - QGenericArgument val2, - QGenericArgument val3, - QGenericArgument val4, - QGenericArgument val5, - QGenericArgument val6, - QGenericArgument val7, - QGenericArgument val8, - QGenericArgument val9) const -{ - if (!object || !mobj) - return false; - - Q_ASSERT(mobj->cast(object)); - - // check return type - if (returnValue.data()) { - const char *retType = typeName(); - if (qstrcmp(returnValue.name(), retType) != 0) { - // normalize the return value as well - QByteArray normalized = QMetaObject::normalizedType(returnValue.name()); - if (qstrcmp(normalized.constData(), retType) != 0) { - // String comparison failed, try compare the metatype. - int t = returnType(); - if (t == QMetaType::UnknownType || t != QMetaType::type(normalized)) - return false; - } - } - } - - // check argument count (we don't allow invoking a method if given too few arguments) - const char *typeNames[] = { - returnValue.name(), - val0.name(), - val1.name(), - val2.name(), - val3.name(), - val4.name(), - val5.name(), - val6.name(), - val7.name(), - val8.name(), - val9.name() - }; - int paramCount; - for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) { - if (qstrlen(typeNames[paramCount]) <= 0) - break; - } - if (paramCount <= QMetaMethodPrivate::get(this)->parameterCount()) - return false; - - // check connection type - QThread *currentThread = QThread::currentThread(); - QThread *objectThread = object->thread(); - if (connectionType == Qt::AutoConnection) { - connectionType = currentThread == objectThread - ? Qt::DirectConnection - : Qt::QueuedConnection; - } - -#ifdef QT_NO_THREAD - if (connectionType == Qt::BlockingQueuedConnection) { - connectionType = Qt::DirectConnection; - } -#endif - - // invoke! - void *param[] = { - returnValue.data(), - val0.data(), - val1.data(), - val2.data(), - val3.data(), - val4.data(), - val5.data(), - val6.data(), - val7.data(), - val8.data(), - val9.data() - }; - int idx_relative = QMetaMethodPrivate::get(this)->ownMethodIndex(); - int idx_offset = mobj->methodOffset(); - Q_ASSERT(QMetaObjectPrivate::get(mobj)->revision >= 6); - QObjectPrivate::StaticMetaCallFunction callFunction = mobj->d.static_metacall; - - if (connectionType == Qt::DirectConnection) { - if (callFunction) { - callFunction(object, QMetaObject::InvokeMetaMethod, idx_relative, param); - return true; - } else { - return QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, idx_relative + idx_offset, param) < 0; - } - } else if (connectionType == Qt::QueuedConnection) { - if (returnValue.data()) { - qWarning("QMetaMethod::invoke: Unable to invoke methods with return values in " - "queued connections"); - return false; - } - - int nargs = 1; // include return type - void **args = (void **) malloc(paramCount * sizeof(void *)); - Q_CHECK_PTR(args); - int *types = (int *) malloc(paramCount * sizeof(int)); - Q_CHECK_PTR(types); - types[0] = 0; // return type - args[0] = 0; - - for (int i = 1; i < paramCount; ++i) { - types[i] = QMetaType::type(typeNames[i]); - if (types[i] != QMetaType::UnknownType) { - args[i] = QMetaType::create(types[i], param[i]); - ++nargs; - } else if (param[i]) { - // Try to register the type and try again before reporting an error. - void *argv[] = { &types[i], &i }; - QMetaObject::metacall(object, QMetaObject::RegisterMethodArgumentMetaType, - idx_relative + idx_offset, argv); - if (types[i] == -1) { - qWarning("QMetaMethod::invoke: Unable to handle unregistered datatype '%s'", - typeNames[i]); - for (int x = 1; x < i; ++x) { - if (types[x] && args[x]) - QMetaType::destroy(types[x], args[x]); - } - free(types); - free(args); - return false; - } - } - } - - QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction, - 0, -1, nargs, types, args)); - } else { // blocking queued connection -#ifndef QT_NO_THREAD - if (currentThread == objectThread) { - qWarning("QMetaMethod::invoke: Dead lock detected in " - "BlockingQueuedConnection: Receiver is %s(%p)", - mobj->className(), object); - } - - QSemaphore semaphore; - QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction, - 0, -1, 0, 0, param, &semaphore)); - semaphore.acquire(); -#endif // QT_NO_THREAD - } - return true; -} - -/*! \fn bool QMetaMethod::invoke(QObject *object, - QGenericReturnArgument returnValue, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const - \overload invoke() - - This overload always invokes this method using the connection type Qt::AutoConnection. -*/ - -/*! \fn bool QMetaMethod::invoke(QObject *object, - Qt::ConnectionType connectionType, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const - - \overload invoke() - - This overload can be used if the return value of the member is of no interest. -*/ - -/*! - \fn bool QMetaMethod::invoke(QObject *object, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const - - \overload invoke() - - This overload invokes this method using the - connection type Qt::AutoConnection and ignores return values. -*/ - -/*! - \class QMetaEnum - \inmodule QtCore - \brief The QMetaEnum class provides meta-data about an enumerator. - - \ingroup objectmodel - - Use name() for the enumerator's name. The enumerator's keys (names - of each enumerated item) are returned by key(); use keyCount() to find - the number of keys. isFlag() returns whether the enumerator is - meant to be used as a flag, meaning that its values can be combined - using the OR operator. - - The conversion functions keyToValue(), valueToKey(), keysToValue(), - and valueToKeys() allow conversion between the integer - representation of an enumeration or set value and its literal - representation. The scope() function returns the class scope this - enumerator was declared in. - - \sa QMetaObject, QMetaMethod, QMetaProperty -*/ - -/*! - \fn bool QMetaEnum::isValid() const - - Returns \c true if this enum is valid (has a name); otherwise returns - false. - - \sa name() -*/ - -/*! - \fn const QMetaObject *QMetaEnum::enclosingMetaObject() const - \internal -*/ - - -/*! - \fn QMetaEnum::QMetaEnum() - \internal -*/ - -/*! - Returns the name of the enumerator (without the scope). - - For example, the Qt::AlignmentFlag enumeration has \c - AlignmentFlag as the name and \l Qt as the scope. - - \sa isValid(), scope() -*/ -const char *QMetaEnum::name() const -{ - if (!mobj) - return 0; - return rawStringData(mobj, mobj->d.data[handle]); -} - -/*! - Returns the number of keys. - - \sa key() -*/ -int QMetaEnum::keyCount() const -{ - if (!mobj) - return 0; - return mobj->d.data[handle + 2]; -} - - -/*! - Returns the key with the given \a index, or 0 if no such key exists. - - \sa keyCount(), value(), valueToKey() -*/ -const char *QMetaEnum::key(int index) const -{ - if (!mobj) - return 0; - int count = mobj->d.data[handle + 2]; - int data = mobj->d.data[handle + 3]; - if (index >= 0 && index < count) - return rawStringData(mobj, mobj->d.data[data + 2*index]); - return 0; -} - -/*! - Returns the value with the given \a index; or returns -1 if there - is no such value. - - \sa keyCount(), key(), keyToValue() -*/ -int QMetaEnum::value(int index) const -{ - if (!mobj) - return 0; - int count = mobj->d.data[handle + 2]; - int data = mobj->d.data[handle + 3]; - if (index >= 0 && index < count) - return mobj->d.data[data + 2*index + 1]; - return -1; -} - - -/*! - Returns \c true if this enumerator is used as a flag; otherwise returns - false. - - When used as flags, enumerators can be combined using the OR - operator. - - \sa keysToValue(), valueToKeys() -*/ -bool QMetaEnum::isFlag() const -{ - return mobj && mobj->d.data[handle + 1]; -} - - -/*! - Returns the scope this enumerator was declared in. - - For example, the Qt::AlignmentFlag enumeration has \c Qt as - the scope and \c AlignmentFlag as the name. - - \sa name() -*/ -const char *QMetaEnum::scope() const -{ - return mobj?rawStringData(mobj, 0) : 0; -} - -/*! - Returns the integer value of the given enumeration \a key, or -1 - if \a key is not defined. - - If \a key is not defined, *\a{ok} is set to false; otherwise - *\a{ok} is set to true. - - For flag types, use keysToValue(). - - \sa valueToKey(), isFlag(), keysToValue() -*/ -int QMetaEnum::keyToValue(const char *key, bool *ok) const -{ - if (ok != 0) - *ok = false; - if (!mobj || !key) - return -1; - uint scope = 0; - const char *qualified_key = key; - const char *s = key + qstrlen(key); - while (s > key && *s != ':') - --s; - if (s > key && *(s-1)==':') { - scope = s - key - 1; - key += scope + 2; - } - int count = mobj->d.data[handle + 2]; - int data = mobj->d.data[handle + 3]; - for (int i = 0; i < count; ++i) { - if ((!scope || (stringSize(mobj, 0) == int(scope) && strncmp(qualified_key, rawStringData(mobj, 0), scope) == 0)) - && strcmp(key, rawStringData(mobj, mobj->d.data[data + 2*i])) == 0) { - if (ok != 0) - *ok = true; - return mobj->d.data[data + 2*i + 1]; - } - } - return -1; -} - -/*! - Returns the string that is used as the name of the given - enumeration \a value, or 0 if \a value is not defined. - - For flag types, use valueToKeys(). - - \sa isFlag(), valueToKeys() -*/ -const char* QMetaEnum::valueToKey(int value) const -{ - if (!mobj) - return 0; - int count = mobj->d.data[handle + 2]; - int data = mobj->d.data[handle + 3]; - for (int i = 0; i < count; ++i) - if (value == (int)mobj->d.data[data + 2*i + 1]) - return rawStringData(mobj, mobj->d.data[data + 2*i]); - return 0; -} - -/*! - Returns the value derived from combining together the values of - the \a keys using the OR operator, or -1 if \a keys is not - defined. Note that the strings in \a keys must be '|'-separated. - - If \a keys is not defined, *\a{ok} is set to false; otherwise - *\a{ok} is set to true. - - \sa isFlag(), valueToKey(), valueToKeys() -*/ -int QMetaEnum::keysToValue(const char *keys, bool *ok) const -{ - if (ok != 0) - *ok = false; - if (!mobj || !keys) - return -1; - if (ok != 0) - *ok = true; - QStringList l = QString::fromLatin1(keys).split(QLatin1Char('|')); - if (l.isEmpty()) - return 0; - //#### TODO write proper code, do not use QStringList - int value = 0; - int count = mobj->d.data[handle + 2]; - int data = mobj->d.data[handle + 3]; - for (int li = 0; li < l.size(); ++li) { - QString trimmed = l.at(li).trimmed(); - QByteArray qualified_key = trimmed.toLatin1(); - const char *key = qualified_key.constData(); - uint scope = 0; - const char *s = key + qstrlen(key); - while (s > key && *s != ':') - --s; - if (s > key && *(s-1)==':') { - scope = s - key - 1; - key += scope + 2; - } - int i; - for (i = count-1; i >= 0; --i) - if ((!scope || (stringSize(mobj, 0) == int(scope) && strncmp(qualified_key.constData(), rawStringData(mobj, 0), scope) == 0)) - && strcmp(key, rawStringData(mobj, mobj->d.data[data + 2*i])) == 0) { - value |= mobj->d.data[data + 2*i + 1]; - break; - } - if (i < 0) { - if (ok != 0) - *ok = false; - value |= -1; - } - } - return value; -} - -/*! - Returns a byte array of '|'-separated keys that represents the - given \a value. - - \sa isFlag(), valueToKey(), keysToValue() -*/ -QByteArray QMetaEnum::valueToKeys(int value) const -{ - QByteArray keys; - if (!mobj) - return keys; - int count = mobj->d.data[handle + 2]; - int data = mobj->d.data[handle + 3]; - int v = value; - for(int i = 0; i < count; i++) { - int k = mobj->d.data[data + 2*i + 1]; - if ((k != 0 && (v & k) == k ) || (k == value)) { - v = v & ~k; - if (!keys.isEmpty()) - keys += '|'; - keys += stringData(mobj, mobj->d.data[data + 2*i]); - } - } - return keys; -} - -static QByteArray qualifiedName(const QMetaEnum &e) -{ - return QByteArray(e.scope()) + "::" + e.name(); -} - -/*! - \class QMetaProperty - \inmodule QtCore - \brief The QMetaProperty class provides meta-data about a property. - - \ingroup objectmodel - - Property meta-data is obtained from an object's meta-object. See - QMetaObject::property() and QMetaObject::propertyCount() for - details. - - \section1 Property Meta-Data - - A property has a name() and a type(), as well as various - attributes that specify its behavior: isReadable(), isWritable(), - isDesignable(), isScriptable(), revision(), and isStored(). - - If the property is an enumeration, isEnumType() returns \c true; if the - property is an enumeration that is also a flag (i.e. its values - can be combined using the OR operator), isEnumType() and - isFlagType() both return true. The enumerator for these types is - available from enumerator(). - - The property's values are set and retrieved with read(), write(), - and reset(); they can also be changed through QObject's set and get - functions. See QObject::setProperty() and QObject::property() for - details. - - \section1 Copying and Assignment - - QMetaProperty objects can be copied by value. However, each copy will - refer to the same underlying property meta-data. - - \sa QMetaObject, QMetaEnum, QMetaMethod, {Qt's Property System} -*/ - -/*! - \fn bool QMetaProperty::isValid() const - - Returns \c true if this property is valid (readable); otherwise - returns \c false. - - \sa isReadable() -*/ - -/*! - \fn const QMetaObject *QMetaProperty::enclosingMetaObject() const - \internal -*/ - -/*! - \internal -*/ -QMetaProperty::QMetaProperty() - : mobj(0), handle(0), idx(0) -{ -} - - -/*! - Returns this property's name. - - \sa type(), typeName() -*/ -const char *QMetaProperty::name() const -{ - if (!mobj) - return 0; - int handle = priv(mobj->d.data)->propertyData + 3*idx; - return rawStringData(mobj, mobj->d.data[handle]); -} - -/*! - Returns the name of this property's type. - - \sa type(), name() -*/ -const char *QMetaProperty::typeName() const -{ - if (!mobj) - return 0; - int handle = priv(mobj->d.data)->propertyData + 3*idx; - return rawTypeNameFromTypeInfo(mobj, mobj->d.data[handle + 1]); -} - -/*! - Returns this property's type. The return value is one - of the values of the QVariant::Type enumeration. - - \sa userType(), typeName(), name() -*/ -QVariant::Type QMetaProperty::type() const -{ - if (!mobj) - return QVariant::Invalid; - int handle = priv(mobj->d.data)->propertyData + 3*idx; - - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - uint type = typeFromTypeInfo(mobj, mobj->d.data[handle + 1]); - if (type >= QMetaType::User) - return QVariant::UserType; - if (type != QMetaType::UnknownType) - return QVariant::Type(type); - if (isEnumType()) { - int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); - if (enumMetaTypeId == QMetaType::UnknownType) - return QVariant::Int; - } -#ifdef QT_COORD_TYPE - // qreal metatype must be resolved at runtime. - if (strcmp(typeName(), "qreal") == 0) - return QVariant::Type(qMetaTypeId()); -#endif - - return QVariant::UserType; -} - -/*! - \since 4.2 - - Returns this property's user type. The return value is one - of the values that are registered with QMetaType, or QMetaType::UnknownType if - the type is not registered. - - \sa type(), QMetaType, typeName() - */ -int QMetaProperty::userType() const -{ - if (!mobj) - return QMetaType::UnknownType; - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - int handle = priv(mobj->d.data)->propertyData + 3*idx; - int type = typeFromTypeInfo(mobj, mobj->d.data[handle + 1]); - if (type != QMetaType::UnknownType) - return type; - if (isEnumType()) { - type = QMetaType::type(qualifiedName(menum)); - if (type == QMetaType::UnknownType) { - void *argv[] = { &type }; - mobj->static_metacall(QMetaObject::RegisterPropertyMetaType, idx, argv); - if (type == -1 || type == QMetaType::UnknownType) - return QVariant::Int; // Match behavior of QMetaType::type() - } - return type; - } - type = QMetaType::type(typeName()); - if (type != QMetaType::UnknownType) - return type; - void *argv[] = { &type }; - mobj->static_metacall(QMetaObject::RegisterPropertyMetaType, idx, argv); - if (type != -1) - return type; - return QMetaType::UnknownType; -} - -/*! - \since 4.6 - - Returns this property's index. -*/ -int QMetaProperty::propertyIndex() const -{ - if (!mobj) - return -1; - return idx + mobj->propertyOffset(); -} - -/*! - Returns \c true if the property's type is an enumeration value that - is used as a flag; otherwise returns \c false. - - Flags can be combined using the OR operator. A flag type is - implicitly also an enum type. - - \sa isEnumType(), enumerator(), QMetaEnum::isFlag() -*/ - -bool QMetaProperty::isFlagType() const -{ - return isEnumType() && menum.isFlag(); -} - -/*! - Returns \c true if the property's type is an enumeration value; - otherwise returns \c false. - - \sa enumerator(), isFlagType() -*/ -bool QMetaProperty::isEnumType() const -{ - if (!mobj) - return false; - int handle = priv(mobj->d.data)->propertyData + 3*idx; - int flags = mobj->d.data[handle + 2]; - return (flags & EnumOrFlag) && menum.name(); -} - -/*! - \internal - - Returns \c true if the property has a C++ setter function that - follows Qt's standard "name" / "setName" pattern. Designer and uic - query hasStdCppSet() in order to avoid expensive - QObject::setProperty() calls. All properties in Qt [should] follow - this pattern. -*/ -bool QMetaProperty::hasStdCppSet() const -{ - if (!mobj) - return false; - int handle = priv(mobj->d.data)->propertyData + 3*idx; - int flags = mobj->d.data[handle + 2]; - return (flags & StdCppSet); -} - -/*! - Returns the enumerator if this property's type is an enumerator - type; otherwise the returned value is undefined. - - \sa isEnumType(), isFlagType() -*/ -QMetaEnum QMetaProperty::enumerator() const -{ - return menum; -} - -/*! - Reads the property's value from the given \a object. Returns the value - if it was able to read it; otherwise returns an invalid variant. - - \sa write(), reset(), isReadable() -*/ -QVariant QMetaProperty::read(const QObject *object) const -{ - if (!object || !mobj) - return QVariant(); - - uint t = QVariant::Int; - if (isEnumType()) { - /* - try to create a QVariant that can be converted to this enum - type (only works if the enum has already been registered - with QMetaType) - */ - int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); - if (enumMetaTypeId != QMetaType::UnknownType) - t = enumMetaTypeId; - } else { - int handle = priv(mobj->d.data)->propertyData + 3*idx; - const char *typeName = 0; - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - uint typeInfo = mobj->d.data[handle + 1]; - if (!(typeInfo & IsUnresolvedType)) - t = typeInfo; - else { - typeName = rawStringData(mobj, typeInfo & TypeNameIndexMask); - t = QMetaType::type(typeName); - } - if (t == QMetaType::UnknownType) { - // Try to register the type and try again before reporting an error. - int registerResult = -1; - void *argv[] = { ®isterResult }; - QMetaObject::metacall(const_cast(object), QMetaObject::RegisterPropertyMetaType, - idx + mobj->propertyOffset(), argv); - if (registerResult == -1) { - qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name()); - return QVariant(); - } - t = registerResult; - } - } - - // the status variable is changed by qt_metacall to indicate what it did - // this feature is currently only used by Qt D-Bus and should not be depended - // upon. Don't change it without looking into QDBusAbstractInterface first - // -1 (unchanged): normal qt_metacall, result stored in argv[0] - // changed: result stored directly in value - int status = -1; - QVariant value; - void *argv[] = { 0, &value, &status }; - if (t == QMetaType::QVariant) { - argv[0] = &value; - } else { - value = QVariant(t, (void*)0); - argv[0] = value.data(); - } - QMetaObject::metacall(const_cast(object), QMetaObject::ReadProperty, - idx + mobj->propertyOffset(), argv); - - if (status != -1) - return value; - if (t != QMetaType::QVariant && argv[0] != value.data()) - // pointer or reference - return QVariant((QVariant::Type)t, argv[0]); - return value; -} - -/*! - Writes \a value as the property's value to the given \a object. Returns - true if the write succeeded; otherwise returns \c false. - - \sa read(), reset(), isWritable() -*/ -bool QMetaProperty::write(QObject *object, const QVariant &value) const -{ - if (!object || !isWritable()) - return false; - - QVariant v = value; - uint t = QVariant::Invalid; - if (isEnumType()) { - if (v.type() == QVariant::String) { - bool ok; - if (isFlagType()) - v = QVariant(menum.keysToValue(value.toByteArray(), &ok)); - else - v = QVariant(menum.keyToValue(value.toByteArray(), &ok)); - if (!ok) - return false; - } else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) { - int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); - if ((enumMetaTypeId == QMetaType::UnknownType) || (v.userType() != enumMetaTypeId) || !v.constData()) - return false; - v = QVariant(*reinterpret_cast(v.constData())); - } - v.convert(QVariant::Int); - } else { - int handle = priv(mobj->d.data)->propertyData + 3*idx; - const char *typeName = 0; - Q_ASSERT(priv(mobj->d.data)->revision >= 7); - uint typeInfo = mobj->d.data[handle + 1]; - if (!(typeInfo & IsUnresolvedType)) - t = typeInfo; - else { - typeName = rawStringData(mobj, typeInfo & TypeNameIndexMask); - t = QMetaType::type(typeName); - } - if (t == QMetaType::UnknownType) { - Q_ASSERT(typeName != 0); - const char *vtypeName = value.typeName(); - if (vtypeName && strcmp(typeName, vtypeName) == 0) - t = value.userType(); - else - t = QVariant::nameToType(typeName); - } - if (t == QVariant::Invalid) - return false; - if (t != QMetaType::QVariant && t != (uint)value.userType() && (t < QMetaType::User && !v.convert((QVariant::Type)t))) - return false; - } - - // the status variable is changed by qt_metacall to indicate what it did - // this feature is currently only used by Qt D-Bus and should not be depended - // upon. Don't change it without looking into QDBusAbstractInterface first - // -1 (unchanged): normal qt_metacall, result stored in argv[0] - // changed: result stored directly in value, return the value of status - int status = -1; - // the flags variable is used by the declarative module to implement - // interception of property writes. - int flags = 0; - void *argv[] = { 0, &v, &status, &flags }; - if (t == QMetaType::QVariant) - argv[0] = &v; - else - argv[0] = v.data(); - QMetaObject::metacall(object, QMetaObject::WriteProperty, idx + mobj->propertyOffset(), argv); - return status; -} - -/*! - Resets the property for the given \a object with a reset method. - Returns \c true if the reset worked; otherwise returns \c false. - - Reset methods are optional; only a few properties support them. - - \sa read(), write() -*/ -bool QMetaProperty::reset(QObject *object) const -{ - if (!object || !mobj || !isResettable()) - return false; - void *argv[] = { 0 }; - QMetaObject::metacall(object, QMetaObject::ResetProperty, idx + mobj->propertyOffset(), argv); - return true; -} - -/*! - Returns \c true if this property can be reset to a default value; otherwise - returns \c false. - - \sa reset() -*/ -bool QMetaProperty::isResettable() const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - return flags & Resettable; -} - -/*! - Returns \c true if this property is readable; otherwise returns \c false. - - \sa isWritable(), read(), isValid() - */ -bool QMetaProperty::isReadable() const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - return flags & Readable; -} - -/*! - Returns \c true if this property has a corresponding change notify signal; - otherwise returns \c false. - - \sa notifySignal() - */ -bool QMetaProperty::hasNotifySignal() const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - return flags & Notify; -} - -/*! - \since 4.5 - - Returns the QMetaMethod instance of the property change notifying signal if - one was specified, otherwise returns an invalid QMetaMethod. - - \sa hasNotifySignal() - */ -QMetaMethod QMetaProperty::notifySignal() const -{ - int id = notifySignalIndex(); - if (id != -1) - return mobj->method(id); - else - return QMetaMethod(); -} - -/*! - \since 4.6 - - Returns the index of the property change notifying signal if one was - specified, otherwise returns -1. - - \sa hasNotifySignal() - */ -int QMetaProperty::notifySignalIndex() const -{ - if (hasNotifySignal()) { - int offset = priv(mobj->d.data)->propertyData + - priv(mobj->d.data)->propertyCount * 3 + idx; - return mobj->d.data[offset] + mobj->methodOffset(); - } else { - return -1; - } -} - -// This method has been around for a while, but the documentation was marked \internal until 5.1 -/*! - \since 5.1 - - Returns the property revision if one was - specified by REVISION, otherwise returns 0. - */ -int QMetaProperty::revision() const -{ - if (!mobj) - return 0; - int flags = mobj->d.data[handle + 2]; - if (flags & Revisioned) { - int offset = priv(mobj->d.data)->propertyData + - priv(mobj->d.data)->propertyCount * 3 + idx; - // Revision data is placed after NOTIFY data, if present. - // Iterate through properties to discover whether we have NOTIFY signals. - for (int i = 0; i < priv(mobj->d.data)->propertyCount; ++i) { - int handle = priv(mobj->d.data)->propertyData + 3*i; - if (mobj->d.data[handle + 2] & Notify) { - offset += priv(mobj->d.data)->propertyCount; - break; - } - } - return mobj->d.data[offset]; - } else { - return 0; - } -} - -/*! - Returns \c true if this property is writable; otherwise returns - false. - - \sa isReadable(), write() - */ -bool QMetaProperty::isWritable() const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - return flags & Writable; -} - - -/*! - Returns \c true if this property is designable for the given \a object; - otherwise returns \c false. - - If no \a object is given, the function returns \c false if the - \c{Q_PROPERTY()}'s \c DESIGNABLE attribute is false; otherwise - returns \c true (if the attribute is true or is a function or expression). - - \sa isScriptable(), isStored() -*/ -bool QMetaProperty::isDesignable(const QObject *object) const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - bool b = flags & Designable; - if (object) { - void *argv[] = { &b }; - QMetaObject::metacall(const_cast(object), QMetaObject::QueryPropertyDesignable, - idx + mobj->propertyOffset(), argv); - } - return b; - - -} - -/*! - Returns \c true if the property is scriptable for the given \a object; - otherwise returns \c false. - - If no \a object is given, the function returns \c false if the - \c{Q_PROPERTY()}'s \c SCRIPTABLE attribute is false; otherwise returns - true (if the attribute is true or is a function or expression). - - \sa isDesignable(), isStored() -*/ -bool QMetaProperty::isScriptable(const QObject *object) const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - bool b = flags & Scriptable; - if (object) { - void *argv[] = { &b }; - QMetaObject::metacall(const_cast(object), QMetaObject::QueryPropertyScriptable, - idx + mobj->propertyOffset(), argv); - } - return b; -} - -/*! - Returns \c true if the property is stored for \a object; otherwise returns - false. - - If no \a object is given, the function returns \c false if the - \c{Q_PROPERTY()}'s \c STORED attribute is false; otherwise returns - true (if the attribute is true or is a function or expression). - - \sa isDesignable(), isScriptable() -*/ -bool QMetaProperty::isStored(const QObject *object) const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - bool b = flags & Stored; - if (object) { - void *argv[] = { &b }; - QMetaObject::metacall(const_cast(object), QMetaObject::QueryPropertyStored, - idx + mobj->propertyOffset(), argv); - } - return b; -} - -/*! - Returns \c true if this property is designated as the \c USER - property, i.e., the one that the user can edit for \a object or - that is significant in some other way. Otherwise it returns - false. e.g., the \c text property is the \c USER editable property - of a QLineEdit. - - If \a object is null, the function returns \c false if the \c - {Q_PROPERTY()}'s \c USER attribute is false. Otherwise it returns - true. - - \sa QMetaObject::userProperty(), isDesignable(), isScriptable() -*/ -bool QMetaProperty::isUser(const QObject *object) const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - bool b = flags & User; - if (object) { - void *argv[] = { &b }; - QMetaObject::metacall(const_cast(object), QMetaObject::QueryPropertyUser, - idx + mobj->propertyOffset(), argv); - } - return b; -} - -/*! - \since 4.6 - Returns \c true if the property is constant; otherwise returns \c false. - - A property is constant if the \c{Q_PROPERTY()}'s \c CONSTANT attribute - is set. -*/ -bool QMetaProperty::isConstant() const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - return flags & Constant; -} - -/*! - \since 4.6 - Returns \c true if the property is final; otherwise returns \c false. - - A property is final if the \c{Q_PROPERTY()}'s \c FINAL attribute - is set. -*/ -bool QMetaProperty::isFinal() const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - return flags & Final; -} - -/*! - \obsolete - - Returns \c true if the property is editable for the given \a object; - otherwise returns \c false. - - If no \a object is given, the function returns \c false if the - \c{Q_PROPERTY()}'s \c EDITABLE attribute is false; otherwise returns - true (if the attribute is true or is a function or expression). - - \sa isDesignable(), isScriptable(), isStored() -*/ -bool QMetaProperty::isEditable(const QObject *object) const -{ - if (!mobj) - return false; - int flags = mobj->d.data[handle + 2]; - bool b = flags & Editable; - if (object) { - void *argv[] = { &b }; - QMetaObject::metacall(const_cast(object), QMetaObject::QueryPropertyEditable, - idx + mobj->propertyOffset(), argv); - } - return b; -} - -/*! - \class QMetaClassInfo - \inmodule QtCore - - \brief The QMetaClassInfo class provides additional information - about a class. - - \ingroup objectmodel - - Class information items are simple \e{name}--\e{value} pairs that - are specified using Q_CLASSINFO() in the source code. The - information can be retrieved using name() and value(). For example: - - \snippet code/src_corelib_kernel_qmetaobject.cpp 5 - - This mechanism is free for you to use in your Qt applications. Qt - doesn't use it for any of its classes. - - \sa QMetaObject -*/ - - -/*! - \fn QMetaClassInfo::QMetaClassInfo() - \internal -*/ - -/*! - \fn const QMetaObject *QMetaClassInfo::enclosingMetaObject() const - \internal -*/ - -/*! - Returns the name of this item. - - \sa value() -*/ -const char *QMetaClassInfo::name() const -{ - if (!mobj) - return 0; - return rawStringData(mobj, mobj->d.data[handle]); -} - -/*! - Returns the value of this item. - - \sa name() -*/ -const char* QMetaClassInfo::value() const -{ - if (!mobj) - return 0; - return rawStringData(mobj, mobj->d.data[handle + 1]); -} - -/*! - \macro QGenericArgument Q_ARG(Type, const Type &value) - \relates QMetaObject - - This macro takes a \a Type and a \a value of that type and - returns a \l QGenericArgument object that can be passed to - QMetaObject::invokeMethod(). - - \sa Q_RETURN_ARG() -*/ - -/*! - \macro QGenericReturnArgument Q_RETURN_ARG(Type, Type &value) - \relates QMetaObject - - This macro takes a \a Type and a non-const reference to a \a - value of that type and returns a QGenericReturnArgument object - that can be passed to QMetaObject::invokeMethod(). - - \sa Q_ARG() -*/ - -/*! - \class QGenericArgument - \inmodule QtCore - - \brief The QGenericArgument class is an internal helper class for - marshalling arguments. - - This class should never be used directly. Please use the \l Q_ARG() - macro instead. - - \sa Q_ARG(), QMetaObject::invokeMethod(), QGenericReturnArgument -*/ - -/*! - \fn QGenericArgument::QGenericArgument(const char *name, const void *data) - - Constructs a QGenericArgument object with the given \a name and \a data. -*/ - -/*! - \fn QGenericArgument::data () const - - Returns the data set in the constructor. -*/ - -/*! - \fn QGenericArgument::name () const - - Returns the name set in the constructor. -*/ - -/*! - \class QGenericReturnArgument - \inmodule QtCore - - \brief The QGenericReturnArgument class is an internal helper class for - marshalling arguments. - - This class should never be used directly. Please use the - Q_RETURN_ARG() macro instead. - - \sa Q_RETURN_ARG(), QMetaObject::invokeMethod(), QGenericArgument -*/ - -/*! - \fn QGenericReturnArgument::QGenericReturnArgument(const char *name, void *data) - - Constructs a QGenericReturnArgument object with the given \a name - and \a data. -*/ - -/*! - \internal - If the local_method_index is a cloned method, return the index of the original. - - Example: if the index of "destroyed()" is passed, the index of "destroyed(QObject*)" is returned - */ -int QMetaObjectPrivate::originalClone(const QMetaObject *mobj, int local_method_index) -{ - Q_ASSERT(local_method_index < get(mobj)->methodCount); - int handle = get(mobj)->methodData + 5 * local_method_index; - while (mobj->d.data[handle + 4] & MethodCloned) { - Q_ASSERT(local_method_index > 0); - handle -= 5; - local_method_index--; - } - return local_method_index; -} - -/*! - \internal - - Returns the parameter type names extracted from the given \a signature. -*/ -QList QMetaObjectPrivate::parameterTypeNamesFromSignature(const char *signature) -{ - QList list; - while (*signature && *signature != '(') - ++signature; - while (*signature && *signature != ')' && *++signature != ')') { - const char *begin = signature; - int level = 0; - while (*signature && (level > 0 || *signature != ',') && *signature != ')') { - if (*signature == '<') - ++level; - else if (*signature == '>') - --level; - ++signature; - } - list += QByteArray(begin, signature - begin); - } - return list; -} - -QT_END_NAMESPACE diff --git a/DOtherSide/DynamicQObject/private/qmetaobject.h b/DOtherSide/DynamicQObject/private/qmetaobject.h deleted file mode 100644 index 8186131..0000000 --- a/DOtherSide/DynamicQObject/private/qmetaobject.h +++ /dev/null @@ -1,277 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMETAOBJECT_H -#define QMETAOBJECT_H - -#include -#include - -QT_BEGIN_NAMESPACE - - -template class QList; - -#define Q_METAMETHOD_INVOKE_MAX_ARGS 10 - -class Q_CORE_EXPORT QMetaMethod -{ -public: - inline QMetaMethod() : mobj(0),handle(0) {} - - QByteArray methodSignature() const; - QByteArray name() const; - const char *typeName() const; - int returnType() const; - int parameterCount() const; - int parameterType(int index) const; - void getParameterTypes(int *types) const; - QList parameterTypes() const; - QList parameterNames() const; - const char *tag() const; - enum Access { Private, Protected, Public }; - Access access() const; - enum MethodType { Method, Signal, Slot, Constructor }; - MethodType methodType() const; - enum Attributes { Compatibility = 0x1, Cloned = 0x2, Scriptable = 0x4 }; - int attributes() const; - int methodIndex() const; - int revision() const; - - inline const QMetaObject *enclosingMetaObject() const { return mobj; } - - bool invoke(QObject *object, - Qt::ConnectionType connectionType, - QGenericReturnArgument returnValue, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const; - inline bool invoke(QObject *object, - QGenericReturnArgument returnValue, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const - { - return invoke(object, Qt::AutoConnection, returnValue, - val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); - } - inline bool invoke(QObject *object, - Qt::ConnectionType connectionType, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const - { - return invoke(object, connectionType, QGenericReturnArgument(), - val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); - } - inline bool invoke(QObject *object, - QGenericArgument val0 = QGenericArgument(0), - QGenericArgument val1 = QGenericArgument(), - QGenericArgument val2 = QGenericArgument(), - QGenericArgument val3 = QGenericArgument(), - QGenericArgument val4 = QGenericArgument(), - QGenericArgument val5 = QGenericArgument(), - QGenericArgument val6 = QGenericArgument(), - QGenericArgument val7 = QGenericArgument(), - QGenericArgument val8 = QGenericArgument(), - QGenericArgument val9 = QGenericArgument()) const - { - return invoke(object, Qt::AutoConnection, QGenericReturnArgument(), - val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); - } - - inline bool isValid() const { return mobj != 0; } - -#ifdef Q_QDOC - static QMetaMethod fromSignal(PointerToMemberFunction signal); -#else - template - static inline QMetaMethod fromSignal(Func signal) - { - typedef QtPrivate::FunctionPointer SignalType; - Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro::Value, - "No Q_OBJECT in the class with the signal"); - return fromSignalImpl(&SignalType::Object::staticMetaObject, - reinterpret_cast(&signal)); - } -#endif - -private: -#if QT_DEPRECATED_SINCE(5,0) - // signature() has been renamed to methodSignature() in Qt 5. - // Warning, that function returns a QByteArray; check the life time if - // you convert to char*. - char *signature(struct renamedInQt5_warning_checkTheLifeTime * = 0) Q_DECL_EQ_DELETE; -#endif - static QMetaMethod fromSignalImpl(const QMetaObject *, void **); - - const QMetaObject *mobj; - uint handle; - friend class QMetaMethodPrivate; - friend struct QMetaObject; - friend struct QMetaObjectPrivate; - friend class QObject; - friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2); - friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2); -}; -Q_DECLARE_TYPEINFO(QMetaMethod, Q_MOVABLE_TYPE); - -inline bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) -{ return m1.mobj == m2.mobj && m1.handle == m2.handle; } -inline bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) -{ return !(m1 == m2); } - -class Q_CORE_EXPORT QMetaEnum -{ -public: - inline QMetaEnum() : mobj(0),handle(0) {} - - const char *name() const; - bool isFlag() const; - - int keyCount() const; - const char *key(int index) const; - int value(int index) const; - - const char *scope() const; - - int keyToValue(const char *key, bool *ok = 0) const; - const char* valueToKey(int value) const; - int keysToValue(const char * keys, bool *ok = 0) const; - QByteArray valueToKeys(int value) const; - - inline const QMetaObject *enclosingMetaObject() const { return mobj; } - - inline bool isValid() const { return name() != 0; } -private: - const QMetaObject *mobj; - uint handle; - friend struct QMetaObject; -}; -Q_DECLARE_TYPEINFO(QMetaEnum, Q_MOVABLE_TYPE); - -class Q_CORE_EXPORT QMetaProperty -{ -public: - QMetaProperty(); - - const char *name() const; - const char *typeName() const; - QVariant::Type type() const; - int userType() const; - int propertyIndex() const; - - bool isReadable() const; - bool isWritable() const; - bool isResettable() const; - bool isDesignable(const QObject *obj = 0) const; - bool isScriptable(const QObject *obj = 0) const; - bool isStored(const QObject *obj = 0) const; - bool isEditable(const QObject *obj = 0) const; - bool isUser(const QObject *obj = 0) const; - bool isConstant() const; - bool isFinal() const; - - bool isFlagType() const; - bool isEnumType() const; - QMetaEnum enumerator() const; - - bool hasNotifySignal() const; - QMetaMethod notifySignal() const; - int notifySignalIndex() const; - - int revision() const; - - QVariant read(const QObject *obj) const; - bool write(QObject *obj, const QVariant &value) const; - bool reset(QObject *obj) const; - - bool hasStdCppSet() const; - inline bool isValid() const { return isReadable(); } - inline const QMetaObject *enclosingMetaObject() const { return mobj; } - -private: - const QMetaObject *mobj; - uint handle; - int idx; - QMetaEnum menum; - friend struct QMetaObject; - friend struct QMetaObjectPrivate; -}; - -class Q_CORE_EXPORT QMetaClassInfo -{ -public: - inline QMetaClassInfo() : mobj(0),handle(0) {} - const char *name() const; - const char *value() const; - inline const QMetaObject *enclosingMetaObject() const { return mobj; } -private: - const QMetaObject *mobj; - uint handle; - friend struct QMetaObject; -}; -Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE); - -QT_END_NAMESPACE - -#endif // QMETAOBJECT_H diff --git a/DOtherSide/DynamicQObject/private/qmetaobject_moc_p.h b/DOtherSide/DynamicQObject/private/qmetaobject_moc_p.h deleted file mode 100644 index d26cd54..0000000 --- a/DOtherSide/DynamicQObject/private/qmetaobject_moc_p.h +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#if !defined(QMETAOBJECT_P_H) && !defined(UTILS_H) -# error "Include qmetaobject_p.h (or moc's utils.h) before including this file." -#endif - -QT_BEGIN_NAMESPACE - -// This function is shared with moc.cpp. This file should be included where needed. -static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true) -{ - int len = e - t; - /* - Convert 'char const *' into 'const char *'. Start at index 1, - not 0, because 'const char *' is already OK. - */ - QByteArray constbuf; - for (int i = 1; i < len; i++) { - if ( t[i] == 'c' - && strncmp(t + i + 1, "onst", 4) == 0 - && (i + 5 >= len || !is_ident_char(t[i + 5])) - && !is_ident_char(t[i-1]) - ) { - constbuf = QByteArray(t, len); - if (is_space(t[i-1])) - constbuf.remove(i-1, 6); - else - constbuf.remove(i, 5); - constbuf.prepend("const "); - t = constbuf.data(); - e = constbuf.data() + constbuf.length(); - break; - } - /* - We mustn't convert 'char * const *' into 'const char **' - and we must beware of 'Bar'. - */ - if (t[i] == '&' || t[i] == '*' ||t[i] == '<') - break; - } - if (adjustConst && e > t + 6 && strncmp("const ", t, 6) == 0) { - if (*(e-1) == '&') { // treat const reference as value - t += 6; - --e; - } else if (is_ident_char(*(e-1)) || *(e-1) == '>') { // treat const value as value - t += 6; - } - } - QByteArray result; - result.reserve(len); - -#if 1 - // consume initial 'const ' - if (strncmp("const ", t, 6) == 0) { - t+= 6; - result += "const "; - } -#endif - - // some type substitutions for 'unsigned x' - if (strncmp("unsigned", t, 8) == 0) { - // make sure "unsigned" is an isolated word before making substitutions - if (!t[8] || !is_ident_char(t[8])) { - if (strncmp(" int", t+8, 4) == 0) { - t += 8+4; - result += "uint"; - } else if (strncmp(" long", t+8, 5) == 0) { - if ((strlen(t + 8 + 5) < 4 || strncmp(t + 8 + 5, " int", 4) != 0) // preserve '[unsigned] long int' - && (strlen(t + 8 + 5) < 5 || strncmp(t + 8 + 5, " long", 5) != 0) // preserve '[unsigned] long long' - ) { - t += 8+5; - result += "ulong"; - } - } else if (strncmp(" short", t+8, 6) != 0 // preserve unsigned short - && strncmp(" char", t+8, 5) != 0) { // preserve unsigned char - // treat rest (unsigned) as uint - t += 8; - result += "uint"; - } - } - } else { - // discard 'struct', 'class', and 'enum'; they are optional - // and we don't want them in the normalized signature - struct { - const char *keyword; - int len; - } optional[] = { - { "struct ", 7 }, - { "class ", 6 }, - { "enum ", 5 }, - { 0, 0 } - }; - int i = 0; - do { - if (strncmp(optional[i].keyword, t, optional[i].len) == 0) { - t += optional[i].len; - break; - } - } while (optional[++i].keyword != 0); - } - - bool star = false; - while (t != e) { - char c = *t++; - if (fixScope && c == ':' && *t == ':' ) { - ++t; - c = *t++; - int i = result.size() - 1; - while (i >= 0 && is_ident_char(result.at(i))) - --i; - result.resize(i + 1); - } - star = star || c == '*'; - result += c; - if (c == '<') { - //template recursion - const char* tt = t; - int templdepth = 1; - int scopeDepth = 0; - while (t != e) { - c = *t++; - if (c == '{' || c == '(' || c == '[') - ++scopeDepth; - if (c == '}' || c == ')' || c == ']') - --scopeDepth; - if (scopeDepth == 0) { - if (c == '<') - ++templdepth; - if (c == '>') - --templdepth; - if (templdepth == 0 || (templdepth == 1 && c == ',')) { - result += normalizeTypeInternal(tt, t-1, fixScope, false); - result += c; - if (templdepth == 0) { - if (*t == '>') - result += ' '; // avoid >> - break; - } - tt = t; - } - } - } - } - - // cv qualifers can appear after the type as well - if (!is_ident_char(c) && t != e && (e - t >= 5 && strncmp("const", t, 5) == 0) - && (e - t == 5 || !is_ident_char(t[5]))) { - t += 5; - while (t != e && is_space(*t)) - ++t; - if (adjustConst && t != e && *t == '&') { - // treat const ref as value - ++t; - } else if (adjustConst && !star) { - // treat const as value - } else if (!star) { - // move const to the front (but not if const comes after a *) - result.prepend("const "); - } else { - // keep const after a * - result += "const"; - } - } - } - - return result; -} - -QT_END_NAMESPACE diff --git a/DOtherSide/DynamicQObject/private/qmetaobjectbuilder.cpp b/DOtherSide/DynamicQObject/private/qmetaobjectbuilder.cpp deleted file mode 100644 index 09d8271..0000000 --- a/DOtherSide/DynamicQObject/private/qmetaobjectbuilder.cpp +++ /dev/null @@ -1,2726 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmetaobjectbuilder_p.h" - -#include "qobject_p.h" -#include "qmetaobject_p.h" - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QMetaObjectBuilder - \inmodule QtCore - \internal - \brief The QMetaObjectBuilder class supports building QMetaObject objects at runtime. - -*/ - -/*! - \enum QMetaObjectBuilder::AddMember - This enum defines which members of QMetaObject should be copied by QMetaObjectBuilder::addMetaObject() - - \value ClassName Add the class name. - \value SuperClass Add the super class. - \value Methods Add methods that aren't signals or slots. - \value Signals Add signals. - \value Slots Add slots. - \value Constructors Add constructors. - \value Properties Add properties. - \value Enumerators Add enumerators. - \value ClassInfos Add items of class information. - \value RelatedMetaObjects Add related meta objects. - \value StaticMetacall Add the static metacall function. - \value PublicMethods Add public methods (ignored for signals). - \value ProtectedMethods Add protected methods (ignored for signals). - \value PrivateMethods All private methods (ignored for signals). - \value AllMembers Add all members. - \value AllPrimaryMembers Add everything except the class name, super class, and static metacall function. -*/ - -// copied from moc's generator.cpp -namespace QtPrivate { -Q_CORE_EXPORT bool isBuiltinType(const QByteArray &type) -{ - int id = QMetaType::type(type); - if (!id && !type.isEmpty() && type != "void") - return false; - return (id < QMetaType::User); -} -} // namespace QtPrivate - -// copied from qmetaobject.cpp -static inline Q_DECL_UNUSED const QMetaObjectPrivate *priv(const uint* data) -{ return reinterpret_cast(data); } - -class QMetaMethodBuilderPrivate -{ -public: - QMetaMethodBuilderPrivate - (QMetaMethod::MethodType _methodType, - const QByteArray& _signature, - const QByteArray& _returnType = QByteArray("void"), - QMetaMethod::Access _access = QMetaMethod::Public, - int _revision = 0) - : signature(QMetaObject::normalizedSignature(_signature.constData())), - returnType(QMetaObject::normalizedType(_returnType)), - attributes(((int)_access) | (((int)_methodType) << 2)), - revision(_revision) - { - Q_ASSERT((_methodType == QMetaMethod::Constructor) == returnType.isNull()); - } - - QByteArray signature; - QByteArray returnType; - QList parameterNames; - QByteArray tag; - int attributes; - int revision; - - QMetaMethod::MethodType methodType() const - { - return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2); - } - - QMetaMethod::Access access() const - { - return (QMetaMethod::Access)(attributes & AccessMask); - } - - void setAccess(QMetaMethod::Access value) - { - attributes = ((attributes & ~AccessMask) | (int)value); - } - - QList parameterTypes() const - { - return QMetaObjectPrivate::parameterTypeNamesFromSignature(signature); - } - - int parameterCount() const - { - return parameterTypes().size(); - } - - QByteArray name() const - { - return signature.left(qMax(signature.indexOf('('), 0)); - } -}; - -class QMetaPropertyBuilderPrivate -{ -public: - QMetaPropertyBuilderPrivate - (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1, - int _revision = 0) - : name(_name), - type(QMetaObject::normalizedType(_type.constData())), - flags(Readable | Writable | Scriptable), notifySignal(-1), - revision(_revision) - { - if (notifierIdx >= 0) { - flags |= Notify; - notifySignal = notifierIdx; - } - } - - QByteArray name; - QByteArray type; - int flags; - int notifySignal; - int revision; - - bool flag(int f) const - { - return ((flags & f) != 0); - } - - void setFlag(int f, bool value) - { - if (value) - flags |= f; - else - flags &= ~f; - } -}; - -class QMetaEnumBuilderPrivate -{ -public: - QMetaEnumBuilderPrivate(const QByteArray& _name) - : name(_name), isFlag(false) - { - } - - QByteArray name; - bool isFlag; - QList keys; - QList values; -}; - -class QMetaObjectBuilderPrivate -{ -public: - QMetaObjectBuilderPrivate() - : flags(0) - { - superClass = &QObject::staticMetaObject; - staticMetacallFunction = 0; - } - - bool hasRevisionedProperties() const; - bool hasRevisionedMethods() const; - - QByteArray className; - const QMetaObject *superClass; - QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction; - QList methods; - QList constructors; - QList properties; - QList classInfoNames; - QList classInfoValues; - QList enumerators; - QList relatedMetaObjects; - int flags; -}; - -bool QMetaObjectBuilderPrivate::hasRevisionedProperties() const -{ - for (int i = 0; i < properties.size(); ++i) { - if (properties.at(i).revision) - return true; - } - return false; -} - -bool QMetaObjectBuilderPrivate::hasRevisionedMethods() const -{ - for (int i = 0; i < methods.size(); ++i) { - if (methods.at(i).revision) - return true; - } - return false; -} - -/*! - Constructs a new QMetaObjectBuilder. -*/ -QMetaObjectBuilder::QMetaObjectBuilder() -{ - d = new QMetaObjectBuilderPrivate(); -} - -/*! - Constructs a new QMetaObjectBuilder which is a copy of the - meta object information in \a prototype. Note: the super class - contents for \a prototype are not copied, only the immediate - class that is defined by \a prototype. - - The \a members parameter indicates which members of \a prototype - should be added. The default is AllMembers. - - \sa addMetaObject() -*/ -QMetaObjectBuilder::QMetaObjectBuilder - (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members) -{ - d = new QMetaObjectBuilderPrivate(); - addMetaObject(prototype, members); -} - -/*! - Destroys this meta object builder. -*/ -QMetaObjectBuilder::~QMetaObjectBuilder() -{ - delete d; -} - -/*! - Returns the name of the class being constructed by this - meta object builder. The default value is an empty QByteArray. - - \sa setClassName(), superClass() -*/ -QByteArray QMetaObjectBuilder::className() const -{ - return d->className; -} - -/*! - Sets the \a name of the class being constructed by this - meta object builder. - - \sa className(), setSuperClass() -*/ -void QMetaObjectBuilder::setClassName(const QByteArray& name) -{ - d->className = name; -} - -/*! - Returns the superclass meta object of the class being constructed - by this meta object builder. The default value is the meta object - for QObject. - - \sa setSuperClass(), className() -*/ -const QMetaObject *QMetaObjectBuilder::superClass() const -{ - return d->superClass; -} - -/*! - Sets the superclass meta object of the class being constructed - by this meta object builder to \a meta. The \a meta parameter - must not be null. - - \sa superClass(), setClassName() -*/ -void QMetaObjectBuilder::setSuperClass(const QMetaObject *meta) -{ - Q_ASSERT(meta); - d->superClass = meta; -} - -/*! - Returns the flags of the class being constructed by this meta object - builder. - - \sa setFlags() -*/ -QMetaObjectBuilder::MetaObjectFlags QMetaObjectBuilder::flags() const -{ - return (QMetaObjectBuilder::MetaObjectFlags)d->flags; -} - -/*! - Sets the \a flags of the class being constructed by this meta object - builder. - - \sa flags() -*/ -void QMetaObjectBuilder::setFlags(MetaObjectFlags flags) -{ - d->flags = flags; -} - -/*! - Returns the number of methods in this class, excluding the number - of methods in the base class. These include signals and slots - as well as normal member functions. - - \sa addMethod(), method(), removeMethod(), indexOfMethod() -*/ -int QMetaObjectBuilder::methodCount() const -{ - return d->methods.size(); -} - -/*! - Returns the number of constructors in this class. - - \sa addConstructor(), constructor(), removeConstructor(), indexOfConstructor() -*/ -int QMetaObjectBuilder::constructorCount() const -{ - return d->constructors.size(); -} - -/*! - Returns the number of properties in this class, excluding the number - of properties in the base class. - - \sa addProperty(), property(), removeProperty(), indexOfProperty() -*/ -int QMetaObjectBuilder::propertyCount() const -{ - return d->properties.size(); -} - -/*! - Returns the number of enumerators in this class, excluding the - number of enumerators in the base class. - - \sa addEnumerator(), enumerator(), removeEnumerator() - \sa indexOfEnumerator() -*/ -int QMetaObjectBuilder::enumeratorCount() const -{ - return d->enumerators.size(); -} - -/*! - Returns the number of items of class information in this class, - exclusing the number of items of class information in the base class. - - \sa addClassInfo(), classInfoName(), classInfoValue(), removeClassInfo() - \sa indexOfClassInfo() -*/ -int QMetaObjectBuilder::classInfoCount() const -{ - return d->classInfoNames.size(); -} - -/*! - Returns the number of related meta objects that are associated - with this class. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa addRelatedMetaObject(), relatedMetaObject() - \sa removeRelatedMetaObject() -*/ -int QMetaObjectBuilder::relatedMetaObjectCount() const -{ - return d->relatedMetaObjects.size(); -} - -/*! - Adds a new public method to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the method. The \a signature will be normalized before it is - added to the class. - - \sa method(), methodCount(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new public method to this class with the specified - \a signature and \a returnType. Returns an object that can be - used to adjust the other attributes of the method. The \a signature - and \a returnType will be normalized before they are added to - the class. - - \sa method(), methodCount(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addMethod - (const QByteArray& signature, const QByteArray& returnType) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate - (QMetaMethod::Method, signature, returnType)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new public method to this class that has the same information as - \a prototype. This is used to clone the methods of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the method. - - This function will detect if \a prototype is an ordinary method, - signal, slot, or constructor and act accordingly. - - \sa method(), methodCount(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype) -{ - QMetaMethodBuilder method; - if (prototype.methodType() == QMetaMethod::Method) - method = addMethod(prototype.methodSignature()); - else if (prototype.methodType() == QMetaMethod::Signal) - method = addSignal(prototype.methodSignature()); - else if (prototype.methodType() == QMetaMethod::Slot) - method = addSlot(prototype.methodSignature()); - else if (prototype.methodType() == QMetaMethod::Constructor) - method = addConstructor(prototype.methodSignature()); - method.setReturnType(prototype.typeName()); - method.setParameterNames(prototype.parameterNames()); - method.setTag(prototype.tag()); - method.setAccess(prototype.access()); - method.setAttributes(prototype.attributes()); - method.setRevision(prototype.revision()); - return method; -} - -/*! - Adds a new public slot to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the slot. The \a signature will be normalized before it is - added to the class. - - \sa addMethod(), addSignal(), indexOfSlot() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new signal to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the signal. The \a signature will be normalized before it is - added to the class. - - \sa addMethod(), addSlot(), indexOfSignal() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate - (QMetaMethod::Signal, signature, QByteArray("void"), QMetaMethod::Public)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new constructor to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the constructor. The \a signature will be normalized before it is - added to the class. - - \sa constructor(), constructorCount(), removeConstructor() - \sa indexOfConstructor() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature) -{ - int index = d->constructors.size(); - d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature, - /*returnType=*/QByteArray())); - return QMetaMethodBuilder(this, -(index + 1)); -} - -/*! - Adds a new constructor to this class that has the same information as - \a prototype. This is used to clone the constructors of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the constructor. - - This function requires that \a prototype be a constructor. - - \sa constructor(), constructorCount(), removeConstructor() - \sa indexOfConstructor() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype) -{ - Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor); - QMetaMethodBuilder ctor = addConstructor(prototype.methodSignature()); - ctor.setReturnType(prototype.typeName()); - ctor.setParameterNames(prototype.parameterNames()); - ctor.setTag(prototype.tag()); - ctor.setAccess(prototype.access()); - ctor.setAttributes(prototype.attributes()); - return ctor; -} - -/*! - Adds a new readable/writable property to this class with the - specified \a name and \a type. Returns an object that can be used - to adjust the other attributes of the property. The \a type will - be normalized before it is added to the class. \a notifierId will - be registered as the property's \e notify signal. - - \sa property(), propertyCount(), removeProperty(), indexOfProperty() -*/ -QMetaPropertyBuilder QMetaObjectBuilder::addProperty - (const QByteArray& name, const QByteArray& type, int notifierId) -{ - int index = d->properties.size(); - d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId)); - return QMetaPropertyBuilder(this, index); -} - -/*! - Adds a new property to this class that has the same information as - \a prototype. This is used to clone the properties of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the property. - - \sa property(), propertyCount(), removeProperty(), indexOfProperty() -*/ -QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& prototype) -{ - QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName()); - property.setReadable(prototype.isReadable()); - property.setWritable(prototype.isWritable()); - property.setResettable(prototype.isResettable()); - property.setDesignable(prototype.isDesignable()); - property.setScriptable(prototype.isScriptable()); - property.setStored(prototype.isStored()); - property.setEditable(prototype.isEditable()); - property.setUser(prototype.isUser()); - property.setStdCppSet(prototype.hasStdCppSet()); - property.setEnumOrFlag(prototype.isEnumType()); - property.setConstant(prototype.isConstant()); - property.setFinal(prototype.isFinal()); - property.setRevision(prototype.revision()); - if (prototype.hasNotifySignal()) { - // Find an existing method for the notify signal, or add a new one. - QMetaMethod method = prototype.notifySignal(); - int index = indexOfMethod(method.methodSignature()); - if (index == -1) - index = addMethod(method).index(); - d->properties[property._index].notifySignal = index; - d->properties[property._index].setFlag(Notify, true); - } - return property; -} - -/*! - Adds a new enumerator to this class with the specified - \a name. Returns an object that can be used to adjust - the other attributes of the enumerator. - - \sa enumerator(), enumeratorCount(), removeEnumerator() - \sa indexOfEnumerator() -*/ -QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name) -{ - int index = d->enumerators.size(); - d->enumerators.append(QMetaEnumBuilderPrivate(name)); - return QMetaEnumBuilder(this, index); -} - -/*! - Adds a new enumerator to this class that has the same information as - \a prototype. This is used to clone the enumerators of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the enumerator. - - \sa enumerator(), enumeratorCount(), removeEnumerator() - \sa indexOfEnumerator() -*/ -QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype) -{ - QMetaEnumBuilder en = addEnumerator(prototype.name()); - en.setIsFlag(prototype.isFlag()); - int count = prototype.keyCount(); - for (int index = 0; index < count; ++index) - en.addKey(prototype.key(index), prototype.value(index)); - return en; -} - -/*! - Adds \a name and \a value as an item of class information to this class. - Returns the index of the new item of class information. - - \sa classInfoCount(), classInfoName(), classInfoValue(), removeClassInfo() - \sa indexOfClassInfo() -*/ -int QMetaObjectBuilder::addClassInfo(const QByteArray& name, const QByteArray& value) -{ - int index = d->classInfoNames.size(); - d->classInfoNames += name; - d->classInfoValues += value; - return index; -} - -/*! - Adds \a meta to this class as a related meta object. Returns - the index of the new related meta object entry. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa relatedMetaObjectCount(), relatedMetaObject() - \sa removeRelatedMetaObject() -*/ -int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObject *meta) -{ - Q_ASSERT(meta); - int index = d->relatedMetaObjects.size(); - d->relatedMetaObjects.append(meta); - return index; -} - -/*! - Adds the contents of \a prototype to this meta object builder. - This function is useful for cloning the contents of an existing QMetaObject. - - The \a members parameter indicates which members of \a prototype - should be added. The default is AllMembers. -*/ -void QMetaObjectBuilder::addMetaObject - (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members) -{ - Q_ASSERT(prototype); - int index; - - if ((members & ClassName) != 0) - d->className = prototype->className(); - - if ((members & SuperClass) != 0) - d->superClass = prototype->superClass(); - - if ((members & (Methods | Signals | Slots)) != 0) { - for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) { - QMetaMethod method = prototype->method(index); - if (method.methodType() != QMetaMethod::Signal) { - if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0) - continue; - if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0) - continue; - if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0) - continue; - } - if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) { - addMethod(method); - } else if (method.methodType() == QMetaMethod::Signal && - (members & Signals) != 0) { - addMethod(method); - } else if (method.methodType() == QMetaMethod::Slot && - (members & Slots) != 0) { - addMethod(method); - } - } - } - - if ((members & Constructors) != 0) { - for (index = 0; index < prototype->constructorCount(); ++index) - addConstructor(prototype->constructor(index)); - } - - if ((members & Properties) != 0) { - for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index) - addProperty(prototype->property(index)); - } - - if ((members & Enumerators) != 0) { - for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index) - addEnumerator(prototype->enumerator(index)); - } - - if ((members & ClassInfos) != 0) { - for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) { - QMetaClassInfo ci = prototype->classInfo(index); - addClassInfo(ci.name(), ci.value()); - } - } - - if ((members & RelatedMetaObjects) != 0) { - Q_ASSERT(priv(prototype->d.data)->revision >= 2); - const QMetaObject * const *objects = prototype->d.relatedMetaObjects; - if (objects) { - while (*objects != 0) { - addRelatedMetaObject(*objects); - ++objects; - } - } - } - - if ((members & StaticMetacall) != 0) { - Q_ASSERT(priv(prototype->d.data)->revision >= 6); - if (prototype->d.static_metacall) - setStaticMetacallFunction(prototype->d.static_metacall); - } -} - -/*! - Returns the method at \a index in this class. - - \sa methodCount(), addMethod(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::method(int index) const -{ - if (index >= 0 && index < d->methods.size()) - return QMetaMethodBuilder(this, index); - else - return QMetaMethodBuilder(); -} - -/*! - Returns the constructor at \a index in this class. - - \sa methodCount(), addMethod(), removeMethod(), indexOfConstructor() -*/ -QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const -{ - if (index >= 0 && index < d->constructors.size()) - return QMetaMethodBuilder(this, -(index + 1)); - else - return QMetaMethodBuilder(); -} - -/*! - Returns the property at \a index in this class. - - \sa methodCount(), addMethod(), removeMethod(), indexOfProperty() -*/ -QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const -{ - if (index >= 0 && index < d->properties.size()) - return QMetaPropertyBuilder(this, index); - else - return QMetaPropertyBuilder(); -} - -/*! - Returns the enumerator at \a index in this class. - - \sa enumeratorCount(), addEnumerator(), removeEnumerator() - \sa indexOfEnumerator() -*/ -QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const -{ - if (index >= 0 && index < d->enumerators.size()) - return QMetaEnumBuilder(this, index); - else - return QMetaEnumBuilder(); -} - -/*! - Returns the related meta object at \a index in this class. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa relatedMetaObjectCount(), addRelatedMetaObject() - \sa removeRelatedMetaObject() -*/ -const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const -{ - if (index >= 0 && index < d->relatedMetaObjects.size()) - return d->relatedMetaObjects[index]; - else - return 0; -} - -/*! - Returns the name of the item of class information at \a index - in this class. - - \sa classInfoCount(), addClassInfo(), classInfoValue(), removeClassInfo() - \sa indexOfClassInfo() -*/ -QByteArray QMetaObjectBuilder::classInfoName(int index) const -{ - if (index >= 0 && index < d->classInfoNames.size()) - return d->classInfoNames[index]; - else - return QByteArray(); -} - -/*! - Returns the value of the item of class information at \a index - in this class. - - \sa classInfoCount(), addClassInfo(), classInfoName(), removeClassInfo() - \sa indexOfClassInfo() -*/ -QByteArray QMetaObjectBuilder::classInfoValue(int index) const -{ - if (index >= 0 && index < d->classInfoValues.size()) - return d->classInfoValues[index]; - else - return QByteArray(); -} - -/*! - Removes the method at \a index from this class. The indices of - all following methods will be adjusted downwards by 1. If the - method is registered as a notify signal on a property, then the - notify signal will be removed from the property. - - \sa methodCount(), addMethod(), method(), indexOfMethod() -*/ -void QMetaObjectBuilder::removeMethod(int index) -{ - if (index >= 0 && index < d->methods.size()) { - d->methods.removeAt(index); - for (int prop = 0; prop < d->properties.size(); ++prop) { - // Adjust the indices of property notify signal references. - if (d->properties[prop].notifySignal == index) { - d->properties[prop].notifySignal = -1; - d->properties[prop].setFlag(Notify, false); - } else if (d->properties[prop].notifySignal > index) - (d->properties[prop].notifySignal)--; - } - } -} - -/*! - Removes the constructor at \a index from this class. The indices of - all following constructors will be adjusted downwards by 1. - - \sa constructorCount(), addConstructor(), constructor() - \sa indexOfConstructor() -*/ -void QMetaObjectBuilder::removeConstructor(int index) -{ - if (index >= 0 && index < d->constructors.size()) - d->constructors.removeAt(index); -} - -/*! - Removes the property at \a index from this class. The indices of - all following properties will be adjusted downwards by 1. - - \sa propertyCount(), addProperty(), property(), indexOfProperty() -*/ -void QMetaObjectBuilder::removeProperty(int index) -{ - if (index >= 0 && index < d->properties.size()) - d->properties.removeAt(index); -} - -/*! - Removes the enumerator at \a index from this class. The indices of - all following enumerators will be adjusted downwards by 1. - - \sa enumertorCount(), addEnumerator(), enumerator() - \sa indexOfEnumerator() -*/ -void QMetaObjectBuilder::removeEnumerator(int index) -{ - if (index >= 0 && index < d->enumerators.size()) - d->enumerators.removeAt(index); -} - -/*! - Removes the item of class information at \a index from this class. - The indices of all following items will be adjusted downwards by 1. - - \sa classInfoCount(), addClassInfo(), classInfoName(), classInfoValue() - \sa indexOfClassInfo() -*/ -void QMetaObjectBuilder::removeClassInfo(int index) -{ - if (index >= 0 && index < d->classInfoNames.size()) { - d->classInfoNames.removeAt(index); - d->classInfoValues.removeAt(index); - } -} - -/*! - Removes the related meta object at \a index from this class. - The indices of all following related meta objects will be adjusted - downwards by 1. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa relatedMetaObjectCount(), addRelatedMetaObject() - \sa relatedMetaObject() -*/ -void QMetaObjectBuilder::removeRelatedMetaObject(int index) -{ - if (index >= 0 && index < d->relatedMetaObjects.size()) - d->relatedMetaObjects.removeAt(index); -} - -/*! - Finds a method with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa method(), methodCount(), addMethod(), removeMethod() -*/ -int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { - if (sig == d->methods[index].signature) - return index; - } - return -1; -} - -/*! - Finds a signal with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa indexOfMethod(), indexOfSlot() -*/ -int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { - if (sig == d->methods[index].signature && - d->methods[index].methodType() == QMetaMethod::Signal) - return index; - } - return -1; -} - -/*! - Finds a slot with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa indexOfMethod(), indexOfSignal() -*/ -int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { - if (sig == d->methods[index].signature && - d->methods[index].methodType() == QMetaMethod::Slot) - return index; - } - return -1; -} - -/*! - Finds a constructor with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa constructor(), constructorCount(), addConstructor(), removeConstructor() -*/ -int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->constructors.size(); ++index) { - if (sig == d->constructors[index].signature) - return index; - } - return -1; -} - -/*! - Finds a property with the specified \a name and returns its index; - otherwise returns -1. - - \sa property(), propertyCount(), addProperty(), removeProperty() -*/ -int QMetaObjectBuilder::indexOfProperty(const QByteArray& name) -{ - for (int index = 0; index < d->properties.size(); ++index) { - if (name == d->properties[index].name) - return index; - } - return -1; -} - -/*! - Finds an enumerator with the specified \a name and returns its index; - otherwise returns -1. - - \sa enumertor(), enumeratorCount(), addEnumerator(), removeEnumerator() -*/ -int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name) -{ - for (int index = 0; index < d->enumerators.size(); ++index) { - if (name == d->enumerators[index].name) - return index; - } - return -1; -} - -/*! - Finds an item of class information with the specified \a name and - returns its index; otherwise returns -1. - - \sa classInfoName(), classInfoValue(), classInfoCount(), addClassInfo() - \sa removeClassInfo() -*/ -int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name) -{ - for (int index = 0; index < d->classInfoNames.size(); ++index) { - if (name == d->classInfoNames[index]) - return index; - } - return -1; -} - -// Align on a specific type boundary. -#define ALIGN(size,type) \ - (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1) - -/*! - \class QMetaStringTable - \inmodule QtCore - \internal - \brief The QMetaStringTable class can generate a meta-object string table at runtime. -*/ - -QMetaStringTable::QMetaStringTable(const QByteArray &className) - : m_index(0) - , m_className(className) -{ - const int index = enter(m_className); - Q_ASSERT(index == 0); - Q_UNUSED(index); -} - -// Enters the given value into the string table (if it hasn't already been -// entered). Returns the index of the string. -int QMetaStringTable::enter(const QByteArray &value) -{ - Entries::iterator it = m_entries.find(value); - if (it != m_entries.end()) - return it.value(); - int pos = m_index; - m_entries.insert(value, pos); - ++m_index; - return pos; -} - -int QMetaStringTable::preferredAlignment() -{ - return Q_ALIGNOF(QByteArrayData); -} - -// Returns the size (in bytes) required for serializing this string table. -int QMetaStringTable::blobSize() const -{ - int size = m_entries.size() * sizeof(QByteArrayData); - Entries::const_iterator it; - for (it = m_entries.constBegin(); it != m_entries.constEnd(); ++it) - size += it.key().size() + 1; - return size; -} - -static void writeString(char *out, int i, const QByteArray &str, - const int offsetOfStringdataMember, int &stringdataOffset) -{ - int size = str.size(); - qptrdiff offset = offsetOfStringdataMember + stringdataOffset - - i * sizeof(QByteArrayData); - const QByteArrayData data = - Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset); - - memcpy(out + i * sizeof(QByteArrayData), &data, sizeof(QByteArrayData)); - - memcpy(out + offsetOfStringdataMember + stringdataOffset, str.constData(), size); - out[offsetOfStringdataMember + stringdataOffset + size] = '\0'; - - stringdataOffset += size + 1; -} - -// Writes strings to string data struct. -// The struct consists of an array of QByteArrayData, followed by a char array -// containing the actual strings. This format must match the one produced by -// moc (see generator.cpp). -void QMetaStringTable::writeBlob(char *out) const -{ - Q_ASSERT(!(reinterpret_cast(out) & (preferredAlignment()-1))); - - int offsetOfStringdataMember = m_entries.size() * sizeof(QByteArrayData); - int stringdataOffset = 0; - - // qt_metacast expects the first string in the string table to be the class name. - writeString(out, /*index*/0, m_className, offsetOfStringdataMember, stringdataOffset); - - for (Entries::ConstIterator it = m_entries.constBegin(), end = m_entries.constEnd(); - it != end; ++it) { - const int i = it.value(); - if (i == 0) - continue; - const QByteArray &str = it.key(); - - writeString(out, i, str, offsetOfStringdataMember, stringdataOffset); - } -} - -// Returns the sum of all parameters (including return type) for the given -// \a methods. This is needed for calculating the size of the methods' -// parameter type/name meta-data. -static int aggregateParameterCount(const QList &methods) -{ - int sum = 0; - for (int i = 0; i < methods.size(); ++i) - sum += methods.at(i).parameterCount() + 1; // +1 for return type - return sum; -} - -// Build a QMetaObject in "buf" based on the information in "d". -// If "buf" is null, then return the number of bytes needed to -// build the QMetaObject. Returns -1 if the metaobject if -// relocatable is set, but the metaobject contains relatedMetaObjects. -static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, - int expectedSize, bool relocatable) -{ - Q_UNUSED(expectedSize); // Avoid warning in release mode - int size = 0; - int dataIndex; - int paramsIndex; - int enumIndex; - int index; - bool hasRevisionedMethods = d->hasRevisionedMethods(); - bool hasRevisionedProperties = d->hasRevisionedProperties(); - bool hasNotifySignals = false; - - if (relocatable && - (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction)) - return -1; - - // Create the main QMetaObject structure at the start of the buffer. - QMetaObject *meta = reinterpret_cast(buf); - size += sizeof(QMetaObject); - ALIGN(size, int); - if (buf) { - if (!relocatable) meta->d.superdata = d->superClass; - meta->d.relatedMetaObjects = 0; - meta->d.extradata = 0; - meta->d.static_metacall = d->staticMetacallFunction; - } - - // Populate the QMetaObjectPrivate structure. - QMetaObjectPrivate *pmeta - = reinterpret_cast(buf + size); - int pmetaSize = size; - dataIndex = MetaObjectPrivateFieldCount; - for (index = 0; index < d->properties.size(); ++index) { - if (d->properties[index].notifySignal != -1) { - hasNotifySignals = true; - break; - } - } - int methodParametersDataSize = - ((aggregateParameterCount(d->methods) - + aggregateParameterCount(d->constructors)) * 2) // types and parameter names - - d->methods.size() // return "parameters" don't have names - - d->constructors.size(); // "this" parameters don't have names - if (buf) { - Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 7, "QMetaObjectBuilder should generate the same version as moc"); - pmeta->revision = QMetaObjectPrivate::OutputRevision; - pmeta->flags = d->flags; - pmeta->className = 0; // Class name is always the first string. - //pmeta->signalCount is handled in the "output method loop" as an optimization. - - pmeta->classInfoCount = d->classInfoNames.size(); - pmeta->classInfoData = dataIndex; - dataIndex += 2 * d->classInfoNames.size(); - - pmeta->methodCount = d->methods.size(); - pmeta->methodData = dataIndex; - dataIndex += 5 * d->methods.size(); - if (hasRevisionedMethods) - dataIndex += d->methods.size(); - paramsIndex = dataIndex; - dataIndex += methodParametersDataSize; - - pmeta->propertyCount = d->properties.size(); - pmeta->propertyData = dataIndex; - dataIndex += 3 * d->properties.size(); - if (hasNotifySignals) - dataIndex += d->properties.size(); - if (hasRevisionedProperties) - dataIndex += d->properties.size(); - - pmeta->enumeratorCount = d->enumerators.size(); - pmeta->enumeratorData = dataIndex; - dataIndex += 4 * d->enumerators.size(); - - pmeta->constructorCount = d->constructors.size(); - pmeta->constructorData = dataIndex; - dataIndex += 5 * d->constructors.size(); - } else { - dataIndex += 2 * d->classInfoNames.size(); - dataIndex += 5 * d->methods.size(); - if (hasRevisionedMethods) - dataIndex += d->methods.size(); - paramsIndex = dataIndex; - dataIndex += methodParametersDataSize; - dataIndex += 3 * d->properties.size(); - if (hasNotifySignals) - dataIndex += d->properties.size(); - if (hasRevisionedProperties) - dataIndex += d->properties.size(); - dataIndex += 4 * d->enumerators.size(); - dataIndex += 5 * d->constructors.size(); - } - - // Allocate space for the enumerator key names and values. - enumIndex = dataIndex; - for (index = 0; index < d->enumerators.size(); ++index) { - QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - dataIndex += 2 * enumerator->keys.size(); - } - - // Zero terminator at the end of the data offset table. - ++dataIndex; - - // Find the start of the data and string tables. - int *data = reinterpret_cast(pmeta); - size += dataIndex * sizeof(int); - ALIGN(size, void *); - char *str = reinterpret_cast(buf + size); - if (buf) { - if (relocatable) { - meta->d.stringdata = reinterpret_cast((quintptr)size); - meta->d.data = reinterpret_cast((quintptr)pmetaSize); - } else { - meta->d.stringdata = reinterpret_cast(str); - meta->d.data = reinterpret_cast(data); - } - } - - // Reset the current data position to just past the QMetaObjectPrivate. - dataIndex = MetaObjectPrivateFieldCount; - - QMetaStringTable strings(d->className); - - // Output the class infos, - Q_ASSERT(!buf || dataIndex == pmeta->classInfoData); - for (index = 0; index < d->classInfoNames.size(); ++index) { - int name = strings.enter(d->classInfoNames[index]); - int value = strings.enter(d->classInfoValues[index]); - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = value; - } - dataIndex += 2; - } - - // Output the methods in the class. - Q_ASSERT(!buf || dataIndex == pmeta->methodData); - for (index = 0; index < d->methods.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(d->methods[index]); - int name = strings.enter(method->name()); - int argc = method->parameterCount(); - int tag = strings.enter(method->tag); - int attrs = method->attributes; - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = argc; - data[dataIndex + 2] = paramsIndex; - data[dataIndex + 3] = tag; - data[dataIndex + 4] = attrs; - if (method->methodType() == QMetaMethod::Signal) - pmeta->signalCount++; - } - dataIndex += 5; - paramsIndex += 1 + argc * 2; - } - if (hasRevisionedMethods) { - for (index = 0; index < d->methods.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(d->methods[index]); - if (buf) - data[dataIndex] = method->revision; - ++dataIndex; - } - } - - // Output the method parameters in the class. - Q_ASSERT(!buf || dataIndex == pmeta->methodData + d->methods.size() * 5 - + (hasRevisionedMethods ? d->methods.size() : 0)); - for (int x = 0; x < 2; ++x) { - QList &methods = (x == 0) ? d->methods : d->constructors; - for (index = 0; index < methods.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(methods[index]); - QList paramTypeNames = method->parameterTypes(); - int paramCount = paramTypeNames.size(); - for (int i = -1; i < paramCount; ++i) { - const QByteArray &typeName = (i < 0) ? method->returnType : paramTypeNames.at(i); - int typeInfo; - if (QtPrivate::isBuiltinType(typeName)) - typeInfo = QMetaType::type(typeName); - else - typeInfo = IsUnresolvedType | strings.enter(typeName); - if (buf) - data[dataIndex] = typeInfo; - ++dataIndex; - } - - QList paramNames = method->parameterNames; - while (paramNames.size() < paramCount) - paramNames.append(QByteArray()); - for (int i = 0; i < paramCount; ++i) { - int stringIndex = strings.enter(paramNames.at(i)); - if (buf) - data[dataIndex] = stringIndex; - ++dataIndex; - } - } - } - - // Output the properties in the class. - Q_ASSERT(!buf || dataIndex == pmeta->propertyData); - for (index = 0; index < d->properties.size(); ++index) { - QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); - int name = strings.enter(prop->name); - - int typeInfo; - if (QtPrivate::isBuiltinType(prop->type)) - typeInfo = QMetaType::type(prop->type); - else - typeInfo = IsUnresolvedType | strings.enter(prop->type); - - int flags = prop->flags; - - if (!QtPrivate::isBuiltinType(prop->type)) - flags |= EnumOrFlag; - - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = typeInfo; - data[dataIndex + 2] = flags; - } - dataIndex += 3; - } - if (hasNotifySignals) { - for (index = 0; index < d->properties.size(); ++index) { - QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); - if (buf) { - if (prop->notifySignal != -1) - data[dataIndex] = prop->notifySignal; - else - data[dataIndex] = 0; - } - ++dataIndex; - } - } - if (hasRevisionedProperties) { - for (index = 0; index < d->properties.size(); ++index) { - QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); - if (buf) - data[dataIndex] = prop->revision; - ++dataIndex; - } - } - - // Output the enumerators in the class. - Q_ASSERT(!buf || dataIndex == pmeta->enumeratorData); - for (index = 0; index < d->enumerators.size(); ++index) { - QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - int name = strings.enter(enumerator->name); - int isFlag = (int)(enumerator->isFlag); - int count = enumerator->keys.size(); - int enumOffset = enumIndex; - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = isFlag; - data[dataIndex + 2] = count; - data[dataIndex + 3] = enumOffset; - } - for (int key = 0; key < count; ++key) { - int keyIndex = strings.enter(enumerator->keys[key]); - if (buf) { - data[enumOffset++] = keyIndex; - data[enumOffset++] = enumerator->values[key]; - } - } - dataIndex += 4; - enumIndex += 2 * count; - } - - // Output the constructors in the class. - Q_ASSERT(!buf || dataIndex == pmeta->constructorData); - for (index = 0; index < d->constructors.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(d->constructors[index]); - int name = strings.enter(method->name()); - int argc = method->parameterCount(); - int tag = strings.enter(method->tag); - int attrs = method->attributes; - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = argc; - data[dataIndex + 2] = paramsIndex; - data[dataIndex + 3] = tag; - data[dataIndex + 4] = attrs; - } - dataIndex += 5; - paramsIndex += 1 + argc * 2; - } - - size += strings.blobSize(); - - if (buf) - strings.writeBlob(str); - - // Output the zero terminator in the data array. - if (buf) - data[enumIndex] = 0; - - // Create the relatedMetaObjects block if we need one. - if (d->relatedMetaObjects.size() > 0) { - ALIGN(size, QMetaObject *); - const QMetaObject **objects = - reinterpret_cast(buf + size); - if (buf) { - meta->d.relatedMetaObjects = objects; - for (index = 0; index < d->relatedMetaObjects.size(); ++index) - objects[index] = d->relatedMetaObjects[index]; - objects[index] = 0; - } - size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1); - } - - // Align the final size and return it. - ALIGN(size, void *); - Q_ASSERT(!buf || size == expectedSize); - return size; -} - -/*! - Converts this meta object builder into a concrete QMetaObject. - The return value should be deallocated using free() once it - is no longer needed. - - The returned meta object is a snapshot of the state of the - QMetaObjectBuilder. Any further modifications to the QMetaObjectBuilder - will not be reflected in previous meta objects returned by - this method. -*/ -QMetaObject *QMetaObjectBuilder::toMetaObject() const -{ - int size = buildMetaObject(d, 0, 0, false); - char *buf = reinterpret_cast(malloc(size)); - memset(buf, 0, size); - buildMetaObject(d, buf, size, false); - return reinterpret_cast(buf); -} - -/* - \internal - - Converts this meta object builder into relocatable data. This data can - be stored, copied and later passed to fromRelocatableData() to create a - concrete QMetaObject. - - The data is specific to the architecture on which it was created, but is not - specific to the process that created it. Not all meta object builder's can - be converted to data in this way. If \a ok is provided, it will be set to - true if the conversion succeeds, and false otherwise. If a - staticMetacallFunction() or any relatedMetaObject()'s are specified the - conversion to relocatable data will fail. -*/ -QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const -{ - int size = buildMetaObject(d, 0, 0, true); - if (size == -1) { - if (ok) *ok = false; - return QByteArray(); - } - - QByteArray data; - data.resize(size); - char *buf = data.data(); - memset(buf, 0, size); - buildMetaObject(d, buf, size, true); - if (ok) *ok = true; - return data; -} - -/* - \internal - - Sets the \a data returned from toRelocatableData() onto a concrete - QMetaObject instance, \a output. As the meta object's super class is not - saved in the relocatable data, it must be passed as \a superClass. -*/ -void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, - const QMetaObject *superclass, - const QByteArray &data) -{ - if (!output) - return; - - const char *buf = data.constData(); - const QMetaObject *dataMo = reinterpret_cast(buf); - - quintptr stringdataOffset = (quintptr)dataMo->d.stringdata; - quintptr dataOffset = (quintptr)dataMo->d.data; - - output->d.superdata = superclass; - output->d.stringdata = reinterpret_cast(buf + stringdataOffset); - output->d.data = reinterpret_cast(buf + dataOffset); - output->d.extradata = 0; - output->d.relatedMetaObjects = 0; - output->d.static_metacall = 0; -} - -/*! - \typedef QMetaObjectBuilder::StaticMetacallFunction - - Typedef for static metacall functions. The three parameters are - the call type value, the constructor index, and the - array of parameters. -*/ - -/*! - Returns the static metacall function to use to construct objects - of this class. The default value is null. - - \sa setStaticMetacallFunction() -*/ -QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const -{ - return d->staticMetacallFunction; -} - -/*! - Sets the static metacall function to use to construct objects - of this class to \a value. The default value is null. - - \sa staticMetacallFunction() -*/ -void QMetaObjectBuilder::setStaticMetacallFunction - (QMetaObjectBuilder::StaticMetacallFunction value) -{ - d->staticMetacallFunction = value; -} - -#ifndef QT_NO_DATASTREAM - -/*! - Serializes the contents of the meta object builder onto \a stream. - - \sa deserialize() -*/ -void QMetaObjectBuilder::serialize(QDataStream& stream) const -{ - int index; - - // Write the class and super class names. - stream << d->className; - if (d->superClass) - stream << QByteArray(d->superClass->className()); - else - stream << QByteArray(); - - // Write the counts for each type of class member. - stream << d->classInfoNames.size(); - stream << d->methods.size(); - stream << d->properties.size(); - stream << d->enumerators.size(); - stream << d->constructors.size(); - stream << d->relatedMetaObjects.size(); - - // Write the items of class information. - for (index = 0; index < d->classInfoNames.size(); ++index) { - stream << d->classInfoNames[index]; - stream << d->classInfoValues[index]; - } - - // Write the methods. - for (index = 0; index < d->methods.size(); ++index) { - const QMetaMethodBuilderPrivate *method = &(d->methods[index]); - stream << method->signature; - stream << method->returnType; - stream << method->parameterNames; - stream << method->tag; - stream << method->attributes; - if (method->revision) - stream << method->revision; - } - - // Write the properties. - for (index = 0; index < d->properties.size(); ++index) { - const QMetaPropertyBuilderPrivate *property = &(d->properties[index]); - stream << property->name; - stream << property->type; - stream << property->flags; - stream << property->notifySignal; - if (property->revision) - stream << property->revision; - } - - // Write the enumerators. - for (index = 0; index < d->enumerators.size(); ++index) { - const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - stream << enumerator->name; - stream << enumerator->isFlag; - stream << enumerator->keys; - stream << enumerator->values; - } - - // Write the constructors. - for (index = 0; index < d->constructors.size(); ++index) { - const QMetaMethodBuilderPrivate *method = &(d->constructors[index]); - stream << method->signature; - stream << method->returnType; - stream << method->parameterNames; - stream << method->tag; - stream << method->attributes; - } - - // Write the related meta objects. - for (index = 0; index < d->relatedMetaObjects.size(); ++index) { - const QMetaObject *meta = d->relatedMetaObjects[index]; - stream << QByteArray(meta->className()); - } - - // Add an extra empty QByteArray for additional data in future versions. - // This should help maintain backwards compatibility, allowing older - // versions to read newer data. - stream << QByteArray(); -} - -// Resolve a class name using the name reference map. -static const QMetaObject *resolveClassName - (const QMap& references, - const QByteArray& name) -{ - if (name == QByteArray("QObject")) - return &QObject::staticMetaObject; - else - return references.value(name, 0); -} - -/*! - Deserializes a meta object builder from \a stream into - this meta object builder. - - The \a references parameter specifies a mapping from class names - to QMetaObject instances for resolving the super class name and - related meta objects in the object that is deserialized. - The meta object for QObject is implicitly added to \a references - and does not need to be supplied. - - The QDataStream::status() value on \a stream will be set to - QDataStream::ReadCorruptData if the input data is corrupt. - The status will be set to QDataStream::ReadPastEnd if the - input was exhausted before the full meta object was read. - - \sa serialize() -*/ -void QMetaObjectBuilder::deserialize - (QDataStream& stream, - const QMap& references) -{ - QByteArray name; - const QMetaObject *cl; - int index; - - // Clear all members in the builder to their default states. - d->className.clear(); - d->superClass = &QObject::staticMetaObject; - d->classInfoNames.clear(); - d->classInfoValues.clear(); - d->methods.clear(); - d->properties.clear(); - d->enumerators.clear(); - d->constructors.clear(); - d->relatedMetaObjects.clear(); - d->staticMetacallFunction = 0; - - // Read the class and super class names. - stream >> d->className; - stream >> name; - if (name.isEmpty()) { - d->superClass = 0; - } else if ((cl = resolveClassName(references, name)) != 0) { - d->superClass = cl; - } else { - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - - // Read the counts for each type of class member. - int classInfoCount, methodCount, propertyCount; - int enumeratorCount, constructorCount, relatedMetaObjectCount; - stream >> classInfoCount; - stream >> methodCount; - stream >> propertyCount; - stream >> enumeratorCount; - stream >> constructorCount; - stream >> relatedMetaObjectCount; - if (classInfoCount < 0 || methodCount < 0 || - propertyCount < 0 || enumeratorCount < 0 || - constructorCount < 0 || relatedMetaObjectCount < 0) { - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - - // Read the items of class information. - for (index = 0; index < classInfoCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - QByteArray value; - stream >> name; - stream >> value; - addClassInfo(name, value); - } - - // Read the member methods. - for (index = 0; index < methodCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - addMethod(name); - QMetaMethodBuilderPrivate *method = &(d->methods[index]); - stream >> method->returnType; - stream >> method->parameterNames; - stream >> method->tag; - stream >> method->attributes; - if (method->attributes & MethodRevisioned) - stream >> method->revision; - if (method->methodType() == QMetaMethod::Constructor) { - // Cannot add a constructor in this set of methods. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the properties. - for (index = 0; index < propertyCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - QByteArray type; - stream >> name; - stream >> type; - addProperty(name, type); - QMetaPropertyBuilderPrivate *property = &(d->properties[index]); - stream >> property->flags; - stream >> property->notifySignal; - if (property->notifySignal < -1 || - property->notifySignal >= d->methods.size()) { - // Notify signal method index is out of range. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - if (property->notifySignal >= 0 && - d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) { - // Notify signal method index does not refer to a signal. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - if (property->flags & Revisioned) - stream >> property->revision; - } - - // Read the enumerators. - for (index = 0; index < enumeratorCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - addEnumerator(name); - QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - stream >> enumerator->isFlag; - stream >> enumerator->keys; - stream >> enumerator->values; - if (enumerator->keys.size() != enumerator->values.size()) { - // Mismatch between number of keys and number of values. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the constructor methods. - for (index = 0; index < constructorCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - addConstructor(name); - QMetaMethodBuilderPrivate *method = &(d->constructors[index]); - stream >> method->returnType; - stream >> method->parameterNames; - stream >> method->tag; - stream >> method->attributes; - if (method->methodType() != QMetaMethod::Constructor) { - // The type must be Constructor. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the related meta objects. - for (index = 0; index < relatedMetaObjectCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - cl = resolveClassName(references, name); - if (!cl) { - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - addRelatedMetaObject(cl); - } - - // Read the extra data block, which is reserved for future use. - stream >> name; -} - -#endif // !QT_NO_DATASTREAM - -/*! - \class QMetaMethodBuilder - \inmodule QtCore - \internal - \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder. -*/ - -QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const -{ - // Positive indices indicate methods, negative indices indicate constructors. - if (_mobj && _index >= 0 && _index < _mobj->d->methods.size()) - return &(_mobj->d->methods[_index]); - else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size()) - return &(_mobj->d->constructors[(-_index) - 1]); - else - return 0; -} - -/*! - \fn QMetaMethodBuilder::QMetaMethodBuilder() - \internal -*/ - -/*! - Returns the index of this method within its QMetaObjectBuilder. -*/ -int QMetaMethodBuilder::index() const -{ - if (_index >= 0) - return _index; // Method, signal, or slot - else - return (-_index) - 1; // Constructor -} - -/*! - Returns the type of this method (signal, slot, method, or constructor). -*/ -QMetaMethod::MethodType QMetaMethodBuilder::methodType() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->methodType(); - else - return QMetaMethod::Method; -} - -/*! - Returns the signature of this method. - - \sa parameterNames(), returnType() -*/ -QByteArray QMetaMethodBuilder::signature() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->signature; - else - return QByteArray(); -} - -/*! - Returns the return type for this method; empty if the method's - return type is \c{void}. - - \sa setReturnType(), signature() -*/ -QByteArray QMetaMethodBuilder::returnType() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->returnType; - else - return QByteArray(); -} - -/*! - Sets the return type for this method to \a value. If \a value - is empty, then the method's return type is \c{void}. The \a value - will be normalized before it is added to the method. - - \sa returnType(), parameterTypes(), signature() -*/ -void QMetaMethodBuilder::setReturnType(const QByteArray& value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->returnType = QMetaObject::normalizedType(value); -} - -/*! - Returns the list of parameter types for this method. - - \sa returnType(), parameterNames() -*/ -QList QMetaMethodBuilder::parameterTypes() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->parameterTypes(); - else - return QList(); -} - -/*! - Returns the list of parameter names for this method. - - \sa setParameterNames() -*/ -QList QMetaMethodBuilder::parameterNames() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->parameterNames; - else - return QList(); -} - -/*! - Sets the list of parameter names for this method to \a value. - - \sa parameterNames() -*/ -void QMetaMethodBuilder::setParameterNames(const QList& value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->parameterNames = value; -} - -/*! - Returns the tag associated with this method. - - \sa setTag() -*/ -QByteArray QMetaMethodBuilder::tag() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->tag; - else - return QByteArray(); -} - -/*! - Sets the tag associated with this method to \a value. - - \sa setTag() -*/ -void QMetaMethodBuilder::setTag(const QByteArray& value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->tag = value; -} - -/*! - Returns the access specification of this method (private, protected, - or public). The default value is QMetaMethod::Public for methods, - slots, signals and constructors. - - \sa setAccess() -*/ -QMetaMethod::Access QMetaMethodBuilder::access() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->access(); - else - return QMetaMethod::Public; -} - -/*! - Sets the access specification of this method (private, protected, - or public) to \a value. If the method is a signal, this function - will be ignored. - - \sa access() -*/ -void QMetaMethodBuilder::setAccess(QMetaMethod::Access value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d && d->methodType() != QMetaMethod::Signal) - d->setAccess(value); -} - -/*! - Returns the additional attributes for this method. - - \sa setAttributes() -*/ -int QMetaMethodBuilder::attributes() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return (d->attributes >> 4); - else - return 0; -} - -/*! - Sets the additional attributes for this method to \a value. - - \sa attributes() -*/ -void QMetaMethodBuilder::setAttributes(int value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->attributes = ((d->attributes & 0x0f) | (value << 4)); -} - -/*! - Returns the revision of this method. - - \sa setRevision() -*/ -int QMetaMethodBuilder::revision() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->revision; - return 0; - -} - -/*! - Sets the \a revision of this method. - - \sa revision() -*/ -void QMetaMethodBuilder::setRevision(int revision) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) { - d->revision = revision; - if (revision) - d->attributes |= MethodRevisioned; - else - d->attributes &= ~MethodRevisioned; - } -} - -/*! - \class QMetaPropertyBuilder - \inmodule QtCore - \internal - \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder. -*/ - -QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const -{ - if (_mobj && _index >= 0 && _index < _mobj->d->properties.size()) - return &(_mobj->d->properties[_index]); - else - return 0; -} - -/*! - \fn QMetaPropertyBuilder::QMetaPropertyBuilder() - \internal -*/ - -/*! - \fn int QMetaPropertyBuilder::index() const - - Returns the index of this property within its QMetaObjectBuilder. -*/ - -/*! - Returns the name associated with this property. - - \sa type() -*/ -QByteArray QMetaPropertyBuilder::name() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->name; - else - return QByteArray(); -} - -/*! - Returns the type associated with this property. - - \sa name() -*/ -QByteArray QMetaPropertyBuilder::type() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->type; - else - return QByteArray(); -} - -/*! - Returns \c true if this property has a notify signal; false otherwise. - - \sa notifySignal(), setNotifySignal(), removeNotifySignal() -*/ -bool QMetaPropertyBuilder::hasNotifySignal() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Notify); - else - return false; -} - -/*! - Returns the notify signal associated with this property. - - \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal() -*/ -QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d && d->notifySignal >= 0) - return QMetaMethodBuilder(_mobj, d->notifySignal); - else - return QMetaMethodBuilder(); -} - -/*! - Sets the notify signal associated with this property to \a value. - - \sa hasNotifySignal(), notifySignal(), removeNotifySignal() -*/ -void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) { - if (value._mobj) { - d->notifySignal = value._index; - d->setFlag(Notify, true); - } else { - d->notifySignal = -1; - d->setFlag(Notify, false); - } - } -} - -/*! - Removes the notify signal from this property. - - \sa hasNotifySignal(), notifySignal(), setNotifySignal() -*/ -void QMetaPropertyBuilder::removeNotifySignal() -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) { - d->notifySignal = -1; - d->setFlag(Notify, false); - } -} - -/*! - Returns \c true if this property is readable; otherwise returns \c false. - The default value is true. - - \sa setReadable(), isWritable() -*/ -bool QMetaPropertyBuilder::isReadable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Readable); - else - return false; -} - -/*! - Returns \c true if this property is writable; otherwise returns \c false. - The default value is true. - - \sa setWritable(), isReadable() -*/ -bool QMetaPropertyBuilder::isWritable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Writable); - else - return false; -} - -/*! - Returns \c true if this property can be reset to a default value; otherwise - returns \c false. The default value is false. - - \sa setResettable() -*/ -bool QMetaPropertyBuilder::isResettable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Resettable); - else - return false; -} - -/*! - Returns \c true if this property is designable; otherwise returns \c false. - This default value is false. - - \sa setDesignable(), isScriptable(), isStored() -*/ -bool QMetaPropertyBuilder::isDesignable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Designable); - else - return false; -} - -/*! - Returns \c true if the property is scriptable; otherwise returns \c false. - This default value is true. - - \sa setScriptable(), isDesignable(), isStored() -*/ -bool QMetaPropertyBuilder::isScriptable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Scriptable); - else - return false; -} - -/*! - Returns \c true if the property is stored; otherwise returns \c false. - This default value is false. - - \sa setStored(), isDesignable(), isScriptable() -*/ -bool QMetaPropertyBuilder::isStored() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Stored); - else - return false; -} - -/*! - Returns \c true if the property is editable; otherwise returns \c false. - This default value is false. - - \sa setEditable(), isDesignable(), isScriptable(), isStored() -*/ -bool QMetaPropertyBuilder::isEditable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Editable); - else - return false; -} - -/*! - Returns \c true if this property is designated as the \c USER - property, i.e., the one that the user can edit or that is - significant in some other way. Otherwise it returns - false. This default value is false. - - \sa setUser(), isDesignable(), isScriptable() -*/ -bool QMetaPropertyBuilder::isUser() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(User); - else - return false; -} - -/*! - Returns \c true if the property has a C++ setter function that - follows Qt's standard "name" / "setName" pattern. Designer and uic - query hasStdCppSet() in order to avoid expensive - QObject::setProperty() calls. All properties in Qt [should] follow - this pattern. The default value is false. - - \sa setStdCppSet() -*/ -bool QMetaPropertyBuilder::hasStdCppSet() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(StdCppSet); - else - return false; -} - -/*! - Returns \c true if the property is an enumerator or flag type; - otherwise returns \c false. This default value is false. - - \sa setEnumOrFlag() -*/ -bool QMetaPropertyBuilder::isEnumOrFlag() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(EnumOrFlag); - else - return false; -} - -/*! - Returns \c true if the property is constant; otherwise returns \c false. - The default value is false. -*/ -bool QMetaPropertyBuilder::isConstant() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Constant); - else - return false; -} - -/*! - Returns \c true if the property is final; otherwise returns \c false. - The default value is false. -*/ -bool QMetaPropertyBuilder::isFinal() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Final); - else - return false; -} - -/*! - Sets this property to readable if \a value is true. - - \sa isReadable(), setWritable() -*/ -void QMetaPropertyBuilder::setReadable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Readable, value); -} - -/*! - Sets this property to writable if \a value is true. - - \sa isWritable(), setReadable() -*/ -void QMetaPropertyBuilder::setWritable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Writable, value); -} - -/*! - Sets this property to resettable if \a value is true. - - \sa isResettable() -*/ -void QMetaPropertyBuilder::setResettable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Resettable, value); -} - -/*! - Sets this property to designable if \a value is true. - - \sa isDesignable(), setScriptable(), setStored() -*/ -void QMetaPropertyBuilder::setDesignable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Designable, value); -} - -/*! - Sets this property to scriptable if \a value is true. - - \sa isScriptable(), setDesignable(), setStored() -*/ -void QMetaPropertyBuilder::setScriptable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Scriptable, value); -} - -/*! - Sets this property to storable if \a value is true. - - \sa isStored(), setDesignable(), setScriptable() -*/ -void QMetaPropertyBuilder::setStored(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Stored, value); -} - -/*! - Sets this property to editable if \a value is true. - - \sa isEditable(), setDesignable(), setScriptable(), setStored() -*/ -void QMetaPropertyBuilder::setEditable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Editable, value); -} - -/*! - Sets the \c USER flag on this property to \a value. - - \sa isUser(), setDesignable(), setScriptable() -*/ -void QMetaPropertyBuilder::setUser(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(User, value); -} - -/*! - Sets the C++ setter flag on this property to \a value, which is - true if the property has a C++ setter function that follows Qt's - standard "name" / "setName" pattern. - - \sa hasStdCppSet() -*/ -void QMetaPropertyBuilder::setStdCppSet(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(StdCppSet, value); -} - -/*! - Sets this property to be of an enumerator or flag type if - \a value is true. - - \sa isEnumOrFlag() -*/ -void QMetaPropertyBuilder::setEnumOrFlag(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(EnumOrFlag, value); -} - -/*! - Sets the \c CONSTANT flag on this property to \a value. - - \sa isConstant() -*/ -void QMetaPropertyBuilder::setConstant(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Constant, value); -} - -/*! - Sets the \c FINAL flag on this property to \a value. - - \sa isFinal() -*/ -void QMetaPropertyBuilder::setFinal(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Final, value); -} - -/*! - Returns the revision of this property. - - \sa setRevision() -*/ -int QMetaPropertyBuilder::revision() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->revision; - return 0; - -} - -/*! - Sets the \a revision of this property. - - \sa revision() -*/ -void QMetaPropertyBuilder::setRevision(int revision) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) { - d->revision = revision; - d->setFlag(Revisioned, revision != 0); - } -} - - -/*! - \class QMetaEnumBuilder - \inmodule QtCore - \internal - \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder. -*/ - -QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const -{ - if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size()) - return &(_mobj->d->enumerators[_index]); - else - return 0; -} - -/*! - \fn QMetaEnumBuilder::QMetaEnumBuilder() - \internal -*/ - -/*! - \fn int QMetaEnumBuilder::index() const - - Returns the index of this enumerator within its QMetaObjectBuilder. -*/ - -/*! - Returns the name of the enumerator (without the scope). -*/ -QByteArray QMetaEnumBuilder::name() const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - return d->name; - else - return QByteArray(); -} - -/*! - Returns \c true if this enumerator is used as a flag; otherwise returns - false. - - \sa setIsFlag() -*/ -bool QMetaEnumBuilder::isFlag() const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - return d->isFlag; - else - return false; -} - -/*! - Sets this enumerator to be used as a flag if \a value is true. - - \sa isFlag() -*/ -void QMetaEnumBuilder::setIsFlag(bool value) -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - d->isFlag = value; -} - -/*! - Returns the number of keys. - - \sa key(), addKey() -*/ -int QMetaEnumBuilder::keyCount() const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - return d->keys.size(); - else - return 0; -} - -/*! - Returns the key with the given \a index, or an empty QByteArray - if no such key exists. - - \sa keyCount(), addKey(), value() -*/ -QByteArray QMetaEnumBuilder::key(int index) const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d && index >= 0 && index < d->keys.size()) - return d->keys[index]; - else - return QByteArray(); -} - -/*! - Returns the value with the given \a index; or returns -1 if there - is no such value. - - \sa keyCount(), addKey(), key() -*/ -int QMetaEnumBuilder::value(int index) const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d && index >= 0 && index < d->keys.size()) - return d->values[index]; - else - return -1; -} - -/*! - Adds a new key called \a name to this enumerator, associated - with \a value. Returns the index of the new key. - - \sa keyCount(), key(), value(), removeKey() -*/ -int QMetaEnumBuilder::addKey(const QByteArray& name, int value) -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) { - int index = d->keys.size(); - d->keys += name; - d->values += value; - return index; - } else { - return -1; - } -} - -/*! - Removes the key at \a index from this enumerator. - - \sa addKey() -*/ -void QMetaEnumBuilder::removeKey(int index) -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d && index >= 0 && index < d->keys.size()) { - d->keys.removeAt(index); - d->values.removeAt(index); - } -} - -QT_END_NAMESPACE diff --git a/DOtherSide/DynamicQObject/private/qmetatype.cpp b/DOtherSide/DynamicQObject/private/qmetatype.cpp deleted file mode 100644 index f74c592..0000000 --- a/DOtherSide/DynamicQObject/private/qmetatype.cpp +++ /dev/null @@ -1,2408 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmetatype.h" -#include "qmetatype_p.h" -#include "qobjectdefs.h" -#include "qdatetime.h" -#include "qbytearray.h" -#include "qreadwritelock.h" -#include "qstring.h" -#include "qstringlist.h" -#include "qvector.h" -#include "qlocale.h" -#include "qeasingcurve.h" -#include "quuid.h" -#include "qvariant.h" -#include "qmetatypeswitcher_p.h" - -#ifndef QT_BOOTSTRAPPED -# include "qbitarray.h" -# include "qurl.h" -# include "qvariant.h" -# include "qabstractitemmodel.h" -# include "qregularexpression.h" -# include "qjsonvalue.h" -# include "qjsonobject.h" -# include "qjsonarray.h" -# include "qjsondocument.h" -#endif - -#ifndef QT_NO_GEOM_VARIANT -# include "qsize.h" -# include "qpoint.h" -# include "qrect.h" -# include "qline.h" -#endif - -QT_BEGIN_NAMESPACE - -#define NS(x) QT_PREPEND_NAMESPACE(x) - - -namespace { -struct DefinedTypesFilter { - template - struct Acceptor { - static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition::IsAvailable && QModulesPrivate::QTypeModuleInfo::IsCore; - }; -}; -} // namespace - -/*! - \macro Q_DECLARE_OPAQUE_POINTER(PointerType) - \relates QMetaType - \since 5.0 - - This macro enables pointers to forward-declared types (\a PointerType) - to be registered with QMetaType using either Q_DECLARE_METATYPE() - or qRegisterMetaType(). - - \sa Q_DECLARE_METATYPE(), qRegisterMetaType() -*/ - -/*! - \macro Q_DECLARE_METATYPE(Type) - \relates QMetaType - - This macro makes the type \a Type known to QMetaType as long as it - provides a public default constructor, a public copy constructor and - a public destructor. - It is needed to use the type \a Type as a custom type in QVariant. - - This macro requires that \a Type is a fully defined type at the point where - it is used. For pointer types, it also requires that the pointed to type is - fully defined. Use in conjunction with Q_DECLARE_OPAQUE_POINTER() to - register pointers to forward declared types. - - Ideally, this macro should be placed below the declaration of - the class or struct. If that is not possible, it can be put in - a private header file which has to be included every time that - type is used in a QVariant. - - Adding a Q_DECLARE_METATYPE() makes the type known to all template - based functions, including QVariant. Note that if you intend to - use the type in \e queued signal and slot connections or in - QObject's property system, you also have to call - qRegisterMetaType() since the names are resolved at runtime. - - This example shows a typical use case of Q_DECLARE_METATYPE(): - - \snippet code/src_corelib_kernel_qmetatype.cpp 0 - - If \c MyStruct is in a namespace, the Q_DECLARE_METATYPE() macro - has to be outside the namespace: - - \snippet code/src_corelib_kernel_qmetatype.cpp 1 - - Since \c{MyStruct} is now known to QMetaType, it can be used in QVariant: - - \snippet code/src_corelib_kernel_qmetatype.cpp 2 - - \sa qRegisterMetaType() -*/ - -/*! - \macro Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(Container) - \relates QMetaType - - This macro makes the container \a Container known to QMetaType as a sequential - container. This makes it possible to put an instance of Container into - a QVariant, if T itself is known to QMetaType. - - Note that all of the Qt sequential containers already have built-in - support, and it is not necessary to use this macro with them. The - std::vector and std::list containers also have built-in support. - - This example shows a typical use of Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(): - - \snippet code/src_corelib_kernel_qmetatype.cpp 10 -*/ - -/*! - \macro Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(Container) - \relates QMetaType - - This macro makes the container \a Container known to QMetaType as an associative - container. This makes it possible to put an instance of Container into - a QVariant, if T and U are themselves known to QMetaType. - - Note that all of the Qt associative containers already have built-in - support, and it is not necessary to use this macro with them. The - std::map container also has built-in support. - - This example shows a typical use of Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(): - - \snippet code/src_corelib_kernel_qmetatype.cpp 11 -*/ - -/*! - \macro Q_DECLARE_SMART_POINTER_METATYPE(SmartPointer) - \relates QMetaType - - This macro makes the smart pointer \a SmartPointer known to QMetaType as a - smart pointer. This makes it possible to put an instance of SmartPointer into - a QVariant, if T is a type which inherits QObject. - - Note that the QWeakPointer, QSharedPointer and QPointer already have built-in - support, and it is not necessary to use this macro with them. - - This example shows a typical use of Q_DECLARE_SMART_POINTER_METATYPE(): - - \snippet code/src_corelib_kernel_qmetatype.cpp 13 -*/ - -/*! - \enum QMetaType::Type - - These are the built-in types supported by QMetaType: - - \value Void \c void - \value Bool \c bool - \value Int \c int - \value UInt \c{unsigned int} - \value Double \c double - \value QChar QChar - \value QString QString - \value QByteArray QByteArray - - \value VoidStar \c{void *} - \value Long \c{long} - \value LongLong LongLong - \value Short \c{short} - \value Char \c{char} - \value ULong \c{unsigned long} - \value ULongLong ULongLong - \value UShort \c{unsigned short} - \value SChar \c{signed char} - \value UChar \c{unsigned char} - \value Float \c float - \value QObjectStar QObject * - \value QVariant QVariant - - \value QCursor QCursor - \value QDate QDate - \value QSize QSize - \value QTime QTime - \value QVariantList QVariantList - \value QPolygon QPolygon - \value QPolygonF QPolygonF - \value QColor QColor - \value QSizeF QSizeF - \value QRectF QRectF - \value QLine QLine - \value QTextLength QTextLength - \value QStringList QStringList - \value QVariantMap QVariantMap - \value QVariantHash QVariantHash - \value QIcon QIcon - \value QPen QPen - \value QLineF QLineF - \value QTextFormat QTextFormat - \value QRect QRect - \value QPoint QPoint - \value QUrl QUrl - \value QRegExp QRegExp - \value QRegularExpression QRegularExpression - \value QDateTime QDateTime - \value QPointF QPointF - \value QPalette QPalette - \value QFont QFont - \value QBrush QBrush - \value QRegion QRegion - \value QBitArray QBitArray - \value QImage QImage - \value QKeySequence QKeySequence - \value QSizePolicy QSizePolicy - \value QPixmap QPixmap - \value QLocale QLocale - \value QBitmap QBitmap - \value QMatrix QMatrix - \value QTransform QTransform - \value QMatrix4x4 QMatrix4x4 - \value QVector2D QVector2D - \value QVector3D QVector3D - \value QVector4D QVector4D - \value QQuaternion QQuaternion - \value QEasingCurve QEasingCurve - \value QJsonValue QJsonValue - \value QJsonObject QJsonObject - \value QJsonArray QJsonArray - \value QJsonDocument QJsonDocument - \value QModelIndex QModelIndex - \value QUuid QUuid - - \value User Base value for user types - \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered - - Additional types can be registered using Q_DECLARE_METATYPE(). - - \sa type(), typeName() -*/ - -/*! - \enum QMetaType::TypeFlag - - The enum describes attributes of a type supported by QMetaType. - - \value NeedsConstruction This type has non-trivial constructors. If the flag is not set instances can be safely initialized with memset to 0. - \value NeedsDestruction This type has a non-trivial destructor. If the flag is not set calls to the destructor are not necessary before discarding objects. - \value MovableType An instance of a type having this attribute can be safely moved by memcpy. - \omitvalue SharedPointerToQObject - \omitvalue IsEnumeration - \omitvalue PointerToQObject - \omitvalue WeakPointerToQObject - \omitvalue TrackingPointerToQObject - \omitvalue WasDeclaredAsMetaType -*/ - -/*! - \class QMetaType - \inmodule QtCore - \brief The QMetaType class manages named types in the meta-object system. - - \ingroup objectmodel - \threadsafe - - The class is used as a helper to marshall types in QVariant and - in queued signals and slots connections. It associates a type - name to a type so that it can be created and destructed - dynamically at run-time. Declare new types with Q_DECLARE_METATYPE() - to make them available to QVariant and other template-based functions. - Call qRegisterMetaType() to make type available to non-template based - functions, such as the queued signal and slot connections. - - Any class or struct that has a public default - constructor, a public copy constructor, and a public destructor - can be registered. - - The following code allocates and destructs an instance of - \c{MyClass}: - - \snippet code/src_corelib_kernel_qmetatype.cpp 3 - - If we want the stream operators \c operator<<() and \c - operator>>() to work on QVariant objects that store custom types, - the custom type must provide \c operator<<() and \c operator>>() - operators. - - \sa Q_DECLARE_METATYPE(), QVariant::setValue(), QVariant::value(), QVariant::fromValue() -*/ - -/*! - \fn bool QMetaType::isValid() const - \since 5.0 - - Returns \c true if this QMetaType object contains valid - information about a type, false otherwise. -*/ - -/*! - \fn bool QMetaType::isRegistered() const - \since 5.0 - - Returns \c true if this QMetaType object contains valid - information about a type, false otherwise. -*/ - -/*! - \fn bool QMetaType::sizeOf() const - \since 5.0 - - Returns the size of the type in bytes (i.e. sizeof(T), - where T is the actual type for which this QMetaType instance - was constructed for). - - This function is typically used together with construct() - to perform low-level management of the memory used by a type. - - \sa QMetaType::construct(), QMetaType::sizeOf() -*/ - -/*! - \fn TypeFlags QMetaType::flags() const - \since 5.0 - - Returns flags of the type for which this QMetaType instance was constructed. - - \sa QMetaType::TypeFlags, QMetaType::typeFlags() -*/ - -/*! - \fn const QMetaObject *QMetaType::metaObject() const - \since 5.0 - \internal -*/ - -/*! - \fn void *QMetaType::create(const void *copy = 0) const - \since 5.0 - - Returns a copy of \a copy, assuming it is of the type that this - QMetaType instance was created for. If \a copy is null, creates - a default constructed instance. - - \sa QMetaType::destroy() -*/ - -/*! - \fn void QMetaType::destroy(void *data) const - \since 5.0 - - Destroys the \a data, assuming it is of the type that this - QMetaType instance was created for. - - \sa QMetaType::create() -*/ - -/*! - \fn void *QMetaType::construct(void *where, const void *copy = 0) const - \since 5.0 - - Constructs a value of the type that this QMetaType instance - was constructed for in the existing memory addressed by \a where, - that is a copy of \a copy, and returns \a where. If \a copy is - zero, the value is default constructed. - - This is a low-level function for explicitly managing the memory - used to store the type. Consider calling create() if you don't - need this level of control (that is, use "new" rather than - "placement new"). - - You must ensure that \a where points to a location where the new - value can be stored and that \a where is suitably aligned. - The type's size can be queried by calling sizeOf(). - - The rule of thumb for alignment is that a type is aligned to its - natural boundary, which is the smallest power of 2 that is bigger - than the type, unless that alignment is larger than the maximum - useful alignment for the platform. For practical purposes, - alignment larger than 2 * sizeof(void*) is only necessary for - special hardware instructions (e.g., aligned SSE loads and stores - on x86). -*/ - -/*! - \fn void QMetaType::destruct(void *data) const - \since 5.0 - - Destructs the value, located at \a data, assuming that it is - of the type for which this QMetaType instance was constructed for. - - Unlike destroy(), this function only invokes the type's - destructor, it doesn't invoke the delete operator. - \sa QMetaType::construct() -*/ - -/*! - \fn QMetaType::~QMetaType() - - Destructs this object. -*/ - -#define QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeId, RealName) \ - { #RealName, sizeof(#RealName) - 1, MetaTypeId }, - -#define QT_ADD_STATIC_METATYPE_ALIASES_ITER(MetaTypeName, MetaTypeId, AliasingName, RealNameStr) \ - { RealNameStr, sizeof(RealNameStr) - 1, QMetaType::MetaTypeName }, - -#define QT_ADD_STATIC_METATYPE_HACKS_ITER(MetaTypeName, TypeId, Name) \ - QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeName, Name) - -static const struct { const char * typeName; int typeNameLength; int type; } types[] = { - QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE) - QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER) - QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER) - {0, 0, QMetaType::UnknownType} -}; - -Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0; -Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = 0; -Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = 0; - -class QCustomTypeInfo : public QMetaTypeInterface -{ -public: - QCustomTypeInfo() - : alias(-1) - { - QMetaTypeInterface empty = QT_METATYPE_INTERFACE_INIT(void); - *static_cast(this) = empty; - } - QByteArray typeName; - int alias; -}; - -template -class QMetaTypeFunctionRegistry -{ -public: - ~QMetaTypeFunctionRegistry() - { - const QWriteLocker locker(&lock); - map.clear(); - } - - bool contains(Key k) const - { - const QReadLocker locker(&lock); - return map.contains(k); - } - - bool insertIfNotContains(Key k, const T *f) - { - const QWriteLocker locker(&lock); - const T* &fun = map[k]; - if (fun != 0) - return false; - fun = f; - return true; - } - - const T *function(Key k) const - { - const QReadLocker locker(&lock); - return map.value(k, 0); - } - - void remove(int from, int to) - { - const Key k(from, to); - const QWriteLocker locker(&lock); - map.remove(k); - } -private: - mutable QReadWriteLock lock; - QHash map; -}; - -typedef QMetaTypeFunctionRegistry > -QMetaTypeConverterRegistry; -typedef QMetaTypeFunctionRegistry -QMetaTypeComparatorRegistry; -typedef QMetaTypeFunctionRegistry -QMetaTypeDebugStreamRegistry; - -namespace -{ -union CheckThatItIsPod -{ // This should break if QMetaTypeInterface is not a POD type - QMetaTypeInterface iface; -}; -} - -Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE); -Q_GLOBAL_STATIC(QVector, customTypes) -Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock) -Q_GLOBAL_STATIC(QMetaTypeConverterRegistry, customTypesConversionRegistry) -Q_GLOBAL_STATIC(QMetaTypeComparatorRegistry, customTypesComparatorRegistry) -Q_GLOBAL_STATIC(QMetaTypeDebugStreamRegistry, customTypesDebugStreamRegistry) - -/*! - \fn bool QMetaType::registerConverter() - \since 5.2 - Registers the possibility of an implicit conversion from type From to type To in the meta - type system. Returns \c true if the registration succeeded, otherwise false. -*/ - -/*! - \fn bool QMetaType::registerConverter(MemberFunction function) - \since 5.2 - \overload - Registers a method \a function like To From::function() const as converter from type From - to type To in the meta type system. Returns \c true if the registration succeeded, otherwise false. -*/ - -/*! - \fn bool QMetaType::registerConverter(MemberFunctionOk function) - \since 5.2 - \overload - Registers a method \a function like To From::function(bool *ok) const as converter from type From - to type To in the meta type system. Returns \c true if the registration succeeded, otherwise false. -*/ - -/*! - \fn bool QMetaType::registerConverter(UnaryFunction function) - \since 5.2 - \overload - Registers a unary function object \a function as converter from type From - to type To in the meta type system. Returns \c true if the registration succeeded, otherwise false. -*/ - -/*! - \fn bool QMetaType::registerComparators() - \since 5.2 - Registers comparison operetarors for the user-registered type T. This requires T to have - both an operator== and an operator<. - Returns \c true if the registration succeeded, otherwise false. -*/ - -#ifndef QT_NO_DEBUG_STREAM -/*! - \fn bool QMetaType::registerDebugStreamOperator() - Registers the debug stream operator for the user-registered type T. This requires T to have - an operator<<(QDebug dbg, T). - Returns \c true if the registration succeeded, otherwise false. -*/ -#endif - -/*! - Registers function \a f as converter function from type id \a from to \a to. - If there's already a conversion registered, this does nothing but deleting \a f. - Returns \c true if the registration succeeded, otherwise false. - \since 5.2 - \internal -*/ -bool QMetaType::registerConverterFunction(const QtPrivate::AbstractConverterFunction *f, int from, int to) -{ - if (!customTypesConversionRegistry()->insertIfNotContains(qMakePair(from, to), f)) { - qWarning("Type conversion already registered from type %s to type %s", - QMetaType::typeName(from), QMetaType::typeName(to)); - return false; - } - return true; -} - -/*! - \internal - - Invoked automatically when a converter function object is destroyed. - */ -void QMetaType::unregisterConverterFunction(int from, int to) -{ - if (customTypesConversionRegistry.isDestroyed()) - return; - customTypesConversionRegistry()->remove(from, to); -} - -bool QMetaType::registerComparatorFunction(const QtPrivate::AbstractComparatorFunction *f, int type) -{ - if (!customTypesComparatorRegistry()->insertIfNotContains(type, f)) { - qWarning("Comparators already registered for type %s", QMetaType::typeName(type)); - return false; - } - return true; -} - -/*! - \fn bool QMetaType::hasRegisteredComparators() - Returns \c true, if the meta type system has registered comparators for type T. - \since 5.2 - */ - -/*! - Returns \c true, if the meta type system has registered comparators for type id \a typeId. - \since 5.2 - */ -bool QMetaType::hasRegisteredComparators(int typeId) -{ - return customTypesComparatorRegistry()->contains(typeId); -} - -#ifndef QT_NO_DEBUG_STREAM -bool QMetaType::registerDebugStreamOperatorFunction(const QtPrivate::AbstractDebugStreamFunction *f, - int type) -{ - if (!customTypesDebugStreamRegistry()->insertIfNotContains(type, f)) { - qWarning("Debug stream operator already registered for type %s", QMetaType::typeName(type)); - return false; - } - return true; -} - -/*! - \fn bool QMetaType::hasRegisteredDebugStreamOperator() - Returns \c true, if the meta type system has a registered debug stream operator for type T. - \since 5.2 - */ - -/*! - Returns \c true, if the meta type system has a registered debug stream operator for type - id \a typeId. - \since 5.2 -*/ -bool QMetaType::hasRegisteredDebugStreamOperator(int typeId) -{ - return customTypesDebugStreamRegistry()->contains(typeId); -} -#endif - -/*! - Converts the object at \a from from \a fromTypeId to the preallocated space at \a to - typed \a toTypeId. Returns \c true, if the conversion succeeded, otherwise false. - \since 5.2 -*/ -bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId) -{ - const QtPrivate::AbstractConverterFunction * const f = - customTypesConversionRegistry()->function(qMakePair(fromTypeId, toTypeId)); - return f && f->convert(f, from, to); -} - -/*! - Compares the objects at \a lhs and \a rhs. Both objects need to be of type \a typeId. - \a result is set to less than, equal to or greater than zero, if \a lhs is less than, equal to - or greater than \a rhs. Returns \c true, if the comparison succeeded, otherwiess false. - \since 5.2 -*/ -bool QMetaType::compare(const void *lhs, const void *rhs, int typeId, int* result) -{ - const QtPrivate::AbstractComparatorFunction * const f = - customTypesComparatorRegistry()->function(typeId); - if (!f) - return false; - if (f->equals(f, lhs, rhs)) - *result = 0; - else - *result = f->lessThan(f, lhs, rhs) ? -1 : 1; - return true; -} - -/*! - Streams the object at \a rhs of type \a typeId to the debug stream \a dbg. Returns \c true - on success, otherwise false. - \since 5.2 -*/ -bool QMetaType::debugStream(QDebug& dbg, const void *rhs, int typeId) -{ - const QtPrivate::AbstractDebugStreamFunction * const f = customTypesDebugStreamRegistry()->function(typeId); - if (!f) - return false; - f->stream(f, dbg, rhs); - return true; -} - -/*! - \fn bool QMetaType::hasRegisteredConverterFunction() - Returns \c true, if the meta type system has a registered conversion from type From to type To. - \since 5.2 - \overload - */ - -/*! - Returns \c true, if the meta type system has a registered conversion from meta type id \a fromTypeId - to \a toTypeId - \since 5.2 -*/ -bool QMetaType::hasRegisteredConverterFunction(int fromTypeId, int toTypeId) -{ - return customTypesConversionRegistry()->contains(qMakePair(fromTypeId, toTypeId)); -} - -#ifndef QT_NO_DATASTREAM -/*! - \internal -*/ -void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveOp, - LoadOperator loadOp) -{ - registerStreamOperators(type(typeName), saveOp, loadOp); -} - -/*! - \internal -*/ -void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp, - LoadOperator loadOp) -{ - if (idx < User) - return; //builtin types should not be registered; - QVector *ct = customTypes(); - if (!ct) - return; - QWriteLocker locker(customTypesLock()); - QCustomTypeInfo &inf = (*ct)[idx - User]; - inf.saveOp = saveOp; - inf.loadOp = loadOp; -} -#endif // QT_NO_DATASTREAM - -/*! - Returns the type name associated with the given \a typeId, or 0 if no - matching type was found. The returned pointer must not be deleted. - - \sa type(), isRegistered(), Type -*/ -const char *QMetaType::typeName(int typeId) -{ - const uint type = typeId; - // In theory it can be filled during compilation time, but for some reason template code - // that is able to do it causes GCC 4.6 to generate additional 3K of executable code. Probably - // it is not worth of it. - static const char *namesCache[QMetaType::HighestInternalId + 1]; - - const char *result; - if (type <= QMetaType::HighestInternalId && ((result = namesCache[type]))) - return result; - -#define QT_METATYPE_TYPEID_TYPENAME_CONVERTER(MetaTypeName, TypeId, RealName) \ - case QMetaType::MetaTypeName: result = #RealName; break; - - switch (QMetaType::Type(type)) { - QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_TYPEID_TYPENAME_CONVERTER) - - default: { - if (Q_UNLIKELY(type < QMetaType::User)) { - return 0; // It can happen when someone cast int to QVariant::Type, we should not crash... - } else { - const QVector * const ct = customTypes(); - QReadLocker locker(customTypesLock()); - return ct && uint(ct->count()) > type - QMetaType::User && !ct->at(type - QMetaType::User).typeName.isEmpty() - ? ct->at(type - QMetaType::User).typeName.constData() - : 0; - } - } - } -#undef QT_METATYPE_TYPEID_TYPENAME_CONVERTER - - Q_ASSERT(type <= QMetaType::HighestInternalId); - namesCache[type] = result; - return result; -} - -/*! - \internal - Similar to QMetaType::type(), but only looks in the static set of types. -*/ -static inline int qMetaTypeStaticType(const char *typeName, int length) -{ - int i = 0; - while (types[i].typeName && ((length != types[i].typeNameLength) - || strcmp(typeName, types[i].typeName))) { - ++i; - } - return types[i].type; -} - -/*! - \internal - Similar to QMetaType::type(), but only looks in the custom set of - types, and doesn't lock the mutex. -*/ -static int qMetaTypeCustomType_unlocked(const char *typeName, int length) -{ - const QVector * const ct = customTypes(); - if (!ct) - return QMetaType::UnknownType; - - for (int v = 0; v < ct->count(); ++v) { - const QCustomTypeInfo &customInfo = ct->at(v); - if ((length == customInfo.typeName.size()) - && !strcmp(typeName, customInfo.typeName.constData())) { - if (customInfo.alias >= 0) - return customInfo.alias; - return v + QMetaType::User; - } - } - return QMetaType::UnknownType; -} - -/*! - \internal - - This function is needed until existing code outside of qtbase - has been changed to call the new version of registerType(). - */ -int QMetaType::registerType(const char *typeName, Deleter deleter, - Creator creator) -{ - return registerType(typeName, deleter, creator, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Construct, 0, TypeFlags(), 0); -} - -/*! - \internal - \since 5.0 - - Registers a user type for marshalling, with \a typeName, a \a - deleter, a \a creator, a \a destructor, a \a constructor, and - a \a size. Returns the type's handle, or -1 if the type could - not be registered. - */ -int QMetaType::registerType(const char *typeName, Deleter deleter, - Creator creator, - Destructor destructor, - Constructor constructor, - int size, TypeFlags flags, const QMetaObject *metaObject) -{ -#ifdef QT_NO_QOBJECT - NS(QByteArray) normalizedTypeName = typeName; -#else - NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); -#endif - - return registerNormalizedType(normalizedTypeName, deleter, creator, destructor, constructor, size, flags, metaObject); -} - - -/*! - \internal - \since 5.0 - - Registers a user type for marshalling, with \a normalizedTypeName, a \a - deleter, a \a creator, a \a destructor, a \a constructor, and - a \a size. Returns the type's handle, or -1 if the type could - not be registered. Note that normalizedTypeName is not checked for - conformance with Qt's normalized format, so it must already - conform. - */ -int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, Deleter deleter, - Creator creator, - Destructor destructor, - Constructor constructor, - int size, TypeFlags flags, const QMetaObject *metaObject) -{ - QVector *ct = customTypes(); - if (!ct || normalizedTypeName.isEmpty() || !deleter || !creator || !destructor || !constructor) - return -1; - - int idx = qMetaTypeStaticType(normalizedTypeName.constData(), - normalizedTypeName.size()); - - int previousSize = 0; - int previousFlags = 0; - if (idx == UnknownType) { - QWriteLocker locker(customTypesLock()); - idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), - normalizedTypeName.size()); - if (idx == UnknownType) { - QCustomTypeInfo inf; - inf.typeName = normalizedTypeName; - inf.creator = creator; - inf.deleter = deleter; -#ifndef QT_NO_DATASTREAM - inf.loadOp = 0; - inf.saveOp = 0; -#endif - inf.alias = -1; - inf.constructor = constructor; - inf.destructor = destructor; - inf.size = size; - inf.flags = flags; - inf.metaObject = metaObject; - idx = ct->size() + User; - ct->append(inf); - return idx; - } - - if (idx >= User) { - previousSize = ct->at(idx - User).size; - previousFlags = ct->at(idx - User).flags; - } - } - - if (idx < User) { - previousSize = QMetaType::sizeOf(idx); - previousFlags = QMetaType::typeFlags(idx); - } - - if (previousSize != size) { - qFatal("QMetaType::registerType: Binary compatibility break " - "-- Size mismatch for type '%s' [%i]. Previously registered " - "size %i, now registering size %i.", - normalizedTypeName.constData(), idx, previousSize, size); - } - - // Ignore WasDeclaredAsMetaType inconsitency, to many users were hitting the problem - previousFlags |= WasDeclaredAsMetaType; - flags |= WasDeclaredAsMetaType; - - if (previousFlags != flags) { - const int maskForTypeInfo = NeedsConstruction | NeedsDestruction | MovableType; - const char *msg = "QMetaType::registerType: Binary compatibility break. " - "\nType flags for type '%s' [%i] don't match. Previously " - "registered TypeFlags(0x%x), now registering TypeFlags(0x%x). " - "This is an ODR break, which means that your application depends on a C++ undefined behavior." - "\nHint: %s"; - QT_PREPEND_NAMESPACE(QByteArray) hint; - if ((previousFlags & maskForTypeInfo) != (flags & maskForTypeInfo)) { - hint += "\nIt seems that the type was registered at least twice in a different translation units, " - "but Q_DECLARE_TYPEINFO is not visible from all the translations unit or different flags were used." - "Remember that Q_DECLARE_TYPEINFO should be declared before QMetaType registration, " - "preferably it should be placed just after the type declaration and before Q_DECLARE_METATYPE"; - } - qFatal(msg, normalizedTypeName.constData(), idx, previousFlags, int(flags), hint.constData()); - } - - return idx; -} - -/*! - \internal - \since 4.7 - - Registers a user type for marshalling, as an alias of another type (typedef) -*/ -int QMetaType::registerTypedef(const char* typeName, int aliasId) -{ -#ifdef QT_NO_QOBJECT - NS(QByteArray) normalizedTypeName = typeName; -#else - NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); -#endif - - return registerNormalizedTypedef(normalizedTypeName, aliasId); -} - -/*! - \internal - \since 5.0 - - Registers a user type for marshalling, as an alias of another type (typedef). - Note that normalizedTypeName is not checked for conformance with Qt's normalized format, - so it must already conform. -*/ -int QMetaType::registerNormalizedTypedef(const NS(QByteArray) &normalizedTypeName, int aliasId) -{ - QVector *ct = customTypes(); - if (!ct || normalizedTypeName.isEmpty()) - return -1; - - int idx = qMetaTypeStaticType(normalizedTypeName.constData(), - normalizedTypeName.size()); - - if (idx == UnknownType) { - QWriteLocker locker(customTypesLock()); - idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), - normalizedTypeName.size()); - - if (idx == UnknownType) { - QCustomTypeInfo inf; - inf.typeName = normalizedTypeName; - inf.alias = aliasId; - inf.creator = 0; - inf.deleter = 0; - ct->append(inf); - return aliasId; - } - } - - if (idx != aliasId) { - qWarning("QMetaType::registerTypedef: " - "-- Type name '%s' previously registered as typedef of '%s' [%i], " - "now registering as typedef of '%s' [%i].", - normalizedTypeName.constData(), QMetaType::typeName(idx), idx, - QMetaType::typeName(aliasId), aliasId); - } - return idx; -} - -/*! - Returns \c true if the datatype with ID \a type is registered; - otherwise returns \c false. - - \sa type(), typeName(), Type -*/ -bool QMetaType::isRegistered(int type) -{ - // predefined type - if ((type >= FirstCoreType && type <= LastCoreType) - || (type >= FirstGuiType && type <= LastGuiType) - || (type >= FirstWidgetsType && type <= LastWidgetsType)) { - return true; - } - - QReadLocker locker(customTypesLock()); - const QVector * const ct = customTypes(); - return ((type >= User) && (ct && ct->count() > type - User) && !ct->at(type - User).typeName.isEmpty()); -} - -/*! - \fn int qMetaTypeTypeImpl(const char *typeName) - \internal - - Implementation of QMetaType::type(). -*/ -template -static inline int qMetaTypeTypeImpl(const char *typeName) -{ - int length = qstrlen(typeName); - if (!length) - return QMetaType::UnknownType; - int type = qMetaTypeStaticType(typeName, length); - if (type == QMetaType::UnknownType) { - QReadLocker locker(customTypesLock()); - type = qMetaTypeCustomType_unlocked(typeName, length); -#ifndef QT_NO_QOBJECT - if ((type == QMetaType::UnknownType) && tryNormalizedType) { - const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); - type = qMetaTypeStaticType(normalizedTypeName.constData(), - normalizedTypeName.size()); - if (type == QMetaType::UnknownType) { - type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(), - normalizedTypeName.size()); - } - } -#endif - } - return type; -} - -/*! - Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is - no such type. - - \sa isRegistered(), typeName(), Type -*/ -int QMetaType::type(const char *typeName) -{ - return qMetaTypeTypeImpl(typeName); -} - -/*! - \a internal - - Similar to QMetaType::type(); the only difference is that this function - doesn't attempt to normalize the type name (i.e., the lookup will fail - for type names in non-normalized form). -*/ -int qMetaTypeTypeInternal(const char *typeName) -{ - return qMetaTypeTypeImpl(typeName); -} - -#ifndef QT_NO_DATASTREAM -/*! - Writes the object pointed to by \a data with the ID \a type to - the given \a stream. Returns \c true if the object is saved - successfully; otherwise returns \c false. - - The type must have been registered with qRegisterMetaType() and - qRegisterMetaTypeStreamOperators() beforehand. - - Normally, you should not need to call this function directly. - Instead, use QVariant's \c operator<<(), which relies on save() - to stream custom types. - - \sa load(), qRegisterMetaTypeStreamOperators() -*/ -bool QMetaType::save(QDataStream &stream, int type, const void *data) -{ - if (!data || !isRegistered(type)) - return false; - - switch(type) { - case QMetaType::UnknownType: - case QMetaType::Void: - case QMetaType::VoidStar: - case QMetaType::QObjectStar: - case QMetaType::QModelIndex: - case QMetaType::QJsonValue: - case QMetaType::QJsonObject: - case QMetaType::QJsonArray: - case QMetaType::QJsonDocument: - return false; - case QMetaType::Long: - stream << qlonglong(*static_cast(data)); - break; - case QMetaType::Int: - stream << *static_cast(data); - break; - case QMetaType::Short: - stream << *static_cast(data); - break; - case QMetaType::Char: - // force a char to be signed - stream << *static_cast(data); - break; - case QMetaType::ULong: - stream << qulonglong(*static_cast(data)); - break; - case QMetaType::UInt: - stream << *static_cast(data); - break; - case QMetaType::LongLong: - stream << *static_cast(data); - break; - case QMetaType::ULongLong: - stream << *static_cast(data); - break; - case QMetaType::UShort: - stream << *static_cast(data); - break; - case QMetaType::SChar: - stream << *static_cast(data); - break; - case QMetaType::UChar: - stream << *static_cast(data); - break; - case QMetaType::Bool: - stream << qint8(*static_cast(data)); - break; - case QMetaType::Float: - stream << *static_cast(data); - break; - case QMetaType::Double: - stream << *static_cast(data); - break; - case QMetaType::QChar: - stream << *static_cast(data); - break; -#ifndef QT_BOOTSTRAPPED - case QMetaType::QVariantMap: - stream << *static_cast(data); - break; - case QMetaType::QVariantHash: - stream << *static_cast(data); - break; - case QMetaType::QVariantList: - stream << *static_cast(data); - break; - case QMetaType::QVariant: - stream << *static_cast(data); - break; -#endif - case QMetaType::QByteArray: - stream << *static_cast(data); - break; - case QMetaType::QString: - stream << *static_cast(data); - break; - case QMetaType::QStringList: - stream << *static_cast(data); - break; -#ifndef QT_BOOTSTRAPPED - case QMetaType::QBitArray: - stream << *static_cast(data); - break; -#endif - case QMetaType::QDate: - stream << *static_cast(data); - break; - case QMetaType::QTime: - stream << *static_cast(data); - break; - case QMetaType::QDateTime: - stream << *static_cast(data); - break; -#ifndef QT_BOOTSTRAPPED - case QMetaType::QUrl: - stream << *static_cast(data); - break; -#endif - case QMetaType::QLocale: - stream << *static_cast(data); - break; -#ifndef QT_NO_GEOM_VARIANT - case QMetaType::QRect: - stream << *static_cast(data); - break; - case QMetaType::QRectF: - stream << *static_cast(data); - break; - case QMetaType::QSize: - stream << *static_cast(data); - break; - case QMetaType::QSizeF: - stream << *static_cast(data); - break; - case QMetaType::QLine: - stream << *static_cast(data); - break; - case QMetaType::QLineF: - stream << *static_cast(data); - break; - case QMetaType::QPoint: - stream << *static_cast(data); - break; - case QMetaType::QPointF: - stream << *static_cast(data); - break; -#endif -#ifndef QT_NO_REGEXP - case QMetaType::QRegExp: - stream << *static_cast(data); - break; -#endif -#ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGULAREXPRESSION - case QMetaType::QRegularExpression: - stream << *static_cast(data); - break; -#endif // QT_NO_REGULAREXPRESSION - case QMetaType::QEasingCurve: - stream << *static_cast(data); - break; -#endif // QT_BOOTSTRAPPED - case QMetaType::QFont: - case QMetaType::QPixmap: - case QMetaType::QBrush: - case QMetaType::QColor: - case QMetaType::QPalette: - case QMetaType::QImage: - case QMetaType::QPolygon: - case QMetaType::QPolygonF: - case QMetaType::QRegion: - case QMetaType::QBitmap: - case QMetaType::QCursor: - case QMetaType::QKeySequence: - case QMetaType::QPen: - case QMetaType::QTextLength: - case QMetaType::QTextFormat: - case QMetaType::QMatrix: - case QMetaType::QTransform: - case QMetaType::QMatrix4x4: - case QMetaType::QVector2D: - case QMetaType::QVector3D: - case QMetaType::QVector4D: - case QMetaType::QQuaternion: - case QMetaType::QIcon: - if (!qMetaTypeGuiHelper) - return false; - qMetaTypeGuiHelper[type - FirstGuiType].saveOp(stream, data); - break; - case QMetaType::QSizePolicy: - if (!qMetaTypeWidgetsHelper) - return false; - qMetaTypeWidgetsHelper[type - FirstWidgetsType].saveOp(stream, data); - break; - case QMetaType::QUuid: - stream << *static_cast(data); - break; - default: { - const QVector * const ct = customTypes(); - if (!ct) - return false; - - SaveOperator saveOp = 0; - { - QReadLocker locker(customTypesLock()); - saveOp = ct->at(type - User).saveOp; - } - - if (!saveOp) - return false; - saveOp(stream, data); - break; } - } - - return true; -} - -/*! - Reads the object of the specified \a type from the given \a - stream into \a data. Returns \c true if the object is loaded - successfully; otherwise returns \c false. - - The type must have been registered with qRegisterMetaType() and - qRegisterMetaTypeStreamOperators() beforehand. - - Normally, you should not need to call this function directly. - Instead, use QVariant's \c operator>>(), which relies on load() - to stream custom types. - - \sa save(), qRegisterMetaTypeStreamOperators() -*/ -bool QMetaType::load(QDataStream &stream, int type, void *data) -{ - if (!data || !isRegistered(type)) - return false; - - switch(type) { - case QMetaType::UnknownType: - case QMetaType::Void: - case QMetaType::VoidStar: - case QMetaType::QObjectStar: - case QMetaType::QModelIndex: - case QMetaType::QJsonValue: - case QMetaType::QJsonObject: - case QMetaType::QJsonArray: - case QMetaType::QJsonDocument: - return false; - case QMetaType::Long: { - qlonglong l; - stream >> l; - *static_cast(data) = long(l); - break; } - case QMetaType::Int: - stream >> *static_cast(data); - break; - case QMetaType::Short: - stream >> *static_cast(data); - break; - case QMetaType::Char: - // force a char to be signed - stream >> *static_cast(data); - break; - case QMetaType::ULong: { - qulonglong ul; - stream >> ul; - *static_cast(data) = ulong(ul); - break; } - case QMetaType::UInt: - stream >> *static_cast(data); - break; - case QMetaType::LongLong: - stream >> *static_cast(data); - break; - case QMetaType::ULongLong: - stream >> *static_cast(data); - break; - case QMetaType::UShort: - stream >> *static_cast(data); - break; - case QMetaType::SChar: - stream >> *static_cast(data); - break; - case QMetaType::UChar: - stream >> *static_cast(data); - break; - case QMetaType::Bool: { - qint8 b; - stream >> b; - *static_cast(data) = b; - break; } - case QMetaType::Float: - stream >> *static_cast(data); - break; - case QMetaType::Double: - stream >> *static_cast(data); - break; - case QMetaType::QChar: - stream >> *static_cast< NS(QChar)*>(data); - break; -#ifndef QT_BOOTSTRAPPED - case QMetaType::QVariantMap: - stream >> *static_cast< NS(QVariantMap)*>(data); - break; - case QMetaType::QVariantHash: - stream >> *static_cast< NS(QVariantHash)*>(data); - break; - case QMetaType::QVariantList: - stream >> *static_cast< NS(QVariantList)*>(data); - break; - case QMetaType::QVariant: - stream >> *static_cast< NS(QVariant)*>(data); - break; -#endif - case QMetaType::QByteArray: - stream >> *static_cast< NS(QByteArray)*>(data); - break; - case QMetaType::QString: - stream >> *static_cast< NS(QString)*>(data); - break; - case QMetaType::QStringList: - stream >> *static_cast< NS(QStringList)*>(data); - break; -#ifndef QT_BOOTSTRAPPED - case QMetaType::QBitArray: - stream >> *static_cast< NS(QBitArray)*>(data); - break; -#endif - case QMetaType::QDate: - stream >> *static_cast< NS(QDate)*>(data); - break; - case QMetaType::QTime: - stream >> *static_cast< NS(QTime)*>(data); - break; - case QMetaType::QDateTime: - stream >> *static_cast< NS(QDateTime)*>(data); - break; -#ifndef QT_BOOTSTRAPPED - case QMetaType::QUrl: - stream >> *static_cast< NS(QUrl)*>(data); - break; -#endif - case QMetaType::QLocale: - stream >> *static_cast< NS(QLocale)*>(data); - break; -#ifndef QT_NO_GEOM_VARIANT - case QMetaType::QRect: - stream >> *static_cast< NS(QRect)*>(data); - break; - case QMetaType::QRectF: - stream >> *static_cast< NS(QRectF)*>(data); - break; - case QMetaType::QSize: - stream >> *static_cast< NS(QSize)*>(data); - break; - case QMetaType::QSizeF: - stream >> *static_cast< NS(QSizeF)*>(data); - break; - case QMetaType::QLine: - stream >> *static_cast< NS(QLine)*>(data); - break; - case QMetaType::QLineF: - stream >> *static_cast< NS(QLineF)*>(data); - break; - case QMetaType::QPoint: - stream >> *static_cast< NS(QPoint)*>(data); - break; - case QMetaType::QPointF: - stream >> *static_cast< NS(QPointF)*>(data); - break; -#endif -#ifndef QT_NO_REGEXP - case QMetaType::QRegExp: - stream >> *static_cast< NS(QRegExp)*>(data); - break; -#endif -#ifndef QT_BOOTSTRAPPED -#ifndef QT_NO_REGULAREXPRESSION - case QMetaType::QRegularExpression: - stream >> *static_cast< NS(QRegularExpression)*>(data); - break; -#endif // QT_NO_REGULAREXPRESSION - case QMetaType::QEasingCurve: - stream >> *static_cast< NS(QEasingCurve)*>(data); - break; -#endif // QT_BOOTSTRAPPED - case QMetaType::QFont: - case QMetaType::QPixmap: - case QMetaType::QBrush: - case QMetaType::QColor: - case QMetaType::QPalette: - case QMetaType::QImage: - case QMetaType::QPolygon: - case QMetaType::QPolygonF: - case QMetaType::QRegion: - case QMetaType::QBitmap: - case QMetaType::QCursor: - case QMetaType::QKeySequence: - case QMetaType::QPen: - case QMetaType::QTextLength: - case QMetaType::QTextFormat: - case QMetaType::QMatrix: - case QMetaType::QTransform: - case QMetaType::QMatrix4x4: - case QMetaType::QVector2D: - case QMetaType::QVector3D: - case QMetaType::QVector4D: - case QMetaType::QQuaternion: - case QMetaType::QIcon: - if (!qMetaTypeGuiHelper) - return false; - qMetaTypeGuiHelper[type - FirstGuiType].loadOp(stream, data); - break; - case QMetaType::QSizePolicy: - if (!qMetaTypeWidgetsHelper) - return false; - qMetaTypeWidgetsHelper[type - FirstWidgetsType].loadOp(stream, data); - break; - case QMetaType::QUuid: - stream >> *static_cast< NS(QUuid)*>(data); - break; - default: { - const QVector * const ct = customTypes(); - if (!ct) - return false; - - LoadOperator loadOp = 0; - { - QReadLocker locker(customTypesLock()); - loadOp = ct->at(type - User).loadOp; - } - - if (!loadOp) - return false; - loadOp(stream, data); - break; } - } - return true; -} -#endif // QT_NO_DATASTREAM -namespace { -class TypeCreator { - template::IsAccepted> - struct CreatorImpl { - static void *Create(const int /* type */, const void *copy) - { - // Using QMetaTypeFunctionHelper::Create adds function call cost, even if it is a template (gcc). - // This "copy" check is moved out from the switcher by compiler (at least by gcc) - return copy ? new T(*static_cast(copy)) : new T(); - } - }; - template - struct CreatorImpl { - static void *Create(const int type, const void *copy) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) { - if (Q_LIKELY(qMetaTypeGuiHelper)) - return qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].creator(copy); - } - if (QModulesPrivate::QTypeModuleInfo::IsWidget) { - if (Q_LIKELY(qMetaTypeWidgetsHelper)) - return qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].creator(copy); - } - // This point can be reached only for known types that definition is not available, for example - // in bootstrap mode. We have no other choice then ignore it. - return 0; - } - }; -public: - TypeCreator(const int type) - : m_type(type) - {} - - template - void *delegate(const T *copy) { return CreatorImpl::Create(m_type, copy); } - void *delegate(const void*) { return 0; } - void *delegate(const QMetaTypeSwitcher::UnknownType *) { return 0; } - void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) - { - QMetaType::Creator creator; - const QVector * const ct = customTypes(); - { - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(m_type < QMetaType::User || !ct || ct->count() <= m_type - QMetaType::User)) - return 0; - creator = ct->at(m_type - QMetaType::User).creator; - } - Q_ASSERT_X(creator, "void *QMetaType::create(int type, const void *copy)", "The type was not properly registered"); - return creator(copy); - } -private: - const int m_type; -}; -} // namespace - -/*! - Returns a copy of \a copy, assuming it is of type \a type. If \a - copy is zero, creates a default constructed instance. - - \sa destroy(), isRegistered(), Type -*/ -void *QMetaType::create(int type, const void *copy) -{ - TypeCreator typeCreator(type); - return QMetaTypeSwitcher::switcher(typeCreator, type, copy); -} - -namespace { -class TypeDestroyer { - template::IsAccepted> - struct DestroyerImpl { - static void Destroy(const int /* type */, void *where) { QtMetaTypePrivate::QMetaTypeFunctionHelper::Delete(where); } - }; - template - struct DestroyerImpl { - static void Destroy(const int type, void *where) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) { - if (Q_LIKELY(qMetaTypeGuiHelper)) - qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where); - return; - } - if (QModulesPrivate::QTypeModuleInfo::IsWidget) { - if (Q_LIKELY(qMetaTypeWidgetsHelper)) - qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where); - return; - } - // This point can be reached only for known types that definition is not available, for example - // in bootstrap mode. We have no other choice then ignore it. - } - }; -public: - TypeDestroyer(const int type) - : m_type(type) - {} - - template - void delegate(const T *where) { DestroyerImpl::Destroy(m_type, const_cast(where)); } - void delegate(const void *) {} - void delegate(const QMetaTypeSwitcher::UnknownType*) {} - void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); } - -private: - static void customTypeDestroyer(const int type, void *where) - { - QMetaType::Destructor deleter; - const QVector * const ct = customTypes(); - { - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) - return; - deleter = ct->at(type - QMetaType::User).deleter; - } - Q_ASSERT_X(deleter, "void QMetaType::destroy(int type, void *data)", "The type was not properly registered"); - deleter(where); - } - - const int m_type; -}; -} // namespace - - -/*! - Destroys the \a data, assuming it is of the \a type given. - - \sa create(), isRegistered(), Type -*/ -void QMetaType::destroy(int type, void *data) -{ - TypeDestroyer deleter(type); - QMetaTypeSwitcher::switcher(deleter, type, data); -} - -namespace { -class TypeConstructor { - template::IsAccepted> - struct ConstructorImpl { - static void *Construct(const int /*type*/, void *where, const void *copy) { return QtMetaTypePrivate::QMetaTypeFunctionHelper::Construct(where, copy); } - }; - template - struct ConstructorImpl { - static void *Construct(const int type, void *where, const void *copy) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; - - if (QModulesPrivate::QTypeModuleInfo::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; - - // This point can be reached only for known types that definition is not available, for example - // in bootstrap mode. We have no other choice then ignore it. - return 0; - } - }; -public: - TypeConstructor(const int type, void *where) - : m_type(type) - , m_where(where) - {} - - template - void *delegate(const T *copy) { return ConstructorImpl::Construct(m_type, m_where, copy); } - void *delegate(const void *) { return m_where; } - void *delegate(const QMetaTypeSwitcher::UnknownType*) { return m_where; } - void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); } - -private: - static void *customTypeConstructor(const int type, void *where, const void *copy) - { - QMetaType::Constructor ctor; - const QVector * const ct = customTypes(); - { - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) - return 0; - ctor = ct->at(type - QMetaType::User).constructor; - } - Q_ASSERT_X(ctor, "void *QMetaType::construct(int type, void *where, const void *copy)", "The type was not properly registered"); - return ctor(where, copy); - } - - const int m_type; - void *m_where; -}; -} // namespace - -/*! - \since 5.0 - - Constructs a value of the given \a type in the existing memory - addressed by \a where, that is a copy of \a copy, and returns - \a where. If \a copy is zero, the value is default constructed. - - This is a low-level function for explicitly managing the memory - used to store the type. Consider calling create() if you don't - need this level of control (that is, use "new" rather than - "placement new"). - - You must ensure that \a where points to a location that can store - a value of type \a type, and that \a where is suitably aligned. - The type's size can be queried by calling sizeOf(). - - The rule of thumb for alignment is that a type is aligned to its - natural boundary, which is the smallest power of 2 that is bigger - than the type, unless that alignment is larger than the maximum - useful alignment for the platform. For practical purposes, - alignment larger than 2 * sizeof(void*) is only necessary for - special hardware instructions (e.g., aligned SSE loads and stores - on x86). - - \sa destruct(), sizeOf() -*/ -void *QMetaType::construct(int type, void *where, const void *copy) -{ - if (!where) - return 0; - TypeConstructor constructor(type, where); - return QMetaTypeSwitcher::switcher(constructor, type, copy); -} - - -namespace { -class TypeDestructor { - template::IsAccepted> - struct DestructorImpl { - static void Destruct(const int /* type */, void *where) { QtMetaTypePrivate::QMetaTypeFunctionHelper::Destruct(where); } - }; - template - struct DestructorImpl { - static void Destruct(const int type, void *where) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) { - if (Q_LIKELY(qMetaTypeGuiHelper)) - qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor(where); - return; - } - if (QModulesPrivate::QTypeModuleInfo::IsWidget) { - if (Q_LIKELY(qMetaTypeWidgetsHelper)) - qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor(where); - return; - } - // This point can be reached only for known types that definition is not available, for example - // in bootstrap mode. We have no other choice then ignore it. - } - }; -public: - TypeDestructor(const int type) - : m_type(type) - {} - - template - void delegate(const T *where) { DestructorImpl::Destruct(m_type, const_cast(where)); } - void delegate(const void *) {} - void delegate(const QMetaTypeSwitcher::UnknownType*) {} - void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); } - -private: - static void customTypeDestructor(const int type, void *where) - { - QMetaType::Destructor dtor; - const QVector * const ct = customTypes(); - { - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) - return; - dtor = ct->at(type - QMetaType::User).destructor; - } - Q_ASSERT_X(dtor, "void QMetaType::destruct(int type, void *where)", "The type was not properly registered"); - dtor(where); - } - - const int m_type; -}; -} // namespace - -/*! - \since 5.0 - - Destructs the value of the given \a type, located at \a where. - - Unlike destroy(), this function only invokes the type's - destructor, it doesn't invoke the delete operator. - - \sa construct() -*/ -void QMetaType::destruct(int type, void *where) -{ - if (!where) - return; - TypeDestructor destructor(type); - QMetaTypeSwitcher::switcher(destructor, type, where); -} - - -namespace { -class SizeOf { - template::IsAccepted> - struct SizeOfImpl { - static int Size(const int) { return QTypeInfo::sizeOf; } - }; - template - struct SizeOfImpl { - static int Size(const int type) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size : 0; - - if (QModulesPrivate::QTypeModuleInfo::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size : 0; - - // This point can be reached only for known types that definition is not available, for example - // in bootstrap mode. We have no other choice then ignore it. - return 0; - } - }; - -public: - SizeOf(int type) - : m_type(type) - {} - - template - int delegate(const T*) { return SizeOfImpl::Size(m_type); } - int delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } - int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); } -private: - static int customTypeSizeOf(const int type) - { - const QVector * const ct = customTypes(); - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) - return 0; - return ct->at(type - QMetaType::User).size; - } - - const int m_type; -}; -} // namespace - -/*! - \since 5.0 - - Returns the size of the given \a type in bytes (i.e. sizeof(T), - where T is the actual type identified by the \a type argument). - - This function is typically used together with construct() - to perform low-level management of the memory used by a type. - - \sa construct() -*/ -int QMetaType::sizeOf(int type) -{ - SizeOf sizeOf(type); - return QMetaTypeSwitcher::switcher(sizeOf, type, 0); -} - -namespace { -class Flags -{ - template::IsAccepted> - struct FlagsImpl - { - static quint32 Flags(const int /* type */) - { - return QtPrivate::QMetaTypeTypeFlags::Flags; - } - }; - template - struct FlagsImpl - { - static quint32 Flags(const int type) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0; - - if (QModulesPrivate::QTypeModuleInfo::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0; - - // This point can be reached only for known types that definition is not available, for example - // in bootstrap mode. We have no other choice then ignore it. - return 0; - } - }; -public: - Flags(const int type) - : m_type(type) - {} - template - quint32 delegate(const T*) { return FlagsImpl::Flags(m_type); } - quint32 delegate(const void*) { return 0; } - quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } - quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); } -private: - const int m_type; - static quint32 customTypeFlags(const int type) - { - const QVector * const ct = customTypes(); - if (Q_UNLIKELY(!ct || type < QMetaType::User)) - return 0; - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) - return 0; - return ct->at(type - QMetaType::User).flags; - } -}; -} // namespace - -/*! - \since 5.0 - - Returns flags of the given \a type. - - \sa QMetaType::TypeFlags -*/ -QMetaType::TypeFlags QMetaType::typeFlags(int type) -{ - Flags flags(type); - return static_cast(QMetaTypeSwitcher::switcher(flags, type, 0)); -} - -#ifndef QT_BOOTSTRAPPED -namespace { -class MetaObject -{ -public: - MetaObject(const int type) - : m_type(type) - {} - template - const QMetaObject *delegate(const T*) { return QtPrivate::MetaObjectForType::value(); } - const QMetaObject *delegate(const void*) { return 0; } - const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } - const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); } -private: - const int m_type; - static const QMetaObject *customMetaObject(const int type) - { - const QVector * const ct = customTypes(); - if (Q_UNLIKELY(!ct || type < QMetaType::User)) - return 0; - QReadLocker locker(customTypesLock()); - if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) - return 0; - return ct->at(type - QMetaType::User).metaObject; - } -}; -} // namespace -#endif - -/*! - \since 5.0 - - Returns QMetaObject of a given \a type, if the \a type is a pointer to type derived from QObject. -*/ -const QMetaObject *QMetaType::metaObjectForType(int type) -{ -#ifndef QT_BOOTSTRAPPED - MetaObject mo(type); - return QMetaTypeSwitcher::switcher(mo, type, 0); -#else - Q_UNUSED(type); - return 0; -#endif -} - -/*! - \fn int qRegisterMetaType(const char *typeName) - \relates QMetaType - \threadsafe - - Registers the type name \a typeName for the type \c{T}. Returns - the internal ID used by QMetaType. Any class or struct that has a - public default constructor, a public copy constructor and a public - destructor can be registered. - - This function requires that \c{T} is a fully defined type at the point - where the function is called. For pointer types, it also requires that the - pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able - to register pointers to forward declared types. - - After a type has been registered, you can create and destroy - objects of that type dynamically at run-time. - - This example registers the class \c{MyClass}: - - \snippet code/src_corelib_kernel_qmetatype.cpp 4 - - This function is useful to register typedefs so they can be used - by QMetaProperty, or in QueuedConnections - - \snippet code/src_corelib_kernel_qmetatype.cpp 9 - - \warning This function is useful only for registering an alias (typedef) - for every other use case Q_DECLARE_METATYPE and qMetaTypeId() should be used instead. - - \sa qRegisterMetaTypeStreamOperators(), QMetaType::isRegistered(), - Q_DECLARE_METATYPE() -*/ - -/*! - \fn void qRegisterMetaTypeStreamOperators(const char *typeName) - \relates QMetaType - \threadsafe - - Registers the stream operators for the type \c{T} called \a - typeName. - - Afterward, the type can be streamed using QMetaType::load() and - QMetaType::save(). These functions are used when streaming a - QVariant. - - \snippet code/src_corelib_kernel_qmetatype.cpp 5 - - The stream operators should have the following signatures: - - \snippet code/src_corelib_kernel_qmetatype.cpp 6 - - \sa qRegisterMetaType(), QMetaType::isRegistered(), Q_DECLARE_METATYPE() -*/ - -/*! \typedef QMetaType::Deleter - \internal -*/ -/*! \typedef QMetaType::Creator - \internal -*/ -/*! \typedef QMetaType::SaveOperator - \internal -*/ -/*! \typedef QMetaType::LoadOperator - \internal -*/ -/*! \typedef QMetaType::Destructor - \internal -*/ -/*! \typedef QMetaType::Constructor - \internal -*/ - -/*! - \fn int qRegisterMetaType() - \relates QMetaType - \threadsafe - \since 4.2 - - Call this function to register the type \c T. \c T must be declared with - Q_DECLARE_METATYPE(). Returns the meta type Id. - - Example: - - \snippet code/src_corelib_kernel_qmetatype.cpp 7 - - This function requires that \c{T} is a fully defined type at the point - where the function is called. For pointer types, it also requires that the - pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able - to register pointers to forward declared types. - - After a type has been registered, you can create and destroy - objects of that type dynamically at run-time. - - To use the type \c T in QVariant, using Q_DECLARE_METATYPE() is - sufficient. To use the type \c T in queued signal and slot connections, - \c{qRegisterMetaType()} must be called before the first connection - is established. - - Also, to use type \c T with the QObject::property() API, - \c{qRegisterMetaType()} must be called before it is used, typically - in the constructor of the class that uses \c T, or in the \c{main()} - function. - - \sa Q_DECLARE_METATYPE() - */ - -/*! - \fn int qMetaTypeId() - \relates QMetaType - \threadsafe - \since 4.1 - - Returns the meta type id of type \c T at compile time. If the - type was not declared with Q_DECLARE_METATYPE(), compilation will - fail. - - Typical usage: - - \snippet code/src_corelib_kernel_qmetatype.cpp 8 - - QMetaType::type() returns the same ID as qMetaTypeId(), but does - a lookup at runtime based on the name of the type. - QMetaType::type() is a bit slower, but compilation succeeds if a - type is not registered. - - \sa Q_DECLARE_METATYPE(), QMetaType::type() -*/ - -namespace { -class TypeInfo { - template::IsAccepted> - struct TypeInfoImpl - { - TypeInfoImpl(const uint /* type */, QMetaTypeInterface &info) - { - QMetaTypeInterface tmp = QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(T); - info = tmp; - } - }; - - template - struct TypeInfoImpl - { - TypeInfoImpl(const uint type, QMetaTypeInterface &info) - { - if (QModulesPrivate::QTypeModuleInfo::IsGui) { - if (Q_LIKELY(qMetaTypeGuiHelper)) - info = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType]; - return; - } - if (QModulesPrivate::QTypeModuleInfo::IsWidget) { - if (Q_LIKELY(qMetaTypeWidgetsHelper)) - info = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType]; - return; - } - } - }; -public: - QMetaTypeInterface info; - TypeInfo(const uint type) - : m_type(type) - { - QMetaTypeInterface tmp = QT_METATYPE_INTERFACE_INIT_EMPTY(); - info = tmp; - } - template - void delegate(const T*) { TypeInfoImpl(m_type, info); } - void delegate(const QMetaTypeSwitcher::UnknownType*) {} - void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); } -private: - void customTypeInfo(const uint type) - { - const QVector * const ct = customTypes(); - if (Q_UNLIKELY(!ct)) - return; - QReadLocker locker(customTypesLock()); - if (Q_LIKELY(uint(ct->count()) > type - QMetaType::User)) - info = ct->at(type - QMetaType::User); - } - - const uint m_type; -}; -} // namespace - -/*! - \fn QMetaType QMetaType::typeInfo(const int type) - \internal -*/ -QMetaType QMetaType::typeInfo(const int type) -{ - TypeInfo typeInfo(type); - QMetaTypeSwitcher::switcher(typeInfo, type, 0); - return typeInfo.info.creator ? QMetaType(QMetaType::NoExtensionFlags - , static_cast(0) // typeInfo::info is a temporary variable, we can't return address of it. - , typeInfo.info.creator - , typeInfo.info.deleter - , typeInfo.info.saveOp - , typeInfo.info.loadOp - , typeInfo.info.constructor - , typeInfo.info.destructor - , typeInfo.info.size - , typeInfo.info.flags - , type - , typeInfo.info.metaObject) - : QMetaType(UnknownType); -} - -/*! - \fn QMetaType::QMetaType(const int typeId) - \since 5.0 - - Constructs a QMetaType object that contains all information about type \a typeId. -*/ -QMetaType::QMetaType(const int typeId) - : m_typeId(typeId) -{ - if (Q_UNLIKELY(typeId == UnknownType)) { - // Constructs invalid QMetaType instance. - m_extensionFlags = 0xffffffff; - Q_ASSERT(!isValid()); - } else { - // TODO it can be better. - *this = QMetaType::typeInfo(typeId); - if (m_typeId == UnknownType) - m_extensionFlags = 0xffffffff; - else if (m_typeId == QMetaType::Void) - m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx; - } -} - -/*! - \fn QMetaType::QMetaType(const QMetaType &other) - \since 5.0 - - Copy constructs a QMetaType object. -*/ -QMetaType::QMetaType(const QMetaType &other) - : m_creator(other.m_creator) - , m_deleter(other.m_deleter) - , m_saveOp(other.m_saveOp) - , m_loadOp(other.m_loadOp) - , m_constructor(other.m_constructor) - , m_destructor(other.m_destructor) - , m_extension(other.m_extension) // space reserved for future use - , m_size(other.m_size) - , m_typeFlags(other.m_typeFlags) - , m_extensionFlags(other.m_extensionFlags) - , m_typeId(other.m_typeId) - , m_metaObject(other.m_metaObject) -{} - -QMetaType &QMetaType::operator =(const QMetaType &other) -{ - m_creator = other.m_creator; - m_deleter = other.m_deleter; - m_saveOp = other.m_saveOp; - m_loadOp = other.m_loadOp; - m_constructor = other.m_constructor; - m_destructor = other.m_destructor; - m_size = other.m_size; - m_typeFlags = other.m_typeFlags; - m_extensionFlags = other.m_extensionFlags; - m_extension = other.m_extension; // space reserved for future use - m_typeId = other.m_typeId; - m_metaObject = other.m_metaObject; - return *this; -} - -/*! - \fn void QMetaType::ctor(const QMetaTypeInterface *info) - \internal - - Method used for future binary compatible extensions. The function may be - called from within QMetaType's constructor to force a library call from - inlined code. -*/ -void QMetaType::ctor(const QMetaTypeInterface *info) -{ - // Special case for Void type, the type is valid but not constructible. - // In future we may consider to remove this assert and extend this function to initialize - // differently m_extensionFlags for different types. Currently it is not needed. - Q_ASSERT(m_typeId == QMetaType::Void); - Q_UNUSED(info); - m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx; -} - -/*! - \fn void QMetaType::dtor() - \internal - - Method used for future binary compatible extensions. The function may be - called from within QMetaType's destructor to force a library call from - inlined code. -*/ -void QMetaType::dtor() -{} - -/*! - \fn void *QMetaType::createExtended(const void *copy) const - \internal - - Method used for future binary compatible extensions. The function may be called - during QMetaType::create to force library call from inlined code. -*/ -void *QMetaType::createExtended(const void *copy) const -{ - Q_UNUSED(copy); - return 0; -} - -/*! - \fn void QMetaType::destroyExtended(void *data) const - \internal - - Method used for future binary compatible extensions. The function may be called - during QMetaType::destroy to force library call from inlined code. -*/ -void QMetaType::destroyExtended(void *data) const -{ - Q_UNUSED(data); -} - -/*! - \fn void *QMetaType::constructExtended(void *where, const void *copy) const - \internal - - Method used for future binary compatible extensions. The function may be called - during QMetaType::construct to force library call from inlined code. -*/ -void *QMetaType::constructExtended(void *where, const void *copy) const -{ - Q_UNUSED(where); - Q_UNUSED(copy); - return 0; -} - -/*! - \fn void QMetaType::destructExtended(void *data) const - \internal - - Method used for future binary compatible extensions. The function may be called - during QMetaType::destruct to force library call from inlined code. -*/ -void QMetaType::destructExtended(void *data) const -{ - Q_UNUSED(data); -} - -/*! - \fn uint QMetaType::sizeExtended() const - \internal - - Method used for future binary compatible extensions. The function may be - called from within QMetaType::size to force a library call from - inlined code. -*/ -uint QMetaType::sizeExtended() const -{ - return 0; -} - -/*! - \fn QMetaType::TypeFlags QMetaType::flagsExtended() const - \internal - - Method used for future binary compatible extensions. The function may be - called from within QMetaType::flags to force a library call from - inlined code. -*/ -QMetaType::TypeFlags QMetaType::flagsExtended() const -{ - return 0; -} - -/*! - \brief QMetaType::metaObjectExtended - \internal - - Method used for future binary compatible extensions. The function may be - called from within QMetaType::metaObject to force a library call from - inlined code. -*/ -const QMetaObject *QMetaType::metaObjectExtended() const -{ - return 0; -} - - -namespace QtPrivate -{ -const QMetaObject *metaObjectForQWidget() -{ - if (!qMetaTypeWidgetsHelper) - return 0; - return qMetaObjectWidgetsHelper; -} -} - -QT_END_NAMESPACE diff --git a/DOtherSide/DynamicQObject/private/qmetatype.h b/DOtherSide/DynamicQObject/private/qmetatype.h deleted file mode 100644 index 3b35a51..0000000 --- a/DOtherSide/DynamicQObject/private/qmetatype.h +++ /dev/null @@ -1,2080 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMETATYPE_H -#define QMETATYPE_H - -#include -#include -#include -#include -#include -#include -#ifndef QT_NO_QOBJECT -#include -#endif -#include - -#include -#include -#include - -#ifdef Bool -#error qmetatype.h must be included before any header file that defines Bool -#endif - -QT_BEGIN_NAMESPACE - -template -struct QMetaTypeId2; - -template -inline Q_DECL_CONSTEXPR int qMetaTypeId(); - -// F is a tuple: (QMetaType::TypeName, QMetaType::TypeNameID, RealType) -#define QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ - F(Void, 43, void) \ - F(Bool, 1, bool) \ - F(Int, 2, int) \ - F(UInt, 3, uint) \ - F(LongLong, 4, qlonglong) \ - F(ULongLong, 5, qulonglong) \ - F(Double, 6, double) \ - F(Long, 32, long) \ - F(Short, 33, short) \ - F(Char, 34, char) \ - F(ULong, 35, ulong) \ - F(UShort, 36, ushort) \ - F(UChar, 37, uchar) \ - F(Float, 38, float) \ - F(SChar, 40, signed char) \ - -#define QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(F)\ - F(VoidStar, 31, void*) \ - -#define QT_FOR_EACH_STATIC_CORE_CLASS(F)\ - F(QChar, 7, QChar) \ - F(QString, 10, QString) \ - F(QStringList, 11, QStringList) \ - F(QByteArray, 12, QByteArray) \ - F(QBitArray, 13, QBitArray) \ - F(QDate, 14, QDate) \ - F(QTime, 15, QTime) \ - F(QDateTime, 16, QDateTime) \ - F(QUrl, 17, QUrl) \ - F(QLocale, 18, QLocale) \ - F(QRect, 19, QRect) \ - F(QRectF, 20, QRectF) \ - F(QSize, 21, QSize) \ - F(QSizeF, 22, QSizeF) \ - F(QLine, 23, QLine) \ - F(QLineF, 24, QLineF) \ - F(QPoint, 25, QPoint) \ - F(QPointF, 26, QPointF) \ - F(QRegExp, 27, QRegExp) \ - F(QEasingCurve, 29, QEasingCurve) \ - F(QUuid, 30, QUuid) \ - F(QVariant, 41, QVariant) \ - F(QModelIndex, 42, QModelIndex) \ - F(QRegularExpression, 44, QRegularExpression) \ - F(QJsonValue, 45, QJsonValue) \ - F(QJsonObject, 46, QJsonObject) \ - F(QJsonArray, 47, QJsonArray) \ - F(QJsonDocument, 48, QJsonDocument) \ - -#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\ - F(QObjectStar, 39, QObject*) - -#define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\ - F(QVariantMap, 8, QVariantMap) \ - F(QVariantList, 9, QVariantList) \ - F(QVariantHash, 28, QVariantHash) \ - -#define QT_FOR_EACH_STATIC_GUI_CLASS(F)\ - F(QFont, 64, QFont) \ - F(QPixmap, 65, QPixmap) \ - F(QBrush, 66, QBrush) \ - F(QColor, 67, QColor) \ - F(QPalette, 68, QPalette) \ - F(QIcon, 69, QIcon) \ - F(QImage, 70, QImage) \ - F(QPolygon, 71, QPolygon) \ - F(QRegion, 72, QRegion) \ - F(QBitmap, 73, QBitmap) \ - F(QCursor, 74, QCursor) \ - F(QKeySequence, 75, QKeySequence) \ - F(QPen, 76, QPen) \ - F(QTextLength, 77, QTextLength) \ - F(QTextFormat, 78, QTextFormat) \ - F(QMatrix, 79, QMatrix) \ - F(QTransform, 80, QTransform) \ - F(QMatrix4x4, 81, QMatrix4x4) \ - F(QVector2D, 82, QVector2D) \ - F(QVector3D, 83, QVector3D) \ - F(QVector4D, 84, QVector4D) \ - F(QQuaternion, 85, QQuaternion) \ - F(QPolygonF, 86, QPolygonF) \ - - -#define QT_FOR_EACH_STATIC_WIDGETS_CLASS(F)\ - F(QSizePolicy, 121, QSizePolicy) \ - -// ### FIXME kill that set -#define QT_FOR_EACH_STATIC_HACKS_TYPE(F)\ - F(QMetaTypeId2::MetaType, -1, qreal) - -// F is a tuple: (QMetaType::TypeName, QMetaType::TypeNameID, AliasingType, "RealType") -#define QT_FOR_EACH_STATIC_ALIAS_TYPE(F)\ - F(ULong, -1, ulong, "unsigned long") \ - F(UInt, -1, uint, "unsigned int") \ - F(UShort, -1, ushort, "unsigned short") \ - F(UChar, -1, uchar, "unsigned char") \ - F(LongLong, -1, qlonglong, "long long") \ - F(ULongLong, -1, qulonglong, "unsigned long long") \ - F(SChar, -1, signed char, "qint8") \ - F(UChar, -1, uchar, "quint8") \ - F(Short, -1, short, "qint16") \ - F(UShort, -1, ushort, "quint16") \ - F(Int, -1, int, "qint32") \ - F(UInt, -1, uint, "quint32") \ - F(LongLong, -1, qlonglong, "qint64") \ - F(ULongLong, -1, qulonglong, "quint64") \ - F(QVariantList, -1, QVariantList, "QList") \ - F(QVariantMap, -1, QVariantMap, "QMap") \ - F(QVariantHash, -1, QVariantHash, "QHash") \ - -#define QT_FOR_EACH_STATIC_TYPE(F)\ - QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ - QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(F)\ - QT_FOR_EACH_STATIC_CORE_CLASS(F)\ - QT_FOR_EACH_STATIC_CORE_POINTER(F)\ - QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\ - QT_FOR_EACH_STATIC_GUI_CLASS(F)\ - QT_FOR_EACH_STATIC_WIDGETS_CLASS(F)\ - -#define QT_DEFINE_METATYPE_ID(TypeName, Id, Name) \ - TypeName = Id, - -#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(F) \ - F(QList) \ - F(QVector) \ - F(QQueue) \ - F(QStack) \ - F(QSet) \ - F(QLinkedList) - -#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_2ARG(F) \ - F(QHash, class) \ - F(QMap, class) \ - F(QPair, struct) - -#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(F) \ - F(QSharedPointer) \ - F(QWeakPointer) \ - F(QPointer) - -class QDataStream; -class QMetaTypeInterface; -struct QMetaObject; - -namespace QtPrivate -{ -/*! - This template is used for implicit conversion from type From to type To. - \internal -*/ -template -To convertImplicit(const From& from) -{ - return from; -} - -#ifndef QT_NO_DEBUG_STREAM -struct AbstractDebugStreamFunction -{ - typedef void (*Stream)(const AbstractDebugStreamFunction *, QDebug&, const void *); - typedef void (*Destroy)(AbstractDebugStreamFunction *); - explicit AbstractDebugStreamFunction(Stream s = 0, Destroy d = 0) - : stream(s), destroy(d) {} - Q_DISABLE_COPY(AbstractDebugStreamFunction) - Stream stream; - Destroy destroy; -}; - -template -struct BuiltInDebugStreamFunction : public AbstractDebugStreamFunction -{ - BuiltInDebugStreamFunction() - : AbstractDebugStreamFunction(stream, destroy) {} - static void stream(const AbstractDebugStreamFunction *, QDebug& dbg, const void *r) - { - const T *rhs = static_cast(r); - operator<<(dbg, *rhs); - } - - static void destroy(AbstractDebugStreamFunction *_this) - { - delete static_cast(_this); - } -}; -#endif - -struct AbstractComparatorFunction -{ - typedef bool (*LessThan)(const AbstractComparatorFunction *, const void *, const void *); - typedef bool (*Equals)(const AbstractComparatorFunction *, const void *, const void *); - typedef void (*Destroy)(AbstractComparatorFunction *); - explicit AbstractComparatorFunction(LessThan lt = 0, Equals e = 0, Destroy d = 0) - : lessThan(lt), equals(e), destroy(d) {} - Q_DISABLE_COPY(AbstractComparatorFunction) - LessThan lessThan; - Equals equals; - Destroy destroy; -}; - -template -struct BuiltInComparatorFunction : public AbstractComparatorFunction -{ - BuiltInComparatorFunction() - : AbstractComparatorFunction(lessThan, equals, destroy) {} - static bool lessThan(const AbstractComparatorFunction *, const void *l, const void *r) - { - const T *lhs = static_cast(l); - const T *rhs = static_cast(r); - return *lhs < *rhs; - } - - static bool equals(const AbstractComparatorFunction *, const void *l, const void *r) - { - const T *lhs = static_cast(l); - const T *rhs = static_cast(r); - return *lhs == *rhs; - } - - static void destroy(AbstractComparatorFunction *_this) - { - delete static_cast(_this); - } -}; - -struct AbstractConverterFunction -{ - typedef bool (*Converter)(const AbstractConverterFunction *, const void *, void*); - explicit AbstractConverterFunction(Converter c = 0) - : convert(c) {} - Q_DISABLE_COPY(AbstractConverterFunction) - Converter convert; -}; - -template -struct ConverterMemberFunction : public AbstractConverterFunction -{ - explicit ConverterMemberFunction(To(From::*function)() const) - : AbstractConverterFunction(convert), - m_function(function) {} - ~ConverterMemberFunction(); - static bool convert(const AbstractConverterFunction *_this, const void *in, void *out) - { - const From *f = static_cast(in); - To *t = static_cast(out); - const ConverterMemberFunction *_typedThis = - static_cast(_this); - *t = (f->*_typedThis->m_function)(); - return true; - } - - To(From::* const m_function)() const; -}; - -template -struct ConverterMemberFunctionOk : public AbstractConverterFunction -{ - explicit ConverterMemberFunctionOk(To(From::*function)(bool *) const) - : AbstractConverterFunction(convert), - m_function(function) {} - ~ConverterMemberFunctionOk(); - static bool convert(const AbstractConverterFunction *_this, const void *in, void *out) - { - const From *f = static_cast(in); - To *t = static_cast(out); - bool ok = false; - const ConverterMemberFunctionOk *_typedThis = - static_cast(_this); - *t = (f->*_typedThis->m_function)(&ok); - if (!ok) - *t = To(); - return ok; - } - - To(From::* const m_function)(bool*) const; -}; - -template -struct ConverterFunctor : public AbstractConverterFunction -{ - explicit ConverterFunctor(UnaryFunction function) - : AbstractConverterFunction(convert), - m_function(function) {} - ~ConverterFunctor(); - static bool convert(const AbstractConverterFunction *_this, const void *in, void *out) - { - const From *f = static_cast(in); - To *t = static_cast(out); - const ConverterFunctor *_typedThis = - static_cast(_this); - *t = _typedThis->m_function(*f); - return true; - } - - UnaryFunction m_function; -}; - - template - struct ValueTypeIsMetaType; - template - struct AssociativeValueTypeIsMetaType; - template - struct IsMetaTypePair; - template - struct MetaTypeSmartPointerHelper; -} - -class Q_CORE_EXPORT QMetaType { - enum ExtensionFlag { NoExtensionFlags, - CreateEx = 0x1, DestroyEx = 0x2, - ConstructEx = 0x4, DestructEx = 0x8, - NameEx = 0x10, SizeEx = 0x20, - CtorEx = 0x40, DtorEx = 0x80, - FlagsEx = 0x100, MetaObjectEx = 0x200 - }; -public: -#ifndef Q_QDOC - // The code that actually gets compiled. - enum Type { - // these are merged with QVariant - QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID) - - FirstCoreType = Bool, - LastCoreType = QJsonDocument, - FirstGuiType = QFont, - LastGuiType = QPolygonF, - FirstWidgetsType = QSizePolicy, - LastWidgetsType = QSizePolicy, - HighestInternalId = LastWidgetsType, - - QReal = sizeof(qreal) == sizeof(double) ? Double : Float, - - UnknownType = 0, - User = 1024 - }; -#else - // If we are using QDoc it fakes the Type enum looks like this. - enum Type { - UnknownType = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5, - Double = 6, Long = 32, Short = 33, Char = 34, ULong = 35, UShort = 36, - UChar = 37, Float = 38, - VoidStar = 31, - QChar = 7, QString = 10, QStringList = 11, QByteArray = 12, - QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17, - QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22, - QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27, - QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42, - QRegularExpression = 44, - QJsonValue = 45, QJsonObject = 46, QJsonArray = 47, QJsonDocument = 48, - QObjectStar = 39, SChar = 40, - Void = 43, - QVariantMap = 8, QVariantList = 9, QVariantHash = 28, - QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68, - QIcon = 69, QImage = 70, QPolygon = 71, QRegion = 72, QBitmap = 73, - QCursor = 74, QKeySequence = 75, QPen = 76, QTextLength = 77, QTextFormat = 78, - QMatrix = 79, QTransform = 80, QMatrix4x4 = 81, QVector2D = 82, - QVector3D = 83, QVector4D = 84, QQuaternion = 85, QPolygonF = 86, - QSizePolicy = 121, - User = 1024 - }; -#endif - - enum TypeFlag { - NeedsConstruction = 0x1, - NeedsDestruction = 0x2, - MovableType = 0x4, - PointerToQObject = 0x8, - IsEnumeration = 0x10, - SharedPointerToQObject = 0x20, - WeakPointerToQObject = 0x40, - TrackingPointerToQObject = 0x80, - WasDeclaredAsMetaType = 0x100 - }; - Q_DECLARE_FLAGS(TypeFlags, TypeFlag) - - typedef void (*Deleter)(void *); - typedef void *(*Creator)(const void *); - - typedef void (*Destructor)(void *); - typedef void *(*Constructor)(void *, const void *); - - typedef void (*SaveOperator)(QDataStream &, const void *); - typedef void (*LoadOperator)(QDataStream &, void *); -#ifndef QT_NO_DATASTREAM - static void registerStreamOperators(const char *typeName, SaveOperator saveOp, - LoadOperator loadOp); - static void registerStreamOperators(int type, SaveOperator saveOp, - LoadOperator loadOp); -#endif - static int registerType(const char *typeName, Deleter deleter, - Creator creator); - static int registerType(const char *typeName, Deleter deleter, - Creator creator, - Destructor destructor, - Constructor constructor, - int size, - QMetaType::TypeFlags flags, - const QMetaObject *metaObject); - static int registerNormalizedType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, Deleter deleter, - Creator creator, - Destructor destructor, - Constructor constructor, - int size, - QMetaType::TypeFlags flags, - const QMetaObject *metaObject); - static int registerTypedef(const char *typeName, int aliasId); - static int registerNormalizedTypedef(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, int aliasId); - static int type(const char *typeName); - static const char *typeName(int type); - static int sizeOf(int type); - static TypeFlags typeFlags(int type); - static const QMetaObject *metaObjectForType(int type); - static bool isRegistered(int type); - static void *create(int type, const void *copy = 0); -#if QT_DEPRECATED_SINCE(5, 0) - QT_DEPRECATED static void *construct(int type, const void *copy = 0) - { return create(type, copy); } -#endif - static void destroy(int type, void *data); - static void *construct(int type, void *where, const void *copy); - static void destruct(int type, void *where); - -#ifndef QT_NO_DATASTREAM - static bool save(QDataStream &stream, int type, const void *data); - static bool load(QDataStream &stream, int type, void *data); -#endif - - explicit QMetaType(const int type); - inline ~QMetaType(); - - inline bool isValid() const; - inline bool isRegistered() const; - inline int sizeOf() const; - inline TypeFlags flags() const; - inline const QMetaObject *metaObject() const; - - inline void *create(const void *copy = 0) const; - inline void destroy(void *data) const; - inline void *construct(void *where, const void *copy = 0) const; - inline void destruct(void *data) const; - -public: - template - static bool registerComparators() - { - Q_STATIC_ASSERT_X((!QMetaTypeId2::IsBuiltIn), - "QMetaType::registerComparators: The type must be a custom type."); - - const int typeId = qMetaTypeId(); - static const QtPrivate::BuiltInComparatorFunction f; - return registerComparatorFunction( &f, typeId); - } - template - static bool hasRegisteredComparators() - { - return hasRegisteredComparators(qMetaTypeId()); - } - static bool hasRegisteredComparators(int typeId); - - -#ifndef QT_NO_DEBUG_STREAM - template - static bool registerDebugStreamOperator() - { - Q_STATIC_ASSERT_X((!QMetaTypeId2::IsBuiltIn), - "QMetaType::registerDebugStreamOperator: The type must be a custom type."); - - const int typeId = qMetaTypeId(); - static const QtPrivate::BuiltInDebugStreamFunction f; - return registerDebugStreamOperatorFunction(&f, typeId); - } - template - static bool hasRegisteredDebugStreamOperator() - { - return hasRegisteredDebugStreamOperator(qMetaTypeId()); - } - static bool hasRegisteredDebugStreamOperator(int typeId); -#endif - - // implicit conversion supported like double -> float - template - static bool registerConverter() - { - return registerConverter(QtPrivate::convertImplicit); - } - -#ifdef Q_QDOC - static bool registerConverter(MemberFunction function); - static bool registerConverter(MemberFunctionOk function); - static bool registerConverter(UnaryFunction function); -#else - // member function as in "QString QFont::toString() const" - template - static bool registerConverter(To(From::*function)() const) - { - Q_STATIC_ASSERT_X((!QMetaTypeId2::IsBuiltIn || !QMetaTypeId2::IsBuiltIn), - "QMetaType::registerConverter: At least one of the types must be a custom type."); - - const int fromTypeId = qMetaTypeId(); - const int toTypeId = qMetaTypeId(); - static const QtPrivate::ConverterMemberFunction f(function); - return registerConverterFunction(&f, fromTypeId, toTypeId); - } - - // member function as in "double QString::toDouble(bool *ok = 0) const" - template - static bool registerConverter(To(From::*function)(bool*) const) - { - Q_STATIC_ASSERT_X((!QMetaTypeId2::IsBuiltIn || !QMetaTypeId2::IsBuiltIn), - "QMetaType::registerConverter: At least one of the types must be a custom type."); - - const int fromTypeId = qMetaTypeId(); - const int toTypeId = qMetaTypeId(); - static const QtPrivate::ConverterMemberFunctionOk f(function); - return registerConverterFunction(&f, fromTypeId, toTypeId); - } - - // functor or function pointer - template - static bool registerConverter(UnaryFunction function) - { - Q_STATIC_ASSERT_X((!QMetaTypeId2::IsBuiltIn || !QMetaTypeId2::IsBuiltIn), - "QMetaType::registerConverter: At least one of the types must be a custom type."); - - const int fromTypeId = qMetaTypeId(); - const int toTypeId = qMetaTypeId(); - static const QtPrivate::ConverterFunctor f(function); - return registerConverterFunction(&f, fromTypeId, toTypeId); - } -#endif - - static bool convert(const void *from, int fromTypeId, void *to, int toTypeId); - static bool compare(const void *lhs, const void *rhs, int typeId, int* result); - static bool debugStream(QDebug& dbg, const void *rhs, int typeId); - - template - static bool hasRegisteredConverterFunction() - { - return hasRegisteredConverterFunction(qMetaTypeId(), qMetaTypeId()); - } - - static bool hasRegisteredConverterFunction(int fromTypeId, int toTypeId); - -private: - static QMetaType typeInfo(const int type); - inline QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeInterface *info, - Creator creator, - Deleter deleter, - SaveOperator saveOp, - LoadOperator loadOp, - Constructor constructor, - Destructor destructor, - uint sizeOf, - uint theTypeFlags, - int typeId, - const QMetaObject *metaObject); - QMetaType(const QMetaType &other); - QMetaType &operator =(const QMetaType &); - inline bool isExtended(const ExtensionFlag flag) const { return m_extensionFlags & flag; } - - // Methods used for future binary compatible extensions - void ctor(const QMetaTypeInterface *info); - void dtor(); - uint sizeExtended() const; - QMetaType::TypeFlags flagsExtended() const; - const QMetaObject *metaObjectExtended() const; - void *createExtended(const void *copy = 0) const; - void destroyExtended(void *data) const; - void *constructExtended(void *where, const void *copy = 0) const; - void destructExtended(void *data) const; - - static bool registerComparatorFunction(const QtPrivate::AbstractComparatorFunction *f, int type); -#ifndef QT_NO_DEBUG_STREAM - static bool registerDebugStreamOperatorFunction(const QtPrivate::AbstractDebugStreamFunction *f, int type); -#endif - -#ifndef Q_NO_TEMPLATE_FRIENDS -#ifndef Q_QDOC - template - friend bool qRegisterSequentialConverter(); - template friend struct QtPrivate::ValueTypeIsMetaType; - template friend struct QtPrivate::ConverterMemberFunction; - template friend struct QtPrivate::ConverterMemberFunctionOk; - template friend struct QtPrivate::ConverterFunctor; - template - friend bool qRegisterAssociativeConverter(); - template friend struct QtPrivate::AssociativeValueTypeIsMetaType; - template friend struct QtPrivate::IsMetaTypePair; - template friend struct QtPrivate::MetaTypeSmartPointerHelper; -#endif -#else -public: -#endif - static bool registerConverterFunction(const QtPrivate::AbstractConverterFunction *f, int from, int to); - static void unregisterConverterFunction(int from, int to); -private: - - Creator m_creator; - Deleter m_deleter; - SaveOperator m_saveOp; - LoadOperator m_loadOp; - Constructor m_constructor; - Destructor m_destructor; - void *m_extension; // space reserved for future use - uint m_size; - uint m_typeFlags; - uint m_extensionFlags; - int m_typeId; - const QMetaObject *m_metaObject; -}; - -#undef QT_DEFINE_METATYPE_ID - -Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaType::TypeFlags) - -namespace QtPrivate { - -template -ConverterMemberFunction::~ConverterMemberFunction() -{ - QMetaType::unregisterConverterFunction(qMetaTypeId(), qMetaTypeId()); -} -template -ConverterMemberFunctionOk::~ConverterMemberFunctionOk() -{ - QMetaType::unregisterConverterFunction(qMetaTypeId(), qMetaTypeId()); -} -template -ConverterFunctor::~ConverterFunctor() -{ - QMetaType::unregisterConverterFunction(qMetaTypeId(), qMetaTypeId()); -} - -} - -namespace QtMetaTypePrivate { -template -struct QMetaTypeFunctionHelper { - static void Delete(void *t) - { - delete static_cast(t); - } - - static void *Create(const void *t) - { - if (t) - return new T(*static_cast(t)); - return new T(); - } - - static void Destruct(void *t) - { - Q_UNUSED(t) // Silence MSVC that warns for POD types. - static_cast(t)->~T(); - } - - static void *Construct(void *where, const void *t) - { - if (t) - return new (where) T(*static_cast(t)); - return new (where) T; - } -#ifndef QT_NO_DATASTREAM - static void Save(QDataStream &stream, const void *t) - { - stream << *static_cast(t); - } - - static void Load(QDataStream &stream, void *t) - { - stream >> *static_cast(t); - } -#endif // QT_NO_DATASTREAM -}; - -template -struct QMetaTypeFunctionHelper { - static void Delete(void *) {} - static void *Create(const void *) { return 0; } - static void Destruct(void *) {} - static void *Construct(void *, const void *) { return 0; } -#ifndef QT_NO_DATASTREAM - static void Save(QDataStream &, const void *) {} - static void Load(QDataStream &, void *) {} -#endif // QT_NO_DATASTREAM -}; -template <> -struct QMetaTypeFunctionHelper - : public QMetaTypeFunctionHelper -{}; - -struct VariantData -{ - VariantData(const int metaTypeId_, - const void *data_, - const uint flags_) - : metaTypeId(metaTypeId_) - , data(data_) - , flags(flags_) - { - } - VariantData(const VariantData &other) - : metaTypeId(other.metaTypeId), data(other.data), flags(other.flags){} - const int metaTypeId; - const void *data; - const uint flags; -private: - // copy constructor allowed to be implicit to silence level 4 warning from MSVC - VariantData &operator=(const VariantData &) Q_DECL_EQ_DELETE; -}; - -template -struct IteratorOwner -{ - static void assign(void **ptr, const_iterator iterator) - { - *ptr = new const_iterator(iterator); - } - static void assign(void **ptr, void * const * src) - { - *ptr = new const_iterator(*static_cast(*src)); - } - - static void advance(void **iterator, int step) - { - const_iterator &it = *static_cast(*iterator); - std::advance(it, step); - } - - static void destroy(void **ptr) - { - delete static_cast(*ptr); - } - - static const void *getData(void * const *iterator) - { - return &**static_cast(*iterator); - } - - static const void *getData(const_iterator it) - { - return &*it; - } - - static bool equal(void * const *it, void * const *other) - { - return *static_cast(*it) == *static_cast(*other); - } -}; -template -struct IteratorOwner -{ - static void assign(void **ptr, const value_type *iterator ) - { - *ptr = const_cast(iterator); - } - static void assign(void **ptr, void * const * src) - { - *ptr = static_cast(*src); - } - - static void advance(void **iterator, int step) - { - value_type *it = static_cast(*iterator); - std::advance(it, step); - *iterator = it; - } - - static void destroy(void **) - { - } - - static const void *getData(void * const *iterator) - { - return *iterator; - } - - static const void *getData(const value_type *it) - { - return it; - } - - static bool equal(void * const *it, void * const *other) - { - return static_cast(*it) == static_cast(*other); - } -}; - -enum IteratorCapability -{ - ForwardCapability = 1, - BiDirectionalCapability = 2, - RandomAccessCapability = 4 -}; - -template::iterator_category> -struct CapabilitiesImpl; - -template -struct CapabilitiesImpl -{ enum { IteratorCapabilities = ForwardCapability }; }; -template -struct CapabilitiesImpl -{ enum { IteratorCapabilities = BiDirectionalCapability | ForwardCapability }; }; -template -struct CapabilitiesImpl -{ enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; }; - -template -struct ContainerAPI : CapabilitiesImpl -{ - static int size(const T *t) { return int(std::distance(t->begin(), t->end())); } -}; - -template -struct ContainerAPI > : CapabilitiesImpl > -{ static int size(const QList *t) { return t->size(); } }; - -template -struct ContainerAPI > : CapabilitiesImpl > -{ static int size(const QVector *t) { return t->size(); } }; - -template -struct ContainerAPI > : CapabilitiesImpl > -{ static int size(const std::vector *t) { return t->size(); } }; - -template -struct ContainerAPI > : CapabilitiesImpl > -{ static int size(const std::list *t) { return t->size(); } }; - -class QSequentialIterableImpl -{ -public: - const void * _iterable; - void *_iterator; - int _metaType_id; - uint _metaType_flags; - uint _iteratorCapabilities; - typedef int(*sizeFunc)(const void *p); - typedef const void * (*atFunc)(const void *p, int); - typedef void (*moveIteratorFunc)(const void *p, void **); - typedef void (*advanceFunc)(void **p, int); - typedef VariantData (*getFunc)( void * const *p, int metaTypeId, uint flags); - typedef void (*destroyIterFunc)(void **p); - typedef bool (*equalIterFunc)(void * const *p, void * const *other); - typedef void (*copyIterFunc)(void **, void * const *); - - sizeFunc _size; - atFunc _at; - moveIteratorFunc _moveToBegin; - moveIteratorFunc _moveToEnd; - advanceFunc _advance; - getFunc _get; - destroyIterFunc _destroyIter; - equalIterFunc _equalIter; - copyIterFunc _copyIter; - - template - static int sizeImpl(const void *p) - { return ContainerAPI::size(static_cast(p)); } - - template - static const void* atImpl(const void *p, int idx) - { - typename T::const_iterator i = static_cast(p)->begin(); - std::advance(i, idx); - return IteratorOwner::getData(i); - } - - template - static void moveToBeginImpl(const void *container, void **iterator) - { IteratorOwner::assign(iterator, static_cast(container)->begin()); } - - template - static void moveToEndImpl(const void *container, void **iterator) - { IteratorOwner::assign(iterator, static_cast(container)->end()); } - - template - static VariantData getImpl(void * const *iterator, int metaTypeId, uint flags) - { return VariantData(metaTypeId, IteratorOwner::getData(iterator), flags); } - -public: - template QSequentialIterableImpl(const T*p) - : _iterable(p) - , _iterator(0) - , _metaType_id(qMetaTypeId()) - , _metaType_flags(QTypeInfo::isPointer) - , _iteratorCapabilities(ContainerAPI::IteratorCapabilities) - , _size(sizeImpl) - , _at(atImpl) - , _moveToBegin(moveToBeginImpl) - , _moveToEnd(moveToEndImpl) - , _advance(IteratorOwner::advance) - , _get(getImpl) - , _destroyIter(IteratorOwner::destroy) - , _equalIter(IteratorOwner::equal) - , _copyIter(IteratorOwner::assign) - { - } - - QSequentialIterableImpl() - : _iterable(0) - , _iterator(0) - , _metaType_id(QMetaType::UnknownType) - , _metaType_flags(0) - , _iteratorCapabilities(0) - , _size(0) - , _at(0) - , _moveToBegin(0) - , _moveToEnd(0) - , _advance(0) - , _get(0) - , _destroyIter(0) - , _equalIter(0) - , _copyIter(0) - { - } - - inline void moveToBegin() { _moveToBegin(_iterable, &_iterator); } - inline void moveToEnd() { _moveToEnd(_iterable, &_iterator); } - inline bool equal(const QSequentialIterableImpl&other) const { return _equalIter(&_iterator, &other._iterator); } - inline QSequentialIterableImpl &advance(int i) { - Q_ASSERT(i > 0 || _iteratorCapabilities & BiDirectionalCapability); - _advance(&_iterator, i); - return *this; - } - - inline VariantData getCurrent() const { return _get(&_iterator, _metaType_id, _metaType_flags); } - - VariantData at(int idx) const - { return VariantData(_metaType_id, _at(_iterable, idx), _metaType_flags); } - - int size() const { Q_ASSERT(_iterable); return _size(_iterable); } - - inline void destroyIter() { _destroyIter(&_iterator); } - - void copy(const QSequentialIterableImpl &other) - { - *this = other; - _copyIter(&_iterator, &other._iterator); - } -}; - -template -struct QSequentialIterableConvertFunctor -{ - QSequentialIterableImpl operator()(const From &f) const - { - return QSequentialIterableImpl(&f); - } -}; -} - -namespace QtMetaTypePrivate { -template::value> -struct AssociativeContainerAccessor -{ - static const typename T::key_type& getKey(const typename T::const_iterator &it) - { - return it.key(); - } - - static const typename T::mapped_type& getValue(const typename T::const_iterator &it) - { - return it.value(); - } -}; - -template >::value> -struct StlStyleAssociativeContainerAccessor; - -template -struct StlStyleAssociativeContainerAccessor -{ - static const typename T::key_type& getKey(const typename T::const_iterator &it) - { - return it->first; - } - - static const typename T::mapped_type& getValue(const typename T::const_iterator &it) - { - return it->second; - } -}; - -template -struct AssociativeContainerAccessor : public StlStyleAssociativeContainerAccessor -{ -}; - -class QAssociativeIterableImpl -{ -public: - const void *_iterable; - void *_iterator; - int _metaType_id_key; - uint _metaType_flags_key; - int _metaType_id_value; - uint _metaType_flags_value; - typedef int(*sizeFunc)(const void *p); - typedef void (*findFunc)(const void *container, const void *p, void **iterator); - typedef void (*beginFunc)(const void *p, void **); - typedef void (*advanceFunc)(void **p, int); - typedef VariantData (*getFunc)(void * const *p, int metaTypeId, uint flags); - typedef void (*destroyIterFunc)(void **p); - typedef bool (*equalIterFunc)(void * const *p, void * const *other); - typedef void (*copyIterFunc)(void **, void * const *); - - sizeFunc _size; - findFunc _find; - beginFunc _begin; - beginFunc _end; - advanceFunc _advance; - getFunc _getKey; - getFunc _getValue; - destroyIterFunc _destroyIter; - equalIterFunc _equalIter; - copyIterFunc _copyIter; - - template - static int sizeImpl(const void *p) - { return int(std::distance(static_cast(p)->begin(), - static_cast(p)->end())); } - - template - static void findImpl(const void *container, const void *p, void **iterator) - { IteratorOwner::assign(iterator, - static_cast(container)->find(*static_cast(p))); } - - template - static void advanceImpl(void **p, int step) - { std::advance(*static_cast(*p), step); } - - template - static void beginImpl(const void *container, void **iterator) - { IteratorOwner::assign(iterator, static_cast(container)->begin()); } - - template - static void endImpl(const void *container, void **iterator) - { IteratorOwner::assign(iterator, static_cast(container)->end()); } - - template - static VariantData getKeyImpl(void * const *iterator, int metaTypeId, uint flags) - { return VariantData(metaTypeId, &AssociativeContainerAccessor::getKey(*static_cast(*iterator)), flags); } - - template - static VariantData getValueImpl(void * const *iterator, int metaTypeId, uint flags) - { return VariantData(metaTypeId, &AssociativeContainerAccessor::getValue(*static_cast(*iterator)), flags); } - -public: - template QAssociativeIterableImpl(const T*p) - : _iterable(p) - , _metaType_id_key(qMetaTypeId()) - , _metaType_flags_key(QTypeInfo::isPointer) - , _metaType_id_value(qMetaTypeId()) - , _metaType_flags_value(QTypeInfo::isPointer) - , _size(sizeImpl) - , _find(findImpl) - , _begin(beginImpl) - , _end(endImpl) - , _advance(advanceImpl) - , _getKey(getKeyImpl) - , _getValue(getValueImpl) - , _destroyIter(IteratorOwner::destroy) - , _equalIter(IteratorOwner::equal) - , _copyIter(IteratorOwner::assign) - { - } - - QAssociativeIterableImpl() - : _iterable(0) - , _metaType_id_key(QMetaType::UnknownType) - , _metaType_flags_key(0) - , _metaType_id_value(QMetaType::UnknownType) - , _metaType_flags_value(0) - , _size(0) - , _find(0) - , _begin(0) - , _end(0) - , _advance(0) - , _getKey(0) - , _getValue(0) - , _destroyIter(0) - , _equalIter(0) - , _copyIter(0) - { - } - - inline void begin() { _begin(_iterable, &_iterator); } - inline void end() { _end(_iterable, &_iterator); } - inline bool equal(const QAssociativeIterableImpl&other) const { return _equalIter(&_iterator, &other._iterator); } - inline QAssociativeIterableImpl &advance(int i) { _advance(&_iterator, i); return *this; } - - inline void destroyIter() { _destroyIter(&_iterator); } - - inline VariantData getCurrentKey() const { return _getKey(&_iterator, _metaType_id_key, _metaType_flags_value); } - inline VariantData getCurrentValue() const { return _getValue(&_iterator, _metaType_id_value, _metaType_flags_value); } - - inline void find(const VariantData &key) - { _find(_iterable, key.data, &_iterator); } - - int size() const { Q_ASSERT(_iterable); return _size(_iterable); } - - void copy(const QAssociativeIterableImpl &other) - { - *this = other; - _copyIter(&_iterator, &other._iterator); - } -}; - -template -struct QAssociativeIterableConvertFunctor -{ - QAssociativeIterableImpl operator()(const From& f) const - { - return QAssociativeIterableImpl(&f); - } -}; - -class QPairVariantInterfaceImpl -{ - const void *_pair; - int _metaType_id_first; - uint _metaType_flags_first; - int _metaType_id_second; - uint _metaType_flags_second; - - typedef VariantData (*getFunc)(const void * const *p, int metaTypeId, uint flags); - - getFunc _getFirst; - getFunc _getSecond; - - template - static VariantData getFirstImpl(const void * const *pair, int metaTypeId, uint flags) - { return VariantData(metaTypeId, &static_cast(*pair)->first, flags); } - template - static VariantData getSecondImpl(const void * const *pair, int metaTypeId, uint flags) - { return VariantData(metaTypeId, &static_cast(*pair)->second, flags); } - -public: - template QPairVariantInterfaceImpl(const T*p) - : _pair(p) - , _metaType_id_first(qMetaTypeId()) - , _metaType_flags_first(QTypeInfo::isPointer) - , _metaType_id_second(qMetaTypeId()) - , _metaType_flags_second(QTypeInfo::isPointer) - , _getFirst(getFirstImpl) - , _getSecond(getSecondImpl) - { - } - - QPairVariantInterfaceImpl() - : _pair(0) - , _getFirst(0) - , _getSecond(0) - { - } - - inline VariantData first() const { return _getFirst(&_pair, _metaType_id_first, _metaType_flags_first); } - inline VariantData second() const { return _getSecond(&_pair, _metaType_id_second, _metaType_flags_second); } -}; - -template -struct QPairVariantInterfaceConvertFunctor; - -template -struct QPairVariantInterfaceConvertFunctor > -{ - QPairVariantInterfaceImpl operator()(const QPair& f) const - { - return QPairVariantInterfaceImpl(&f); - } -}; - -template -struct QPairVariantInterfaceConvertFunctor > -{ - QPairVariantInterfaceImpl operator()(const std::pair& f) const - { - return QPairVariantInterfaceImpl(&f); - } -}; - -} - -class QObject; -class QWidget; - -#define QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER(Name) \ - template class Name; \ - -QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER) - -namespace QtPrivate -{ - template - struct IsPointerToTypeDerivedFromQObject - { - enum { Value = false }; - }; - - // Specialize to avoid sizeof(void) warning - template<> - struct IsPointerToTypeDerivedFromQObject - { - enum { Value = false }; - }; - template<> - struct IsPointerToTypeDerivedFromQObject - { - enum { Value = true }; - }; - - template - struct IsPointerToTypeDerivedFromQObject - { - typedef qint8 yes_type; - typedef qint64 no_type; - -#ifndef QT_NO_QOBJECT - static yes_type checkType(QObject* ); -#endif - static no_type checkType(...); - Q_STATIC_ASSERT_X(sizeof(T), "Type argument of Q_DECLARE_METATYPE(T*) must be fully defined"); - enum { Value = sizeof(checkType(static_cast(0))) == sizeof(yes_type) }; - }; - - template::Value> - struct MetaObjectForType - { - static inline const QMetaObject *value() { return 0; } - }; - - template - struct MetaObjectForType - { - static inline const QMetaObject *value() { return &T::staticMetaObject; } - }; - - template - struct IsSharedPointerToTypeDerivedFromQObject - { - enum { Value = false }; - }; - - template - struct IsSharedPointerToTypeDerivedFromQObject > : IsPointerToTypeDerivedFromQObject - { - }; - - template - struct IsWeakPointerToTypeDerivedFromQObject - { - enum { Value = false }; - }; - - template - struct IsWeakPointerToTypeDerivedFromQObject > : IsPointerToTypeDerivedFromQObject - { - }; - - template - struct IsTrackingPointerToTypeDerivedFromQObject - { - enum { Value = false }; - }; - - template - struct IsTrackingPointerToTypeDerivedFromQObject > - { - enum { Value = true }; - }; - - template - struct IsSequentialContainer - { - enum { Value = false }; - }; - - template - struct IsAssociativeContainer - { - enum { Value = false }; - }; - - template::Value> - struct SequentialContainerConverterHelper - { - static bool registerConverter(int) - { - return false; - } - }; - - template::Defined> - struct ValueTypeIsMetaType - { - static bool registerConverter(int) - { - return false; - } - }; - - template - struct SequentialContainerConverterHelper : ValueTypeIsMetaType - { - }; - - template::Value> - struct AssociativeContainerConverterHelper - { - static bool registerConverter(int) - { - return false; - } - }; - - template::Defined> - struct AssociativeValueTypeIsMetaType - { - static bool registerConverter(int) - { - return false; - } - }; - - template::Defined> - struct KeyAndValueTypeIsMetaType - { - static bool registerConverter(int) - { - return false; - } - }; - - template - struct KeyAndValueTypeIsMetaType : AssociativeValueTypeIsMetaType - { - }; - - template - struct AssociativeContainerConverterHelper : KeyAndValueTypeIsMetaType - { - }; - - template::Defined - && QMetaTypeId2::Defined> - struct IsMetaTypePair - { - static bool registerConverter(int) - { - return false; - } - }; - - template - struct IsMetaTypePair - { - inline static bool registerConverter(int id); - }; - - template - struct IsPair - { - static bool registerConverter(int) - { - return false; - } - }; - template - struct IsPair > : IsMetaTypePair > {}; - template - struct IsPair > : IsMetaTypePair > {}; - - template - struct MetaTypePairHelper : IsPair {}; - - template - struct MetaTypeSmartPointerHelper - { - static bool registerConverter(int) { return false; } - }; - - Q_CORE_EXPORT bool isBuiltinType(const QByteArray &type); -} // namespace QtPrivate - -template ::Value> -struct QMetaTypeIdQObject -{ - enum { - Defined = 0 - }; -}; - -template -struct QMetaTypeId : public QMetaTypeIdQObject -{ -}; - -template -struct QMetaTypeId2 -{ - enum { Defined = QMetaTypeId::Defined, IsBuiltIn=false }; - static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return QMetaTypeId::qt_metatype_id(); } -}; - -template -struct QMetaTypeId2 : QMetaTypeId2 {}; - -namespace QtPrivate { - template ::Defined> - struct QMetaTypeIdHelper { - static inline Q_DECL_CONSTEXPR int qt_metatype_id() - { return QMetaTypeId2::qt_metatype_id(); } - }; - template struct QMetaTypeIdHelper { - static inline Q_DECL_CONSTEXPR int qt_metatype_id() - { return -1; } - }; - -#ifndef Q_COMPILER_VARIADIC_TEMPLATES - // Function pointers don't derive from QObject - template struct IsPointerToTypeDerivedFromQObject { enum { Value = false }; }; - template struct IsPointerToTypeDerivedFromQObject { enum { Value = false }; }; - template struct IsPointerToTypeDerivedFromQObject { enum { Value = false }; }; - template struct IsPointerToTypeDerivedFromQObject { enum { Value = false }; }; -#else - template - struct IsPointerToTypeDerivedFromQObject { enum { Value = false }; }; -#endif - - template - struct QMetaTypeTypeFlags - { - enum { Flags = (!QTypeInfo::isStatic ? QMetaType::MovableType : 0) - | (QTypeInfo::isComplex ? QMetaType::NeedsConstruction : 0) - | (QTypeInfo::isComplex ? QMetaType::NeedsDestruction : 0) - | (IsPointerToTypeDerivedFromQObject::Value ? QMetaType::PointerToQObject : 0) - | (IsSharedPointerToTypeDerivedFromQObject::Value ? QMetaType::SharedPointerToQObject : 0) - | (IsWeakPointerToTypeDerivedFromQObject::Value ? QMetaType::WeakPointerToQObject : 0) - | (IsTrackingPointerToTypeDerivedFromQObject::Value ? QMetaType::TrackingPointerToQObject : 0) - | (Q_IS_ENUM(T) ? QMetaType::IsEnumeration : 0) - }; - }; - - template - struct MetaTypeDefinedHelper - { - enum DefinedType { Defined = defined }; - }; - - template - struct QSmartPointerConvertFunctor - { - QObject* operator()(const SmartPointer &p) const - { - return p.operator->(); - } - }; - - template - struct QSmartPointerConvertFunctor > - { - QObject* operator()(const QWeakPointer &p) const - { - return p.data(); - } - }; -} - -template -int qRegisterNormalizedMetaType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName -#ifndef Q_QDOC - , T * dummy = 0 - , typename QtPrivate::MetaTypeDefinedHelper::Defined && !QMetaTypeId2::IsBuiltIn>::DefinedType defined = QtPrivate::MetaTypeDefinedHelper::Defined && !QMetaTypeId2::IsBuiltIn>::Defined -#endif -) -{ -#ifndef QT_NO_QOBJECT - Q_ASSERT_X(normalizedTypeName == QMetaObject::normalizedType(normalizedTypeName.constData()), "qRegisterNormalizedMetaType", "qRegisterNormalizedMetaType was called with a not normalized type name, please call qRegisterMetaType instead."); -#endif - const int typedefOf = dummy ? -1 : QtPrivate::QMetaTypeIdHelper::qt_metatype_id(); - if (typedefOf != -1) - return QMetaType::registerNormalizedTypedef(normalizedTypeName, typedefOf); - - QMetaType::TypeFlags flags(QtPrivate::QMetaTypeTypeFlags::Flags); - - if (defined) - flags |= QMetaType::WasDeclaredAsMetaType; - - const int id = QMetaType::registerNormalizedType(normalizedTypeName, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Delete, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Create, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Construct, - int(sizeof(T)), - flags, - QtPrivate::MetaObjectForType::value()); - - if (id > 0) { - QtPrivate::SequentialContainerConverterHelper::registerConverter(id); - QtPrivate::AssociativeContainerConverterHelper::registerConverter(id); - QtPrivate::MetaTypePairHelper::registerConverter(id); - QtPrivate::MetaTypeSmartPointerHelper::registerConverter(id); - } - - return id; -} - -template -int qRegisterMetaType(const char *typeName -#ifndef Q_QDOC - , T * dummy = 0 - , typename QtPrivate::MetaTypeDefinedHelper::Defined && !QMetaTypeId2::IsBuiltIn>::DefinedType defined = QtPrivate::MetaTypeDefinedHelper::Defined && !QMetaTypeId2::IsBuiltIn>::Defined -#endif -) -{ -#ifdef QT_NO_QOBJECT - QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = typeName; -#else - QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName); -#endif - return qRegisterNormalizedMetaType(normalizedTypeName, dummy, defined); -} - -#ifndef QT_NO_DATASTREAM -template -void qRegisterMetaTypeStreamOperators(const char *typeName -#ifndef Q_QDOC - , T * /* dummy */ = 0 -#endif -) -{ - qRegisterMetaType(typeName); - QMetaType::registerStreamOperators(typeName, QtMetaTypePrivate::QMetaTypeFunctionHelper::Save, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Load); -} -#endif // QT_NO_DATASTREAM - -template -inline Q_DECL_CONSTEXPR int qMetaTypeId() -{ - Q_STATIC_ASSERT_X(QMetaTypeId2::Defined, "Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system"); - return QMetaTypeId2::qt_metatype_id(); -} - -template -inline Q_DECL_CONSTEXPR int qRegisterMetaType() -{ - return qMetaTypeId(); -} - -#if QT_DEPRECATED_SINCE(5, 1) && !defined(Q_QDOC) -// There used to be a T *dummy = 0 argument in Qt 4.0 to support MSVC6 -template -QT_DEPRECATED inline Q_DECL_CONSTEXPR int qMetaTypeId(T *) -{ return qMetaTypeId(); } -#ifndef Q_CC_SUN -template -QT_DEPRECATED inline Q_DECL_CONSTEXPR int qRegisterMetaType(T *) -{ return qRegisterMetaType(); } -#endif -#endif - -template -struct QMetaTypeIdQObject -{ - enum { - Defined = 1 - }; - - static int qt_metatype_id() - { - static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); - if (const int id = metatype_id.loadAcquire()) - return id; - const char * const cName = T::staticMetaObject.className(); - QByteArray typeName; - typeName.reserve(int(strlen(cName)) + 1); - typeName.append(cName).append('*'); - const int newId = qRegisterNormalizedMetaType( - typeName, - reinterpret_cast(quintptr(-1))); - metatype_id.storeRelease(newId); - return newId; - } -}; - -#ifndef QT_NO_DATASTREAM -template -inline int qRegisterMetaTypeStreamOperators() -{ - int id = qMetaTypeId(); - QMetaType::registerStreamOperators(id, QtMetaTypePrivate::QMetaTypeFunctionHelper::Save, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Load); - return id; -} -#endif - -#define Q_DECLARE_OPAQUE_POINTER(POINTER) \ - QT_BEGIN_NAMESPACE namespace QtPrivate { \ - template <> \ - struct IsPointerToTypeDerivedFromQObject \ - { \ - enum { Value = false }; \ - }; \ - } QT_END_NAMESPACE \ - /**/ - -#define Q_DECLARE_METATYPE(TYPE) Q_DECLARE_METATYPE_IMPL(TYPE) -#define Q_DECLARE_METATYPE_IMPL(TYPE) \ - QT_BEGIN_NAMESPACE \ - template <> \ - struct QMetaTypeId< TYPE > \ - { \ - enum { Defined = 1 }; \ - static int qt_metatype_id() \ - { \ - static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ - if (const int id = metatype_id.loadAcquire()) \ - return id; \ - const int newId = qRegisterMetaType< TYPE >(#TYPE, \ - reinterpret_cast< TYPE *>(quintptr(-1))); \ - metatype_id.storeRelease(newId); \ - return newId; \ - } \ - }; \ - QT_END_NAMESPACE - - -#define Q_DECLARE_BUILTIN_METATYPE(TYPE, METATYPEID, NAME) \ - QT_BEGIN_NAMESPACE \ - template<> struct QMetaTypeId2 \ - { \ - enum { Defined = 1, IsBuiltIn = true, MetaType = METATYPEID }; \ - static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return METATYPEID; } \ - }; \ - QT_END_NAMESPACE - -#define QT_FORWARD_DECLARE_STATIC_TYPES_ITER(TypeName, TypeId, Name) \ - class Name; - -QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER) -QT_FOR_EACH_STATIC_GUI_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER) -QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER) - -#undef QT_FORWARD_DECLARE_STATIC_TYPES_ITER - -typedef QList QVariantList; -typedef QMap QVariantMap; -typedef QHash QVariantHash; - -#define Q_DECLARE_METATYPE_TEMPLATE_1ARG(SINGLE_ARG_TEMPLATE) \ -QT_BEGIN_NAMESPACE \ -template \ -struct QMetaTypeId< SINGLE_ARG_TEMPLATE > \ -{ \ - enum { \ - Defined = QMetaTypeId2::Defined \ - }; \ - static int qt_metatype_id() \ - { \ - static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ - if (const int id = metatype_id.load()) \ - return id; \ - const char *tName = QMetaType::typeName(qMetaTypeId()); \ - Q_ASSERT(tName); \ - const int tNameLen = int(qstrlen(tName)); \ - QByteArray typeName; \ - typeName.reserve(int(sizeof(#SINGLE_ARG_TEMPLATE)) + 1 + tNameLen + 1 + 1); \ - typeName.append(#SINGLE_ARG_TEMPLATE, int(sizeof(#SINGLE_ARG_TEMPLATE)) - 1) \ - .append('<').append(tName, tNameLen); \ - if (typeName.endsWith('>')) \ - typeName.append(' '); \ - typeName.append('>'); \ - const int newId = qRegisterNormalizedMetaType< SINGLE_ARG_TEMPLATE >( \ - typeName, \ - reinterpret_cast< SINGLE_ARG_TEMPLATE *>(quintptr(-1))); \ - metatype_id.storeRelease(newId); \ - return newId; \ - } \ -}; \ -namespace QtPrivate { \ -template \ -struct IsSequentialContainer > \ -{ \ - enum { Value = true }; \ -}; \ -} \ -QT_END_NAMESPACE - -#define Q_DECLARE_METATYPE_TEMPLATE_2ARG(DOUBLE_ARG_TEMPLATE) \ -QT_BEGIN_NAMESPACE \ -template \ -struct QMetaTypeId< DOUBLE_ARG_TEMPLATE > \ -{ \ - enum { \ - Defined = QMetaTypeId2::Defined && QMetaTypeId2::Defined \ - }; \ - static int qt_metatype_id() \ - { \ - static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ - if (const int id = metatype_id.loadAcquire()) \ - return id; \ - const char *tName = QMetaType::typeName(qMetaTypeId()); \ - const char *uName = QMetaType::typeName(qMetaTypeId()); \ - Q_ASSERT(tName); \ - Q_ASSERT(uName); \ - const int tNameLen = int(qstrlen(tName)); \ - const int uNameLen = int(qstrlen(uName)); \ - QByteArray typeName; \ - typeName.reserve(int(sizeof(#DOUBLE_ARG_TEMPLATE)) + 1 + tNameLen + 1 + uNameLen + 1 + 1); \ - typeName.append(#DOUBLE_ARG_TEMPLATE, int(sizeof(#DOUBLE_ARG_TEMPLATE)) - 1) \ - .append('<').append(tName, tNameLen).append(',').append(uName, uNameLen); \ - if (typeName.endsWith('>')) \ - typeName.append(' '); \ - typeName.append('>'); \ - const int newId = qRegisterNormalizedMetaType< DOUBLE_ARG_TEMPLATE >(\ - typeName, \ - reinterpret_cast< DOUBLE_ARG_TEMPLATE *>(quintptr(-1))); \ - metatype_id.storeRelease(newId); \ - return newId; \ - } \ -}; \ -QT_END_NAMESPACE - -namespace QtPrivate { - -template -struct SharedPointerMetaTypeIdHelper -{ - enum { - Defined = 0 - }; - static int qt_metatype_id() - { - return -1; - } -}; - -} - -#define Q_DECLARE_SMART_POINTER_METATYPE(SMART_POINTER) \ -QT_BEGIN_NAMESPACE \ -namespace QtPrivate { \ -template \ -struct SharedPointerMetaTypeIdHelper, true> \ -{ \ - enum { \ - Defined = 1 \ - }; \ - static int qt_metatype_id() \ - { \ - static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ - if (const int id = metatype_id.loadAcquire()) \ - return id; \ - const char * const cName = T::staticMetaObject.className(); \ - QByteArray typeName; \ - typeName.reserve(int(sizeof(#SMART_POINTER) + 1 + strlen(cName) + 1)); \ - typeName.append(#SMART_POINTER, int(sizeof(#SMART_POINTER)) - 1) \ - .append('<').append(cName).append('>'); \ - const int newId = qRegisterNormalizedMetaType< SMART_POINTER >( \ - typeName, \ - reinterpret_cast< SMART_POINTER *>(quintptr(-1))); \ - metatype_id.storeRelease(newId); \ - return newId; \ - } \ -}; \ -template \ -struct MetaTypeSmartPointerHelper , \ - typename QEnableIf::Value >::Type> \ -{ \ - static bool registerConverter(int id) \ - { \ - const int toId = QMetaType::QObjectStar; \ - if (!QMetaType::hasRegisteredConverterFunction(id, toId)) { \ - QtPrivate::QSmartPointerConvertFunctor > o; \ - static const QtPrivate::ConverterFunctor, \ - QObject*, \ - QSmartPointerConvertFunctor > > f(o); \ - return QMetaType::registerConverterFunction(&f, id, toId); \ - } \ - return true; \ - } \ -}; \ -} \ -template \ -struct QMetaTypeId< SMART_POINTER > \ - : QtPrivate::SharedPointerMetaTypeIdHelper< SMART_POINTER, \ - QtPrivate::IsPointerToTypeDerivedFromQObject::Value> \ -{ \ -};\ -QT_END_NAMESPACE - -#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER(TEMPLATENAME) \ - QT_BEGIN_NAMESPACE \ - template class TEMPLATENAME; \ - QT_END_NAMESPACE \ - Q_DECLARE_METATYPE_TEMPLATE_1ARG(TEMPLATENAME) - -QT_END_NAMESPACE - -QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER) - -#undef Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER - -#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE Q_DECLARE_METATYPE_TEMPLATE_1ARG - -Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(std::vector) -Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(std::list) - -#define Q_FORWARD_DECLARE_METATYPE_TEMPLATE_2ARG_ITER(TEMPLATENAME, CPPTYPE) \ - QT_BEGIN_NAMESPACE \ - template CPPTYPE TEMPLATENAME; \ - QT_END_NAMESPACE \ - -QT_FOR_EACH_AUTOMATIC_TEMPLATE_2ARG(Q_FORWARD_DECLARE_METATYPE_TEMPLATE_2ARG_ITER) - -#undef Q_DECLARE_METATYPE_TEMPLATE_2ARG_ITER - -#define Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(TEMPLATENAME) \ - QT_BEGIN_NAMESPACE \ - namespace QtPrivate { \ - template \ - struct IsAssociativeContainer > \ - { \ - enum { Value = true }; \ - }; \ - } \ - QT_END_NAMESPACE \ - Q_DECLARE_METATYPE_TEMPLATE_2ARG(TEMPLATENAME) - -Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(QHash) -Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(QMap) -Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(std::map) - -Q_DECLARE_METATYPE_TEMPLATE_2ARG(QPair) -Q_DECLARE_METATYPE_TEMPLATE_2ARG(std::pair) - -#define Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER(TEMPLATENAME) \ - Q_DECLARE_SMART_POINTER_METATYPE(TEMPLATENAME) - - -QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER) - -QT_BEGIN_NAMESPACE - -#undef Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER - -inline QMetaType::QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeInterface *info, - Creator creator, - Deleter deleter, - SaveOperator saveOp, - LoadOperator loadOp, - Constructor constructor, - Destructor destructor, - uint size, - uint theTypeFlags, - int typeId, - const QMetaObject *_metaObject) - : m_creator(creator) - , m_deleter(deleter) - , m_saveOp(saveOp) - , m_loadOp(loadOp) - , m_constructor(constructor) - , m_destructor(destructor) - , m_extension(0) - , m_size(size) - , m_typeFlags(theTypeFlags) - , m_extensionFlags(extensionFlags) - , m_typeId(typeId) - , m_metaObject(_metaObject) -{ - if (Q_UNLIKELY(isExtended(CtorEx) || typeId == QMetaType::Void)) - ctor(info); -} - -inline QMetaType::~QMetaType() -{ - if (Q_UNLIKELY(isExtended(DtorEx))) - dtor(); -} - -inline bool QMetaType::isValid() const -{ - return m_typeId != UnknownType; -} - -inline bool QMetaType::isRegistered() const -{ - return isValid(); -} - -inline void *QMetaType::create(const void *copy) const -{ - if (Q_UNLIKELY(isExtended(CreateEx))) - return createExtended(copy); - return m_creator(copy); -} - -inline void QMetaType::destroy(void *data) const -{ - if (Q_UNLIKELY(isExtended(DestroyEx))) - return destroyExtended(data); - m_deleter(data); -} - -inline void *QMetaType::construct(void *where, const void *copy) const -{ - if (Q_UNLIKELY(isExtended(ConstructEx))) - return constructExtended(where, copy); - return m_constructor(where, copy); -} - -inline void QMetaType::destruct(void *data) const -{ - if (Q_UNLIKELY(isExtended(DestructEx))) - return destructExtended(data); - if (Q_UNLIKELY(!data)) - return; - m_destructor(data); -} - -inline int QMetaType::sizeOf() const -{ - if (Q_UNLIKELY(isExtended(SizeEx))) - return sizeExtended(); - return m_size; -} - -inline QMetaType::TypeFlags QMetaType::flags() const -{ - if (Q_UNLIKELY(isExtended(FlagsEx))) - return flagsExtended(); - return QMetaType::TypeFlags(m_typeFlags); -} - -inline const QMetaObject *QMetaType::metaObject() const -{ - if (Q_UNLIKELY(isExtended(MetaObjectEx))) - return metaObjectExtended(); - return m_metaObject; -} - -QT_END_NAMESPACE - - -QT_FOR_EACH_STATIC_TYPE(Q_DECLARE_BUILTIN_METATYPE) - -Q_DECLARE_METATYPE(QtMetaTypePrivate::QSequentialIterableImpl) -Q_DECLARE_METATYPE(QtMetaTypePrivate::QAssociativeIterableImpl) -Q_DECLARE_METATYPE(QtMetaTypePrivate::QPairVariantInterfaceImpl) - -QT_BEGIN_NAMESPACE - -template -inline bool QtPrivate::IsMetaTypePair::registerConverter(int id) -{ - const int toId = qMetaTypeId(); - if (!QMetaType::hasRegisteredConverterFunction(id, toId)) { - QtMetaTypePrivate::QPairVariantInterfaceConvertFunctor o; - static const QtPrivate::ConverterFunctor > f(o); - return QMetaType::registerConverterFunction(&f, id, toId); - } - return true; -} - -namespace QtPrivate { - template - struct ValueTypeIsMetaType - { - static bool registerConverter(int id) - { - const int toId = qMetaTypeId(); - if (!QMetaType::hasRegisteredConverterFunction(id, toId)) { - QtMetaTypePrivate::QSequentialIterableConvertFunctor o; - static const QtPrivate::ConverterFunctor > f(o); - return QMetaType::registerConverterFunction(&f, id, toId); - } - return true; - } - }; - - template - struct AssociativeValueTypeIsMetaType - { - static bool registerConverter(int id) - { - const int toId = qMetaTypeId(); - if (!QMetaType::hasRegisteredConverterFunction(id, toId)) { - QtMetaTypePrivate::QAssociativeIterableConvertFunctor o; - static const QtPrivate::ConverterFunctor > f(o); - return QMetaType::registerConverterFunction(&f, id, toId); - } - return true; - } - }; -} - -QT_END_NAMESPACE - -#endif // QMETATYPE_H diff --git a/DOtherSide/DynamicQObject/private/qmetatype_p.h b/DOtherSide/DynamicQObject/private/qmetatype_p.h deleted file mode 100644 index 95b9e2e..0000000 --- a/DOtherSide/DynamicQObject/private/qmetatype_p.h +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMETATYPE_P_H -#define QMETATYPE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmetatype.h" - -QT_BEGIN_NAMESPACE - -namespace QModulesPrivate { -enum Names { Core, Gui, Widgets, Unknown, ModulesCount /* ModulesCount has to be at the end */ }; - -static inline int moduleForType(const uint typeId) -{ - if (typeId <= QMetaType::LastCoreType) - return Core; - if (typeId >= QMetaType::FirstGuiType && typeId <= QMetaType::LastGuiType) - return Gui; - if (typeId >= QMetaType::FirstWidgetsType && typeId <= QMetaType::LastWidgetsType) - return Widgets; - return Unknown; -} - -template -class QTypeModuleInfo -{ -public: - enum Module { - IsCore = !QTypeInfo::isComplex, // Primitive types are in Core - IsWidget = false, - IsGui = false, - IsUnknown = !IsCore - }; -}; - -#define QT_ASSIGN_TYPE_TO_MODULE(TYPE, MODULE) \ -template<> \ -class QTypeModuleInfo \ -{ \ -public: \ - enum Module { \ - IsCore = (((MODULE) == (QModulesPrivate::Core))), \ - IsWidget = (((MODULE) == (QModulesPrivate::Widgets))), \ - IsGui = (((MODULE) == (QModulesPrivate::Gui))), \ - IsUnknown = !(IsCore || IsWidget || IsGui) \ - }; \ - static inline int module() { return MODULE; } \ - Q_STATIC_ASSERT((IsUnknown && !(IsCore || IsWidget || IsGui)) \ - || (IsCore && !(IsUnknown || IsWidget || IsGui)) \ - || (IsWidget && !(IsUnknown || IsCore || IsGui)) \ - || (IsGui && !(IsUnknown || IsCore || IsWidget))); \ -}; - - -#define QT_DECLARE_CORE_MODULE_TYPES_ITER(TypeName, TypeId, Name) \ - QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Core); -#define QT_DECLARE_GUI_MODULE_TYPES_ITER(TypeName, TypeId, Name) \ - QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Gui); -#define QT_DECLARE_WIDGETS_MODULE_TYPES_ITER(TypeName, TypeId, Name) \ - QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Widgets); - -QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER) -QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER) -QT_FOR_EACH_STATIC_GUI_CLASS(QT_DECLARE_GUI_MODULE_TYPES_ITER) -QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER) -} // namespace QModulesPrivate - -#undef QT_DECLARE_CORE_MODULE_TYPES_ITER -#undef QT_DECLARE_GUI_MODULE_TYPES_ITER -#undef QT_DECLARE_WIDGETS_MODULE_TYPES_ITER - -class QMetaTypeInterface -{ -public: - QMetaType::Creator creator; - QMetaType::Deleter deleter; - QMetaType::SaveOperator saveOp; - QMetaType::LoadOperator loadOp; - QMetaType::Constructor constructor; - QMetaType::Destructor destructor; - int size; - quint32 flags; // same as QMetaType::TypeFlags - const QMetaObject *metaObject; -}; - -#ifndef QT_NO_DATASTREAM -# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \ - /*saveOp*/(QtMetaTypePrivate::QMetaTypeFunctionHelper::IsAvailable>::Save), \ - /*loadOp*/(QtMetaTypePrivate::QMetaTypeFunctionHelper::IsAvailable>::Load), -# define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \ - /*saveOp*/ 0, \ - /*loadOp*/ 0, -#else -# define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \ - /*saveOp*/ 0, \ - /*loadOp*/ 0, -# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \ - QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) -#endif - -#ifndef QT_BOOTSTRAPPED -#define METAOBJECT_DELEGATE(Type) (QtPrivate::MetaObjectForType::value()) -#else -#define METAOBJECT_DELEGATE(Type) 0 -#endif - -#define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \ -{ \ - /*creator*/(QtMetaTypePrivate::QMetaTypeFunctionHelper::IsAvailable>::Create), \ - /*deleter*/(QtMetaTypePrivate::QMetaTypeFunctionHelper::IsAvailable>::Delete), \ - DATASTREAM_DELEGATE(Type) \ - /*constructor*/(QtMetaTypePrivate::QMetaTypeFunctionHelper::IsAvailable>::Construct), \ - /*destructor*/(QtMetaTypePrivate::QMetaTypeFunctionHelper::IsAvailable>::Destruct), \ - /*size*/(QTypeInfo::sizeOf), \ - /*flags*/QtPrivate::QMetaTypeTypeFlags::Flags, \ - /*metaObject*/METAOBJECT_DELEGATE(Type) \ -} - - -/* These QT_METATYPE_INTERFACE_INIT* macros are used to initialize QMetaTypeInterface instance. - - - QT_METATYPE_INTERFACE_INIT(Type) -> It takes Type argument and creates all necessary wrapper functions for the Type, - it detects if QT_NO_DATASTREAM was defined. Probably it is the macro that you want to use. - - - QT_METATYPE_INTERFACE_INIT_EMPTY() -> It initializes an empty QMetaTypeInterface instance. - - - QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) -> Temporary workaround for missing auto-detection of data stream - operators. It creates same instance as QT_METATYPE_INTERFACE_INIT(Type) but with null stream operators callbacks. - */ -#define QT_METATYPE_INTERFACE_INIT(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL) -#define QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL) -#define QT_METATYPE_INTERFACE_INIT_EMPTY() \ -{ \ - /*creator*/ 0, \ - /*deleter*/ 0, \ - QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(void) \ - /*constructor*/ 0, \ - /*destructor*/ 0, \ - /*size*/ 0, \ - /*flags*/ 0, \ - /*metaObject*/ 0 \ -} - -namespace QtMetaTypePrivate { -template -struct TypeDefinition { - static const bool IsAvailable = true; -}; - -// Ignore these types, as incomplete -#ifdef QT_BOOTSTRAPPED -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_GEOM_VARIANT -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_REGEXP -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGULAREXPRESSION) -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_SHORTCUT -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_CURSOR -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_MATRIX4X4 -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_VECTOR2D -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_VECTOR3D -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_VECTOR4D -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_QUATERNION -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -#ifdef QT_NO_ICON -template<> struct TypeDefinition { static const bool IsAvailable = false; }; -#endif -} //namespace QtMetaTypePrivate - -QT_END_NAMESPACE - -#endif // QMETATYPE_P_H diff --git a/DOtherSide/DynamicQObject/private/qmetatypeswitcher_p.h b/DOtherSide/DynamicQObject/private/qmetatypeswitcher_p.h deleted file mode 100644 index 2916bde..0000000 --- a/DOtherSide/DynamicQObject/private/qmetatypeswitcher_p.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMETATYPESWITCHER_P_H -#define QMETATYPESWITCHER_P_H - -#include "qmetatype.h" - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -QT_BEGIN_NAMESPACE - -class QMetaTypeSwitcher { -public: - class NotBuiltinType; // type is not a built-in type, but it may be a custom type or an unknown type - class UnknownType; // type not known to QMetaType system - template - static ReturnType switcher(DelegateObject &logic, int type, const void *data); -}; - - -#define QT_METATYPE_SWICHER_CASE(TypeName, TypeId, Name)\ - case QMetaType::TypeName: return logic.delegate(static_cast(data)); - -template -ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const void *data) -{ - switch (QMetaType::Type(type)) { - QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_SWICHER_CASE) - - case QMetaType::UnknownType: - return logic.delegate(static_cast(data)); - default: - if (type < QMetaType::User) - return logic.delegate(static_cast(data)); - return logic.delegate(static_cast(data)); - } -} - -#undef QT_METATYPE_SWICHER_CASE - -QT_END_NAMESPACE - -#endif // QMETATYPESWITCHER_P_H