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