summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetaobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qmetaobject.h')
-rw-r--r--src/corelib/kernel/qmetaobject.h195
1 files changed, 130 insertions, 65 deletions
diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h
index 20a5c67586..4e52e854d9 100644
--- a/src/corelib/kernel/qmetaobject.h
+++ b/src/corelib/kernel/qmetaobject.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** 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
@@ -46,12 +10,14 @@
QT_BEGIN_NAMESPACE
+class QUntypedBindable;
+
#define Q_METAMETHOD_INVOKE_MAX_ARGS 10
class Q_CORE_EXPORT QMetaMethod
{
public:
- Q_DECL_CONSTEXPR inline QMetaMethod() : mobj(nullptr), data({ nullptr }) {}
+ constexpr inline QMetaMethod() : mobj(nullptr), data({ nullptr }) {}
QByteArray methodSignature() const;
QByteArray name() const;
@@ -63,6 +29,7 @@ public:
QMetaType parameterMetaType(int index) const;
void getParameterTypes(int *types) const;
QList<QByteArray> parameterTypes() const;
+ QByteArray parameterTypeName(int index) const;
QList<QByteArray> parameterNames() const;
const char *tag() const;
enum Access { Private, Protected, Public };
@@ -74,9 +41,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,
@@ -108,7 +77,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(),
@@ -123,7 +92,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(),
@@ -150,7 +119,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(),
@@ -164,6 +133,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; }
@@ -172,16 +213,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 };
@@ -195,33 +240,33 @@ 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);
+ friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) noexcept
+ { return m1.data == m2.data; }
+ friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) noexcept
+ { return !(m1 == 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); }
+Q_DECLARE_TYPEINFO(QMetaMethod, Q_RELOCATABLE_TYPE);
class Q_CORE_EXPORT QMetaEnum
{
public:
- Q_DECL_CONSTEXPR inline QMetaEnum() : mobj(nullptr), data({ nullptr }) {}
+ constexpr inline QMetaEnum() : mobj(nullptr), data({ nullptr }) {}
const char *name() const;
const char *enumName() const;
+ QMetaType metaType() const;
+
bool isFlag() const;
bool isScoped() const;
@@ -232,18 +277,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));
@@ -257,6 +304,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;
};
@@ -268,7 +316,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
{
@@ -277,8 +325,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;
@@ -293,7 +349,7 @@ public:
bool isConstant() const;
bool isFinal() const;
bool isRequired() const;
- bool isQProperty() const;
+ bool isBindable() const;
bool isFlagType() const;
bool isEnumType() const;
@@ -307,10 +363,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;
@@ -319,7 +379,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 };
@@ -336,6 +399,7 @@ private:
};
QMetaProperty(const QMetaObject *mobj, int index);
+ static Data getMetaPropertyData(const QMetaObject *mobj, int index);
const QMetaObject *mobj;
Data data;
@@ -347,10 +411,11 @@ private:
class Q_CORE_EXPORT QMetaClassInfo
{
public:
- Q_DECL_CONSTEXPR inline QMetaClassInfo() : mobj(nullptr), data({ nullptr }) {}
+ constexpr inline QMetaClassInfo() : mobj(nullptr), data({ nullptr }) {}
const char *name() const;
const char *value() const;
inline const QMetaObject *enclosingMetaObject() const { return mobj; }
+
private:
struct Data {
enum { Size = 2 };
@@ -365,7 +430,7 @@ private:
Data data;
friend struct QMetaObject;
};
-Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_RELOCATABLE_TYPE);
QT_END_NAMESPACE