KRunner 5.109.0
|
The RunnerContext class provides information related to a search, including the search term, metadata on the search term and collected matches. More...
#include <KRunner/RunnerContext>
Signals | |
void | matchesChanged () |
Public Member Functions | |
RunnerContext (QObject *parent=nullptr) | |
RunnerContext (RunnerContext &other, QObject *parent=nullptr) | |
Copy constructor. | |
bool | addMatch (const QueryMatch &match) |
Appends a match to the existing list of matches. | |
bool | addMatches (const QList< QueryMatch > &matches) |
Appends lists of matches to the list of matches. | |
void | ignoreCurrentMatchForHistory () const |
Set this to true in the AbstractRunner::run method to prevent the entry from being saved to the history. | |
bool | isValid () const |
QList< QueryMatch > | matches () const |
Retrieves all available matches for the current search term. | |
RunnerContext & | operator= (const RunnerContext &other) |
Assignment operator. | |
QString | query () const |
void | requestQueryStringUpdate (const QString &text, int cursorPosition) const |
Request that KRunner updates the query string and stasy open, even after running a match. | |
void | reset () |
Resets the search term for this object. | |
void | restore (const KConfigGroup &config) |
Sets the launch counts for the associated match ids. | |
void | run (const QueryMatch &match) |
Run a match using the information from this context. | |
void | save (KConfigGroup &config) |
void | setQuery (const QString &term) |
Sets the query term for this object and attempts to determine the type of the search. | |
void | setSingleRunnerQueryMode (bool enabled) |
Sets single runner query mode. | |
bool | singleRunnerQueryMode () const |
The RunnerContext class provides information related to a search, including the search term, metadata on the search term and collected matches.
Plasma::RunnerContext::RunnerContext | ( | RunnerContext & | other, |
QObject * | parent = nullptr |
||
) |
Copy constructor.
bool Plasma::RunnerContext::addMatch | ( | const QueryMatch & | match | ) |
Appends a match to the existing list of matches.
If you are going to be adding multiple matches, use
match | the match to add |
bool Plasma::RunnerContext::addMatches | ( | const QList< QueryMatch > & | matches | ) |
Appends lists of matches to the list of matches.
matches | the matches to add |
void Plasma::RunnerContext::ignoreCurrentMatchForHistory | ( | ) | const |
Set this to true in the AbstractRunner::run method to prevent the entry from being saved to the history.
bool Plasma::RunnerContext::isValid | ( | ) | const |
while (.. a possibly large iteration) { if (!context.isValid()) { return; }
... some processing ... }
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< QueryMatch > Plasma::RunnerContext::matches | ( | ) | const |
Retrieves all available matches for the current search term.
RunnerContext & Plasma::RunnerContext::operator= | ( | const RunnerContext & | other | ) |
Assignment operator.
QString Plasma::RunnerContext::query | ( | ) | const |
void Plasma::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 |
void Plasma::RunnerContext::reset | ( | ) |
Resets the search term for this object.
This removes all current matches in the process and turns off single runner query mode.
void Plasma::RunnerContext::restore | ( | const KConfigGroup & | config | ) |
Sets the launch counts for the associated match ids.
If a runner adds a match to this context, the context will check if the match id has been launched before and increase the matches relevance correspondingly. In this manner, any front end can implement adaptive search by sorting items according to relevance.
config | the config group where launch data was stored |
void Plasma::RunnerContext::run | ( | const QueryMatch & | match | ) |
Run a match using the information from this context.
The context will also keep track of the number of times the match was launched to sort future matches according to user habits
match | the match to run |
void Plasma::RunnerContext::save | ( | KConfigGroup & | config | ) |
config | the config group where launch data should be stored |
void Plasma::RunnerContext::setQuery | ( | const QString & | term | ) |
Sets the query term for this object and attempts to determine the type of the search.
void Plasma::RunnerContext::setSingleRunnerQueryMode | ( | bool | enabled | ) |
Sets single runner query mode.
Note that a call to reset() will turn off single runner query mode.
bool Plasma::RunnerContext::singleRunnerQueryMode | ( | ) | const |