Plasma
Plasma::DataContainer Class Reference
A set of data exported via a DataEngine. More...
#include <Plasma/DataContainer>

Public Slots | |
void | disconnectVisualization (QObject *visualization) |
Signals | |
void | becameUnused (const QString &source) |
void | dataUpdated (const QString &source, const Plasma::DataEngine::Data &data) |
void | updateRequested (DataContainer *source) |
Public Member Functions | |
void | connectVisualization (QObject *visualization, uint pollingInterval, Plasma::IntervalAlignment alignment) |
const DataEngine::Data | data () const |
DataContainer (QObject *parent=0) | |
void | removeAllData () |
void | setData (const QString &key, const QVariant &value) |
bool | visualizationIsConnected (QObject *visualization) const |
virtual | ~DataContainer () |
Protected Slots | |
void | checkUsage () |
Protected Member Functions | |
void | checkForUpdate () |
void | setNeedsUpdate (bool update=true) |
uint | timeSinceLastUpdate () const |
Detailed Description
A set of data exported via a DataEngine.Plasma::DataContainer wraps the data exported by a DataEngine implementation, providing a generic wrapper for the data.
A DataContainer may have zero or more associated pieces of data which are keyed by strings. The data itself is stored as QVariants. This allows easy and flexible retrieval of the information associated with this object without writing DataContainer or DataEngine specific code in visualizations.
If you are creating your own DataContainer objects (and are passing them to DataEngine::addSource()), you normally just need to listen to the updateRequested() signal (as well as any other methods you might have of being notified of new data) and call setData() to actually update the data. Then you need to either trigger the scheduleSourcesUpdated signal of the parent DataEngine or call checkForUpdate() on the DataContainer.
You also need to set a suitable name for the source with setObjectName(). See DataEngine::addSource() for more information.
Note that there is normally no need to subclass DataContainer, except as a way of encapsulating the data retreival for a source, since all notifications are done via signals rather than virtual methods.
Definition at line 61 of file datacontainer.h.
Constructor & Destructor Documentation
Plasma::DataContainer::DataContainer | ( | QObject * | parent = 0 |
) | [explicit] |
Constructs a default DataContainer that has no name or data associated with it.
Definition at line 32 of file datacontainer.cpp.
Plasma::DataContainer::~DataContainer | ( | ) | [virtual] |
Definition at line 38 of file datacontainer.cpp.
Member Function Documentation
void Plasma::DataContainer::becameUnused | ( | const QString & | source | ) | [signal] |
Emitted when the last visualization is disconnected.
Note that if this source was created by DataEngine::sourceRequestEvent(), it will be deleted by DataEngine once control returns to the event loop after this signal is emitted.
- Parameters:
-
source the name of the source that became unused
void Plasma::DataContainer::checkForUpdate | ( | ) | [protected] |
Checks whether any data has changed and, if so, emits dataUpdated().
Definition at line 163 of file datacontainer.cpp.
void Plasma::DataContainer::checkUsage | ( | ) | [protected, slot] |
Check if the DataContainer is still in use.
If not the signal "becameUnused" will be emitted.
Warning: The DataContainer may be invalid after calling this function, because a listener to becameUnused() may have deleted it.
Definition at line 189 of file datacontainer.cpp.
void Plasma::DataContainer::connectVisualization | ( | QObject * | visualization, | |
uint | pollingInterval, | |||
Plasma::IntervalAlignment | alignment | |||
) |
Connects an object to this DataContainer.
May be called repeatedly for the same visualization without side effects
- Parameters:
-
visualization the object to connect to this DataContainer pollingInterval the time in milliseconds between updates alignment the clock position to align updates to
Definition at line 77 of file datacontainer.cpp.
const DataEngine::Data Plasma::DataContainer::data | ( | ) | const |
void Plasma::DataContainer::dataUpdated | ( | const QString & | source, | |
const Plasma::DataEngine::Data & | data | |||
) | [signal] |
Emitted when the data has been updated, allowing visualizations to reflect the new data.
Note that you should not normally emit this directly. Instead, use checkForUpdates() or the DataEngine::scheduleSourcesUpdated() slot.
- Parameters:
-
source the objectName() of the DataContainer (and hence the name of the source) that updated its data data the updated data
void Plasma::DataContainer::disconnectVisualization | ( | QObject * | visualization | ) | [slot] |
Disconnects an object from this DataContainer.
Note that if this source was created by DataEngine::sourceRequestEvent(), it will be deleted by DataEngine once control returns to the event loop.
Definition at line 139 of file datacontainer.cpp.
void Plasma::DataContainer::removeAllData | ( | ) |
Removes all data currently associated with this source.
If you call removeAllData() on a DataContainer, you need to either trigger the scheduleSourcesUpdated() slot for the data engine it belongs to or call checkForUpdate() on the DataContainer.
Definition at line 60 of file datacontainer.cpp.
Set a value for a key.
This also marks this source as needing to signal an update.
If you call setData() directly on a DataContainer, you need to either trigger the scheduleSourcesUpdated() slot for the data engine it belongs to or call checkForUpdate() on the DataContainer.
- Parameters:
-
key a string used as the key for the data value a QVariant holding the actual data. If a null or invalid QVariant is passed in and the key currently exists in the data, then the data entry is removed
Definition at line 48 of file datacontainer.cpp.
void Plasma::DataContainer::setNeedsUpdate | ( | bool | update = true |
) | [protected] |
Indicates that the data should be treated as dirty the next time hasUpdates() is called.
This is needed for the case where updateRequested() is triggered but we don't want to update the data immediately because it has just been updated. The second request won't be fulfilled in this case, because we never updated the data and so never called checkForUpdate(). So we claim it needs an update anyway.
Definition at line 184 of file datacontainer.cpp.
uint Plasma::DataContainer::timeSinceLastUpdate | ( | ) | const [protected] |
Returns how long ago, in msecs, that the data in this container was last updated.
This is used by DataEngine to compress updates that happen more quickly than the minimum polling interval by calling setNeedsUpdate() instead of calling updateSourceEvent() immediately.
Definition at line 177 of file datacontainer.cpp.
void Plasma::DataContainer::updateRequested | ( | DataContainer * | source | ) | [signal] |
Emitted when an update is requested.
If a polling interval was passed connectVisualization(), this signal will be emitted every time the interval expires.
Note that if you create your own DataContainer (and pass it to DataEngine::addSource()), you will need to listen to this signal and refresh the data when it is triggered.
- Parameters:
-
source the datacontainer the update was requested for. Useful for classes that update the data for several containers.
bool Plasma::DataContainer::visualizationIsConnected | ( | QObject * | visualization | ) | const |
- Returns:
- true if the visualization is currently connected
Definition at line 72 of file datacontainer.cpp.
The documentation for this class was generated from the following files: