MCPcopy Index your code
hub / github.com/PyQt5/PyQt / QObject

Function QObject

QWebChannel/Data/qwebchannel.js:176–441  ·  view source on GitHub ↗
(name, data, webChannel)

Source from the content-addressed store, hash-verified

174};
175
176function QObject(name, data, webChannel)
177{
178 this.__id__ = name;
179 webChannel.objects[name] = this;
180
181 // List of callbacks that get invoked upon signal emission
182 this.__objectSignals__ = {};
183
184 // Cache of all properties, updated when a notify signal is emitted
185 this.__propertyCache__ = {};
186
187 var object = this;
188
189 // ----------------------------------------------------------------------
190
191 this.unwrapQObject = function(response)
192 {
193 if (response instanceof Array) {
194 // support list of objects
195 return response.map(qobj => object.unwrapQObject(qobj))
196 }
197 if (!(response instanceof Object))
198 return response;
199
200 if (!response["__QObject*__"] || response.id === undefined) {
201 var jObj = {};
202 for (const propName of Object.keys(response)) {
203 jObj[propName] = object.unwrapQObject(response[propName]);
204 }
205 return jObj;
206 }
207
208 var objectId = response.id;
209 if (webChannel.objects[objectId])
210 return webChannel.objects[objectId];
211
212 if (!response.data) {
213 console.error("Cannot unwrap unknown QObject " + objectId + " without data.");
214 return;
215 }
216
217 var qObject = new QObject( objectId, response.data, webChannel );
218 qObject.destroyed.connect(function() {
219 if (webChannel.objects[objectId] === qObject) {
220 delete webChannel.objects[objectId];
221 // reset the now deleted QObject to an empty {} object
222 // just assigning {} though would not have the desired effect, but the
223 // below also ensures all external references will see the empty map
224 // NOTE: this detour is necessary to workaround QTBUG-40021
225 Object.keys(qObject).forEach(name => delete qObject[name]);
226 }
227 });
228 // here we are already initialized, and thus must directly unwrap the properties
229 qObject.unwrapProperties();
230 return qObject;
231 }
232
233 this.unwrapProperties = function()

Callers

nothing calls this directly

Calls 4

keysMethod · 0.80
errorMethod · 0.80
invokeSignalCallbacksFunction · 0.70
addSignalFunction · 0.70

Tested by

no test coverage detected