Commit 24966aba authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Add new methods to resuse matches

parent c97c76d5
......@@ -428,6 +428,40 @@ bool AbstractRunner::hasMatchRegex() const
return d->hasMatchRegex;
}
void AbstractRunner::addMatch(const QueryMatch &match)
{
if (match.idIsDetByData()) {
d->matches.insert(match.data().toString(), match);
} else {
d->matches.insert(match.id(), match);
}
}
void AbstractRunner::addMatch(const QString &id, const QueryMatch &match)
{
d->matches.insert(id, match);
}
void AbstractRunner::removeMatch(const QString &id)
{
d->matches.remove(id);
}
void AbstractRunner::clearMatches()
{
d->matches.clear();
}
QueryMatch AbstractRunner::getMatch(const QString &id) const
{
return d->matches.value(id);
}
QHash<QString, Plasma::QueryMatch> AbstractRunner::matches() const
{
return d->matches;
}
AbstractRunnerPrivate::AbstractRunnerPrivate(AbstractRunner *r)
: priority(AbstractRunner::NormalPriority),
speed(AbstractRunner::NormalSpeed),
......
......@@ -503,6 +503,52 @@ class KRUNNER_EXPORT AbstractRunner : public QObject
*/
void clearActions();
/**
* Add a match. This can be alter fetched using the getMatch method.
* As a key the id of the match is used. But in case the id was indirectly specified when setting the data the
* data as a string can be used to retrieve this entry.
* @see QueryMatch::idIsDetByData()
* @param match
* @since 5.76
*/
void addMatch(const Plasma::QueryMatch &match);
/**
* Add a match. This can be alter fetched using getMatch(id)
* @param id
* @param match
* @since 5.76
*/
void addMatch(const QString &id, const Plasma::QueryMatch &match);
/**
* Removes match with the given id.
* @param id
* @since 5.76
*/
void removeMatch(const QString &id);
/**
* Clears all matches.
* @since 5.76
*/
void clearMatches();
/**
* Get match with the given id.
* @param id
* @return QueryMatch
* @since 5.76
*/
QueryMatch getMatch(const QString &id) const;
/**
* QHash of all the matches that are set for this runner.
* @return QHash<QString, Plasma::QueryMatch>
* @since 5.76
*/
QHash<QString, Plasma::QueryMatch> matches() const;
/**
* Adds a registered syntax that this runner understands. This is used to
* display to the user what this runner can understand and how it can be
......
......@@ -44,6 +44,7 @@ public:
int fastRuns;
QReadWriteLock speedLock;
QHash<QString, QAction*> actions;
QHash<QString, QueryMatch> matches;
QList<RunnerSyntax> syntaxes;
RunnerSyntax *defaultSyntax;
bool hasRunOptions : 1;
......
......@@ -352,5 +352,10 @@ QList<QAction *> QueryMatch::actions() const
return d->actions;
}
bool QueryMatch::idIsDetByData() const
{
QReadLocker locker(d->lock);
return d->idSetByData;
}
} // Plasma namespace
......@@ -178,6 +178,13 @@ class KRUNNER_EXPORT QueryMatch
*/
QString id() const;
/**
* If the ID is indirectly set by setting the data.
* @return idIsDetByData
* @since 5.76
*/
bool idIsDetByData() const;
/**
* Sets the main title text for this match; should be short
* enough to fit nicely on one line in a user interface
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment