KRunner::RunnerContext Class

class KRunner::RunnerContext

The RunnerContext class provides information related to a search, including the search term and collected matches. More...

Header: #include <KRunner/RunnerContext>
CMake: find_package(KF6 REQUIRED COMPONENTS Runner)
target_link_libraries(mytarget PRIVATE KF6::Runner)

Public Functions

RunnerContext(KRunner::RunnerManager *manager = nullptr)
bool addMatch(const KRunner::QueryMatch &match)
bool addMatches(const QList<KRunner::QueryMatch> &matches)
(since 5.90) void ignoreCurrentMatchForHistory() const
bool isValid() const
QList<KRunner::QueryMatch> matches() const
QString query() const
(since 5.90) void requestQueryStringUpdate(const QString &text, int cursorPosition) const
void setQuery(const QString &term)
bool singleRunnerQueryMode() const

Detailed Description

Member Function Documentation

[explicit] RunnerContext::RunnerContext(KRunner::RunnerManager *manager = nullptr)

bool RunnerContext::addMatch(const KRunner::QueryMatch &match)

Appends a match to the existing list of matches.

If you are going to be adding multiple matches, it is more performant to use addMatches instead.

match the match to add

Returns true if the match was added, false otherwise.

bool RunnerContext::addMatches(const QList<KRunner::QueryMatch> &matches)

Appends lists of matches to the list of matches.

matches the matches to add

Returns true if matches were added, false if matches were e.g. outdated

[since 5.90] void RunnerContext::ignoreCurrentMatchForHistory() const

Set this to true in the AbstractRunner::run method to prevent the entry from being saved to the history.

This function was introduced in 5.90.

bool RunnerContext::isValid() const

Returnss true if this context is no longer valid and therefore matching using it should abort. While not required to be used within runners, it provides a nice way to avoid unnecessary processing in runners that may run for an extended period (as measured in 10s of ms) and therefore improve the user experience.

QList<KRunner::QueryMatch> RunnerContext::matches() const

Retrieves all available matches for the current search term.

Returns a list of matches

QString RunnerContext::query() const

Returns the current search query term.

See also setQuery().

[since 5.90] void RunnerContext::requestQueryStringUpdate(const QString &text, int cursorPosition) const

Request that KRunner updates the query string and stasy open, even after running a match. This method is const so it can be called in a const context.

text Text that will be displayed in the search field

cursorPosition Position of the cursor, if this is different than the length of the text, the characters between the position and text will be selected

This function was introduced in 5.90.

void RunnerContext::setQuery(const QString &term)

Sets the query term for this object and attempts to determine the type of the search.

See also query().

bool RunnerContext::singleRunnerQueryMode() const

Returns true if the current query is a single runner query