1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQMLPROPERTY_P_H
41#define QQMLPROPERTY_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "qqmlproperty.h"
55#include "qqmlengine.h"
56
57#include <private/qobject_p.h>
58#include <private/qtqmlglobal_p.h>
59#include <private/qqmlrefcount_p.h>
60#include <private/qqmlcontext_p.h>
61#include <private/qqmlboundsignalexpressionpointer_p.h>
62#include <private/qqmlpropertydata_p.h>
63
64QT_BEGIN_NAMESPACE
65
66class QQmlContext;
67class QQmlEnginePrivate;
68class QQmlJavaScriptExpression;
69class QQmlMetaObject;
70
71class Q_QML_PRIVATE_EXPORT QQmlPropertyPrivate : public QQmlRefCount
72{
73public:
74 QQmlContextData *context;
75 QPointer<QQmlEngine> engine;
76 QPointer<QObject> object;
77
78 QQmlPropertyData core;
79 QQmlPropertyData valueTypeData;
80
81 bool isNameCached:1;
82 QString nameCache;
83
84 QQmlPropertyPrivate();
85
86 QQmlPropertyIndex encodedIndex() const
87 { return encodedIndex(core, valueTypeData); }
88 static QQmlPropertyIndex encodedIndex(const QQmlPropertyData &core, const QQmlPropertyData &valueTypeData)
89 { return QQmlPropertyIndex(core.coreIndex(), valueTypeData.coreIndex()); }
90
91 inline QQmlContextData *effectiveContext() const;
92
93 void initProperty(QObject *obj, const QString &name);
94 void initDefault(QObject *obj);
95
96 bool isValueType() const;
97 int propertyType() const;
98 QQmlProperty::Type type() const;
99 QQmlProperty::PropertyTypeCategory propertyTypeCategory() const;
100
101 QVariant readValueProperty();
102 bool writeValueProperty(const QVariant &, QQmlPropertyData::WriteFlags);
103
104 static QQmlMetaObject rawMetaObjectForType(QQmlEnginePrivate *, int);
105 static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object,
106 const QVariant &value, int flags);
107 static bool writeValueProperty(QObject *,
108 const QQmlPropertyData &, const QQmlPropertyData &valueTypeData,
109 const QVariant &, QQmlContextData *,
110 QQmlPropertyData::WriteFlags flags = nullptr);
111 static bool write(QObject *, const QQmlPropertyData &, const QVariant &,
112 QQmlContextData *, QQmlPropertyData::WriteFlags flags = nullptr);
113 static void findAliasTarget(QObject *, QQmlPropertyIndex, QObject **, QQmlPropertyIndex *);
114
115 enum BindingFlag {
116 None = 0,
117 DontEnable = 0x1
118 };
119 Q_DECLARE_FLAGS(BindingFlags, BindingFlag)
120
121 static void setBinding(QQmlAbstractBinding *binding, BindingFlags flags = None,
122 QQmlPropertyData::WriteFlags writeFlags = QQmlPropertyData::DontRemoveBinding);
123
124 static void removeBinding(const QQmlProperty &that);
125 static void removeBinding(QObject *o, QQmlPropertyIndex index);
126 static void removeBinding(QQmlAbstractBinding *b);
127 static QQmlAbstractBinding *binding(QObject *, QQmlPropertyIndex index);
128
129 static QQmlProperty restore(QObject *, const QQmlPropertyData &, const QQmlPropertyData *, QQmlContextData *);
130
131 int signalIndex() const;
132
133 static inline QQmlPropertyPrivate *get(const QQmlProperty &p) { return p.d; }
134
135 // "Public" (to QML) methods
136 static QQmlAbstractBinding *binding(const QQmlProperty &that);
137 static void setBinding(const QQmlProperty &that, QQmlAbstractBinding *);
138 static QQmlBoundSignalExpression *signalExpression(const QQmlProperty &that);
139 static void setSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *);
140 static void takeSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *);
141 static bool write(const QQmlProperty &that, const QVariant &, QQmlPropertyData::WriteFlags);
142 static QQmlPropertyIndex propertyIndex(const QQmlProperty &that);
143 static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
144 static bool connect(const QObject *sender, int signal_index,
145 const QObject *receiver, int method_index,
146 int type = 0, int *types = nullptr);
147 static void flushSignal(const QObject *sender, int signal_index);
148
149 static QVariant resolvedUrlSequence(const QVariant &value, QQmlContextData *context);
150 static QQmlProperty create(QObject *target, const QString &propertyName, QQmlContextData *context);
151
152};
153
154Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::BindingFlags)
155
156QT_END_NAMESPACE
157
158#endif // QQMLPROPERTY_P_H
159