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