Invalidate the context using a dummy pointer instead of 0. This avoids emitting to a null pointer.

BUG: 188940

svn path=/trunk/KDE/kdelibs/; revision=957813
This commit is contained in:
Jacopo De Simoi 2009-04-22 22:50:20 +00:00
parent c54617a1bd
commit 7e598b49ec

View File

@ -210,6 +210,11 @@ class RunnerContextPrivate : public QSharedData
}
}
void invalidate()
{
q = &s_dummyContext;
}
QReadWriteLock lock;
QList<QueryMatch> matches;
QMap<QString, const QueryMatch*> matchesById;
@ -217,8 +222,11 @@ class RunnerContextPrivate : public QSharedData
QString mimeType;
RunnerContext::Type type;
RunnerContext * q;
static RunnerContext s_dummyContext;
};
RunnerContext RunnerContextPrivate::s_dummyContext;
RunnerContext::RunnerContext(QObject *parent)
: QObject(parent),
d(new RunnerContextPrivate(this))
@ -244,14 +252,14 @@ void RunnerContext::reset()
// if we are the 'main' context others copied from. Resetting
// one RunnerContext makes all the copies obsolete.
//we need to mark the q pointer of the detached RunnerContextPrivate
//as dirty on detach to avoid receiving results for old queries
d->q = 0;
// We need to mark the q pointer of the detached RunnerContextPrivate
// as dirty on detach to avoid receiving results for old queries
d->invalidate();
d.detach();
//now that we detached the d pointer we need to mark its q pointer as
//this to receive the signals
// Now that we detached the d pointer we need to reset its q pointer
d->q = this;
// we still have to remove all the matches, since if the
@ -301,15 +309,15 @@ QString RunnerContext::mimeType() const
bool RunnerContext::isValid()
{
// if our qptr is null, we aren't useful anymore
return d->q;
// if our qptr is dirty, we aren't useful anymore
return (d->q != &(d->s_dummyContext));
}
bool RunnerContext::addMatches(const QString &term, const QList<QueryMatch> &matches)
{
Q_UNUSED(term)
if (matches.isEmpty() || !d->q) {
if (matches.isEmpty() || !isValid()) {
//Bail out if the query is empty or the qptr is dirty
return false;
}
@ -338,7 +346,7 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match)
{
Q_UNUSED(term)
if (!d->q) {
if (!isValid()) {
// Bail out if the qptr is dirty
return false;
}
@ -348,7 +356,7 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match)
d->matchesById.insert(match.id(), &d->matches.at(d->matches.size() - 1));
UNLOCK(this);
//kDebug()<< "added match" << match->text();
emit d->q->matchesChanged();
emit d->q->matchesChanged();
return true;
}