Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlprivate.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QQMLPRIVATE_H
6#define QQMLPRIVATE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQml/qjsprimitivevalue.h>
20#include <QtQml/qjsvalue.h>
21#include <QtQml/qqmllist.h>
22#include <QtQml/qqmlparserstatus.h>
23#include <QtQml/qqmlpropertyvaluesource.h>
24#include <QtQml/qtqmlglobal.h>
25
26#include <QtCore/qdatetime.h>
27#include <QtCore/qdebug.h>
28#include <QtCore/qglobal.h>
29#include <QtCore/qmetasequence.h>
30#include <QtCore/qmetaobject.h>
31#include <QtCore/qpointer.h>
32#include <QtCore/qurl.h>
33#include <QtCore/qtyperevision.h>
34#include <QtCore/qvariant.h>
35#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 3
36#include <QtCore/qversionnumber.h>
37#endif
38
39#include <functional>
40#include <limits>
41#include <type_traits>
42
43QT_BEGIN_NAMESPACE
44
45class QQmlPropertyValueInterceptor;
46class QQmlContextData;
47class QQmlFinalizerHook;
48
49namespace QQmlPrivate {
50struct CachedQmlUnit;
51template<typename A>
52using QQmlAttachedPropertiesFunc = A *(*)(QObject *);
53}
54
55namespace QV4 {
56struct ExecutionEngine;
57struct MarkStack;
58class ExecutableCompilationUnit;
59namespace CompiledData {
60struct Unit;
61}
62}
63namespace QmlIR {
64struct Document;
65typedef void (*IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *);
66}
67
68using QQmlAttachedPropertiesFunc = QQmlPrivate::QQmlAttachedPropertiesFunc<QObject>;
69
70inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
71{
72 return qHash(quintptr(func), seed);
73}
74
75template <typename TYPE>
77{
78public:
79 enum {
81 };
82};
83
84
85class QJSEngine;
86class QQmlEngine;
87class QQmlCustomParser;
89
90class QQmlV4Function;
92using QQmlV4ExecutionEnginePtr = QV4::ExecutionEngine *;
93
94template<class T>
95QQmlCustomParser *qmlCreateCustomParser()
96{
97 return nullptr;
98}
99
100namespace QQmlPrivate
101{
103 template<typename T>
104 class QQmlElement final : public T
105 {
106 public:
107 // Not defaulted so that it can be specialized
109
110 ~QQmlElement() override {
111 QQmlPrivate::qdeclarativeelement_destructor(this);
112 }
113 static void operator delete(void *ptr) {
114 // We allocate memory from this class in QQmlType::create
115 // along with some additional memory.
116 // So we override the operator delete in order to avoid the
117 // sized operator delete to be called with a different size than
118 // the size that was allocated.
119 ::operator delete (ptr);
120 }
121#ifdef Q_CC_MSVC
122 static void operator delete(void *, void *) {
123 // Deliberately empty placement delete operator.
124 // Silences MSVC warning C4291: no matching operator delete found
125 // On MinGW it causes -Wmismatched-new-delete, though.
126 }
127#endif
128 };
129
138
139 template<typename T, typename WrapperT = T, typename = std::void_t<>>
141 {
142 static constexpr bool value = false;
143 };
144
145 template<typename T, typename WrapperT>
147 static_cast<QQmlEngine *>(nullptr),
148 static_cast<QJSEngine *>(nullptr)))>>
149 {
150 static constexpr bool value = std::is_same_v<
151 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
152 static_cast<QJSEngine *>(nullptr))), T *>;
153 };
154
155 template<typename>
157
158 template<typename Ret, typename Class>
159 struct QmlMarkerFunction<Ret (Class::*)()>
160 {
161 using ClassType = Class;
162 };
163
164 template<typename T, typename Marker>
165 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
166
167 template<class T>
169 {
170 private:
171 template<class U>
172 static auto test(int) -> std::enable_if_t<
173 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_uncreatable)>::value
174 && bool(U::QmlIsUncreatable::yes),
175 std::true_type>;
176
177 template<class U>
178 static auto test(...) -> std::false_type;
179
180 public:
181 static constexpr bool Value = decltype(test<T>(0))::value;
182 };
183
184 template<typename T, typename WrapperT>
186 {
187 if constexpr (!std::is_base_of<QObject, T>::value)
189 if constexpr (QmlUncreatable<WrapperT>::Value)
191 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
193 if constexpr (std::is_default_constructible<T>::value)
195 if constexpr (HasSingletonFactory<T>::value)
197
199 }
200
201 template<typename T>
202 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
203
204 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
206 {
207 Q_UNUSED(q);
208 Q_UNUSED(j);
209 if constexpr (Mode == SingletonConstructionMode::Constructor)
210 return new T;
211 else if constexpr (Mode == SingletonConstructionMode::Factory)
212 return T::create(q, j);
213 else if constexpr (Mode == SingletonConstructionMode::FactoryWrapper)
214 return WrapperT::create(q, j);
215 else
216 return nullptr;
217 }
218
219 template<typename T>
220 QObject *createParent(QObject *p) { return new T(p); }
221
222 using CreateIntoFunction = void (*)(void *, void *);
226
227 template<typename T, typename WrapperT = T,
228 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
230
231 template<typename T, typename WrapperT>
233 {
235 = QQmlPrivate::createInto<T>;
237 = QQmlPrivate::createSingletonInstance<
239 };
240
241 template<typename T, typename WrapperT>
243 {
244 static constexpr CreateIntoFunction createInto = nullptr;
246 };
247
248 template<typename T, typename WrapperT>
250 {
251 static constexpr CreateIntoFunction createInto = nullptr;
253 = QQmlPrivate::createSingletonInstance<
255 };
256
257 template<typename T, typename WrapperT>
259 {
260 static constexpr CreateIntoFunction createInto = nullptr;
262 = QQmlPrivate::createSingletonInstance<
264 };
265
266 template<typename T, typename WrapperT>
268 {
269 static constexpr CreateIntoFunction createInto = nullptr;
271 = QQmlPrivate::createSingletonInstance<
273 };
274
275 template<typename T,
279
280 template<typename T>
281 struct ExtendedType<T, false, false>
282 {
283 static constexpr const CreateParentFunction createParent = nullptr;
284 static const QMetaObject *staticMetaObject() { return nullptr; }
285 };
286
287 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
288 template<typename T>
289 struct ExtendedType<T, true, false>
290 {
292 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
293 };
294
295 // If it's a Q_GADGET, we don't want the ctor.
296 template<typename T>
297 struct ExtendedType<T, false, true>
298 {
299 static constexpr const CreateParentFunction createParent = nullptr;
300 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
301 };
302
303 template<typename F, typename Result = void>
305 {
306 static constexpr const Result (*create)(const QJSValue &) = nullptr;
307 };
308
309 template<typename F>
310 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
311 {
312 static decltype(F::create(QJSValue())) create(const QJSValue &params)
313 {
314 return F::create(params);
315 }
316 };
317
318 template<typename T, typename F,
319 bool HasCtor = std::is_constructible_v<T, QJSValue>,
320 bool HasFactory = std::is_constructible_v<
321 QVariant, decltype(ValueTypeFactory<F>::create(QJSValue()))>>
322 struct ValueType;
323
324 template<typename T, typename F>
325 struct ValueType<T, F, false, false>
326 {
327 static constexpr const CreateValueTypeFunction create = nullptr;
328 };
329
330 template<typename T, typename F, bool HasCtor>
331 struct ValueType<T, F, HasCtor, true>
332 {
333 static QVariant create(const QJSValue &params)
334 {
335 return F::create(params);
336 }
337 };
338
339 template<typename T, typename F>
340 struct ValueType<T, F, true, false>
341 {
342 static QVariant create(const QJSValue &params)
343 {
344 return QVariant::fromValue(T(params));
345 }
346 };
347
348 template<class From, class To, int N>
350 {
351 static inline int cast() { return -1; }
352 };
353
354 template<class From, class To>
355 struct StaticCastSelectorClass<From, To, sizeof(int)>
356 {
357 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
358 };
359
360 template<class From, class To>
362 {
363 typedef int yes_type;
364 typedef char no_type;
365
366 static yes_type checkType(To *);
367 static no_type checkType(...);
368
369 static inline int cast()
370 {
371 return StaticCastSelectorClass<From, To, sizeof(checkType(reinterpret_cast<From *>(0)))>::cast();
372 }
373 };
374
375 // You can prevent subclasses from using the same attached type by specialzing this.
376 // This is reserved for internal types, though.
377 template<class T, class A>
379 {
380 using Type = A;
381 };
382
383 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
385 {
386 using Type = void;
388 static const QMetaObject *staticMetaObject() { return nullptr; }
389 static Func attachedPropertiesFunc() { return nullptr; }
390 };
391
392 // Defined inline via QML_ATTACHED
393 template<class T>
394 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
395 {
396 // Normal attached properties
397 template <typename Parent, typename Attached>
404
405 // Disabled via OverridableAttachedType
406 template<typename Parent>
407 struct Properties<Parent, void>
408 {
410 static const QMetaObject *staticMetaObject() { return nullptr; }
411 static Func attachedPropertiesFunc() { return nullptr; }
412 };
413
414 using Type = typename std::conditional<
416 typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type, void>::type;
417 using Func = typename Properties<T, Type>::Func;
418
420 {
421 return Properties<T, Type>::staticMetaObject();
422 }
423
425 {
427 }
428 };
429
430 // Separately defined via QQmlTypeInfo
431 template<class T>
432 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
433 {
434 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
436
437 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
439 };
440
441 // This is necessary because both the type containing a default template parameter and the type
442 // instantiating the template need to have access to the default template parameter type. In
443 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
444 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
445 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
446 // struct "fixes" that. For convenience we still want the free standing functions in addition.
447 template<class T>
449 {
451 {
452 return QQmlAttachedPropertiesFunc<QObject>(QmlAttached<T>::attachedPropertiesFunc());
453 }
454
456 {
457 return QmlAttached<T>::staticMetaObject();
458 }
459 };
460
461 template<typename T>
463 {
464 return QmlAttachedAccessor<T>::attachedPropertiesFunc();
465 }
466
467 template<typename T>
469 {
470 return QmlAttachedAccessor<T>::staticMetaObject();
471 }
472
474 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
475
477
485
486 bool has(StructVersion v) const { return structVersion >= int(v); }
487
489
493 // The second parameter of create is for userdata
494 void (*create)(void *, void *);
495 void *userdata;
497
498 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
499 QVariant (*createValueType)(const QJSValue &);
500
501 const char *uri;
503 const char *elementName;
505
508
512
515
516 QQmlCustomParser *customParser;
517
520
522 // If this is extended ensure "version" is bumped!!!
523 };
524
559
571
574
575 AutoParentFunction function;
576 };
577
596
614
622
630
633 const char *uri;
635
636 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
637 // and that's automatic.
638 const char *typeName;
639
643 };
644
656
658 {
659 virtual ~AOTTrackedLocalsStorage() = default;
660 virtual void markObjects(QV4::MarkStack *markStack) const = 0;
661 };
662
663 struct Q_QML_EXPORT AOTCompiledContext {
665
669 union {
672 };
673
674 QObject *thisObject() const;
675 QQmlEngine *qmlEngine() const;
676
677 QJSValue jsMetaType(int index) const;
678 void setInstructionPointer(int offset) const;
679 void setLocals(const AOTTrackedLocalsStorage *locals) const;
680 void setReturnValueUndefined() const;
681
682 static void mark(QObject *object, QV4::MarkStack *markStack);
683 static void mark(const QVariant &variant, QV4::MarkStack *markStack);
684 template<typename T>
685 static void mark(T, QV4::MarkStack *) {}
686
687 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
688 bool captureLookup(uint index, QObject *object) const;
690 void captureTranslation() const;
693 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
695
697
698 void writeToConsole(
700 const QLoggingCategory *loggingCategory) const;
701
704 int ctorIndex, void **args) const;
705#if QT_QML_REMOVED_SINCE(6, 9)
708 int ctorIndex, void *ctorArg) const;
709#endif
710
711 // Those are explicit arguments to the Date() ctor, not implicit coercions.
720
722 double year, double month, double day = 1,
723 double hours = 0, double minutes = 0, double seconds = 0, double msecs = 0) const;
724
725 // All of these lookup functions should be used as follows:
726 //
727 // while (!fooBarLookup(...)) {
728 // setInstructionPointer(...);
729 // initFooBarLookup(...);
730 // if (engine->hasException()) {
731 // ...
732 // break;
733 // }
734 // }
735 //
736 // The bool-returning *Lookup functions exclusively run the happy path and return false if
737 // that fails in any way. The failure may either be in the lookup structs not being
738 // initialized or an exception being thrown.
739 // The init*Lookup functions initialize the lookup structs and amend any exceptions
740 // previously thrown with line numbers. They might also throw their own exceptions. If an
741 // exception is present after the initialization there is no way to carry out the lookup and
742 // the exception should be propagated. If not, the original lookup can be tried again.
743
744 bool callQmlContextPropertyLookup(uint index, void **args, int argc) const;
746
747#if QT_QML_REMOVED_SINCE(6, 9)
749 uint index, void **args, const QMetaType *types, int argc) const;
751#endif
752
753 bool loadContextIdLookup(uint index, void *target) const;
755
756 bool callObjectPropertyLookup(uint index, QObject *object, void **args, int argc) const;
760
761#if QT_QML_REMOVED_SINCE(6, 9)
763 uint index, QObject *object, void **args, const QMetaType *types, int argc) const;
765
766 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
767 void initCallGlobalLookup(uint index) const;
768
769 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
770 void initLoadGlobalLookup(uint index) const;
771#endif
772
773 bool loadGlobalLookup(uint index, void *target) const;
775
779#if QT_QML_REMOVED_SINCE(6, 9)
781#endif
782
783 bool loadSingletonLookup(uint index, void *target) const;
785
786 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
788
789 bool loadTypeLookup(uint index, void *target) const;
791
792 bool getObjectLookup(uint index, QObject *object, void *target) const;
796#if QT_QML_REMOVED_SINCE(6, 9)
798#endif
799
800 bool getValueLookup(uint index, void *value, void *target) const;
801 bool writeBackValueLookup(uint index, void *value, void *source) const;
803#if QT_QML_REMOVED_SINCE(6, 9)
805#endif
806
807 bool getEnumLookup(uint index, void *target) const;
808#if QT_QML_REMOVED_SINCE(6, 6)
809 bool getEnumLookup(uint index, int *target) const;
810#endif
812 const char *enumerator, const char *enumValue) const;
813
814 bool setObjectLookup(uint index, QObject *object, void *value) const;
817#if QT_QML_REMOVED_SINCE(6, 9)
819#endif
820
821 bool setValueLookup(uint index, void *target, void *value) const;
824#if QT_QML_REMOVED_SINCE(6, 9)
826#endif
827
828 bool callValueLookup(uint index, void *target, void **args, int argc) const;
831
838
840 {
841 // This does not cover everything you can possibly wrap into a QVariant.
842 // However, since we only _promise_ to handle single objects, this is OK.
844 return;
845
846 if (QObject *object = *static_cast<QObject *const *>(variant.constData()))
848 }
849
850 template<typename Value>
852 };
853
857 void (*signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes);
858 void (*functionPtr)(const AOTCompiledContext *context, void **argv);
859 };
860
861#if QT_DEPRECATED_SINCE(6, 6)
862 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
864#endif
865
871
872 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
875 QmlUnitCacheLookupFunction lookupCachedQmlUnit;
876 };
877
891
894
895#if QT_DEPRECATED_SINCE(6, 3)
897 {
900 bool alreadyCalled = false;
901 };
902#endif
903
904 struct Q_QML_EXPORT SingletonInstanceFunctor
905 {
907
909
910 // Not a QPointer, so that you cannot assign it to a different
911 // engine when the first one is deleted.
912 // That would mess up the QML contexts.
914 };
915
916 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
917 {
918 if (!metaObject || !key)
919 return -1;
920
921 const int offset = metaObject->classInfoOffset();
922 const int start = (startOffset == -1)
923 ? (metaObject->classInfoCount() + offset - 1)
924 : startOffset;
925 for (int i = start; i >= offset; --i)
926 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
927 return i;
928 }
929 return -1;
930 }
931
932 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
933 {
934 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
935 }
936
937 inline QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key,
938 QTypeRevision defaultValue = QTypeRevision())
939 {
940 const int index = indexOfOwnClassInfo(metaObject, key);
941 return (index == -1) ? defaultValue
942 : QTypeRevision::fromEncodedVersion(
943 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
944 }
945
947
948 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
949 bool defaultValue = false)
950 {
951 const int index = indexOfOwnClassInfo(metaObject, key);
952 if (index == -1)
953 return defaultValue;
954 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
955 }
956
957 // These detector classes are using a somehow "old school" SFINAE
958 // approach (overloaded test() functions, rather than void_t
959 // and similar more modern constructs) to avoid hitting GCC/MSVC
960 // bugs; be careful when refactoring these. In particular, make sure
961 // that they still work with private members even if you befriend
962 // the detector.
963
964 template<class T>
966 {
967 private:
968 template<class U>
969 static auto test(int) -> std::conditional_t<
970 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extended)>::value,
971 typename U::QmlExtendedType *,
972 void *
973 >;
974
975 template<class U>
976 static auto test(...) -> void *;
977
978 public:
979 // Some compilers complain if we have functions return abstract types.
980 // So we add pointers in the above, and remove the pointer here.
981 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
982 };
983
984 template<class T>
986 {
987 private:
988 template<class U>
989 static constexpr auto metaObjectImpl(int) ->
990 decltype((void)U::qmlExtendedNamespace(), static_cast<const QMetaObject *>(nullptr))
991 {
992 if constexpr (QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extendedNamespace)>::value)
993 return U::qmlExtendedNamespace();
994 else
995 return nullptr;
996 }
997
998 template<class U>
999 static constexpr auto metaObjectImpl(...) -> const QMetaObject *
1000 {
1001 return nullptr;
1002 }
1003
1004 public:
1005 static constexpr const QMetaObject *metaObject() { return metaObjectImpl<T>(0); }
1006 };
1007
1008 template<class T>
1010 {
1011 private:
1012 template<class U>
1013 static auto test(int) -> std::conditional_t<
1014 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_foreign)>::value,
1015 typename U::QmlForeignType *,
1016 U *
1017 >;
1018
1019 template<class U>
1020 static auto test(...) -> U *;
1021
1022 public:
1023 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
1024 };
1025
1026 template<class T>
1028 {
1029 private:
1030 template<class U>
1031 static auto test(int) -> std::enable_if_t<
1032 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_anonymous)>::value
1033 && bool(U::QmlIsAnonymous::yes),
1034 std::true_type
1035 >;
1036
1037 template<class U>
1038 static auto test(...) -> std::false_type;
1039
1040 public:
1041 static constexpr bool Value = decltype(test<T>(0))::value;
1042 };
1043
1044 template <class T>
1046 {
1047 private:
1048 template<class U>
1049 static auto test(int) -> std::enable_if_t<
1050 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_singleton)>::value
1051 && bool(U::QmlIsSingleton::yes),
1052 std::true_type
1053 >;
1054
1055 template<class U>
1056 static auto test(...) -> std::false_type;
1057
1058 public:
1059 static constexpr bool Value = decltype(test<T>(0))::value;
1060 };
1061
1062 template<class T>
1064 {
1065 private:
1066 template<class U>
1067 static auto test_impl(int) -> std::bool_constant<bool(U::QmlIsSequence::yes)>;
1068
1069 template<class U>
1070 static auto test_impl(...) -> std::false_type;
1071
1072 template<class U>
1073 static constexpr bool test() {
1074 if constexpr (decltype(test_impl<U>(0))::value) {
1075 static_assert((std::is_same_v<typename U::QmlSequenceValueType,
1076 typename QmlResolved<U>::Type::value_type>));
1077 return true;
1078 }
1079 return false;
1080 }
1081
1082 public:
1083 static constexpr bool Value = test<T>();
1084 };
1085
1086 template<class T>
1088 {
1089 private:
1090 template<class U>
1091 static auto test(int) ->
1092 decltype((void)qobject_interface_iid<U *>(), std::bool_constant<bool(U::QmlIsInterface::yes)>{});
1093
1094 template<class U>
1095 static auto test(...) -> std::false_type;
1096
1097 public:
1098 static constexpr bool Value = decltype(test<T>(0))::value;
1099 };
1100
1101 template<class T, typename = std::void_t<>>
1103 {
1104 static const QMetaObject *staticMetaObject() { return nullptr; }
1105 };
1106
1107 template<class T>
1109 {
1110 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
1111 };
1112
1113 template<class T>
1115 {
1116 static constexpr bool hasAcceptableCtors()
1117 {
1118 if constexpr (!std::is_default_constructible_v<T>)
1119 return false;
1120 else if constexpr (std::is_base_of_v<QObject, T>)
1121 return true;
1122 else
1123 return std::is_copy_constructible_v<T>;
1124 }
1125
1126 static constexpr QMetaType self()
1127 {
1128 if constexpr (std::is_base_of_v<QObject, T>)
1129 return QMetaType::fromType<T*>();
1130 else
1131 return QMetaType::fromType<T>();
1132 }
1133
1134 static constexpr QMetaType list()
1135 {
1136 if constexpr (std::is_base_of_v<QObject, T>)
1137 return QMetaType::fromType<QQmlListProperty<T>>();
1138 else
1139 return QMetaType::fromType<QList<T>>();
1140 }
1141
1142 static constexpr QMetaSequence sequence()
1143 {
1144 if constexpr (std::is_base_of_v<QObject, T>)
1145 return QMetaSequence();
1146 else
1147 return QMetaSequence::fromContainer<QList<T>>();
1148 }
1149
1150 static constexpr int size()
1151 {
1152 return sizeof(T);
1153 }
1154 };
1155
1156 template<>
1157 struct QmlMetaType<void>
1158 {
1159 static constexpr bool hasAcceptableCtors() { return true; }
1160 static constexpr QMetaType self() { return QMetaType(); }
1161 static constexpr QMetaType list() { return QMetaType(); }
1162 static constexpr QMetaSequence sequence() { return QMetaSequence(); }
1163 static constexpr int size() { return 0; }
1164 };
1165
1166 template<typename T, typename E, typename WrapperT = T>
1167 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1168 const QMetaObject *classInfoMetaObject,
1169 QList<int> *qmlTypeIds, const QMetaObject *extension)
1170 {
1171 static_assert(std::is_base_of_v<QObject, T>);
1173 0,
1174
1175 uri,
1176 QTypeRevision::fromMajorVersion(versionMajor),
1177
1178 Constructors<T, WrapperT>::createSingletonInstance,
1179
1180 StaticMetaObject<T>::staticMetaObject(),
1181 classInfoMetaObject,
1182
1183 QmlMetaType<T>::self(),
1184
1185 ExtendedType<E>::createParent,
1186 extension ? extension : ExtendedType<E>::staticMetaObject(),
1187
1188 qmlTypeIds
1189 };
1190
1191 qmlregister(SingletonAndRevisionsRegistration, &api);
1192 }
1193
1194 template<typename T, typename E>
1195 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1196 const QMetaObject *classInfoMetaObject,
1197 QList<int> *qmlTypeIds, const QMetaObject *extension,
1198 bool forceAnonymous = false)
1199 {
1201 3,
1202 QmlMetaType<T>::self(),
1203 QmlMetaType<T>::list(),
1204 QmlMetaType<T>::size(),
1205 Constructors<T>::createInto,
1206 nullptr,
1207 ValueType<T, E>::create,
1208
1209 uri,
1210 QTypeRevision::fromMajorVersion(versionMajor),
1211
1212 StaticMetaObject<T>::staticMetaObject(),
1213 classInfoMetaObject,
1214
1215 attachedPropertiesFunc<T>(),
1216 attachedPropertiesMetaObject<T>(),
1217
1218 StaticCastSelector<T, QQmlParserStatus>::cast(),
1219 StaticCastSelector<T, QQmlPropertyValueSource>::cast(),
1220 StaticCastSelector<T, QQmlPropertyValueInterceptor>::cast(),
1221
1222 ExtendedType<E>::createParent,
1223 extension ? extension : ExtendedType<E>::staticMetaObject(),
1224
1225 &qmlCreateCustomParser<T>,
1226 qmlTypeIds,
1227 StaticCastSelector<T, QQmlFinalizerHook>::cast(),
1228
1229 forceAnonymous,
1230 QmlMetaType<T>::sequence(),
1231 };
1232
1233 // Initialize the extension so that we can find it by name or ID.
1234 qMetaTypeId<E>();
1235
1236 qmlregister(TypeAndRevisionsRegistration, &type);
1237 }
1238
1239 template<typename T>
1240 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1241 const QMetaObject *classInfoMetaObject,
1242 QList<int> *qmlTypeIds)
1243 {
1245 0,
1246 uri,
1247 QTypeRevision::fromMajorVersion(versionMajor),
1248 classInfoMetaObject,
1249 QMetaType::fromType<T>(),
1250 QMetaSequence::fromContainer<T>(),
1251 qmlTypeIds
1252 };
1253
1255 }
1256
1257 template<>
1259 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1260 QList<int> *qmlTypeIds, const QMetaObject *, bool);
1261
1263 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1264 {
1265 return {
1266 /*.revision=*/ 0,
1267 /*.alignment=*/ 0,
1268 /*.size=*/ 0,
1269 /*.flags=*/ 0,
1270 /*.typeId=*/ QBasicAtomicInt(),
1271 /*.metaObject=*/ metaObjectFunction,
1272 /*.name=*/ name,
1273 /*.defaultCtr=*/ nullptr,
1274 /*.copyCtr=*/ nullptr,
1275 /*.moveCtr=*/ nullptr,
1276 /*.dtor=*/ nullptr,
1277 /*.equals*/ nullptr,
1278 /*.lessThan*/ nullptr,
1279 /*.debugStream=*/ nullptr,
1280 /*.dataStreamOut=*/ nullptr,
1281 /*.dataStreamIn=*/ nullptr,
1282 /*.legacyRegisterOp=*/ nullptr
1283 };
1284 }
1285
1286 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1287
1293
1294 Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type);
1295
1296 Q_QML_EXPORT QMetaType compositeMetaType(
1298 Q_QML_EXPORT QMetaType compositeMetaType(
1300 Q_QML_EXPORT QMetaType compositeListMetaType(
1302 Q_QML_EXPORT QMetaType compositeListMetaType(
1304
1305} // namespace QQmlPrivate
1306
1307QT_END_NAMESPACE
1308
1309Q_DECLARE_OPAQUE_POINTER(QQmlV4FunctionPtr)
1310Q_DECLARE_OPAQUE_POINTER(QQmlV4ExecutionEnginePtr)
1311
1312#endif // QQMLPRIVATE_H
void operator delete(void *)
friend class QJSEngine
static void operator delete(void *ptr)
@ hasAttachedProperties
Definition qqmlprivate.h:80
QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key, QTypeRevision defaultValue=QTypeRevision())
QObject * createParent(QObject *p)
A *(*)(QObject *) QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:52
constexpr QtPrivate::QMetaTypeInterface metaTypeForNamespace(const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
void(*)(void *, void *) CreateIntoFunction
std::is_same< T, typename QmlMarkerFunction< Marker >::ClassType > QmlTypeHasMarker
QObject * createSingletonInstance(QQmlEngine *q, QJSEngine *j)
void Q_QML_EXPORT qmlRegisterTypeAndRevisions< QQmlTypeNotAvailable, void >(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *, bool)
Definition qqml.cpp:1119
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset=-1)
void createInto(void *memory, void *)
void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds)
Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type)
Definition qqml.cpp:172
@ CompositeSingletonRegistration
@ SingletonRegistration
@ SequentialContainerRegistration
@ SequentialContainerAndRevisionsRegistration
@ QmlUnitCacheHookRegistration
@ CompositeRegistration
@ SingletonAndRevisionsRegistration
@ InterfaceRegistration
@ AutoParentRegistration
@ TypeAndRevisionsRegistration
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
@ UnconstructibleSingleton
constexpr SingletonConstructionMode singletonConstructionMode()
const QMetaObject * attachedPropertiesMetaObject()
const char * classInfo(const QMetaObject *metaObject, const char *key)
void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *extension)
bool boolClassInfo(const QMetaObject *metaObject, const char *key, bool defaultValue=false)
void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *extension, bool forceAnonymous=false)
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(DynamicFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(BoundFunction, JavaScriptFunctionObject)
DECLARE_HEAP_OBJECT(ConstructorFunction, ScriptFunction)
DECLARE_HEAP_OBJECT(FunctionObject, Object)
DECLARE_HEAP_OBJECT(JavaScriptFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(MemberFunction, ArrowFunction)
DECLARE_HEAP_OBJECT(ScriptFunction, ArrowFunction)
Definition qjsvalue.h:24
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
void(* IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *)
Definition qqmlprivate.h:65
size_t qHash(QByteArrayView key, size_t seed) noexcept
Definition qhash.cpp:876
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:95
QV4::ExecutionEngine * QQmlV4ExecutionEnginePtr
Definition qqmlprivate.h:92
QQmlV4Function * QQmlV4FunctionPtr
Definition qqmlprivate.h:91
DEFINE_OBJECT_VTABLE(SharedArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBuffer)
DEFINE_OBJECT_VTABLE(SharedArrayBuffer)
#define V4_NEEDS_DESTROY
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define RETURN_UNDEFINED()
void(* functionPtr)(const AOTCompiledContext *context, void **argv)
void(* signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes)
virtual ~AOTTrackedLocalsStorage()=default
virtual void markObjects(QV4::MarkStack *markStack) const =0
const AOTCompiledFunction * aotCompiledFunctions
const QV4::CompiledData::Unit * qmlData
static const QMetaObject * staticMetaObject()
static constexpr const CreateParentFunction createParent
static constexpr bool value
static constexpr bool Value
static QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static Func attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static constexpr const QMetaObject * metaObject()
static constexpr bool Value
static constexpr QMetaSequence sequence()
static constexpr QMetaType self()
static constexpr bool hasAcceptableCtors()
static constexpr QMetaType list()
static constexpr int size()
static constexpr QMetaType list()
static constexpr QMetaSequence sequence()
static constexpr QMetaType self()
static constexpr bool hasAcceptableCtors()
static constexpr int size()
static constexpr bool Value
static constexpr bool Value
static constexpr bool Value
QmlUnitCacheLookupFunction lookupCachedQmlUnit
std::function< QObject *(QQmlEngine *, QJSEngine *)> qObjectApi
std::function< QObject *(QQmlEngine *, QJSEngine *)> qObjectApi
QObject *(* extensionObjectCreate)(QObject *)
std::function< QJSValue(QQmlEngine *, QJSEngine *)> scriptApi
const QMetaObject * extensionMetaObject
const QMetaObject * instanceMetaObject
QObject *(* extensionObjectCreate)(QObject *)
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunction
QVariant(* createValueType)(const QJSValue &)
const QMetaObject * extensionMetaObject
const QMetaObject * classInfoMetaObject
const QMetaObject * attachedPropertiesMetaObject
QQmlCustomParser * customParser
void(* create)(void *, void *)
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunction
QVariant(* createValueType)(const QJSValue &)
const QMetaObject * extensionMetaObject
QObject *(* extensionObjectCreate)(QObject *)
const QMetaObject * metaObject
const QMetaObject * attachedPropertiesMetaObject
bool has(StructVersion v) const
ValueTypeCreationMethod creationMethod
static no_type checkType(...)
static yes_type checkType(To *)
static const QMetaObject * staticMetaObject()
static QVariant create(const QJSValue &params)
static constexpr const CreateValueTypeFunction create
static QVariant create(const QJSValue &params)
static ReturnedValue method_isView(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static void virtualCallWithMetaTypes(const FunctionObject *f, QObject *thisObject, void **a, const QMetaType *types, int argc)
static ReturnedValue virtualCall(const QV4::FunctionObject *f, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static QQmlRefPointer< ExecutableCompilationUnit > parse(ExecutionEngine *engine, const Value *argv, int argc, Type t=Type_Function)
static ReturnedValue method_bind(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_call(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_apply(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name=nullptr)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call)
void init(QV4::ExecutionEngine *engine)
Heap::InternalClass * classForConstructor() const
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc, bool shared)