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
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
29QT_BEGIN_NAMESPACE
30
31class QQmlContextData;
32
34{
35 Q_DECLARE_PUBLIC(QQmlContext)
36public:
40
42 return static_cast<QQmlContext *>(context->q_func());
43 }
44
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
75 QQmlContextPrivate(QQmlContextData *data) : m_data(data) {}
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
91QT_END_NAMESPACE
92
93#endif // QQMLCONTEXT_P_H
void dropDestroyedQObject(const QString &name, QObject *destroyed)
void setNotifyIndex(int notifyIndex)
void setPropertyValue(int index, const QVariant &value)
void appendInstance(QObject *instance)
int notifyIndex() const
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)
static bool readObjectProperty(const QQmlRefPointer< QQmlContextData > &data, QObject *object, const QString &name, QVariant *target)