Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmltcobjectcreationhelper_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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
4#ifndef QQMLTCOBJECTCREATIONHELPER_P_H
5#define QQMLTCOBJECTCREATIONHELPER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQml/qqml.h>
19#include <QtCore/private/qglobal_p.h>
20#include <QtCore/qversionnumber.h>
21#include <private/qtqmlglobal_p.h>
22#include <private/qqmltype_p.h>
23
24#include <array>
25
27
36{
37 QObject **m_data = nullptr; // QObject* array
38 const qsizetype m_size = 0; // size of m_data array, exists for bounds checking
39 const qsizetype m_offset = 0; // global offset into m_data array
40
41 qsizetype offset() const { return m_offset; }
42
43public:
52
58 : m_data(base->m_data), m_size(base->m_size), m_offset(base->m_offset + localOffset)
59 {
60 }
61
62 template<typename T>
63 T *get(qsizetype i) const
64 {
66 Q_ASSERT(i >= 0 && i + offset() < m_size);
67 Q_ASSERT(qobject_cast<T *>(m_data[i + offset()]) != nullptr);
68 // Note: perform cheap cast as we know *exactly* the real type of the
69 // object
70 return static_cast<T *>(m_data[i + offset()]);
71 }
72
73 void set(qsizetype i, QObject *object)
74 {
76 Q_ASSERT(i >= 0 && i + offset() < m_size);
77 Q_ASSERT(m_data[i + offset()] == nullptr); // prevent accidental resets
78 m_data[i + offset()] = object;
79 }
80
81 template<typename T>
82 static constexpr uint typeCount() noexcept
83 {
84 return T::q_qmltc_typeCount();
85 }
86};
87
94template<typename QmltcGeneratedType>
96{
97 // Note: +1 for the document root itself
98 std::array<QObject *, QmltcGeneratedType::q_qmltc_typeCount() + 1> m_objects = {};
99
100public:
102 {
103 return QQmltcObjectCreationHelper(m_objects.data(), m_objects.size());
104 }
105};
106
108{
111 const QMetaObject *metaObject = nullptr;
112
113 template<typename QmltcGeneratedType>
114 QmltcTypeData(QmltcGeneratedType *)
115 : allocationSize(sizeof(QmltcGeneratedType)),
116 metaObject(&QmltcGeneratedType::staticMetaObject)
117 {
118 }
119};
120
121Q_QML_EXPORT void qmltcCreateDynamicMetaObject(QObject *object, const QmltcTypeData &data);
122
124
125#endif // QQMLTCOBJECTCREATIONHELPER_P_H
NSData * m_data
\inmodule QtCore
Definition qobject.h:103
QQmltcObjectCreationHelper view()
QQmltcObjectCreationHelper(const QQmltcObjectCreationHelper *base, qsizetype localOffset)
Constructs new "view" from base view, adding localOffset to the offset of that base.
static constexpr uint typeCount() noexcept
QQmltcObjectCreationHelper(QObject **data, qsizetype size)
Constructs initial "view" from basic data.
void set(qsizetype i, QObject *object)
Combined button and popup list for selecting options.
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
Q_QML_EXPORT void qmltcCreateDynamicMetaObject(QObject *object, const QmltcTypeData &data)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
static const uint base
Definition qurlidna.cpp:20
\inmodule QtCore
QQmlType::RegistrationType regType
const QMetaObject * metaObject
QmltcTypeData(QmltcGeneratedType *)