KTextEditor::Variable

Search for usage in LXR

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.

Introduction

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()
Author
Dominik Haumann <dhaum.nosp@m.ann@.nosp@m.kde.o.nosp@m.rg>

Definition at line 34 of file variable.h.

Member Typedef Documentation

◆ ExpandFunction

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

Function that is called to expand a variable in text.

Parameters
text

Definition at line 41 of file variable.h.

Constructor & Destructor Documentation

◆ Variable() [1/3]

KTextEditor::Variable::Variable ( )
default

Constructs an invalid Variable, see isValid().

◆ Variable() [2/3]

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).

Note
The name should not be translated.

Definition at line 11 of file variable.cpp.

◆ Variable() [3/3]

KTextEditor::Variable::Variable ( const Variable & copy)
default

Copy constructor.

Member Function Documentation

◆ description()

QString KTextEditor::Variable::description ( ) const

Returns the description that was provided in the constructor.

Definition at line 34 of file variable.cpp.

◆ evaluate()

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.

Returns
the expanded variable.

Definition at line 39 of file variable.cpp.

◆ isPrefixMatch()

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.

◆ isValid()

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.

◆ name()

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.

◆ operator=()

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

Assignment operator.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.