diff options
Diffstat (limited to 'src/corelib/kernel/qmetaobject.h')
-rw-r--r-- | src/corelib/kernel/qmetaobject.h | 184 |
1 files changed, 123 insertions, 61 deletions
diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index 08c57d5f28..91f287a8d3 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -1,47 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QMETAOBJECT_H #define QMETAOBJECT_H #include <QtCore/qobjectdefs.h> +#include <QtCore/qcompare.h> #include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE @@ -77,9 +42,11 @@ public: int methodIndex() const; int relativeMethodIndex() const; int revision() const; + bool isConst() const; inline const QMetaObject *enclosingMetaObject() const { return mobj; } +#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0) bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, @@ -111,7 +78,7 @@ public: } inline bool invoke(QObject *object, Qt::ConnectionType connectionType, - QGenericArgument val0 = QGenericArgument(nullptr), + QGenericArgument val0, QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), @@ -126,7 +93,7 @@ public: val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); } inline bool invoke(QObject *object, - QGenericArgument val0 = QGenericArgument(nullptr), + QGenericArgument val0, QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), @@ -153,7 +120,7 @@ public: QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument()) const; inline bool invokeOnGadget(void *gadget, - QGenericArgument val0 = QGenericArgument(nullptr), + QGenericArgument val0, QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), @@ -167,6 +134,78 @@ public: return invokeOnGadget(gadget, QGenericReturnArgument(), val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); } +#endif + + template <typename ReturnArg, typename... Args> +#ifdef Q_QDOC + bool +#else + QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...> +#endif + invoke(QObject *obj, Qt::ConnectionType c, QTemplatedMetaMethodReturnArgument<ReturnArg> r, + Args &&... arguments) const + { + auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...); + return invokeImpl(*this, obj, c, h.parameterCount(), h.parameters.data(), + h.typeNames.data(), h.metaTypes.data()); + } + + template <typename... Args> +#ifdef Q_QDOC + bool +#else + QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...> +#endif + invoke(QObject *obj, Qt::ConnectionType c, Args &&... arguments) const + { + return invoke(obj, c, QTemplatedMetaMethodReturnArgument<void>{}, std::forward<Args>(arguments)...); + } + + template <typename ReturnArg, typename... Args> +#ifdef Q_QDOC + bool +#else + QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...> +#endif + invoke(QObject *obj, QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments) const + { + return invoke(obj, Qt::AutoConnection, r, std::forward<Args>(arguments)...); + } + + template <typename... Args> +#ifdef Q_QDOC + bool +#else + QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...> +#endif + invoke(QObject *obj, Args &&... arguments) const + { + return invoke(obj, Qt::AutoConnection, std::forward<Args>(arguments)...); + } + + template <typename ReturnArg, typename... Args> +#ifdef Q_QDOC + bool +#else + QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...> +#endif + invokeOnGadget(void *gadget, QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments) const + { + auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...); + return invokeImpl(*this, gadget, Qt::ConnectionType(-1), h.parameterCount(), + h.parameters.data(), h.typeNames.data(), h.metaTypes.data()); + } + + template <typename... Args> +#ifdef Q_QDOC + bool +#else + QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...> +#endif + invokeOnGadget(void *gadget, Args &&... arguments) const + { + return invokeOnGadget(gadget, QTemplatedMetaMethodReturnArgument<void>{}, std::forward<Args>(arguments)...); + } inline bool isValid() const { return mobj != nullptr; } @@ -175,16 +214,20 @@ public: { typedef QtPrivate::FunctionPointer<PointerToMemberFunction> SignalType; static_assert(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value, - "No Q_OBJECT in the class with the signal"); + "No Q_OBJECT in the class with the signal"); return fromSignalImpl(&SignalType::Object::staticMetaObject, reinterpret_cast<void **>(&signal)); } private: + static bool invokeImpl(QMetaMethod self, void *target, Qt::ConnectionType, qsizetype paramCount, + const void *const *parameters, const char *const *typeNames, + const QtPrivate::QMetaTypeInterface *const *metaTypes); static QMetaMethod fromSignalImpl(const QMetaObject *, void **); static QMetaMethod fromRelativeMethodIndex(const QMetaObject *mobj, int index); static QMetaMethod fromRelativeConstructorIndex(const QMetaObject *mobj, int index); +protected: struct Data { enum { Size = 6 }; @@ -198,25 +241,24 @@ private: const uint *d; }; +private: constexpr QMetaMethod(const QMetaObject *metaObject, const Data &data_) : mobj(metaObject), data(data_) {} +protected: const QMetaObject *mobj; Data data; - 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.data == m2.data; } -inline bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) -{ return !(m1 == m2); } +private: + friend bool comparesEqual(const QMetaMethod &lhs, const QMetaMethod &rhs) noexcept + { return lhs.data == rhs.data; } + Q_DECLARE_EQUALITY_COMPARABLE(QMetaMethod) +}; +Q_DECLARE_TYPEINFO(QMetaMethod, Q_RELOCATABLE_TYPE); class Q_CORE_EXPORT QMetaEnum { @@ -225,6 +267,8 @@ public: const char *name() const; const char *enumName() const; + QMetaType metaType() const; + bool isFlag() const; bool isScoped() const; @@ -235,18 +279,20 @@ public: const char *scope() const; int keyToValue(const char *key, bool *ok = nullptr) const; - const char* valueToKey(int value) const; - int keysToValue(const char * keys, bool *ok = nullptr) const; + const char *valueToKey(int value) const; + int keysToValue(const char *keys, bool *ok = nullptr) const; QByteArray valueToKeys(int value) const; inline const QMetaObject *enclosingMetaObject() const { return mobj; } inline bool isValid() const { return name() != nullptr; } - template<typename T> static QMetaEnum fromType() { + template<typename T> + static QMetaEnum fromType() + { static_assert(QtPrivate::IsQEnumHelper<T>::Value, - "QMetaEnum::fromType only works with enums declared as " - "Q_ENUM, Q_ENUM_NS, Q_FLAG or Q_FLAG_NS"); + "QMetaEnum::fromType only works with enums declared as " + "Q_ENUM, Q_ENUM_NS, Q_FLAG or Q_FLAG_NS"); const QMetaObject *metaObject = qt_getEnumMetaObject(T()); const char *name = qt_getEnumName(T()); return metaObject->enumerator(metaObject->indexOfEnumerator(name)); @@ -260,6 +306,7 @@ private: quint32 flags() const { return d[2]; } qint32 keyCount() const { return static_cast<qint32>(d[3]); } quint32 data() const { return d[4]; } + int index(const QMetaObject *mobj) const; const uint *d; }; @@ -271,7 +318,7 @@ private: friend struct QMetaObject; friend struct QMetaObjectPrivate; }; -Q_DECLARE_TYPEINFO(QMetaEnum, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QMetaEnum, Q_RELOCATABLE_TYPE); class Q_CORE_EXPORT QMetaProperty { @@ -280,8 +327,16 @@ public: const char *name() const; const char *typeName() const; - QVariant::Type type() const; - int userType() const; +#if QT_DEPRECATED_SINCE(6, 0) + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + QT_DEPRECATED_VERSION_6_0 + QVariant::Type type() const + { int t = userType(); return t >= QMetaType::User ? QVariant::UserType : QVariant::Type(t); } + QT_WARNING_POP +#endif + int userType() const { return typeId(); } + int typeId() const { return metaType().id(); } QMetaType metaType() const; int propertyIndex() const; int relativePropertyIndex() const; @@ -310,12 +365,14 @@ public: QVariant read(const QObject *obj) const; bool write(QObject *obj, const QVariant &value) const; + bool write(QObject *obj, QVariant &&value) const; bool reset(QObject *obj) const; QUntypedBindable bindable(QObject *object) const; QVariant readOnGadget(const void *gadget) const; bool writeOnGadget(void *gadget, const QVariant &value) const; + bool writeOnGadget(void *gadget, QVariant &&value) const; bool resetOnGadget(void *gadget) const; bool hasStdCppSet() const; @@ -324,7 +381,10 @@ public: inline const QMetaObject *enclosingMetaObject() const { return mobj; } private: +#if QT_DEPRECATED_SINCE(6, 4) + QT_DEPRECATED_VERSION_X_6_4("obsolete, simply returns typeId()") int registerPropertyType() const; +#endif struct Data { enum { Size = 5 }; @@ -341,6 +401,7 @@ private: }; QMetaProperty(const QMetaObject *mobj, int index); + static Data getMetaPropertyData(const QMetaObject *mobj, int index); const QMetaObject *mobj; Data data; @@ -356,6 +417,7 @@ public: const char *name() const; const char *value() const; inline const QMetaObject *enclosingMetaObject() const { return mobj; } + private: struct Data { enum { Size = 2 }; @@ -370,7 +432,7 @@ private: Data data; friend struct QMetaObject; }; -Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_RELOCATABLE_TYPE); QT_END_NAMESPACE |