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
qqmlcontext_p.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
4#ifndef QQMLCONTEXT_P_H
5#define QQMLCONTEXT_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 <QtCore/qlist.h>
19#include <QtCore/qstring.h>
20#include <QtCore/qvariant.h>
21#include <QtCore/qpointer.h>
22#include <QtQml/qqmlcontext.h>
23#include <QtQml/qqmllist.h>
24
25#include <QtCore/private/qobject_p.h>
26#include <QtCore/qtaggedpointer.h>
27#include <QtQml/private/qqmlrefcount_p.h>
28
30
31class QQmlContextData;
32
34{
35 Q_DECLARE_PUBLIC(QQmlContext)
36public:
40
42 return static_cast<QQmlContext *>(context->q_func());
43 }
44
45 static qsizetype context_count(QQmlListProperty<QObject> *);
46 static QObject *context_at(QQmlListProperty<QObject> *, qsizetype);
47
48 void dropDestroyedQObject(const QString &name, QObject *destroyed);
49
50 int notifyIndex() const { return m_notifyIndex; }
51 void setNotifyIndex(int notifyIndex) { m_notifyIndex = notifyIndex; }
52
53 int numPropertyValues() const {
54 auto size = m_propertyValues.size();
55 Q_ASSERT(size <= std::numeric_limits<int>::max());
56 return int(size);
57 }
58 void appendPropertyValue(const QVariant &value) { m_propertyValues.append(value); }
59 void setPropertyValue(int index, const QVariant &value) { m_propertyValues[index] = value; }
60 QVariant propertyValue(int index) const { return m_propertyValues[index]; }
61
62 QList<QPointer<QObject>> instances() const { return m_instances; }
63 void appendInstance(QObject *instance) { m_instances.append(instance); }
65 {
66 for (auto it = m_instances.begin(); it != m_instances.end();
67 it->isNull() ? (it = m_instances.erase(it)) : ++it) {}
68 }
69
70 void emitDestruction();
71
72private:
73 friend class QQmlContextData;
74
76 QQmlContextPrivate(QQmlContext *publicContext, const QQmlRefPointer<QQmlContextData> &parent,
77 QQmlEngine *engine = nullptr);
78
79 // Intentionally a bare pointer. QQmlContextData knows whether it owns QQmlContext or vice
80 // versa. If QQmlContext is the owner, QQmlContextData keeps an extra ref for its publicContext.
81 // The publicContext ref is released when doing QQmlContextData::setPublicContext(nullptr).
82 QQmlContextData *m_data;
83
84 QList<QVariant> m_propertyValues;
85 int m_notifyIndex = -1;
86
87 // Only used for debugging
88 QList<QPointer<QObject>> m_instances;
89};
90
92
93#endif // QQMLCONTEXT_P_H
qsizetype size() const noexcept
Definition qlist.h:397
iterator erase(const_iterator begin, const_iterator end)
Definition qlist.h:889
iterator end()
Definition qlist.h:626
iterator begin()
Definition qlist.h:625
void append(parameter_type t)
Definition qlist.h:458
QObject * parent
Definition qobject.h:73
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
void dropDestroyedQObject(const QString &name, QObject *destroyed)
static QQmlContext * get(QQmlContextPrivate *context)
static qsizetype context_count(QQmlListProperty< QObject > *)
void setNotifyIndex(int notifyIndex)
void setPropertyValue(int index, const QVariant &value)
void appendInstance(QObject *instance)
int notifyIndex() const
static QQmlContextPrivate * get(QQmlContext *context)
void appendPropertyValue(const QVariant &value)
QList< QPointer< QObject > > instances() const
int numPropertyValues() const
QVariant propertyValue(int index) const
static QObject * context_at(QQmlListProperty< QObject > *, qsizetype)
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static void * context
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
ptrdiff_t qsizetype
Definition qtypes.h:165
QJSEngine engine
[0]