Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qmetaobject.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 
0005 #ifndef QMETAOBJECT_H
0006 #define QMETAOBJECT_H
0007 
0008 #include <QtCore/qobjectdefs.h>
0009 #include <QtCore/qvariant.h>
0010 
0011 QT_BEGIN_NAMESPACE
0012 
0013 class QUntypedBindable;
0014 
0015 #define Q_METAMETHOD_INVOKE_MAX_ARGS 10
0016 
0017 class Q_CORE_EXPORT QMetaMethod
0018 {
0019 public:
0020     constexpr inline QMetaMethod() : mobj(nullptr), data({ nullptr }) {}
0021 
0022     QByteArray methodSignature() const;
0023     QByteArray name() const;
0024     const char *typeName() const;
0025     int returnType() const;
0026     QMetaType returnMetaType() const;
0027     int parameterCount() const;
0028     int parameterType(int index) const;
0029     QMetaType parameterMetaType(int index) const;
0030     void getParameterTypes(int *types) const;
0031     QList<QByteArray> parameterTypes() const;
0032     QByteArray parameterTypeName(int index) const;
0033     QList<QByteArray> parameterNames() const;
0034     const char *tag() const;
0035     enum Access { Private, Protected, Public };
0036     Access access() const;
0037     enum MethodType { Method, Signal, Slot, Constructor };
0038     MethodType methodType() const;
0039     enum Attributes { Compatibility = 0x1, Cloned = 0x2, Scriptable = 0x4 };
0040     int attributes() const;
0041     int methodIndex() const;
0042     int relativeMethodIndex() const;
0043     int revision() const;
0044     bool isConst() const;
0045 
0046     inline const QMetaObject *enclosingMetaObject() const { return mobj; }
0047 
0048 #if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
0049     bool invoke(QObject *object,
0050                 Qt::ConnectionType connectionType,
0051                 QGenericReturnArgument returnValue,
0052                 QGenericArgument val0 = QGenericArgument(nullptr),
0053                 QGenericArgument val1 = QGenericArgument(),
0054                 QGenericArgument val2 = QGenericArgument(),
0055                 QGenericArgument val3 = QGenericArgument(),
0056                 QGenericArgument val4 = QGenericArgument(),
0057                 QGenericArgument val5 = QGenericArgument(),
0058                 QGenericArgument val6 = QGenericArgument(),
0059                 QGenericArgument val7 = QGenericArgument(),
0060                 QGenericArgument val8 = QGenericArgument(),
0061                 QGenericArgument val9 = QGenericArgument()) const;
0062     inline bool invoke(QObject *object,
0063                        QGenericReturnArgument returnValue,
0064                        QGenericArgument val0 = QGenericArgument(nullptr),
0065                        QGenericArgument val1 = QGenericArgument(),
0066                        QGenericArgument val2 = QGenericArgument(),
0067                        QGenericArgument val3 = QGenericArgument(),
0068                        QGenericArgument val4 = QGenericArgument(),
0069                        QGenericArgument val5 = QGenericArgument(),
0070                        QGenericArgument val6 = QGenericArgument(),
0071                        QGenericArgument val7 = QGenericArgument(),
0072                        QGenericArgument val8 = QGenericArgument(),
0073                        QGenericArgument val9 = QGenericArgument()) const
0074     {
0075         return invoke(object, Qt::AutoConnection, returnValue,
0076                       val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
0077     }
0078     inline bool invoke(QObject *object,
0079                        Qt::ConnectionType connectionType,
0080                        QGenericArgument val0,
0081                        QGenericArgument val1 = QGenericArgument(),
0082                        QGenericArgument val2 = QGenericArgument(),
0083                        QGenericArgument val3 = QGenericArgument(),
0084                        QGenericArgument val4 = QGenericArgument(),
0085                        QGenericArgument val5 = QGenericArgument(),
0086                        QGenericArgument val6 = QGenericArgument(),
0087                        QGenericArgument val7 = QGenericArgument(),
0088                        QGenericArgument val8 = QGenericArgument(),
0089                        QGenericArgument val9 = QGenericArgument()) const
0090     {
0091         return invoke(object, connectionType, QGenericReturnArgument(),
0092                       val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
0093     }
0094     inline bool invoke(QObject *object,
0095                        QGenericArgument val0,
0096                        QGenericArgument val1 = QGenericArgument(),
0097                        QGenericArgument val2 = QGenericArgument(),
0098                        QGenericArgument val3 = QGenericArgument(),
0099                        QGenericArgument val4 = QGenericArgument(),
0100                        QGenericArgument val5 = QGenericArgument(),
0101                        QGenericArgument val6 = QGenericArgument(),
0102                        QGenericArgument val7 = QGenericArgument(),
0103                        QGenericArgument val8 = QGenericArgument(),
0104                        QGenericArgument val9 = QGenericArgument()) const
0105     {
0106         return invoke(object, Qt::AutoConnection, QGenericReturnArgument(),
0107                       val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
0108     }
0109     bool invokeOnGadget(void *gadget,
0110                         QGenericReturnArgument returnValue,
0111                         QGenericArgument val0 = QGenericArgument(nullptr),
0112                         QGenericArgument val1 = QGenericArgument(),
0113                         QGenericArgument val2 = QGenericArgument(),
0114                         QGenericArgument val3 = QGenericArgument(),
0115                         QGenericArgument val4 = QGenericArgument(),
0116                         QGenericArgument val5 = QGenericArgument(),
0117                         QGenericArgument val6 = QGenericArgument(),
0118                         QGenericArgument val7 = QGenericArgument(),
0119                         QGenericArgument val8 = QGenericArgument(),
0120                         QGenericArgument val9 = QGenericArgument()) const;
0121     inline bool invokeOnGadget(void *gadget,
0122                                QGenericArgument val0,
0123                                QGenericArgument val1 = QGenericArgument(),
0124                                QGenericArgument val2 = QGenericArgument(),
0125                                QGenericArgument val3 = QGenericArgument(),
0126                                QGenericArgument val4 = QGenericArgument(),
0127                                QGenericArgument val5 = QGenericArgument(),
0128                                QGenericArgument val6 = QGenericArgument(),
0129                                QGenericArgument val7 = QGenericArgument(),
0130                                QGenericArgument val8 = QGenericArgument(),
0131                                QGenericArgument val9 = QGenericArgument()) const
0132     {
0133         return invokeOnGadget(gadget, QGenericReturnArgument(),
0134                               val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
0135     }
0136 #endif
0137 
0138     template <typename ReturnArg, typename... Args>
0139 #ifdef Q_QDOC
0140     bool
0141 #else
0142     QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0143 #endif
0144     invoke(QObject *obj, Qt::ConnectionType c, QTemplatedMetaMethodReturnArgument<ReturnArg> r,
0145            Args &&... arguments) const
0146     {
0147         auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...);
0148         return invokeImpl(*this, obj, c, h.parameterCount(), h.parameters.data(),
0149                           h.typeNames.data(), h.metaTypes.data());
0150     }
0151 
0152     template <typename... Args>
0153 #ifdef Q_QDOC
0154     bool
0155 #else
0156     QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0157 #endif
0158     invoke(QObject *obj, Qt::ConnectionType c, Args &&... arguments) const
0159     {
0160         return invoke(obj, c, QTemplatedMetaMethodReturnArgument<void>{}, std::forward<Args>(arguments)...);
0161     }
0162 
0163     template <typename ReturnArg, typename... Args>
0164 #ifdef Q_QDOC
0165     bool
0166 #else
0167     QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0168 #endif
0169     invoke(QObject *obj, QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments) const
0170     {
0171         return invoke(obj, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
0172     }
0173 
0174     template <typename... Args>
0175 #ifdef Q_QDOC
0176     bool
0177 #else
0178     QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0179 #endif
0180     invoke(QObject *obj, Args &&... arguments) const
0181     {
0182         return invoke(obj, Qt::AutoConnection, std::forward<Args>(arguments)...);
0183     }
0184 
0185     template <typename ReturnArg, typename... Args>
0186 #ifdef Q_QDOC
0187     bool
0188 #else
0189     QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0190 #endif
0191     invokeOnGadget(void *gadget, QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments) const
0192     {
0193         auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...);
0194         return invokeImpl(*this, gadget, Qt::ConnectionType(-1), h.parameterCount(),
0195                           h.parameters.data(), h.typeNames.data(), h.metaTypes.data());
0196     }
0197 
0198     template <typename... Args>
0199 #ifdef Q_QDOC
0200     bool
0201 #else
0202     QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0203 #endif
0204     invokeOnGadget(void *gadget, Args &&... arguments) const
0205     {
0206         return invokeOnGadget(gadget, QTemplatedMetaMethodReturnArgument<void>{}, std::forward<Args>(arguments)...);
0207     }
0208 
0209     inline bool isValid() const { return mobj != nullptr; }
0210 
0211     template <typename PointerToMemberFunction>
0212     static inline QMetaMethod fromSignal(PointerToMemberFunction signal)
0213     {
0214         typedef QtPrivate::FunctionPointer<PointerToMemberFunction> SignalType;
0215         static_assert(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value,
0216                       "No Q_OBJECT in the class with the signal");
0217         return fromSignalImpl(&SignalType::Object::staticMetaObject,
0218                               reinterpret_cast<void **>(&signal));
0219     }
0220 
0221 private:
0222     static bool invokeImpl(QMetaMethod self, void *target, Qt::ConnectionType, qsizetype paramCount,
0223                            const void *const *parameters, const char *const *typeNames,
0224                            const QtPrivate::QMetaTypeInterface *const *metaTypes);
0225     static QMetaMethod fromSignalImpl(const QMetaObject *, void **);
0226     static QMetaMethod fromRelativeMethodIndex(const QMetaObject *mobj, int index);
0227     static QMetaMethod fromRelativeConstructorIndex(const QMetaObject *mobj, int index);
0228 
0229 protected:
0230     struct Data {
0231         enum { Size = 6 };
0232 
0233         uint name() const { return d[0]; }
0234         uint argc() const { return d[1]; }
0235         uint parameters() const { return d[2]; }
0236         uint tag() const { return d[3]; }
0237         uint flags() const { return d[4]; }
0238         uint metaTypeOffset() const { return d[5]; }
0239         bool operator==(const Data &other) const { return d == other.d; }
0240 
0241         const uint *d;
0242     };
0243 private:
0244     constexpr QMetaMethod(const QMetaObject *metaObject, const Data &data_)
0245         : mobj(metaObject), data(data_)
0246     {}
0247 protected:
0248 
0249     const QMetaObject *mobj;
0250     Data data;
0251     friend struct QMetaObject;
0252     friend struct QMetaObjectPrivate;
0253     friend class QObject;
0254     friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) noexcept
0255     { return m1.data == m2.data; }
0256     friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) noexcept
0257     { return !(m1 == m2); }
0258 };
0259 Q_DECLARE_TYPEINFO(QMetaMethod, Q_RELOCATABLE_TYPE);
0260 
0261 class Q_CORE_EXPORT QMetaEnum
0262 {
0263 public:
0264     constexpr inline QMetaEnum() : mobj(nullptr), data({ nullptr }) {}
0265 
0266     const char *name() const;
0267     const char *enumName() const;
0268     QMetaType metaType() const;
0269 
0270     bool isFlag() const;
0271     bool isScoped() const;
0272 
0273     int keyCount() const;
0274     const char *key(int index) const;
0275     int value(int index) const;
0276 
0277     const char *scope() const;
0278 
0279     int keyToValue(const char *key, bool *ok = nullptr) const;
0280     const char *valueToKey(int value) const;
0281     int keysToValue(const char *keys, bool *ok = nullptr) const;
0282     QByteArray valueToKeys(int value) const;
0283 
0284     inline const QMetaObject *enclosingMetaObject() const { return mobj; }
0285 
0286     inline bool isValid() const { return name() != nullptr; }
0287 
0288     template<typename T>
0289     static QMetaEnum fromType()
0290     {
0291         static_assert(QtPrivate::IsQEnumHelper<T>::Value,
0292                       "QMetaEnum::fromType only works with enums declared as "
0293                       "Q_ENUM, Q_ENUM_NS, Q_FLAG or Q_FLAG_NS");
0294         const QMetaObject *metaObject = qt_getEnumMetaObject(T());
0295         const char *name = qt_getEnumName(T());
0296         return metaObject->enumerator(metaObject->indexOfEnumerator(name));
0297     }
0298 
0299 private:
0300     struct Data {
0301         enum { Size = 5 };
0302         quint32 name() const { return d[0]; }
0303         quint32 alias() const { return d[1]; }
0304         quint32 flags() const { return d[2]; }
0305         qint32 keyCount() const { return static_cast<qint32>(d[3]); }
0306         quint32 data() const { return d[4]; }
0307         int index(const QMetaObject *mobj) const;
0308 
0309         const uint *d;
0310     };
0311 
0312     QMetaEnum(const QMetaObject *mobj, int index);
0313 
0314     const QMetaObject *mobj;
0315     Data data;
0316     friend struct QMetaObject;
0317     friend struct QMetaObjectPrivate;
0318 };
0319 Q_DECLARE_TYPEINFO(QMetaEnum, Q_RELOCATABLE_TYPE);
0320 
0321 class Q_CORE_EXPORT QMetaProperty
0322 {
0323 public:
0324     constexpr QMetaProperty() : mobj(nullptr), data({ nullptr }) {}
0325 
0326     const char *name() const;
0327     const char *typeName() const;
0328 #if QT_DEPRECATED_SINCE(6, 0)
0329     QT_WARNING_PUSH
0330     QT_WARNING_DISABLE_DEPRECATED
0331     QT_DEPRECATED_VERSION_6_0
0332     QVariant::Type type() const
0333     { int t = userType(); return t >= QMetaType::User ? QVariant::UserType : QVariant::Type(t); }
0334     QT_WARNING_POP
0335 #endif
0336     int userType() const { return typeId(); }
0337     int typeId() const { return metaType().id(); }
0338     QMetaType metaType() const;
0339     int propertyIndex() const;
0340     int relativePropertyIndex() const;
0341 
0342     bool isReadable() const;
0343     bool isWritable() const;
0344     bool isResettable() const;
0345     bool isDesignable() const;
0346     bool isScriptable() const;
0347     bool isStored() const;
0348     bool isUser() const;
0349     bool isConstant() const;
0350     bool isFinal() const;
0351     bool isRequired() const;
0352     bool isBindable() const;
0353 
0354     bool isFlagType() const;
0355     bool isEnumType() const;
0356     QMetaEnum enumerator() const;
0357 
0358     bool hasNotifySignal() const;
0359     QMetaMethod notifySignal() const;
0360     int notifySignalIndex() const;
0361 
0362     int revision() const;
0363 
0364     QVariant read(const QObject *obj) const;
0365     bool write(QObject *obj, const QVariant &value) const;
0366     bool write(QObject *obj, QVariant &&value) const;
0367     bool reset(QObject *obj) const;
0368 
0369     QUntypedBindable bindable(QObject *object) const;
0370 
0371     QVariant readOnGadget(const void *gadget) const;
0372     bool writeOnGadget(void *gadget, const QVariant &value) const;
0373     bool writeOnGadget(void *gadget, QVariant &&value) const;
0374     bool resetOnGadget(void *gadget) const;
0375 
0376     bool hasStdCppSet() const;
0377     bool isAlias() const;
0378     inline bool isValid() const { return isReadable(); }
0379     inline const QMetaObject *enclosingMetaObject() const { return mobj; }
0380 
0381 private:
0382 #if QT_DEPRECATED_SINCE(6, 4)
0383     QT_DEPRECATED_VERSION_X_6_4("obsolete, simply returns typeId()")
0384     int registerPropertyType() const;
0385 #endif
0386 
0387     struct Data {
0388         enum { Size = 5 };
0389 
0390         uint name() const { return d[0]; }
0391         uint type() const { return d[1]; }
0392         uint flags() const { return d[2]; }
0393         uint notifyIndex() const { return d[3]; }
0394         uint revision() const { return d[4]; }
0395 
0396         int index(const QMetaObject *mobj) const;
0397 
0398         const uint *d;
0399     };
0400 
0401     QMetaProperty(const QMetaObject *mobj, int index);
0402     static Data getMetaPropertyData(const QMetaObject *mobj, int index);
0403 
0404     const QMetaObject *mobj;
0405     Data data;
0406     QMetaEnum menum;
0407     friend struct QMetaObject;
0408     friend struct QMetaObjectPrivate;
0409 };
0410 
0411 class Q_CORE_EXPORT QMetaClassInfo
0412 {
0413 public:
0414     constexpr inline QMetaClassInfo() : mobj(nullptr), data({ nullptr }) {}
0415     const char *name() const;
0416     const char *value() const;
0417     inline const QMetaObject *enclosingMetaObject() const { return mobj; }
0418 
0419 private:
0420     struct Data {
0421         enum { Size = 2 };
0422 
0423         uint name() const { return d[0]; }
0424         uint value() const { return d[1]; }
0425 
0426         const uint *d;
0427     };
0428 
0429     const QMetaObject *mobj;
0430     Data data;
0431     friend struct QMetaObject;
0432 };
0433 Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_RELOCATABLE_TYPE);
0434 
0435 QT_END_NAMESPACE
0436 
0437 #endif // QMETAOBJECT_H