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// Qt-Security score:significant
4
5#ifndef QQMLCONTEXT_P_H
6#define QQMLCONTEXT_P_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 <QtCore/qlist.h>
20#include <QtCore/qstring.h>
21#include <QtCore/qvariant.h>
22#include <QtCore/qpointer.h>
23#include <QtQml/qqmlcontext.h>
24#include <QtQml/qqmllist.h>
25
26#include <QtCore/private/qobject_p.h>
27#include <QtCore/qtaggedpointer.h>
28#include <QtQml/private/qqmlrefcount_p.h>
29
30QT_BEGIN_NAMESPACE
31
32class QQmlContextData;
33
35{
36 Q_DECLARE_PUBLIC(QQmlContext)
37public:
41
43 return static_cast<QQmlContext *>(context->q_func());
44 }
45
47 static QObject *context_at(QQmlListProperty<QObject> *, qsizetype);
48
49 void dropDestroyedQObject(const QString &name, QObject *destroyed);
50
51 int notifyIndex() const { return m_notifyIndex; }
52 void setNotifyIndex(int notifyIndex) { m_notifyIndex = notifyIndex; }
53
54 int numPropertyValues() const {
55 auto size = m_propertyValues.size();
56 Q_ASSERT(size <= std::numeric_limits<int>::max());
57 return int(size);
58 }
59 void appendPropertyValue(const QVariant &value) { m_propertyValues.append(value); }
60 void setPropertyValue(int index, const QVariant &value) { m_propertyValues[index] = value; }
61 QVariant propertyValue(int index) const { return m_propertyValues[index]; }
62
63 QList<QPointer<QObject>> instances() const { return m_instances; }
64 void appendInstance(QObject *instance) { m_instances.append(instance); }
66 {
67 for (auto it = m_instances.begin(); it != m_instances.end();
68 it->isNull() ? (it = m_instances.erase(it)) : ++it) {}
69 }
70
71 void emitDestruction();
72
73private:
74 friend class QQmlContextData;
75
76 QQmlContextPrivate(QQmlContextData *data) : m_data(data) {}
77 QQmlContextPrivate(QQmlContext *publicContext, const QQmlRefPointer<QQmlContextData> &parent,
78 QQmlEngine *engine = nullptr);
79
80 // Intentionally a bare pointer. QQmlContextData knows whether it owns QQmlContext or vice
81 // versa. If QQmlContext is the owner, QQmlContextData keeps an extra ref for its publicContext.
82 // The publicContext ref is released when doing QQmlContextData::setPublicContext(nullptr).
83 QQmlContextData *m_data;
84
85 QList<QVariant> m_propertyValues;
86 int m_notifyIndex = -1;
87
88 // Only used for debugging
89 QList<QPointer<QObject>> m_instances;
90};
91
92QT_END_NAMESPACE
93
94#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)
Combined button and popup list for selecting options.
static bool readObjectProperty(const QQmlRefPointer< QQmlContextData > &data, QObject *object, const QString &name, QVariant *target)
static QObject * objectForNameInQQmlContextData(const QQmlRefPointer< QQmlContextData > &data, const QQmlContextPrivate *d, const QString &name)