diff --git a/dataengine.cpp b/dataengine.cpp index ba451afbb..47842d374 100644 --- a/dataengine.cpp +++ b/dataengine.cpp @@ -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()); diff --git a/dataengine.h b/dataengine.h index eb9689684..3e694b917 100644 --- a/dataengine.h +++ b/dataengine.h @@ -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. diff --git a/datasource.cpp b/datasource.cpp index e761f83f8..0a699962d 100644 --- a/datasource.cpp +++ b/datasource.cpp @@ -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; } diff --git a/datasource.h b/datasource.h index 4aed80be5..73ab71831 100644 --- a/datasource.h +++ b/datasource.h @@ -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);