* removeData method added to DataEngine which allows one to, well, remove data from a source

* passing a null or invalid QVariant to DataSource::setData now results in the removal of the entry if it exists

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=676783
This commit is contained in:
Aaron J. Seigo 2007-06-17 17:38:54 +00:00
parent f39618e727
commit a452da7dd2
4 changed files with 30 additions and 2 deletions

View File

@ -218,6 +218,15 @@ void DataEngine::setData(const QString& source, const QString& key, const QVaria
d->queueUpdate();
}
void DataEngine::removeData(const QString& source, const QString& key)
{
DataSource* s = d->source(source, false);
if (s) {
s->setData(key, QVariant());
d->queueUpdate();
}
}
void DataEngine::addSource(DataSource* source)
{
SourceDict::const_iterator it = d->sources.find(source->objectName());

View File

@ -205,6 +205,14 @@ class PLASMA_EXPORT DataEngine : public QObject
**/
void setData(const QString& source, const QString& key, const QVariant& value);
/**
* Removes a data entry from a source
*
* @param source the name of the data source
* @param key the data entry to remove
**/
void removeData(const QString& source, const QString& key);
/**
* Adds an already constructed data source. The DataEngine takes
* ownership of the DataSource object.

View File

@ -56,7 +56,16 @@ const DataEngine::Data DataSource::data() const
void DataSource::setData(const QString& key, const QVariant& value)
{
d->data[key] = value;
if (value.isNull() || !value.isValid()) {
if (!d->data.contains(key)) {
return;
}
d->data.remove(key);
} else {
d->data[key] = value;
}
d->dirty = true;
}

View File

@ -63,7 +63,9 @@ class PLASMA_EXPORT DataSource : public QObject
* is done by the engine. This allows for batching updates.
*
* @param key a string used as the key for the data
* @param value a QVariant holding the actual data
* @param 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
**/
void setData(const QString& key, const QVariant& value);