KTextEditor

variable.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "variable.h"
8 
9 namespace KTextEditor
10 {
11 Variable::Variable(const QString &name, const QString &description, Variable::ExpandFunction func, bool isPrefixMatch)
12  : m_name(name)
13  , m_description(description)
14  , m_function(std::move(func))
15  , m_isPrefixMatch(isPrefixMatch)
16 {
17 }
18 
19 bool Variable::isValid() const
20 {
21  return (!m_name.isEmpty()) && (m_function != nullptr);
22 }
23 
25 {
26  return m_isPrefixMatch;
27 }
28 
30 {
31  return m_name;
32 }
33 
35 {
36  return m_description;
37 }
38 
40 {
41  return isValid() ? m_function(prefix, view) : QString();
42 }
43 
44 }
Variable()=default
Constructs an invalid Variable, see isValid().
QString description() const
Returns the description that was provided in the constructor.
Definition: variable.cpp:34
bool isValid() const
Returns true, if the name is non-empty and the function provided in the constructor is not a nullptr.
Definition: variable.cpp:19
bool isEmpty() const const
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:243
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition: katetextblock.h:19
QString name() const
Returns the name that was provided in the constructor.
Definition: variable.cpp:29
bool isPrefixMatch() const
Returns whether this Variable represents an exact match (false) or a prefix match (true).
Definition: variable.cpp:24
QString evaluate(const QStringView &prefix, KTextEditor::View *view) const
Expands the Variable to its value.
Definition: variable.cpp:39
std::function< QString(const QStringView &text, KTextEditor::View *view)> ExpandFunction
Function that is called to expand a variable in text.
Definition: variable.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:50:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.