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/qvariant.h>
34#include <QtCore/qversionnumber.h>
35
36#include <functional>
37#include <limits>
38#include <type_traits>
39
40QT_BEGIN_NAMESPACE
41
42class QQmlPropertyValueInterceptor;
43class QQmlContextData;
44class QQmlFinalizerHook;
45
46namespace QQmlPrivate {
47struct CachedQmlUnit;
48template<typename A>
49using QQmlAttachedPropertiesFunc = A *(*)(QObject *);
50}
51
52namespace QV4 {
53struct ExecutionEngine;
54struct MarkStack;
55class ExecutableCompilationUnit;
56namespace CompiledData {
57struct Unit;
58}
59}
60namespace QmlIR {
61struct Document;
62typedef void (*IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *);
63}
64
65using QQmlAttachedPropertiesFunc = QQmlPrivate::QQmlAttachedPropertiesFunc<QObject>;
66
67inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
68{
69 return qHash(quintptr(func), seed);
70}
71
72template <typename TYPE>
74{
75public:
76 enum {
78 };
79};
80
81
82class QJSEngine;
83class QQmlEngine;
84class QQmlCustomParser;
86
87class QQmlV4Function;
89using QQmlV4ExecutionEnginePtr = QV4::ExecutionEngine *;
90
91template<class T>
92QQmlCustomParser *qmlCreateCustomParser()
93{
94 return nullptr;
95}
96
97namespace QQmlPrivate
98{
100 template<typename T>
101 class QQmlElement final : public T
102 {
103 public:
104 // Not defaulted so that it can be specialized
106
107 ~QQmlElement() override {
108 QQmlPrivate::qdeclarativeelement_destructor(this);
109 }
110 static void operator delete(void *ptr) {
111 // We allocate memory from this class in QQmlType::create
112 // along with some additional memory.
113 // So we override the operator delete in order to avoid the
114 // sized operator delete to be called with a different size than
115 // the size that was allocated.
116 ::operator delete (ptr);
117 }
118#ifdef Q_CC_MSVC
119 static void operator delete(void *, void *) {
120 // Deliberately empty placement delete operator.
121 // Silences MSVC warning C4291: no matching operator delete found
122 // On MinGW it causes -Wmismatched-new-delete, though.
123 }
124#endif
125 };
126
134
135 template<typename T, typename WrapperT = T, typename = std::void_t<>>
137 {
138 static constexpr bool value = false;
139 };
140
141 template<typename T, typename WrapperT>
143 static_cast<QQmlEngine *>(nullptr),
144 static_cast<QJSEngine *>(nullptr)))>>
145 {
146 static constexpr bool value = std::is_same_v<
147 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
148 static_cast<QJSEngine *>(nullptr))), T *>;
149 };
150
151 template<typename T, typename WrapperT>
153 {
154 if constexpr (!std::is_base_of<QObject, T>::value)
156 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
158 if constexpr (std::is_default_constructible<T>::value)
160 if constexpr (HasSingletonFactory<T>::value)
162
164 }
165
166 template<typename>
168
169 template<typename Ret, typename Class>
170 struct QmlMarkerFunction<Ret (Class::*)()>
171 {
172 using ClassType = Class;
173 };
174
175 template<typename T, typename Marker>
176 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
177
178 template<typename T>
179 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
180
181 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
183 {
184 Q_UNUSED(q);
185 Q_UNUSED(j);
186 if constexpr (Mode == SingletonConstructionMode::Constructor)
187 return new T;
188 else if constexpr (Mode == SingletonConstructionMode::Factory)
189 return T::create(q, j);
190 else if constexpr (Mode == SingletonConstructionMode::FactoryWrapper)
191 return WrapperT::create(q, j);
192 else
193 return nullptr;
194 }
195
196 template<typename T>
197 QObject *createParent(QObject *p) { return new T(p); }
198
199 using CreateIntoFunction = void (*)(void *, void *);
203
204 template<typename T, typename WrapperT = T,
205 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
207
208 template<typename T, typename WrapperT>
210 {
212 = QQmlPrivate::createInto<T>;
214 = QQmlPrivate::createSingletonInstance<
216 };
217
218 template<typename T, typename WrapperT>
220 {
221 static constexpr CreateIntoFunction createInto = nullptr;
223 };
224
225 template<typename T, typename WrapperT>
227 {
228 static constexpr CreateIntoFunction createInto = nullptr;
230 = QQmlPrivate::createSingletonInstance<
232 };
233
234 template<typename T, typename WrapperT>
236 {
237 static constexpr CreateIntoFunction createInto = nullptr;
239 = QQmlPrivate::createSingletonInstance<
241 };
242
243 template<typename T,
247
248 template<typename T>
249 struct ExtendedType<T, false, false>
250 {
251 static constexpr const CreateParentFunction createParent = nullptr;
252 static const QMetaObject *staticMetaObject() { return nullptr; }
253 };
254
255 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
256 template<typename T>
257 struct ExtendedType<T, true, false>
258 {
260 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
261 };
262
263 // If it's a Q_GADGET, we don't want the ctor.
264 template<typename T>
265 struct ExtendedType<T, false, true>
266 {
267 static constexpr const CreateParentFunction createParent = nullptr;
268 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
269 };
270
271 template<typename F, typename Result = void>
273 {
274 static constexpr const Result (*create)(const QJSValue &) = nullptr;
275 };
276
277 template<typename F>
278 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
279 {
280 static decltype(F::create(QJSValue())) create(const QJSValue &params)
281 {
282 return F::create(params);
283 }
284 };
285
286 template<typename T, typename F,
287 bool HasCtor = std::is_constructible_v<T, QJSValue>,
288 bool HasFactory = std::is_constructible_v<
289 QVariant, decltype(ValueTypeFactory<F>::create(QJSValue()))>>
290 struct ValueType;
291
292 template<typename T, typename F>
293 struct ValueType<T, F, false, false>
294 {
295 static constexpr const CreateValueTypeFunction create = nullptr;
296 };
297
298 template<typename T, typename F, bool HasCtor>
299 struct ValueType<T, F, HasCtor, true>
300 {
301 static QVariant create(const QJSValue &params)
302 {
303 return F::create(params);
304 }
305 };
306
307 template<typename T, typename F>
308 struct ValueType<T, F, true, false>
309 {
310 static QVariant create(const QJSValue &params)
311 {
312 return QVariant::fromValue(T(params));
313 }
314 };
315
316 template<class From, class To, int N>
318 {
319 static inline int cast() { return -1; }
320 };
321
322 template<class From, class To>
323 struct StaticCastSelectorClass<From, To, sizeof(int)>
324 {
325 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
326 };
327
328 template<class From, class To>
330 {
331 typedef int yes_type;
332 typedef char no_type;
333
334 static yes_type checkType(To *);
335 static no_type checkType(...);
336
337 static inline int cast()
338 {
339 return StaticCastSelectorClass<From, To, sizeof(checkType(reinterpret_cast<From *>(0)))>::cast();
340 }
341 };
342
343 // You can prevent subclasses from using the same attached type by specialzing this.
344 // This is reserved for internal types, though.
345 template<class T, class A>
347 {
348 using Type = A;
349 };
350
351 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
353 {
354 using Type = void;
356 static const QMetaObject *staticMetaObject() { return nullptr; }
357 static Func attachedPropertiesFunc() { return nullptr; }
358 };
359
360 // Defined inline via QML_ATTACHED
361 template<class T>
362 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
363 {
364 // Normal attached properties
365 template <typename Parent, typename Attached>
372
373 // Disabled via OverridableAttachedType
374 template<typename Parent>
375 struct Properties<Parent, void>
376 {
378 static const QMetaObject *staticMetaObject() { return nullptr; }
379 static Func attachedPropertiesFunc() { return nullptr; }
380 };
381
382 using Type = typename std::conditional<
384 typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type, void>::type;
385 using Func = typename Properties<T, Type>::Func;
386
388 {
389 return Properties<T, Type>::staticMetaObject();
390 }
391
393 {
395 }
396 };
397
398 // Separately defined via QQmlTypeInfo
399 template<class T>
400 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
401 {
402 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
404
405 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
407 };
408
409 // This is necessary because both the type containing a default template parameter and the type
410 // instantiating the template need to have access to the default template parameter type. In
411 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
412 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
413 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
414 // struct "fixes" that. For convenience we still want the free standing functions in addition.
415 template<class T>
417 {
419 {
420 return QQmlAttachedPropertiesFunc<QObject>(QmlAttached<T>::attachedPropertiesFunc());
421 }
422
424 {
425 return QmlAttached<T>::staticMetaObject();
426 }
427 };
428
429 template<typename T>
431 {
432 return QmlAttachedAccessor<T>::attachedPropertiesFunc();
433 }
434
435 template<typename T>
437 {
438 return QmlAttachedAccessor<T>::staticMetaObject();
439 }
440
442 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
443
445
453
454 bool has(StructVersion v) const { return structVersion >= int(v); }
455
457
461 // The second parameter of create is for userdata
462 void (*create)(void *, void *);
463 void *userdata;
465
466 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
467 QVariant (*createValueType)(const QJSValue &);
468
469 const char *uri;
471 const char *elementName;
473
476
480
483
484 QQmlCustomParser *customParser;
485
488
490 // If this is extended ensure "version" is bumped!!!
491 };
492
527
539
542
543 AutoParentFunction function;
544 };
545
564
582
590
598
601 const char *uri;
603
604 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
605 // and that's automatic.
606 const char *typeName;
607
611 };
612
624
626 {
627 virtual ~AOTTrackedLocalsStorage() = default;
628 virtual void markObjects(QV4::MarkStack *markStack) const = 0;
629 };
630
631 struct Q_QML_EXPORT AOTCompiledContext {
633
637 union {
640 };
641
642 QObject *thisObject() const;
643 QQmlEngine *qmlEngine() const;
644
645 QJSValue jsMetaType(int index) const;
646 void setInstructionPointer(int offset) const;
647 void setLocals(const AOTTrackedLocalsStorage *locals) const;
648 void setReturnValueUndefined() const;
649
650 static void mark(QObject *object, QV4::MarkStack *markStack);
651 static void mark(const QVariant &variant, QV4::MarkStack *markStack);
652 template<typename T>
653 static void mark(T, QV4::MarkStack *) {}
654
655 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
656 bool captureLookup(uint index, QObject *object) const;
658 void captureTranslation() const;
661 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
663
665
666 void writeToConsole(
668 const QLoggingCategory *loggingCategory) const;
669
672 int ctorIndex, void **args) const;
673#if QT_QML_REMOVED_SINCE(6, 9)
676 int ctorIndex, void *ctorArg) const;
677#endif
678
679 // Those are explicit arguments to the Date() ctor, not implicit coercions.
688
690 double year, double month, double day = 1,
691 double hours = 0, double minutes = 0, double seconds = 0, double msecs = 0) const;
692
693 // All of these lookup functions should be used as follows:
694 //
695 // while (!fooBarLookup(...)) {
696 // setInstructionPointer(...);
697 // initFooBarLookup(...);
698 // if (engine->hasException()) {
699 // ...
700 // break;
701 // }
702 // }
703 //
704 // The bool-returning *Lookup functions exclusively run the happy path and return false if
705 // that fails in any way. The failure may either be in the lookup structs not being
706 // initialized or an exception being thrown.
707 // The init*Lookup functions initialize the lookup structs and amend any exceptions
708 // previously thrown with line numbers. They might also throw their own exceptions. If an
709 // exception is present after the initialization there is no way to carry out the lookup and
710 // the exception should be propagated. If not, the original lookup can be tried again.
711
712 bool callQmlContextPropertyLookup(uint index, void **args, int argc) const;
714
715#if QT_QML_REMOVED_SINCE(6, 9)
717 uint index, void **args, const QMetaType *types, int argc) const;
719#endif
720
721 bool loadContextIdLookup(uint index, void *target) const;
723
724 bool callObjectPropertyLookup(uint index, QObject *object, void **args, int argc) const;
728
729#if QT_QML_REMOVED_SINCE(6, 9)
731 uint index, QObject *object, void **args, const QMetaType *types, int argc) const;
733
734 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
735 void initCallGlobalLookup(uint index) const;
736
737 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
738 void initLoadGlobalLookup(uint index) const;
739#endif
740
741 bool loadGlobalLookup(uint index, void *target) const;
743
747#if QT_QML_REMOVED_SINCE(6, 9)
749#endif
750
751 bool loadSingletonLookup(uint index, void *target) const;
753
754 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
756
757 bool loadTypeLookup(uint index, void *target) const;
759
760 bool getObjectLookup(uint index, QObject *object, void *target) const;
764#if QT_QML_REMOVED_SINCE(6, 9)
766#endif
767
768 bool getValueLookup(uint index, void *value, void *target) const;
769 bool writeBackValueLookup(uint index, void *value, void *source) const;
771#if QT_QML_REMOVED_SINCE(6, 9)
773#endif
774
775 bool getEnumLookup(uint index, void *target) const;
776#if QT_QML_REMOVED_SINCE(6, 6)
777 bool getEnumLookup(uint index, int *target) const;
778#endif
780 const char *enumerator, const char *enumValue) const;
781
782 bool setObjectLookup(uint index, QObject *object, void *value) const;
785#if QT_QML_REMOVED_SINCE(6, 9)
787#endif
788
789 bool setValueLookup(uint index, void *target, void *value) const;
792#if QT_QML_REMOVED_SINCE(6, 9)
794#endif
795
796 bool callValueLookup(uint index, void *target, void **args, int argc) const;
799
806
808 {
809 // This does not cover everything you can possibly wrap into a QVariant.
810 // However, since we only _promise_ to handle single objects, this is OK.
812 return;
813
814 if (QObject *object = *static_cast<QObject *const *>(variant.constData()))
816 }
817
818 template<typename Value>
820 };
821
825 void (*signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes);
826 void (*functionPtr)(const AOTCompiledContext *context, void **argv);
827 };
828
829#if QT_DEPRECATED_SINCE(6, 6)
830 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
832#endif
833
839
840 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
843 QmlUnitCacheLookupFunction lookupCachedQmlUnit;
844 };
845
859
862
863#if QT_DEPRECATED_SINCE(6, 3)
865 {
868 bool alreadyCalled = false;
869 };
870#endif
871
872 struct Q_QML_EXPORT SingletonInstanceFunctor
873 {
875
877
878 // Not a QPointer, so that you cannot assign it to a different
879 // engine when the first one is deleted.
880 // That would mess up the QML contexts.
882 };
883
884 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
885 {
886 if (!metaObject || !key)
887 return -1;
888
889 const int offset = metaObject->classInfoOffset();
890 const int start = (startOffset == -1)
891 ? (metaObject->classInfoCount() + offset - 1)
892 : startOffset;
893 for (int i = start; i >= offset; --i)
894 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
895 return i;
896 }
897 return -1;
898 }
899
900 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
901 {
902 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
903 }
904
905 inline QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key,
906 QTypeRevision defaultValue = QTypeRevision())
907 {
908 const int index = indexOfOwnClassInfo(metaObject, key);
909 return (index == -1) ? defaultValue
910 : QTypeRevision::fromEncodedVersion(
911 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
912 }
913
915
916 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
917 bool defaultValue = false)
918 {
919 const int index = indexOfOwnClassInfo(metaObject, key);
920 if (index == -1)
921 return defaultValue;
922 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
923 }
924
925 // These detector classes are using a somehow "old school" SFINAE
926 // approach (overloaded test() functions, rather than void_t
927 // and similar more modern constructs) to avoid hitting GCC/MSVC
928 // bugs; be careful when refactoring these. In particular, make sure
929 // that they still work with private members even if you befriend
930 // the detector.
931
932 template<class T>
934 {
935 private:
936 template<class U>
937 static auto test(int) -> std::conditional_t<
938 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extended)>::value,
939 typename U::QmlExtendedType *,
940 void *
941 >;
942
943 template<class U>
944 static auto test(...) -> void *;
945
946 public:
947 // Some compilers complain if we have functions return abstract types.
948 // So we add pointers in the above, and remove the pointer here.
949 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
950 };
951
952 template<class T>
954 {
955 private:
956 template<class U>
957 static constexpr auto metaObjectImpl(int) ->
958 decltype((void)U::qmlExtendedNamespace(), static_cast<const QMetaObject *>(nullptr))
959 {
960 if constexpr (QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extendedNamespace)>::value)
961 return U::qmlExtendedNamespace();
962 else
963 return nullptr;
964 }
965
966 template<class U>
967 static constexpr auto metaObjectImpl(...) -> const QMetaObject *
968 {
969 return nullptr;
970 }
971
972 public:
973 static constexpr const QMetaObject *metaObject() { return metaObjectImpl<T>(0); }
974 };
975
976 template<class T>
978 {
979 private:
980 template<class U>
981 static auto test(int) -> std::conditional_t<
982 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_foreign)>::value,
983 typename U::QmlForeignType *,
984 U *
985 >;
986
987 template<class U>
988 static auto test(...) -> U *;
989
990 public:
991 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
992 };
993
994 template<class T>
996 {
997 private:
998 template<class U>
999 static auto test(int) -> std::enable_if_t<
1000 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_uncreatable)>::value
1001 && bool(U::QmlIsUncreatable::yes),
1002 std::true_type>;
1003
1004 template<class U>
1005 static auto test(...) -> std::false_type;
1006
1007 public:
1008 static constexpr bool Value = decltype(test<T>(0))::value;
1009 };
1010
1011 template<class T>
1013 {
1014 private:
1015 template<class U>
1016 static auto test(int) -> std::enable_if_t<
1017 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_anonymous)>::value
1018 && bool(U::QmlIsAnonymous::yes),
1019 std::true_type
1020 >;
1021
1022 template<class U>
1023 static auto test(...) -> std::false_type;
1024
1025 public:
1026 static constexpr bool Value = decltype(test<T>(0))::value;
1027 };
1028
1029 template <class T>
1031 {
1032 private:
1033 template<class U>
1034 static auto test(int) -> std::enable_if_t<
1035 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_singleton)>::value
1036 && bool(U::QmlIsSingleton::yes),
1037 std::true_type
1038 >;
1039
1040 template<class U>
1041 static auto test(...) -> std::false_type;
1042
1043 public:
1044 static constexpr bool Value = decltype(test<T>(0))::value;
1045 };
1046
1047 template<class T>
1049 {
1050 private:
1051 template<class U>
1052 static auto test_impl(int) -> std::bool_constant<bool(U::QmlIsSequence::yes)>;
1053
1054 template<class U>
1055 static auto test_impl(...) -> std::false_type;
1056
1057 template<class U>
1058 static constexpr bool test() {
1059 if constexpr (decltype(test_impl<U>(0))::value) {
1060 static_assert((std::is_same_v<typename U::QmlSequenceValueType,
1061 typename QmlResolved<U>::Type::value_type>));
1062 return true;
1063 }
1064 return false;
1065 }
1066
1067 public:
1068 static constexpr bool Value = test<T>();
1069 };
1070
1071 template<class T>
1073 {
1074 private:
1075 template<class U>
1076 static auto test(int) ->
1077 decltype((void)qobject_interface_iid<U *>(), std::bool_constant<bool(U::QmlIsInterface::yes)>{});
1078
1079 template<class U>
1080 static auto test(...) -> std::false_type;
1081
1082 public:
1083 static constexpr bool Value = decltype(test<T>(0))::value;
1084 };
1085
1086 template<class T, typename = std::void_t<>>
1088 {
1089 static const QMetaObject *staticMetaObject() { return nullptr; }
1090 };
1091
1092 template<class T>
1094 {
1095 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
1096 };
1097
1098 template<class T>
1100 {
1101 static constexpr bool hasAcceptableCtors()
1102 {
1103 if constexpr (!std::is_default_constructible_v<T>)
1104 return false;
1105 else if constexpr (std::is_base_of_v<QObject, T>)
1106 return true;
1107 else
1108 return std::is_copy_constructible_v<T>;
1109 }
1110
1111 static constexpr QMetaType self()
1112 {
1113 if constexpr (std::is_base_of_v<QObject, T>)
1114 return QMetaType::fromType<T*>();
1115 else
1116 return QMetaType::fromType<T>();
1117 }
1118
1119 static constexpr QMetaType list()
1120 {
1121 if constexpr (std::is_base_of_v<QObject, T>)
1122 return QMetaType::fromType<QQmlListProperty<T>>();
1123 else
1124 return QMetaType::fromType<QList<T>>();
1125 }
1126
1127 static constexpr QMetaSequence sequence()
1128 {
1129 if constexpr (std::is_base_of_v<QObject, T>)
1130 return QMetaSequence();
1131 else
1132 return QMetaSequence::fromContainer<QList<T>>();
1133 }
1134
1135 static constexpr int size()
1136 {
1137 return sizeof(T);
1138 }
1139 };
1140
1141 template<>
1142 struct QmlMetaType<void>
1143 {
1144 static constexpr bool hasAcceptableCtors() { return true; }
1145 static constexpr QMetaType self() { return QMetaType(); }
1146 static constexpr QMetaType list() { return QMetaType(); }
1147 static constexpr QMetaSequence sequence() { return QMetaSequence(); }
1148 static constexpr int size() { return 0; }
1149 };
1150
1151 template<typename T, typename E, typename WrapperT = T>
1152 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1153 const QMetaObject *classInfoMetaObject,
1154 QList<int> *qmlTypeIds, const QMetaObject *extension)
1155 {
1156 static_assert(std::is_base_of_v<QObject, T>);
1158 0,
1159
1160 uri,
1161 QTypeRevision::fromMajorVersion(versionMajor),
1162
1163 Constructors<T, WrapperT>::createSingletonInstance,
1164
1165 StaticMetaObject<T>::staticMetaObject(),
1166 classInfoMetaObject,
1167
1168 QmlMetaType<T>::self(),
1169
1170 ExtendedType<E>::createParent,
1171 extension ? extension : ExtendedType<E>::staticMetaObject(),
1172
1173 qmlTypeIds
1174 };
1175
1176 qmlregister(SingletonAndRevisionsRegistration, &api);
1177 }
1178
1179 template<typename T, typename E>
1180 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1181 const QMetaObject *classInfoMetaObject,
1182 QList<int> *qmlTypeIds, const QMetaObject *extension,
1183 bool forceAnonymous = false)
1184 {
1186 3,
1187 QmlMetaType<T>::self(),
1188 QmlMetaType<T>::list(),
1189 QmlMetaType<T>::size(),
1190 Constructors<T>::createInto,
1191 nullptr,
1192 ValueType<T, E>::create,
1193
1194 uri,
1195 QTypeRevision::fromMajorVersion(versionMajor),
1196
1197 StaticMetaObject<T>::staticMetaObject(),
1198 classInfoMetaObject,
1199
1200 attachedPropertiesFunc<T>(),
1201 attachedPropertiesMetaObject<T>(),
1202
1203 StaticCastSelector<T, QQmlParserStatus>::cast(),
1204 StaticCastSelector<T, QQmlPropertyValueSource>::cast(),
1205 StaticCastSelector<T, QQmlPropertyValueInterceptor>::cast(),
1206
1207 ExtendedType<E>::createParent,
1208 extension ? extension : ExtendedType<E>::staticMetaObject(),
1209
1210 &qmlCreateCustomParser<T>,
1211 qmlTypeIds,
1212 StaticCastSelector<T, QQmlFinalizerHook>::cast(),
1213
1214 forceAnonymous,
1215 QmlMetaType<T>::sequence(),
1216 };
1217
1218 // Initialize the extension so that we can find it by name or ID.
1219 qMetaTypeId<E>();
1220
1221 qmlregister(TypeAndRevisionsRegistration, &type);
1222 }
1223
1224 template<typename T>
1225 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1226 const QMetaObject *classInfoMetaObject,
1227 QList<int> *qmlTypeIds)
1228 {
1230 0,
1231 uri,
1232 QTypeRevision::fromMajorVersion(versionMajor),
1233 classInfoMetaObject,
1234 QMetaType::fromType<T>(),
1235 QMetaSequence::fromContainer<T>(),
1236 qmlTypeIds
1237 };
1238
1240 }
1241
1242 template<>
1244 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1245 QList<int> *qmlTypeIds, const QMetaObject *, bool);
1246
1248 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1249 {
1250 return {
1251 /*.revision=*/ 0,
1252 /*.alignment=*/ 0,
1253 /*.size=*/ 0,
1254 /*.flags=*/ 0,
1255 /*.typeId=*/ QBasicAtomicInt(),
1256 /*.metaObject=*/ metaObjectFunction,
1257 /*.name=*/ name,
1258 /*.defaultCtr=*/ nullptr,
1259 /*.copyCtr=*/ nullptr,
1260 /*.moveCtr=*/ nullptr,
1261 /*.dtor=*/ nullptr,
1262 /*.equals*/ nullptr,
1263 /*.lessThan*/ nullptr,
1264 /*.debugStream=*/ nullptr,
1265 /*.dataStreamOut=*/ nullptr,
1266 /*.dataStreamIn=*/ nullptr,
1267 /*.legacyRegisterOp=*/ nullptr
1268 };
1269 }
1270
1271 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1272
1278
1279 Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type);
1280
1281 Q_QML_EXPORT QMetaType compositeMetaType(
1283 Q_QML_EXPORT QMetaType compositeMetaType(
1285 Q_QML_EXPORT QMetaType compositeListMetaType(
1287 Q_QML_EXPORT QMetaType compositeListMetaType(
1289
1290} // namespace QQmlPrivate
1291
1292QT_END_NAMESPACE
1293
1294Q_DECLARE_OPAQUE_POINTER(QQmlV4FunctionPtr)
1295Q_DECLARE_OPAQUE_POINTER(QQmlV4ExecutionEnginePtr)
1296
1297#endif // QQMLPRIVATE_H
void operator delete(void *)
friend class QJSEngine
static void operator delete(void *ptr)
@ hasAttachedProperties
Definition qqmlprivate.h:77
QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key, QTypeRevision defaultValue=QTypeRevision())
QObject * createParent(QObject *p)
A *(*)(QObject *) QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:49
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:1117
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:62
size_t qHash(QByteArrayView key, size_t seed) noexcept
Definition qhash.cpp:876
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:92
QV4::ExecutionEngine * QQmlV4ExecutionEnginePtr
Definition qqmlprivate.h:89
QQmlV4Function * QQmlV4FunctionPtr
Definition qqmlprivate.h:88
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)