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
qqmlpreviewbindingpatchcontext_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 reason:default
4#ifndef QQMLPREVIEWBINDINGPATCHCONTEXT_P_H
5#define QQMLPREVIEWBINDINGPATCHCONTEXT_P_H
6
7#include <private/qduplicatetracker_p.h>
8#include <private/qqmlanybinding_p.h>
9#include <private/qqmlboundsignal_p.h>
10#include <private/qqmlcontextdata_p.h>
11#include <private/qqmldata_p.h>
12#include <private/qqmlpreviewdiff_p.h>
13#include <private/qqmlvmemetaobject_p.h>
14#include <private/qv4executablecompilationunit_p.h>
15
16#include <QtCore/qpointer.h>
17#include <QtCore/qvariant.h>
18
19#include <unordered_map>
20
21//
22// W A R N I N G
23// -------------
24//
25// This file is not part of the Qt API. It exists purely as an
26// implementation detail. This header file may change from version to
27// version without notice, or even be removed.
28//
29// We mean it.
30//
31
32QT_BEGIN_NAMESPACE
33
34namespace QQmlPreview {
35
45
46// Maps a property name bound by the new compilation unit to the new binding. Used to
47// recognize properties that repopulateBindings() will re-assign (so resetting them is
48// redundant) and, for group/attached properties, to find the matching new sub-object.
50
52{
54public:
57 static void retireObject(QObject *object);
58 static void clearBindingsRecursive(QObject *object);
59
60 // The constant value a literal binding assigns, or an invalid QVariant for a script (or other
61 // non-literal) binding. Used by the in-place patch to install/reset literal bindings.
62 static QVariant literalValue(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
63 const QV4::CompiledData::Binding *binding);
64
65 BindingPatchContext(QObject *object, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
66 int objectIndex, const QString &prefix)
67 : m_object(object), unit(unit), objectIndex(objectIndex), prefix(prefix + QLatin1Char('.'))
68 {
69 }
70
71 BindingPatchContext(QObject *object, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
72 int objectIndex)
73 : m_object(object), unit(unit), objectIndex(objectIndex)
74 {
75 }
76
79
80 void reset(const std::vector<QQmlRefPointer<QV4::ExecutableCompilationUnit>> &unitsToUnparent,
81 const std::vector<CompositeLevel> &internalUnits);
83 const std::vector<CompositeLevel> &internalUnits,
84 QDuplicateTracker<QObject *> *seenChildren);
85 void refreshObjects();
87
88 BindingPatchContext *childContext(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
89 int objectIndex, const QV4::CompiledData::Binding *binding,
90 QDuplicateTracker<QObject *> *seenChildren);
91 BindingPatchContext *childContext(const QString &name, QObject *object,
92 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
93 int objectIndex, QDuplicateTracker<QObject *> *seenChildren);
94 BindingPatchContext *attachedContext(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
95 const QV4::CompiledData::Binding *binding,
96 QDuplicateTracker<QObject *> *seenChildren);
97
98 // Walk this object's group- and attached-property sub-object tree and find the right one to
99 // apply the change to. Return true if the change was applied or false otherwise.
100 bool applyBindingChange(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
101 const QV4::CompiledData::Change &change);
102
103private:
104 struct StoredBinding
105 {
106 QString propertyName;
107 QQmlAnyBinding binding;
108 QPointer<QObject> sourceGuard;
109 };
110
111 struct StoredValue
112 {
113 QString propertyName;
114 QVariant value;
115 };
116
117 struct StoredSignalHandler
118 {
119 QString signature;
120 std::unique_ptr<QQmlBoundSignal> handler;
121 };
122
123 void recordBindingValues(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
124 int cuIndex, QHash<QString, QVariant> *constantValues,
125 QDuplicateTracker<QObject *> *seenChildren);
126 void resetBinding(int objectIndex, const QV4::CompiledData::Binding *binding,
127 const QString &name,
128 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
129 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
130 const ReboundBindings &rebound);
131 void resetBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit, int cuIndex,
132 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
133 int newCuIndex);
134 void patchBinding(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
135 const QV4::CompiledData::Change &change);
136
137
138 QPointer<QObject> m_object;
139 QQmlRefPointer<QV4::ExecutableCompilationUnit> unit;
140 int objectIndex;
141 QString prefix;
142
143 std::vector<StoredBinding> m_storedBindings;
144 std::vector<StoredValue> m_storedValues;
145 std::vector<StoredSignalHandler> m_storedSignalHandlers;
147};
148
149} // namespace QQmlPreview
150
151QT_END_NAMESPACE
152
153#endif
bool applyBindingChange(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &newUnit, const QV4::CompiledData::Change &change)
void reset(const std::vector< QQmlRefPointer< QV4::ExecutableCompilationUnit > > &unitsToUnparent, const std::vector< CompositeLevel > &internalUnits)
BindingPatchContext & operator=(BindingPatchContext &&)=default
BindingPatchContext * attachedContext(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, const QV4::CompiledData::Binding *binding, QDuplicateTracker< QObject * > *seenChildren)
BindingPatchContext * childContext(const QString &name, QObject *object, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int objectIndex, QDuplicateTracker< QObject * > *seenChildren)
BindingPatchContext(QObject *object, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int objectIndex)
BindingPatchContext(BindingPatchContext &&)=default
BindingPatchContext(QObject *object, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int objectIndex, const QString &prefix)
static QVariant literalValue(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, const QV4::CompiledData::Binding *binding)
void stashExternalState(const std::vector< CompositeLevel > &internalUnits, QDuplicateTracker< QObject * > *seenChildren)
BindingPatchContext * childContext(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int objectIndex, const QV4::CompiledData::Binding *binding, QDuplicateTracker< QObject * > *seenChildren)
static QVariant literalBindingValue(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, const QV4::CompiledData::Binding *binding)
static bool isExternalFunction(const QV4::Function *f, const std::vector< CompositeLevel > &internalUnits, QObject *target)
static QVariant coerceToPropertyType(QV4::ExecutionEngine *v4, const QVariant &value, QMetaType propertyType)
static ReboundBindings reboundBindings(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int cuIndex)
static bool functionBelongsToObject(const QV4::Function *f, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &cu, int objectIndex)
static QObject * propertyToPropertySource(const QQmlAnyBinding &binding)
static int reboundSubObjectIndex(const ReboundBindings &rebound, const QString &name, QV4::CompiledData::Binding::Type type)
static bool isExternalUnitBinding(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &cu, const std::vector< CompositeLevel > &internalUnits, QObject *target)
static QObject * idTarget(QObject *object, const QString &name)
static bool isExternalBinding(const QQmlAnyBinding &binding, const std::vector< CompositeLevel > &internalUnits, QObject *target)
static bool rebuildReachesUnitViaContext(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &cu, const std::vector< CompositeLevel > &internalUnits, QObject *target)
Combined button and popup list for selecting options.
QQmlRefPointer< QV4::ExecutableCompilationUnit > newCu
QQmlRefPointer< QV4::ExecutableCompilationUnit > oldCu
QQmlRefPointer< QQmlContextData > context