Beautify bindable properties documentation
Some minor formatting changes Change-Id: I336a442d01cb048397b2a65977cfb96bb7179752 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
parent
3e65d0408b
commit
59b0212215
@ -127,23 +127,24 @@
|
|||||||
|
|
||||||
Bindable properties must not be used as variables in algorithms. Each value written
|
Bindable properties must not be used as variables in algorithms. Each value written
|
||||||
would be communicated to dependent properties.
|
would be communicated to dependent properties.
|
||||||
For example, in the following code, other properties dependent on myProperty would be
|
For example, in the following code, other properties that depend on
|
||||||
first informed about the change to 42, then about the change to maxvalue.
|
\b myProperty would be first informed about the change to \b 42, then about
|
||||||
|
the change to \b maxValue.
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
myProperty = somecomputation(); // returning, say, 42
|
myProperty = somecomputation(); // returning, say, 42
|
||||||
if (myProperty.value() > maxvalue)
|
if (myProperty.value() > maxValue)
|
||||||
myProperty = maxvalue;
|
myProperty = maxValue;
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
Instead, perform the computation in a separate variable. Correct usage is shown in the
|
Instead, perform the computation in a separate variable. Correct usage is shown in the
|
||||||
following example.
|
following example.
|
||||||
|
|
||||||
\code
|
\code
|
||||||
int newvalue = somecomputation();
|
int newValue = someComputation();
|
||||||
if (newvalue > maxvalue)
|
if (newValue > maxValue)
|
||||||
newvalue = maxvalue;
|
newValue = maxValue;
|
||||||
myProperty = newvalue; // only write to the property once
|
myProperty = newValue; // only write to the property once
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\section2 Writing Bindable Properties in Transitional States
|
\section2 Writing Bindable Properties in Transitional States
|
||||||
@ -153,15 +154,15 @@
|
|||||||
not be written in transient states, when class invariants are not met.
|
not be written in transient states, when class invariants are not met.
|
||||||
|
|
||||||
For example, in a class representing a circle which holds two members
|
For example, in a class representing a circle which holds two members
|
||||||
"radius" and "area" consistent, a setter might look like this (where radius
|
\b radius and \b area consistent, a setter might look like this (where radius
|
||||||
is a bindable property):
|
is a bindable property):
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
void setRadius(double newvalue)
|
void setRadius(double newValue)
|
||||||
{
|
{
|
||||||
radius = newvalue; // this might trigger change handlers
|
radius = newValue; // this might trigger change handlers
|
||||||
area = M_PI*radius*radius;
|
area = M_PI * radius * radius;
|
||||||
emit radiusChanged();
|
emit radiusChanged();
|
||||||
}
|
}
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user