KTutorial  0.5.1
Public Member Functions
ktutorial::WaitForProperty Class Reference

Waits for a property to have a specific value. More...

#include <WaitForProperty.h>

Inheritance diagram for ktutorial::WaitForProperty:
Inheritance graph
[legend]
Collaboration diagram for ktutorial::WaitForProperty:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Q_INVOKABLE WaitForProperty ()
 Creates a new WaitForProperty.
 WaitForProperty (QObject *object, const QString &propertyName, const QVariant &value)
 Creates a new WaitForProperty.
virtual ~WaitForProperty ()
 Destroys this WaitForProperty.
Q_INVOKABLE void setProperty (QObject *object, const QString &propertyName, const QVariant &value)
 Sets the property to wait for.
Q_INVOKABLE void setPropertyToWaitFor (QObject *object, const QString &propertyName, const QVariant &value)
 setProperty(QObject*, const QString&, const QVariant&) version to be used in Ruby scripts.
virtual bool conditionMet () const
 Returns true if the property has the expected value, false otherwise.

Detailed Description

Waits for a property to have a specific value.

When the property changes its value to the specified one and the WaitForProperty is active, the wait ends.

Note that the condition can be met even if the wait did not end. The condition is met if the property has the expected value. However, the wait ends only when the property changes to the expected value while the WaitFor is active. That is, in an active WaitFor, the condition would be met even if the expected value was set in the property when the WaitFor was inactive, but the wait would not end until the expected value was set again in the property after the WaitFor was activated.

Not every property can be used to wait for its value to change. Only properties that have a notify signal can be used with that purpose.

WaitForProperty with properties that do not have a notify signal can still be used to enrich other WaitFors (for example, a WaitForAnd containing a WaitForSignal and a WaitForProperty: waiting for a signal to be emitted but only changing to the next step if, in addition, some property has some value), but they can not be used alone as single WaitFors (for example, waiting just for the property "visible" of some widget to have some value would never end).

Using a WaitForProperty just to perform further checks when other WaitFor ends its waiting should be done only with properties that do not have a notify signal. For example, if a WaitForAnd contains a WaitForSignal and a WaitForProperty, and the WaitForProperty uses a property with a notify signal, it may happen that the property changes to the expected value after the signal was emitted. If that happens, the WaitForProperty would end its waiting, and so the WaitForAnd as the WaitForSignal had already ended its waiting too. It may not be the desired behavior if the WaitForProperty was there to be checked only when the WaitForSignal ended. In that case, instead of using a WaitForProperty, the proper way to do it is executing a custom slot when the WaitForSignal ends its waiting, and checking the value of the property in a "if" construction in that slot.

Definition at line 65 of file WaitForProperty.h.


Constructor & Destructor Documentation

Creates a new WaitForProperty.

This constructor is needed to dynamically create WaitForProperty objects in scripts using ScriptingModule::newWaitFor(const QString&). Method setProperty(QObject*, const QString&, const QVariant&) must be called to finish setting up the object. For C++ tutorials, use WaitForProperty(QObject*, const QString&, const QVariant&) constructor instead of this one.

Definition at line 34 of file WaitForProperty.cpp.

ktutorial::WaitForProperty::WaitForProperty ( QObject *  object,
const QString &  propertyName,
const QVariant &  value 
)

Creates a new WaitForProperty.

Parameters:
objectThe object that contains the property.
propertyNameThe name of the property.
valueThe value of the property to wait for.

Definition at line 38 of file WaitForProperty.cpp.

References setProperty().


Member Function Documentation

bool ktutorial::WaitForProperty::conditionMet ( ) const [virtual]

Returns true if the property has the expected value, false otherwise.

Note that it will return true even if the property got the expected value when this WaitForProperty was inactive. That is, as long as the property has the expected value, it will return true, no matter when that value was set.

Returns:
True if the property has the expected value, false otherwise.

Implements ktutorial::WaitFor.

Definition at line 92 of file WaitForProperty.cpp.

References ktutorial::WaitForPropertyPrivate::mObject, ktutorial::WaitForPropertyPrivate::mPropertyName, and ktutorial::WaitForPropertyPrivate::mValue.

void ktutorial::WaitForProperty::setProperty ( QObject *  object,
const QString &  propertyName,
const QVariant &  value 
)

Sets the property to wait for.

This method can be invoked from a script.

In fact, you should only invoke this method from a script, and only once, to set up the object. For C++ tutorials, use WaitForProperty(QObject*, const QString&, const QVariant&) constructor when creating this WaitForProperty.

Parameters:
objectThe object that contains the property.
propertyNameThe name of the property.
valueThe value of the property to wait for.

Definition at line 48 of file WaitForProperty.cpp.

References ktutorial::WaitForPropertyPrivate::mObject, ktutorial::WaitForPropertyPrivate::mPropertyName, and ktutorial::WaitForPropertyPrivate::mValue.

Referenced by setPropertyToWaitFor(), and WaitForProperty().

void ktutorial::WaitForProperty::setPropertyToWaitFor ( QObject *  object,
const QString &  propertyName,
const QVariant &  value 
)

setProperty(QObject*, const QString&, const QVariant&) version to be used in Ruby scripts.

Ruby backend calls setProperty(const char*, const QVariant&) method instead of the aforementioned one. This method just offers a non overloaded name and delegates the call in the method from WaitForProperty.

Parameters:
objectThe object that contains the property.
propertyNameThe name of the property.
valueThe value of the property to wait for.
Todo:
Remove when Ruby backend gets proper support for overloaded methods.

Definition at line 86 of file WaitForProperty.cpp.

References setProperty().


The documentation for this class was generated from the following files: