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 QQMLCONNECTIONS_H |
5 | #define QQMLCONNECTIONS_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 <qqml.h> |
19 | #include <private/qqmlcustomparser_p.h> |
20 | |
21 | #include <QtCore/qobject.h> |
22 | #include <QtCore/qstring.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QQmlBoundSignal; |
27 | class QQmlContext; |
28 | class QQmlConnectionsPrivate; |
29 | class Q_QML_PRIVATE_EXPORT QQmlConnections : public QObject, public QQmlParserStatus |
30 | { |
31 | Q_OBJECT |
32 | Q_DECLARE_PRIVATE(QQmlConnections) |
33 | |
34 | Q_INTERFACES(QQmlParserStatus) |
35 | Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) |
36 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged REVISION(2, 3)) |
37 | Q_PROPERTY(bool ignoreUnknownSignals READ ignoreUnknownSignals WRITE setIgnoreUnknownSignals) |
38 | QML_NAMED_ELEMENT(Connections) |
39 | QML_ADDED_IN_VERSION(2, 0) |
40 | QML_CUSTOMPARSER |
41 | |
42 | public: |
43 | QQmlConnections(QObject *parent=nullptr); |
44 | |
45 | QObject *target() const; |
46 | void setTarget(QObject *); |
47 | |
48 | bool isEnabled() const; |
49 | void setEnabled(bool enabled); |
50 | |
51 | bool ignoreUnknownSignals() const; |
52 | void setIgnoreUnknownSignals(bool ignore); |
53 | |
54 | protected: |
55 | void classBegin() override; |
56 | void componentComplete() override; |
57 | |
58 | Q_SIGNALS: |
59 | void targetChanged(); |
60 | Q_REVISION(2, 3) void enabledChanged(); |
61 | |
62 | private: |
63 | void connectSignals(); |
64 | void connectSignalsToMethods(); |
65 | void connectSignalsToBindings(); |
66 | }; |
67 | |
68 | // TODO: Drop this class as soon as we can |
69 | class QQmlConnectionsParser : public QQmlCustomParser |
70 | { |
71 | public: |
72 | void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props) override; |
73 | void applyBindings(QObject *object, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override; |
74 | }; |
75 | |
76 | // TODO: We won't need Connections to be a custom type anymore once we can drop the |
77 | // automatic signal handler inference from undeclared properties. |
78 | template<> |
79 | inline QQmlCustomParser *qmlCreateCustomParser<QQmlConnections>() |
80 | { |
81 | return new QQmlConnectionsParser; |
82 | } |
83 | |
84 | QT_END_NAMESPACE |
85 | |
86 | QML_DECLARE_TYPE(QQmlConnections) |
87 | |
88 | #endif |
89 |