MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / QObject

Function QObject

Plugins/WebBrowser/Resource/js/QWebChannel.js:178–441  ·  view source on GitHub ↗
(name, data, webChannel)

Source from the content-addressed store, hash-verified

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

Callers 1

Q_LOGGING_CATEGORYFunction · 0.85

Calls 2

invokeSignalCallbacksFunction · 0.85
addSignalFunction · 0.85

Tested by

no test coverage detected