clean up from the sources if somebody deletes a DataContainer

BUG:235881

svn path=/trunk/KDE/kdelibs/; revision=1136398
This commit is contained in:
Marco Martin 2010-06-09 18:04:28 +00:00
parent 85d9343669
commit 3e3fd09aab
3 changed files with 22 additions and 0 deletions

View File

@ -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<DataContainer *>(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) {

View File

@ -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;
};

View File

@ -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;