aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlbinding_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/qqmlbinding_p.h')
-rw-r--r--src/qml/qml/qqmlbinding_p.h107
1 files changed, 33 insertions, 74 deletions
diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h
index bf73c24c9e..4031a2655e 100644
--- a/src/qml/qml/qqmlbinding_p.h
+++ b/src/qml/qml/qqmlbinding_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQMLBINDING_P_H
#define QQMLBINDING_P_H
@@ -51,12 +15,8 @@
// We mean it.
//
-#include "qqml.h"
-#include "qqmlpropertyvaluesource.h"
-#include "qqmlexpression.h"
#include "qqmlproperty.h"
#include "qqmlscriptstring.h"
-#include "qqmlproperty_p.h"
#include <QtCore/QObject>
#include <QtCore/QMetaProperty>
@@ -64,11 +24,12 @@
#include <private/qqmlabstractbinding_p.h>
#include <private/qqmljavascriptexpression_p.h>
#include <private/qv4functionobject_p.h>
+#include <private/qqmltranslation_p.h>
QT_BEGIN_NAMESPACE
class QQmlContext;
-class Q_QML_PRIVATE_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
+class Q_QML_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
public QQmlAbstractBinding
{
friend class QQmlAbstractBinding;
@@ -86,16 +47,26 @@ public:
const QQmlPropertyData *property, QV4::Function *function, QObject *obj,
const QQmlRefPointer<QQmlContextData> &ctxt, QV4::ExecutionContext *scope);
+ static QQmlBinding *create(QMetaType propertyType, QV4::Function *function, QObject *obj,
+ const QQmlRefPointer<QQmlContextData> &ctxt,
+ QV4::ExecutionContext *scope);
+
static QQmlBinding *createTranslationBinding(
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
const QV4::CompiledData::Binding *binding, QObject *obj,
const QQmlRefPointer<QQmlContextData> &ctxt);
- ~QQmlBinding() override;
+ static QQmlBinding *
+ createTranslationBinding(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
+ const QQmlRefPointer<QQmlContextData> &ctxt,
+ const QString &propertyName, const QQmlTranslation &translationData,
+ const QQmlSourceLocation &location, QObject *obj);
- void setTarget(const QQmlProperty &);
- bool setTarget(QObject *, const QQmlPropertyData &, const QQmlPropertyData *valueType);
+ Kind kind() const final { return QQmlAbstractBinding::QmlBinding; }
+
+ ~QQmlBinding() override;
+ bool mustCaptureBindableProperty() const final {return true;}
void refresh() override;
void setEnabled(bool, QQmlPropertyData::WriteFlags flags = QQmlPropertyData::DontRemoveBinding) override;
@@ -108,6 +79,10 @@ public:
};
QVariant evaluate();
+ bool evaluate(void *result, QMetaType type)
+ {
+ return QQmlJavaScriptExpression::evaluate(&result, &type, 0);
+ }
void expressionChanged() override;
@@ -116,6 +91,7 @@ public:
void setBoundFunction(QV4::BoundFunction *boundFunction) {
m_boundFunction.set(boundFunction->engine(), *boundFunction);
}
+ bool hasBoundFunction() const { return m_boundFunction.valueRef(); }
/**
* This method returns a snapshot of the currently tracked dependencies of
@@ -125,52 +101,35 @@ public:
* Call this method from the UI thread.
*/
QVector<QQmlProperty> dependencies() const;
+ // This method is used internally to check whether a binding is constant and can be removed
virtual bool hasDependencies() const;
protected:
virtual void doUpdate(const DeleteWatcher &watcher,
- QQmlPropertyData::WriteFlags flags, QV4::Scope &scope) = 0;
+ QQmlPropertyData::WriteFlags flags, QV4::Scope &scope);
+
+ virtual bool write(const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) = 0;
+ virtual bool write(void *result, QMetaType type, bool isUndefined, QQmlPropertyData::WriteFlags flags) = 0;
- void getPropertyData(QQmlPropertyData **propertyData, QQmlPropertyData *valueTypeData) const;
int getPropertyType() const;
bool slowWrite(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData,
const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags);
+ bool slowWrite(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData,
+ const void *result, QMetaType resultType, bool isUndefined,
+ QQmlPropertyData::WriteFlags flags);
QV4::ReturnedValue evaluate(bool *isUndefined);
private:
- inline bool updatingFlag() const;
- inline void setUpdatingFlag(bool);
- inline bool enabledFlag() const;
- inline void setEnabledFlag(bool);
-
- static QQmlBinding *newBinding(QQmlEnginePrivate *engine, const QQmlPropertyData *property);
+ static QQmlBinding *newBinding(const QQmlPropertyData *property);
+ static QQmlBinding *newBinding(QMetaType propertyType);
QQmlSourceLocation *m_sourceLocation = nullptr; // used for Qt.binding() created functions
QV4::PersistentValue m_boundFunction; // used for Qt.binding() that are created from a bound function object
+ void handleWriteError(const void *result, QMetaType resultType, QMetaType metaType);
};
-bool QQmlBinding::updatingFlag() const
-{
- return m_target.tag().testFlag(UpdatingBinding);
-}
-
-void QQmlBinding::setUpdatingFlag(bool v)
-{
- m_target.setTag(m_target.tag().setFlag(UpdatingBinding, v));
-}
-
-bool QQmlBinding::enabledFlag() const
-{
- return m_target.tag().testFlag(BindingEnabled);
-}
-
-void QQmlBinding::setEnabledFlag(bool v)
-{
- m_target.setTag(m_target.tag().setFlag(BindingEnabled, v));
-}
-
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QQmlBinding*)