* require a SearchContext in exec since the context may have shifted during matching due to multithreading
* differentiate between resetSearchTerm and just setSearchTerm (to be used with the above) * remove the SearchContext ptr from SearchMatch's dptr as it isn't used; don't want to mislead people or waste memory * more const correctness svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=764593
This commit is contained in:
parent
ddadcc6765
commit
2f479c7084
@ -141,10 +141,14 @@ SearchContext::~SearchContext()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void SearchContext::setSearchTerm(const QString &term)
|
||||
void SearchContext::resetSearchTerm(const QString &term)
|
||||
{
|
||||
d->resetState();
|
||||
setSearchTerm(term);
|
||||
}
|
||||
|
||||
void SearchContext::setSearchTerm(const QString &term)
|
||||
{
|
||||
if (term.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -58,8 +58,15 @@ class PLASMA_EXPORT SearchContext : public QObject
|
||||
SearchContext(QObject *parent, const SearchContext& other);
|
||||
|
||||
/**
|
||||
* Sets the search term for this object. This clears all current
|
||||
* matches in the process.
|
||||
* Sets the search term for this object and attempts to determine
|
||||
* the type of the search.
|
||||
* This clears all current matches in the process.
|
||||
*/
|
||||
void resetSearchTerm(const QString&);
|
||||
|
||||
/**
|
||||
* Sets the search term for this object and attempts to determine
|
||||
* the type of the search.
|
||||
*/
|
||||
void setSearchTerm(const QString&);
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <QStringList>
|
||||
#include <QIcon>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "searchmatch.h"
|
||||
|
||||
#include "abstractrunner.h"
|
||||
@ -32,9 +34,8 @@ namespace Plasma
|
||||
class SearchMatch::Private
|
||||
{
|
||||
public:
|
||||
Private(SearchContext* s, AbstractRunner *r)
|
||||
: /*search(s),*/
|
||||
runner(r),
|
||||
Private(const SearchContext *s, AbstractRunner *r)
|
||||
: runner(r),
|
||||
type(SearchMatch::ExactMatch),
|
||||
enabled(true),
|
||||
relevance(1)
|
||||
@ -42,8 +43,8 @@ class SearchMatch::Private
|
||||
searchTerm = s->searchTerm();
|
||||
mimetype = s->mimetype();
|
||||
}
|
||||
|
||||
QString searchTerm;
|
||||
SearchContext *search;
|
||||
AbstractRunner *runner;
|
||||
SearchMatch::Type type;
|
||||
QString mimetype;
|
||||
@ -55,7 +56,7 @@ class SearchMatch::Private
|
||||
};
|
||||
|
||||
|
||||
SearchMatch::SearchMatch(SearchContext *search, AbstractRunner *runner)
|
||||
SearchMatch::SearchMatch(const SearchContext *search, AbstractRunner *runner)
|
||||
: d(new Private(search, runner))
|
||||
{
|
||||
}
|
||||
@ -82,12 +83,12 @@ void SearchMatch::setMimetype(const QString &mimetype)
|
||||
|
||||
QString SearchMatch::mimetype() const
|
||||
{
|
||||
return d->mimetype;//.isEmpty() ? d->search->mimetype() : d->mimetype;
|
||||
return d->mimetype;
|
||||
}
|
||||
|
||||
QString SearchMatch::searchTerm() const
|
||||
{
|
||||
return d->searchTerm;//->searchTerm();
|
||||
return d->searchTerm;
|
||||
}
|
||||
|
||||
void SearchMatch::setRelevance(qreal relevance)
|
||||
@ -150,12 +151,20 @@ bool SearchMatch::operator<(const SearchMatch& other) const
|
||||
return d->relevance < other.d->relevance;
|
||||
}
|
||||
|
||||
void SearchMatch::exec()
|
||||
void SearchMatch::exec(const SearchContext *context)
|
||||
{
|
||||
Q_ASSERT(context);
|
||||
|
||||
//kDebug() << "reseting the terms to the most recent status" << context;
|
||||
d->searchTerm = context->searchTerm();
|
||||
d->mimetype = context->mimetype();
|
||||
|
||||
//kDebug() << "we have" << d->searchTerm << d->mimetype;
|
||||
if (d->runner) {
|
||||
//TODO: this could be dangerous if the runner is deleted behind our backs.
|
||||
//TODO: this could be dangerous if the runner is deleted behind our backs.
|
||||
d->runner->exec(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // Plasma namespace
|
||||
|
||||
|
@ -39,7 +39,7 @@ class PLASMA_EXPORT SearchMatch
|
||||
ExactMatch,
|
||||
PossibleMatch };
|
||||
|
||||
SearchMatch(SearchContext *search, AbstractRunner *runner);
|
||||
SearchMatch(const SearchContext *search, AbstractRunner *runner);
|
||||
~SearchMatch();
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ class PLASMA_EXPORT SearchMatch
|
||||
|
||||
//Pending a better solution, changing this to public
|
||||
// public Q_SLOTS:
|
||||
void exec();
|
||||
void exec(const SearchContext *context);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
|
Loading…
Reference in New Issue
Block a user