Groups the firstSubscriberAppeared and lastSubscriberDisappeared from multiple Property objects together. More...
#include <ContextProvider>
Signals | |
void | firstSubscriberAppeared () |
Emitted when the group of Context objects is subscribed to. | |
void | lastSubscriberDisappeared () |
Emitted when the group of Context objects is unsubscribed from. | |
Public Member Functions | |
Group (QObject *parent=0) | |
Contructs an empty Group object with the given parent. | |
~Group () | |
Destructor. | |
void | add (const Property &prop) |
Adds a Property object to the Group. | |
bool | isSubscribedTo () const |
Returns true iff any Property objects in the group are subscribed to. | |
QSet< const Property * > | getProperties () |
Returns the set of properties currently belonging to the Group. | |
Group & | operator<< (const Property &prop) |
Group & | operator<< (const Property *prop) |
Groups the firstSubscriberAppeared and lastSubscriberDisappeared from multiple Property objects together.
Group is useful in cases when multiple properties are provided by the same source, such as a hardware sensor. When any of these properties is subscribed to, the source needs to be turned on, and when none of these properties are subscribed to, the source needs to be turned off.
For example,
Property location("Location"); Property altitude("Altitude"); Group gps; gps << location << altitude; connect(gps, SIGNAL(firstSubscriberAppeared()), this, SLOT(turnGpsOn())); connect(gps, SIGNAL(lastSubscriberDisappeared()), this, SLOT(onGpsOff()));
This way, the provider doesn't need to store the subscription statuses of the related keys.
Initially, none of the Property objects related to a Group are subscribed to. When some of them are subscribed to, Group emits the firstSubscriberAppeared signal. When all of them are again unsubscribed, Group emits the lastSubscriberDisappeared signal.
ContextProvider::Group::Group | ( | QObject * | parent = 0 |
) | [explicit] |
Contructs an empty Group object with the given parent.
ContextProvider::Group::~Group | ( | ) |
Destructor.
void ContextProvider::Group::add | ( | const Property & | property | ) |
void ContextProvider::Group::firstSubscriberAppeared | ( | ) | [signal] |
Emitted when the group of Context objects is subscribed to.
I.e., when none of them were subscribed to and now some of them were subscribed to.
QSet< const Property * > ContextProvider::Group::getProperties | ( | ) |
Returns the set of properties currently belonging to the Group.
bool ContextProvider::Group::isSubscribedTo | ( | ) | const |
Returns true iff any Property objects in the group are subscribed to.
void ContextProvider::Group::lastSubscriberDisappeared | ( | ) | [signal] |
Emitted when the group of Context objects is unsubscribed from.
I.e., when some of them were subscribed to and now all of them were unsubscribed from.