[Qt-interest] QWebView for document editing
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Mon Jul 13 05:29:49 CEST 2009
Nathan wrote:
> Tony wrote:
>
> > I have a similar requirement but I had problems when editing the
> > nodes in javascript. In particular, I do NOT want to just replace nodes
with
> > text HTML. I need to replace some of the nodes, and copy other existing
> > ones (by ID) - which may be whole trees of nodes. But I couldn't see
how to
> > do this in a nice generic way through signals to the javascript.
>
> I'm not sure exactly what you're saying here. But note that in
> Javascript you can overwrite an entire node's content (though it be a
> whole tree) with another one very easily, by calling
>
> node.innerHTML = 'new html code here';
>
> Then if node was a <p>, let's say, it will still be a <p>, but with
> all new content (however complex) that you specified inside the string
> that you assigned to innerHTML.
>
> Is that what you meant?
>
> Nathan
Hi Nathan,
I meant in situations eg when a new node is inserted or removed at the root
of the tree. It is too slow to recurse down and regenerate the entire tree
- there will be thousands of nodes. If the existing root node looks like:
<span id="root">
<span id="abc">...</span>
<span id="xyz">...</span>
</span>
If I now insert id="jkl" after "abc", I shouldn't have to regenerate abc and
xyz. It would be nice to pass in say:
<span id="root">
<span id="abc" />
<span id="jkl">New jkl content</span>
<span id="xyz" />
</span>
Note that the sub-levels of abc and xyz are not included. Instead of just
replacing the root node innerHTML, the javascript would create a temporary
node for this fragment, then for each id in the fragment, see if there is
the same id in the root node. If there is, then cut the subtree out of root
and move it into the temporary one. Last of all, the root node would be
replaced by the temporary one.
Hope that makes it clear.
Tony.
More information about the Qt-interest-old
mailing list