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_H |
5 | #define QQMLCONTEXT_H |
6 | |
7 | #include <QtCore/qurl.h> |
8 | #include <QtCore/qobject.h> |
9 | #include <QtCore/qlist.h> |
10 | #include <QtCore/qpair.h> |
11 | #include <QtQml/qjsvalue.h> |
12 | #include <QtCore/qmetatype.h> |
13 | #include <QtCore/qvariant.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | |
18 | class QString; |
19 | class QQmlEngine; |
20 | class QQmlContextPrivate; |
21 | class QQmlCompositeTypeData; |
22 | class QQmlContextData; |
23 | |
24 | class Q_QML_EXPORT QQmlContext : public QObject |
25 | { |
26 | Q_OBJECT |
27 | Q_DECLARE_PRIVATE(QQmlContext) |
28 | |
29 | public: |
30 | struct PropertyPair { QString name; QVariant value; }; |
31 | |
32 | QQmlContext(QQmlEngine *parent, QObject *objParent = nullptr); |
33 | QQmlContext(QQmlContext *parent, QObject *objParent = nullptr); |
34 | ~QQmlContext() override; |
35 | |
36 | bool isValid() const; |
37 | |
38 | QQmlEngine *engine() const; |
39 | QQmlContext *parentContext() const; |
40 | |
41 | QObject *contextObject() const; |
42 | void setContextObject(QObject *); |
43 | |
44 | QVariant contextProperty(const QString &) const; |
45 | void setContextProperty(const QString &, QObject *); |
46 | void setContextProperty(const QString &, const QVariant &); |
47 | void setContextProperties(const QList<PropertyPair> &properties); |
48 | |
49 | QString nameForObject(const QObject *) const; |
50 | QObject *objectForName(const QString &) const; |
51 | |
52 | QUrl resolvedUrl(const QUrl &) const; |
53 | |
54 | void setBaseUrl(const QUrl &); |
55 | QUrl baseUrl() const; |
56 | |
57 | QJSValue importedScript(const QString &name) const; |
58 | |
59 | private: |
60 | friend class QQmlEngine; |
61 | friend class QQmlEnginePrivate; |
62 | friend class QQmlExpression; |
63 | friend class QQmlExpressionPrivate; |
64 | friend class QQmlComponent; |
65 | friend class QQmlComponentPrivate; |
66 | friend class QQmlScriptPrivate; |
67 | friend class QQmlContextData; |
68 | QQmlContext(QQmlContextPrivate &dd, QObject *parent = nullptr); |
69 | QQmlContext(QQmlEngine *, bool); |
70 | Q_DISABLE_COPY(QQmlContext) |
71 | }; |
72 | QT_END_NAMESPACE |
73 | |
74 | #endif // QQMLCONTEXT_H |
75 |