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