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 QQMLBOUNDSIGNAL_P_H
5#define QQMLBOUNDSIGNAL_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/qmetaobject.h>
19
20#include <private/qqmljavascriptexpression_p.h>
21#include <private/qqmlnotifier_p.h>
22#include <private/qqmlrefcount_p.h>
23#include <private/qtqmlglobal_p.h>
24
25QT_BEGIN_NAMESPACE
26
27class Q_QML_PRIVATE_EXPORT QQmlBoundSignalExpression
28 : public QQmlJavaScriptExpression,
29 public QQmlRefCounted<QQmlBoundSignalExpression>
30{
31 friend class QQmlRefCounted<QQmlBoundSignalExpression>;
32public:
33 QQmlBoundSignalExpression(
34 const QObject *target, int index, const QQmlRefPointer<QQmlContextData> &ctxt, QObject *scope,
35 const QString &expression, const QString &fileName, quint16 line, quint16 column,
36 const QString &handlerName = QString(), const QString &parameterString = QString());
37
38 QQmlBoundSignalExpression(
39 const QObject *target, int index, const QQmlRefPointer<QQmlContextData> &ctxt,
40 QObject *scopeObject, QV4::Function *function, QV4::ExecutionContext *scope = nullptr);
41
42 // inherited from QQmlJavaScriptExpression.
43 QString expressionIdentifier() const override;
44 void expressionChanged() override;
45
46 // evaluation of a bound signal expression doesn't return any value
47 void evaluate(void **a);
48
49 bool mustCaptureBindableProperty() const final {return true;}
50
51 QString expression() const;
52 const QObject *target() const { return m_target; }
53
54private:
55 ~QQmlBoundSignalExpression() override;
56
57 void init(const QQmlRefPointer<QQmlContextData> &ctxt, QObject *scope);
58
59 bool expressionFunctionValid() const { return function() != nullptr; }
60
61 int m_index;
62 const QObject *m_target;
63};
64
65class Q_QML_PRIVATE_EXPORT QQmlBoundSignal : public QQmlNotifierEndpoint
66{
67public:
68 QQmlBoundSignal(QObject *target, int signal, QObject *owner, QQmlEngine *engine);
69 ~QQmlBoundSignal();
70
71 void removeFromObject();
72
73 QQmlBoundSignalExpression *expression() const;
74 void takeExpression(QQmlBoundSignalExpression *);
75
76 void setEnabled(bool enabled);
77
78private:
79 friend void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **);
80 friend class QQmlPropertyPrivate;
81 friend class QQmlData;
82 friend class QQmlEngineDebugService;
83
84 void addToObject(QObject *owner);
85
86 QQmlBoundSignal **m_prevSignal;
87 QQmlBoundSignal *m_nextSignal;
88
89 bool m_enabled;
90
91 QQmlRefPointer<QQmlBoundSignalExpression> m_expression;
92};
93
94class QQmlPropertyObserver : public QPropertyObserver
95{
96public:
97 QQmlPropertyObserver(QQmlBoundSignalExpression *expr);
98
99private:
100 QQmlRefPointer<QQmlBoundSignalExpression> expression;
101};
102
103QT_END_NAMESPACE
104
105#endif // QQMLBOUNDSIGNAL_P_H
106

source code of qtdeclarative/src/qml/qml/qqmlboundsignal_p.h