diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2015-02-04 19:12:12 +0100 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2015-02-04 19:12:12 +0100 |
commit | 801076803ce92d7bd646a58c792015c2b833d0c5 (patch) | |
tree | b9bc16705a541cf402ee4614da7115135efb19d5 /src/webchannel/qwebchannel.js | |
parent | 9d705911391c456813ce54a52f70aa2ccbc5b553 (diff) | |
parent | 358e5acba3154a8ab4b53b22797c2c1eae4707dc (diff) | |
download | qtwebchannel-801076803ce92d7bd646a58c792015c2b833d0c5.tar.gz |
Merge branch '5.4' into dev
This merge required extensive conflict handling because
the bug fix in 5.4 to properly wrap and forward QObjects
referenced by published objects' properties clashed with
some feature additions in dev, namely the client separation
logic.
All unit test pass for me locally now again.
Conflicts:
.qmake.conf
src/webchannel/qmetaobjectpublisher.cpp
tests/auto/qml/tst_webchannel.qml
Change-Id: If3d00e13b265c6ab9fb2c38023014f97f8e7779b
Diffstat (limited to 'src/webchannel/qwebchannel.js')
-rw-r--r-- | src/webchannel/qwebchannel.js | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/webchannel/qwebchannel.js b/src/webchannel/qwebchannel.js index 13e9da5..4a1c784 100644 --- a/src/webchannel/qwebchannel.js +++ b/src/webchannel/qwebchannel.js @@ -155,6 +155,10 @@ var QWebChannel = function(transport, initCallback) for (var objectName in data) { var object = new QObject(objectName, data[objectName], channel); } + // now unwrap properties, which might reference other registered objects + for (var objectName in channel.objects) { + channel.objects[objectName].unwrapProperties(); + } if (initCallback) { initCallback(channel); } @@ -177,18 +181,31 @@ function QObject(name, data, webChannel) // ---------------------------------------------------------------------- - function unwrapQObject( response ) + this.unwrapQObject = function(response) { + if (response instanceof Array) { + // support list of objects + var ret = new Array(response.length); + for (var i = 0; i < response.length; ++i) { + ret[i] = object.unwrapQObject(response[i]); + } + return ret; + } if (!response || !response["__QObject*__"] - || response["id"] === undefined - || response["data"] === undefined) { + || response["id"] === undefined) { return response; } + var objectId = response.id; if (webChannel.objects[objectId]) return webChannel.objects[objectId]; + if (!response.data) { + console.error("Cannot unwrap unknown QObject " + objectId + " without data."); + return; + } + var qObject = new QObject( objectId, response.data, webChannel ); qObject.destroyed.connect(function() { if (webChannel.objects[objectId] === qObject) { @@ -206,9 +223,18 @@ function QObject(name, data, webChannel) } } }); + // here we are already initialized, and thus must directly unwrap the properties + qObject.unwrapProperties(); return qObject; } + this.unwrapProperties = function() + { + for (var propertyIdx in object.__propertyCache__) { + object.__propertyCache__[propertyIdx] = object.unwrapQObject(object.__propertyCache__[propertyIdx]); + } + } + function addSignal(signalData, isPropertyNotifySignal) { var signalName = signalData[0]; @@ -311,7 +337,7 @@ function QObject(name, data, webChannel) "args": args }, function(response) { if (response !== undefined) { - var result = unwrapQObject(response); + var result = object.unwrapQObject(response); if (callback) { (callback)(result); } @@ -326,6 +352,8 @@ function QObject(name, data, webChannel) var propertyName = propertyInfo[1]; var notifySignalData = propertyInfo[2]; // initialize property cache with current value + // NOTE: if this is an object, it is not directly unwrapped as it might + // reference other QObject that we do not know yet object.__propertyCache__[propertyIndex] = propertyInfo[3]; if (notifySignalData) { |