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
58 BindingPatchContext(QObject *object, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
59 int objectIndex, const QString &prefix)
60 : m_object(object), unit(unit), objectIndex(objectIndex), prefix(prefix + QLatin1Char('.'))
61 {
62 }
63
64 BindingPatchContext(QObject *object, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
65 int objectIndex)
66 : m_object(object), unit(unit), objectIndex(objectIndex)
67 {
68 }
69
72
73 void reset(const std::vector<QQmlRefPointer<QV4::ExecutableCompilationUnit>> &unitsToUnparent,
74 const std::vector<CompositeLevel> &internalUnits);
76 const std::vector<CompositeLevel> &internalUnits,
77 QDuplicateTracker<QObject *> *seenChildren);
78 void refreshObjects();
80
81 BindingPatchContext *childContext(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
82 const QV4::CompiledData::Binding *binding,
83 QDuplicateTracker<QObject *> *seenChildren);
84 BindingPatchContext *childContext(const QString &name, QObject *object,
85 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
86 int objectIndex, QDuplicateTracker<QObject *> *seenChildren);
87 BindingPatchContext *attachedContext(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
88 const QV4::CompiledData::Binding *binding,
89 QDuplicateTracker<QObject *> *seenChildren);
90
91 // Walk this object's group- and attached-property sub-object tree and find the right one to
92 // apply the change to. Return true if the change was applied or false otherwise.
93 bool applyBindingChange(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
94 const QV4::CompiledData::Change &change);
95
96private:
97 struct StoredBinding
98 {
99 QString propertyName;
100 QQmlAnyBinding binding;
101 QPointer<QObject> sourceGuard;
102 };
103
104 struct StoredValue
105 {
106 QString propertyName;
107 QVariant value;
108 };
109
110 struct StoredSignalHandler
111 {
112 QString signature;
113 std::unique_ptr<QQmlBoundSignal> handler;
114 };
115
116 void recordBindingValues(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
117 int cuIndex, QHash<QString, QVariant> *constantValues,
118 QDuplicateTracker<QObject *> *seenChildren);
119 void resetBinding(const QV4::CompiledData::Binding *binding, const QString &name,
120 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
121 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
122 const ReboundBindings &rebound);
123 void resetBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit, int cuIndex,
124 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
125 int newCuIndex);
126 void patchBinding(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
127 const QV4::CompiledData::Change &change);
128
129 static void retireObject(QObject *object);
130 static void clearBindingsRecursive(QObject *object);
131
132
133 QPointer<QObject> m_object;
134 QQmlRefPointer<QV4::ExecutableCompilationUnit> unit;
135 int objectIndex;
136 QString prefix;
137
138 std::vector<StoredBinding> m_storedBindings;
139 std::vector<StoredValue> m_storedValues;
140 std::vector<StoredSignalHandler> m_storedSignalHandlers;
142};
143
144} // namespace QQmlPreview
145
146QT_END_NAMESPACE
147
148#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 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)
void stashExternalState(const std::vector< CompositeLevel > &internalUnits, 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 QObject * idTarget(QObject *object, const QString &name)
static bool isExternalBinding(const QQmlAnyBinding &binding, 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