[Development] QML: grouping property changes for a single callback invocation

Alberto Mardegan mardy at users.sourceforge.net
Mon Mar 5 09:46:21 CET 2012


On 03/05/2012 03:39 AM, Alan Alpert wrote:
> It's pretty much as you described. With the slight addendum that what you're 
> asking for is probably not possible (in the general case). X and Y are 
> independent variables, one may change without the other. So the code can't 
> just wait for a signal which may or may not ever come. If you have a solution 
> for this problem, I'm all ears :) .

I've been giving it some thoughts, but my idea is very rough at the
moment. It's about queuing all the invocations of property signals (and
property bindings) and fire them in an idle callback to be invoked later.
So, supposing that you have this QML code:

=======
property int width: x + sizeX

onXChanged: functionA()
=======

instead of connecting the onXChanged() signal to function A and to the
re-evaluation of the "width" property, you would connect to a slot that
simply does something like this:

{
    listOfChangedProperties.append("x");
    /* next line sets up an idle event (QTimer with time set to 0,
     * maybe), if one is not set already */
    setupIdleEvent();
}

Then, when the idle callback will be invoked, it will go through
listOfChangedProperties and for each of them invoke the slots connected
to them, and recompute the values of other properties depending on them,
each time marking the dependent slot/property as processed, in order to
avoid processing it more than once during the same idle invocation.

This would also mean that if both "x" and "sizeX" change before the idle
callback is invoked, the "width" property expression would have to be
computed only once.

I didn't have a look at QDeclarative source code yet, so I'm all ears
for your opinion (and hints, in case I want to spend some time to
investigate this possibility).

Ciao,
  Alberto

-- 
http://blog.mardy.it <- geek in un lingua international!



More information about the Development mailing list