KTextEditor::Variable Class Reference

#include <variable.h>

Public Types

using ExpandFunction = std::function< QString(const QStringView &text, KTextEditor::View *view)>

Public Member Functions

 Variable ()=default
 Variable (const QString &name, const QString &description, ExpandFunction expansionFunc, bool isPrefixMatch)
 Variable (const Variable &copy)=default
QString description () const
QString evaluate (const QStringView &prefix, KTextEditor::View *view) const
bool isPrefixMatch () const
bool isValid () const
QString name () const
Variableoperator= (const Variable &copy)=default

Detailed Description

Variable for variable expansion.


A Variable is used by the KTextEditor::Editor to expand variables, also know as expanding macros. A Variable itself is defined by the variable name() as well as a description() and a function that replaces the variable by its value.

To register a Variable in the Editor use either Editor::registerVariableMatch() or Editor::registerPrefixMatch().

See also
KTextEditor::Editor, KTextEditor::Editor::registerVariableMatch(), KTextEditor::Editor::registerPrefixMatch()
Dominik Haumann <dhaum[email protected][email protected][email protected]kde.o[email protected]rg>

Definition at line 35 of file variable.h.

Member Typedef Documentation

using KTextEditor::Variable::ExpandFunction = std::function<QString(const QStringView &text, KTextEditor::View *view)>

Function that is called to expand a variable in text.


Definition at line 42 of file variable.h.

Constructor & Destructor Documentation

KTextEditor::Variable::Variable ( )

Constructs an invalid Variable, see isValid().

KTextEditor::Variable::Variable ( const QString name,
const QString description,
Variable::ExpandFunction  func,
bool  isPrefixMatch 

Constructor defining a Variable by its name, its description, and its function expansionFunc to expand a variable to its corresponding value.

The parameter isPrefixMatch indicates whether this Variable represents an exact match (false) or a prefix match (true).

The name should not be translated.

Definition at line 11 of file variable.cpp.

KTextEditor::Variable::Variable ( const Variable copy)

Copy constructor.

Member Function Documentation

QString KTextEditor::Variable::description ( ) const

Returns the description that was provided in the constructor.

Definition at line 34 of file variable.cpp.

QString KTextEditor::Variable::evaluate ( const QStringView prefix,
KTextEditor::View view 
) const

Expands the Variable to its value.

As example for an exact match, a variable "CurerntDocument:Cursor:Line" uses the view to return the current line of the text cursor. In this case prefix equals the text of the variable itself, i.e. "CurerntDocument:Cursor:Line".

As example of a prefix match, a variable "ENV:value" expands the environment value value, e.g. "ENV:HOME". In this case, the prefix equals the text "ENV:HOME" and view would be unused.

the expanded variable.

Definition at line 39 of file variable.cpp.

bool KTextEditor::Variable::isPrefixMatch ( ) const

Returns whether this Variable represents an exact match (false) or a prefix match (true).

Definition at line 24 of file variable.cpp.

bool KTextEditor::Variable::isValid ( ) const

Returns true, if the name is non-empty and the function provided in the constructor is not a nullptr.

Definition at line 19 of file variable.cpp.

QString KTextEditor::Variable::name ( ) const

Returns the name that was provided in the constructor.

Depending on where the Variable is registered, this name is used to identify an exact match or a prefix match.

Definition at line 29 of file variable.cpp.

Variable& KTextEditor::Variable::operator= ( const Variable copy)

Assignment operator.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jan 21 2021 23:00:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.