From 3e3fd09aab1f04b0e926a650903758b8aa6843e8 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 9 Jun 2010 18:04:28 +0000 Subject: [PATCH] clean up from the sources if somebody deletes a DataContainer BUG:235881 svn path=/trunk/KDE/kdelibs/; revision=1136398 --- dataengine.cpp | 16 ++++++++++++++++ dataengine.h | 1 + private/dataengine_p.h | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/dataengine.cpp b/dataengine.cpp index 8e3a92e69..83d596233 100644 --- a/dataengine.cpp +++ b/dataengine.cpp @@ -251,6 +251,7 @@ void DataEngine::addSource(DataContainer *source) QObject::connect(source, SIGNAL(updateRequested(DataContainer*)), this, SLOT(internalUpdateSource(DataContainer*))); + QObject::connect(source, SIGNAL(destroyed()), this, SLOT(sourceDestroyed())); d->sources.insert(source->objectName(), source); emit sourceAdded(source->objectName()); scheduleSourcesUpdated(); @@ -620,6 +621,7 @@ DataContainer *DataEnginePrivate::source(const QString &sourceName, bool createW DataContainer *s = new DataContainer(q); s->setObjectName(sourceName); sources.insert(sourceName, s); + QObject::connect(s, SIGNAL(destroyed(QObject *)), q, SLOT(sourceDestroyed(QObject *))); QObject::connect(s, SIGNAL(updateRequested(DataContainer*)), q, SLOT(internalUpdateSource(DataContainer*))); @@ -667,6 +669,20 @@ void DataEnginePrivate::connectSource(DataContainer *s, QObject *visualization, } } +void DataEnginePrivate::sourceDestroyed(QObject *object) +{ + DataContainer *container = qobject_cast(object); + + DataEngine::SourceDict::const_iterator it = sources.begin(); + while (it != sources.constEnd()) { + if (it.value() == object) { + sources.remove(it.key()); + break; + } + ++it; + } +} + DataContainer *DataEnginePrivate::requestSource(const QString &sourceName, bool *newSource) { if (newSource) { diff --git a/dataengine.h b/dataengine.h index fe78f45e8..94cfe7432 100644 --- a/dataengine.h +++ b/dataengine.h @@ -485,6 +485,7 @@ NoAlignment) const; friend class NullEngine; Q_PRIVATE_SLOT(d, void internalUpdateSource(DataContainer *source)) + Q_PRIVATE_SLOT(d, void sourceDestroyed(QObject *object)); DataEnginePrivate *const d; }; diff --git a/private/dataengine_p.h b/private/dataengine_p.h index 5f896c438..781e3d3a5 100644 --- a/private/dataengine_p.h +++ b/private/dataengine_p.h @@ -79,6 +79,11 @@ class DataEnginePrivate */ bool isPublished() const; + /** + * a datacontainer has been destroyed, clean up stuff + */ + void sourceDestroyed(QObject *object); + DataEngine *q; KPluginInfo dataEngineDescription; int refCount;