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
qqmlbinding_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
4#ifndef QQMLBINDING_P_H
5#define QQMLBINDING_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 "qqmlproperty.h"
20
21#include <QtCore/QObject>
22#include <QtCore/QMetaProperty>
23
24#include <private/qqmlabstractbinding_p.h>
25#include <private/qqmljavascriptexpression_p.h>
26#include <private/qv4functionobject_p.h>
27#include <private/qqmltranslation_p.h>
28
29QT_BEGIN_NAMESPACE
30
31class QQmlContext;
32class Q_QML_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
33 public QQmlAbstractBinding
34{
35 friend class QQmlAbstractBinding;
36public:
37 typedef QExplicitlySharedDataPointer<QQmlBinding> Ptr;
38
39 static QQmlBinding *create(const QQmlPropertyData *, const QQmlScriptString &, QObject *, QQmlContext *);
40
41 static QQmlBinding *create(
42 const QQmlPropertyData *, const QString &, QObject *,
43 const QQmlRefPointer<QQmlContextData> &, const QString &url = QString(),
44 quint16 lineNumber = 0);
45
46 static QQmlBinding *create(
47 const QQmlPropertyData *property, QV4::Function *function, QObject *obj,
48 const QQmlRefPointer<QQmlContextData> &ctxt, QV4::ExecutionContext *scope);
49
50 static QQmlBinding *create(QMetaType propertyType, QV4::Function *function, QObject *obj,
51 const QQmlRefPointer<QQmlContextData> &ctxt,
52 QV4::ExecutionContext *scope);
53
54 static QQmlBinding *createTranslationBinding(
55 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
56 const QV4::CompiledData::Binding *binding, QObject *obj,
57 const QQmlRefPointer<QQmlContextData> &ctxt);
58
59 static QQmlBinding *
60 createTranslationBinding(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
61 const QQmlRefPointer<QQmlContextData> &ctxt,
62 const QString &propertyName, const QQmlTranslation &translationData,
63 const QQmlSourceLocation &location, QObject *obj);
64
65 Kind kind() const final { return QQmlAbstractBinding::QmlBinding; }
66
67 ~QQmlBinding() override;
68
69 bool mustCaptureBindableProperty() const final {return true;}
70 void refresh() override;
71
72 void setEnabled(bool, QQmlPropertyData::WriteFlags flags = QQmlPropertyData::DontRemoveBinding) override;
73 QString expression() const override;
74 void update(QQmlPropertyData::WriteFlags flags = QQmlPropertyData::DontRemoveBinding);
75
76 void printBindingLoopError(const QQmlProperty &prop) override;
77
78 typedef int Identifier;
79 enum {
80 Invalid = -1
81 };
82
83 QVariant evaluate();
84 bool evaluate(void *result, QMetaType type)
85 {
86 return QQmlJavaScriptExpression::evaluate(&result, &type, 0);
87 }
88
89 void expressionChanged() override;
90
91 QQmlSourceLocation sourceLocation() const override;
92 void setSourceLocation(const QQmlSourceLocation &location);
93 void setBoundFunction(QV4::BoundFunction *boundFunction) {
94 m_boundFunction.set(boundFunction->engine(), *boundFunction);
95 }
96 bool hasBoundFunction() const { return m_boundFunction.valueRef(); }
97
98 /**
99 * This method returns a snapshot of the currently tracked dependencies of
100 * this binding. The dependencies can change upon reevaluation. This method is
101 * used in GammaRay to visualize binding hierarchies.
102 *
103 * Call this method from the UI thread.
104 */
105 QVector<QQmlProperty> dependencies() const;
106 // This method is used internally to check whether a binding is constant and can be removed
107 virtual bool hasDependencies() const;
108
109protected:
110 virtual void doUpdate(const DeleteWatcher &watcher,
111 QQmlPropertyData::WriteFlags flags, QV4::Scope &scope);
112
113 virtual bool write(const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) = 0;
114 virtual bool write(void *result, QMetaType type, bool isUndefined, QQmlPropertyData::WriteFlags flags) = 0;
115
116 int getPropertyType() const;
117
118 bool slowWrite(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData,
119 const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags);
120 bool slowWrite(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData,
121 const void *result, QMetaType resultType, bool isUndefined,
122 QQmlPropertyData::WriteFlags flags);
123
124 QV4::ReturnedValue evaluate(bool *isUndefined);
125
126private:
127 static QQmlBinding *newBinding(const QQmlPropertyData *property);
128 static QQmlBinding *newBinding(QMetaType propertyType);
129
130 QQmlSourceLocation *m_sourceLocation = nullptr; // used for Qt.binding() created functions
131 QV4::PersistentValue m_boundFunction; // used for Qt.binding() that are created from a bound function object
132 void handleWriteError(const void *result, QMetaType resultType, QMetaType metaType);
133};
134
135QT_END_NAMESPACE
136
137Q_DECLARE_METATYPE(QQmlBinding*)
138
139#endif // QQMLBINDING_P_H
Q_ALWAYS_INLINE bool write(const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
Q_ALWAYS_INLINE bool write(void *result, QMetaType type, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
Q_ALWAYS_INLINE bool doStore(T value, const QQmlPropertyData *pd, QQmlPropertyData::WriteFlags flags) const
QObjectPointerBinding(QMetaType propertyType)
Q_ALWAYS_INLINE bool write(const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
Q_ALWAYS_INLINE bool write(void *result, QMetaType type, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
QString bindingValue() const override
QQmlSourceLocation sourceLocation() const override final
QQmlTranslationBindingFromBinding(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QV4::CompiledData::Binding *binding)
QQmlSourceLocation sourceLocation() const override final
QQmlTranslationBindingFromTranslationInfo(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QQmlTranslation &translationData, quint16 line, quint16 column)
virtual QString bindingValue() const override
QQmlTranslationBinding(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit)
void doUpdate(const DeleteWatcher &watcher, QQmlPropertyData::WriteFlags flags, QV4::Scope &scope) override final
static void onLanguageChange(QPropertyObserver *observer, QUntypedPropertyData *)
virtual QString bindingValue() const =0
bool hasDependencies() const override final
Combined button and popup list for selecting options.
Definition qjsvalue.h:23