1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2019 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtQml module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QQMLTYPE_P_H 41 #define QQMLTYPE_P_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <functional> 55 56 #include <private/qtqmlglobal_p.h> 57 #include <private/qqmlrefcount_p.h> 58 59 #include <QtQml/qqmlprivate.h> 60 #include <QtQml/qjsvalue.h> 61 62 #include <QtCore/qobject.h> 63 64 QT_BEGIN_NAMESPACE 65 66 class QHashedCStringRef; 67 class QQmlTypePrivate; 68 class QHashedString; 69 class QHashedStringRef; 70 class QQmlCustomParser; 71 class QQmlEnginePrivate; 72 class QQmlPropertyCache; 73 74 namespace QV4 { 75 struct String; 76 } 77 struct CompositeMetaTypeIds; 78 79 class Q_QML_PRIVATE_EXPORT QQmlType 80 { 81 public: 82 QQmlType(); 83 QQmlType(const QQmlType &other); 84 QQmlType(QQmlType &&other); 85 QQmlType &operator =(const QQmlType &other); 86 QQmlType &operator =(QQmlType &&other); 87 explicit QQmlType(const QQmlTypePrivate *priv); 88 ~QQmlType(); 89 90 bool operator ==(const QQmlType &other) const { 91 return d.data() == other.d.data(); 92 } 93 isValid()94 bool isValid() const { return !d.isNull(); } 95 96 QByteArray typeName() const; 97 QString qmlTypeName() const; 98 QString elementName() const; 99 100 QHashedString module() const; 101 int majorVersion() const; 102 int minorVersion() const; 103 104 bool availableInVersion(int vmajor, int vminor) const; 105 bool availableInVersion(const QHashedStringRef &module, int vmajor, int vminor) const; 106 107 QObject *create() const; 108 void create(QObject **, void **, size_t) const; 109 110 typedef void (*CreateFunc)(void *); 111 CreateFunc createFunction() const; 112 QQmlCustomParser *customParser() const; 113 114 bool isCreatable() const; 115 typedef QObject *(*ExtensionFunc)(QObject *); 116 ExtensionFunc extensionFunction() const; 117 bool isExtendedType() const; 118 QString noCreationReason() const; 119 120 bool isSingleton() const; 121 bool isInterface() const; 122 bool isComposite() const; 123 bool isCompositeSingleton() const; 124 bool isQObjectSingleton() const; 125 bool isQJSValueSingleton() const; 126 127 int typeId() const; 128 int qListTypeId() const; 129 130 const QMetaObject *metaObject() const; 131 const QMetaObject *baseMetaObject() const; 132 int metaObjectRevision() const; 133 bool containsRevisionedAttributes() const; 134 135 QQmlAttachedPropertiesFunc attachedPropertiesFunction(QQmlEnginePrivate *engine) const; 136 const QMetaObject *attachedPropertiesType(QQmlEnginePrivate *engine) const; 137 #if QT_DEPRECATED_SINCE(5, 14) 138 QT_DEPRECATED int attachedPropertiesId(QQmlEnginePrivate *engine) const; 139 #endif 140 141 int parserStatusCast() const; 142 const char *interfaceIId() const; 143 int propertyValueSourceCast() const; 144 int propertyValueInterceptorCast() const; 145 146 int index() const; 147 148 bool isInlineComponentType() const; 149 int inlineComponendId() const; 150 151 struct Q_QML_PRIVATE_EXPORT SingletonInstanceInfo 152 { 153 QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *) = nullptr; 154 std::function<QObject *(QQmlEngine *, QJSEngine *)> qobjectCallback = {}; 155 const QMetaObject *instanceMetaObject = nullptr; 156 QString typeName; 157 QUrl url; // used by composite singletons 158 }; 159 SingletonInstanceInfo *singletonInstanceInfo() const; 160 161 QUrl sourceUrl() const; 162 163 int enumValue(QQmlEnginePrivate *engine, const QHashedStringRef &, bool *ok) const; 164 int enumValue(QQmlEnginePrivate *engine, const QHashedCStringRef &, bool *ok) const; 165 int enumValue(QQmlEnginePrivate *engine, const QV4::String *, bool *ok) const; 166 167 int scopedEnumIndex(QQmlEnginePrivate *engine, const QV4::String *, bool *ok) const; 168 int scopedEnumIndex(QQmlEnginePrivate *engine, const QString &, bool *ok) const; 169 int scopedEnumValue(QQmlEnginePrivate *engine, int index, const QV4::String *, bool *ok) const; 170 int scopedEnumValue(QQmlEnginePrivate *engine, int index, const QString &, bool *ok) const; 171 int scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &, const QByteArray &, bool *ok) const; 172 int scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &, const QStringRef &, bool *ok) const; 173 int inlineComponentObjectId(); 174 void setInlineComponentObjectId(int id) const; // TODO: const setters are BAD 175 priv()176 const QQmlTypePrivate *priv() const { return d.data(); } 177 static void refHandle(const QQmlTypePrivate *priv); 178 static void derefHandle(const QQmlTypePrivate *priv); 179 static int refCount(const QQmlTypePrivate *priv); 180 181 enum RegistrationType { 182 CppType = 0, 183 SingletonType = 1, 184 InterfaceType = 2, 185 CompositeType = 3, 186 CompositeSingletonType = 4, 187 InlineComponentType = 5, 188 AnyRegistrationType = 255 189 }; 190 191 QQmlType containingType() const; 192 int lookupInlineComponentIdByName(const QString &name) const; 193 QQmlType lookupInlineComponentById(int objectid) const; 194 int generatePlaceHolderICId() const; 195 196 void associateInlineComponent(const QString &name, int objectID, const CompositeMetaTypeIds &metaTypeIds, QQmlType existingType); 197 void setPendingResolutionName(const QString &name); 198 QString pendingResolutionName() const; 199 200 private: 201 friend class QQmlTypePrivate; 202 friend uint qHash(const QQmlType &t, uint seed); 203 QQmlRefPointer<const QQmlTypePrivate> d; 204 }; 205 206 inline uint qHash(const QQmlType &t, uint seed = 0) 207 { 208 return qHash(reinterpret_cast<quintptr>(t.d.data()), seed); 209 } 210 211 QT_END_NAMESPACE 212 213 #endif // QQMLTYPE_P_H 214