[Qt-interest] QWebView for document editing

Nathan Carter nathancarter5 at gmail.com
Mon Jul 13 06:46:44 CEST 2009


On Jul 12, 2009, at 11:29 PM, Tony Rietwyk wrote:

> 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.

Yeah, there are Javascript calls for all of this stuff.  You can write  
a Javascript inverse of my nodeAddress() which turns an address into a  
node (or a selector for one).  Build a selector you can use like this:

	myTopNode.querySelector( 'Child_Index_6 > Child_Index_0 >  
Child_Index_13' )

or whatever.  The 'A > B > C > D' syntax means that the A, B, C, D are  
ids and the > mean "child of".  Google Javascript/HTML selectors for  
more info.

Then you can use Javascript calls to insert a next sibling of a node,  
or whatever you need to do. All the tree-manipulation routines you'd  
expect there to be in Javascript for dealing with the DOM, there are.   
I recommend Mozilla Developer Connection website.

Nathan




More information about the Qt-interest-old mailing list