Add removeMatch(es) methods

Review: http://reviewboard.kde.org/r/2260


svn path=/trunk/KDE/kdelibs/; revision=1053618
This commit is contained in:
Jacopo De Simoi 2009-11-24 12:05:46 +00:00
parent b0630bfd58
commit dc295eca70
4 changed files with 87 additions and 0 deletions

View File

@ -212,6 +212,11 @@ QueryMatch &QueryMatch::operator=(const QueryMatch &other)
return *this; return *this;
} }
bool QueryMatch::operator==(const QueryMatch &other) const
{
return (d == other.d);
}
void QueryMatch::run(const RunnerContext &context) const void QueryMatch::run(const RunnerContext &context) const
{ {
//kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype(); //kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype();

View File

@ -83,6 +83,7 @@ class PLASMA_EXPORT QueryMatch
~QueryMatch(); ~QueryMatch();
QueryMatch &operator=(const QueryMatch &other); QueryMatch &operator=(const QueryMatch &other);
bool operator==(const QueryMatch &other) const;
bool operator<(const QueryMatch &other) const; bool operator<(const QueryMatch &other) const;

View File

@ -396,6 +396,63 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match)
return true; return true;
} }
bool RunnerContext::removeMatches(const QStringList matchIdList)
{
if (!isValid()) {
return false;
}
QStringList presentMatchIdList;
QList<const QueryMatch*> presentMatchList;
LOCK_FOR_READ(d)
foreach(QString matchId, matchIdList) {
const QueryMatch* match = d->matchesById.value(matchId, 0);
if (match) {
presentMatchList << match;
presentMatchIdList << matchId;
}
}
UNLOCK(d)
if (presentMatchIdList.isEmpty()) {
return false;
}
LOCK_FOR_WRITE(d)
foreach(const QueryMatch *match, presentMatchList) {
d->matches.removeAll(*match);
}
foreach(QString matchId, presentMatchIdList) {
d->matchesById.remove(matchId);
}
UNLOCK(d)
emit d->q->matchesChanged();
return true;
}
bool RunnerContext::removeMatch(const QString matchId)
{
if (!isValid()) {
return false;
}
LOCK_FOR_READ(d)
const QueryMatch* match = d->matchesById.value(matchId, 0);
UNLOCK(d)
if (!match) {
return false;
}
LOCK_FOR_WRITE(d)
d->matches.removeAll(*match);
d->matchesById.remove(matchId);
UNLOCK(d)
emit d->q->matchesChanged();
return true;
}
QList<QueryMatch> RunnerContext::matches() const QList<QueryMatch> RunnerContext::matches() const
{ {
LOCK_FOR_READ(d) LOCK_FOR_READ(d)

View File

@ -154,6 +154,30 @@ class PLASMA_EXPORT RunnerContext : public QObject
// plus: it is Q_UNUSED // plus: it is Q_UNUSED
bool addMatch(const QString &term, const QueryMatch &match); bool addMatch(const QString &term, const QueryMatch &match);
/**
* Removes a match from the existing list of matches.
*
* If you are going to be removing multiple matches, use removeMatches instead.
*
* @arg matchId the id of match to remove
*
* @return true if the match was removed, false otherwise.
* @since 4.4
*/
bool removeMatch(const QString matchId);
/**
* Removes lists of matches from the existing list of matches.
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @arg matchIdList the list of matches id to remove
*
* @return true if at least one match was removed, false otherwise.
* @since 4.4
*/
bool removeMatches(const QStringList matchIdList);
/** /**
* Retrieves all available matches for the current search term. * Retrieves all available matches for the current search term.
* *